Consolidate most constant memory addresses in bootasm.h part1/2. Convert
authorMatthew Dillon <dillon@dragonflybsd.org>
Sun, 18 Jul 2004 23:40:09 +0000 (23:40 +0000)
committerMatthew Dillon <dillon@dragonflybsd.org>
Sun, 18 Jul 2004 23:40:09 +0000 (23:40 +0000)
all .s files into .S files and replace any remaining M4 use with standard
preprocessor directives.

Files generated should be the same as before this commit.

30 files changed:
sys/boot/i386/boot0/Makefile
sys/boot/i386/boot0/boot0.S
sys/boot/i386/boot0/boot0.s [deleted file]
sys/boot/i386/boot2/Makefile
sys/boot/i386/boot2/boot1.S
sys/boot/i386/boot2/boot1.s [deleted file]
sys/boot/i386/boot2/boot2.c
sys/boot/i386/boot2/sio.S
sys/boot/i386/boot2/sio.s [deleted file]
sys/boot/i386/bootasm.h [new file with mode: 0644]
sys/boot/i386/btx/btx/Makefile
sys/boot/i386/btx/btx/btx.S
sys/boot/i386/btx/btx/btx.s [deleted file]
sys/boot/i386/cdboot/cdboot.S
sys/boot/i386/cdboot/cdboot.s [deleted file]
sys/boot/i386/pxeldr/Makefile
sys/boot/i386/pxeldr/pxeldr.S
sys/boot/i386/pxeldr/pxeldr.s [deleted file]
sys/boot/pc32/boot0/Makefile
sys/boot/pc32/boot0/boot0.S
sys/boot/pc32/boot2/Makefile
sys/boot/pc32/boot2/boot1.S
sys/boot/pc32/boot2/boot2.c
sys/boot/pc32/boot2/sio.S
sys/boot/pc32/bootasm.h [new file with mode: 0644]
sys/boot/pc32/btx/btx/Makefile
sys/boot/pc32/btx/btx/btx.S
sys/boot/pc32/cdboot/cdboot.S
sys/boot/pc32/pxeldr/Makefile
sys/boot/pc32/pxeldr/pxeldr.S

index e6eea5f..c5a098a 100644 (file)
@@ -1,5 +1,5 @@
 # $FreeBSD: src/sys/boot/i386/boot0/Makefile,v 1.17 2002/09/17 01:48:54 peter Exp $
-# $DragonFly: src/sys/boot/i386/boot0/Attic/Makefile,v 1.3 2003/11/10 06:08:34 dillon Exp $
+# $DragonFly: src/sys/boot/i386/boot0/Attic/Makefile,v 1.4 2004/07/18 23:39:59 dillon Exp $
 
 PROG=          boot0
 NOMAN=
@@ -7,8 +7,6 @@ STRIP=
 BINDIR?=       /boot
 BINMODE=       444
 
-M4?=   m4
-
 # The default set of flags compiled into boot0.  This enables update (writing
 # the modified boot0 back to disk after running so that the selection made is
 # saved), packet mode (detect and use the BIOS EDD extensions if we try to
@@ -28,9 +26,9 @@ boot0: boot0.o
        ${LD} -N -e start -Ttext ${BOOT_BOOT0_ORG} -o boot0.out boot0.o
        objcopy -S -O binary boot0.out ${.TARGET}
 
-boot0.o: boot0.s
-       ${AS} ${AFLAGS} --defsym FLAGS=${BOOT_BOOT0_FLAGS} \
-               --defsym TICKS=${BOOT_BOOT0_TICKS} ${.IMPSRC} -o ${.TARGET}
+boot0.o: boot0.S
+       ${CC} -c -DFLAGS=${BOOT_BOOT0_FLAGS} -DTICKS=${BOOT_BOOT0_TICKS} \
+               ${AFLAGS} ${.IMPSRC} -o ${.TARGET}
 
 CLEANFILES+= boot0.out boot0.o
 
index df2cb71..6d3cb7f 100644 (file)
@@ -1,28 +1,27 @@
-#
-# 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: src/sys/boot/i386/boot0/boot0.s,v 1.26 2003/06/01 20:41:04 obrien Exp $
-# $DragonFly: src/sys/boot/i386/boot0/Attic/boot0.S,v 1.4 2004/07/18 18:26:33 dillon Exp $
-
-# A 512-byte boot manager.
-
-               .set NHRDRV,0x475               # Number of hard drives
-               .set ORIGIN,0x600               # Execution address
-               .set FAKE,0x800                 # Partition entry
-               .set LOAD,0x7c00                # Load address
+/*
+ * 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: src/sys/boot/i386/boot0/boot0.s,v 1.26 2003/06/01 20:41:04 obrien Exp $
+ * $DragonFly: src/sys/boot/i386/boot0/Attic/boot0.S,v 1.5 2004/07/18 23:39:59 dillon Exp $
+ */
 
+#include "../bootasm.h"
+
+               /*
+                * A 512-byte boot manager.
+                */
                .set PRT_OFF,0x1be              # Partition table
 
                .set TBL0SZ,0x3                 # Table 0 size
                .set KEY_F1,0x3b                # F1 key scan code
                .set KEY_1,0x02                 # #1 key scan code
 
-#
-# Addresses in the sector of embedded data values.
-# Accessed with negative offsets from the end of the relocated sector (%ebp).
-#
+               /*
+                * Addresses in the sector of embedded data values.  Accessed
+                * with negative offsets from the end of the relocated sector
+                * (%ebp).
+                */
                .set _NXTDRV,-0x48              # Next drive
                .set _OPT,-0x47                 # Default option
                .set _SETDRV,-0x46              # Drive to force
                .globl start                    # Entry point
                .code16                         # This runs in real mode
 
-#
-# Initialise segments and registers to known values.
-# segments start at 0.
-# The stack is immediately below the address we were loaded to.
-#
+               /*
+                * Initialise segments and registers to known values.  
+                * segments start at 0.  The stack is immediately below the
+                * address we were loaded to.
+                */
 start:         cld                             # String ops inc
                xorw %ax,%ax                    # Zero
                movw %ax,%es                    # Address
@@ -62,83 +62,95 @@ start:              cld                             # String ops inc
                movw %ax,%ss                    # Set up
                movw $LOAD,%sp                  #  stack
        
-#
-# Copy this code to the address it was linked for
-#
+               /*
+                * Copy this code to the address it was linked for
+                */
                movw %sp,%si                    # Source
                movw $start,%di                 # Destination
                movw $0x100,%cx                 # Word count
                rep                             # Relocate
                movsw                           #  code
-#
-# Set address for variable space beyond code, and clear it.
-# Notice that this is also used to point to the values embedded in the block,
-# by using negative offsets.
-#
+
+               /*
+                * Set address for variable space beyond code, and clear it.
+                * Notice that this is also used to point to the values 
+                * embedded in the block, by using negative offsets.
+                */
                movw %di,%bp                    # Address variables
                movb $0x8,%cl                   # Words to clear
                rep                             # Zero
                stosw                           #  them
-#
-# Relocate to the new copy of the code.
-#
+
+               /*
+                * Relocate to the new copy of the code.
+                */
                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.
-#
+               jmp main-LOAD+BOOT0_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:          testb $0x20,_FLAGS(%bp)         # Set number drive?
                jnz main.1                      # Yes
                testb %dl,%dl                   # Drive number valid?
                js main.2                       # Possibly (0x80 set)
 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.
-#
+
+               /*
+                * Whatever we decided to use, now store it into the fake
+                * partition entry that lives in the data space above us.
+                */
 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
-# so that after 4 iterations it's beyond the end of the sector.
-# and beyond a 256 byte boundary and has overflowed 8 bits (see next comment).
-# (remember that the table starts 2 bytes earlier than you would expect
-# as the bootable flag is after it in the block)
-#
+
+               /*
+                * Start out with a pointer to the 4th byte of the first
+                * table entry so that after 4 iterations it's beyond the
+                * end of the sector.  and beyond a 256 byte boundary and
+                * has overflowed 8 bits (see next comment).  (remember
+                * that the table starts 2 bytes earlier than you would
+                * expect as the bootable flag is after it in the block)
+                */
                movw $(partbl+0x4),%bx          # Partition table (+4)
                xorw %dx,%dx                    # Item 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.
-#
+
+               /*
+                * 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:        movb %ch,-0x4(%bx)              # Zero active flag (ch == 0)
                btw %dx,_FLAGS(%bp)             # Entry enabled?
                jnc main.5                      # No
-#
-# 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.
-#
+
+               /*
+                * 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.
+                */
                movb (%bx),%al                  # Load type
                movw $tables,%di                # Lookup tables
                movb $TBL0SZ,%cl                # Number of entries
                repne                           # Exclude
                scasb                           #  partition?
                je main.5                       # Yes
-#
-# Now scan the table of known types
-#
+
+               /*
+                * Now scan the table of known types
+                */
                movb $TBL1SZ,%cl                # Number of entries
                repne                           # Known
                scasb                           #  type?
                jne main.4                      # No
-#
-# 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 "?".
-#
+
+               /*
+                * 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:        movb (%di),%cl                  # Partition
                addw %cx,%di                    #  description
@@ -146,39 +158,47 @@ main.4:   movb (%di),%cl                  # Partition
 main.5:        incw %dx                        # Next item 
                addb $0x10,%bl                  # Next entry
                jnc main.3                      # Till done
-#
-# Passed a 256 byte boundary..
-# table is finished.
-# Add one to the drive number and check it is valid, 
-#
+
+               /*
+                * Passed a 256 byte boundary..
+                * table is finished.
+                * Add one to the drive number and check it is valid, 
+                */
                popw %ax                        # Drive number
                subb $0x80-0x1,%al              # Does next
                cmpb NHRDRV,%al                 #  drive exist? (from BIOS?)
                jb main.6                       # Yes
-# If not then if there is only one drive,
-# Don't display drive as an option.
-#
+
+               /*
+                * If not then if there is only one drive,
+                * Don't display drive as an option.
+                */
                decw %ax                        # Already drive 0?
                jz main.7                       # Yes
-# If it was illegal or we cycled through them,
-# then go back to drive 0.
-#
+
+               /*
+                * If it was illegal or we cycled through them,
+                * then go back to drive 0.
+                */
                xorb %al,%al                    # Drive 0
-#
-# Whatever drive we selected, make it an ascii digit and save it back
-# to the "next drive" location in the loaded block in case we
-# want to save it for next time.
-# This also is part of the printed drive string so add 0x80 to indicate
-# end of string.
-#
+
+               /*
+                * Whatever drive we selected, make it an ascii digit and
+                * save it back to the "next drive" location in the loaded
+                * block in case we want to save it for next time.  This also
+                * is part of the printed drive string so add 0x80 to indicate
+                * end of string.
+                */
 main.6:        addb $'0'|0x80,%al              # Save next
                movb %al,_NXTDRV(%bp)           #  drive number
                movw $drive,%di                 # Display
                callw putx                      #  item
-#
-# Now that we've printed the drive (if we needed to), display a prompt.
-# Get ready for the input by noting the time.
-#
+
+               /*
+                * Now that we've printed the drive (if we needed to), 
+                * display a prompt.  Get ready for the input by noting the
+                * time.
+                */
 main.7:        movw $prompt,%si                # Display
                callw putstr                    #  prompt
                movb _OPT(%bp),%dl              # Display
@@ -188,10 +208,11 @@ main.7:   movw $prompt,%si                # Display
                int $0x1a                       #  system time
                movw %dx,%di                    # Ticks when
                addw _TICKS(%bp),%di            #  timeout
-# 
-# Busy loop, looking for keystrokes but
-# keeping one eye on the time.
-#
+
+               /* 
+                * Busy loop, looking for keystrokes but
+                * keeping one eye on the time.
+                */
 main.8:        movb $0x1,%ah                   # BIOS: Check
                int $0x16                       #  for keypress
                jnz main.11                     # Have one
@@ -199,54 +220,61 @@ main.8:   movb $0x1,%ah                   # BIOS: Check
                int $0x1a                       #  system time
                cmpw %di,%dx                    # Timeout?
                jb main.8                       # No
-#
-# If timed out or defaulting, come here.
-#
+
+               /*
+                * If timed out or defaulting, come here.
+                */
 main.9:        movb _OPT(%bp),%al              # Load default
                jmp main.12                     # Join common code
-#
-# User's last try was bad, beep in displeasure.
-# Since nothing was printed, just continue on as if the user
-# hadn't done anything. This gives the effect of the user getting a beep 
-# for all bad keystrokes but no action until either the timeout
-# occurs or the user hits a good key.
-#
+
+               /*
+                * User's last try was bad, beep in displeasure.
+                * Since nothing was printed, just continue on as if the
+                * user hadn't done anything. This gives the effect of the
+                * user getting a beep for all bad keystrokes but no action
+                * until either the timeout occurs or the user hits a good
+                * key.
+                */
 main.10:       movb $0x7,%al                   # Signal
                callw putchr                    #  error
-#
-# Get the keystroke.
-#
+
+               /*
+                * Get the keystroke.
+                */
 main.11:       xorb %ah,%ah                    # BIOS: Get
                int $0x16                       #  keypress
                movb %ah,%al                    # Scan code
-#
-# If it's CR act as if timed out.
-#
+
+               /*
+                * If it's CR act as if timed out.
+                */
                cmpb $KEY_ENTER,%al             # Enter pressed?
                je main.9                       # Yes
-#
-# Otherwise check if legal
-# If not ask again.
-#
+
+               /*
+                * Otherwise check if legal
+                * If not ask again.
+                */
                subb $KEY_F1,%al                # Less F1 scan code
                cmpb $0x4,%al                   # F1..F5?
                jna main.12                     # Yes
                subb $(KEY_1 - KEY_F1),%al      # Less #1 scan code
                cmpb $0x4,%al                   # #1..#5?
                ja main.10                      # No
-#
-# We have a selection.
-# but if it's a bad selection go back to complain.
-# The bits in MNUOPT were set when the options were printed.
-# Anything not printed is not an option.
-#
+
+               /*
+                * We have a selection.  But if it's a bad selection go back
+                * to complain.  The bits in MNUOPT were set when the options
+                * were printed.  Anything not printed is not an option.
+                */
 main.12:       cbtw                            # Option
                btw %ax,_MNUOPT(%bp)            #  enabled?
                jnc main.10                     # No
-#
-# Save the info in the original tables
-# for rewriting to the disk.
-#
+
+               /*
+                * Save the info in the original tables
+                * for rewriting to the disk.
+                */
                movb %al,_OPT(%bp)              # Save option
                movw $FAKE,%si                  # Partition for write
                movb (%si),%dl                  # Drive number
@@ -258,9 +286,10 @@ main.12:   cbtw                            # Option
                addw $partbl,%ax                #  selected
                xchgw %bx,%ax                   #  partition
                movb $0x80,(%bx)                # Flag active
-#
-# If not asked to do a write-back (flags 0x40) don't do one.
-#
+
+               /*
+                * If not asked to do a write-back (flags 0x40) don't do one.
+                */
 main.13:       pushw %bx                       # Save
                testb $0x40,_FLAGS(%bp)         # No updates?
                jnz main.14                     # Yes
@@ -269,19 +298,21 @@ main.13:  pushw %bx                       # Save
                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!
-#
+
+               /*
+                * If going to next drive, replace drive with selected one.
+                * Remember to un-ascii it. Hey 0x80 is already set, cool!
+                */
                jne main.15                     # If not F5
                movb _NXTDRV(%bp),%dl           # Next drive
                subb $'0',%dl                   #  number
-# 
-# load  selected bootsector to the LOAD location in RAM.
-# If it fails to read or isn't marked bootable, treat it
-# as a bad selection.
-# XXX what does %si carry?
-#
+
+               /* 
+                * load  selected bootsector to the LOAD location in RAM.
+                * If it fails to read or isn't marked bootable, treat it
+                * as a bad selection.
+                * XXX what does %si carry?
+                */
 main.15:       movw $LOAD,%bx                  # Address for read
                movb $0x2,%ah                   # Read sector
                callw intx13                    #  from disk
@@ -293,20 +324,20 @@ main.15:  movw $LOAD,%bx                  # Address for read
                callw puts                      #  space
                popw %si                        # Restore
                jmp *%bx                        # Invoke bootstrap
-#
-# Display routines
-#
 
+               /*
+                * Display routines
+                */
 putkey:        movb $'F',%al                   # Display
                callw putchr                    #  'F'
                movb $'1',%al                   # Prepare
                addb %dl,%al                    #  digit
                jmp putstr.1                    # Display the rest
 
-#
-# Display the option and note that it is a valid option.
-# That last point is a bit tricky..
-#
+               /*
+                * Display the option and note that it is a valid option.
+                * That last point is a bit tricky..
+                */
 putx:          btsw %dx,_MNUOPT(%bp)           # Enable menu option
                movw $item,%si                  # Display
                callw putkey                    #  key
@@ -330,14 +361,15 @@ putchr:   pusha                           # Save
                popa                            # Restore
                retw                            # To caller
 
-# One-sector disk I/O routine
-#
-# Setup for both the packet and non-packet interfaces then select one or
-# the other.
-#
-# Don't trust the BIOS to keep registers intact across the call, use
-# pusha/popa.
-
+               /*
+                * One-sector disk I/O routine
+                *
+                * Setup for both the packet and non-packet interfaces 
+                * then select one or the other.
+                *
+                * Don't trust the BIOS to keep registers intact across 
+                * the call, use pusha/popa.
+                */
 intx13:        movb 0x1(%si),%dh               # (nonpkt) head
                movw 0x2(%si),%cx               # (nonpkt) cylinder:sector
                movb $0x1,%al                   # (nonpkt) Sector count
@@ -360,28 +392,35 @@ intx13.1: int $0x13                       # BIOS: Disk I/O
                popa                            # Restore registers
                retw
 
-# Menu strings
+               /*
+                * Menu strings
+                */
 
 item:          .ascii "  ";         .byte ' '|0x80
 prompt:        .ascii "\nDefault:"; .byte ' '|0x80
 crlf:          .ascii "\r";         .byte '\n'|0x80
 
-# Partition type tables
+               /*
+                * Partition type tables
+                */
 
 tables:
-#
-# These entries identify invalid or NON BOOT types and partitions.
-#
+               /*
+                * These entries identify invalid or NON BOOT types and
+                * partitions.
+                */
                .byte 0x0, 0x5, 0xf
-#
-# These values indicate bootable types we know the names of
-#
+
+               /*
+                * These values indicate bootable types we know the names of.
+                */
                .byte 0x1, 0x4, 0x6, 0xb, 0xc, 0xe, 0x83
                .byte 0x9f, 0xa5, 0xa6, 0xa9
-#
-# These are offsets that match the known names above and point to the strings
-# that will be printed.
-#
+
+               /*
+                * These are offsets that match the known names above and
+                * point to the strings that will be printed.
+                */
                .byte os_misc-.                 # Unknown
                .byte os_dos-.                  # DOS
                .byte os_dos-.                  # DOS
@@ -394,10 +433,12 @@ tables:
                .byte os_freebsd-.              # FreeBSD
                .byte os_bsd-.                  # OpenBSD
                .byte os_bsd-.                  # NetBSD
-#
-# And here are the strings themselves. 0x80 or'd into a byte indicates 
-# the end of the string. (not so great for Russians but...)
-#
+
+               /*
+                * And here are the strings themselves. 0x80 or'd into a
+                * byte indicates the end of the string. (not so great for
+                * Russians but...)
+                */
 os_misc:       .ascii "?";    .byte '?'|0x80
 os_dos:        .ascii "DO";   .byte 'S'|0x80
 os_linux:      .ascii "Linu"; .byte 'x'|0x80
@@ -408,11 +449,11 @@ os_bsd:   .ascii "BS";   .byte 'D'|0x80
 
                .word B0MAGIC                   # Magic number
 
-#
-# These values are sometimes changed before writing back to the drive
-# Be especially careful that nxtdrv: must come after drive:, as it 
-# is part of the same string.
-#
+               /*
+                * These values are sometimes changed before writing back 
+                * to the drive.  Be especially careful that nxtdrv: must
+                * come after drive:, as it is part of the same string.
+                */
 drive:         .ascii "Drive "
 nxtdrv:        .byte 0x0                       # Next drive number
 opt:           .byte 0x0                       # Option
@@ -420,8 +461,9 @@ setdrv:     .byte 0x80                      # Drive to force
 flags:         .byte FLAGS                     # Flags
 ticks:         .word TICKS                     # Delay
 
-#
-# here is the 64 byte partition table that fdisk would fiddle with.
-#
+               /*
+                * here is the 64 byte partition table that fdisk would 
+                * fiddle with.
+                */
 partbl:        .fill 0x40,0x1,0x0              # Partition table
                .word MAGIC                     # Magic number
diff --git a/sys/boot/i386/boot0/boot0.s b/sys/boot/i386/boot0/boot0.s
deleted file mode 100644 (file)
index 2d413e4..0000000
+++ /dev/null
@@ -1,427 +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: src/sys/boot/i386/boot0/boot0.s,v 1.26 2003/06/01 20:41:04 obrien Exp $
-# $DragonFly: src/sys/boot/i386/boot0/Attic/boot0.s,v 1.4 2004/07/18 18:26:33 dillon Exp $
-
-# A 512-byte boot manager.
-
-               .set NHRDRV,0x475               # Number of hard drives
-               .set ORIGIN,0x600               # Execution address
-               .set FAKE,0x800                 # Partition entry
-               .set LOAD,0x7c00                # Load address
-
-               .set PRT_OFF,0x1be              # Partition table
-
-               .set TBL0SZ,0x3                 # Table 0 size
-               .set TBL1SZ,0xc                 # Table 1 size
-
-               .set MAGIC,0xaa55               # Magic: bootable
-               .set B0MAGIC,0xbb66             # Identification
-
-               .set KEY_ENTER,0x1c             # Enter key scan code
-               .set KEY_F1,0x3b                # F1 key scan code
-               .set KEY_1,0x02                 # #1 key scan code
-
-#
-# Addresses in the sector of embedded data values.
-# Accessed with negative offsets from the end of the relocated sector (%ebp).
-#
-               .set _NXTDRV,-0x48              # Next drive
-               .set _OPT,-0x47                 # Default option
-               .set _SETDRV,-0x46              # Drive to force
-               .set _FLAGS,-0x45               # Flags
-               .set _TICKS,-0x44               # Timeout ticks
-               .set _FAKE,0x0                  # Fake partition entry
-               .set _MNUOPT,0xc                # Menu options
-
-               .globl start                    # Entry point
-               .code16                         # This runs in real mode
-
-#
-# Initialise segments and registers to known values.
-# segments start at 0.
-# The stack is immediately below the address we were loaded to.
-#
-start:         cld                             # String ops inc
-               xorw %ax,%ax                    # Zero
-               movw %ax,%es                    # Address
-               movw %ax,%ds                    #  data
-               movw %ax,%ss                    # Set up
-               movw $LOAD,%sp                  #  stack
-       
-#
-# Copy this code to the address it was linked for
-#
-               movw %sp,%si                    # Source
-               movw $start,%di                 # Destination
-               movw $0x100,%cx                 # Word count
-               rep                             # Relocate
-               movsw                           #  code
-#
-# Set address for variable space beyond code, and clear it.
-# Notice that this is also used to point to the values embedded in the block,
-# by using negative offsets.
-#
-               movw %di,%bp                    # Address variables
-               movb $0x8,%cl                   # Words to clear
-               rep                             # Zero
-               stosw                           #  them
-#
-# Relocate to the new copy of the code.
-#
-               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:          testb $0x20,_FLAGS(%bp)         # Set number drive?
-               jnz main.1                      # Yes
-               testb %dl,%dl                   # Drive number valid?
-               js main.2                       # Possibly (0x80 set)
-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:        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
-# so that after 4 iterations it's beyond the end of the sector.
-# and beyond a 256 byte boundary and has overflowed 8 bits (see next comment).
-# (remember that the table starts 2 bytes earlier than you would expect
-# as the bootable flag is after it in the block)
-#
-               movw $(partbl+0x4),%bx          # Partition table (+4)
-               xorw %dx,%dx                    # Item 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:        movb %ch,-0x4(%bx)              # Zero active flag (ch == 0)
-               btw %dx,_FLAGS(%bp)             # Entry enabled?
-               jnc main.5                      # No
-#
-# 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.
-#
-               movb (%bx),%al                  # Load type
-               movw $tables,%di                # Lookup tables
-               movb $TBL0SZ,%cl                # Number of entries
-               repne                           # Exclude
-               scasb                           #  partition?
-               je main.5                       # Yes
-#
-# Now scan the table of known types
-#
-               movb $TBL1SZ,%cl                # Number of entries
-               repne                           # Known
-               scasb                           #  type?
-               jne main.4                      # No
-#
-# 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:        movb (%di),%cl                  # Partition
-               addw %cx,%di                    #  description
-               callw putx                      # Display it
-main.5:        incw %dx                        # Next item 
-               addb $0x10,%bl                  # Next entry
-               jnc main.3                      # Till done
-#
-# Passed a 256 byte boundary..
-# table is finished.
-# Add one to the drive number and check it is valid, 
-#
-               popw %ax                        # Drive number
-               subb $0x80-0x1,%al              # Does next
-               cmpb NHRDRV,%al                 #  drive exist? (from BIOS?)
-               jb main.6                       # Yes
-# If not then if there is only one drive,
-# Don't display drive as an option.
-#
-               decw %ax                        # Already drive 0?
-               jz main.7                       # Yes
-# If it was illegal or we cycled through them,
-# then go back to drive 0.
-#
-               xorb %al,%al                    # Drive 0
-#
-# Whatever drive we selected, make it an ascii digit and save it back
-# to the "next drive" location in the loaded block in case we
-# want to save it for next time.
-# This also is part of the printed drive string so add 0x80 to indicate
-# end of string.
-#
-main.6:        addb $'0'|0x80,%al              # Save next
-               movb %al,_NXTDRV(%bp)           #  drive number
-               movw $drive,%di                 # Display
-               callw putx                      #  item
-#
-# Now that we've printed the drive (if we needed to), display a prompt.
-# Get ready for the input by noting the time.
-#
-main.7:        movw $prompt,%si                # Display
-               callw putstr                    #  prompt
-               movb _OPT(%bp),%dl              # Display
-               decw %si                        #  default
-               callw putkey                    #  key
-               xorb %ah,%ah                    # BIOS: Get
-               int $0x1a                       #  system time
-               movw %dx,%di                    # Ticks when
-               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
-               jnz main.11                     # Have one
-               xorb %ah,%ah                    # BIOS: Get
-               int $0x1a                       #  system time
-               cmpw %di,%dx                    # Timeout?
-               jb main.8                       # No
-#
-# If timed out or defaulting, come here.
-#
-main.9:        movb _OPT(%bp),%al              # Load default
-               jmp main.12                     # Join common code
-#
-# User's last try was bad, beep in displeasure.
-# Since nothing was printed, just continue on as if the user
-# hadn't done anything. This gives the effect of the user getting a beep 
-# for all bad keystrokes but no action until either the timeout
-# occurs or the user hits a good key.
-#
-main.10:       movb $0x7,%al                   # Signal
-               callw putchr                    #  error
-#
-# Get the keystroke.
-#
-main.11:       xorb %ah,%ah                    # BIOS: Get
-               int $0x16                       #  keypress
-               movb %ah,%al                    # Scan code
-#
-# If it's CR act as if timed out.
-#
-               cmpb $KEY_ENTER,%al             # Enter pressed?
-               je main.9                       # Yes
-#
-# Otherwise check if legal
-# If not ask again.
-#
-               subb $KEY_F1,%al                # Less F1 scan code
-               cmpb $0x4,%al                   # F1..F5?
-               jna main.12                     # Yes
-               subb $(KEY_1 - KEY_F1),%al      # Less #1 scan code
-               cmpb $0x4,%al                   # #1..#5?
-               ja main.10                      # No
-#
-# We have a selection.
-# but if it's a bad selection go back to complain.
-# The bits in MNUOPT were set when the options were printed.
-# Anything not printed is not an option.
-#
-main.12:       cbtw                            # Option
-               btw %ax,_MNUOPT(%bp)            #  enabled?
-               jnc main.10                     # No
-#
-# Save the info in the original tables
-# for rewriting to the disk.
-#
-               movb %al,_OPT(%bp)              # Save option
-               movw $FAKE,%si                  # Partition for write
-               movb (%si),%dl                  # Drive number
-               movw %si,%bx                    # Partition for read
-               cmpb $0x4,%al                   # F5 pressed?
-               pushf                           # Save
-               je main.13                      # Yes
-               shlb $0x4,%al                   # Point to
-               addw $partbl,%ax                #  selected
-               xchgw %bx,%ax                   #  partition
-               movb $0x80,(%bx)                # Flag active
-#
-# If not asked to do a write-back (flags 0x40) don't do one.
-#
-main.13:       pushw %bx                       # Save
-               testb $0x40,_FLAGS(%bp)         # No updates?
-               jnz main.14                     # Yes
-               movw $start,%bx                 # Data to write
-               movb $0x3,%ah                   # Write sector
-               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!
-#
-               jne main.15                     # If not F5
-               movb _NXTDRV(%bp),%dl           # Next drive
-               subb $'0',%dl                   #  number
-# 
-# load  selected bootsector to the LOAD location in RAM.
-# If it fails to read or isn't marked bootable, treat it
-# as a bad selection.
-# XXX what does %si carry?
-#
-main.15:       movw $LOAD,%bx                  # Address for read
-               movb $0x2,%ah                   # Read sector
-               callw intx13                    #  from disk
-               jc main.10                      # If error
-               cmpw $MAGIC,0x1fe(%bx)          # Bootable?
-               jne main.10                     # No
-               pushw %si                       # Save
-               movw $crlf,%si                  # Leave some
-               callw puts                      #  space
-               popw %si                        # Restore
-               jmp *%bx                        # Invoke bootstrap
-#
-# Display routines
-#
-
-putkey:        movb $'F',%al                   # Display
-               callw putchr                    #  'F'
-               movb $'1',%al                   # Prepare
-               addb %dl,%al                    #  digit
-               jmp putstr.1                    # Display the rest
-
-#
-# Display the option and note that it is a valid option.
-# That last point is a bit tricky..
-#
-putx:          btsw %dx,_MNUOPT(%bp)           # Enable menu option
-               movw $item,%si                  # Display
-               callw putkey                    #  key
-               movw %di,%si                    # Display the rest
-
-puts:          callw putstr                    # Display string
-
-putn:          movw $crlf,%si                  # To next line
-
-putstr:        lodsb                           # Get byte
-               testb $0x80,%al                 # End of string?
-               jnz putstr.2                    # Yes
-putstr.1:      callw putchr                    # Display char
-               jmp putstr                      # Continue
-putstr.2:      andb $~0x80,%al                 # Clear MSB
-
-putchr:        pusha                           # Save
-               movw $0x7,%bx                   # Page:attribute
-               movb $0xe,%ah                   # BIOS: Display
-               int $0x10                       #  character
-               popa                            # Restore
-               retw                            # To caller
-
-# One-sector disk I/O routine
-#
-# Setup for both the packet and non-packet interfaces then select one or
-# the other.
-#
-# Don't trust the BIOS to keep registers intact across the call, use
-# pusha/popa.
-
-intx13:        movb 0x1(%si),%dh               # (nonpkt) head
-               movw 0x2(%si),%cx               # (nonpkt) cylinder:sector
-               movb $0x1,%al                   # (nonpkt) Sector count
-               pusha                           # save: do not trust the bios
-               pushl $0x0                      # (pkt) LBA address
-               pushl 0x8(%si)                  # (pkt)
-               pushw %es                       # (pkt) xfer buffer address
-               pushw %bx                       # (pkt)
-               pushw $1                        # (pkt) Block count
-               pushw $16                       # (pkt) Packet size
-               testb $0x80,_FLAGS(%bp)         # Use packet interface?
-               jz intx13.1
-               movw %sp,%si                    # Yes, set packet pointer
-               decw %ax                        # Verify off
-               orb $0x40,%ah                   # Set pkt mode in command
-intx13.1:      int $0x13                       # BIOS: Disk I/O
-               # WARNING: RETAIN CARRY AFTER BIOS CALL
-               movw %sp,%si
-               lea 16(%si),%sp                 # cleanup the stack
-               popa                            # Restore registers
-               retw
-
-# Menu strings
-
-item:          .ascii "  ";         .byte ' '|0x80
-prompt:        .ascii "\nDefault:"; .byte ' '|0x80
-crlf:          .ascii "\r";         .byte '\n'|0x80
-
-# Partition type tables
-
-tables:
-#
-# These entries identify invalid or NON BOOT types and partitions.
-#
-               .byte 0x0, 0x5, 0xf
-#
-# These values indicate bootable types we know the names of
-#
-               .byte 0x1, 0x4, 0x6, 0xb, 0xc, 0xe, 0x83
-               .byte 0x9f, 0xa5, 0xa6, 0xa9
-#
-# These are offsets that match the known names above and point to the strings
-# that will be printed.
-#
-               .byte os_misc-.                 # Unknown
-               .byte os_dos-.                  # DOS
-               .byte os_dos-.                  # DOS
-               .byte os_dos-.                  # DOS
-               .byte os_dos-.                  # Windows
-               .byte os_dos-.                  # Windows
-               .byte os_dos-.                  # Windows
-               .byte os_linux-.                # Linux
-               .byte os_bsd-.                  # BSD/OS
-               .byte os_freebsd-.              # FreeBSD
-               .byte os_bsd-.                  # OpenBSD
-               .byte os_bsd-.                  # NetBSD
-#
-# And here are the strings themselves. 0x80 or'd into a byte indicates 
-# the end of the string. (not so great for Russians but...)
-#
-os_misc:       .ascii "?";    .byte '?'|0x80
-os_dos:        .ascii "DO";   .byte 'S'|0x80
-os_linux:      .ascii "Linu"; .byte 'x'|0x80
-os_freebsd:    .ascii "Free"
-os_bsd:        .ascii "BS";   .byte 'D'|0x80
-
-               .org PRT_OFF-0xe,0x90
-
-               .word B0MAGIC                   # Magic number
-
-#
-# These values are sometimes changed before writing back to the drive
-# Be especially careful that nxtdrv: must come after drive:, as it 
-# is part of the same string.
-#
-drive:         .ascii "Drive "
-nxtdrv:        .byte 0x0                       # Next drive number
-opt:           .byte 0x0                       # Option
-setdrv:        .byte 0x80                      # Drive to force
-flags:         .byte FLAGS                     # Flags
-ticks:         .word TICKS                     # Delay
-
-#
-# here is the 64 byte partition table that fdisk would fiddle with.
-#
-partbl:        .fill 0x40,0x1,0x0              # Partition table
-               .word MAGIC                     # Magic number
index 109e0d8..b0461e2 100644 (file)
@@ -1,5 +1,5 @@
 # $FreeBSD: src/sys/boot/i386/boot2/Makefile,v 1.47 2003/06/26 03:51:57 peter Exp $
-# $DragonFly: src/sys/boot/i386/boot2/Attic/Makefile,v 1.6 2004/04/10 12:07:20 joerg Exp $
+# $DragonFly: src/sys/boot/i386/boot2/Attic/Makefile,v 1.7 2004/07/18 23:40:01 dillon Exp $
 
 PROG=          boot2
 NOMAN=
@@ -62,9 +62,9 @@ boot1: boot1.out
 boot1.out: boot1.o
        ${LD} ${LDFLAGS} -e start -Ttext ${ORG1} -o ${.TARGET} boot1.o
 
-boot1.o: boot1.s
-       ${CPP} ${CFLAGS} ${.IMPSRC} | \
-           ${AS} ${AFLAGS} --defsym FLAGS=${B1FLAGS} -o ${.TARGET}
+boot1.o: boot1.S
+       ${CC} ${CFLAGS} -DFLAGS=${B1FLAGS} ${AFLAGS} \
+               ${.IMPSRC} -o ${.TARGET} -c
 
 boot2.o: boot2.c ${.CURDIR}/../../common/ufsread.c
        ${CC} ${CFLAGS} -S -o boot2.s.tmp ${.IMPSRC}
@@ -98,11 +98,10 @@ boot2.out: boot2.o sio.o
 
 boot2.o: boot2.h
 
-sio.o: sio.s
-       ${AS} ${AFLAGS} --defsym SIOPRT=${BOOT_COMCONSOLE_PORT} \
-               --defsym SIOFMT=${B2SIOFMT} \
-               --defsym SIOSPD=${BOOT_COMCONSOLE_SPEED} \
-               ${.IMPSRC} -o ${.TARGET}
+sio.o: sio.S
+       ${CC} -DSIOPRT=${BOOT_COMCONSOLE_PORT} -DSIOFMT=${B2SIOFMT} \
+               -DSIOSPD=${BOOT_COMCONSOLE_SPEED} \
+               ${AFLAGS} ${.IMPSRC} -o ${.TARGET} -c
 
 install:
        ${INSTALL} -o ${BINOWN} -g ${BINGRP} -m ${BINMODE} \
index b76c591..ba0d169 100644 (file)
@@ -1,30 +1,22 @@
-//
-// 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.
-//
+/*
+ * 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: src/sys/boot/i386/boot2/boot1.s,v 1.23 2003/08/22 01:59:28 imp Exp $
+ * $DragonFly: src/sys/boot/i386/boot2/Attic/boot1.S,v 1.5 2004/07/18 23:40:01 dillon Exp $
+ */
 
-// $FreeBSD: src/sys/boot/i386/boot2/boot1.s,v 1.23 2003/08/22 01:59:28 imp Exp $
-// $DragonFly: src/sys/boot/i386/boot2/Attic/boot1.S,v 1.4 2004/03/04 00:06:58 dillon Exp $
-
-// Memory Locations
-               .set MEM_REL,0x700              // Relocation address
-               .set MEM_ARG,0x900              // Arguments
-               .set MEM_ORG,0x7c00             // Origin
-               .set MEM_BUF,0x8c00             // Load area
-               .set MEM_BTX,0x9000             // BTX start
-               .set MEM_JMP,0x9010             // BTX entry point
-               .set MEM_USR,0xa000             // Client start
-               .set BDA_BOOT,0x472             // Boot howto flag
+#include "../bootasm.h"
        
 // Partition Constants 
                .set PRT_OFF,0x1be              // Partition offset
@@ -37,8 +29,8 @@
 // Misc. Constants
                .set SIZ_PAG,0x1000             // Page size
                .set SIZ_SEC,0x200              // Sector size
-
                .set NSECT,0x10
+
                .globl start
                .globl xread
                .code16
diff --git a/sys/boot/i386/boot2/boot1.s b/sys/boot/i386/boot2/boot1.s
deleted file mode 100644 (file)
index f109eb1..0000000
+++ /dev/null
@@ -1,366 +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: src/sys/boot/i386/boot2/boot1.s,v 1.23 2003/08/22 01:59:28 imp Exp $
-// $DragonFly: src/sys/boot/i386/boot2/Attic/boot1.s,v 1.4 2004/03/04 00:06:58 dillon Exp $
-
-// Memory Locations
-               .set MEM_REL,0x700              // Relocation address
-               .set MEM_ARG,0x900              // Arguments
-               .set MEM_ORG,0x7c00             // Origin
-               .set MEM_BUF,0x8c00             // Load area
-               .set MEM_BTX,0x9000             // BTX start
-               .set MEM_JMP,0x9010             // BTX entry point
-               .set MEM_USR,0xa000             // Client start
-               .set BDA_BOOT,0x472             // Boot howto flag
-       
-// Partition Constants 
-               .set PRT_OFF,0x1be              // Partition offset
-               .set PRT_NUM,0x4                // Partitions
-               .set PRT_BSD,0xa5               // Partition type
-
-// Flag Bits
-               .set FL_PACKET,0x80             // Packet mode
-
-// Misc. Constants
-               .set SIZ_PAG,0x1000             // Page size
-               .set SIZ_SEC,0x200              // Sector size
-
-               .set NSECT,0x10
-               .globl start
-               .globl xread
-               .code16
-
-start:         jmp main                        // Start recognizably
-
-// This is the start of a standard BIOS Parameter Block (BPB). Most bootable
-// FAT disks have this at the start of their MBR. While normal BIOS's will
-// work fine without this section, IBM's El Torito emulation "fixes" up the
-// BPB by writing into the memory copy of the MBR. Rather than have data
-// written into our xread routine, we'll define a BPB to work around it.
-// The data marked with (T) indicates a field required for a ThinkPad to
-// recognize the disk and (W) indicates fields written from IBM BIOS code.
-// The use of the BPB is based on what OpenBSD and NetBSD implemented in
-// their boot code but the required fields were determined by trial and error.
-//
-// Note: If additional space is needed in boot1, one solution would be to
-// move the "prompt" message data (below) to replace the OEM ID.
-
-               .org 0x03, 0x00
-oemid:         .space 0x08, 0x00       // OEM ID
-
-               .org 0x0b, 0x00
-bpb:           .word   512             // sector size (T)
-               .byte   0               // sectors/clustor
-               .word   0               // reserved sectors
-               .byte   0               // number of FATs
-               .word   0               // root entries
-               .word   0               // small sectors
-               .byte   0               // media type (W)
-               .word   0               // sectors/fat
-               .word   18              // sectors per track (T)
-               .word   2               // number of heads (T)
-               .long   0               // hidden sectors (W)
-               .long   0               // large sectors
-
-               .org 0x24, 0x00
-ebpb:          .byte   0               // BIOS physical drive number (W)
-
-               .org 0x25,0x90
-// 
-// Trampoline used by boot2 to call read to read data from the disk via
-// the BIOS.  Call with:
-//
-// %cx:%ax     - long    - LBA to read in
-// %es:(%bx)   - caddr_t - buffer to read data into
-// %dl         - byte    - drive to read from
-// %dh         - byte    - num sectors to read
-// 
-
-xread:         push %ss                        // Address
-               pop %ds                         //  data
-//
-// Setup an EDD disk packet and pass it to read
-// 
-xread.1:                                       // Starting
-               pushl $0x0                      //  absolute
-               push %cx                        //  block
-               push %ax                        //  number
-               push %es                        // Address of
-               push %bx                        //  transfer buffer
-               xor %ax,%ax                     // Number of
-               movb %dh,%al                    //  blocks to
-               push %ax                        //  transfer
-               push $0x10                      // Size of packet
-               mov %sp,%bp                     // Packet pointer
-               callw read                      // Read from disk
-               lea 0x10(%bp),%sp               // Clear stack
-               lret                            // To far caller
-// 
-// Load the rest of boot2 and BTX up, copy the parts to the right locations,
-// and start it all up.
-//
-
-//
-// Setup the segment registers to flat addressing (segment 0) and setup the
-// stack to end just below the start of our code.
-// 
-main:          cld                             // String ops inc
-               xor %cx,%cx                     // Zero
-               mov %cx,%es                     // Address
-               mov %cx,%ds                     //  data
-               mov %cx,%ss                     // Set up
-               mov $start,%sp                  //  stack
-//
-// Relocate ourself to MEM_REL.  Since %cx == 0, the inc %ch sets
-// %cx == 0x100.
-// 
-               mov %sp,%si                     // Source
-               mov $MEM_REL,%di                // Destination
-               incb %ch                        // Word count
-               rep                             // Copy
-               movsw                           //  code
-//
-// If we are on a hard drive, then load the MBR and look for the first
-// FreeBSD slice.  We use the fake partition entry below that points to
-// the MBR when we call nread.  The first pass looks for the first active
-// FreeBSD slice.  The second pass looks for the first non-active FreeBSD
-// slice if the first one fails.
-// 
-               mov $part4,%si                  // Partition
-               cmpb $0x80,%dl                  // Hard drive?
-               jb main.4                       // No
-               movb $0x1,%dh                   // Block count
-               callw nread                     // Read MBR
-               mov $0x1,%cx                    // Two passes
-main.1:        mov $MEM_BUF+PRT_OFF,%si        // Partition table
-               movb $0x1,%dh                   // Partition
-main.2:        cmpb $PRT_BSD,0x4(%si)          // Our partition type?
-               jne main.3                      // No
-               jcxz main.5                     // If second pass
-               testb $0x80,(%si)               // Active?
-               jnz main.5                      // Yes
-main.3:        add $0x10,%si                   // Next entry
-               incb %dh                        // Partition
-               cmpb $0x1+PRT_NUM,%dh           // In table?
-               jb main.2                       // Yes
-               dec %cx                         // Do two
-               jcxz main.1                     //  passes
-//
-// If we get here, we didn't find any FreeBSD slices at all, so print an
-// error message and die.
-// 
-               mov $msg_part,%si               // Message
-               jmp error                       // Error
-//
-// Floppies use partition 0 of drive 0.
-// 
-main.4:        xor %dx,%dx                     // Partition:drive
-//
-// Ok, we have a slice and drive in %dx now, so use that to locate and load
-// boot2.  %si references the start of the slice we are looking for, so go
-// ahead and load up the first 16 sectors (boot1 + boot2) from that.  When
-// we read it in, we conveniently use 0x8c00 as our transfer buffer.  Thus,
-// boot1 ends up at 0x8c00, and boot2 starts at 0x8c00 + 0x200 = 0x8e00.
-// The first part of boot2 is the disklabel, which is 0x200 bytes long.
-// The second part is BTX, which is thus loaded into 0x9000, which is where
-// it also runs from.  The boot2.bin binary starts right after the end of
-// BTX, so we have to figure out where the start of it is and then move the
-// binary to 0xc000.  Normally, BTX clients start at MEM_USR, or 0xa000, but
-// when we use btxld to create boot2, we use an entry point of 0x2000.  That
-// entry point is relative to MEM_USR; thus boot2.bin starts at 0xc000.
-// 
-main.5:        mov %dx,MEM_ARG                 // Save args
-               movb $NSECT,%dh                 // Sector count
-               callw nread                     // Read disk
-               mov $MEM_BTX,%bx                // BTX
-               mov 0xa(%bx),%si                // Get BTX length and set
-               add %bx,%si                     //  %si to start of boot2.bin
-               mov $MEM_USR+SIZ_PAG*2,%di      // Client page 2
-               mov $MEM_BTX+(NSECT-1)*SIZ_SEC,%cx // Byte
-               sub %si,%cx                     //  count
-               rep                             // Relocate
-               movsb                           //  client
-               sub %di,%cx                     // Byte count
-               xorb %al,%al                    // Zero assumed bss from
-               rep                             //  the end of boot2.bin
-               stosb                           //  up to 0x10000
-               callw seta20                    // Enable A20
-               jmp start+MEM_JMP-MEM_ORG       // Start BTX
-// 
-// Enable A20 so we can access memory above 1 meg.
-// 
-seta20:        cli                             // Disable interrupts
-seta20.1:      inb $0x64,%al                   // Get status
-               testb $0x2,%al                  // Busy?
-               jnz seta20.1                    // Yes
-               movb $0xd1,%al                  // Command: Write
-               outb %al,$0x64                  //  output port
-seta20.2:      inb $0x64,%al                   // Get status
-               testb $0x2,%al                  // Busy?
-               jnz seta20.2                    // Yes
-               movb $0xdf,%al                  // Enable
-               outb %al,$0x60                  //  A20
-               sti                             // Enable interrupts
-               retw                            // To caller
-// 
-// Trampoline used to call read from within boot1.
-// 
-nread:         mov $MEM_BUF,%bx                // Transfer buffer
-               mov 0x8(%si),%ax                // Get
-               mov 0xa(%si),%cx                //  LBA
-               push %cs                        // Read from
-               callw xread.1                   //  disk
-               jnc return                      // If success, return
-               mov $msg_read,%si               // Otherwise, set the error
-                                               //  message and fall through to
-                                               //  the error routine
-// 
-// Print out the error message pointed to by %ds:(%si) followed
-// by a prompt, wait for a keypress, and then reboot the machine.
-// 
-error:         callw putstr                    // Display message
-               mov $prompt,%si                 // Display
-               callw putstr                    //  prompt
-               xorb %ah,%ah                    // BIOS: Get
-               int $0x16                       //  keypress
-               movw $0x1234, BDA_BOOT          // Do a warm boot
-               ljmp $0xffff,$0x0               // reboot the machine
-// 
-// Display a null-terminated string using the BIOS output.
-// 
-putstr.0:      mov $0x7,%bx                    // Page:attribute
-               movb $0xe,%ah                   // BIOS: Display
-               int $0x10                       //  character
-putstr:        lodsb                           // Get char
-               testb %al,%al                   // End of string?
-               jne putstr.0                    // No
-
-//
-// Overused return code.  ereturn is used to return an error from the
-// read function.  Since we assume putstr succeeds, we (ab)use the
-// same code when we return from putstr. 
-// 
-ereturn:       movb $0x1,%ah                   // Invalid
-               stc                             //  argument
-return:        retw                            // To caller
-// 
-// Reads sectors from the disk.  If EDD is enabled, then check if it is
-// installed and use it if it is.  If it is not installed or not enabled, then
-// fall back to using CHS.  Since we use a LBA, if we are using CHS, we have to
-// fetch the drive parameters from the BIOS and divide it out ourselves.
-// Call with:
-//
-// %dl - byte     - drive number
-// stack - 10 bytes - EDD Packet
-//
-read:          push %dx                        // Save
-               movb $0x8,%ah                   // BIOS: Get drive
-               int $0x13                       //  parameters
-               movb %dh,%ch                    // Max head number
-               pop %dx                         // Restore
-               jc return                       // If error
-               andb $0x3f,%cl                  // Sectors per track
-               jz ereturn                      // If zero
-               cli                             // Disable interrupts
-               mov 0x8(%bp),%eax               // Get LBA
-               push %dx                        // Save
-               movzbl %cl,%ebx                 // Divide by
-               xor %edx,%edx                   //  sectors
-               div %ebx                        //  per track
-               movb %ch,%bl                    // Max head number
-               movb %dl,%ch                    // Sector number
-               inc %bx                         // Divide by
-               xorb %dl,%dl                    //  number
-               div %ebx                        //  of heads
-               movb %dl,%bh                    // Head number
-               pop %dx                         // Restore
-               cmpl $0x3ff,%eax                // Cylinder number supportable?
-               sti                             // Enable interrupts
-               ja read.7                       // No, try EDD
-               xchgb %al,%ah                   // Set up cylinder
-               rorb $0x2,%al                   //  number
-               orb %ch,%al                     // Merge
-               inc %ax                         //  sector
-               xchg %ax,%cx                    //  number
-               movb %bh,%dh                    // Head number
-               subb %ah,%al                    // Sectors this track
-               mov 0x2(%bp),%ah                // Blocks to read
-               cmpb %ah,%al                    // To read
-               jb read.2                       //  this
-#ifdef TRACK_AT_A_TIME
-               movb %ah,%al                    //  track
-#else
-               movb $1,%al                     //  one sector
-#endif
-read.2:        mov $0x5,%di                    // Try count
-read.3:        les 0x4(%bp),%bx                // Transfer buffer
-               push %ax                        // Save
-               movb $0x2,%ah                   // BIOS: Read
-               int $0x13                       //  from disk
-               pop %bx                         // Restore
-               jnc read.4                      // If success
-               dec %di                         // Retry?
-               jz read.6                       // No
-               xorb %ah,%ah                    // BIOS: Reset
-               int $0x13                       //  disk system
-               xchg %bx,%ax                    // Block count
-               jmp read.3                      // Continue
-read.4:        movzbw %bl,%ax                  // Sectors read
-               add %ax,0x8(%bp)                // Adjust
-               jnc read.5                      //  LBA,
-               incw 0xa(%bp)                   //  transfer
-read.5:        shlb %bl                        //  buffer
-               add %bl,0x5(%bp)                //  pointer,
-               sub %al,0x2(%bp)                //  block count
-               ja read                         // If not done
-read.6:        retw                            // To caller
-read.7:                testb $FL_PACKET,%cs:MEM_REL+flags-start // LBA support enabled?
-               jz ereturn                      // No, so return an error
-               mov $0x55aa,%bx                 // Magic
-               push %dx                        // Save
-               movb $0x41,%ah                  // BIOS: Check
-               int $0x13                       //  extensions present
-               pop %dx                         // Restore
-               jc return                       // If error, return an error
-               cmp $0xaa55,%bx                 // Magic?
-               jne ereturn                     // No, so return an error
-               testb $0x1,%cl                  // Packet interface?
-               jz ereturn                      // No, so return an error
-               mov %bp,%si                     // Disk packet
-               movb $0x42,%ah                  // BIOS: Extended
-               int $0x13                       //  read
-               retw                            // To caller
-
-// Messages
-
-msg_read:      .asciz "Read"
-msg_part:      .asciz "Boot"
-
-prompt:        .asciz " error\r\n"
-
-flags:         .byte FLAGS                     // Flags
-
-               .org PRT_OFF,0x90
-
-// Partition table
-
-               .fill 0x30,0x1,0x0
-part4:         .byte 0x80, 0x00, 0x01, 0x00
-               .byte 0xa5, 0xfe, 0xff, 0xff
-               .byte 0x00, 0x00, 0x00, 0x00
-               .byte 0x50, 0xc3, 0x00, 0x00    // 50000 sectors long, bleh
-
-               .word 0xaa55                    // Magic number
index a6a48ec..04df85e 100644 (file)
@@ -13,7 +13,7 @@
  * purpose.
  *
  * $FreeBSD: src/sys/boot/i386/boot2/boot2.c,v 1.64 2003/08/25 23:28:31 obrien Exp $
- * $DragonFly: src/sys/boot/i386/boot2/Attic/boot2.c,v 1.10 2004/06/27 08:00:46 dillon Exp $
+ * $DragonFly: src/sys/boot/i386/boot2/Attic/boot2.c,v 1.11 2004/07/18 23:40:01 dillon Exp $
  */
 #include <sys/param.h>
 #include <sys/disklabel.h>
@@ -31,6 +31,7 @@
 
 #include "boot2.h"
 #include "lib.h"
+#include "../bootasm.h"
 
 #define SECOND         18      /* Circa that many ticks in a second. */
 
@@ -61,7 +62,6 @@
 #define PATH_BOOT3     "/boot/loader"
 #define PATH_KERNEL    "/kernel"
 
-#define ARGS           0x900
 #define NDEV           3
 #define MEM_BASE       0x12
 #define MEM_EXT        0x15
@@ -221,10 +221,10 @@ main(void)
 
     dmadat = (void *)(roundup2(__base + (int32_t)&_end, 0x10000) - __base);
     v86.ctl = V86_FLAGS;
-    dsk.drive = *(uint8_t *)PTOV(ARGS);
+    dsk.drive = *(uint8_t *)PTOV(MEM_ARG);
     dsk.type = dsk.drive & DRV_HARD ? TYPE_AD : TYPE_FD;
     dsk.unit = dsk.drive & DRV_MASK;
-    dsk.slice = *(uint8_t *)PTOV(ARGS + 1) + 1;
+    dsk.slice = *(uint8_t *)PTOV(MEM_ARG + 1) + 1;
     bootinfo.bi_version = BOOTINFO_VERSION;
     bootinfo.bi_size = sizeof(bootinfo);
     bootinfo.bi_basemem = 0;   /* XXX will be filled by loader or kernel */
index 396e588..09c047b 100644 (file)
@@ -1,21 +1,20 @@
-#
-# 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: src/sys/boot/i386/boot2/sio.s,v 1.4 1999/08/28 00:40:02 peter Exp $
-# $DragonFly: src/sys/boot/i386/boot2/Attic/sio.S,v 1.5 2004/06/27 08:00:46 dillon Exp $
-
+/*
+ * 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: src/sys/boot/i386/boot2/sio.s,v 1.4 1999/08/28 00:40:02 peter Exp $
+ * $DragonFly: src/sys/boot/i386/boot2/Attic/sio.S,v 1.6 2004/07/18 23:40:01 dillon Exp $
+ */
                .set SIO_PRT,SIOPRT             # Base port
                .set SIO_FMT,SIOFMT             # 8N1
                .set SIO_DIV,(115200/SIOSPD)    # 115200 / SPD
                .globl sio_getc
                .globl sio_ischar
 
-# int sio_init(void)
-# 
-# returns non-zero if we couldn't init, which can happen if the
-# serial port is unmapped and the inb's all return 0xFF (we fail
-# to flush the input).
-
+               /*
+                * int sio_init(void)
+                * 
+                * returns non-zero if we couldn't init, which can happen if
+                * the serial port is unmapped and the inb's all return
+                * 0xFF (we fail to flush the input).
+                */
 sio_init:      movw $SIO_PRT+0x3,%dx           # Data format reg
                movb $SIO_FMT|0x80,%al          # Set format and DLAB
                outb %al,(%dx)                  # BASE+3
@@ -40,9 +40,12 @@ sio_init:    movw $SIO_PRT+0x3,%dx           # Data format reg
                outw %ax,(%dx)                  # BASE+0 (divisor w/ DLAB set)
                movw $SIO_PRT+0x2,%dx
                movb $0x01,%al                  # Enable FIFO
-               # DISABLED - apparently many new laptops only implement 
-               # 8250s, this might crash them? XXX
-               # outb %al,(%dx)                        # BASE+2
+
+               /* 
+                * DISABLED - apparently many new laptops only implement 
+                * 8250s, this might crash them? XXX
+                */
+                /* outb %al,(%dx) */                   # BASE+2
                incl %edx
                movb $SIO_FMT,%al               # Clear DLAB
                outb %al,(%dx)                  # BASE+3
@@ -51,20 +54,22 @@ sio_init:   movw $SIO_PRT+0x3,%dx           # Data format reg
                outb %al,(%dx)                  # BASE+4
                incl %edx                       # BASE+5 Line status reg
 
-               # fall through to io_flush
-               #
-               # sio_flush: flush pending data in the serial port,
-               # return non-zero if we were unable to flush (aka
-               # ischar always returned true)
-
+               /* 
+                * fall through to io_flush
+                *
+                * sio_flush: flush pending data in the serial port,
+                * return non-zero if we were unable to flush (aka
+                * ischar always returned true)
+                */
 sio_flush:     movb $1,%ch                     # let %cl be garbage
 1:             call sio_getc.1
                call sio_ischar
                loopnz 1b
                ret
 
-# void sio_putc(int c)
-
+               /*
+                * void sio_putc(int c)
+                */
 sio_putc:      movw $SIO_PRT+0x5,%dx           # Line status reg
                movb $0x40,%ch                  # Timeout counter.  Allow %cl
                                                # to contain garbage.
@@ -77,16 +82,18 @@ sio_putc.1: inb (%dx),%al                   # Transmitter buffer empty?
                outb %al,(%dx)                  # Write character
 sio_putc.2:    ret $0x4
 
-# int sio_getc(void)
-
+               /*
+                * int sio_getc(void)
+                */
 sio_getc:      call sio_ischar                 # Character available?
                jz sio_getc                     # No
 sio_getc.1:    subb $0x5,%dl                   # Receiver buffer reg
                inb (%dx),%al                   # Read character
                ret
 
-# int sio_ischar(void)
-
+               /*
+                * int sio_ischar(void)
+                */
 sio_ischar:    movw $SIO_PRT+0x5,%dx           # Line status register
                xorl %eax,%eax                  # Zero
                inb (%dx),%al                   # Received data ready?
@@ -94,6 +101,6 @@ sio_ischar:  movw $SIO_PRT+0x5,%dx           # Line status register
                ret
 
                .globl inbser
-inbser:        movw $SIO_PRT+5,%dx
+inbser:                movw $SIO_PRT+5,%dx
                inb (%dx),%al
                ret
diff --git a/sys/boot/i386/boot2/sio.s b/sys/boot/i386/boot2/sio.s
deleted file mode 100644 (file)
index 191f97f..0000000
+++ /dev/null
@@ -1,99 +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: src/sys/boot/i386/boot2/sio.s,v 1.4 1999/08/28 00:40:02 peter Exp $
-# $DragonFly: src/sys/boot/i386/boot2/Attic/sio.s,v 1.5 2004/06/27 08:00:46 dillon Exp $
-
-               .set SIO_PRT,SIOPRT             # Base port
-               .set SIO_FMT,SIOFMT             # 8N1
-               .set SIO_DIV,(115200/SIOSPD)    # 115200 / SPD
-
-               .globl sio_init
-               .globl sio_flush
-               .globl sio_putc
-               .globl sio_getc
-               .globl sio_ischar
-
-# int sio_init(void)
-# 
-# returns non-zero if we couldn't init, which can happen if the
-# serial port is unmapped and the inb's all return 0xFF (we fail
-# to flush the input).
-
-sio_init:      movw $SIO_PRT+0x3,%dx           # Data format reg
-               movb $SIO_FMT|0x80,%al          # Set format and DLAB
-               outb %al,(%dx)                  # BASE+3
-               subb $0x3,%dl
-               movw $SIO_DIV,%ax               # divisor
-               outw %ax,(%dx)                  # BASE+0 (divisor w/ DLAB set)
-               movw $SIO_PRT+0x2,%dx
-               movb $0x01,%al                  # Enable FIFO
-               # DISABLED - apparently many new laptops only implement 
-               # 8250s, this might crash them? XXX
-               # outb %al,(%dx)                        # BASE+2
-               incl %edx
-               movb $SIO_FMT,%al               # Clear DLAB
-               outb %al,(%dx)                  # BASE+3
-               incl %edx
-               movb $0x3,%al                   # RTS+DTR
-               outb %al,(%dx)                  # BASE+4
-               incl %edx                       # BASE+5 Line status reg
-
-               # fall through to io_flush
-               #
-               # sio_flush: flush pending data in the serial port,
-               # return non-zero if we were unable to flush (aka
-               # ischar always returned true)
-
-sio_flush:     movb $1,%ch                     # let %cl be garbage
-1:             call sio_getc.1
-               call sio_ischar
-               loopnz 1b
-               ret
-
-# void sio_putc(int c)
-
-sio_putc:      movw $SIO_PRT+0x5,%dx           # Line status reg
-               movb $0x40,%ch                  # Timeout counter.  Allow %cl
-                                               # to contain garbage.
-sio_putc.1:    inb (%dx),%al                   # Transmitter buffer empty?
-               testb $0x20,%al
-               loopz sio_putc.1                # No
-               jz sio_putc.2                   # If timeout
-               movb 0x4(%esp,1),%al            # Get character
-               subb $0x5,%dl                   # Transmitter hold reg
-               outb %al,(%dx)                  # Write character
-sio_putc.2:    ret $0x4
-
-# int sio_getc(void)
-
-sio_getc:      call sio_ischar                 # Character available?
-               jz sio_getc                     # No
-sio_getc.1:    subb $0x5,%dl                   # Receiver buffer reg
-               inb (%dx),%al                   # Read character
-               ret
-
-# int sio_ischar(void)
-
-sio_ischar:    movw $SIO_PRT+0x5,%dx           # Line status register
-               xorl %eax,%eax                  # Zero
-               inb (%dx),%al                   # Received data ready?
-               andb $0x1,%al
-               ret
-
-               .globl inbser
-inbser:        movw $SIO_PRT+5,%dx
-               inb (%dx),%al
-               ret
diff --git a/sys/boot/i386/bootasm.h b/sys/boot/i386/bootasm.h
new file mode 100644 (file)
index 0000000..da8cefc
--- /dev/null
@@ -0,0 +1,78 @@
+/* 
+ * Copyright (c) 2004 The DragonFly Project.  All rights reserved.
+ * 
+ * This code is derived from software contributed to The DragonFly Project
+ * by Matthew Dillon <dillon@backplane.com>
+ * 
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in
+ *    the documentation and/or other materials provided with the
+ *    distribution.
+ * 3. Neither the name of The DragonFly Project nor the names of its
+ *    contributors may be used to endorse or promote products derived
+ *    from this software without specific, prior written permission.
+ * 
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+ * FOR A PARTICULAR PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE
+ * COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY OR CONSEQUENTIAL DAMAGES (INCLUDING,
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
+ * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
+ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ * $DragonFly: src/sys/boot/i386/Attic/bootasm.h,v 1.1 2004/07/18 23:39:55 dillon Exp $
+ */
+
+#define NHRDRV         0x475
+#define BOOT0_ORIGIN   0x600           /* boot0 relocated      */
+#define FAKE           0x800           /* Fake partition entry */
+#define LOAD           0x7c00          /* Load address         */
+
+#define MEM_ARG_SIZE   0x18
+#define MEM_PAGE_SIZE  0x1000
+
+#define MEM_REL                0x700           /* Relocation address   */
+#define MEM_ARG                0x900           /* Arguments            */
+#define MEM_ORG                0x7c00          /* Origin               */
+#define MEM_BUF                0x8c00          /* Load area            */
+#define MEM_BTX                0x9000          /* BTX start            */
+#define MEM_JMP                0x9010          /* BTX entry point      */
+#define MEM_USR                0xa000          /* Client start         */
+#define BDA_BOOT       0x472           /* Boot howto flag      */
+#define BDA_MEM                0x413           /* Free memory          */
+#define BDA_KEYFLAGS   0x417           /* Keyboard shift-state flags   */
+#define BDA_SCR                0x449           /* Video mode           */
+#define BDA_POS                0x450           /* Cursor position      */
+#define BDA_KEYBOARD   0x496           /* BDA byte with keyboard bit */
+
+#define MEM_BTX_START  0x1000          /* start of BTX memory */
+#define MEM_BTX_ESP0   0x1800          /* Supervisor stack */
+#define MEM_BTX_BUF    0x1800          /* Scratch buffer stack */
+#define MEM_BTX_ESP1   0x1e00          /* Link stack */
+#define MEM_BTX_IDT    0x1e00          /* IDT */
+#define MEM_BTX_TSS    0x1f98          /* TSS */
+#define MEM_BTX_MAP    0x2000          /* I/O bit map */
+#define MEM_BTX_DIR    0x4000          /* Page directory */
+#define MEM_BTX_TBL    0x5000          /* Page tables */
+#define MEM_BTX_ORG    0x9000          /* base of BTX code */
+#define MEM_BTX_ENTRY  0x9010          /* BTX starts execution here */
+#define MEM_BTX_USR    0xa000          /* base of BTX client/user memory */
+#define MEM_BTX_USR_ARG        0xa100
+#define MEM_BTX_LDR_OFF        MEM_PAGE_SIZE   /* offset of btx in the loader
+
+/*
+ * CDBOOT
+ */
+#define MEM_BTX_LDR_OFFSET     0x1000  /* Offset of BTX in the loader */
+
index 797f6bb..a13dab8 100644 (file)
@@ -1,10 +1,8 @@
 # $FreeBSD: src/sys/boot/i386/btx/btx/Makefile,v 1.13 2002/09/17 01:48:54 peter Exp $
-# $DragonFly: src/sys/boot/i386/btx/btx/Attic/Makefile,v 1.3 2003/11/10 06:08:35 dillon Exp $
-
-M4?=   m4
+# $DragonFly: src/sys/boot/i386/btx/btx/Attic/Makefile,v 1.4 2004/07/18 23:40:04 dillon Exp $
 
 .if defined(PAGING)
-M4FLAGS+=      -DPAGING
+AFLAGS+=       -DPAGING
 .endif
 
 .if defined(BOOT_BTX_NOHANG)
@@ -13,14 +11,14 @@ BOOT_BTX_FLAGS=0x1
 BOOT_BTX_FLAGS=0x0
 .endif
 
-AFLAGS+=       --defsym BTX_FLAGS=${BOOT_BTX_FLAGS}
+AFLAGS+=       -DBTX_FLAGS=${BOOT_BTX_FLAGS}
 
 .if defined(BTX_SERIAL)
 BOOT_COMCONSOLE_PORT?= 0x3f8
 BOOT_COMCONSOLE_SPEED?= 9600
 B2SIOFMT?=     0x3
 
-M4FLAGS+=      -DBTX_SERIAL -DSIOPRT=${BOOT_COMCONSOLE_PORT} \
+AFLAGS+=       -DBTX_SERIAL -DSIOPRT=${BOOT_COMCONSOLE_PORT} \
                -DSIOFMT=${B2SIOFMT} -DSIOSPD=${BOOT_COMCONSOLE_SPEED}
 .endif
 
@@ -32,9 +30,8 @@ btx: btx.o
        ${LD} -N -e start -Ttext ${ORG} -o btx.out btx.o
        objcopy -S -O binary btx.out ${.TARGET}
 
-btx.o: btx.s
-       (cd ${.CURDIR}; ${M4} ${M4FLAGS} btx.s) | \
-          ${AS} ${AFLAGS} -o ${.TARGET}
+btx.o: btx.S
+       ${CC} ${CFLAGS} ${AFLAGS} ${.IMPSRC} -o ${.TARGET} -c
 
 CLEANFILES+= btx btx.out btx.o
 
index b122a10..cd17e9c 100644 (file)
@@ -1,43 +1,32 @@
-#
-# 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.
-#
+/*
+ * 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: src/sys/boot/i386/btx/btx/btx.s,v 1.32 2002/10/08 18:19:02 jhb Exp $
+ * $DragonFly: src/sys/boot/i386/btx/btx/Attic/btx.S,v 1.5 2004/07/18 23:40:04 dillon Exp $
+ */
 
-# $FreeBSD: src/sys/boot/i386/btx/btx/btx.s,v 1.32 2002/10/08 18:19:02 jhb Exp $
-# $DragonFly: src/sys/boot/i386/btx/btx/Attic/btx.S,v 1.4 2004/06/24 23:31:06 dillon Exp $
+#include "../../bootasm.h"
 
-#
-# Memory layout.
-#
-               .set MEM_BTX,0x1000             # Start of BTX memory
-               .set MEM_ESP0,0x1800            # Supervisor stack
-               .set MEM_BUF,0x1800             # Scratch buffer
-               .set MEM_ESP1,0x1e00            # Link stack
-               .set MEM_IDT,0x1e00             # IDT
-               .set MEM_TSS,0x1f98             # TSS
-               .set MEM_MAP,0x2000             # I/O bit map
-               .set MEM_DIR,0x4000             # Page directory
-               .set MEM_TBL,0x5000             # Page tables
-               .set MEM_ORG,0x9000             # BTX code
-               .set MEM_USR,0xa000             # Start of user memory
-#
-# Paging control.
-#
+               /*
+                * Paging control.
+                */
                .set PAG_SIZ,0x1000             # Page size
                .set PAG_CNT,0x1000             # Pages to map
-#
-# Segment selectors.
-#
+
+               /*
+                * Segment selectors.
+                */
                .set SEL_SCODE,0x8              # Supervisor code
                .set SEL_SDATA,0x10             # Supervisor data
                .set SEL_RCODE,0x18             # Real mode code
                .set SEL_UCODE,0x28|3           # User code
                .set SEL_UDATA,0x30|3           # User data
                .set SEL_TSS,0x38               # TSS
-#
-# Task state segment fields.
-#
+
+               /*
+                * Task state segment fields.
+                */
                .set TSS_ESP0,0x4               # PL 0 ESP
                .set TSS_SS0,0x8                # PL 0 SS
                .set TSS_ESP1,0xc               # PL 1 ESP
                .set TSS_MAP,0x66               # I/O bit map base
-#
-# System calls.
-#
+
+               /*
+                * System calls.
+                */
                .set SYS_EXIT,0x0               # Exit
                .set SYS_EXEC,0x1               # Exec
-#
-# V86 constants.
-#
+
+               /*
+                * V86 constants.
+                */
                .set V86_FLG,0x208eff           # V86 flag mask
                .set V86_STK,0x400              # V86 stack allowance
-#
-# Dump format control bytes.
-#
+
+               /*
+                * Dump format control bytes.
+                */
                .set DMP_X16,0x1                # Word
                .set DMP_X32,0x2                # Long
                .set DMP_MEM,0x4                # Memory
                .set DMP_EOL,0x8                # End of line
-#
-# Screen defaults and assumptions.
-#
+
+               /*
+                * Screen defaults and assumptions.
+                */
                .set SCR_MAT,0x7                # Mode/attribute
                .set SCR_COL,0x50               # Columns per row
                .set SCR_ROW,0x19               # Rows per screen
-#
-# BIOS Data Area locations.
-#
-               .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
-#
-# Derivations, for brevity.
-#
-               .set _ESP0H,MEM_ESP0>>0x8       # Byte 1 of ESP0
-               .set _ESP1H,MEM_ESP1>>0x8       # Byte 1 of ESP1
-               .set _TSSIO,MEM_MAP-MEM_TSS     # TSS I/O base
-               .set _TSSLM,MEM_DIR-MEM_TSS-1   # TSS limit
-               .set _IDTLM,MEM_TSS-MEM_IDT-1   # IDT limit
-#
-# Code segment.
-#
+
+               /*
+                * Derivations, for brevity.
+                */
+               .set _ESP0H,MEM_BTX_ESP0>>0x8   # Byte 1 of ESP0
+               .set _ESP1H,MEM_BTX_ESP1>>0x8   # Byte 1 of ESP1
+               .set _TSSIO,MEM_BTX_MAP-MEM_BTX_TSS     # TSS I/O base
+               .set _TSSLM,MEM_BTX_DIR-MEM_BTX_TSS-1   # TSS limit
+               .set _IDTLM,MEM_BTX_TSS-MEM_BTX_IDT-1   # IDT limit
+
+               /*
+                * Code segment.
+                */
                .globl start
                .code16
 start:                                         # Start of code
-#
-# BTX header.
-#
+
+               /*
+                * BTX header.
+                */
 btx_hdr:       .byte 0xeb                      # Machine ID
                .byte 0xe                       # Header size
                .ascii "BTX"                    # Magic
                .byte 0x1                       # Major version
                .byte 0x1                       # Minor version
                .byte BTX_FLAGS                 # Flags
-               .word PAG_CNT-MEM_ORG>>0xc      # Paging control
+               .word PAG_CNT-MEM_BTX_ORG>>0xc  # Paging control
                .word break-start               # Text size
                .long 0x0                       # Entry address
-#
-# Initialization routine.
-#
+
+               /*
+                * Initialization routine.
+                */
 init:          cli                             # Disable interrupts
                xor %ax,%ax                     # Zero/segment
                mov %ax,%ss                     # Set up
-               mov $MEM_ESP0,%sp               #  stack
+               mov $MEM_BTX_ESP0,%sp           #  stack
                mov %ax,%es                     # Address
                mov %ax,%ds                     #  data
                pushl $0x2                      # Clear
                popfl                           #  flags
-#
-# Initialize memory.
-#
-               mov $MEM_IDT,%di                # Memory to initialize
-               mov $(MEM_ORG-MEM_IDT)/2,%cx    # Words to zero
+
+               /*
+                * Initialize memory.
+                */
+               mov $MEM_BTX_IDT,%di            # Memory to initialize
+               mov $(MEM_BTX_ORG-MEM_BTX_IDT)/2,%cx    # Words to zero
                push %di                        # Save
                rep                             # Zero-fill
                stosw                           #  memory
                pop %di                         # Restore
-#
-# Create IDT.
-#
+
+               /*
+                * Create IDT.
+                */
                mov $idtctl,%si                 # Control string
 init.1:        lodsb                           # Get entry
                cbw                             #  count
@@ -152,39 +144,41 @@ init.2:   shr %bx                         # Handle this int?
 init.3:        lea 0x8(%di),%di                # Next entry
                loop init.2                     # Till set done
                jmp init.1                      # Continue
-#
-# Initialize TSS.
-#
+
+               /*
+                * Initialize TSS.
+                */
 init.4:        movb $_ESP0H,TSS_ESP0+1(%di)    # Set ESP0
                movb $SEL_SDATA,TSS_SS0(%di)    # Set SS0
                movb $_ESP1H,TSS_ESP1+1(%di)    # Set ESP1
                movb $_TSSIO,TSS_MAP(%di)       # Set I/O bit map base
-ifdef(`PAGING',`
-#
-# Create page directory.
-#
+#ifdef PAGING
+               /*
+                * Create page directory.
+                */
                xor %edx,%edx                   # Page
                mov $PAG_SIZ>>0x8,%dh           #  size
                xor %eax,%eax                   # Zero
-               mov $MEM_DIR,%di                # Page directory
+               mov $MEM_BTX_DIR,%di            # Page directory
                mov $PAG_CNT>>0xa,%cl           # Entries
-               mov $MEM_TBL|0x7,%ax            # First entry
+               mov $MEM_BTX_TBL|0x7,%ax        # First entry
 init.5:        stosl                           # Write entry
                add %dx,%ax                     # To next
                loop init.5                     # Till done
-#
-# Create page tables.
-#
-               mov $MEM_TBL,%di                # Page table
+
+               /*
+                * Create page tables.
+                */
+               mov $MEM_BTX_TBL,%di            # Page table
                mov $PAG_CNT>>0x8,%ch           # Entries
                xor %ax,%ax                     # Start address
 init.6:        mov $0x7,%al                    # Set U:W:P flags
                cmp btx_hdr+0x8,%cx             # Standard user page?
                jb init.7                       # Yes
-               cmp $PAG_CNT-MEM_BTX>>0xc,%cx   # BTX memory?
+               cmp $PAG_CNT-MEM_BTX_START>>0xc,%cx     # BTX memory?
                jae init.7                      # No or first page
                and $~0x2,%al                   # Clear W flag
-               cmp $PAG_CNT-MEM_USR>>0xc,%cx   # User page zero?
+               cmp $PAG_CNT-MEM_BTX_USR>>0xc,%cx       # User page zero?
                jne init.7                      # No
                testb $0x80,btx_hdr+0x7         # Unmap it?
                jz init.7                       # No
@@ -192,37 +186,38 @@ init.6:   mov $0x7,%al                    # Set U:W:P flags
 init.7:        stosl                           # Set entry
                add %edx,%eax                   # Next address
                loop init.6                     # Till done
-')
-#
-# Bring up the system.
-#
+#endif
+               /*
+                * Bring up the system.
+                */
                mov $0x2820,%bx                 # Set protected mode
                callw setpic                    #  IRQ offsets
                lidt idtdesc                    # Set IDT
-ifdef(`PAGING',`
+#ifdef PAGING
                xor %eax,%eax                   # Set base
-               mov $MEM_DIR>>0x8,%ah           #  of page
+               mov $MEM_BTX_DIR>>0x8,%ah               #  of page
                mov %eax,%cr3                   #  directory
-')
+#endif
                lgdt gdtdesc                    # Set GDT
                mov %cr0,%eax                   # Switch to protected
-ifdef(`PAGING',`
+#ifdef PAGING
                or $0x80000001,%eax             #  mode and enable paging
-',`
+#else
                or $0x01,%eax                   #  mode
-')
+#endif
                mov %eax,%cr0                   #  
                ljmp $SEL_SCODE,$init.8         # To 32-bit code
                .code32
 init.8:        xorl %ecx,%ecx                  # Zero
                movb $SEL_SDATA,%cl             # To 32-bit
                movw %cx,%ss                    #  stack
-#
-# Launch user task.
-#
+
+               /*
+                * Launch user task.
+                */
                movb $SEL_TSS,%cl               # Set task
                ltr %cx                         #  register
-               movl $MEM_USR,%edx              # User base address
+               movl $MEM_BTX_USR,%edx          # User base address
                movzwl %ss:BDA_MEM,%eax         # Get free memory
                shll $0xa,%eax                  # To bytes
                subl $0x1000,%eax               # Less arg space
@@ -241,35 +236,39 @@ init.8:   xorl %ecx,%ecx                  # Zero
                movb $0x7,%cl                   # Set remaining
 init.9:                push $0x0                       #  general
                loop init.9                     #  registers
-ifdef(`BTX_SERIAL',`
+#ifdef BTX_SERIAL
                call sio_init                   # setup the serial console
-')
+#endif
                popa                            #  and initialize
                popl %es                        # Initialize
                popl %ds                        #  user
                popl %fs                        #  segment
                popl %gs                        #  registers
                iret                            # To user mode
-#
-# Exit routine.
-#
+
+               /*
+                * Exit routine.
+                */
 exit:          cli                             # Disable interrupts
-               movl $MEM_ESP0,%esp             # Clear stack
-#
-# Turn off paging.
-#
+               movl $MEM_BTX_ESP0,%esp         # Clear stack
+
+               /*
+                * Turn off paging.
+                */
                movl %cr0,%eax                  # Get CR0
                andl $~0x80000000,%eax          # Disable
                movl %eax,%cr0                  #  paging
                xorl %ecx,%ecx                  # Zero
                movl %ecx,%cr3                  # Flush TLB
-#
-# Restore the GDT in case we caught a kernel trap.
-#
+
+               /*
+                * Restore the GDT in case we caught a kernel trap.
+                */
                lgdt gdtdesc                    # Set GDT
-#
-# To 16 bits.
-#
+
+               /*
+                * To 16 bits.
+                */
                ljmpw $SEL_RCODE,$exit.1        # Reload CS
                .code16
 exit.1:        mov $SEL_RDATA,%cl              # 16-bit selector
@@ -278,9 +277,10 @@ exit.1:    mov $SEL_RDATA,%cl              # 16-bit selector
                mov %cx,%es                     #  remaining
                mov %cx,%fs                     #  segment
                mov %cx,%gs                     #  registers
-#
-# To real-address mode.
-#
+
+               /*
+                * To real-address mode.
+                */
                dec %ax                         # Switch to
                mov %eax,%cr0                   #  real mode
                ljmp $0x0,$exit.2               # Reload CS
@@ -290,17 +290,19 @@ exit.2:   xor %ax,%ax                     # Real mode segment
                mov $0x7008,%bx                 # Set real mode
                callw setpic                    #  IRQ offsets
                lidt ivtdesc                    # Set IVT
-#
-# Reboot or await reset.
-#
+
+               /*
+                * Reboot or await reset.
+                */
                sti                             # Enable interrupts
                testb $0x1,btx_hdr+0x7          # Reboot?
 exit.3:                jz exit.3                       # No
                movw $0x1234, BDA_BOOT          # Do a warm boot
                ljmp $0xf000,$0xfff0            # reboot the machine
-#
-# Set IRQ offsets by reprogramming 8259A PICs.
-#
+
+               /*
+                * Set IRQ offsets by reprogramming 8259A PICs.
+                */
 setpic:        in $0x21,%al                    # Save master
                push %ax                        #  IMR
                in $0xa1,%al                    # Save slave
@@ -325,13 +327,15 @@ setpic:   in $0x21,%al                    # Save master
                outb %al,$0x21                  #  IMR
                retw                            # To caller
                .code32
-#
-# Initiate return from V86 mode to user mode.
-#
+
+               /*
+                * Initiate return from V86 mode to user mode.
+                */
 inthlt:        hlt                             # To supervisor mode
-#
-# Exception jump table.
-#
+
+               /*
+                * Exception jump table.
+                */
 intx00:        push $0x0                       # Int 0x0: #DE
                jmp ex_noc                      # Divide error
                push $0x1                       # Int 0x1: #DB
@@ -360,20 +364,23 @@ intx00:   push $0x0                       # Int 0x0: #DE
                jmp except                      # Page fault
 intx10:        push $0x10                      # Int 0x10: #MF
                jmp ex_noc                      # Floating-point error
-#
-# Handle #GP exception.
-#
+
+               /*
+                * Handle #GP exception.
+                */
 ex_v86:        testb $0x2,0x12(%esp,1)         # V86 mode?
                jz except                       # No
                jmp v86mon                      # To monitor
-#
-# Save a zero error code.
-#
+
+               /*
+                * Save a zero error code.
+                */
 ex_noc:        pushl (%esp,1)                  # Duplicate int no
                movb $0x0,0x4(%esp,1)           # Fake error code
-#
-# Handle exception.
-#
+
+               /*
+                * Handle exception.
+                */
 except:        cld                             # String ops inc
                pushl %ds                       # Save
                pushl %es                       #  most
@@ -401,7 +408,7 @@ except.2:   push $SEL_SDATA                 # Set up
                popl %es                        #  data
                movl %esp,%ebx                  # Stack frame
                movl $dmpfmt,%esi               # Dump format string
-               movl $MEM_BUF,%edi              # Buffer
+               movl $MEM_BTX_BUF,%edi          # Buffer
                pushl %edi                      # Dump to
                call dump                       #  buffer
                popl %esi                       #  and
@@ -419,19 +426,20 @@ except.2: push $SEL_SDATA                 # Set up
 except.2a:     jmp exit                        # Exit
 except.3:      leal 0x8(%esp,1),%esp           # Discard err, int no
                iret                            # From interrupt
-#
-# Return to user mode from V86 mode.
-#
+
+               /*
+                * Return to user mode from V86 mode.
+                */
 intrtn:        cld                             # String ops inc
                pushl %ds                       # Address
                popl %es                        #  data
                leal 0x3c(%ebp),%edx            # V86 Segment registers
-               movl MEM_TSS+TSS_ESP1,%esi      # Link stack pointer
+               movl MEM_BTX_TSS+TSS_ESP1,%esi  # Link stack pointer
                lodsl                           # INT_V86 args pointer
                movl %esi,%ebx                  # Saved exception frame
                testl %eax,%eax                 # INT_V86 args?
                jz intrtn.2                     # No
-               movl $MEM_USR,%edi              # User base
+               movl $MEM_BTX_USR,%edi          # User base
                movl 0x1c(%esi),%ebx            # User ESP
                movl %eax,(%edi,%ebx,1)         # Restore to user stack
                leal 0x8(%edi,%eax,1),%edi      # Arg segment registers
@@ -453,7 +461,7 @@ intrtn.2:   movl %edx,%esi                  # Segment registers
                movb $0x5,%cl                   #  frame to
                rep                             #  supervisor
                movsl                           #  stack
-               movl %esi,MEM_TSS+TSS_ESP1      # Link stack pointer
+               movl %esi,MEM_BTX_TSS+TSS_ESP1  # Link stack pointer
                popa                            # Restore
                leal 0x8(%esp,1),%esp           # Discard err, int no
                popl %es                        # Restore
@@ -461,9 +469,10 @@ intrtn.2:  movl %edx,%esi                  # Segment registers
                popl %fs                        #  segment
                popl %gs                        #  registers
                iret                            # To user mode
-#
-# V86 monitor.
-#
+
+               /*
+                * V86 monitor.
+                */
 v86mon:        cld                             # String ops inc
                pushl $SEL_SDATA                # Set up for
                popl %ds                        #  flat addressing
@@ -527,93 +536,103 @@ v86mon.7:        subl %edi,%esi                  # From linear
                popa                            # Restore
                leal 0x8(%esp,1),%esp           # Discard int no, error
                iret                            # To V86 mode
-#
-# Emulate MOV EAX,CR0.
-#
+
+               /*
+                * Emulate MOV EAX,CR0.
+                */
 v86mov:        movl %cr0,%eax                  # CR0 to
                movl %eax,0x1c(%ebp)            #  saved EAX
                incl %esi                       # Adjust IP
-#
-# Return from emulating a 0x0f prefixed instruction
-#
+
+               /*
+                * Return from emulating a 0x0f prefixed instruction
+                */
 v86preret:     incl %esi                       # Adjust IP
                jmp v86mon.7                    # Finish up
-#
-# Emulate WBINVD
-#
+
+               /*
+                * Emulate WBINVD
+                */
 v86wbinvd:     wbinvd                          # Write back and invalidate
                                                #  cache
                jmp v86preret                   # Finish up
-#
-# Emulate WRMSR
-#
-v86wrmsr:      movl 0x18(%ebp),%ecx            # Get user's %ecx (MSR to write)
+               /*
+                * Emulate WRMSR
+                */
+v86wrmsr:      movl 0x18(%ebp),%ecx            # Get users %ecx (MSR to write)
                movl 0x14(%ebp),%edx            # Load the value
                movl 0x1c(%ebp),%eax            #  to write
                wrmsr                           # Write MSR
                jmp v86preret                   # Finish up
-#
-# Emulate RDMSR
-#
+
+               /*
+                * Emulate RDMSR
+                */
 v86rdmsr:      movl 0x18(%ebp),%ecx            # MSR to read
                rdmsr                           # Read the MSR
                movl %eax,0x1c(%ebp)            # Return the value of
                movl %edx,0x14(%ebp)            #  the MSR to the user
                jmp v86preret                   # Finish up
-#
-# Emulate CLI.
-#
+
+               /*
+                * Emulate CLI.
+                */
 v86cli:        andb $~0x2,0x31(%ebp)           # Clear IF
                jmp v86mon.7                    # Finish up
-#
-# Emulate STI.
-#
+
+               /*
+                * Emulate STI.
+                */
 v86sti:        orb $0x2,0x31(%ebp)             # Set IF
                jmp v86mon.7                    # Finish up
-#
-# Emulate PUSHF/PUSHFD.
-#
+
+               /*
+                * Emulate PUSHF/PUSHFD.
+                */
 v86pushf:      subl %ecx,%ebx                  # Adjust SP
                cmpb $0x4,%cl                   # 32-bit
                je v86pushf.1                   # Yes
-               data16                          # 16-bit
+               data16                          # 16-bit (STDALONE ON PURPOSE)
 v86pushf.1:    movl %edx,(%ebx)                # Save flags
                jmp v86mon.6                    # Finish up
-#
-# Emulate IRET/IRETD.
-#
+
+               /*
+                * Emulate IRET/IRETD.
+                */
 v86iret:       movzwl (%ebx),%esi              # Load V86 IP
                movzwl 0x2(%ebx),%edi           # Load V86 CS
                leal 0x4(%ebx),%ebx             # Adjust SP
                movl %edi,0x2c(%ebp)            # Save V86 CS
                xorl %edi,%edi                  # No ESI adjustment
-#
-# Emulate POPF/POPFD (and remainder of IRET/IRETD).
-#
+
+               /*
+                * Emulate POPF/POPFD (and remainder of IRET/IRETD).
+                */
 v86popf:       cmpb $0x4,%cl                   # 32-bit?
                je v86popf.1                    # Yes
                movl %edx,%eax                  # Initialize
-               data16                          # 16-bit
+               data16                          # 16-bit (STDALONE ON PURPOSE)
 v86popf.1:     movl (%ebx),%eax                # Load flags
                addl %ecx,%ebx                  # Adjust SP
                andl $V86_FLG,%eax              # Merge
                andl $~V86_FLG,%edx             #  the
                orl %eax,%edx                   #  flags
                jmp v86mon.5                    # Finish up
-#
-# trap int 15, function 87
-# reads %es:%si from saved registers on stack to find a GDT containing
-# source and destination locations
-# reads count of words from saved %cx
-# returns success by setting %ah to 0
-#
+
+               /*
+                * trap int 15, function 87
+                * reads %es:%si from saved registers on stack to find a 
+                * GDT containing source and destination locations reads
+                * count of words from saved %cx returns success by
+                * setting %ah to 0
+                */
 int15_87:      pushl %eax                      # Save 
                pushl %ebx                      #  some information 
                pushl %esi                      #  onto the stack.
                pushl %edi
                xorl %eax,%eax                  # clean EAX 
                xorl %ebx,%ebx                  # clean EBX 
-               movl 0x4(%ebp),%esi             # Get user's ESI
+               movl 0x4(%ebp),%esi             # Get users ESI
                movl 0x3C(%ebp),%ebx            # store ES
                movw %si,%ax                    # store SI
                shll $0x4,%ebx                  # Make it a seg.
@@ -632,7 +651,7 @@ int15_87:   pushl %eax                      # Save
                popl %es                        # es = ds
                pushl %ecx                      # stash ECX
                xorl %ecx,%ecx                  # highw of ECX is clear
-               movw 0x18(%ebp),%cx             # Get user's ECX
+               movw 0x18(%ebp),%cx             # Get users ECX
                shll $0x1,%ecx                  # Convert from num words to num
                                                #  bytes
                rep                             # repeat...
@@ -647,26 +666,27 @@ int15_87: pushl %eax                      # Save
                andb $0xfe,%dl                  # clear CF
                jmp v86mon.5                    # Finish up
 
-#
-# Reboot the machine by setting the reboot flag and exiting
-#
+               /*
+                * 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
-#
+               /*
+                * 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.3                   #  no, skip parse
                pushl %eax                      # stash EAX
-               movl 0x1c(%ebp),%eax            # user's saved EAX
+               movl 0x1c(%ebp),%eax            # users saved EAX
                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
+               jmp int15_87                    # its our cue
 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
@@ -689,9 +709,10 @@ v86intn.3: subl %edi,%esi                  # From
                xorl %edi,%edi                  # No ESI adjustment
                andb $~0x1,%dh                  # Clear TF
                jmp v86mon.5                    # Finish up
-#
-# Hardware interrupt jump table.
-#
+
+               /*
+                * Hardware interrupt jump table.
+                */
 intx20:        push $0x8                       # Int 0x20: IRQ0
                jmp int_hw                      # V86 int 0x8
                push $0x9                       # Int 0x21: IRQ1
@@ -724,9 +745,10 @@ intx20:    push $0x8                       # Int 0x20: IRQ0
                jmp int_hw                      # V86 int 0x76
                push $0x77                      # Int 0x2f: IRQ15
                jmp int_hw                      # V86 int 0x77
-#
-# Reflect hardware interrupts.
-#
+
+               /*
+                * Reflect hardware interrupts.
+                */
 int_hw:        testb $0x2,0xe(%esp,1)          # V86 mode?
                jz intusr                       # No
                pushl $SEL_SDATA                # Address
@@ -753,14 +775,16 @@ int_hw:   testb $0x2,0xe(%esp,1)          # V86 mode?
                popl %ebp                       #  saved
                popl %eax                       #  registers
                iret                            # To V86 mode
-#
-# Invoke V86 interrupt from user mode, with arguments.
-#
+
+               /*
+                * Invoke V86 interrupt from user mode, with arguments.
+                */
 intx31:        stc                             # Have btx_v86
                pushl %eax                      # Missing int no
-#
-# Invoke V86 interrupt from user mode.
-#
+
+               /*
+                * Invoke V86 interrupt from user mode.
+                */
 intusr:        std                             # String ops dec
                pushl %eax                      # Expand
                pushl %eax                      #  stack
@@ -775,7 +799,7 @@ intusr:     std                             # String ops dec
                popl %ds                        #  to
                pushl %ds                       #  address
                popl %es                        #  data
-               movl $MEM_USR,%ebx              # User base
+               movl $MEM_BTX_USR,%ebx          # User base
                movl %ebx,%edx                  #  address
                jc intusr.1                     # If btx_v86
                xorl %edx,%edx                  # Control flags
@@ -783,7 +807,7 @@ intusr:     std                             # String ops dec
 intusr.1:      leal 0x50(%esp,1),%esi          # Base of frame
                pushl %esi                      # Save
                addl -0x4(%esi),%ebx            # User ESP
-               movl MEM_TSS+TSS_ESP1,%edi      # Link stack pointer
+               movl MEM_BTX_TSS+TSS_ESP1,%edi  # Link stack pointer
                leal -0x4(%edi),%edi            # Adjust for push
                xorl %ecx,%ecx                  # Zero
                movb $0x5,%cl                   # Push exception
@@ -803,7 +827,7 @@ intusr.1:   leal 0x50(%esp,1),%esi          # Base of frame
                movl 0x4(%edx),%eax             # Get int no/address
                movzwl 0x2(%edx),%edx           # Get control flags
 intusr.2:      movl %ebp,(%edi)                # Push btx_v86 and
-               movl %edi,MEM_TSS+TSS_ESP1      #  save link stack ptr
+               movl %edi,MEM_BTX_TSS+TSS_ESP1  #  save link stack ptr
                popl %edi                       # Base of frame
                xchgl %eax,%ebp                 # Save intno/address
                movl 0x48(%esp,1),%eax          # Get flags
@@ -845,9 +869,10 @@ intusr.5:  movl %eax,%ecx                  # Save
                leal 0x10(%esp,1),%esp          # Discard seg regs
                popa                            # Restore
                iret                            # To V86 mode
-#
-# System Call.
-#
+
+               /*
+                * System Call.
+                */
 intx30:        cmpl $SYS_EXEC,%eax             # Exec system call?
                jne intx30.1                    # No
                pushl %ss                       # Set up
@@ -856,25 +881,26 @@ intx30:   cmpl $SYS_EXEC,%eax             # Exec system call?
                popl %ds                        #  registers
                pushl %ds                       #  for the
                popl %fs                        #  program
-               pushl %fs                       #  we're
+               pushl %fs                       #  were
                popl %gs                        #  invoking
-               movl $MEM_USR,%eax              # User base address
+               movl $MEM_BTX_USR,%eax          # User base address
                addl 0xc(%esp,1),%eax           # Change to user
                leal 0x4(%eax),%esp             #  stack
-ifdef(`PAGING',`
+#ifdef PAGING
                movl %cr0,%eax                  # Turn
                andl $~0x80000000,%eax          #  off
                movl %eax,%cr0                  #  paging
                xorl %eax,%eax                  # Flush
                movl %eax,%cr3                  #  TLB
-')
+#endif
                popl %eax                       # Call
                call *%eax                      #  program
 intx30.1:      orb $0x1,%ss:btx_hdr+0x7        # Flag reboot
                jmp exit                        # Exit
-#
-# Dump structure [EBX] to [EDI], using format string [ESI].
-#
+
+               /*
+                * Dump structure [EBX] to [EDI], using format string [ESI].
+                */
 dump.0:        stosb                           # Save char
 dump:          lodsb                           # Load char
                testb %al,%al                   # End of string?
@@ -883,7 +909,7 @@ dump:               lodsb                           # Load char
                jz dump.0                       # No
                movb %al,%ch                    # Save control
                movb $'=',%al                   # Append
-               stosb                           #  '='
+               stosb                           #  "="
                lodsb                           # Get offset
                pushl %esi                      # Save
                movsbl %al,%esi                 # To
@@ -943,9 +969,10 @@ dump.8:    popl %esi                       # Restore
 dump.9:        jmp dump.0                      # Continue
 dump.10:       stosb                           # Terminate string
                ret                             # To caller
-#
-# Convert EAX, AX, or AL to hex, saving the result to [EDI].
-#
+
+               /*
+                * Convert EAX, AX, or AL to hex, saving the result to [EDI].
+                */
 hex32:         pushl %eax                      # Save
                shrl $0x10,%eax                 # Do upper
                call hex16                      #  16
@@ -963,21 +990,23 @@ hex8.1:   andb $0xf,%al                   # Get lower 4
                orb $0x20,%al                   # To lower case
                stosb                           # Save char
                ret                             # (Recursive)
-#
-# Output zero-terminated string [ESI] to the console.
-#
+
+               /*
+                * Output zero-terminated string [ESI] to the console.
+                */
 putstr.0:      call putchr                     # Output char
 putstr:        lodsb                           # Load char
                testb %al,%al                   # End of string?
                jnz putstr.0                    # No
                ret                             # To caller
-ifdef(`BTX_SERIAL',`
+#ifdef BTX_SERIAL
                .set SIO_PRT,SIOPRT             # Base port
                .set SIO_FMT,SIOFMT             # 8N1
                .set SIO_DIV,(115200/SIOSPD)    # 115200 / SPD
 
-# void sio_init(void)
-
+               /* 
+                * void sio_init(void) 
+                */
 sio_init:      movw $SIO_PRT+0x3,%dx           # Data format reg
                movb $SIO_FMT|0x80,%al          # Set format
                outb %al,(%dx)                  #  and DLAB
@@ -993,15 +1022,17 @@ sio_init:        movw $SIO_PRT+0x3,%dx           # Data format reg
                outb %al,(%dx)                  #  DTR
                incl %edx                       # Line status reg
 
-# void sio_flush(void)
-
+               /*
+                * void sio_flush(void)
+                */
 sio_flush.0:   call sio_getc.1                 # Get character
 sio_flush:     call sio_ischar                 # Check for character
                jnz sio_flush.0                 # Till none
                ret                             # To caller
 
-# void sio_putc(int c)
-
+               /*
+                * void sio_putc(int c)
+                */
 sio_putc:      movw $SIO_PRT+0x5,%dx           # Line status reg
                xor %ecx,%ecx                   # Timeout
                movb $0x40,%ch                  #  counter
@@ -1014,25 +1045,27 @@ sio_putc.1:     inb (%dx),%al                   # Transmitter
                outb %al,(%dx)                  # Write character
 sio_putc.2:    ret $0x4                        # To caller
 
-# int sio_getc(void)
-
+               /*
+                * int sio_getc(void)
+                */
 sio_getc:      call sio_ischar                 # Character available?
                jz sio_getc                     # No
 sio_getc.1:    subb $0x5,%dl                   # Receiver buffer reg
                inb (%dx),%al                   # Read character
                ret                             # To caller
 
-# int sio_ischar(void)
-
+               /*
+                * int sio_ischar(void)
+                */
 sio_ischar:    movw $SIO_PRT+0x5,%dx           # Line status register
                xorl %eax,%eax                  # Zero
                inb (%dx),%al                   # Received data
                andb $0x1,%al                   #  ready?
                ret                             # To caller
 
-#
-# Output character AL to the serial console.
-#
+               /*
+                * Output character AL to the serial console.
+                */
 putchr:        pusha                           # Save
                cmpb $10, %al                   # is it a newline?
                jne putchr.1                    #  no?, then leave
@@ -1044,10 +1077,10 @@ putchr.1:       pushl %eax                      # Push the character
                call sio_putc                   # Output the character
                popa                            # Restore
                ret                             # To caller
-',`
-#
-# Output character AL to the console.
-#
+#else
+               /*
+                * Output character AL to the console.
+                */
 putchr:        pusha                           # Save
                xorl %ecx,%ecx                  # Zero for loops
                movb $SCR_MAT,%ah               # Mode/attribute
@@ -1086,30 +1119,31 @@ putchr.3:       cmpb $SCR_ROW,%dh               # Beyond screen?
 putchr.4:      movw %dx,(%ebx)                 # Update position
                popa                            # Restore
                ret                             # To caller
-')
+#endif
 
+               /*
+                * Global descriptor table.
+                */
                .p2align 4
-#
-# Global descriptor table.
-#
 gdt:           .word 0x0,0x0,0x0,0x0           # Null entry
                .word 0xffff,0x0,0x9a00,0xcf    # SEL_SCODE
                .word 0xffff,0x0,0x9200,0xcf    # SEL_SDATA
                .word 0xffff,0x0,0x9a00,0x0     # SEL_RCODE
                .word 0xffff,0x0,0x9200,0x0     # SEL_RDATA
-               .word 0xffff,MEM_USR,0xfa00,0xcf# SEL_UCODE
-               .word 0xffff,MEM_USR,0xf200,0xcf# SEL_UDATA
-               .word _TSSLM,MEM_TSS,0x8900,0x0 # SEL_TSS
+               .word 0xffff,MEM_BTX_USR,0xfa00,0xcf# SEL_UCODE
+               .word 0xffff,MEM_BTX_USR,0xf200,0xcf# SEL_UDATA
+               .word _TSSLM,MEM_BTX_TSS,0x8900,0x0 # SEL_TSS
 gdt.1:
-#
-# Pseudo-descriptors.
-#
+               /*
+                * Pseudo-descriptors.
+                */
 gdtdesc:       .word gdt.1-gdt-1,gdt,0x0       # GDT
-idtdesc:       .word _IDTLM,MEM_IDT,0x0        # IDT
+idtdesc:       .word _IDTLM,MEM_BTX_IDT,0x0    # IDT
 ivtdesc:       .word 0x400-0x0-1,0x0,0x0       # IVT
-#
-# IDT construction control string.
-#
+
+               /*
+                * IDT construction control string.
+                */
 idtctl:        .byte 0x10,  0x8e               # Int 0x0-0xf
                .word 0x7dfb,intx00             #  (exceptions)
                .byte 0x10,  0x8e               # Int 0x10
@@ -1121,9 +1155,10 @@ idtctl:  .byte 0x10,  0x8e               # Int 0x0-0xf
                .byte 0x2,   0xee               # Int 0x31-0x32
                .word 0x1,   intx31             #  (V86, null)
                .byte 0x0                       # End of string
-#
-# Dump format string.
-#
+
+               /*
+                * Dump format string.
+                */
 dmpfmt:        .byte '\n'                      # "\n"
                .ascii "int"                    # "int="
                .byte 0x80|DMP_X32,        0x40 # "00000000  "
@@ -1167,8 +1202,9 @@ dmpfmt:   .byte '\n'                      # "\n"
                .ascii "ss:esp"                 # "ss:esp="
                .byte 0x80|DMP_MEM|DMP_EOL,0x0  # "00 00 ... 00 00\n"
                .asciz "BTX halted\n"           # End
-#
-# End of BTX memory.
-#
+
+               /*
+                * End of BTX memory.
+                */
                .p2align 4
 break:
diff --git a/sys/boot/i386/btx/btx/btx.s b/sys/boot/i386/btx/btx/btx.s
deleted file mode 100644 (file)
index 27c08a4..0000000
+++ /dev/null
@@ -1,1174 +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: src/sys/boot/i386/btx/btx/btx.s,v 1.32 2002/10/08 18:19:02 jhb Exp $
-# $DragonFly: src/sys/boot/i386/btx/btx/Attic/btx.s,v 1.4 2004/06/24 23:31:06 dillon Exp $
-
-#
-# Memory layout.
-#
-               .set MEM_BTX,0x1000             # Start of BTX memory
-               .set MEM_ESP0,0x1800            # Supervisor stack
-               .set MEM_BUF,0x1800             # Scratch buffer
-               .set MEM_ESP1,0x1e00            # Link stack
-               .set MEM_IDT,0x1e00             # IDT
-               .set MEM_TSS,0x1f98             # TSS
-               .set MEM_MAP,0x2000             # I/O bit map
-               .set MEM_DIR,0x4000             # Page directory
-               .set MEM_TBL,0x5000             # Page tables
-               .set MEM_ORG,0x9000             # BTX code
-               .set MEM_USR,0xa000             # Start of user memory
-#
-# Paging control.
-#
-               .set PAG_SIZ,0x1000             # Page size
-               .set PAG_CNT,0x1000             # Pages to map
-#
-# Segment selectors.
-#
-               .set SEL_SCODE,0x8              # Supervisor code
-               .set SEL_SDATA,0x10             # Supervisor data
-               .set SEL_RCODE,0x18             # Real mode code
-               .set SEL_RDATA,0x20             # Real mode data
-               .set SEL_UCODE,0x28|3           # User code
-               .set SEL_UDATA,0x30|3           # User data
-               .set SEL_TSS,0x38               # TSS
-#
-# Task state segment fields.
-#
-               .set TSS_ESP0,0x4               # PL 0 ESP
-               .set TSS_SS0,0x8                # PL 0 SS
-               .set TSS_ESP1,0xc               # PL 1 ESP
-               .set TSS_MAP,0x66               # I/O bit map base
-#
-# System calls.
-#
-               .set SYS_EXIT,0x0               # Exit
-               .set SYS_EXEC,0x1               # Exec
-#
-# V86 constants.
-#
-               .set V86_FLG,0x208eff           # V86 flag mask
-               .set V86_STK,0x400              # V86 stack allowance
-#
-# Dump format control bytes.
-#
-               .set DMP_X16,0x1                # Word
-               .set DMP_X32,0x2                # Long
-               .set DMP_MEM,0x4                # Memory
-               .set DMP_EOL,0x8                # End of line
-#
-# Screen defaults and assumptions.
-#
-               .set SCR_MAT,0x7                # Mode/attribute
-               .set SCR_COL,0x50               # Columns per row
-               .set SCR_ROW,0x19               # Rows per screen
-#
-# BIOS Data Area locations.
-#
-               .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
-#
-# Derivations, for brevity.
-#
-               .set _ESP0H,MEM_ESP0>>0x8       # Byte 1 of ESP0
-               .set _ESP1H,MEM_ESP1>>0x8       # Byte 1 of ESP1
-               .set _TSSIO,MEM_MAP-MEM_TSS     # TSS I/O base
-               .set _TSSLM,MEM_DIR-MEM_TSS-1   # TSS limit
-               .set _IDTLM,MEM_TSS-MEM_IDT-1   # IDT limit
-#
-# Code segment.
-#
-               .globl start
-               .code16
-start:                                         # Start of code
-#
-# BTX header.
-#
-btx_hdr:       .byte 0xeb                      # Machine ID
-               .byte 0xe                       # Header size
-               .ascii "BTX"                    # Magic
-               .byte 0x1                       # Major version
-               .byte 0x1                       # Minor version
-               .byte BTX_FLAGS                 # Flags
-               .word PAG_CNT-MEM_ORG>>0xc      # Paging control
-               .word break-start               # Text size
-               .long 0x0                       # Entry address
-#
-# Initialization routine.
-#
-init:          cli                             # Disable interrupts
-               xor %ax,%ax                     # Zero/segment
-               mov %ax,%ss                     # Set up
-               mov $MEM_ESP0,%sp               #  stack
-               mov %ax,%es                     # Address
-               mov %ax,%ds                     #  data
-               pushl $0x2                      # Clear
-               popfl                           #  flags
-#
-# Initialize memory.
-#
-               mov $MEM_IDT,%di                # Memory to initialize
-               mov $(MEM_ORG-MEM_IDT)/2,%cx    # Words to zero
-               push %di                        # Save
-               rep                             # Zero-fill
-               stosw                           #  memory
-               pop %di                         # Restore
-#
-# Create IDT.
-#
-               mov $idtctl,%si                 # Control string
-init.1:        lodsb                           # Get entry
-               cbw                             #  count
-               xchg %ax,%cx                    #  as word
-               jcxz init.4                     # If done
-               lodsb                           # Get segment
-               xchg %ax,%dx                    #  P:DPL:type
-               lodsw                           # Get control
-               xchg %ax,%bx                    #  set
-               lodsw                           # Get handler offset
-               mov $SEL_SCODE,%dh              # Segment selector
-init.2:        shr %bx                         # Handle this int?
-               jnc init.3                      # No
-               mov %ax,(%di)                   # Set handler offset
-               mov %dh,0x2(%di)                #  and selector
-               mov %dl,0x5(%di)                # Set P:DPL:type
-               add $0x4,%ax                    # Next handler
-init.3:        lea 0x8(%di),%di                # Next entry
-               loop init.2                     # Till set done
-               jmp init.1                      # Continue
-#
-# Initialize TSS.
-#
-init.4:        movb $_ESP0H,TSS_ESP0+1(%di)    # Set ESP0
-               movb $SEL_SDATA,TSS_SS0(%di)    # Set SS0
-               movb $_ESP1H,TSS_ESP1+1(%di)    # Set ESP1
-               movb $_TSSIO,TSS_MAP(%di)       # Set I/O bit map base
-ifdef(`PAGING',`
-#
-# Create page directory.
-#
-               xor %edx,%edx                   # Page
-               mov $PAG_SIZ>>0x8,%dh           #  size
-               xor %eax,%eax                   # Zero
-               mov $MEM_DIR,%di                # Page directory
-               mov $PAG_CNT>>0xa,%cl           # Entries
-               mov $MEM_TBL|0x7,%ax            # First entry
-init.5:        stosl                           # Write entry
-               add %dx,%ax                     # To next
-               loop init.5                     # Till done
-#
-# Create page tables.
-#
-               mov $MEM_TBL,%di                # Page table
-               mov $PAG_CNT>>0x8,%ch           # Entries
-               xor %ax,%ax                     # Start address
-init.6:        mov $0x7,%al                    # Set U:W:P flags
-               cmp btx_hdr+0x8,%cx             # Standard user page?
-               jb init.7                       # Yes
-               cmp $PAG_CNT-MEM_BTX>>0xc,%cx   # BTX memory?
-               jae init.7                      # No or first page
-               and $~0x2,%al                   # Clear W flag
-               cmp $PAG_CNT-MEM_USR>>0xc,%cx   # User page zero?
-               jne init.7                      # No
-               testb $0x80,btx_hdr+0x7         # Unmap it?
-               jz init.7                       # No
-               and $~0x1,%al                   # Clear P flag
-init.7:        stosl                           # Set entry
-               add %edx,%eax                   # Next address
-               loop init.6                     # Till done
-')
-#
-# Bring up the system.
-#
-               mov $0x2820,%bx                 # Set protected mode
-               callw setpic                    #  IRQ offsets
-               lidt idtdesc                    # Set IDT
-ifdef(`PAGING',`
-               xor %eax,%eax                   # Set base
-               mov $MEM_DIR>>0x8,%ah           #  of page
-               mov %eax,%cr3                   #  directory
-')
-               lgdt gdtdesc                    # Set GDT
-               mov %cr0,%eax                   # Switch to protected
-ifdef(`PAGING',`
-               or $0x80000001,%eax             #  mode and enable paging
-',`
-               or $0x01,%eax                   #  mode
-')
-               mov %eax,%cr0                   #  
-               ljmp $SEL_SCODE,$init.8         # To 32-bit code
-               .code32
-init.8:        xorl %ecx,%ecx                  # Zero
-               movb $SEL_SDATA,%cl             # To 32-bit
-               movw %cx,%ss                    #  stack
-#
-# Launch user task.
-#
-               movb $SEL_TSS,%cl               # Set task
-               ltr %cx                         #  register
-               movl $MEM_USR,%edx              # User base address
-               movzwl %ss:BDA_MEM,%eax         # Get free memory
-               shll $0xa,%eax                  # To bytes
-               subl $0x1000,%eax               # Less arg space
-               subl %edx,%eax                  # Less base
-               movb $SEL_UDATA,%cl             # User data selector
-               pushl %ecx                      # Set SS
-               pushl %eax                      # Set ESP
-               push $0x202                     # Set flags (IF set)
-               push $SEL_UCODE                 # Set CS
-               pushl btx_hdr+0xc               # Set EIP
-               pushl %ecx                      # Set GS
-               pushl %ecx                      # Set FS
-               pushl %ecx                      # Set DS
-               pushl %ecx                      # Set ES
-               pushl %edx                      # Set EAX
-               movb $0x7,%cl                   # Set remaining
-init.9:                push $0x0                       #  general
-               loop init.9                     #  registers
-ifdef(`BTX_SERIAL',`
-               call sio_init                   # setup the serial console
-')
-               popa                            #  and initialize
-               popl %es                        # Initialize
-               popl %ds                        #  user
-               popl %fs                        #  segment
-               popl %gs                        #  registers
-               iret                            # To user mode
-#
-# Exit routine.
-#
-exit:          cli                             # Disable interrupts
-               movl $MEM_ESP0,%esp             # Clear stack
-#
-# Turn off paging.
-#
-               movl %cr0,%eax                  # Get CR0
-               andl $~0x80000000,%eax          # Disable
-               movl %eax,%cr0                  #  paging
-               xorl %ecx,%ecx                  # Zero
-               movl %ecx,%cr3                  # Flush TLB
-#
-# Restore the GDT in case we caught a kernel trap.
-#
-               lgdt gdtdesc                    # Set GDT
-#
-# To 16 bits.
-#
-               ljmpw $SEL_RCODE,$exit.1        # Reload CS
-               .code16
-exit.1:        mov $SEL_RDATA,%cl              # 16-bit selector
-               mov %cx,%ss                     # Reload SS
-               mov %cx,%ds                     # Load
-               mov %cx,%es                     #  remaining
-               mov %cx,%fs                     #  segment
-               mov %cx,%gs                     #  registers
-#
-# To real-address mode.
-#
-               dec %ax                         # Switch to
-               mov %eax,%cr0                   #  real mode
-               ljmp $0x0,$exit.2               # Reload CS
-exit.2:        xor %ax,%ax                     # Real mode segment
-               mov %ax,%ss                     # Reload SS
-               mov %ax,%ds                     # Address data
-               mov $0x7008,%bx                 # Set real mode
-               callw setpic                    #  IRQ offsets
-               lidt ivtdesc                    # Set IVT
-#
-# Reboot or await reset.
-#
-               sti                             # Enable interrupts
-               testb $0x1,btx_hdr+0x7          # Reboot?
-exit.3:                jz exit.3                       # No
-               movw $0x1234, BDA_BOOT          # Do a warm boot
-               ljmp $0xf000,$0xfff0            # reboot the machine
-#
-# Set IRQ offsets by reprogramming 8259A PICs.
-#
-setpic:        in $0x21,%al                    # Save master
-               push %ax                        #  IMR
-               in $0xa1,%al                    # Save slave
-               push %ax                        #  IMR
-               movb $0x11,%al                  # ICW1 to
-               outb %al,$0x20                  #  master,
-               outb %al,$0xa0                  #  slave
-               movb %bl,%al                    # ICW2 to
-               outb %al,$0x21                  #  master
-               movb %bh,%al                    # ICW2 to
-               outb %al,$0xa1                  #  slave
-               movb $0x4,%al                   # ICW3 to
-               outb %al,$0x21                  #  master
-               movb $0x2,%al                   # ICW3 to
-               outb %al,$0xa1                  #  slave
-               movb $0x1,%al                   # ICW4 to
-               outb %al,$0x21                  #  master,
-               outb %al,$0xa1                  #  slave
-               pop %ax                         # Restore slave
-               outb %al,$0xa1                  #  IMR
-               pop %ax                         # Restore master
-               outb %al,$0x21                  #  IMR
-               retw                            # To caller
-               .code32
-#
-# Initiate return from V86 mode to user mode.
-#
-inthlt:        hlt                             # To supervisor mode
-#
-# Exception jump table.
-#
-intx00:        push $0x0                       # Int 0x0: #DE
-               jmp ex_noc                      # Divide error
-               push $0x1                       # Int 0x1: #DB
-               jmp ex_noc                      # Debug
-               push $0x3                       # Int 0x3: #BP
-               jmp ex_noc                      # Breakpoint
-               push $0x4                       # Int 0x4: #OF
-               jmp ex_noc                      # Overflow
-               push $0x5                       # Int 0x5: #BR
-               jmp ex_noc                      # BOUND range exceeded
-               push $0x6                       # Int 0x6: #UD
-               jmp ex_noc                      # Invalid opcode
-               push $0x7                       # Int 0x7: #NM
-               jmp ex_noc                      # Device not available
-               push $0x8                       # Int 0x8: #DF
-               jmp except                      # Double fault
-               push $0xa                       # Int 0xa: #TS
-               jmp except                      # Invalid TSS
-               push $0xb                       # Int 0xb: #NP
-               jmp except                      # Segment not present
-               push $0xc                       # Int 0xc: #SS
-               jmp except                      # Stack segment fault
-               push $0xd                       # Int 0xd: #GP
-               jmp ex_v86                      # General protection
-               push $0xe                       # Int 0xe: #PF
-               jmp except                      # Page fault
-intx10:        push $0x10                      # Int 0x10: #MF
-               jmp ex_noc                      # Floating-point error
-#
-# Handle #GP exception.
-#
-ex_v86:        testb $0x2,0x12(%esp,1)         # V86 mode?
-               jz except                       # No
-               jmp v86mon                      # To monitor
-#
-# Save a zero error code.
-#
-ex_noc:        pushl (%esp,1)                  # Duplicate int no
-               movb $0x0,0x4(%esp,1)           # Fake error code
-#
-# Handle exception.
-#
-except:        cld                             # String ops inc
-               pushl %ds                       # Save
-               pushl %es                       #  most
-               pusha                           #  registers
-               movb $0x6,%al                   # Push loop count
-               testb $0x2,0x3a(%esp,1)         # V86 mode?
-               jnz except.1                    # Yes
-               pushl %gs                       # Set GS
-               pushl %fs                       # Set FS
-               pushl %ds                       # Set DS
-               pushl %es                       # Set ES
-               movb $0x2,%al                   # Push loop count
-               cmpw $SEL_SCODE,0x44(%esp,1)    # Supervisor mode?
-               jne except.1                    # No
-               pushl %ss                       # Set SS
-               leal 0x50(%esp,1),%eax          # Set
-               pushl %eax                      #  ESP
-               jmp except.2                    # Join common code
-except.1:      pushl 0x50(%esp,1)              # Set GS, FS, DS, ES
-               decb %al                        #  (if V86 mode), and
-               jne except.1                    #  SS, ESP
-except.2:      push $SEL_SDATA                 # Set up
-               popl %ds                        #  to
-               pushl %ds                       #  address
-               popl %es                        #  data
-               movl %esp,%ebx                  # Stack frame
-               movl $dmpfmt,%esi               # Dump format string
-               movl $MEM_BUF,%edi              # Buffer
-               pushl %edi                      # Dump to
-               call dump                       #  buffer
-               popl %esi                       #  and
-               call putstr                     #  display
-               leal 0x18(%esp,1),%esp          # Discard frame
-               popa                            # Restore
-               popl %es                        #  registers
-               popl %ds                        #  saved
-               cmpb $0x3,(%esp,1)              # Breakpoint?
-               je except.3                     # Yes
-               cmpb $0x1,(%esp,1)              # Debug?
-               jne except.2a                   # No
-               testl $0x100,0x10(%esp,1)       # Trap flag set?
-               jnz except.3                    # Yes
-except.2a:     jmp exit                        # Exit
-except.3:      leal 0x8(%esp,1),%esp           # Discard err, int no
-               iret                            # From interrupt
-#
-# Return to user mode from V86 mode.
-#
-intrtn:        cld                             # String ops inc
-               pushl %ds                       # Address
-               popl %es                        #  data
-               leal 0x3c(%ebp),%edx            # V86 Segment registers
-               movl MEM_TSS+TSS_ESP1,%esi      # Link stack pointer
-               lodsl                           # INT_V86 args pointer
-               movl %esi,%ebx                  # Saved exception frame
-               testl %eax,%eax                 # INT_V86 args?
-               jz intrtn.2                     # No
-               movl $MEM_USR,%edi              # User base
-               movl 0x1c(%esi),%ebx            # User ESP
-               movl %eax,(%edi,%ebx,1)         # Restore to user stack
-               leal 0x8(%edi,%eax,1),%edi      # Arg segment registers
-               testb $0x4,-0x6(%edi)           # Return flags?
-               jz intrtn.1                     # No
-               movl 0x30(%ebp),%eax            # Get V86 flags
-               movw %ax,0x18(%esi)             # Set user flags
-intrtn.1:      leal 0x10(%esi),%ebx            # Saved exception frame
-               xchgl %edx,%esi                 # Segment registers
-               movb $0x4,%cl                   # Update seg regs
-               rep                             #  in INT_V86
-               movsl                           #  args
-intrtn.2:      movl %edx,%esi                  # Segment registers
-               leal 0x28(%ebp),%edi            # Set up seg
-               movb $0x4,%cl                   #  regs for
-               rep                             #  later
-               movsl                           #  pop
-               movl %ebx,%esi                  # Restore exception
-               movb $0x5,%cl                   #  frame to
-               rep                             #  supervisor
-               movsl                           #  stack
-               movl %esi,MEM_TSS+TSS_ESP1      # Link stack pointer
-               popa                            # Restore
-               leal 0x8(%esp,1),%esp           # Discard err, int no
-               popl %es                        # Restore
-               popl %ds                        #  user
-               popl %fs                        #  segment
-               popl %gs                        #  registers
-               iret                            # To user mode
-#
-# V86 monitor.
-#
-v86mon:        cld                             # String ops inc
-               pushl $SEL_SDATA                # Set up for
-               popl %ds                        #  flat addressing
-               pusha                           # Save registers
-               movl %esp,%ebp                  # Address stack frame
-               movzwl 0x2c(%ebp),%edi          # Load V86 CS
-               shll $0x4,%edi                  # To linear
-               movl 0x28(%ebp),%esi            # Load V86 IP
-               addl %edi,%esi                  # Code pointer
-               xorl %ecx,%ecx                  # Zero
-               movb $0x2,%cl                   # 16-bit operands
-               xorl %eax,%eax                  # Zero
-v86mon.1:      lodsb                           # Get opcode
-               cmpb $0x66,%al                  # Operand size prefix?
-               jne v86mon.2                    # No
-               movb $0x4,%cl                   # 32-bit operands
-               jmp v86mon.1                    # Continue
-v86mon.2:      cmpb $0xf4,%al                  # HLT?
-               jne v86mon.3                    # No
-               cmpl $inthlt+0x1,%esi           # Is inthlt?
-               jne v86mon.7                    # No (ignore)
-               jmp intrtn                      # Return to user mode
-v86mon.3:      cmpb $0xf,%al                   # Prefixed instruction?
-               jne v86mon.4                    # No
-               cmpb $0x09,(%esi)               # Is it a WBINVD?
-               je v86wbinvd                    # Yes
-               cmpb $0x30,(%esi)               # Is it a WRMSR?
-               je v86wrmsr                     # Yes
-               cmpb $0x32,(%esi)               # Is it a RDMSR?
-               je v86rdmsr                     # Yes
-               cmpb $0x20,(%esi)               # Is this a
-               jne v86mon.4                    #  MOV EAX,CR0
-               cmpb $0xc0,0x1(%esi)            #  instruction?
-               je v86mov                       # Yes
-v86mon.4:      cmpb $0xfa,%al                  # CLI?
-               je v86cli                       # Yes
-               cmpb $0xfb,%al                  # STI?
-               je v86sti                       # Yes
-               movzwl 0x38(%ebp),%ebx          # Load V86 SS
-               shll $0x4,%ebx                  # To offset
-               pushl %ebx                      # Save
-               addl 0x34(%ebp),%ebx            # Add V86 SP
-               movl 0x30(%ebp),%edx            # Load V86 flags
-               cmpb $0x9c,%al                  # PUSHF/PUSHFD?
-               je v86pushf                     # Yes
-               cmpb $0x9d,%al                  # POPF/POPFD?
-               je v86popf                      # Yes
-               cmpb $0xcd,%al                  # INT imm8?
-               je v86intn                      # Yes
-               cmpb $0xcf,%al                  # IRET/IRETD?
-               je v86iret                      # Yes
-               popl %ebx                       # Restore
-               popa                            # Restore
-               jmp except                      # Handle exception
-v86mon.5:      movl %edx,0x30(%ebp)            # Save V86 flags
-v86mon.6:      popl %edx                       # V86 SS adjustment
-               subl %edx,%ebx                  # Save V86
-               movl %ebx,0x34(%ebp)            #  SP
-v86mon.7:      subl %edi,%esi                  # From linear
-               movl %esi,0x28(%ebp)            # Save V86 IP
-               popa                            # Restore
-               leal 0x8(%esp,1),%esp           # Discard int no, error
-               iret                            # To V86 mode
-#
-# Emulate MOV EAX,CR0.
-#
-v86mov:        movl %cr0,%eax                  # CR0 to
-               movl %eax,0x1c(%ebp)            #  saved EAX
-               incl %esi                       # Adjust IP
-#
-# Return from emulating a 0x0f prefixed instruction
-#
-v86preret:     incl %esi                       # Adjust IP
-               jmp v86mon.7                    # Finish up
-#
-# Emulate WBINVD
-#
-v86wbinvd:     wbinvd                          # Write back and invalidate
-                                               #  cache
-               jmp v86preret                   # Finish up
-#
-# Emulate WRMSR
-#
-v86wrmsr:      movl 0x18(%ebp),%ecx            # Get user's %ecx (MSR to write)
-               movl 0x14(%ebp),%edx            # Load the value
-               movl 0x1c(%ebp),%eax            #  to write
-               wrmsr                           # Write MSR
-               jmp v86preret                   # Finish up
-#
-# Emulate RDMSR
-#
-v86rdmsr:      movl 0x18(%ebp),%ecx            # MSR to read
-               rdmsr                           # Read the MSR
-               movl %eax,0x1c(%ebp)            # Return the value of
-               movl %edx,0x14(%ebp)            #  the MSR to the user
-               jmp v86preret                   # Finish up
-#
-# Emulate CLI.
-#
-v86cli:        andb $~0x2,0x31(%ebp)           # Clear IF
-               jmp v86mon.7                    # Finish up
-#
-# Emulate STI.
-#
-v86sti:        orb $0x2,0x31(%ebp)             # Set IF
-               jmp v86mon.7                    # Finish up
-#
-# Emulate PUSHF/PUSHFD.
-#
-v86pushf:      subl %ecx,%ebx                  # Adjust SP
-               cmpb $0x4,%cl                   # 32-bit
-               je v86pushf.1                   # Yes
-               data16                          # 16-bit
-v86pushf.1:    movl %edx,(%ebx)                # Save flags
-               jmp v86mon.6                    # Finish up
-#
-# Emulate IRET/IRETD.
-#
-v86iret:       movzwl (%ebx),%esi              # Load V86 IP
-               movzwl 0x2(%ebx),%edi           # Load V86 CS
-               leal 0x4(%ebx),%ebx             # Adjust SP
-               movl %edi,0x2c(%ebp)            # Save V86 CS
-               xorl %edi,%edi                  # No ESI adjustment
-#
-# Emulate POPF/POPFD (and remainder of IRET/IRETD).
-#
-v86popf:       cmpb $0x4,%cl                   # 32-bit?
-               je v86popf.1                    # Yes
-               movl %edx,%eax                  # Initialize
-               data16                          # 16-bit
-v86popf.1:     movl (%ebx),%eax                # Load flags
-               addl %ecx,%ebx                  # Adjust SP
-               andl $V86_FLG,%eax              # Merge
-               andl $~V86_FLG,%edx             #  the
-               orl %eax,%edx                   #  flags
-               jmp v86mon.5                    # Finish up
-#
-# trap int 15, function 87
-# reads %es:%si from saved registers on stack to find a GDT containing
-# source and destination locations
-# reads count of words from saved %cx
-# returns success by setting %ah to 0
-#
-int15_87:      pushl %eax                      # Save 
-               pushl %ebx                      #  some information 
-               pushl %esi                      #  onto the stack.
-               pushl %edi
-               xorl %eax,%eax                  # clean EAX 
-               xorl %ebx,%ebx                  # clean EBX 
-               movl 0x4(%ebp),%esi             # Get user's ESI
-               movl 0x3C(%ebp),%ebx            # store ES
-               movw %si,%ax                    # store SI
-               shll $0x4,%ebx                  # Make it a seg.
-               addl %eax,%ebx                  # ebx=(es<<4)+si
-               movb 0x14(%ebx),%al             # Grab the
-               movb 0x17(%ebx),%ah             #  necessary
-               shll $0x10,%eax                 #  information
-               movw 0x12(%ebx),%ax             #  from
-               movl %eax,%esi                  #  the
-               movb 0x1c(%ebx),%al             #  GDT in order to
-               movb 0x1f(%ebx),%ah             #  have %esi offset
-               shll $0x10,%eax                 #  of source and %edi
-               movw 0x1a(%ebx),%ax             #  of destination.
-               movl %eax,%edi
-               pushl %ds                       # Make:
-               popl %es                        # es = ds
-               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
-               popl %edi
-               popl %esi                       #  previous
-               popl %ebx                       #  register
-               popl %eax                       #  values.
-               movb $0x0,0x1d(%ebp)            # set ah = 0 to indicate
-                                               #  success
-               andb $0xfe,%dl                  # clear CF
-               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.3                   #  no, skip parse
-               pushl %eax                      # stash EAX
-               movl 0x1c(%ebp),%eax            # user's saved EAX
-               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:     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
-               andb $0xc,%al                   # mask off just Ctrl and Alt
-               cmpb $0xc,%al                   # are both Ctrl and Alt down?
-               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
-               leal -0x6(%ebx),%ebx            # Adjust SP
-               movw %si,(%ebx)                 # Save IP
-               shll $0x2,%eax                  # Scale
-               movzwl (%eax),%esi              # Load IP
-               movzwl 0x2(%eax),%edi           # Load CS
-               movl %edi,0x2c(%ebp)            # Save CS
-               xorl %edi,%edi                  # No ESI adjustment
-               andb $~0x1,%dh                  # Clear TF
-               jmp v86mon.5                    # Finish up
-#
-# Hardware interrupt jump table.
-#
-intx20:        push $0x8                       # Int 0x20: IRQ0
-               jmp int_hw                      # V86 int 0x8
-               push $0x9                       # Int 0x21: IRQ1
-               jmp int_hw                      # V86 int 0x9
-               push $0xa                       # Int 0x22: IRQ2
-               jmp int_hw                      # V86 int 0xa
-               push $0xb                       # Int 0x23: IRQ3
-               jmp int_hw                      # V86 int 0xb
-               push $0xc                       # Int 0x24: IRQ4
-               jmp int_hw                      # V86 int 0xc
-               push $0xd                       # Int 0x25: IRQ5
-               jmp int_hw                      # V86 int 0xd
-               push $0xe                       # Int 0x26: IRQ6
-               jmp int_hw                      # V86 int 0xe
-               push $0xf                       # Int 0x27: IRQ7
-               jmp int_hw                      # V86 int 0xf
-               push $0x70                      # Int 0x28: IRQ8
-               jmp int_hw                      # V86 int 0x70
-               push $0x71                      # Int 0x29: IRQ9
-               jmp int_hw                      # V86 int 0x71
-               push $0x72                      # Int 0x2a: IRQ10
-               jmp int_hw                      # V86 int 0x72
-               push $0x73                      # Int 0x2b: IRQ11
-               jmp int_hw                      # V86 int 0x73
-               push $0x74                      # Int 0x2c: IRQ12
-               jmp int_hw                      # V86 int 0x74
-               push $0x75                      # Int 0x2d: IRQ13
-               jmp int_hw                      # V86 int 0x75
-               push $0x76                      # Int 0x2e: IRQ14
-               jmp int_hw                      # V86 int 0x76
-               push $0x77                      # Int 0x2f: IRQ15
-               jmp int_hw                      # V86 int 0x77
-#
-# Reflect hardware interrupts.
-#
-int_hw:        testb $0x2,0xe(%esp,1)          # V86 mode?
-               jz intusr                       # No
-               pushl $SEL_SDATA                # Address
-               popl %ds                        #  data
-               xchgl %eax,(%esp,1)             # Swap EAX, int no
-               pushl %ebp                      # Address
-               movl %esp,%ebp                  #  stack frame
-               pushl %ebx                      # Save
-               shll $0x2,%eax                  # Get int
-               movl (%eax),%eax                #  vector
-               subl $0x6,0x14(%ebp)            # Adjust V86 ESP
-               movzwl 0x18(%ebp),%ebx          # V86 SS
-               shll $0x4,%ebx                  #  * 0x10
-               addl 0x14(%ebp),%ebx            #  + V86 ESP
-               xchgw %ax,0x8(%ebp)             # Swap V86 IP
-               rorl $0x10,%eax                 # Swap words
-               xchgw %ax,0xc(%ebp)             # Swap V86 CS
-               roll $0x10,%eax                 # Swap words
-               movl %eax,(%ebx)                # CS:IP for IRET
-               movl 0x10(%ebp),%eax            # V86 flags
-               movw %ax,0x4(%ebx)              # Flags for IRET
-               andb $~0x3,0x11(%ebp)           # Clear IF, TF
-               popl %ebx                       # Restore
-               popl %ebp                       #  saved
-               popl %eax                       #  registers
-               iret                            # To V86 mode
-#
-# Invoke V86 interrupt from user mode, with arguments.
-#
-intx31:        stc                             # Have btx_v86
-               pushl %eax                      # Missing int no
-#
-# Invoke V86 interrupt from user mode.
-#
-intusr:        std                             # String ops dec
-               pushl %eax                      # Expand
-               pushl %eax                      #  stack
-               pushl %eax                      #  frame
-               pusha                           # Save
-               pushl %gs                       # Save
-               movl %esp,%eax                  #  seg regs
-               pushl %fs                       #  and
-               pushl %ds                       #  point
-               pushl %es                       #  to them
-               push $SEL_SDATA                 # Set up
-               popl %ds                        #  to
-               pushl %ds                       #  address
-               popl %es                        #  data
-               movl $MEM_USR,%ebx              # User base
-               movl %ebx,%edx                  #  address
-               jc intusr.1                     # If btx_v86
-               xorl %edx,%edx                  # Control flags
-               xorl %ebp,%ebp                  # btx_v86 pointer
-intusr.1:      leal 0x50(%esp,1),%esi          # Base of frame
-               pushl %esi                      # Save
-               addl -0x4(%esi),%ebx            # User ESP
-               movl MEM_TSS+TSS_ESP1,%edi      # Link stack pointer
-               leal -0x4(%edi),%edi            # Adjust for push
-               xorl %ecx,%ecx                  # Zero
-               movb $0x5,%cl                   # Push exception
-               rep                             #  frame on
-               movsl                           #  link stack
-               xchgl %eax,%esi                 # Saved seg regs
-               movl 0x40(%esp,1),%eax          # Get int no
-               testl %edx,%edx                 # Have btx_v86?
-               jz intusr.2                     # No
-               movl (%ebx),%ebp                # btx_v86 pointer
-               movb $0x4,%cl                   # Count
-               addl %ecx,%ebx                  # Adjust for pop
-               rep                             # Push saved seg regs
-               movsl                           #  on link stack
-               addl %ebp,%edx                  # Flatten btx_v86 ptr
-               leal 0x14(%edx),%esi            # Seg regs pointer
-               movl 0x4(%edx),%eax             # Get int no/address
-               movzwl 0x2(%edx),%edx           # Get control flags
-intusr.2:      movl %ebp,(%edi)                # Push btx_v86 and
-               movl %edi,MEM_TSS+TSS_ESP1      #  save link stack ptr
-               popl %edi                       # Base of frame
-               xchgl %eax,%ebp                 # Save intno/address
-               movl 0x48(%esp,1),%eax          # Get flags
-               testb $0x2,%dl                  # Simulate CALLF?
-               jnz intusr.3                    # Yes
-               decl %ebx                       # Push flags
-               decl %ebx                       #  on V86
-               movw %ax,(%ebx)                 #  stack
-intusr.3:      movb $0x4,%cl                   # Count
-               subl %ecx,%ebx                  # Push return address
-               movl $inthlt,(%ebx)             #  on V86 stack
-               rep                             # Copy seg regs to
-               movsl                           #  exception frame
-               xchgl %eax,%ecx                 # Save flags
-               movl %ebx,%eax                  # User ESP
-               subl $V86_STK,%eax              # Less bytes
-               ja intusr.4                     #  to
-               xorl %eax,%eax                  #  keep
-intusr.4:      shrl $0x4,%eax                  # Gives segment
-               stosl                           # Set SS
-               shll $0x4,%eax                  # To bytes
-               xchgl %eax,%ebx                 # Swap
-               subl %ebx,%eax                  # Gives offset
-               stosl                           # Set ESP
-               xchgl %eax,%ecx                 # Get flags
-               btsl $0x11,%eax                 # Set VM
-               andb $~0x1,%ah                  # Clear TF
-               stosl                           # Set EFL
-               xchgl %eax,%ebp                 # Get int no/address
-               testb $0x1,%dl                  # Address?
-               jnz intusr.5                    # Yes
-               shll $0x2,%eax                  # Scale
-               movl (%eax),%eax                # Load int vector
-intusr.5:      movl %eax,%ecx                  # Save
-               shrl $0x10,%eax                 # Gives segment
-               stosl                           # Set CS
-               movw %cx,%ax                    # Restore
-               stosl                           # Set EIP
-               leal 0x10(%esp,1),%esp          # Discard seg regs
-               popa                            # Restore
-               iret                            # To V86 mode
-#
-# System Call.
-#
-intx30:        cmpl $SYS_EXEC,%eax             # Exec system call?
-               jne intx30.1                    # No
-               pushl %ss                       # Set up
-               popl %es                        #  all
-               pushl %es                       #  segment
-               popl %ds                        #  registers
-               pushl %ds                       #  for the
-               popl %fs                        #  program
-               pushl %fs                       #  we're
-               popl %gs                        #  invoking
-               movl $MEM_USR,%eax              # User base address
-               addl 0xc(%esp,1),%eax           # Change to user
-               leal 0x4(%eax),%esp             #  stack
-ifdef(`PAGING',`
-               movl %cr0,%eax                  # Turn
-               andl $~0x80000000,%eax          #  off
-               movl %eax,%cr0                  #  paging
-               xorl %eax,%eax                  # Flush
-               movl %eax,%cr3                  #  TLB
-')
-               popl %eax                       # Call
-               call *%eax                      #  program
-intx30.1:      orb $0x1,%ss:btx_hdr+0x7        # Flag reboot
-               jmp exit                        # Exit
-#
-# Dump structure [EBX] to [EDI], using format string [ESI].
-#
-dump.0:        stosb                           # Save char
-dump:          lodsb                           # Load char
-               testb %al,%al                   # End of string?
-               jz dump.10                      # Yes
-               testb $0x80,%al                 # Control?
-               jz dump.0                       # No
-               movb %al,%ch                    # Save control
-               movb $'=',%al                   # Append
-               stosb                           #  '='
-               lodsb                           # Get offset
-               pushl %esi                      # Save
-               movsbl %al,%esi                 # To
-               addl %ebx,%esi                  #  pointer
-               testb $DMP_X16,%ch              # Dump word?
-               jz dump.1                       # No
-               lodsw                           # Get and
-               call hex16                      #  dump it
-dump.1:        testb $DMP_X32,%ch              # Dump long?
-               jz dump.2                       # No
-               lodsl                           # Get and
-               call hex32                      #  dump it
-dump.2:        testb $DMP_MEM,%ch              # Dump memory?
-               jz dump.8                       # No
-               pushl %ds                       # Save
-               testb $0x2,0x52(%ebx)           # V86 mode?
-               jnz dump.3                      # Yes
-               verr 0x4(%esi)                  # Readable selector?
-               jnz dump.3                      # No
-               ldsl (%esi),%esi                # Load pointer
-               jmp dump.4                      # Join common code
-dump.3:        lodsl                           # Set offset
-               xchgl %eax,%edx                 # Save
-               lodsl                           # Get segment
-               shll $0x4,%eax                  #  * 0x10
-               addl %edx,%eax                  #  + offset
-               xchgl %eax,%esi                 # Set pointer
-dump.4:        movb $2,%dl                     # Num lines
-dump.4a:       movb $0x10,%cl                  # Bytes to dump
-dump.5:        lodsb                           # Get byte and
-               call hex8                       #  dump it
-               decb %cl                        # Keep count
-               jz dump.6a                      # If done
-               movb $'-',%al                   # Separator
-               cmpb $0x8,%cl                   # Half way?
-               je dump.6                       # Yes
-               movb $' ',%al                   # Use space
-dump.6:        stosb                           # Save separator
-               jmp dump.5                      # Continue
-dump.6a:       decb %dl                        # Keep count
-               jz dump.7                       # If done
-               movb $0xa,%al                   # Line feed
-               stosb                           # Save one
-               movb $7,%cl                     # Leading
-               movb $' ',%al                   #  spaces
-dump.6b:       stosb                           # Dump
-               decb %cl                        #  spaces
-               jnz dump.6b
-               jmp dump.4a                     # Next line
-dump.7:        popl %ds                        # Restore
-dump.8:        popl %esi                       # Restore
-               movb $0xa,%al                   # Line feed
-               testb $DMP_EOL,%ch              # End of line?
-               jnz dump.9                      # Yes
-               movb $' ',%al                   # Use spaces
-               stosb                           # Save one
-dump.9:        jmp dump.0                      # Continue
-dump.10:       stosb                           # Terminate string
-               ret                             # To caller
-#
-# Convert EAX, AX, or AL to hex, saving the result to [EDI].
-#
-hex32:         pushl %eax                      # Save
-               shrl $0x10,%eax                 # Do upper
-               call hex16                      #  16
-               popl %eax                       # Restore
-hex16:         call hex16.1                    # Do upper 8
-hex16.1:       xchgb %ah,%al                   # Save/restore
-hex8:          pushl %eax                      # Save
-               shrb $0x4,%al                   # Do upper
-               call hex8.1                     #  4
-               popl %eax                       # Restore
-hex8.1:        andb $0xf,%al                   # Get lower 4
-               cmpb $0xa,%al                   # Convert
-               sbbb $0x69,%al                  #  to hex
-               das                             #  digit
-               orb $0x20,%al                   # To lower case
-               stosb                           # Save char
-               ret                             # (Recursive)
-#
-# Output zero-terminated string [ESI] to the console.
-#
-putstr.0:      call putchr                     # Output char
-putstr:        lodsb                           # Load char
-               testb %al,%al                   # End of string?
-               jnz putstr.0                    # No
-               ret                             # To caller
-ifdef(`BTX_SERIAL',`
-               .set SIO_PRT,SIOPRT             # Base port
-               .set SIO_FMT,SIOFMT             # 8N1
-               .set SIO_DIV,(115200/SIOSPD)    # 115200 / SPD
-
-# void sio_init(void)
-
-sio_init:      movw $SIO_PRT+0x3,%dx           # Data format reg
-               movb $SIO_FMT|0x80,%al          # Set format
-               outb %al,(%dx)                  #  and DLAB
-               pushl %edx                      # Save
-               subb $0x3,%dl                   # Divisor latch reg
-               movw $SIO_DIV,%ax               # Set
-               outw %ax,(%dx)                  #  BPS
-               popl %edx                       # Restore
-               movb $SIO_FMT,%al               # Clear
-               outb %al,(%dx)                  #  DLAB
-               incl %edx                       # Modem control reg
-               movb $0x3,%al                   # Set RTS,
-               outb %al,(%dx)                  #  DTR
-               incl %edx                       # Line status reg
-
-# void sio_flush(void)
-
-sio_flush.0:   call sio_getc.1                 # Get character
-sio_flush:     call sio_ischar                 # Check for character
-               jnz sio_flush.0                 # Till none
-               ret                             # To caller
-
-# void sio_putc(int c)
-
-sio_putc:      movw $SIO_PRT+0x5,%dx           # Line status reg
-               xor %ecx,%ecx                   # Timeout
-               movb $0x40,%ch                  #  counter
-sio_putc.1:    inb (%dx),%al                   # Transmitter
-               testb $0x20,%al                 #  buffer empty?
-               loopz sio_putc.1                # No
-               jz sio_putc.2                   # If timeout
-               movb 0x4(%esp,1),%al            # Get character
-               subb $0x5,%dl                   # Transmitter hold reg
-               outb %al,(%dx)                  # Write character
-sio_putc.2:    ret $0x4                        # To caller
-
-# int sio_getc(void)
-
-sio_getc:      call sio_ischar                 # Character available?
-               jz sio_getc                     # No
-sio_getc.1:    subb $0x5,%dl                   # Receiver buffer reg
-               inb (%dx),%al                   # Read character
-               ret                             # To caller
-
-# int sio_ischar(void)
-
-sio_ischar:    movw $SIO_PRT+0x5,%dx           # Line status register
-               xorl %eax,%eax                  # Zero
-               inb (%dx),%al                   # Received data
-               andb $0x1,%al                   #  ready?
-               ret                             # To caller
-
-#
-# Output character AL to the serial console.
-#
-putchr:        pusha                           # Save
-               cmpb $10, %al                   # is it a newline?
-               jne putchr.1                    #  no?, then leave
-               push $13                        # output a carriage
-               call sio_putc                   #  return first
-               movb $10, %al                   # restore %al
-putchr.1:      pushl %eax                      # Push the character
-                                               #  onto the stack
-               call sio_putc                   # Output the character
-               popa                            # Restore
-               ret                             # To caller
-',`
-#
-# Output character AL to the console.
-#
-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
-               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)
-putchr.1:      cmpb $0xa,%al                   # New line?
-               je putchr.2                     # Yes
-               xchgl %eax,%ecx                 # Save char
-               movb $SCR_COL,%al               # Columns per row
-               mulb %dh                        #  * row position
-               addb %dl,%al                    #  + column
-               adcb $0x0,%ah                   #  position
-               shll %eax                       #  * 2
-               xchgl %eax,%ecx                 # Swap char, offset
-               movw %ax,(%edi,%ecx,1)          # Write attr:char
-               incl %edx                       # Bump cursor
-               cmpb $SCR_COL,%dl               # Beyond row?
-               jb putchr.3                     # No
-putchr.2:      xorb %dl,%dl                    # Zero column
-               incb %dh                        # Bump row
-putchr.3:      cmpb $SCR_ROW,%dh               # Beyond screen?
-               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 $0x20,%al                  # Space
-               movb $SCR_COL,%cl               # Columns to clear
-               rep                             # Clear
-               stosw                           #  line
-               movb $SCR_ROW-1,%dh             # Bottom line
-putchr.4:      movw %dx,(%ebx)                 # Update position
-               popa                            # Restore
-               ret                             # To caller
-')
-
-               .p2align 4
-#
-# Global descriptor table.
-#
-gdt:           .word 0x0,0x0,0x0,0x0           # Null entry
-               .word 0xffff,0x0,0x9a00,0xcf    # SEL_SCODE
-               .word 0xffff,0x0,0x9200,0xcf    # SEL_SDATA
-               .word 0xffff,0x0,0x9a00,0x0     # SEL_RCODE
-               .word 0xffff,0x0,0x9200,0x0     # SEL_RDATA
-               .word 0xffff,MEM_USR,0xfa00,0xcf# SEL_UCODE
-               .word 0xffff,MEM_USR,0xf200,0xcf# SEL_UDATA
-               .word _TSSLM,MEM_TSS,0x8900,0x0 # SEL_TSS
-gdt.1:
-#
-# Pseudo-descriptors.
-#
-gdtdesc:       .word gdt.1-gdt-1,gdt,0x0       # GDT
-idtdesc:       .word _IDTLM,MEM_IDT,0x0        # IDT
-ivtdesc:       .word 0x400-0x0-1,0x0,0x0       # IVT
-#
-# IDT construction control string.
-#
-idtctl:        .byte 0x10,  0x8e               # Int 0x0-0xf
-               .word 0x7dfb,intx00             #  (exceptions)
-               .byte 0x10,  0x8e               # Int 0x10
-               .word 0x1,   intx10             #  (exception)
-               .byte 0x10,  0x8e               # Int 0x20-0x2f
-               .word 0xffff,intx20             #  (hardware)
-               .byte 0x1,   0xee               # int 0x30
-               .word 0x1,   intx30             #  (system call)
-               .byte 0x2,   0xee               # Int 0x31-0x32
-               .word 0x1,   intx31             #  (V86, null)
-               .byte 0x0                       # End of string
-#
-# Dump format string.
-#
-dmpfmt:        .byte '\n'                      # "\n"
-               .ascii "int"                    # "int="
-               .byte 0x80|DMP_X32,        0x40 # "00000000  "
-               .ascii "err"                    # "err="
-               .byte 0x80|DMP_X32,        0x44 # "00000000  "
-               .ascii "efl"                    # "efl="
-               .byte 0x80|DMP_X32,        0x50 # "00000000  "
-               .ascii "eip"                    # "eip="
-               .byte 0x80|DMP_X32|DMP_EOL,0x48 # "00000000\n"
-               .ascii "eax"                    # "eax="
-               .byte 0x80|DMP_X32,        0x34 # "00000000  "
-               .ascii "ebx"                    # "ebx="
-               .byte 0x80|DMP_X32,        0x28 # "00000000  "
-               .ascii "ecx"                    # "ecx="
-               .byte 0x80|DMP_X32,        0x30 # "00000000  "
-               .ascii "edx"                    # "edx="
-               .byte 0x80|DMP_X32|DMP_EOL,0x2c # "00000000\n"
-               .ascii "esi"                    # "esi="
-               .byte 0x80|DMP_X32,        0x1c # "00000000  "
-               .ascii "edi"                    # "edi="
-               .byte 0x80|DMP_X32,        0x18 # "00000000  "
-               .ascii "ebp"                    # "ebp="
-               .byte 0x80|DMP_X32,        0x20 # "00000000  "
-               .ascii "esp"                    # "esp="
-               .byte 0x80|DMP_X32|DMP_EOL,0x0  # "00000000\n"
-               .ascii "cs"                     # "cs="
-               .byte 0x80|DMP_X16,        0x4c # "0000  "
-               .ascii "ds"                     # "ds="
-               .byte 0x80|DMP_X16,        0xc  # "0000  "
-               .ascii "es"                     # "es="
-               .byte 0x80|DMP_X16,        0x8  # "0000  "
-               .ascii "  "                     # "  "
-               .ascii "fs"                     # "fs="
-               .byte 0x80|DMP_X16,        0x10 # "0000  "
-               .ascii "gs"                     # "gs="
-               .byte 0x80|DMP_X16,        0x14 # "0000  "
-               .ascii "ss"                     # "ss="
-               .byte 0x80|DMP_X16|DMP_EOL,0x4  # "0000\n"
-               .ascii "cs:eip"                 # "cs:eip="
-               .byte 0x80|DMP_MEM|DMP_EOL,0x48 # "00 00 ... 00 00\n"
-               .ascii "ss:esp"                 # "ss:esp="
-               .byte 0x80|DMP_MEM|DMP_EOL,0x0  # "00 00 ... 00 00\n"
-               .asciz "BTX halted\n"           # End
-#
-# End of BTX memory.
-#
-               .p2align 4
-break:
index fabd4f0..8de9f2d 100644 (file)
@@ -1,72 +1,66 @@
-#
-# Copyright (c) 2001 John Baldwin
-# 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: src/sys/boot/i386/cdboot/cdboot.s,v 1.9 2001/11/07 01:20:33 jhb Exp $
-# $DragonFly: src/sys/boot/i386/cdboot/Attic/cdboot.S,v 1.4 2004/07/18 16:51:38 dillon Exp $
-
-#
-# This program is a freestanding boot program to load an a.out binary
-# from a CD-ROM booted with no emulation mode as described by the El
-# Torito standard.  Due to broken BIOSen that do not load the desired
-# number of sectors, we try to fit this in as small a space as possible.
-#
-# Basically, we first create a set of boot arguments to pass to the loaded
-# binary.  Then we attempt to load /boot/loader from the CD we were booted
-# off of. 
-#
-
-#
-# Memory locations.
-#
-               .set MEM_PAGE_SIZE,0x1000       # memory page size, 4k
-               .set MEM_ARG,0x900              # Arguments at start
-               .set MEM_ARG_BTX,0xa100         # Where we move them to so the
-                                               #  BTX client can see them
-               .set MEM_ARG_SIZE,0x18          # Size of the arguments
-               .set MEM_BTX_ADDRESS,0x9000     # where BTX lives
-               .set MEM_BTX_ENTRY,0x9010       # where BTX starts to execute
-               .set MEM_BTX_OFFSET,MEM_PAGE_SIZE # offset of BTX in the loader
-               .set MEM_BTX_CLIENT,0xa000      # where BTX clients live
-#
-# a.out header fields
-#
+/*
+ * Copyright (c) 2001 John Baldwin
+ * 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: src/sys/boot/i386/cdboot/cdboot.s,v 1.9 2001/11/07 01:20:33 jhb Exp $
+ * $DragonFly: src/sys/boot/i386/cdboot/Attic/cdboot.S,v 1.5 2004/07/18 23:40:07 dillon Exp $
+ */
+
+/*
+ * This program is a freestanding boot program to load an a.out binary
+ * from a CD-ROM booted with no emulation mode as described by the El
+ * Torito standard.  Due to broken BIOSen that do not load the desired
+ * number of sectors, we try to fit this in as small a space as possible.
+ *
+ * Basically, we first create a set of boot arguments to pass to the loaded
+ * binary.  Then we attempt to load /boot/loader from the CD we were booted
+ * off of. 
+ */
+
+#include "../bootasm.h"
+
+               /*
+                * a.out header fields
+                */
                .set AOUT_TEXT,0x04             # text segment size
                .set AOUT_DATA,0x08             # data segment size
-               .set AOUT_BSS,0x0c              # zero'd BSS size
+               .set AOUT_BSS,0x0c              # zerod BSS size
                .set AOUT_SYMBOLS,0x10          # symbol table
                .set AOUT_ENTRY,0x14            # entry point
                .set AOUT_HEADER,MEM_PAGE_SIZE  # size of the a.out header
-#
-# Flags for kargs->bootflags
-#
+
+               /*
+                * Flags for kargs->bootflags
+                */
                .set KARGS_FLAGS_CD,0x1         # flag to indicate booting from
                                                #  CD loader
-#
-# Segment selectors.
-#
+               /*
+                * Segment selectors.
+                */
                .set SEL_SDATA,0x8              # Supervisor data
                .set SEL_RDATA,0x10             # Real mode data
                .set SEL_SCODE,0x18             # PM-32 code
                .set SEL_SCODE16,0x20           # PM-16 code
-#
-# BTX constants
-#
+
+               /*
+                * BTX constants
+                */
                .set INT_SYS,0x30               # BTX syscall interrupt
-#
-# Constants for reading from the CD.
-#
+
+               /*
+                * Constants for reading from the CD.
+                */
                .set ERROR_TIMEOUT,0x80         # BIOS timeout on read
                .set NUM_RETRIES,3              # Num times to retry
                .set SECTOR_SIZE,0x800          # size of a sector
                .set DIR_SIZE,10                # Offset of 64-bit length
                .set DIR_NAMELEN,32             # Offset of 8-bit name len
                .set DIR_NAME,33                # Offset of dir name
-#
-# We expect to be loaded by the BIOS at 0x7c00 (standard boot loader entry
-# point)
-#
+
+               /*
+                * Program start.
+                *
+                * We expect to be loaded by the BIOS at 0x7c00 (standard
+                * boot loader entry point)
+                */
                .code16
                .globl start
                .org 0x0, 0x0
-#
-# Program start.
-#
+
 start:         cld                             # string ops inc
                xor %ax,%ax                     # zero %ax
                mov %ax,%ss                     # setup the
@@ -106,9 +101,11 @@ start:             cld                             # string ops inc
                mov %dl,drive                   # Save BIOS boot device
                mov $msg_welcome,%si            # %ds:(%si) -> welcome message
                call putstr                     # display the welcome message
-#
-# Setup the arguments that the loader is expecting from boot[12]
-#
+
+               /*
+                * Setup the arguments that the loader is expecting from
+                * boot[12]
+                */
                mov $msg_bootinfo,%si           # %ds:(%si) -> boot args message
                call putstr                     # display the message
                mov $MEM_ARG,%bx                # %ds:(%bx) -> boot args
@@ -122,9 +119,9 @@ start:              cld                             # string ops inc
                mov %dl,0x4(%bx)                #  in kargs->bootdev
                or $KARGS_FLAGS_CD,0x8(%bx)     # kargs->bootflags |=
                                                #  KARGS_FLAGS_CD
-#
-# Load Volume Descriptor
-#
+               /*
+                * Load Volume Descriptor
+                */
                mov $VOLDESC_LBA,%eax           # Set LBA of first VD
 load_vd:
                mov $1,%dh                      # One sector
@@ -138,15 +135,18 @@ load_vd:
                mov $msg_novd,%si               # No VD
                jmp error                       # Halt
 have_vd:                                       # Have Primary VD
-#
-# Lookup the loader binary.
-#
+
+               /*
+                * Lookup the loader binary.
+                */
                mov $loader_path,%si            # File to lookup
                call lookup                     # Try to find it
-#
-# Load the binary into the buffer.  Due to real mode addressing limitations
-# we have to read it in in 64k chunks.
-#
+
+               /*
+                * Load the binary into the buffer.  Due to real mode
+                * addressing limitations we have to read it in in 64k
+                * chunks.
+                */
                mov DIR_SIZE(%bx),%eax          # Read file length
                add $SECTOR_SIZE-1,%eax         # Convert length to sectors
                shr $11,%eax
@@ -171,13 +171,15 @@ load_notrunc:     sub %dh,%cl                     # Update count
                jcxz load_done                  # Done?
                jmp load_loop                   # Keep going
 load_done:
-#
-# Turn on the A20 address line
-#
+               /*
+                * Turn on the A20 address line.
+                */
                call seta20                     # Turn A20 on
-#
-# Relocate the loader and BTX using a very lazy protected mode
-#
+
+               /*
+                * Relocate the loader and BTX using a very lazy
+                * protected mode.
+                */
                mov $msg_relocate,%si           # Display the
                call putstr                     #  relocation message
                mov MEM_READ_BUFFER+AOUT_ENTRY,%edi # %edi is the destination
@@ -212,8 +214,8 @@ pm_start:   mov $SEL_SDATA,%ax              # Initialize
                rep                             # zero the
                stosl                           #  bss
                mov MEM_READ_BUFFER+AOUT_ENTRY,%esi # %esi -> relocated loader
-               add $MEM_BTX_OFFSET,%esi        # %esi -> BTX in the loader
-               mov $MEM_BTX_ADDRESS,%edi       # %edi -> where BTX needs to go
+               add $MEM_BTX_LDR_OFF,%esi       # %esi -> BTX in the loader
+               mov $MEM_BTX_ORG,%edi   # %edi -> where BTX needs to go
                movzwl 0xa(%esi),%ecx           # %ecx -> length of BTX
                rep                             # Relocate
                movsb                           #  BTX
@@ -228,44 +230,50 @@ pm_16:            mov $SEL_RDATA,%ax              # Initialize
                ljmp $0,$pm_end                 # Long jump to clear the
                                                #  instruction pre-fetch queue
 pm_end:                sti                             # Turn interrupts back on now
-#
-# Copy the BTX client to MEM_BTX_CLIENT
-#
+
+               /*
+                * Copy the BTX client to MEM_BTX_USR.
+                */
                xor %ax,%ax                     # zero %ax and set
                mov %ax,%ds                     #  %ds and %es
                mov %ax,%es                     #  to segment 0
-               mov $MEM_BTX_CLIENT,%di         # Prepare to relocate
+               mov $MEM_BTX_USR,%di            # Prepare to relocate
                mov $btx_client,%si             #  the simple btx client
                mov $(btx_client_end-btx_client),%cx # length of btx client
                rep                             # Relocate the
                movsb                           #  simple BTX client
-#
-# Copy the boot[12] args to where the BTX client can see them
-#
+
+               /*
+                * Copy the boot[12] args to where the BTX client
+                * can see them.
+                */
                mov $MEM_ARG,%si                # where the args are at now
-               mov $MEM_ARG_BTX,%di            # where the args are moving to
+               mov $MEM_BTX_USR_ARG,%di                # where the args are moving to
                mov $(MEM_ARG_SIZE/4),%cx       # size of the arguments in longs
                rep                             # Relocate
                movsl                           #  the words
-#
-# Save the entry point so the client can get to it later on
-#
+
+               /*
+                * Save the entry point so the client can get to it
+                * later on
+                */
                pop %eax                        # Restore saved entry point
                stosl                           #  and add it to the end of
                                                #  the arguments
-#
-# Now we just start up BTX and let it do the rest
-#
+               /*
+                * Now we just start up BTX and let it do the rest
+                */
                mov $msg_jump,%si               # Display the
                call putstr                     #  jump message
                ljmp $0,$MEM_BTX_ENTRY          # Jump to the BTX entry point
 
-#
-# Lookup the file in the path at [SI] from the root directory.
-#
-# Trashes: All but BX
-# Returns: BX = pointer to record
-#
+               /*
+                * Lookup the file in the path at [SI] from the root 
+                * directory.
+                *
+                * Trashes: All but BX
+                * Returns: BX = pointer to record
+                */
 lookup:                mov $VD_ROOTDIR+MEM_VOLDESC,%bx # Root directory record
                push %si
                mov $msg_lookup,%si             # Display lookup message
@@ -290,13 +298,17 @@ lookup_done:      mov $msg_lookupok,%si           # Success message
                call putstr
                ret
 
-#
-# Lookup file at [SI] in directory whose record is at [BX].
-#
-# Trashes: All but returns
-# Returns: CF = 0 (success), BX = pointer to record, SX = next path item
-#          CF = 1 (not found), SI = preserved
-#
+               /*
+                * Lookup file at [SI] in directory whose record is at [BX].
+                *
+                * Trashes: All but returns
+                *
+                * Returns:     CF = 0 (success)
+                *              BX = pointer to record,
+                *              SX = next path item
+                *              CF = 1 (not found)
+                *              SI = preserved
+                */
 find_file:     mov DIR_EXTENT(%bx),%eax        # Load extent
                xor %edx,%edx
                mov DIR_EA_LEN(%bx),%dl
@@ -371,11 +383,12 @@ ff.match: add $2,%sp                      # Discard saved %si
                clc                             # Clear carry
                ret
 
-# Load DH sectors starting at LBA EAX into [EBX].  No registers are destroyed.
-# Don't trust the BIOS, especially with regards to the msb 16 bits of our
-# registers.
-#
-read:          pushal                          # don't screw around
+               /*
+                * Load DH sectors starting at LBA EAX into [EBX].  No
+                * registers are destroyed.  Don't trust the BIOS, especially
+                * with regards to the msb 16 bits of our registers.
+                */
+read:          pushal                          # dont screw around
                mov %eax,edd_lba                # LBA to read from
                mov %ebx,%eax                   # Convert address
                shr $4,%eax                     #  to segment
@@ -398,18 +411,18 @@ read.error:       mov %ah,%al                     # Save error
                call hex8                       #  as hex
                mov $msg_badread,%si            # Display Read error message
 
-#
-# Display error message at [SI] and halt.
-#
+               /*
+                * Display error message at [SI] and halt.
+                */
 error:         call putstr                     # Display message
 halt:          hlt
                jmp halt                        # Spin
 
-#
-# Display a null-terminated string.
-#
-# Trashes: AX, SI
-#
+               /*
+                * Display a null-terminated string.
+                *
+                * Trashes: AX, SI
+                */
 putstr:
 putstr.load:   lodsb                           # load %al from %ds:(%si)
                test %al,%al                    # stop at null
@@ -418,8 +431,10 @@ putstr.load:       lodsb                           # load %al from %ds:(%si)
 putstr.putc:   call putc                       # output char
                jmp putstr.load                 # next char
 
-# Display a single char(%al).  Don't trust the bios to save our regs.
-#
+               /*
+                * Display a single char(%al).  Don't trust the bios to save
+                * our regs.
+                */
 putc:          pushal
                mov $0x7,%bx                    # attribute for output
                mov $0xe,%ah                    # BIOS: put_char
@@ -427,9 +442,9 @@ putc:               pushal
                popal
                ret                             # Return to caller
 
-#
-# Output the "twiddle"
-#
+               /*
+                * Output the "twiddle"
+                */
 twiddle:       push %ax                        # Save
                push %bx                        # Save
                mov twiddle_index,%al           # Load index
@@ -445,9 +460,9 @@ twiddle:    push %ax                        # Save
                pop %ax                         # Restore
                ret
 
-#
-# Enable A20
-#
+               /*
+                * Enable A20
+                */
 seta20:        cli                             # Disable interrupts
 seta20.1:      in $0x64,%al                    # Get status
                test $0x2,%al                   # Busy?
@@ -462,9 +477,9 @@ seta20.2:   in $0x64,%al                    # Get status
                sti                             # Enable interrupts
                ret                             # To caller
 
-#
-# Convert AL to hex, saving the result to [EDI].
-#
+               /*
+                * Convert AL to hex, saving the result to [EDI].
+                */
 hex8:          pushl %eax                      # Save
                shrb $0x4,%al                   # Do upper
                call hex8.1                     #  4
@@ -477,11 +492,11 @@ hex8.1:   andb $0xf,%al                   # Get lower 4
                stosb                           # Save char
                ret                             # (Recursive)
 
-#
-# BTX client to start btxldr
-#
+               /*
+                * BTX client to start btxldr
+                */
                .code32
-btx_client:    mov $(MEM_ARG_BTX-MEM_BTX_CLIENT+MEM_ARG_SIZE-4), %esi
+btx_client:    mov $(MEM_BTX_USR_ARG-MEM_BTX_USR+MEM_ARG_SIZE-4), %esi
                                                # %ds:(%esi) -> end
                                                #  of boot[12] args
                mov $(MEM_ARG_SIZE/4),%ecx      # Number of words to push
@@ -490,32 +505,35 @@ push_arg: lodsl                           # Read argument
                push %eax                       # Push it onto the stack
                loop push_arg                   # Push all of the arguments
                cld                             # In case anyone depends on this
-               pushl MEM_ARG_BTX-MEM_BTX_CLIENT+MEM_ARG_SIZE # Entry point of
+               pushl MEM_BTX_USR_ARG-MEM_BTX_USR+MEM_ARG_SIZE # Entry point of
                                                #  the loader
                push %eax                       # Emulate a near call
-               mov $0x1,%eax                   # 'exec' system call
+               mov $0x1,%eax                   # "exec" system call
                int $INT_SYS                    # BTX system call
 btx_client_end:
                .code16
 
                .p2align 4
-#
-# Global descriptor table.
-#
+
+               /*
+                * Global descriptor table.
+                */
 gdt:           .word 0x0,0x0,0x0,0x0           # Null entry
                .word 0xffff,0x0,0x9200,0xcf    # SEL_SDATA
                .word 0xffff,0x0,0x9200,0x0     # SEL_RDATA
                .word 0xffff,0x0,0x9a00,0xcf    # SEL_SCODE (32-bit)
                .word 0xffff,0x0,0x9a00,0x8f    # SEL_SCODE16 (16-bit)
 gdt.1:
-#
-# Pseudo-descriptors.
-#
+
+               /*
+                * Pseudo-descriptors.
+                */
 gdtdesc:       .word gdt.1-gdt-1               # Limit
                .long gdt                       # Base
-#
-# EDD Packet
-#
+
+               /*
+                * EDD Packet
+                */
 edd_packet:    .byte 0x10                      # Length
                .byte 0                         # Reserved
 edd_len:       .byte 0x0                       # Num to read
@@ -525,9 +543,9 @@ edd_lba:    .quad 0x0                       # LBA
 
 drive:         .byte 0
 
-#
-# State for searching dir
-#
+               /*
+                * State for searching dir
+                */
 rec_lba:       .long 0x0                       # LBA (adjusted for EA)
 rec_size:      .long 0x0                       # File size
 name_len:      .byte 0x0                       # Length of current name
diff --git a/sys/boot/i386/cdboot/cdboot.s b/sys/boot/i386/cdboot/cdboot.s
deleted file mode 100644 (file)
index 9b9c98a..0000000
+++ /dev/null
@@ -1,551 +0,0 @@
-#
-# Copyright (c) 2001 John Baldwin
-# 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: src/sys/boot/i386/cdboot/cdboot.s,v 1.9 2001/11/07 01:20:33 jhb Exp $
-# $DragonFly: src/sys/boot/i386/cdboot/Attic/cdboot.s,v 1.4 2004/07/18 16:51:38 dillon Exp $
-
-#
-# This program is a freestanding boot program to load an a.out binary
-# from a CD-ROM booted with no emulation mode as described by the El
-# Torito standard.  Due to broken BIOSen that do not load the desired
-# number of sectors, we try to fit this in as small a space as possible.
-#
-# Basically, we first create a set of boot arguments to pass to the loaded
-# binary.  Then we attempt to load /boot/loader from the CD we were booted
-# off of. 
-#
-
-#
-# Memory locations.
-#
-               .set MEM_PAGE_SIZE,0x1000       # memory page size, 4k
-               .set MEM_ARG,0x900              # Arguments at start
-               .set MEM_ARG_BTX,0xa100         # Where we move them to so the
-                                               #  BTX client can see them
-               .set MEM_ARG_SIZE,0x18          # Size of the arguments
-               .set MEM_BTX_ADDRESS,0x9000     # where BTX lives
-               .set MEM_BTX_ENTRY,0x9010       # where BTX starts to execute
-               .set MEM_BTX_OFFSET,MEM_PAGE_SIZE # offset of BTX in the loader
-               .set MEM_BTX_CLIENT,0xa000      # where BTX clients live
-#
-# a.out header fields
-#
-               .set AOUT_TEXT,0x04             # text segment size
-               .set AOUT_DATA,0x08             # data segment size
-               .set AOUT_BSS,0x0c              # zero'd BSS size
-               .set AOUT_SYMBOLS,0x10          # symbol table
-               .set AOUT_ENTRY,0x14            # entry point
-               .set AOUT_HEADER,MEM_PAGE_SIZE  # size of the a.out header
-#
-# Flags for kargs->bootflags
-#
-               .set KARGS_FLAGS_CD,0x1         # flag to indicate booting from
-                                               #  CD loader
-#
-# Segment selectors.
-#
-               .set SEL_SDATA,0x8              # Supervisor data
-               .set SEL_RDATA,0x10             # Real mode data
-               .set SEL_SCODE,0x18             # PM-32 code
-               .set SEL_SCODE16,0x20           # PM-16 code
-#
-# BTX constants
-#
-               .set INT_SYS,0x30               # BTX syscall interrupt
-#
-# Constants for reading from the CD.
-#
-               .set ERROR_TIMEOUT,0x80         # BIOS timeout on read
-               .set NUM_RETRIES,3              # Num times to retry
-               .set SECTOR_SIZE,0x800          # size of a sector
-               .set SECTOR_SHIFT,11            # number of place to shift
-               .set BUFFER_LEN,0x100           # number of sectors in buffer
-               .set MAX_READ,0x10000           # max we can read at a time
-               .set MAX_READ_SEC,MAX_READ >> SECTOR_SHIFT
-               .set MEM_READ_BUFFER,0x9000     # buffer to read from CD
-               .set MEM_VOLDESC,MEM_READ_BUFFER # volume descriptor
-               .set MEM_DIR,MEM_VOLDESC+SECTOR_SIZE # Lookup buffer
-               .set VOLDESC_LBA,0x10           # LBA of vol descriptor
-               .set VD_PRIMARY,1               # Primary VD
-               .set VD_END,255                 # VD Terminator
-               .set VD_ROOTDIR,156             # Offset of Root Dir Record
-               .set DIR_LEN,0                  # Offset of Dir Record length
-               .set DIR_EA_LEN,1               # Offset of EA length
-               .set DIR_EXTENT,2               # Offset of 64-bit LBA
-               .set DIR_SIZE,10                # Offset of 64-bit length
-               .set DIR_NAMELEN,32             # Offset of 8-bit name len
-               .set DIR_NAME,33                # Offset of dir name
-#
-# We expect to be loaded by the BIOS at 0x7c00 (standard boot loader entry
-# point)
-#
-               .code16
-               .globl start
-               .org 0x0, 0x0
-#
-# Program start.
-#
-start:         cld                             # string ops inc
-               xor %ax,%ax                     # zero %ax
-               mov %ax,%ss                     # setup the
-               mov $start,%sp                  #  stack
-               mov %ax,%ds                     # setup the
-               mov %ax,%es                     #  data segments
-               mov %dl,drive                   # Save BIOS boot device
-               mov $msg_welcome,%si            # %ds:(%si) -> welcome message
-               call putstr                     # display the welcome message
-#
-# Setup the arguments that the loader is expecting from boot[12]
-#
-               mov $msg_bootinfo,%si           # %ds:(%si) -> boot args message
-               call putstr                     # display the message
-               mov $MEM_ARG,%bx                # %ds:(%bx) -> boot args
-               mov %bx,%di                     # %es:(%di) -> boot args
-               xor %eax,%eax                   # zero %eax
-               mov $(MEM_ARG_SIZE/4),%cx       # Size of arguments in 32-bit
-                                               #  dwords
-               rep                             # Clear the arguments
-               stosl                           #  to zero
-               mov drive,%dl                   # Store BIOS boot device
-               mov %dl,0x4(%bx)                #  in kargs->bootdev
-               or $KARGS_FLAGS_CD,0x8(%bx)     # kargs->bootflags |=
-                                               #  KARGS_FLAGS_CD
-#
-# Load Volume Descriptor
-#
-               mov $VOLDESC_LBA,%eax           # Set LBA of first VD
-load_vd:
-               mov $1,%dh                      # One sector
-               mov $MEM_VOLDESC,%ebx           # Destination
-               call read                       # Read it in
-               cmpb $VD_PRIMARY,(%bx)          # Primary VD?
-               je have_vd                      # Yes
-               inc %eax                        #  try next
-               cmpb $VD_END,(%bx)              # Last VD?
-               jne load_vd                     # No, read next
-               mov $msg_novd,%si               # No VD
-               jmp error                       # Halt
-have_vd:                                       # Have Primary VD
-#
-# Lookup the loader binary.
-#
-               mov $loader_path,%si            # File to lookup
-               call lookup                     # Try to find it
-#
-# Load the binary into the buffer.  Due to real mode addressing limitations
-# we have to read it in in 64k chunks.
-#
-               mov DIR_SIZE(%bx),%eax          # Read file length
-               add $SECTOR_SIZE-1,%eax         # Convert length to sectors
-               shr $11,%eax
-               cmp $BUFFER_LEN,%eax
-               jbe load_sizeok
-               mov $msg_load2big,%si           # Error message
-               call error
-load_sizeok:   movzbw %al,%cx                  # Num sectors to read
-               mov DIR_EXTENT(%bx),%eax        # Load extent
-               xor %edx,%edx
-               mov DIR_EA_LEN(%bx),%dl
-               add %edx,%eax                   # Skip extended
-               mov $MEM_READ_BUFFER,%ebx       # Read into the buffer
-load_loop:     mov %cl,%dh
-               cmp $MAX_READ_SEC,%cl           # Truncate to max read size
-               jbe load_notrunc
-               mov $MAX_READ_SEC,%dh
-load_notrunc:  sub %dh,%cl                     # Update count
-               call read                       # Read it in
-               add $MAX_READ_SEC,%eax          # Update LBA
-               add $MAX_READ,%ebx              # Update dest addr
-               jcxz load_done                  # Done?
-               jmp load_loop                   # Keep going
-load_done:
-#
-# Turn on the A20 address line
-#
-               call seta20                     # Turn A20 on
-#
-# Relocate the loader and BTX using a very lazy protected mode
-#
-               mov $msg_relocate,%si           # Display the
-               call putstr                     #  relocation message
-               mov MEM_READ_BUFFER+AOUT_ENTRY,%edi # %edi is the destination
-               mov $(MEM_READ_BUFFER+AOUT_HEADER),%esi # %esi is
-                                               #  the start of the text
-                                               #  segment
-               mov MEM_READ_BUFFER+AOUT_TEXT,%ecx # %ecx = length of the text
-                                               #  segment
-               push %edi                       # Save entry point for later
-               lgdt gdtdesc                    # setup our own gdt
-               cli                             # turn off interrupts
-               mov %cr0,%eax                   # Turn on
-               or $0x1,%al                     #  protected
-               mov %eax,%cr0                   #  mode
-               ljmp $SEL_SCODE,$pm_start       # long jump to clear the
-                                               #  instruction pre-fetch queue
-               .code32
-pm_start:      mov $SEL_SDATA,%ax              # Initialize
-               mov %ax,%ds                     #  %ds and
-               mov %ax,%es                     #  %es to a flat selector
-               rep                             # Relocate the
-               movsb                           #  text segment
-               add $(MEM_PAGE_SIZE - 1),%edi   # pad %edi out to a new page
-               and $~(MEM_PAGE_SIZE - 1),%edi #  for the data segment
-               mov MEM_READ_BUFFER+AOUT_DATA,%ecx # size of the data segment
-               rep                             # Relocate the
-               movsb                           #  data segment
-               mov MEM_READ_BUFFER+AOUT_BSS,%ecx # size of the bss
-               xor %eax,%eax                   # zero %eax
-               add $3,%cl                      # round %ecx up to
-               shr $2,%ecx                     #  a multiple of 4
-               rep                             # zero the
-               stosl                           #  bss
-               mov MEM_READ_BUFFER+AOUT_ENTRY,%esi # %esi -> relocated loader
-               add $MEM_BTX_OFFSET,%esi        # %esi -> BTX in the loader
-               mov $MEM_BTX_ADDRESS,%edi       # %edi -> where BTX needs to go
-               movzwl 0xa(%esi),%ecx           # %ecx -> length of BTX
-               rep                             # Relocate
-               movsb                           #  BTX
-               ljmp $SEL_SCODE16,$pm_16        # Jump to 16-bit PM
-               .code16
-pm_16:         mov $SEL_RDATA,%ax              # Initialize
-               mov %ax,%ds                     #  %ds and
-               mov %ax,%es                     #  %es to a real mode selector
-               mov %cr0,%eax                   # Turn off
-               and $~0x1,%al                   #  protected
-               mov %eax,%cr0                   #  mode
-               ljmp $0,$pm_end                 # Long jump to clear the
-                                               #  instruction pre-fetch queue
-pm_end:                sti                             # Turn interrupts back on now
-#
-# Copy the BTX client to MEM_BTX_CLIENT
-#
-               xor %ax,%ax                     # zero %ax and set
-               mov %ax,%ds                     #  %ds and %es
-               mov %ax,%es                     #  to segment 0
-               mov $MEM_BTX_CLIENT,%di         # Prepare to relocate
-               mov $btx_client,%si             #  the simple btx client
-               mov $(btx_client_end-btx_client),%cx # length of btx client
-               rep                             # Relocate the
-               movsb                           #  simple BTX client
-#
-# Copy the boot[12] args to where the BTX client can see them
-#
-               mov $MEM_ARG,%si                # where the args are at now
-               mov $MEM_ARG_BTX,%di            # where the args are moving to
-               mov $(MEM_ARG_SIZE/4),%cx       # size of the arguments in longs
-               rep                             # Relocate
-               movsl                           #  the words
-#
-# Save the entry point so the client can get to it later on
-#
-               pop %eax                        # Restore saved entry point
-               stosl                           #  and add it to the end of
-                                               #  the arguments
-#
-# Now we just start up BTX and let it do the rest
-#
-               mov $msg_jump,%si               # Display the
-               call putstr                     #  jump message
-               ljmp $0,$MEM_BTX_ENTRY          # Jump to the BTX entry point
-
-#
-# Lookup the file in the path at [SI] from the root directory.
-#
-# Trashes: All but BX
-# Returns: BX = pointer to record
-#
-lookup:                mov $VD_ROOTDIR+MEM_VOLDESC,%bx # Root directory record
-               push %si
-               mov $msg_lookup,%si             # Display lookup message
-               call putstr
-               pop %si
-               push %si
-               call putstr
-               mov $msg_lookup2,%si
-               call putstr
-               pop %si
-lookup_dir:    lodsb                           # Get first char of path
-               cmp $0,%al                      # Are we done?
-               je lookup_done                  # Yes
-               cmp $'/',%al                    # Skip path separator.
-               je lookup_dir
-               dec %si                         # Undo lodsb side effect
-               call find_file                  # Lookup first path item
-               jnc lookup_dir                  # Try next component
-               mov $msg_lookupfail,%si         # Not found.
-               jmp error
-lookup_done:   mov $msg_lookupok,%si           # Success message
-               call putstr
-               ret
-
-#
-# Lookup file at [SI] in directory whose record is at [BX].
-#
-# Trashes: All but returns
-# Returns: CF = 0 (success), BX = pointer to record, SX = next path item
-#          CF = 1 (not found), SI = preserved
-#
-find_file:     mov DIR_EXTENT(%bx),%eax        # Load extent
-               xor %edx,%edx
-               mov DIR_EA_LEN(%bx),%dl
-               add %edx,%eax                   # Skip extended attributes
-               mov %eax,rec_lba                # Save LBA
-               mov DIR_SIZE(%bx),%eax          # Save size
-               mov %eax,rec_size
-               xor %cl,%cl                     # Zero length
-               push %si                        # Save
-ff.namelen:    inc %cl                         # Update length
-               lodsb                           # Read char
-               cmp $0,%al                      # Nul?
-               je ff.namedone                  # Yes
-               cmp $'/',%al                    # Path separator?
-               jnz ff.namelen                  # No, keep going
-ff.namedone:   dec %cl                         # Adjust length and save
-               mov %cl,name_len
-               pop %si                         # Restore
-ff.load:       mov rec_lba,%eax                # Load LBA
-               mov $MEM_DIR,%ebx               # Address buffer
-               mov $1,%dh                      # One sector
-               call read                       # Read directory block
-               incl rec_lba                    # Update LBA to next block
-ff.scan:       mov %ebx,%edx                   # Check for EOF
-               sub $MEM_DIR,%edx
-               cmp %edx,rec_size
-               ja ff.scan.1
-               stc                             # EOF reached
-               ret
-ff.scan.1:     cmpb $0,DIR_LEN(%bx)            # Last record in block?
-               je ff.nextblock
-               push %si                        # Save
-               movzbw DIR_NAMELEN(%bx),%si     # Find end of string
-ff.checkver:   cmpb $'0',DIR_NAME-1(%bx,%si)   # Less than '0'?
-               jb ff.checkver.1
-               cmpb $'9',DIR_NAME-1(%bx,%si)   # Greater than '9'?
-               ja ff.checkver.1
-               dec %si                         # Next char
-               jnz ff.checkver
-               jmp ff.checklen                 # All numbers in name, so
-                                               #  no version
-ff.checkver.1: movzbw DIR_NAMELEN(%bx),%cx
-               cmp %cx,%si                     # Did we find any digits?
-               je ff.checkdot                  # No
-               cmpb $';',DIR_NAME-1(%bx,%si)   # Check for semicolon
-               jne ff.checkver.2
-               dec %si                         # Skip semicolon
-               mov %si,%cx
-               mov %cl,DIR_NAMELEN(%bx)        # Adjust length
-               jmp ff.checkdot
-ff.checkver.2: mov %cx,%si                     # Restore %si to end of string
-ff.checkdot:   cmpb $'.',DIR_NAME-1(%bx,%si)   # Trailing dot?
-               jne ff.checklen                 # No
-               decb DIR_NAMELEN(%bx)           # Adjust length
-ff.checklen:   pop %si                         # Restore
-               movzbw name_len,%cx             # Load length of name
-               cmp %cl,DIR_NAMELEN(%bx)        # Does length match?
-               je ff.checkname                 # Yes, check name
-ff.nextrec:    add DIR_LEN(%bx),%bl            # Next record
-               adc $0,%bh
-               jmp ff.scan
-ff.nextblock:  subl $SECTOR_SIZE,rec_size      # Adjust size
-               jnc ff.load                     # If subtract ok, keep going
-               ret                             # End of file, so not found
-ff.checkname:  lea DIR_NAME(%bx),%di           # Address name in record
-               push %si                        # Save
-               repe cmpsb                      # Compare name
-               jcxz ff.match                   # We have a winner!
-               pop %si                         # Restore
-               jmp ff.nextrec                  # Keep looking.
-ff.match:      add $2,%sp                      # Discard saved %si
-               clc                             # Clear carry
-               ret
-
-# Load DH sectors starting at LBA EAX into [EBX].  No registers are destroyed.
-# Don't trust the BIOS, especially with regards to the msb 16 bits of our
-# registers.
-#
-read:          pushal                          # don't screw around
-               mov %eax,edd_lba                # LBA to read from
-               mov %ebx,%eax                   # Convert address
-               shr $4,%eax                     #  to segment
-               mov %ax,edd_addr+0x2            #  and store
-read.retry:    call twiddle                    # Entertain the user
-               push %dx                        # Save
-               mov $edd_packet,%si             # Address Packet
-               mov %dh,edd_len                 # Set length
-               mov drive,%dl                   # BIOS Device
-               mov $0x42,%ah                   # BIOS: Extended Read
-               int $0x13                       # Call BIOS
-               pop %dx                         # Restore
-               jc read.fail                    # Worked?
-               popal
-               ret                             # Return
-read.fail:     cmp $ERROR_TIMEOUT,%ah          # Timeout?
-               je read.retry                   # Yes, Retry.
-read.error:    mov %ah,%al                     # Save error
-               mov $hex_error,%di              # Format it
-               call hex8                       #  as hex
-               mov $msg_badread,%si            # Display Read error message
-
-#
-# Display error message at [SI] and halt.
-#
-error:         call putstr                     # Display message
-halt:          hlt
-               jmp halt                        # Spin
-
-#
-# Display a null-terminated string.
-#
-# Trashes: AX, SI
-#
-putstr:
-putstr.load:   lodsb                           # load %al from %ds:(%si)
-               test %al,%al                    # stop at null
-               jnz putstr.putc                 # if the char != null, output it
-               ret                             # return when null is hit
-putstr.putc:   call putc                       # output char
-               jmp putstr.load                 # next char
-
-# Display a single char(%al).  Don't trust the bios to save our regs.
-#
-putc:          pushal
-               mov $0x7,%bx                    # attribute for output
-               mov $0xe,%ah                    # BIOS: put_char
-               int $0x10                       # call BIOS, print char in %al
-               popal
-               ret                             # Return to caller
-
-#
-# Output the "twiddle"
-#
-twiddle:       push %ax                        # Save
-               push %bx                        # Save
-               mov twiddle_index,%al           # Load index
-               mov twiddle_chars,%bx           # Address table
-               inc %al                         # Next
-               and $3,%al                      #  char
-               mov %al,twiddle_index           # Save index for next call
-               xlat                            # Get char
-               call putc                       # Output it
-               mov $8,%al                      # Backspace
-               call putc                       # Output it
-               pop %bx                         # Restore
-               pop %ax                         # Restore
-               ret
-
-#
-# Enable A20
-#
-seta20:        cli                             # Disable interrupts
-seta20.1:      in $0x64,%al                    # Get status
-               test $0x2,%al                   # Busy?
-               jnz seta20.1                    # Yes
-               mov $0xd1,%al                   # Command: Write
-               out %al,$0x64                   #  output port
-seta20.2:      in $0x64,%al                    # Get status
-               test $0x2,%al                   # Busy?
-               jnz seta20.2                    # Yes
-               mov $0xdf,%al                   # Enable
-               out %al,$0x60                   #  A20
-               sti                             # Enable interrupts
-               ret                             # To caller
-
-#
-# Convert AL to hex, saving the result to [EDI].
-#
-hex8:          pushl %eax                      # Save
-               shrb $0x4,%al                   # Do upper
-               call hex8.1                     #  4
-               popl %eax                       # Restore
-hex8.1:        andb $0xf,%al                   # Get lower 4
-               cmpb $0xa,%al                   # Convert
-               sbbb $0x69,%al                  #  to hex
-               das                             #  digit
-               orb $0x20,%al                   # To lower case
-               stosb                           # Save char
-               ret                             # (Recursive)
-
-#
-# BTX client to start btxldr
-#
-               .code32
-btx_client:    mov $(MEM_ARG_BTX-MEM_BTX_CLIENT+MEM_ARG_SIZE-4), %esi
-                                               # %ds:(%esi) -> end
-                                               #  of boot[12] args
-               mov $(MEM_ARG_SIZE/4),%ecx      # Number of words to push
-               std                             # Go backwards
-push_arg:      lodsl                           # Read argument
-               push %eax                       # Push it onto the stack
-               loop push_arg                   # Push all of the arguments
-               cld                             # In case anyone depends on this
-               pushl MEM_ARG_BTX-MEM_BTX_CLIENT+MEM_ARG_SIZE # Entry point of
-                                               #  the loader
-               push %eax                       # Emulate a near call
-               mov $0x1,%eax                   # 'exec' system call
-               int $INT_SYS                    # BTX system call
-btx_client_end:
-               .code16
-
-               .p2align 4
-#
-# Global descriptor table.
-#
-gdt:           .word 0x0,0x0,0x0,0x0           # Null entry
-               .word 0xffff,0x0,0x9200,0xcf    # SEL_SDATA
-               .word 0xffff,0x0,0x9200,0x0     # SEL_RDATA
-               .word 0xffff,0x0,0x9a00,0xcf    # SEL_SCODE (32-bit)
-               .word 0xffff,0x0,0x9a00,0x8f    # SEL_SCODE16 (16-bit)
-gdt.1:
-#
-# Pseudo-descriptors.
-#
-gdtdesc:       .word gdt.1-gdt-1               # Limit
-               .long gdt                       # Base
-#
-# EDD Packet
-#
-edd_packet:    .byte 0x10                      # Length
-               .byte 0                         # Reserved
-edd_len:       .byte 0x0                       # Num to read
-               .byte 0                         # Reserved
-edd_addr:      .word 0x0,0x0                   # Seg:Off
-edd_lba:       .quad 0x0                       # LBA
-
-drive:         .byte 0
-
-#
-# State for searching dir
-#
-rec_lba:       .long 0x0                       # LBA (adjusted for EA)
-rec_size:      .long 0x0                       # File size
-name_len:      .byte 0x0                       # Length of current name
-
-twiddle_index: .byte 0x0
-
-msg_welcome:   .asciz  "CD Loader 1.01\r\n\n"
-msg_bootinfo:  .asciz  "Building the boot loader arguments\r\n"
-msg_relocate:  .asciz  "Relocating the loader and the BTX\r\n"
-msg_jump:      .asciz  "Starting the BTX loader\r\n"
-msg_badread:   .ascii  "Read Error: 0x"
-hex_error:     .ascii  "00\r\n"
-msg_novd:      .asciz  "Could not find Primary Volume Descriptor\r\n"
-msg_lookup:    .asciz  "Looking up "
-msg_lookup2:   .asciz  "... "
-msg_lookupok:  .asciz  "Found\r\n"
-msg_lookupfail:        .asciz  "File not found\r\n"
-msg_load2big:  .asciz  "File too big\r\n"
-loader_path:   .asciz  "/BOOT/LOADER"
-twiddle_chars: .ascii  "|/-\\"
-
index 62775d2..4acabba 100644 (file)
@@ -1,5 +1,5 @@
 # $FreeBSD: src/sys/boot/i386/pxeldr/Makefile,v 1.9 2003/09/03 08:12:20 phk Exp $
-# $DragonFly: src/sys/boot/i386/pxeldr/Attic/Makefile,v 1.4 2004/01/31 06:56:42 dillon Exp $
+# $DragonFly: src/sys/boot/i386/pxeldr/Attic/Makefile,v 1.5 2004/07/18 23:40:09 dillon Exp $
 
 ORG=           0x7c00
 
@@ -10,14 +10,13 @@ PROG=               ${BOOT}
 MAN=           ${BOOT}.8
 STRIP=
 BINDIR?=       /boot
-M4?=           m4
 
 .if defined(BOOT_PXELDR_PROBE_KEYBOARD)
-M4FLAGS+=      -DPROBE_KEYBOARD
+AFLAGS+=       -DPROBE_KEYBOARD
 .endif
 
 .if defined(BOOT_PXELDR_ALWAYS_SERIAL)
-M4FLAGS+=      -DALWAYS_SERIAL
+AFLAGS+=       -DALWAYS_SERIAL
 .endif
 
 
@@ -50,9 +49,8 @@ ${LDR}: ${LDR}.o
        ${LD} -N -e start -Ttext ${ORG} -o ${LDR}.out ${LDR}.o
        objcopy -S -O binary ${LDR}.out ${.TARGET}
 
-${LDR}.o: ${LDR}.s
-       (cd ${.CURDIR}; ${M4} ${M4FLAGS} ${LDR}.s) | \
-          ${AS} ${AFLAGS} -o ${.TARGET}
+${LDR}.o: ${LDR}.S
+       ${CC} ${CFLAGS} ${AFLAGS} ${.IMPSRC} -o ${LDR}.o -c
 
 CLEANFILES+= ${LDR} ${LDR}.out ${LDR}.o ${BOOT}.tmp ${LOADER}
 
index 429ac76..aac2632 100644 (file)
@@ -1,87 +1,84 @@
-#
-# Copyright (c) 2000 John Baldwin
-# 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.
-#
+/*
+ * Copyright (c) 2000 John Baldwin
+ * 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: src/sys/boot/i386/pxeldr/pxeldr.s,v 1.9 2003/09/03 08:12:20 phk Exp $
+ * $DragonFly: src/sys/boot/i386/pxeldr/Attic/pxeldr.S,v 1.4 2004/07/18 23:40:09 dillon Exp $
+ */
 
-# $FreeBSD: src/sys/boot/i386/pxeldr/pxeldr.s,v 1.9 2003/09/03 08:12:20 phk Exp $
-# $DragonFly: src/sys/boot/i386/pxeldr/Attic/pxeldr.S,v 1.3 2003/11/10 06:08:37 dillon Exp $
+/*
+ * This simple program is a preloader for the normal boot3 loader.  It is
+ * simply prepended to the beginning of a fully built and btxld'd loader.
+ * It then copies the loader to the address boot2 normally loads it,
+ * emulates the boot[12] environment (protected mode, a bootinfo struct,
+ * etc.), and then jumps to the start of btxldr to start the boot process.
+ * This method allows a stock /boot/loader to be booted over the network
+ * via PXE w/o having to write a separate PXE-aware client just to load
+ * the loader.
+ */
+#include "../bootasm.h"
 
-#
-# This simple program is a preloader for the normal boot3 loader.  It is simply
-# prepended to the beginning of a fully built and btxld'd loader.  It then
-# copies the loader to the address boot2 normally loads it, emulates the
-# boot[12] environment (protected mode, a bootinfo struct, etc.), and then jumps
-# to the start of btxldr to start the boot process.  This method allows a stock
-# /boot/loader to be booted over the network via PXE w/o having to write a
-# separate PXE-aware client just to load the loader.
-#
-
-#
-# Memory locations.
-#
-               .set MEM_PAGE_SIZE,0x1000       # memory page size, 4k
-               .set MEM_ARG,0x900              # Arguments at start
-               .set MEM_ARG_BTX,0xa100         # Where we move them to so the
-                                               #  BTX client can see them
-               .set MEM_ARG_SIZE,0x18          # Size of the arguments
-               .set MEM_BTX_ADDRESS,0x9000     # where BTX lives
-               .set MEM_BTX_ENTRY,0x9010       # where BTX starts to execute
-               .set MEM_BTX_OFFSET,MEM_PAGE_SIZE # offset of BTX in the loader
-               .set MEM_BTX_CLIENT,0xa000      # where BTX clients live
-               .set MEM_BIOS_KEYBOARD,0x496    # BDA byte with keyboard bit
-#
-# a.out header fields
-#
+               /*
+                * a.out header fields
+                */
                .set AOUT_TEXT,0x04             # text segment size
                .set AOUT_DATA,0x08             # data segment size
-               .set AOUT_BSS,0x0c              # zero'd BSS size
+               .set AOUT_BSS,0x0c              # zerod BSS size
                .set AOUT_SYMBOLS,0x10          # symbol table
                .set AOUT_ENTRY,0x14            # entry point
                .set AOUT_HEADER,MEM_PAGE_SIZE  # size of the a.out header
-#
-# Flags for kargs->bootflags
-#
+
+               /*
+                * Flags for kargs->bootflags
+                */
                .set KARGS_FLAGS_PXE,0x2        # flag to indicate booting from
                                                #  PXE loader
-#
-# Boot howto bits
-#
+               /*
+                * Boot howto bits
+                */
                .set RB_SERIAL,0x1000           # serial console
-#
-# Segment selectors.
-#
+
+               /*
+                * Segment selectors.
+                */
                .set SEL_SDATA,0x8              # Supervisor data
                .set SEL_RDATA,0x10             # Real mode data
                .set SEL_SCODE,0x18             # PM-32 code
                .set SEL_SCODE16,0x20           # PM-16 code
-#
-# BTX constants
-#
+
+               /*
+                * BTX constants
+                */
                .set INT_SYS,0x30               # BTX syscall interrupt
-#
-# Bit in MEM_BIOS_KEYBOARD that is set if an enhanced keyboard is present
-#
+
+               /*
+                * Bit in BDA_KEYBOARD that is set if an enhanced
+                * keyboard is present.
+                */
                .set KEYBOARD_BIT,0x10
-#
-# We expect to be loaded by the BIOS at 0x7c00 (standard boot loader entry
-# point)
-#
+
+               /*
+                * We expect to be loaded by the BIOS at LOAD (0x7c00),
+                * which is the standard boot loader entry point.
+                */
                .code16
                .globl start
                .org 0x0, 0x0
-#
-# BTX program loader for PXE network booting
-#
+
+               /*
+                * BTX program loader for PXE network booting
+                */
 start:         cld                             # string ops inc
                xorw %ax, %ax                   # zero %ax
                movw %ax, %ss                   # setup the
@@ -96,9 +93,11 @@ start:               cld                             # string ops inc
                pushl %ecx                      #  save it on the stack
                movw $welcome_msg, %si          # %ds:(%si) -> welcome message
                callw putstr                    # display the welcome message
-#
-# Setup the arguments that the loader is expecting from boot[12]
-#
+
+               /*
+                * Setup the arguments that the loader is expecting
+                * from boot[12]
+                */
                movw $bootinfo_msg, %si         # %ds:(%si) -> boot args message
                callw putstr                    # display the message
                movw $MEM_ARG, %bx              # %ds:(%bx) -> boot args
@@ -111,27 +110,32 @@ start:            cld                             # string ops inc
                orb $KARGS_FLAGS_PXE, 0x8(%bx)  # kargs->bootflags |=
                                                #  KARGS_FLAGS_PXE
                popl 0xc(%bx)                   # kargs->pxeinfo = *PXENV+
-ifdef(`ALWAYS_SERIAL',`
-#
-# set the RBX_SERIAL bit in the howto byte.
+#ifdef ALWAYS_SERIAL
+               /*
+                * set the RBX_SERIAL bit in the howto byte.
+                */
                orl $RB_SERIAL, (%bx)           # enable serial console
-')
-ifdef(`PROBE_KEYBOARD',`
-#
-# Look at the BIOS data area to see if we have an enhanced keyboard.  If not,
-# set the RBX_SERIAL bit in the howto byte.
-               testb $KEYBOARD_BIT, MEM_BIOS_KEYBOARD # keyboard present?
+#endif
+#ifdef PROBE_KEYBOARD
+               /*
+                * Look at the BIOS data area to see if we have an enhanced
+                * keyboard.  If not, set the RBX_SERIAL bit in the howto 
+                * byte.
+                */
+               testb $KEYBOARD_BIT, BDA_KEYBOARD # keyboard present?
                jnz keyb                        # yes, so skip
                orl $RB_SERIAL, (%bx)           # enable serial console
 keyb:
-')
-#
-# Turn on the A20 address line
-#
+#endif
+               /*
+                * Turn on the A20 address line
+                */
                callw seta20                    # Turn A20 on
-#
-# Relocate the loader and BTX using a very lazy protected mode
-#
+
+               /*
+                * Relocate the loader and BTX using a very lazy protected
+                * mode
+                */
                movw $relocate_msg, %si         # Display the
                callw putstr                    #  relocation message
                movl end+AOUT_ENTRY, %edi       # %edi is the destination
@@ -165,8 +169,8 @@ pm_start:   movw $SEL_SDATA, %ax            # Initialize
                rep                             # zero the
                stosl                           #  bss
                movl end+AOUT_ENTRY, %esi       # %esi -> relocated loader
-               addl $MEM_BTX_OFFSET, %esi      # %esi -> BTX in the loader
-               movl $MEM_BTX_ADDRESS, %edi     # %edi -> where BTX needs to go
+               addl $MEM_BTX_LDR_OFF, %esi     # %esi -> BTX in the loader
+               mo