summaryrefslogtreecommitdiffstats
path: root/sys/boot/i386/boot0
diff options
context:
space:
mode:
authorjhb <jhb@FreeBSD.org>2000-05-23 12:18:49 +0000
committerjhb <jhb@FreeBSD.org>2000-05-23 12:18:49 +0000
commit5053ee0d6cc0d8390a4e29ba7b7de827c6cce053 (patch)
treed278a658df406d492fef8fecec7e6e2544fb3827 /sys/boot/i386/boot0
parentf223e71d8fb7d790ab6bd06f4381f12e2e7711d1 (diff)
downloadFreeBSD-src-5053ee0d6cc0d8390a4e29ba7b7de827c6cce053.zip
FreeBSD-src-5053ee0d6cc0d8390a4e29ba7b7de827c6cce053.tar.gz
Clean up all of the 16-bit assembly code in the x86 bootstrap to work
with the new binutils. Now that we have a decent assembler, all the old m4 macros are no longer needed. Instead, straight assembly can be used since as(1) now understands 16-bit addressing, branches, etc. Also, several bugs have been fixed in as(1), allowing boot0.s to be further cleaned up.
Diffstat (limited to 'sys/boot/i386/boot0')
-rw-r--r--sys/boot/i386/boot0/Makefile6
-rw-r--r--sys/boot/i386/boot0/boot0.m477
-rw-r--r--sys/boot/i386/boot0/boot0.s157
3 files changed, 44 insertions, 196 deletions
diff --git a/sys/boot/i386/boot0/Makefile b/sys/boot/i386/boot0/Makefile
index 5ccddf2..015a5e8 100644
--- a/sys/boot/i386/boot0/Makefile
+++ b/sys/boot/i386/boot0/Makefile
@@ -22,9 +22,9 @@ boot0: boot0.o
objcopy -S -O binary boot0.out ${.TARGET}
.endif
-boot0.o: boot0.m4 boot0.s
- (cd ${.CURDIR}; ${M4} -DFLAGS=${B0FLAGS} -DTICKS=${B0TICKS} \
- boot0.m4 boot0.s) | ${AS} ${AFLAGS} -o ${.TARGET}
+boot0.o: boot0.s
+ ${AS} ${AFLAGS} --defsym FLAGS=${B0FLAGS} --defsym TICKS=${B0TICKS} \
+ ${.IMPSRC} -o ${.TARGET}
CLEANFILES+= boot0.out boot0.o
diff --git a/sys/boot/i386/boot0/boot0.m4 b/sys/boot/i386/boot0/boot0.m4
deleted file mode 100644
index 7515d58..0000000
--- a/sys/boot/i386/boot0/boot0.m4
+++ /dev/null
@@ -1,77 +0,0 @@
-#
-# Copyright (c) 1998 Robert Nordier
-# All rights reserved.
-#
-# Redistribution and use in source and binary forms are freely
-# permitted provided that the above copyright notice and this
-# paragraph and the following disclaimer are duplicated in all
-# such forms.
-#
-# This software is provided "AS IS" and without any express or
-# implied warranties, including, without limitation, the implied
-# warranties of merchantability and fitness for a particular
-# purpose.
-#
-
-# $FreeBSD$
-
-define(_al,0x0)dnl
-define(_cl,0x1)dnl
-define(_dl,0x2)dnl
-define(_bl,0x3)dnl
-define(_ah,0x4)dnl
-define(_ch,0x5)dnl
-define(_dh,0x6)dnl
-define(_bh,0x7)dnl
-
-define(_ax,0x0)dnl
-define(_cx,0x1)dnl
-define(_dx,0x2)dnl
-define(_bx,0x3)dnl
-define(_sp,0x4)dnl
-define(_bp,0x5)dnl
-define(_si,0x6)dnl
-define(_di,0x7)dnl
-
-define(_es,0x0)dnl
-define(_cs,0x1)dnl
-define(_ss,0x2)dnl
-define(_ds,0x3)dnl
-define(_fs,0x4)dnl
-define(_gs,0x5)dnl
-
-define(_bx_si,0x0)dnl
-define(_bx_di,0x1)dnl
-define(_bp_si,0x2)dnl
-define(_bp_di,0x3)dnl
-define(_si_,0x4)dnl
-define(_di_,0x5)dnl
-define(_bp_,0x6)dnl
-define(_bx_,0x7)dnl
-
-define(o16,`.byte 0x66')dnl
-
-define(addw1r,`.byte 0x3; .byte 0x40 | ($3 << 0x3) | $2; .byte $1')dnl
-define(addwia,`.byte 0x5; .word $1')dnl
-define(btwr1,`.word 0xa30f; .byte 0x40 | ($1 << 0x3) | $3; .byte $2')dnl
-define(btswr1,`.word 0xab0f; .byte 0x40 | ($1 << 0x3) | $3; .byte $2')dnl
-define(cmpbmr,`.byte 0x3a; .byte 0x6 | ($2 << 0x3); .word $1')dnl
-define(cmpw1r,`.byte 0x3b; .byte 0x40 | ($3 << 0x3) | $2; .byte $1')dnl
-define(cmpwi2,`.byte 0x81; .byte 0xb8 | $3; .word $2; .word $1')dnl
-define(addwir,`.byte 0x83; .byte 0xc0 | $2; .byte $1')dnl
-define(movbr0,`.byte 0x88; .byte ($1 << 0x3) | $2')dnl
-define(movbr1,`.byte 0x88; .byte 0x40 | ($1 << 0x3) | $3; .byte $2')dnl
-define(movwr1,`.byte 0x89; .byte 0x40 | ($1 << 0x3) | $3; .byte $2')dnl
-define(movb0r,`.byte 0x8a; .byte ($2 << 0x3) | $1')dnl
-define(addb0r,`.byte 0x2; .byte ($2 << 0x3) | $1')dnl
-define(movb1r,`.byte 0x8a; .byte 0x40 | ($3 << 0x3) | $2; .byte $1')dnl
-define(movw1r,`.byte 0x8b; .byte 0x40 | ($3 << 0x3) | $2; .byte $1')dnl
-define(movws1,`.byte 0x8c; .byte 0x40 | ($1 << 0x3) | $3; .byte $2')dnl
-define(movwir,`.byte 0xb8 | $2; .word $1')dnl
-define(movbi0,`.byte 0xc6; .byte $2; .byte $1')dnl
-define(callwi,`.byte 0xe8; .word $1 - . - 0x2')dnl
-define(jmpnwi,`.byte 0xe9; .word $1 - . - 0x2')dnl
-define(tstbi1,`.byte 0xf6; .byte 0x40 | $3; .byte $2; .byte $1')dnl
-define(incb1,`.byte 0xfe; .byte 0x40 | $2; .byte $1')dnl
-define(pushw1,`.byte 0xff; .byte 0x70 | $2; .byte $1')dnl
-define(retn,`.byte 0xc3')dnl
diff --git a/sys/boot/i386/boot0/boot0.s b/sys/boot/i386/boot0/boot0.s
index f7a3ec2..4d186ac 100644
--- a/sys/boot/i386/boot0/boot0.s
+++ b/sys/boot/i386/boot0/boot0.s
@@ -79,32 +79,23 @@ start: cld # String ops inc
#
# Relocate to the new copy of the code.
#
- incb1(-0xe,_di_) # Sector number
- /* incb $-0xe(%di) */
- jmpnwi(main-LOAD+ORIGIN) # To relocated code
- /* jmp main-LOAD+ORIGIN */
+ incb -0xe(%di) # Sector number
+ jmp main-LOAD+ORIGIN # To relocated code
#
# Check what flags were loaded with us, specifically, Use a predefined Drive.
# If what the bios gives us is bad, use the '0' in the block instead, as well.
#
-main: tstbi1(0x20,_FLAGS,_bp_) # Set number drive?
- /* testb $(0x20+_FLAGS)(%bp) */
- .code32
+main: testb $0x20,_FLAGS(%bp) # Set number drive?
jnz main.1 # Yes
- .code16
testb %dl,%dl # Drive number valid?
- .code32
js main.2 # Possibly (0x80 set)
- .code16
-main.1: movb1r(_SETDRV,_bp_,_dl) # Drive number to use
- /* movb $_SETDRV(%bp),%dl */
+main.1: movb _SETDRV(%bp),%dl # Drive number to use
#
# Whatever we decided to use, now store it into the fake
# partition entry that lives in the data space above us.
#
-main.2: movbr1(_dl,_FAKE,_bp_) # Save drive number
- /* movb %dl,$_FAKE(%bp) */
- callwi(putn) # To new line
+main.2: movb %dl,_FAKE(%bp) # Save drive number
+ callw putn # To new line
pushw %dx # Save drive number
#
# Start out with a pointer to the 4th byte of the first table entry
@@ -119,51 +110,39 @@ main.2: movbr1(_dl,_FAKE,_bp_) # Save drive number
# Loop around on the partition table, printing values until we
# pass a 256 byte boundary. The end of loop test is at main.5.
#
-main.3: movbr1(_ch,-0x4,_bx_) # Zero active flag (ch == 0)
- /* movb %ch,$-0x4(%bx) */
- btwr1(_dx,_FLAGS,_bp_) # Entry enabled?
- /* bt %dx,$_FLAGS(%bp) */
- .code32
+main.3: movb %ch,-0x4(%bx) # Zero active flag (ch == 0)
+ btw %dx,_FLAGS(%bp) # Entry enabled?
jnc main.5 # No
- .code16
#
# If any of the entries in the table are
# the same as the 'type' in the slice table entry,
# then this is an empty or non bootable partition. Skip it.
#
- movb0r(_bx_,_al) # Load type
- /* movb (%bx),%al */
+ movb (%bx),%al # Load type
movw $tables,%di # Lookup tables
movb $TBL0SZ,%cl # Number of entries
repne # Exclude
scasb # partition?
- .code32
je main.5 # Yes
- .code16
#
# Now scan the table of known types
#
movb $TBL1SZ,%cl # Number of entries
repne # Known
scasb # type?
- .code32
jne main.4 # No
- .code16
#
# If it matches get the matching element in the
# next array. if it doesn't, we are already
# pointing at its first element which points to a "?".
#
addw $TBL1SZ,%di # Adjust
-main.4: movb0r(_di_,_cl) # Partition
- /* movb (%di),%cl */
+main.4: movb (%di),%cl # Partition
addw %cx,%di # description
- callwi(putx) # Display it
+ callw putx # Display it
main.5: incw %dx # Next item
addb $0x10,%bl # Next entry
- .code32
jnc main.3 # Till done
- .code16
#
# Passed a 256 byte boundary..
# table is finished.
@@ -172,16 +151,12 @@ main.5: incw %dx # Next item
popw %ax # Drive number
subb $0x80-0x1,%al # Does next
cmpb NHRDRV,%al # drive exist? (from BIOS?)
- .code32
jb main.6 # Yes
- .code16
# If not then if there is only one drive,
# Don't display drive as an option.
#
decw %ax # Already drive 0?
- .code32
jz main.7 # Yes
- .code16
# If it was illegal or we cycled through them,
# then go back to drive 0.
#
@@ -194,48 +169,38 @@ main.5: incw %dx # Next item
# end of string.
#
main.6: addb $'0'|0x80,%al # Save next
- movbr1(_al,_NXTDRV,_bp_) # drive number
- /* movb %al,$NXTDRV(%bp) */
+ movb %al,_NXTDRV(%bp) # drive number
movw $drive,%di # Display
- callwi(putx) # item
+ callw putx # item
#
# Now that we've printed the drive (if we needed to), display a prompt.
# Get ready for the input byt noting the time.
#
main.7: movw $prompt,%si # Display
- callwi(putstr) # prompt
- movb1r(_OPT,_bp_,_dl) # Display
- /* movb $_OPT(%bp),%dl */
+ callw putstr # prompt
+ movb _OPT(%bp),%dl # Display
decw %si # default
- callwi(putkey) # key
+ callw putkey # key
xorb %ah,%ah # BIOS: Get
int $0x1a # system time
movw %dx,%di # Ticks when
- addw1r(_TICKS,_bp_,_di) # timeout
- /* addw $_TICKS(%bp),%di */
+ addw _TICKS(%bp),%di # timeout
#
# Busy loop, looking for keystrokes but
# keeping one eye on the time.
#
main.8: movb $0x1,%ah # BIOS: Check
int $0x16 # for keypress
- .code32
jnz main.11 # Have one
- .code16
xorb %ah,%ah # BIOS: Get
int $0x1a # system time
cmpw %di,%dx # Timeout?
- .code32
jb main.8 # No
- .code16
#
# If timed out or defaulting, come here.
#
-main.9: movb1r(_OPT,_bp_,_al) # Load default
- /* movb $_OPT(%bp),%al */
- .code32
+main.9: movb _OPT(%bp),%al # Load default
jmp main.12 # Join common code
- .code16
#
# User's last try was bad, beep in displeasure.
# Since nothing was printed, just continue on as if the user
@@ -244,7 +209,7 @@ main.9: movb1r(_OPT,_bp_,_al) # Load default
# occurs or the user hits a good key.
#
main.10: movb $0x7,%al # Signal
- callwi(putchr) # error
+ callw putchr # error
#
# Get the keystroke.
#
@@ -255,18 +220,14 @@ main.11: xorb %ah,%ah # BIOS: Get
# If it's CR act as if timed out.
#
cmpb $KEY_ENTER,%al # Enter pressed?
- .code32
je main.9 # Yes
- .code16
#
# Otherwise check if legal
# If not ask again.
#
subb $KEY_F1,%al # Less F1 scan code
cmpb $0x4,%al # F1..F5?
- .code32
ja main.10 # No
- .code16
#
# We have a selection.
# but if it's a bad selection go back to complain.
@@ -274,54 +235,40 @@ main.11: xorb %ah,%ah # BIOS: Get
# Anything not printed is not an option.
#
main.12: cbtw # Option
- btwr1(_ax,_MNUOPT,_bp_) # enabled?
- /* btw %ax,$_MNUOPT(%bp) */
- .code32
+ btw %ax,_MNUOPT(%bp) # enabled?
jnc main.10 # No
- .code16
#
# Save the info in the original tables
# for rewriting to the disk.
#
- movbr1(_al,_OPT,_bp_) # Save option
- /* movb %al,$OPT(%bp) */
+ movb %al,_OPT(%bp) # Save option
movw $FAKE,%si # Partition for write
- movb0r(_si_,_dl) # Drive number
- /* movb (%si),%dl */
+ movb (%si),%dl # Drive number
movw %si,%bx # Partition for read
cmpb $0x4,%al # F5 pressed?
pushf # Save
- .code32
je main.13 # Yes
- .code16
shlb $0x4,%al # Point to
addw $partbl,%ax # selected
xchgw %bx,%ax # partition
- movbi0(0x80,_bx_) # Flag active
- /* movb $0x80,(%bx) */
+ movb $0x80,(%bx) # Flag active
#
# If not asked to do a write-back (flags 0x40) don't do one.
#
main.13: pushw %bx # Save
- tstbi1(0x40,_FLAGS,_bp_) # No updates?
- /* testb $0x40,$_FLAGS(%bp) */
- .code32
+ testb $0x40,_FLAGS(%bp) # No updates?
jnz main.14 # Yes
- .code16
movw $start,%bx # Data to write
movb $0x3,%ah # Write sector
- callwi(intx13) # to disk
+ callw intx13 # to disk
main.14: popw %si # Restore
popf # Restore
#
# If going to next drive, replace drive with selected one.
# Remember to un-ascii it. Hey 0x80 is already set, cool!
#
- .code32
jne main.15 # If not F5
- .code16
- movb1r(_NXTDRV,_bp_,_dl) # Next drive
- /* movb $_NXTDRV(%bp),%dl */
+ movb _NXTDRV(%bp),%dl # Next drive
subb $'0',%dl # number
#
# load selected bootsector to the LOAD location in RAM.
@@ -331,58 +278,43 @@ main.14: popw %si # Restore
#
main.15: movw $LOAD,%bx # Address for read
movb $0x2,%ah # Read sector
- callwi(intx13) # from disk
- .code32
+ callw intx13 # from disk
jc main.10 # If error
- .code16
- cmpwi2(MAGIC,0x1fe,_bx_) # Bootable?
- /* cmpw $MAGIC,$0x1fe(%bx) */
- .code32
+ cmpw $MAGIC,0x1fe(%bx) # Bootable?
jne main.10 # No
- .code16
pushw %si # Save
movw $crlf,%si # Leave some
- callwi(puts) # space
+ callw puts # space
popw %si # Restore
- .code32
- jmp *%ebx # Invoke bootstrap
- /* jmp *%bx */
- .code16
+ jmp *%bx # Invoke bootstrap
#
# Display routines
#
putkey: movb $'F',%al # Display
- callwi(putchr) # 'F'
+ callw putchr # 'F'
movb $'1',%al # Prepare
addb %dl,%al # digit
- .code32
jmp putstr.1 # Display the rest
- .code16
#
# Display the option and note that it is a valid option.
# That last point is a bit tricky..
#
-putx: btswr1(_dx,_MNUOPT,_bp_) # Enable menu option
- /* btsw %dx,$_MNUOPT(%bp) */
+putx: btsw %dx,_MNUOPT(%bp) # Enable menu option
movw $item,%si # Display
- callwi(putkey) # key
+ callw putkey # key
movw %di,%si # Display the rest
-puts: callwi(putstr) # Display string
+puts: callw putstr # Display string
putn: movw $crlf,%si # To next line
putstr: lodsb # Get byte
testb $0x80,%al # End of string?
- .code32
jnz putstr.2 # Yes
- .code16
-putstr.1: callwi(putchr) # Display char
- .code32
+putstr.1: callw putchr # Display char
jmp putstr # Continue
- .code16
putstr.2: andb $~0x80,%al # Clear MSB
putchr: pushw %bx # Save
@@ -390,26 +322,19 @@ putchr: pushw %bx # Save
movb $0xe,%ah # BIOS: Display
int $0x10 # character
popw %bx # Restore
- retn # To caller
+ retw # To caller
# One-sector disk I/O routine
-intx13: movb1r(0x1,_si_,_dh) # Load head
- /* movb $0x1(%si),%dh */
- movw1r(0x2,_si_,_cx) # Load cylinder:sector
- /* movw $0x2(%si),%cx */
+intx13: movb 0x1(%si),%dh # Load head
+ movw 0x2(%si),%cx # Load cylinder:sector
movb $0x1,%al # Sector count
pushw %si # Save
movw %sp,%di # Save
- tstbi1(0x80,_FLAGS,_bp_) # Use packet interface?
- /* testb $0x80,$_FLAGS(%bp) */
- .code32
+ testb $0x80,_FLAGS(%bp) # Use packet interface?
jz intx13.1 # No
- .code16
pushl $0x0 # Set the
- o16 # LBA
- pushw1(0x8,_si_) # address
- /* pushl $0x8(%si) */
+ pushl 0x8(%si) # LBA address
pushw %es # Set the transfer
pushw %bx # buffer address
push $0x1 # Block count
@@ -420,7 +345,7 @@ intx13: movb1r(0x1,_si_,_dh) # Load head
intx13.1: int $0x13 # BIOS: Disk I/O
movw %di,%sp # Restore
popw %si # Restore
- retn # To caller
+ retw # To caller
# Menu strings
OpenPOWER on IntegriCloud