1998-10-05 10:08:37 +00:00
|
|
|
#
|
|
|
|
# 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.
|
|
|
|
#
|
|
|
|
|
1999-06-18 21:49:18 +00:00
|
|
|
# $Id: boot0.s,v 1.8 1999/03/01 02:42:47 rnordier Exp $
|
1998-10-05 10:08:37 +00:00
|
|
|
|
|
|
|
# A 512-byte boot manager.
|
|
|
|
|
1998-12-05 11:58:33 +00:00
|
|
|
.set NHRDRV,0x475 # Number of hard drives
|
1998-11-29 14:09:00 +00:00
|
|
|
.set ORIGIN,0x600 # Execution address
|
1999-06-18 21:49:18 +00:00
|
|
|
.set FAKE,0x800 # Partition entry
|
1998-12-05 11:58:33 +00:00
|
|
|
.set LOAD,0x7c00 # Load address
|
|
|
|
|
|
|
|
.set PRT_OFF,0x1be # Partition table
|
|
|
|
|
1998-11-29 14:09:00 +00:00
|
|
|
.set TBL0SZ,0x3 # Table 0 size
|
|
|
|
.set TBL1SZ,0xa # Table 1 size
|
|
|
|
|
1998-12-05 11:58:33 +00:00
|
|
|
.set MAGIC,0xaa55 # Magic: bootable
|
|
|
|
|
|
|
|
.set KEY_ENTER,0x1c # Enter key scan code
|
|
|
|
.set KEY_F1,0x3b # F1 key scan code
|
|
|
|
|
1999-02-26 14:51:14 +00:00
|
|
|
.set _NXTDRV,-0x48 # Next drive
|
|
|
|
.set _OPT,-0x47 # Default option
|
|
|
|
.set _SETDRV,-0x46 # Drive to force
|
1998-12-05 11:58:33 +00:00
|
|
|
.set _FLAGS,-0x45 # Flags
|
1998-11-29 14:09:00 +00:00
|
|
|
.set _TICKS,-0x44 # Timeout ticks
|
1999-06-18 21:49:18 +00:00
|
|
|
.set _FAKE,0x0 # Fake partition entry
|
|
|
|
.set _MNUOPT,0xc # Menu options
|
1998-10-05 10:08:37 +00:00
|
|
|
|
|
|
|
.globl start # Entry point
|
|
|
|
|
1998-11-29 14:09:00 +00:00
|
|
|
start: cld # String ops inc
|
1998-10-05 10:08:37 +00:00
|
|
|
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
|
1998-11-29 14:09:00 +00:00
|
|
|
movl %edi,%ebp # Address variables
|
1999-06-18 21:49:18 +00:00
|
|
|
movb $0x8,%cl # Words to clear
|
1998-10-05 10:08:37 +00:00
|
|
|
rep # Zero
|
1998-10-10 14:03:03 +00:00
|
|
|
stosl # them
|
1998-10-05 10:08:37 +00:00
|
|
|
incb1(-0xe,_di_) # Sector number
|
|
|
|
jmpnwi(main-LOAD+ORIGIN) # To relocated code
|
|
|
|
|
1999-06-18 21:49:18 +00:00
|
|
|
main: tstbi1(0x20,_FLAGS,_bp_) # Set number drive?
|
|
|
|
jnz main.1 # Yes
|
|
|
|
testb %dl,%dl # Drive number valid?
|
|
|
|
js main.2 # Possibly
|
|
|
|
main.1: movb1r(_SETDRV,_bp_,_dl) # Drive number to use
|
|
|
|
main.2: movbr1(_dl,_FAKE,_bp_) # Save drive number
|
1998-10-05 10:08:37 +00:00
|
|
|
callwi(putn) # To new line
|
1999-06-18 21:49:18 +00:00
|
|
|
pushl %edx # Save drive number
|
|
|
|
movwir(partbl+0x4,_bx) # Partition table
|
|
|
|
xorl %edx,%edx # Item number
|
|
|
|
main.3: movbr1(_ch,-0x4,_bx_) # Zero active flag
|
|
|
|
movb0r(_bx_,_al) # Load type
|
1998-11-29 14:09:00 +00:00
|
|
|
movwir(tables,_di) # Lookup tables
|
1999-06-18 21:49:18 +00:00
|
|
|
movb $TBL0SZ,%cl # Number of entries
|
1998-10-05 10:08:37 +00:00
|
|
|
repne # Exclude
|
|
|
|
scasb # partition?
|
1999-06-18 21:49:18 +00:00
|
|
|
je main.5 # Yes
|
|
|
|
movb $TBL1SZ,%cl # Number of entries
|
1998-10-05 10:08:37 +00:00
|
|
|
repne # Known
|
|
|
|
scasb # type?
|
1999-06-18 21:49:18 +00:00
|
|
|
jne main.4 # No
|
1998-11-29 14:09:00 +00:00
|
|
|
addwir(TBL1SZ,_di) # Adjust
|
1999-06-18 21:49:18 +00:00
|
|
|
main.4: movb0r(_di_,_cl) # Partition
|
1998-11-29 14:09:00 +00:00
|
|
|
addl %ecx,%edi # description
|
|
|
|
callwi(putx) # Display it
|
1999-06-18 21:49:18 +00:00
|
|
|
main.5: incl %edx # Next item
|
|
|
|
addb $0x10,%bl # Next entry
|
|
|
|
jnc main.3 # Till done
|
|
|
|
popl %eax # Drive number
|
1998-11-29 14:09:00 +00:00
|
|
|
subb $0x80-0x1,%al # Does next
|
|
|
|
cmpbmr(NHRDRV,_al) # drive exist?
|
1999-06-18 21:49:18 +00:00
|
|
|
jb main.6 # Yes
|
|
|
|
decl %eax # Already drive 0?
|
|
|
|
jz main.7 # Yes
|
1998-11-29 14:09:00 +00:00
|
|
|
xorb %al,%al # Drive 0
|
1999-06-18 21:49:18 +00:00
|
|
|
main.6: addb $'0'|0x80,%al # Save next
|
|
|
|
movbr1(_al,_NXTDRV,_bp_) # drive number
|
1998-11-29 14:09:00 +00:00
|
|
|
movwir(drive,_di) # Display
|
|
|
|
callwi(putx) # item
|
1999-06-18 21:49:18 +00:00
|
|
|
main.7: movwir(prompt,_si) # Display
|
1998-10-05 10:08:37 +00:00
|
|
|
callwi(putstr) # prompt
|
1998-11-29 14:09:00 +00:00
|
|
|
movb1r(_OPT,_bp_,_dl) # Display
|
1998-10-05 10:08:37 +00:00
|
|
|
decl %esi # default
|
|
|
|
callwi(putkey) # key
|
|
|
|
xorb %ah,%ah # BIOS: Get
|
|
|
|
int $0x1a # system time
|
1999-06-18 21:49:18 +00:00
|
|
|
movl %edx,%edi # Ticks when
|
|
|
|
addw1r(_TICKS,_bp_,_di) # timeout
|
|
|
|
main.8: movb $0x1,%ah # BIOS: Check
|
1998-10-05 10:08:37 +00:00
|
|
|
int $0x16 # for keypress
|
1999-06-18 21:49:18 +00:00
|
|
|
jnz main.11 # Have one
|
1998-10-05 10:08:37 +00:00
|
|
|
xorb %ah,%ah # BIOS: Get
|
|
|
|
int $0x1a # system time
|
1999-06-18 21:49:18 +00:00
|
|
|
cmpl %edi,%edx # Timeout?
|
|
|
|
jb main.8 # No
|
|
|
|
main.9: movb1r(_OPT,_bp_,_al) # Load default
|
|
|
|
jmp main.12 # Join common code
|
|
|
|
main.10: movb $0x7,%al # Signal
|
1998-10-05 10:08:37 +00:00
|
|
|
callwi(putchr) # error
|
1999-06-18 21:49:18 +00:00
|
|
|
main.11: xorb %ah,%ah # BIOS: Get
|
1998-10-05 10:08:37 +00:00
|
|
|
int $0x16 # keypress
|
|
|
|
movb %ah,%al # Scan code
|
1998-12-05 11:58:33 +00:00
|
|
|
cmpb $KEY_ENTER,%al # Enter pressed?
|
1999-06-18 21:49:18 +00:00
|
|
|
je main.9 # Yes
|
1998-12-05 11:58:33 +00:00
|
|
|
subb $KEY_F1,%al # Less F1 scan code
|
1998-11-29 14:09:00 +00:00
|
|
|
cmpb $0x4,%al # F1..F5?
|
1999-06-18 21:49:18 +00:00
|
|
|
ja main.10 # No
|
|
|
|
main.12: cwtl # Option
|
1998-11-29 14:09:00 +00:00
|
|
|
btwr1(_ax,_MNUOPT,_bp_) # enabled?
|
1999-06-18 21:49:18 +00:00
|
|
|
jnc main.10 # No
|
1998-11-29 14:09:00 +00:00
|
|
|
movbr1(_al,_OPT,_bp_) # Save option
|
1999-03-01 02:42:47 +00:00
|
|
|
movwir(FAKE,_si) # Partition for write
|
|
|
|
movb0r(_si_,_dl) # Drive number
|
|
|
|
movl %esi,%ebx # Partition for read
|
|
|
|
cmpb $0x4,%al # F5 pressed?
|
|
|
|
pushfl # Save
|
1999-06-18 21:49:18 +00:00
|
|
|
je main.13 # Yes
|
|
|
|
shlb $0x4,%al # Point to
|
|
|
|
addwia(partbl) # selected
|
|
|
|
xchgl %ebx,%eax # partition
|
1999-03-01 02:42:47 +00:00
|
|
|
movbi0(0x80,_bx_) # Flag active
|
1999-06-18 21:49:18 +00:00
|
|
|
main.13: pushl %ebx # Save
|
1998-12-05 11:58:33 +00:00
|
|
|
tstbi1(0x40,_FLAGS,_bp_) # No updates?
|
1999-06-18 21:49:18 +00:00
|
|
|
jnz main.14 # Yes
|
1998-10-05 10:08:37 +00:00
|
|
|
movwir(start,_bx) # Data to write
|
1999-06-18 21:49:18 +00:00
|
|
|
movb $0x3,%ah # Write sector
|
1998-10-05 10:08:37 +00:00
|
|
|
callwi(intx13) # to disk
|
1999-06-18 21:49:18 +00:00
|
|
|
main.14: popl %esi # Restore
|
1999-03-01 02:42:47 +00:00
|
|
|
popfl # Restore
|
1999-06-18 21:49:18 +00:00
|
|
|
jne main.15 # If not F5
|
1999-03-01 02:42:47 +00:00
|
|
|
movb1r(_NXTDRV,_bp_,_dl) # Next drive
|
|
|
|
subb $'0',%dl # number
|
1999-06-18 21:49:18 +00:00
|
|
|
main.15: movwir(LOAD,_bx) # Address for read
|
|
|
|
movb $0x2,%ah # Read sector
|
1998-10-05 10:08:37 +00:00
|
|
|
callwi(intx13) # from disk
|
1999-06-18 21:49:18 +00:00
|
|
|
jc main.10 # If error
|
1998-12-05 11:58:33 +00:00
|
|
|
cmpwi2(MAGIC,0x1fe,_bx_) # Bootable?
|
1999-06-18 21:49:18 +00:00
|
|
|
jne main.10 # No
|
|
|
|
pushl %esi # Save
|
1998-10-10 14:03:03 +00:00
|
|
|
movwir(crlf,_si) # Leave some
|
|
|
|
callwi(puts) # space
|
1999-06-18 21:49:18 +00:00
|
|
|
popl %esi # Restore
|
1998-10-05 10:08:37 +00:00
|
|
|
jmp *%ebx # Invoke bootstrap
|
|
|
|
|
|
|
|
# Display routines
|
|
|
|
|
1998-11-29 14:09:00 +00:00
|
|
|
putkey: movb $'F',%al # Display
|
1998-10-05 10:08:37 +00:00
|
|
|
callwi(putchr) # 'F'
|
|
|
|
movb $'1',%al # Prepare
|
|
|
|
addb %dl,%al # digit
|
|
|
|
jmp putstr.1 # Display the rest
|
|
|
|
|
1998-11-29 14:09:00 +00:00
|
|
|
putx: btswr1(_dx,_MNUOPT,_bp_) # Enable menu option
|
|
|
|
movwir(item,_si) # Display
|
|
|
|
callwi(putkey) # key
|
|
|
|
movl %edi,%esi # Display the rest
|
|
|
|
|
1998-10-05 10:08:37 +00:00
|
|
|
puts: callwi(putstr) # Display string
|
|
|
|
|
|
|
|
putn: movwir(crlf,_si) # To next line
|
|
|
|
|
1998-11-29 14:09:00 +00:00
|
|
|
putstr: lodsb # Get byte
|
|
|
|
testb $0x80,%al # End of string?
|
1998-10-05 10:08:37 +00:00
|
|
|
jnz putstr.2 # Yes
|
|
|
|
putstr.1: callwi(putchr) # Display char
|
|
|
|
jmp putstr # Continue
|
1998-11-29 14:09:00 +00:00
|
|
|
putstr.2: andb $~0x80,%al # Clear MSB
|
1998-10-05 10:08:37 +00:00
|
|
|
|
1998-11-29 14:09:00 +00:00
|
|
|
putchr: pushl %ebx # Save
|
|
|
|
movwir(0x7,_bx) # Page:attribute
|
1998-10-05 10:08:37 +00:00
|
|
|
movb $0xe,%ah # BIOS: Display
|
|
|
|
int $0x10 # character
|
|
|
|
popl %ebx # Restore
|
|
|
|
ret # To caller
|
|
|
|
|
1999-06-18 21:49:18 +00:00
|
|
|
# One-sector disk I/O routine
|
1998-10-05 10:08:37 +00:00
|
|
|
|
1999-06-18 21:49:18 +00:00
|
|
|
intx13: movb1r(0x1,_si_,_dh) # Load head
|
1998-10-05 10:08:37 +00:00
|
|
|
movw1r(0x2,_si_,_cx) # Load cylinder:sector
|
1999-06-18 21:49:18 +00:00
|
|
|
movb $0x1,%al # Sector count
|
|
|
|
pushl %esi # Save
|
|
|
|
movl %esp,%edi # Save
|
1998-12-05 11:58:33 +00:00
|
|
|
tstbi1(0x80,_FLAGS,_bp_) # Use packet interface?
|
1998-10-05 10:08:37 +00:00
|
|
|
jz intx13.1 # No
|
1999-06-18 21:49:18 +00:00
|
|
|
o16 # Set
|
|
|
|
pushb $0x0 # the
|
|
|
|
o16 # LBA
|
|
|
|
pushw1(0x8,_si_) # address
|
|
|
|
pushl %es # Set the transfer
|
|
|
|
pushl %ebx # buffer address
|
|
|
|
pushb $0x1 # Block count
|
|
|
|
pushb $0x10 # Packet size
|
|
|
|
movl %esp,%esi # Packet pointer
|
1998-11-29 14:09:00 +00:00
|
|
|
decl %eax # Verify off
|
1999-06-18 21:49:18 +00:00
|
|
|
orb $0x40,%ah # Use disk packet
|
1998-11-29 14:09:00 +00:00
|
|
|
intx13.1: int $0x13 # BIOS: Disk I/O
|
1999-06-18 21:49:18 +00:00
|
|
|
movl %edi,%esp # Restore
|
|
|
|
popl %esi # Restore
|
1998-10-05 10:08:37 +00:00
|
|
|
ret # To caller
|
|
|
|
|
|
|
|
# Menu strings
|
|
|
|
|
1998-11-29 14:09:00 +00:00
|
|
|
item: .ascii " "; .byte ' '|0x80
|
1998-10-05 10:08:37 +00:00
|
|
|
prompt: .ascii "\nDefault:"; .byte ' '|0x80
|
1998-11-29 14:09:00 +00:00
|
|
|
crlf: .ascii "\r"; .byte '\n'|0x80
|
1998-10-05 10:08:37 +00:00
|
|
|
|
|
|
|
# Partition type tables
|
|
|
|
|
1998-11-29 14:09:00 +00:00
|
|
|
tables:
|
|
|
|
.byte 0x0, 0x5, 0xf
|
|
|
|
|
|
|
|
.byte 0x1, 0x4, 0x6, 0xb, 0xc, 0xe, 0x63, 0x83
|
1998-10-05 10:08:37 +00:00
|
|
|
.byte 0xa5, 0xa6
|
|
|
|
|
1998-11-29 14:09:00 +00:00
|
|
|
.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
|
1998-10-05 10:08:37 +00:00
|
|
|
|
|
|
|
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
|
|
|
|
|
1999-02-26 14:51:14 +00:00
|
|
|
.org PRT_OFF-0xc,0x90
|
1998-10-05 10:08:37 +00:00
|
|
|
|
1998-11-29 14:09:00 +00:00
|
|
|
drive: .ascii "Drive "
|
1998-12-05 11:58:33 +00:00
|
|
|
nxtdrv: .byte 0x0 # Next drive number
|
1998-10-19 19:13:53 +00:00
|
|
|
opt: .byte 0x0 # Option
|
1999-02-26 14:51:14 +00:00
|
|
|
setdrv: .byte 0x80 # Drive to force
|
1998-10-19 19:13:53 +00:00
|
|
|
flags: .byte FLAGS # Flags
|
|
|
|
ticks: .word TICKS # Delay
|
1998-10-05 10:08:37 +00:00
|
|
|
|
1998-11-29 14:09:00 +00:00
|
|
|
partbl: .fill 0x40,0x1,0x0 # Partition table
|
1998-12-05 11:58:33 +00:00
|
|
|
.word MAGIC # Magic number
|