summaryrefslogtreecommitdiffstats
path: root/sys/boot/pc98/btx
diff options
context:
space:
mode:
authorkato <kato@FreeBSD.org>2000-03-31 16:03:02 +0000
committerkato <kato@FreeBSD.org>2000-03-31 16:03:02 +0000
commitf6d236e3a23822aff581ece94f1dbb92418fc696 (patch)
treeb1e2352a5faa70647568b07daf49711997024a24 /sys/boot/pc98/btx
parent4cb901960c0aeaed0bc980b0e65c3f6fa199f723 (diff)
downloadFreeBSD-src-f6d236e3a23822aff581ece94f1dbb92418fc696.zip
FreeBSD-src-f6d236e3a23822aff581ece94f1dbb92418fc696.tar.gz
Synced with following files:
src/sys/boot/i386/Makefile.inc 1.1 src/sys/boot/i386/btx/btx/btx.s 1.15 src/sys/boot/i386/btx/btxldr/Makefile 1.8 src/sys/boot/i386/btx/btxldr/btxldr.s 1.9 src/sys/boot/i386/libi386/biosdisk.c 1.29 src/sys/boot/i386/loader/Makefile 1.42 src/sys/boot/i386/loader/main.c 1.18 (entry point address of loader was not changed.) Reviewed by: nyan
Diffstat (limited to 'sys/boot/pc98/btx')
-rw-r--r--sys/boot/pc98/btx/btx/btx.S45
-rw-r--r--sys/boot/pc98/btx/btx/btx.s45
-rw-r--r--sys/boot/pc98/btx/btxldr/Makefile18
-rw-r--r--sys/boot/pc98/btx/btxldr/btxldr.S150
-rw-r--r--sys/boot/pc98/btx/btxldr/btxldr.s150
5 files changed, 246 insertions, 162 deletions
diff --git a/sys/boot/pc98/btx/btx/btx.S b/sys/boot/pc98/btx/btx/btx.S
index 5858dda..408485d 100644
--- a/sys/boot/pc98/btx/btx/btx.S
+++ b/sys/boot/pc98/btx/btx/btx.S
@@ -82,12 +82,15 @@
# BIOS Data Area locations.
#
.`ifdef' PC98
- .set BDA_MEM,0xa1501 # Free memory
- .set BDA_POS,0xa153e # Cursor position
+ .set BDA_MEM,0x501 # Free memory
+ .set BDA_KEYFLAGS,0x53a # Keyboard shift-state flags
+ .set BDA_POS,0x53e # Cursor position
.else
.set BDA_MEM,0x413 # Free memory
+ .set BDA_KEYFLAGS,0x417 # Keyboard shift-state flags
.set BDA_SCR,0x449 # Video mode
.set BDA_POS,0x450 # Cursor position
+ .set BDA_BOOT,0x472 # Boot howto flag
.endif
#
# Derivations, for brevity.
@@ -316,7 +319,10 @@ exit.3: jz exit.3 # No
outb %al,$0xf0
exit.4: jmp exit.4
.else
- int $0x19 # BIOS: Reboot
+ .code16
+ movw $0x1234, BDA_BOOT # Do a warm boot
+ jmpfwi(0xffff,0x0) # reboot the machine
+ .code32
.endif
#
# Set IRQ offsets by reprogramming 8259A PICs.
@@ -671,6 +677,8 @@ int15_87: pushl %eax # Save
pushl %ecx # stash ECX
xorl %ecx,%ecx # highw of ECX is clear
movw 0x18(%ebp),%cx # Get user's ECX
+ shll $0x1,%ecx # Convert from num words to num
+ # bytes
rep # repeat...
movsb # perform copy.
popl %ecx # Restore
@@ -684,19 +692,40 @@ int15_87: pushl %eax # Save
jmp v86mon.5 # Finish up
#
+# Reboot the machine by setting the reboot flag and exiting
+#
+reboot: orb $0x1,btx_hdr+0x7 # Set the reboot flag
+ jmp exit # Terminate BTX and reboot
+
+#
# Emulate INT imm8... also make sure to check if it's int 15/87
#
v86intn: lodsb # Get int no
+ cmpb $0x19,%al # is it int 19?
+ je reboot # yes, reboot the machine
cmpb $0x15,%al # is it int 15?
- jne v86intn.2 # no, skip parse
+ jne v86intn.3 # no, skip parse
pushl %eax # stash EAX
movl 0x1c(%ebp),%eax # user's saved EAX
- cmpb $0x87,%ah # is it our sub function?
- jne v86intn.1 # no, don't handle it
+ cmpb $0x87,%ah # is it the memcpy subfunction?
+ jne v86intn.1 # no, keep checking
popl %eax # get the stack straight
jmp int15_87 # it's our cue
-v86intn.1: popl %eax # restore EAX
-v86intn.2: subl %edi,%esi # From
+v86intn.1: cmpw $0x4f53,%ax # is it the delete key callout?
+ jne v86intn.2 # no, handle the int normally
+ movb BDA_KEYFLAGS,%al # get the shift key state
+.`ifdef' PC98
+ andb $0x18,%al # mask off just Ctrl and Alt
+ cmpb $0x18,%al # are both Ctrl and Alt down?
+.else
+ andb $0xc,%al # mask off just Ctrl and Alt
+ cmpb $0xc,%al # are both Ctrl and Alt down?
+.endif
+ jne v86intn.2 # no, handle the int normally
+ popl %eax # restore EAX
+ jmp reboot # reboot the machine
+v86intn.2: popl %eax # restore EAX
+v86intn.3: subl %edi,%esi # From
shrl $0x4,%edi # linear
movw %dx,-0x2(%ebx) # Save flags
movw %di,-0x4(%ebx) # Save CS
diff --git a/sys/boot/pc98/btx/btx/btx.s b/sys/boot/pc98/btx/btx/btx.s
index 5858dda..408485d 100644
--- a/sys/boot/pc98/btx/btx/btx.s
+++ b/sys/boot/pc98/btx/btx/btx.s
@@ -82,12 +82,15 @@
# BIOS Data Area locations.
#
.`ifdef' PC98
- .set BDA_MEM,0xa1501 # Free memory
- .set BDA_POS,0xa153e # Cursor position
+ .set BDA_MEM,0x501 # Free memory
+ .set BDA_KEYFLAGS,0x53a # Keyboard shift-state flags
+ .set BDA_POS,0x53e # Cursor position
.else
.set BDA_MEM,0x413 # Free memory
+ .set BDA_KEYFLAGS,0x417 # Keyboard shift-state flags
.set BDA_SCR,0x449 # Video mode
.set BDA_POS,0x450 # Cursor position
+ .set BDA_BOOT,0x472 # Boot howto flag
.endif
#
# Derivations, for brevity.
@@ -316,7 +319,10 @@ exit.3: jz exit.3 # No
outb %al,$0xf0
exit.4: jmp exit.4
.else
- int $0x19 # BIOS: Reboot
+ .code16
+ movw $0x1234, BDA_BOOT # Do a warm boot
+ jmpfwi(0xffff,0x0) # reboot the machine
+ .code32
.endif
#
# Set IRQ offsets by reprogramming 8259A PICs.
@@ -671,6 +677,8 @@ int15_87: pushl %eax # Save
pushl %ecx # stash ECX
xorl %ecx,%ecx # highw of ECX is clear
movw 0x18(%ebp),%cx # Get user's ECX
+ shll $0x1,%ecx # Convert from num words to num
+ # bytes
rep # repeat...
movsb # perform copy.
popl %ecx # Restore
@@ -684,19 +692,40 @@ int15_87: pushl %eax # Save
jmp v86mon.5 # Finish up
#
+# Reboot the machine by setting the reboot flag and exiting
+#
+reboot: orb $0x1,btx_hdr+0x7 # Set the reboot flag
+ jmp exit # Terminate BTX and reboot
+
+#
# Emulate INT imm8... also make sure to check if it's int 15/87
#
v86intn: lodsb # Get int no
+ cmpb $0x19,%al # is it int 19?
+ je reboot # yes, reboot the machine
cmpb $0x15,%al # is it int 15?
- jne v86intn.2 # no, skip parse
+ jne v86intn.3 # no, skip parse
pushl %eax # stash EAX
movl 0x1c(%ebp),%eax # user's saved EAX
- cmpb $0x87,%ah # is it our sub function?
- jne v86intn.1 # no, don't handle it
+ cmpb $0x87,%ah # is it the memcpy subfunction?
+ jne v86intn.1 # no, keep checking
popl %eax # get the stack straight
jmp int15_87 # it's our cue
-v86intn.1: popl %eax # restore EAX
-v86intn.2: subl %edi,%esi # From
+v86intn.1: cmpw $0x4f53,%ax # is it the delete key callout?
+ jne v86intn.2 # no, handle the int normally
+ movb BDA_KEYFLAGS,%al # get the shift key state
+.`ifdef' PC98
+ andb $0x18,%al # mask off just Ctrl and Alt
+ cmpb $0x18,%al # are both Ctrl and Alt down?
+.else
+ andb $0xc,%al # mask off just Ctrl and Alt
+ cmpb $0xc,%al # are both Ctrl and Alt down?
+.endif
+ jne v86intn.2 # no, handle the int normally
+ popl %eax # restore EAX
+ jmp reboot # reboot the machine
+v86intn.2: popl %eax # restore EAX
+v86intn.3: subl %edi,%esi # From
shrl $0x4,%edi # linear
movw %dx,-0x2(%ebx) # Save flags
movw %di,-0x4(%ebx) # Save CS
diff --git a/sys/boot/pc98/btx/btxldr/Makefile b/sys/boot/pc98/btx/btxldr/Makefile
index b6f4016..35964ce 100644
--- a/sys/boot/pc98/btx/btxldr/Makefile
+++ b/sys/boot/pc98/btx/btxldr/Makefile
@@ -1,26 +1,28 @@
# $FreeBSD$
-ORG=0x100000
-#AFLAGS+= -x assembler-with-cpp
+M4?= m4
+M4FLAGS+= -DLOADER_ADDRESS=${LOADER_ADDRESS} -DPC98
-#AFLAGS+= --defsym PC98=1 --defsym BTXLDR_VERBOSE=1
-AFLAGS+= --defsym PC98=1
+.if defined(BTXLDR_VERBOSE)
+M4FLAGS+= -DBTXLDR_VERBOSE
+.endif
all: btxldr
btxldr: btxldr.o
.if ${OBJFORMAT} == aout
- ${LD} -nostdlib -N -s -T ${ORG} -o btxldr.out btxldr.o
+ ${LD} -nostdlib -N -s -T ${LOADER_ADDRESS} -o btxldr.out btxldr.o
dd if=btxldr.out of=${.TARGET} ibs=32 skip=1
.else
- ${LD} -N -e start -Ttext ${ORG} -o btxldr.out btxldr.o
+ ${LD} -N -e start -Ttext ${LOADER_ADDRESS} -o btxldr.out btxldr.o
objcopy -S -O binary btxldr.out ${.TARGET}
.endif
btxldr.o: btxldr.s
-# ${CC} ${AFLAGS} -c -o ${.TARGET} ${.CURDIR}/btxldr.s
- ${AS} ${AFLAGS} -o ${.TARGET} ${.CURDIR}/btxldr.s
+ (cd ${.CURDIR}; ${M4} ${M4FLAGS} btxldr.s ) | \
+ ${AS} ${AFLAGS} -o ${.TARGET}
CLEANFILES+= btxldr btxldr.out btxldr.o
+.include <${.CURDIR}/../../Makefile.inc>
.include <bsd.prog.mk>
diff --git a/sys/boot/pc98/btx/btxldr/btxldr.S b/sys/boot/pc98/btx/btxldr/btxldr.S
index acb4a14..74b8a6d 100644
--- a/sys/boot/pc98/btx/btxldr/btxldr.S
+++ b/sys/boot/pc98/btx/btxldr/btxldr.S
@@ -27,7 +27,7 @@
.set MEM_ESP,0x1000 # New stack pointer
.set MEM_TBL,0x5000 # BTX page tables
.set MEM_ENTRY,0x9010 # BTX entry point
- .set MEM_DATA,0x101000 # Data segment
+ .set MEM_DATA,start+0x1000 # Data segment
#
# Segment selectors.
#
@@ -43,37 +43,37 @@
#
# Screen constants.
#
-.ifdef PC98
+ifdef(`PC98',`
.set SCR_MAT,0xe1 # Mode/attribute
-.else
+',`
.set SCR_MAT,0x7 # Mode/attribute
-.endif
+')
.set SCR_COL,0x50 # Columns per row
.set SCR_ROW,0x19 # Rows per screen
#
# BIOS Data Area locations.
#
-.ifdef PC98
+ifdef(`PC98',`
.set BDA_MEM,0xa1501 # Free memory
.set BDA_POS,0xa153e # Cursor position
-.else
+',`
.set BDA_MEM,0x413 # Free memory
.set BDA_SCR,0x449 # Video mode
.set BDA_POS,0x450 # Cursor position
-.endif
+')
#
# Required by aout gas inadequacy.
#
.set SIZ_STUB,0x1a # Size of stub
#
-# We expect to be loaded by boot2 at 0x100000.
+# We expect to be loaded by boot2 at the origin defined in ./Makefile.
#
.globl start
#
# BTX program loader for ELF clients.
#
start: cld # String ops inc
-.ifdef PC98
+ifdef(`PC98',`
cli
gdcwait.1: inb $0x60,%al
testb $0x04,%al
@@ -94,58 +94,68 @@ gdcwait.2: inb $0x60,%al
shlw $1,%dx
movl $BDA_POS,%ebx
movw %dx,(%ebx)
-.endif
+')
movl $m_logo,%esi # Identify
call putstr # ourselves
movzwl BDA_MEM,%eax # Get base memory
-.ifdef PC98
+ifdef(`PC98',`
andl $0x7,%eax
incl %eax
shll $0x11,%eax # in bytes
-.else
+',`
shll $0xa,%eax # in bytes
-.endif
+')
movl %eax,%ebp # Base of user stack
+ifdef(`BTXLDR_VERBOSE',`
movl $m_mem,%esi # Display
- call dhexout # amount of
- call dputstr # base memory
+ call hexout # amount of
+ call putstr # base memory
+')
lgdt gdtdesc # Load new GDT
#
# Relocate caller's arguments.
#
+ifdef('BTXLDR_VERBOSE',`
movl $m_esp,%esi # Display
- movl %esp,%eax # caller's
- call dhexout # stack
- call dputstr # pointer
+ movl %esp,%eax # caller
+ call hexout # stack
+ call putstr # pointer
movl $m_args,%esi # Format string
leal 0x4(%esp,1),%ebx # First argument
movl $0x6,%ecx # Count
start.1: movl (%ebx),%eax # Get argument and
addl $0x4,%ebx # bump pointer
- call dhexout # Display it
+ call hexout # Display it
loop start.1 # Till done
- call dputstr # End message
+ call putstr # End message
+')
movl $0x48,%ecx # Allocate space
subl %ecx,%ebp # for bootinfo
- movl 0x18(%esp,1),%esi # Source
+ movl 0x18(%esp,1),%esi # Source: bootinfo
+ cmpl $0x0, %esi # If the bootinfo pointer
+ je start_null_bi # is null, don't copy it
movl %ebp,%edi # Destination
rep # Copy
movsb # it
movl %ebp,0x18(%esp,1) # Update pointer
+ifdef(`BTXLDR_VERBOSE',`
movl $m_rel_bi,%esi # Display
movl %ebp,%eax # bootinfo
- call dhexout # relocation
- call dputstr # message
- movl $0x18,%ecx # Allocate space
+ call hexout # relocation
+ call putstr # message
+')
+start_null_bi: movl $0x18,%ecx # Allocate space
subl %ecx,%ebp # for arguments
leal 0x4(%esp,1),%esi # Source
movl %ebp,%edi # Destination
rep # Copy
movsb # them
+ifdef(`BTXLDR_VERBOSE',`
movl $m_rel_args,%esi # Display
movl %ebp,%eax # argument
- call dhexout # relocation
- call dputstr # message
+ call hexout # relocation
+ call putstr # message
+')
#
# Set up BTX kernel.
#
@@ -174,24 +184,32 @@ start.1: movl (%ebx),%eax # Get argument and
incl %edi # BTX
shll $0x2,%edi # load
addl $MEM_TBL,%edi # address
- pushl %edi # Save
+ pushl %edi # Save load address
movzwl 0xa(%ebx),%ecx # Image size
- pushl %ecx # Save
+ifdef(`BTXLDR_VERBOSE',`
+ pushl %ecx # Save image size
+')
rep # Relocate
movsb # BTX
movl %esi,%ebx # Keep place
+ifdef(`BTXLDR_VERBOSE',`
movl $m_rel_btx,%esi # Restore
popl %eax # parameters
- call dhexout # and
+ call hexout # and
+')
popl %ebp # display
+ifdef(`BTXLDR_VERBOSE',`
movl %ebp,%eax # the
- call dhexout # relocation
- call dputstr # message
+ call hexout # relocation
+ call putstr # message
+')
addl $PAG_SIZ,%ebp # Display
+ifdef(`BTXLDR_VERBOSE',`
movl $m_base,%esi # the
movl %ebp,%eax # user
- call dhexout # base
- call dputstr # address
+ call hexout # base
+ call putstr # address
+')
#
# Set up ELF-format client program.
#
@@ -200,24 +218,29 @@ start.1: movl (%ebx),%eax # Get argument and
movl $e_fmt,%esi # Display error
call putstr # message
start.2: jmp start.2 # Hang
-start.3: movl $m_elf,%esi # Display ELF
- call dputstr # message
+start.3:
+ifdef(`BTXLDR_VERBOSE',`
+ movl $m_elf,%esi # Display ELF
+ call putstr # message
movl $m_segs,%esi # Format string
+')
movl $0x2,%edi # Segment count
movl 0x1c(%ebx),%edx # Get e_phoff
addl %ebx,%edx # To pointer
movzwl 0x2c(%ebx),%ecx # Get e_phnum
start.4: cmpl $0x1,(%edx) # Is p_type PT_LOAD?
jne start.6 # No
+ifdef(`BTXLDR_VERBOSE',`
movl 0x4(%edx),%eax # Display
- call dhexout # p_offset
+ call hexout # p_offset
movl 0x8(%edx),%eax # Display
- call dhexout # p_vaddr
+ call hexout # p_vaddr
movl 0x10(%edx),%eax # Display
- call dhexout # p_filesz
+ call hexout # p_filesz
movl 0x14(%edx),%eax # Display
- call dhexout # p_memsz
- call dputstr # End message
+ call hexout # p_memsz
+ call putstr # End message
+')
pushl %esi # Save
pushl %edi # working
pushl %ecx # registers
@@ -241,8 +264,11 @@ start.5: popl %ecx # Restore
je start.7 # If none
start.6: addl $0x20,%edx # To next entry
loop start.4 # Till done
-start.7: movl $m_done,%esi # Display done
- call dputstr # message
+start.7:
+ifdef(`BTXLDR_VERBOSE',`
+ movl $m_done,%esi # Display done
+ call putstr # message
+')
movl $start.8,%esi # Real mode stub
movl $MEM_STUB,%edi # Destination
movl $SIZ_STUB,%ecx # Size
@@ -266,10 +292,6 @@ start.9:
#
# Output message [ESI] followed by EAX in hex.
#
-dhexout:
-.ifndef BTXLDR_VERBOSE
- ret
-.endif
hexout: pushl %eax # Save
call putstr # Display message
popl %eax # Restore
@@ -295,12 +317,6 @@ hexout.2: decl %esi # Adjust for inc
#
# Output zero-terminated string [ESI] to the console.
#
-dputstr:
-.ifndef BTXLDR_VERBOSE
- ret
-.else
- jmp putstr
-.endif
putstr.0: call putchr # Output char
putstr: lodsb # Load char
testb %al,%al # End of string?
@@ -309,26 +325,22 @@ putstr: lodsb # Load char
#
# Output character AL to the console.
#
-dputchr:
-.ifndef BTXLDR_VERBOSE
- ret
-.endif
putchr: pusha # Save
xorl %ecx,%ecx # Zero for loops
movb $SCR_MAT,%ah # Mode/attribute
movl $BDA_POS,%ebx # BDA pointer
movw (%ebx),%dx # Cursor position
-.ifdef PC98
+ifdef(`PC98',`
movl $0xa0000,%edi # Regen buffer (color)
-.else
+',`
movl $0xb8000,%edi # Regen buffer (color)
cmpb %ah,BDA_SCR-BDA_POS(%ebx) # Mono mode?
jne putchr.1 # No
xorw %di,%di # Regen buffer (mono)
-.endif
+')
putchr.1: cmpb $0xa,%al # New line?
je putchr.2 # Yes
-.ifdef PC98
+ifdef(`PC98',`
movw %dx,%cx
movb %al,(%edi,%ecx,1) # Write char
addl $0x2000,%ecx
@@ -342,7 +354,7 @@ putchr.2: movw %dx,%ax
mul %dl
movw %ax,%dx
putchr.3: cmpw $SCR_COL*SCR_ROW*2,%dx
-.else
+',`
xchgl %eax,%ecx # Save char
movb $SCR_COL,%al # Columns per row
mulb %dh # * row position
@@ -357,20 +369,20 @@ putchr.3: cmpw $SCR_COL*SCR_ROW*2,%dx
putchr.2: xorb %dl,%dl # Zero column
incb %dh # Bump row
putchr.3: cmpb $SCR_ROW,%dh # Beyond screen?
-.endif
+')
jb putchr.4 # No
leal 2*SCR_COL(%edi),%esi # New top line
movw $(SCR_ROW-1)*SCR_COL/2,%cx # Words to move
rep # Scroll
movsl # screen
movb $' ',%al # Space
-.ifdef PC98
+ifdef(`PC98',`
xorb %ah,%ah
-.endif
+')
movb $SCR_COL,%cl # Columns to clear
rep # Clear
stosw # line
-.ifdef PC98
+ifdef(`PC98',`
movw $(SCR_ROW-1)*SCR_COL*2,%dx
putchr.4: movw %dx,(%ebx) # Update position
shrw $1,%dx
@@ -383,10 +395,10 @@ gdcwait.3: inb $0x60,%al
outb %al,$0x60
movb %dh,%al
outb %al,$0x60
-.else
+',`
movb $SCR_ROW-1,%dh # Bottom line
putchr.4: movw %dx,(%ebx) # Update position
-.endif
+')
popa # Restore
ret # To caller
#
@@ -429,7 +441,7 @@ gdtdesc: .word gdt.1-gdt-1 # Limit
m_logo: .asciz " \nBTX loader 1.00 "
m_vers: .asciz "BTX version is \0\n"
e_fmt: .asciz "Error: Client format not supported\n"
-#.ifdef BTXLDR_VERBOSE
+ifdef(`BTXLDR_VERBOSE',`
m_mem: .asciz "Starting in protected mode (base mem=\0)\n"
m_esp: .asciz "Arguments passed (esp=\0):\n"
m_args: .asciz"<howto="
@@ -452,7 +464,7 @@ m_segs: .asciz "text segment: offset="
.asciz " filesz="
.asciz " memsz=\0\n"
m_done: .asciz "Loading complete\n"
-#.endif
+')
#
# Uninitialized data area.
#
diff --git a/sys/boot/pc98/btx/btxldr/btxldr.s b/sys/boot/pc98/btx/btxldr/btxldr.s
index acb4a14..74b8a6d 100644
--- a/sys/boot/pc98/btx/btxldr/btxldr.s
+++ b/sys/boot/pc98/btx/btxldr/btxldr.s
@@ -27,7 +27,7 @@
.set MEM_ESP,0x1000 # New stack pointer
.set MEM_TBL,0x5000 # BTX page tables
.set MEM_ENTRY,0x9010 # BTX entry point
- .set MEM_DATA,0x101000 # Data segment
+ .set MEM_DATA,start+0x1000 # Data segment
#
# Segment selectors.
#
@@ -43,37 +43,37 @@
#
# Screen constants.
#
-.ifdef PC98
+ifdef(`PC98',`
.set SCR_MAT,0xe1 # Mode/attribute
-.else
+',`
.set SCR_MAT,0x7 # Mode/attribute
-.endif
+')
.set SCR_COL,0x50 # Columns per row
.set SCR_ROW,0x19 # Rows per screen
#
# BIOS Data Area locations.
#
-.ifdef PC98
+ifdef(`PC98',`
.set BDA_MEM,0xa1501 # Free memory
.set BDA_POS,0xa153e # Cursor position
-.else
+',`
.set BDA_MEM,0x413 # Free memory
.set BDA_SCR,0x449 # Video mode
.set BDA_POS,0x450 # Cursor position
-.endif
+')
#
# Required by aout gas inadequacy.
#
.set SIZ_STUB,0x1a # Size of stub
#
-# We expect to be loaded by boot2 at 0x100000.
+# We expect to be loaded by boot2 at the origin defined in ./Makefile.
#
.globl start
#
# BTX program loader for ELF clients.
#
start: cld # String ops inc
-.ifdef PC98
+ifdef(`PC98',`
cli
gdcwait.1: inb $0x60,%al
testb $0x04,%al
@@ -94,58 +94,68 @@ gdcwait.2: inb $0x60,%al
shlw $1,%dx
movl $BDA_POS,%ebx
movw %dx,(%ebx)
-.endif
+')
movl $m_logo,%esi # Identify
call putstr # ourselves
movzwl BDA_MEM,%eax # Get base memory
-.ifdef PC98
+ifdef(`PC98',`
andl $0x7,%eax
incl %eax
shll $0x11,%eax # in bytes
-.else
+',`
shll $0xa,%eax # in bytes
-.endif
+')
movl %eax,%ebp # Base of user stack
+ifdef(`BTXLDR_VERBOSE',`
movl $m_mem,%esi # Display
- call dhexout # amount of
- call dputstr # base memory
+ call hexout # amount of
+ call putstr # base memory
+')
lgdt gdtdesc # Load new GDT
#
# Relocate caller's arguments.
#
+ifdef('BTXLDR_VERBOSE',`
movl $m_esp,%esi # Display
- movl %esp,%eax # caller's
- call dhexout # stack
- call dputstr # pointer
+ movl %esp,%eax # caller
+ call hexout # stack
+ call putstr # pointer
movl $m_args,%esi # Format string
leal 0x4(%esp,1),%ebx # First argument
movl $0x6,%ecx # Count
start.1: movl (%ebx),%eax # Get argument and
addl $0x4,%ebx # bump pointer
- call dhexout # Display it
+ call hexout # Display it
loop start.1 # Till done
- call dputstr # End message
+ call putstr # End message
+')
movl $0x48,%ecx # Allocate space
subl %ecx,%ebp # for bootinfo
- movl 0x18(%esp,1),%esi # Source
+ movl 0x18(%esp,1),%esi # Source: bootinfo
+ cmpl $0x0, %esi # If the bootinfo pointer
+ je start_null_bi # is null, don't copy it
movl %ebp,%edi # Destination
rep # Copy
movsb # it
movl %ebp,0x18(%esp,1) # Update pointer
+ifdef(`BTXLDR_VERBOSE',`
movl $m_rel_bi,%esi # Display
movl %ebp,%eax # bootinfo
- call dhexout # relocation
- call dputstr # message
- movl $0x18,%ecx # Allocate space
+ call hexout # relocation
+ call putstr # message
+')
+start_null_bi: movl $0x18,%ecx # Allocate space
subl %ecx,%ebp # for arguments
leal 0x4(%esp,1),%esi # Source
movl %ebp,%edi # Destination
rep # Copy
movsb # them
+ifdef(`BTXLDR_VERBOSE',`
movl $m_rel_args,%esi # Display
movl %ebp,%eax # argument
- call dhexout # relocation
- call dputstr # message
+ call hexout # relocation
+ call putstr # message
+')
#
# Set up BTX kernel.
#
@@ -174,24 +184,32 @@ start.1: movl (%ebx),%eax # Get argument and
incl %edi # BTX
shll $0x2,%edi # load
addl $MEM_TBL,%edi # address
- pushl %edi # Save
+ pushl %edi # Save load address
movzwl 0xa(%ebx),%ecx # Image size
- pushl %ecx # Save
+ifdef(`BTXLDR_VERBOSE',`
+ pushl %ecx # Save image size
+')
rep # Relocate
movsb # BTX
movl %esi,%ebx # Keep place
+ifdef(`BTXLDR_VERBOSE',`
movl $m_rel_btx,%esi # Restore
popl %eax # parameters
- call dhexout # and
+ call hexout # and
+')
popl %ebp # display
+ifdef(`BTXLDR_VERBOSE',`
movl %ebp,%eax # the
- call dhexout # relocation
- call dputstr # message
+ call hexout # relocation
+ call putstr # message
+')
addl $PAG_SIZ,%ebp # Display
+ifdef(`BTXLDR_VERBOSE',`
movl $m_base,%esi # the
movl %ebp,%eax # user
- call dhexout # base
- call dputstr # address
+ call hexout # base
+ call putstr # address
+')
#
# Set up ELF-format client program.
#
@@ -200,24 +218,29 @@ start.1: movl (%ebx),%eax # Get argument and
movl $e_fmt,%esi # Display error
call putstr # message
start.2: jmp start.2 # Hang
-start.3: movl $m_elf,%esi # Display ELF
- call dputstr # message
+start.3:
+ifdef(`BTXLDR_VERBOSE',`
+ movl $m_elf,%esi # Display ELF
+ call putstr # message
movl $m_segs,%esi # Format string
+')
movl $0x2,%edi # Segment count
movl 0x1c(%ebx),%edx # Get e_phoff
addl %ebx,%edx # To pointer
movzwl 0x2c(%ebx),%ecx # Get e_phnum
start.4: cmpl $0x1,(%edx) # Is p_type PT_LOAD?
jne start.6 # No
+ifdef(`BTXLDR_VERBOSE',`
movl 0x4(%edx),%eax # Display
- call dhexout # p_offset
+ call hexout # p_offset
movl 0x8(%edx),%eax # Display
- call dhexout # p_vaddr
+ call hexout # p_vaddr
movl 0x10(%edx),%eax # Display
- call dhexout # p_filesz
+ call hexout # p_filesz
movl 0x14(%edx),%eax # Display
- call dhexout # p_memsz
- call dputstr # End message
+ call hexout # p_memsz
+ call putstr # End message
+')
pushl %esi # Save
pushl %edi # working
pushl %ecx # registers
@@ -241,8 +264,11 @@ start.5: popl %ecx # Restore
je start.7 # If none
start.6: addl $0x20,%edx # To next entry
loop start.4 # Till done
-start.7: movl $m_done,%esi # Display done
- call dputstr # message
+start.7:
+ifdef(`BTXLDR_VERBOSE',`
+ movl $m_done,%esi # Display done
+ call putstr # message
+')
movl $start.8,%esi # Real mode stub
movl $MEM_STUB,%edi # Destination
movl $SIZ_STUB,%ecx # Size
@@ -266,10 +292,6 @@ start.9:
#
# Output message [ESI] followed by EAX in hex.
#
-dhexout:
-.ifndef BTXLDR_VERBOSE
- ret
-.endif
hexout: pushl %eax # Save
call putstr # Display message
popl %eax # Restore
@@ -295,12 +317,6 @@ hexout.2: decl %esi # Adjust for inc
#
# Output zero-terminated string [ESI] to the console.
#
-dputstr:
-.ifndef BTXLDR_VERBOSE
- ret
-.else
- jmp putstr
-.endif
putstr.0: call putchr # Output char
putstr: lodsb # Load char
testb %al,%al # End of string?
@@ -309,26 +325,22 @@ putstr: lodsb # Load char
#
# Output character AL to the console.
#
-dputchr:
-.ifndef BTXLDR_VERBOSE
- ret
-.endif
putchr: pusha # Save
xorl %ecx,%ecx # Zero for loops
movb $SCR_MAT,%ah # Mode/attribute
movl $BDA_POS,%ebx # BDA pointer
movw (%ebx),%dx # Cursor position
-.ifdef PC98
+ifdef(`PC98',`
movl $0xa0000,%edi # Regen buffer (color)
-.else
+',`
movl $0xb8000,%edi # Regen buffer (color)
cmpb %ah,BDA_SCR-BDA_POS(%ebx) # Mono mode?
jne putchr.1 # No
xorw %di,%di # Regen buffer (mono)
-.endif
+')
putchr.1: cmpb $0xa,%al # New line?
je putchr.2 # Yes
-.ifdef PC98
+ifdef(`PC98',`
movw %dx,%cx
movb %al,(%edi,%ecx,1) # Write char
addl $0x2000,%ecx
@@ -342,7 +354,7 @@ putchr.2: movw %dx,%ax
mul %dl
movw %ax,%dx
putchr.3: cmpw $SCR_COL*SCR_ROW*2,%dx
-.else
+',`
xchgl %eax,%ecx # Save char
movb $SCR_COL,%al # Columns per row
mulb %dh # * row position
@@ -357,20 +369,20 @@ putchr.3: cmpw $SCR_COL*SCR_ROW*2,%dx
putchr.2: xorb %dl,%dl # Zero column
incb %dh # Bump row
putchr.3: cmpb $SCR_ROW,%dh # Beyond screen?
-.endif
+')
jb putchr.4 # No
leal 2*SCR_COL(%edi),%esi # New top line
movw $(SCR_ROW-1)*SCR_COL/2,%cx # Words to move
rep # Scroll
movsl # screen
movb $' ',%al # Space
-.ifdef PC98
+ifdef(`PC98',`
xorb %ah,%ah
-.endif
+')
movb $SCR_COL,%cl # Columns to clear
rep # Clear
stosw # line
-.ifdef PC98
+ifdef(`PC98',`
movw $(SCR_ROW-1)*SCR_COL*2,%dx
putchr.4: movw %dx,(%ebx) # Update position
shrw $1,%dx
@@ -383,10 +395,10 @@ gdcwait.3: inb $0x60,%al
outb %al,$0x60
movb %dh,%al
outb %al,$0x60
-.else
+',`
movb $SCR_ROW-1,%dh # Bottom line
putchr.4: movw %dx,(%ebx) # Update position
-.endif
+')
popa # Restore
ret # To caller
#
@@ -429,7 +441,7 @@ gdtdesc: .word gdt.1-gdt-1 # Limit
m_logo: .asciz " \nBTX loader 1.00 "
m_vers: .asciz "BTX version is \0\n"
e_fmt: .asciz "Error: Client format not supported\n"
-#.ifdef BTXLDR_VERBOSE
+ifdef(`BTXLDR_VERBOSE',`
m_mem: .asciz "Starting in protected mode (base mem=\0)\n"
m_esp: .asciz "Arguments passed (esp=\0):\n"
m_args: .asciz"<howto="
@@ -452,7 +464,7 @@ m_segs: .asciz "text segment: offset="
.asciz " filesz="
.asciz " memsz=\0\n"
m_done: .asciz "Loading complete\n"
-#.endif
+')
#
# Uninitialized data area.
#
OpenPOWER on IntegriCloud