boot0.S (130632) | boot0.S (137298) |
---|---|
1/* 2 * Copyright (c) 2002 Bruce M. Simpson 3 * Copyright (c) 1998 Robert Nordier 4 * All rights reserved. 5 * 6 * Redistribution and use in source and binary forms are freely 7 * permitted provided that the above copyright notice and this 8 * paragraph and the following disclaimer are duplicated in all 9 * such forms. 10 * 11 * This software is provided "AS IS" and without any express or 12 * implied warranties, including, without limitation, the implied 13 * warranties of merchantability and fitness for a particular 14 * purpose. 15 * | 1/* 2 * Copyright (c) 2002 Bruce M. Simpson 3 * Copyright (c) 1998 Robert Nordier 4 * All rights reserved. 5 * 6 * Redistribution and use in source and binary forms are freely 7 * permitted provided that the above copyright notice and this 8 * paragraph and the following disclaimer are duplicated in all 9 * such forms. 10 * 11 * This software is provided "AS IS" and without any express or 12 * implied warranties, including, without limitation, the implied 13 * warranties of merchantability and fitness for a particular 14 * purpose. 15 * |
16 * $FreeBSD: head/sys/boot/i386/boot0/boot0.S 130632 2004-06-17 12:02:25Z phk $ | 16 * $FreeBSD: head/sys/boot/i386/boot0/boot0.S 137298 2004-11-06 06:13:13Z keramida $ |
17 */ 18 19/* A 512-byte boot manager. */ 20#ifdef SIO 21/* ... using a serial console on COM1. */ 22#endif /* SIO */ 23 24 .set NHRDRV,0x475 # Number of hard drives --- 70 unchanged lines hidden (view full) --- 95#ifdef SIO 96/* 97 * Initialize the serial port. bioscom preserves the driver number in DX. 98 */ 99 movw COMSPEED,%ax # defined by Makefile 100 callw bioscom 101#endif /* SIO */ 102/* | 17 */ 18 19/* A 512-byte boot manager. */ 20#ifdef SIO 21/* ... using a serial console on COM1. */ 22#endif /* SIO */ 23 24 .set NHRDRV,0x475 # Number of hard drives --- 70 unchanged lines hidden (view full) --- 95#ifdef SIO 96/* 97 * Initialize the serial port. bioscom preserves the driver number in DX. 98 */ 99 movw COMSPEED,%ax # defined by Makefile 100 callw bioscom 101#endif /* SIO */ 102/* |
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. | 103 * Check what flags were loaded with us, specifically if a predefined drive 104 * number should be used. If what the bios gives us is bad, use the '0' in 105 * the block instead. |
105 */ 106 testb $0x20,_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 */ 115main.2: 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 | 106 */ 107 testb $0x20,_FLAGS(%bp) # Set number drive? 108 jnz main.1 # Yes 109 testb %dl,%dl # Drive number valid? 110 js main.2 # Possibly (0x80 set) 111main.1: movb _SETDRV(%bp),%dl # Drive number to use 112/* 113 * Whatever we decided to use, now store it into the fake 114 * partition entry that lives in the data space above us. 115 */ 116main.2: movb %dl,_FAKE(%bp) # Save drive number 117 callw putn # To new line 118 pushw %dx # Save drive number 119/* 120 * 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 * 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 * 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) | 123 * Remember that the table starts 2 bytes earlier than you would expect 124 * as the bootable flag is after it in the block. |
124 */ 125 movw $(partbl+0x4),%bx # Partition table (+4) 126 xorw %dx,%dx # Item number 127/* 128 * Loop around on the partition table, printing values until we 129 * pass a 256 byte boundary. The end of loop test is at main.5. 130 */ 131main.3: movb %ch,-0x4(%bx) # Zero active flag (ch == 0) 132 btw %dx,_FLAGS(%bp) # Entry enabled? 133 jnc main.5 # No 134/* | 125 */ 126 movw $(partbl+0x4),%bx # Partition table (+4) 127 xorw %dx,%dx # Item number 128/* 129 * Loop around on the partition table, printing values until we 130 * pass a 256 byte boundary. The end of loop test is at main.5. 131 */ 132main.3: movb %ch,-0x4(%bx) # Zero active flag (ch == 0) 133 btw %dx,_FLAGS(%bp) # Entry enabled? 134 jnc main.5 # No 135/* |
135 * If any of the entries in the table are 136 * the same as the 'type' in the slice table entry, 137 * then this is an empty or non bootable partition. Skip it. | 136 * If any of the entries in the table are the same as the 'type' in the slice 137 * table entry, then this is an empty or non bootable partition. Skip it. |
138 */ 139 movb (%bx),%al # Load type 140 movw $tables,%di # Lookup tables 141 movb $TBL0SZ,%cl # Number of entries 142 repne # Exclude 143 scasb # partition? 144 je main.5 # Yes 145/* 146 * Now scan the table of known types 147 */ 148 movb $TBL1SZ,%cl # Number of entries 149 repne # Known 150 scasb # type? 151 jne main.4 # No 152/* | 138 */ 139 movb (%bx),%al # Load type 140 movw $tables,%di # Lookup tables 141 movb $TBL0SZ,%cl # Number of entries 142 repne # Exclude 143 scasb # partition? 144 je main.5 # Yes 145/* 146 * Now scan the table of known types 147 */ 148 movb $TBL1SZ,%cl # Number of entries 149 repne # Known 150 scasb # type? 151 jne main.4 # No 152/* |
153 * If it matches get the matching element in the 154 * next array. if it doesn't, we are already 155 * pointing at its first element which points to a "?". | 153 * If it matches get the matching element in the next array. If it doesn't, 154 * we are already pointing at its first element which points to a "?". |
156 */ 157 addw $TBL1SZ,%di # Adjust 158main.4: movb (%di),%cl # Partition 159 addw %cx,%di # description 160 callw putx # Display it 161main.5: incw %dx # Next item 162 addb $0x10,%bl # Next entry 163 jnc main.3 # Till done 164/* | 155 */ 156 addw $TBL1SZ,%di # Adjust 157main.4: movb (%di),%cl # Partition 158 addw %cx,%di # description 159 callw putx # Display it 160main.5: incw %dx # Next item 161 addb $0x10,%bl # Next entry 162 jnc main.3 # Till done 163/* |
165 * Passed a 256 byte boundary.. 166 * table is finished. 167 * Add one to the drive number and check it is valid, | 164 * Passed a 256 byte boundary; the table is finished. 165 * Add one to the drive number and check it is valid. |
168 */ 169 popw %ax # Drive number 170 subb $0x80-0x1,%al # Does next 171 cmpb NHRDRV,%al # drive exist? (from BIOS?) 172 jb main.6 # Yes 173/* | 166 */ 167 popw %ax # Drive number 168 subb $0x80-0x1,%al # Does next 169 cmpb NHRDRV,%al # drive exist? (from BIOS?) 170 jb main.6 # Yes 171/* |
174 * If not then if there is only one drive, 175 * Don't display drive as an option. | 172 * If this is the only drive, don't display it as an option. |
176 */ 177 decw %ax # Already drive 0? 178 jz main.7 # Yes 179/* | 173 */ 174 decw %ax # Already drive 0? 175 jz main.7 # Yes 176/* |
180 * If it was illegal or we cycled through them, 181 * then go back to drive 0. | 177 * If it was illegal or we cycled through them, go back to drive 0. |
182 */ 183 xorb %al,%al # Drive 0 184/* | 178 */ 179 xorb %al,%al # Drive 0 180/* |
185 * Whatever drive we selected, make it an ascii digit and save it back 186 * to the "next drive" location in the loaded block in case we 187 * want to save it for next time. 188 * This also is part of the printed drive string so add 0x80 to indicate 189 * end of string. | 181 * Whatever drive we selected, make it an ascii digit and save it back to the 182 * "next drive" location in the loaded block in case we want to save it later 183 * for next time. This also is part of the printed drive string so add 0x80 184 * to indicate end of string. |
190 */ 191main.6: addb $'0'|0x80,%al # Save next 192 movb %al,_NXTDRV(%bp) # drive number 193 movw $drive,%di # Display 194 callw putx # item 195/* 196 * Now that we've printed the drive (if we needed to), display a prompt. 197 */ --- 7 unchanged lines hidden (view full) --- 205 */ 206main.10: movb $ASCII_BEL,%al # Signal 207 callw putchr # beep! 208 xorb %ah,%ah # BIOS: Get 209 int $0x1a # system time 210 movw %dx,%di # Ticks when 211 addw _TICKS(%bp),%di # timeout 212/* | 185 */ 186main.6: addb $'0'|0x80,%al # Save next 187 movb %al,_NXTDRV(%bp) # drive number 188 movw $drive,%di # Display 189 callw putx # item 190/* 191 * Now that we've printed the drive (if we needed to), display a prompt. 192 */ --- 7 unchanged lines hidden (view full) --- 200 */ 201main.10: movb $ASCII_BEL,%al # Signal 202 callw putchr # beep! 203 xorb %ah,%ah # BIOS: Get 204 int $0x1a # system time 205 movw %dx,%di # Ticks when 206 addw _TICKS(%bp),%di # timeout 207/* |
213 * Busy loop, looking for keystrokes but 214 * keeping one eye on the time. | 208 * Busy loop, looking for keystrokes but keeping one eye on the time. |
215 */ 216main.8: 217#ifndef SIO 218 movb $0x1,%ah # BIOS: Check 219 int $0x16 # for keypress 220 jnz main.11 # Have one 221#else /* SIO */ 222 movb $0x03,%ah # BIOS: Read COM --- 27 unchanged lines hidden (view full) --- 250 */ 251#ifndef SIO 252 cmpb $KEY_ENTER,%al # Enter pressed? 253#else /* SIO */ 254 cmpb $ASCII_CR,%al # Enter pressed? 255#endif /* SIO */ 256 je main.9 # Yes 257/* | 209 */ 210main.8: 211#ifndef SIO 212 movb $0x1,%ah # BIOS: Check 213 int $0x16 # for keypress 214 jnz main.11 # Have one 215#else /* SIO */ 216 movb $0x03,%ah # BIOS: Read COM --- 27 unchanged lines hidden (view full) --- 244 */ 245#ifndef SIO 246 cmpb $KEY_ENTER,%al # Enter pressed? 247#else /* SIO */ 248 cmpb $ASCII_CR,%al # Enter pressed? 249#endif /* SIO */ 250 je main.9 # Yes 251/* |
258 * Otherwise check if legal 259 * If not ask again. | 252 * Otherwise check if legal. If not ask again. |
260 */ 261#ifndef SIO 262 subb $KEY_F1,%al # Less F1 scan code 263 cmpb $0x4,%al # F1..F5? 264 jna main.12 # Yes 265 subb $(KEY_1 - KEY_F1),%al # Less #1 scan code 266#else /* SIO */ 267 subb $'1',%al # Less '1' ascii character 268#endif /* SIO */ 269 cmpb $0x4,%al # #1..#5? 270 ja main.10 # No 271/* | 253 */ 254#ifndef SIO 255 subb $KEY_F1,%al # Less F1 scan code 256 cmpb $0x4,%al # F1..F5? 257 jna main.12 # Yes 258 subb $(KEY_1 - KEY_F1),%al # Less #1 scan code 259#else /* SIO */ 260 subb $'1',%al # Less '1' ascii character 261#endif /* SIO */ 262 cmpb $0x4,%al # #1..#5? 263 ja main.10 # No 264/* |
272 * We have a selection. 273 * but if it's a bad selection go back to complain. | 265 * We have a selection. If it's a bad selection go back to complain. |
274 * The bits in MNUOPT were set when the options were printed. 275 * Anything not printed is not an option. 276 */ 277main.12: cbtw # Option 278 btw %ax,_MNUOPT(%bp) # enabled? 279 jnc main.10 # No 280/* 281 * Save the info in the original tables --- 24 unchanged lines hidden (view full) --- 306/* 307 * If going to next drive, replace drive with selected one. 308 * Remember to un-ascii it. Hey 0x80 is already set, cool! 309 */ 310 jne main.15 # If not F5/#5 311 movb _NXTDRV(%bp),%dl # Next drive 312 subb $'0',%dl # number 313/* | 266 * The bits in MNUOPT were set when the options were printed. 267 * Anything not printed is not an option. 268 */ 269main.12: cbtw # Option 270 btw %ax,_MNUOPT(%bp) # enabled? 271 jnc main.10 # No 272/* 273 * Save the info in the original tables --- 24 unchanged lines hidden (view full) --- 298/* 299 * If going to next drive, replace drive with selected one. 300 * Remember to un-ascii it. Hey 0x80 is already set, cool! 301 */ 302 jne main.15 # If not F5/#5 303 movb _NXTDRV(%bp),%dl # Next drive 304 subb $'0',%dl # number 305/* |
314 * load selected bootsector to the LOAD location in RAM. 315 * If it fails to read or isn't marked bootable, treat it 316 * as a bad selection. 317 * XXX what does %si carry? | 306 * Load selected bootsector to the LOAD location in RAM. 307 * If it fails to read or isn't marked bootable, treat it as a bad selection. 308 * XXX: What does %si carry? |
318 */ 319main.15: movw $LOAD,%bx # Address for read 320 movb $0x2,%ah # Read sector 321 callw intx13 # from disk 322 jc main.10 # If error 323 cmpw $MAGIC,0x1fe(%bx) # Bootable? 324 jne main.10 # No 325 pushw %si # Save --- 85 unchanged lines hidden (view full) --- 411/* Partition type tables */ 412 413tables: 414/* 415 * These entries identify invalid or NON BOOT types and partitions. 416 */ 417 .byte 0x0, 0x5, 0xf 418/* | 309 */ 310main.15: movw $LOAD,%bx # Address for read 311 movb $0x2,%ah # Read sector 312 callw intx13 # from disk 313 jc main.10 # If error 314 cmpw $MAGIC,0x1fe(%bx) # Bootable? 315 jne main.10 # No 316 pushw %si # Save --- 85 unchanged lines hidden (view full) --- 402/* Partition type tables */ 403 404tables: 405/* 406 * These entries identify invalid or NON BOOT types and partitions. 407 */ 408 .byte 0x0, 0x5, 0xf 409/* |
419 * These values indicate bootable types we know the names of | 410 * These values indicate bootable types we know the names of. |
420 */ 421 .byte 0x1, 0x4, 0x6, 0xb, 0xc, 0xe, 0x83 422 .byte 0x9f, 0xa5, 0xa6, 0xa9 423/* 424 * These are offsets that match the known names above and point to the strings 425 * that will be printed. 426 */ 427 .byte os_misc-. # Unknown --- 30 unchanged lines hidden (view full) --- 458drive: .ascii "Drive " 459nxtdrv: .byte 0x0 # Next drive number 460opt: .byte 0x0 # Option 461setdrv: .byte 0x80 # Drive to force 462flags: .byte FLAGS # Flags 463ticks: .word TICKS # Delay 464 465/* | 411 */ 412 .byte 0x1, 0x4, 0x6, 0xb, 0xc, 0xe, 0x83 413 .byte 0x9f, 0xa5, 0xa6, 0xa9 414/* 415 * These are offsets that match the known names above and point to the strings 416 * that will be printed. 417 */ 418 .byte os_misc-. # Unknown --- 30 unchanged lines hidden (view full) --- 449drive: .ascii "Drive " 450nxtdrv: .byte 0x0 # Next drive number 451opt: .byte 0x0 # Option 452setdrv: .byte 0x80 # Drive to force 453flags: .byte FLAGS # Flags 454ticks: .word TICKS # Delay 455 456/* |
466 * here is the 64 byte partition table that fdisk would fiddle with. | 457 * Here is the 64 byte partition table that fdisk would fiddle with. |
467 */ 468partbl: .fill 0x40,0x1,0x0 # Partition table 469 .word MAGIC # Magic number | 458 */ 459partbl: .fill 0x40,0x1,0x0 # Partition table 460 .word MAGIC # Magic number |