boot0ext.S (127458) | boot0ext.S (128441) |
---|---|
1# 2# Copyright (c) 1998 Robert Nordier 3# All rights reserved. 4# 5# Redistribution and use in source and binary forms are freely 6# permitted provided that the above copyright notice and this 7# paragraph and the following disclaimer are duplicated in all 8# such forms. 9# 10# This software is provided "AS IS" and without any express or 11# implied warranties, including, without limitation, the implied 12# warranties of merchantability and fitness for a particular 13# purpose. 14# 15 | 1# 2# Copyright (c) 1998 Robert Nordier 3# All rights reserved. 4# 5# Redistribution and use in source and binary forms are freely 6# permitted provided that the above copyright notice and this 7# paragraph and the following disclaimer are duplicated in all 8# such forms. 9# 10# This software is provided "AS IS" and without any express or 11# implied warranties, including, without limitation, the implied 12# warranties of merchantability and fitness for a particular 13# purpose. 14# 15 |
16# $FreeBSD: head/sys/boot/i386/boot0/boot0ext.S 127458 2004-03-26 18:46:31Z obrien $ | 16# $FreeBSD: head/sys/boot/i386/boot0/boot0ext.S 128441 2004-04-19 19:31:48Z obrien $ |
17 18# A 1024-byte boot manager. 19 20 .set NHRDRV,0x475 # Number of hard drives 21 .set ORIGIN,0x600 # Execution address 22 .set SECTOR_SIZE,0x200 # Length of a sector 23 .set NUM_SECTORS,2 # Total length in sectors 24 --- 4 unchanged lines hidden (view full) --- 29 30 .set TBL0SZ,table0_end-table0 # Table 0 size 31 .set TBL1SZ,table1_end-table1 # Table 1 size 32 33 .set MAGIC,0xaa55 # Magic: bootable 34 35 .set KEY_ENTER,0x1c # Enter key scan code 36 .set KEY_F1,0x3b # F1 key scan code | 17 18# A 1024-byte boot manager. 19 20 .set NHRDRV,0x475 # Number of hard drives 21 .set ORIGIN,0x600 # Execution address 22 .set SECTOR_SIZE,0x200 # Length of a sector 23 .set NUM_SECTORS,2 # Total length in sectors 24 --- 4 unchanged lines hidden (view full) --- 29 30 .set TBL0SZ,table0_end-table0 # Table 0 size 31 .set TBL1SZ,table1_end-table1 # Table 1 size 32 33 .set MAGIC,0xaa55 # Magic: bootable 34 35 .set KEY_ENTER,0x1c # Enter key scan code 36 .set KEY_F1,0x3b # F1 key scan code |
37 .set KEY_1,0x02 # #1 key scan code |
|
37 38# 39# Flag bits 40# 41 .set FL_PACKET,0x80 # Packet mode 42 .set FL_NOUPDATE,0x40 # Don't save selection 43 .set FL_SETDRV,0x20 # Override drive number 44# 45# Addresses in the sector of embedded data values. 46# Accessed with negative offsets from the end of the relocated sectors (%bp). 47# | 38 39# 40# Flag bits 41# 42 .set FL_PACKET,0x80 # Packet mode 43 .set FL_NOUPDATE,0x40 # Don't save selection 44 .set FL_SETDRV,0x20 # Override drive number 45# 46# Addresses in the sector of embedded data values. 47# Accessed with negative offsets from the end of the relocated sectors (%bp). 48# |
48 .set _PRT_END,(FAKE-(ORIGIN+SECTOR_SIZE)) | 49 .set _PRT_END,(FAKE-(ORIGIN+SECTOR_SIZE*(NUM_SECTORS-1))) |
49 .set _NXTDRV,-(_PRT_END+0x48) # Next drive 50 .set _OPT,-(_PRT_END+0x47) # Default option 51 .set _SETDRV,-(_PRT_END+0x46) # Drive to force 52 .set _FLAGS,-(_PRT_END+0x45) # Flags 53 .set _TICKS,-(_PRT_END+0x44) # Timeout ticks 54 .set _FAKE,0x0 # Fake partition entry 55 .set _MNUOPT,0xc # Menu options 56 --- 24 unchanged lines hidden (view full) --- 81# 82 movw $fake,%bp # Address variables 83 movw %bp,%di # %di used in stosw 84 movw $0x8,%cx # Words to clear 85 rep # Zero 86 stosw # them 87 incb -0xe(%di) # Sector number 1 88# | 50 .set _NXTDRV,-(_PRT_END+0x48) # Next drive 51 .set _OPT,-(_PRT_END+0x47) # Default option 52 .set _SETDRV,-(_PRT_END+0x46) # Drive to force 53 .set _FLAGS,-(_PRT_END+0x45) # Flags 54 .set _TICKS,-(_PRT_END+0x44) # Timeout ticks 55 .set _FAKE,0x0 # Fake partition entry 56 .set _MNUOPT,0xc # Menu options 57 --- 24 unchanged lines hidden (view full) --- 82# 83 movw $fake,%bp # Address variables 84 movw %bp,%di # %di used in stosw 85 movw $0x8,%cx # Words to clear 86 rep # Zero 87 stosw # them 88 incb -0xe(%di) # Sector number 1 89# |
90# Check what flags were loaded with us; specifically, use a predefined Drive. 91# If what the bios gives us is bad, use the '0' in the block instead, as well. 92# 93 testb $FL_SETDRV,LOAD+flags-start # Set number drive? 94 jnz boot.1 # Yes 95 testb %dl,%dl # Drive number valid? 96 js boot.2 # Possibly (0x80 set) 97boot.1: movb LOAD+setdrv-start,%dl # Drive number to use 98boot.2: 99# |
|
89# Reload all of boot0 (including the extra sectors) into memory at the 90# relocation address. 91# 92 push %dx # Save drive number 93 movw $start,%bx # Origin we were linked for 94 movw %bp,%si # Fake PTE 95 movw $0x200+NUM_SECTORS,%ax # Read in all 96 callw intx13 # of boot0 97 pop %dx # Restore 98# 99# Relocate to the new copy of the code. 100# 101 jmp main+ORIGIN-LOAD # To relocated code 102# | 100# Reload all of boot0 (including the extra sectors) into memory at the 101# relocation address. 102# 103 push %dx # Save drive number 104 movw $start,%bx # Origin we were linked for 105 movw %bp,%si # Fake PTE 106 movw $0x200+NUM_SECTORS,%ax # Read in all 107 callw intx13 # of boot0 108 pop %dx # Restore 109# 110# Relocate to the new copy of the code. 111# 112 jmp main+ORIGIN-LOAD # To relocated code 113# |
103# Check what flags were loaded with us; specifically, use a predefined Drive. 104# If what the bios gives us is bad, use the '0' in the block instead, as well. 105# 106main: testb $FL_SETDRV,_FLAGS(%bp) # Set number drive? 107 jnz main.1 # Yes 108 testb %dl,%dl # Drive number valid? 109 js main.2 # Possibly (0x80 set) 110main.1: movb _SETDRV(%bp),%dl # Drive number to use 111# | |
112# Whatever we decided to use, now store it into the fake 113# partition entry that lives in the data space above us. 114# | 114# Whatever we decided to use, now store it into the fake 115# partition entry that lives in the data space above us. 116# |
115main.2: movb %dl,_FAKE(%bp) # Save drive number | 117main: movb %dl,_FAKE(%bp) # Save drive number |
116 callw putn # To new line 117 pushw %dx # Save drive number 118# 119# Start out with a pointer to the 4th byte of the first table entry 120# so that after 4 iterations it's beyond the end of the sector. 121# and beyond a 256 byte boundary and has overflowed 8 bits (see next comment). 122# (remember that the table starts 2 bytes earlier than you would expect 123# as the bootable flag is after it in the block) --- 116 unchanged lines hidden (view full) --- 240 cmpb $KEY_ENTER,%al # Enter pressed? 241 je main.9 # Yes 242# 243# Otherwise check if legal 244# If not ask again. 245# 246 subb $KEY_F1,%al # Less F1 scan code 247 cmpb $0x4,%al # F1..F5? | 118 callw putn # To new line 119 pushw %dx # Save drive number 120# 121# Start out with a pointer to the 4th byte of the first table entry 122# so that after 4 iterations it's beyond the end of the sector. 123# and beyond a 256 byte boundary and has overflowed 8 bits (see next comment). 124# (remember that the table starts 2 bytes earlier than you would expect 125# as the bootable flag is after it in the block) --- 116 unchanged lines hidden (view full) --- 242 cmpb $KEY_ENTER,%al # Enter pressed? 243 je main.9 # Yes 244# 245# Otherwise check if legal 246# If not ask again. 247# 248 subb $KEY_F1,%al # Less F1 scan code 249 cmpb $0x4,%al # F1..F5? |
250 jna main.12 # Yes 251 subb $(KEY_1 - KEY_F1),%al # Less #1 scan code 252 cmpb $0x4,%al # #1..#5? |
|
248 ja main.10 # No 249# 250# We have a selection. 251# but if it's a bad selection go back to complain. 252# The bits in MNUOPT were set when the options were printed. 253# Anything not printed is not an option. 254# 255main.12: cbtw # Option 256 btw %ax,_MNUOPT(%bp) # enabled? 257 jnc main.10 # No 258# 259# Save the info in the original tables 260# for rewriting to the disk. 261# 262 movb %al,_OPT(%bp) # Save option 263 movw $fake,%si # Partition for write 264 movb (%si),%dl # Drive number 265 movw %si,%bx # Partition for read | 253 ja main.10 # No 254# 255# We have a selection. 256# but if it's a bad selection go back to complain. 257# The bits in MNUOPT were set when the options were printed. 258# Anything not printed is not an option. 259# 260main.12: cbtw # Option 261 btw %ax,_MNUOPT(%bp) # enabled? 262 jnc main.10 # No 263# 264# Save the info in the original tables 265# for rewriting to the disk. 266# 267 movb %al,_OPT(%bp) # Save option 268 movw $fake,%si # Partition for write 269 movb (%si),%dl # Drive number 270 movw %si,%bx # Partition for read |
266 cmpb $0x4,%al # F5 pressed? | 271 cmpb $0x4,%al # F5/#5 pressed? |
267 pushf # Save 268 je main.13 # Yes 269 shlb $0x4,%al # Point to 270 addw $partbl,%ax # selected 271 xchgw %bx,%ax # partition 272 movb $0x80,(%bx) # Flag active 273# 274# If not asked to do a write-back (flags 0x40) don't do one. --- 5 unchanged lines hidden (view full) --- 280 movw $0x301,%ax # Write 1 sector 281 callw intx13 # to disk 282main.14: popw %si # Restore 283 popf # Restore 284# 285# If going to next drive, replace drive with selected one. 286# Remember to un-ascii it. Hey 0x80 is already set, cool! 287# | 272 pushf # Save 273 je main.13 # Yes 274 shlb $0x4,%al # Point to 275 addw $partbl,%ax # selected 276 xchgw %bx,%ax # partition 277 movb $0x80,(%bx) # Flag active 278# 279# If not asked to do a write-back (flags 0x40) don't do one. --- 5 unchanged lines hidden (view full) --- 285 movw $0x301,%ax # Write 1 sector 286 callw intx13 # to disk 287main.14: popw %si # Restore 288 popf # Restore 289# 290# If going to next drive, replace drive with selected one. 291# Remember to un-ascii it. Hey 0x80 is already set, cool! 292# |
288 jne main.15 # If not F5 | 293 jne main.15 # If not F5/#5 |
289 movb _NXTDRV(%bp),%dl # Next drive 290 subb $'0',%dl # number 291# 292# load selected bootsector to the LOAD location in RAM. 293# If it fails to read or isn't marked bootable, treat it 294# as a bad selection. 295# 296main.15: movw $LOAD,%bx # Address for read --- 140 unchanged lines hidden (view full) --- 437# 438# These entries identify invalid or NON BOOT types and partitions. 439# 440table0: .byte 0x0, 0x5, 0xf 441table0_end: 442# 443# These values indicate bootable types we know the names of 444# | 294 movb _NXTDRV(%bp),%dl # Next drive 295 subb $'0',%dl # number 296# 297# load selected bootsector to the LOAD location in RAM. 298# If it fails to read or isn't marked bootable, treat it 299# as a bad selection. 300# 301main.15: movw $LOAD,%bx # Address for read --- 140 unchanged lines hidden (view full) --- 442# 443# These entries identify invalid or NON BOOT types and partitions. 444# 445table0: .byte 0x0, 0x5, 0xf 446table0_end: 447# 448# These values indicate bootable types we know the names of 449# |
445table1: .byte 0x1, 0x4, 0x6, 0x7, 0xb, 0xc, 0xe, 0x63, 0x83 | 450table1: .byte 0x1, 0x4, 0x6, 0x7, 0xb, 0xc, 0xe, 0x42, 0x63, 0x83 |
446 .byte 0x9f, 0xa5, 0xa6, 0xa9 447table1_end: 448# 449# These are offsets that match the known names above and point to the strings 450# that will be printed. 451# 452 .byte os_misc-. # Unknown 453 .byte os_dos-. # DOS 454 .byte os_dos-. # DOS 455 .byte os_dos-. # DOS | 451 .byte 0x9f, 0xa5, 0xa6, 0xa9 452table1_end: 453# 454# These are offsets that match the known names above and point to the strings 455# that will be printed. 456# 457 .byte os_misc-. # Unknown 458 .byte os_dos-. # DOS 459 .byte os_dos-. # DOS 460 .byte os_dos-. # DOS |
456 .byte os_nt-. # NT or OS/2 | 461 .byte os_nt-. # NT/XP or OS/2 462 .byte os_windows-. # Windows 32-bit FAT 463 .byte os_windows-. # Windows 32-bit FAT ext int 13 |
457 .byte os_windows-. # Windows | 464 .byte os_windows-. # Windows |
458 .byte os_windows-. # Windows 459 .byte os_windows-. # Windows | 465 .byte os_windows-. # Windows 2000 dyn ext |
460 .byte os_unix-. # UNIX 461 .byte os_linux-. # Linux 462 .byte os_bsdos-. # BSD/OS 463 .byte os_freebsd-. # FreeBSD 464 .byte os_openbsd-. # OpenBSD 465 .byte os_netbsd-. # NetBSD 466# 467# And here are the strings themselves. 0x80 or'd into a byte indicates 468# the end of the string. (not so great for Russians but...) 469# 470os_misc: .ascii "Unknow"; .byte 'n'|0x80 471os_dos: .ascii "DO"; .byte 'S'|0x80 | 466 .byte os_unix-. # UNIX 467 .byte os_linux-. # Linux 468 .byte os_bsdos-. # BSD/OS 469 .byte os_freebsd-. # FreeBSD 470 .byte os_openbsd-. # OpenBSD 471 .byte os_netbsd-. # NetBSD 472# 473# And here are the strings themselves. 0x80 or'd into a byte indicates 474# the end of the string. (not so great for Russians but...) 475# 476os_misc: .ascii "Unknow"; .byte 'n'|0x80 477os_dos: .ascii "DO"; .byte 'S'|0x80 |
472os_nt: .ascii "Windows N"; .byte 'T'|0x80 | 478os_nt: .ascii "Windows NT/X"; .byte 'P'|0x80 |
473os_windows: .ascii "Window"; .byte 's'|0x80 474os_unix: .ascii "UNI"; .byte 'X'|0x80 475os_linux: .ascii "Linu"; .byte 'x'|0x80 476os_freebsd: .ascii "FreeBS"; .byte 'D'|0x80 477os_openbsd: .ascii "OpenBS"; .byte 'D'|0x80 478os_netbsd: .ascii "NetBS"; .byte 'D'|0x80 479os_bsdos: .ascii "BSD/O"; .byte 'S'|0x80 480 481# 482# Fake partition entry created at the end of the table used when loading 483# boot0 at the very beginning and when loading an MBR from another disk when 484# F5 is pressed. 485# 486 .org SECTOR_SIZE*NUM_SECTORS, 0x0 487fake: | 479os_windows: .ascii "Window"; .byte 's'|0x80 480os_unix: .ascii "UNI"; .byte 'X'|0x80 481os_linux: .ascii "Linu"; .byte 'x'|0x80 482os_freebsd: .ascii "FreeBS"; .byte 'D'|0x80 483os_openbsd: .ascii "OpenBS"; .byte 'D'|0x80 484os_netbsd: .ascii "NetBS"; .byte 'D'|0x80 485os_bsdos: .ascii "BSD/O"; .byte 'S'|0x80 486 487# 488# Fake partition entry created at the end of the table used when loading 489# boot0 at the very beginning and when loading an MBR from another disk when 490# F5 is pressed. 491# 492 .org SECTOR_SIZE*NUM_SECTORS, 0x0 493fake: |