freebsd-dev/sys/boot/i386/boot0/boot0.s
Robert Nordier 12c38b04f1 Drop EDD support detection, though retain configurable use of disk
packet interface.  Add booteasy-style F5 support.  Add no-update
option. Implement various space optimizations and consistency fixes.
1998-11-29 14:09:00 +00:00

247 lines
6.8 KiB
ArmAsm

#
# 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.
#
# $Id: boot0.s,v 1.4 1998/10/19 19:13:53 rnordier Exp $
# A 512-byte boot manager.
.set LOAD,0x7c00 # Load address
.set ORIGIN,0x600 # Execution address
.set PRT_OFF,0x1be # Partition table
.set FAKE,0x810 # Partition entry
.set NHRDRV,0x475 # Number of hard drives
.set TBL0SZ,0x3 # Table 0 size
.set TBL1SZ,0xa # Table 1 size
.set _NXTDRV,-0x47 # Drive number
.set _OPT,-0x46 # Default option
.set _FLAG,-0x45 # Flags
.set _TICKS,-0x44 # Timeout ticks
.set _FAKE,0x10 # Fake partition entry
.set _MNUOPT,0x1c # Menu options
.globl start # Entry point
start: cld # String ops inc
xorl %eax,%eax # Zero
movl %eax,%es # Address
movl %eax,%ds # data
movl %eax,%ss # Set up
movwir(LOAD,_sp) # stack
movl %esp,%esi # Source
movwir(start,_di) # Destination
movwir(0x100,_cx) # Word count
rep # Relocate
movsl # code
movl %edi,%ebp # Address variables
movb $0x10,%cl # Words to clear
rep # Zero
stosl # them
incb1(-0xe,_di_) # Sector number
jmpnwi(main-LOAD+ORIGIN) # To relocated code
main: movbr1(_dl,_FAKE,_bp_) # Save drive number
callwi(putn) # To new line
movwir(partbl,_bx) # Partition table
xorl %edx,%edx # Item
main.1: movbr0(_dh,_bx_) # Mark inactive
movb1r(0x4,_bx_,_al) # Load type
movwir(tables,_di) # Lookup tables
movb $TBL0SZ,%cl # Entries
repne # Exclude
scasb # partition?
je main.3 # Yes
movb $TBL1SZ,%cl # Entries
repne # Known
scasb # type?
jne main.2 # No
addwir(TBL1SZ,_di) # Adjust
main.2: movb0r(_di_,_cl) # Partition
addl %ecx,%edi # description
callwi(putx) # Display it
main.3: addwir(0x10,_bx) # Next entry
incl %edx # Next item
cmpb $0x4,%dl # Done?
jb main.1 # No
movb1r(_FAKE,_bp_,_al) # Drive number
subb $0x80-0x1,%al # Does next
cmpbmr(NHRDRV,_al) # drive exist?
jb main.4 # Yes
decb %al # Already drive 0?
jz main.5 # Yes
xorb %al,%al # Drive 0
main.4: addb $'0'|0x80,%al # Save
movbr1(_al,_NXTDRV,_bp_) # it
movwir(drive,_di) # Display
callwi(putx) # item
main.5: movwir(prompt,_si) # Display
callwi(putstr) # prompt
movb1r(_OPT,_bp_,_dl) # Display
decl %esi # default
callwi(putkey) # key
xorb %ah,%ah # BIOS: Get
int $0x1a # system time
movl %edx,%edi # Save
main.6: movb $0x1,%ah # BIOS: Check
int $0x16 # for keypress
jnz main.9 # Have one
xorb %ah,%ah # BIOS: Get
int $0x1a # system time
subl %edi,%edx # Elapsed time
cmpw1r(_TICKS,_bp_,_dx) # Timeout?
jb main.6 # No
main.7: movb1r(_OPT,_bp_,_al) # Load default
jmp main.10 # Join common code
main.8: movb $0x7,%al # Signal
callwi(putchr) # error
main.9: xorb %ah,%ah # BIOS: Get
int $0x16 # keypress
movb %ah,%al # Scan code
cmpb $0x1c,%al # Enter pressed?
je main.7 # No
subb $0x3b,%al # Less F1 scan code
cmpb $0x4,%al # F1..F5?
ja main.8 # No
main.10: cwtl # Option
btwr1(_ax,_MNUOPT,_bp_) # enabled?
jnc main.8 # No
movwir(FAKE,_si) # Partition entry
movb1r(_NXTDRV,_bp_,_dl) # Next drive
subb $'0',%dl # number
cmpb $0x4,%al # F5 pressed?
je main.11 # Yes
movb0r(_si_,_dl) # Drive number
movbr1(_al,_OPT,_bp_) # Save option
shlb $0x4,%al # Point to
addwia(partbl) # partition
xchgl %esi,%eax # entry
tstbi1(0x40,_FLAG,_bp_) # No updates?
jnz main.11 # Yes
movbi0(0x80,_si_) # Flag active
pushl %esi # Save
xchgl %esi,%eax # Fake partition entry
movwir(start,_bx) # Data to write
movwir(0x301,_ax) # Write sector
callwi(intx13) # to disk
popl %esi # Restore
main.11: movwir(LOAD,_bx) # Address for read
movwir(0x201,_ax) # Read sector
callwi(intx13) # from disk
jc main.8 # If error
cmpwi2(0xaa55,0x1fe,_bx_) # Bootable?
jne main.8 # No
movwir(crlf,_si) # Leave some
callwi(puts) # space
jmp *%ebx # Invoke bootstrap
# Display routines
putkey: movb $'F',%al # Display
callwi(putchr) # 'F'
movb $'1',%al # Prepare
addb %dl,%al # digit
jmp putstr.1 # Display the rest
putx: btswr1(_dx,_MNUOPT,_bp_) # Enable menu option
movwir(item,_si) # Display
callwi(putkey) # key
movl %edi,%esi # Display the rest
puts: callwi(putstr) # Display string
putn: movwir(crlf,_si) # To next line
putstr: lodsb # Get byte
testb $0x80,%al # End of string?
jnz putstr.2 # Yes
putstr.1: callwi(putchr) # Display char
jmp putstr # Continue
putstr.2: andb $~0x80,%al # Clear MSB
putchr: pushl %ebx # Save
movwir(0x7,_bx) # Page:attribute
movb $0xe,%ah # BIOS: Display
int $0x10 # character
popl %ebx # Restore
ret # To caller
# Disk I/O routine
intx13: cli # Disable interrupts
movb1r(0x1,_si_,_dh) # Load head
movw1r(0x2,_si_,_cx) # Load cylinder:sector
o16 # Load
movw1r(0x8,_si_,_di) # offset
movwir(break,_si) # Packet pointer
movbi0(0x10,_si_) # Packet size
movbr1(_al,0x2,_si_) # Block count
movwr1(_bx,0x4,_si_) # Transfer
movws1(_es,0x6,_si_) # buffer
o16 # LBA
movwr1(_di,0x8,_si_) # address
sti # Enable interrupts
tstbi1(0x80,_FLAG,_bp_) # Try for extensions?
jz intx13.1 # No
orb $0x40,%ah # Use disk packet
decl %eax # Verify off
intx13.1: int $0x13 # BIOS: Disk I/O
ret # To caller
# Menu strings
item: .ascii " "; .byte ' '|0x80
prompt: .ascii "\nDefault:"; .byte ' '|0x80
crlf: .ascii "\r"; .byte '\n'|0x80
# Partition type tables
tables:
.byte 0x0, 0x5, 0xf
.byte 0x1, 0x4, 0x6, 0xb, 0xc, 0xe, 0x63, 0x83
.byte 0xa5, 0xa6
.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_unix-. # UNIX
.byte os_linux-. # Linux
.byte os_freebsd-. # FreeBSD
.byte os_bsd-. # OpenBSD
os_misc: .ascii "?"; .byte '?'|0x80
os_dos: .ascii "DO"; .byte 'S'|0x80
os_unix: .ascii "UNI"; .byte 'X'|0x80
os_linux: .ascii "Linu"; .byte 'x'|0x80
os_freebsd: .ascii "Free"
os_bsd: .ascii "BS"; .byte 'D'|0x80
.org PRT_OFF-0xb,0x90
drive: .ascii "Drive "
drvnum: .byte 0x0
opt: .byte 0x0 # Option
flags: .byte FLAGS # Flags
ticks: .word TICKS # Delay
partbl: .fill 0x40,0x1,0x0 # Partition table
.word 0xaa55 # Magic number
break: # Uninitialized data