zfsldr.S (219703) | zfsldr.S (221177) |
---|---|
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 * | 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 * $FreeBSD: head/sys/boot/i386/zfsboot/zfsldr.S 219703 2011-03-16 20:19:48Z ae $ | 15 * $FreeBSD: head/sys/boot/i386/zfsboot/zfsldr.S 221177 2011-04-28 17:44:24Z jhb $ |
16 */ 17 18/* Memory Locations */ 19 .set MEM_REL,0x700 # Relocation address 20 .set MEM_ARG,0x900 # Arguments 21 .set MEM_ORG,0x7c00 # Origin 22 .set MEM_BUF,0x8000 # Load area 23 .set MEM_BTX,0x9000 # BTX start 24 .set MEM_JMP,0x9010 # BTX entry point 25 .set MEM_USR,0xa000 # Client start 26 .set BDA_BOOT,0x472 # Boot howto flag 27 28/* Partition Constants */ 29 .set PRT_OFF,0x1be # Partition offset 30 .set PRT_NUM,0x4 # Partitions 31 .set PRT_BSD,0xa5 # Partition type 32 | 16 */ 17 18/* Memory Locations */ 19 .set MEM_REL,0x700 # Relocation address 20 .set MEM_ARG,0x900 # Arguments 21 .set MEM_ORG,0x7c00 # Origin 22 .set MEM_BUF,0x8000 # Load area 23 .set MEM_BTX,0x9000 # BTX start 24 .set MEM_JMP,0x9010 # BTX entry point 25 .set MEM_USR,0xa000 # Client start 26 .set BDA_BOOT,0x472 # Boot howto flag 27 28/* Partition Constants */ 29 .set PRT_OFF,0x1be # Partition offset 30 .set PRT_NUM,0x4 # Partitions 31 .set PRT_BSD,0xa5 # Partition type 32 |
33/* Flag Bits */ 34 .set FL_PACKET,0x80 # Packet mode 35 | |
36/* Misc. Constants */ 37 .set SIZ_PAG,0x1000 # Page size 38 .set SIZ_SEC,0x200 # Sector size 39 40 .set NSECT,0x80 41 .globl start | 33/* Misc. Constants */ 34 .set SIZ_PAG,0x1000 # Page size 35 .set SIZ_SEC,0x200 # Sector size 36 37 .set NSECT,0x80 38 .globl start |
42 .globl xread | |
43 .code16 44 45start: jmp main # Start recognizably 46 47/* 48 * This is the start of a standard BIOS Parameter Block (BPB). Most bootable 49 * FAT disks have this at the start of their MBR. While normal BIOS's will 50 * work fine without this section, IBM's El Torito emulation "fixes" up the 51 * BPB by writing into the memory copy of the MBR. Rather than have data | 39 .code16 40 41start: jmp main # Start recognizably 42 43/* 44 * This is the start of a standard BIOS Parameter Block (BPB). Most bootable 45 * FAT disks have this at the start of their MBR. While normal BIOS's will 46 * work fine without this section, IBM's El Torito emulation "fixes" up the 47 * BPB by writing into the memory copy of the MBR. Rather than have data |
52 * written into our xread routine, we'll define a BPB to work around it. | 48 * written into our code, we'll define a BPB to work around it. |
53 * The data marked with (T) indicates a field required for a ThinkPad to 54 * recognize the disk and (W) indicates fields written from IBM BIOS code. 55 * The use of the BPB is based on what OpenBSD and NetBSD implemented in 56 * their boot code but the required fields were determined by trial and error. 57 * 58 * Note: If additional space is needed in boot1, one solution would be to 59 * move the "prompt" message data (below) to replace the OEM ID. 60 */ --- 14 unchanged lines hidden (view full) --- 75 .long 0 # hidden sectors (W) 76 .long 0 # large sectors 77 78 .org 0x24, 0x00 79ebpb: .byte 0 # BIOS physical drive number (W) 80 81 .org 0x25,0x90 82/* | 49 * The data marked with (T) indicates a field required for a ThinkPad to 50 * recognize the disk and (W) indicates fields written from IBM BIOS code. 51 * The use of the BPB is based on what OpenBSD and NetBSD implemented in 52 * their boot code but the required fields were determined by trial and error. 53 * 54 * Note: If additional space is needed in boot1, one solution would be to 55 * move the "prompt" message data (below) to replace the OEM ID. 56 */ --- 14 unchanged lines hidden (view full) --- 71 .long 0 # hidden sectors (W) 72 .long 0 # large sectors 73 74 .org 0x24, 0x00 75ebpb: .byte 0 # BIOS physical drive number (W) 76 77 .org 0x25,0x90 78/* |
83 * Trampoline used by boot2 to call read to read data from the disk via 84 * the BIOS. Call with: 85 * 86 * %ecx:%eax - long - LBA to read in 87 * %es:(%bx) - caddr_t - buffer to read data into 88 * %dl - byte - drive to read from 89 * %dh - byte - num sectors to read 90 */ 91 92xread: push %ss # Address 93 pop %ds # data 94/* 95 * Setup an EDD disk packet and pass it to read 96 */ 97xread.1: pushl %ecx # Starting absolute block 98 pushl %eax # block number 99 push %es # Address of 100 push %bx # transfer buffer 101 xor %ax,%ax # Number of 102 movb %dh,%al # blocks to 103 push %ax # transfer 104 push $0x10 # Size of packet 105 mov %sp,%bp # Packet pointer 106 callw read # Read from disk 107 lea 0x10(%bp),%sp # Clear stack 108 lret # To far caller 109/* 110 * Load the rest of boot2 and BTX up, copy the parts to the right locations, | 79 * Load the rest of zfsboot2 and BTX up, copy the parts to the right locations, |
111 * and start it all up. 112 */ 113 114/* 115 * Setup the segment registers to flat addressing (segment 0) and setup the 116 * stack to end just below the start of our code. 117 */ 118main: cld # String ops inc --- 57 unchanged lines hidden (view full) --- 176 * (compare to this section of the UFS bootstrap) so we just load it 177 * all at 0x8000. The first part of boot2 is BTX, which wants to run 178 * at 0x9000. The boot2.bin binary starts right after the end of BTX, 179 * so we have to figure out where the start of it is and then move the 180 * binary to 0xc000. After we have moved the client, we relocate BTX 181 * itself to 0x9000 - doing it in this order means that none of the 182 * memcpy regions overlap which would corrupt the copy. Normally, BTX 183 * clients start at MEM_USR, or 0xa000, but when we use btxld to | 80 * and start it all up. 81 */ 82 83/* 84 * Setup the segment registers to flat addressing (segment 0) and setup the 85 * stack to end just below the start of our code. 86 */ 87main: cld # String ops inc --- 57 unchanged lines hidden (view full) --- 145 * (compare to this section of the UFS bootstrap) so we just load it 146 * all at 0x8000. The first part of boot2 is BTX, which wants to run 147 * at 0x9000. The boot2.bin binary starts right after the end of BTX, 148 * so we have to figure out where the start of it is and then move the 149 * binary to 0xc000. After we have moved the client, we relocate BTX 150 * itself to 0x9000 - doing it in this order means that none of the 151 * memcpy regions overlap which would corrupt the copy. Normally, BTX 152 * clients start at MEM_USR, or 0xa000, but when we use btxld to |
184 * create boot2, we use an entry point of 0x2000. That entry point is | 153 * create zfsboot2, we use an entry point of 0x2000. That entry point is |
185 * relative to MEM_USR; thus boot2.bin starts at 0xc000. 186 * 187 * The load area and the target area for the client overlap so we have 188 * to use a decrementing string move. We also play segment register 189 * games with the destination address for the move so that the client 190 * can be larger than 16k (which would overflow the zero segment since 191 * the client starts at 0xc000). Relocating BTX is easy since the load 192 * area and target area do not overlap. --- 43 unchanged lines hidden (view full) --- 236 movb $0xdf,%al # Enable 237 outb %al,$0x60 # A20 238seta20.3: sti # Enable interrupts 239 240 jmp start+MEM_JMP-MEM_ORG # Start BTX 241 242 243/* | 154 * relative to MEM_USR; thus boot2.bin starts at 0xc000. 155 * 156 * The load area and the target area for the client overlap so we have 157 * to use a decrementing string move. We also play segment register 158 * games with the destination address for the move so that the client 159 * can be larger than 16k (which would overflow the zero segment since 160 * the client starts at 0xc000). Relocating BTX is easy since the load 161 * area and target area do not overlap. --- 43 unchanged lines hidden (view full) --- 205 movb $0xdf,%al # Enable 206 outb %al,$0x60 # A20 207seta20.3: sti # Enable interrupts 208 209 jmp start+MEM_JMP-MEM_ORG # Start BTX 210 211 212/* |
244 * Trampoline used to call read from within boot1. | 213 * Trampoline used to call read from within zfsldr. Sets up an EDD 214 * packet on the stack and passes it to read. 215 * 216 * %eax - int - LBA to read in relative to partition start 217 * %dl - byte - drive to read from 218 * %dh - byte - num sectors to read 219 * %si - ptr - MBR partition entry |
245 */ 246nread: xor %eax,%eax # Sector offset in partition | 220 */ 221nread: xor %eax,%eax # Sector offset in partition |
247nread.1: mov $MEM_BUF,%bx # Transfer buffer 248 xor %ecx,%ecx # Get | 222nread.1: xor %ecx,%ecx # Get |
249 addl 0x8(%si),%eax # LBA 250 adc $0,%ecx | 223 addl 0x8(%si),%eax # LBA 224 adc $0,%ecx |
251 push %cs # Read from 252 callw xread.1 # disk | 225 pushl %ecx # Starting absolute block 226 pushl %eax # block number 227 push %es # Address of 228 push $MEM_BUF # transfer buffer 229 xor %ax,%ax # Number of 230 movb %dh,%al # blocks to 231 push %ax # transfer 232 push $0x10 # Size of packet 233 mov %sp,%bp # Packet pointer 234 callw read # Read from disk 235 lea 0x10(%bp),%sp # Clear stack |
253 jnc return # If success, return 254 mov $msg_read,%si # Otherwise, set the error 255 # message and fall through to 256 # the error routine 257/* 258 * Print out the error message pointed to by %ds:(%si) followed 259 * by a prompt, wait for a keypress, and then reboot the machine. 260 */ --- 27 unchanged lines hidden (view full) --- 288 * installed and use it if it is. If it is not installed or not enabled, then 289 * fall back to using CHS. Since we use a LBA, if we are using CHS, we have to 290 * fetch the drive parameters from the BIOS and divide it out ourselves. 291 * Call with: 292 * 293 * %dl - byte - drive number 294 * stack - 10 bytes - EDD Packet 295 */ | 236 jnc return # If success, return 237 mov $msg_read,%si # Otherwise, set the error 238 # message and fall through to 239 # the error routine 240/* 241 * Print out the error message pointed to by %ds:(%si) followed 242 * by a prompt, wait for a keypress, and then reboot the machine. 243 */ --- 27 unchanged lines hidden (view full) --- 271 * installed and use it if it is. If it is not installed or not enabled, then 272 * fall back to using CHS. Since we use a LBA, if we are using CHS, we have to 273 * fetch the drive parameters from the BIOS and divide it out ourselves. 274 * Call with: 275 * 276 * %dl - byte - drive number 277 * stack - 10 bytes - EDD Packet 278 */ |
296read: testb $FL_PACKET,%cs:MEM_REL+flags-start # LBA support enabled? 297 jz read.1 # No, use CHS 298 cmpb $0x80,%dl # Hard drive? | 279read: cmpb $0x80,%dl # Hard drive? |
299 jb read.1 # No, use CHS 300 mov $0x55aa,%bx # Magic 301 push %dx # Save 302 movb $0x41,%ah # BIOS: Check 303 int $0x13 # extensions present 304 pop %dx # Restore 305 jc read.1 # If error, use CHS 306 cmp $0xaa55,%bx # Magic? 307 jne read.1 # No, so use CHS 308 testb $0x1,%cl # Packet interface? 309 jz read.1 # No, so use CHS 310 mov %bp,%si # Disk packet 311 movb $0x42,%ah # BIOS: Extended 312 int $0x13 # read 313 retw # To caller | 280 jb read.1 # No, use CHS 281 mov $0x55aa,%bx # Magic 282 push %dx # Save 283 movb $0x41,%ah # BIOS: Check 284 int $0x13 # extensions present 285 pop %dx # Restore 286 jc read.1 # If error, use CHS 287 cmp $0xaa55,%bx # Magic? 288 jne read.1 # No, so use CHS 289 testb $0x1,%cl # Packet interface? 290 jz read.1 # No, so use CHS 291 mov %bp,%si # Disk packet 292 movb $0x42,%ah # BIOS: Extended 293 int $0x13 # read 294 retw # To caller |
314#if 0 315read.1: push %dx # Save 316 movb $0x8,%ah # BIOS: Get drive 317 int $0x13 # parameters 318 movb %dh,%ch # Max head number 319 pop %dx # Restore 320 jc return # If error 321 andb $0x3f,%cl # Sectors per track 322 jz ereturn # If zero 323 cli # Disable interrupts 324 mov 0x8(%bp),%eax # Get LBA 325 push %dx # Save 326 movzbl %cl,%ebx # Divide by 327 xor %edx,%edx # sectors 328 div %ebx # per track 329 movb %ch,%bl # Max head number 330 movb %dl,%ch # Sector number 331 inc %bx # Divide by 332 xorb %dl,%dl # number 333 div %ebx # of heads 334 movb %dl,%bh # Head number 335 pop %dx # Restore 336 cmpl $0x3ff,%eax # Cylinder number supportable? 337 sti # Enable interrupts 338 ja ereturn # No, return an error 339 xchgb %al,%ah # Set up cylinder 340 rorb $0x2,%al # number 341 orb %ch,%al # Merge 342 inc %ax # sector 343 xchg %ax,%cx # number 344 movb %bh,%dh # Head number 345 subb %ah,%al # Sectors this track 346 mov 0x2(%bp),%ah # Blocks to read 347 cmpb %ah,%al # To read 348 jb read.2 # this 349#ifdef TRACK_AT_A_TIME 350 movb %ah,%al # track 351#else 352 movb $1,%al # one sector 353#endif 354read.2: mov $0x5,%di # Try count 355read.3: les 0x4(%bp),%bx # Transfer buffer 356 push %ax # Save 357 movb $0x2,%ah # BIOS: Read 358 int $0x13 # from disk 359 pop %bx # Restore 360 jnc read.4 # If success 361 dec %di # Retry? 362 jz read.6 # No 363 xorb %ah,%ah # BIOS: Reset 364 int $0x13 # disk system 365 xchg %bx,%ax # Block count 366 jmp read.3 # Continue 367read.4: movzbw %bl,%ax # Sectors read 368 add %ax,0x8(%bp) # Adjust 369 jnc read.5 # LBA, 370 incw 0xa(%bp) # transfer 371read.5: shlb %bl # buffer 372 add %bl,0x5(%bp) # pointer, 373 sub %al,0x2(%bp) # block count 374 ja read.1 # If not done 375read.6: retw # To caller 376#else | |
377read.1: mov $msg_chs,%si 378 jmp error 379msg_chs: .asciz "CHS not supported" | 295read.1: mov $msg_chs,%si 296 jmp error 297msg_chs: .asciz "CHS not supported" |
380#endif | |
381 382/* Messages */ 383 384msg_read: .asciz "Read" 385msg_part: .asciz "Boot" 386 387prompt: .asciz " error\r\n" 388 | 298 299/* Messages */ 300 301msg_read: .asciz "Read" 302msg_part: .asciz "Boot" 303 304prompt: .asciz " error\r\n" 305 |
389flags: .byte FLAGS # Flags 390 | |
391 .org PRT_OFF,0x90 392 393/* Partition table */ 394 395 .fill 0x30,0x1,0x0 396part4: .byte 0x80, 0x00, 0x01, 0x00 397 .byte 0xa5, 0xfe, 0xff, 0xff 398 .byte 0x00, 0x00, 0x00, 0x00 399 .byte 0x50, 0xc3, 0x00, 0x00 # 50000 sectors long, bleh 400 401 .word 0xaa55 # Magic number | 306 .org PRT_OFF,0x90 307 308/* Partition table */ 309 310 .fill 0x30,0x1,0x0 311part4: .byte 0x80, 0x00, 0x01, 0x00 312 .byte 0xa5, 0xfe, 0xff, 0xff 313 .byte 0x00, 0x00, 0x00, 0x00 314 .byte 0x50, 0xc3, 0x00, 0x00 # 50000 sectors long, bleh 315 316 .word 0xaa55 # Magic number |