4 * Automatically retry all BIOS reads 0x80<->0x81 (and if (drive&0x80) drive^=1; in genral)
9 http://cvs.sourceforge.net/viewcvs.py/*checkout*/surprise/surprise/misc/int13sniff.S
12 /* !!! All defines below must be COMMENTED-OUT !
13 * !!! Define to value 0 has no effect.
16 /* Reduce size by omitting DOS-boot header signature to fit in 512 bytes.
17 * Cylinder 0 is requierd, sectors per track == 63 assumed!
18 * This constant is counted from 0 !!!
20 #define BACKUP_SECTOR 63
22 /* Reduce size by omitting DOS-boot header signature to fit in 512 bytes.
24 #define STRIP_BOOT_HEADER 1
26 /* Reduce size by omitting INT 0x18 handler.
30 /* Maintainers: Disable .org macroinstructions: ONLY FOR compilation tuning!
31 * - image produced doen't have any functionality!
35 /* Internal defines */
36 #define MEM_KBYTES 0x413 /* BIOS variable */
38 #define MAX_BOOT_SIZE_100 0xb6 /* LILO: leave some space for NT's and DR DOS' dirty */
39 #define MAX_BOOT_SIZE (MAX_BOOT_SIZE_100+0x100)
45 movw $0x0E00 | \char,%ax
53 #define MYORG(offset) .org (offset) + START /* "+ START" MUST be on the end of line - WHY?!? */
76 #define PUSHALL_SIZE (7*2)
77 #define PUSHALL_SI ((1/*%bp*/+1/*%di*/)*2)
79 .macro CallJumpVector0x13
80 pushf /* create 'lret' stack by this pushf... */
81 pushw %cs /* ...this segment... */
82 call JumpVector0x13 /* ...and this return address */
87 /* Code starts here */
88 /********************/
98 cli /* just a paranoia, shouldn't be needed */
99 jmp InitRawStack /* We don't want to have 0x90 on offset 2 (one of recognization rules by DOS) */
102 .macro places offset length string
103 .org (\offset) + START
105 .org (\offset) + (\length) + START /* we can't check whether it isn't too short :-( */
107 .macro placex offset length bytes
108 .org (\offset) + START
110 .org (\offset) + (\length) + START /* we can't check whether it isn't too short :-( */
113 /* We rather supply empty (=zeroed) FAT filesystem table
115 #ifndef STRIP_BOOT_HEADER
116 places 0x03,8,"BIOSRAID" /* OEM ID */
117 placex 0x43,3,"0x5E,0x81,0xA2" /* Volume Serial Number: 5E81A2?? as "SERIAL??" */
118 placex 0x43+3,1,BACKUP_SECTOR /* Volume Serial Number: 5E81A23F as "SERIAL??" */
119 places 0x47,11,"BIOSauRAID\0" /* Volume Label */
120 places 0x52,8,"BootOnly" /* Filesystem ID */
122 places 0x03,8,"BIOSRAI2" /* OEM ID */
123 placex 0x03+8,1,BACKUP_SECTOR /* Sanity checked by: biosautoraid.pl */
124 placex 0x03+9,1,MAX_BOOT_SIZE_100 /* Sanity checked by: biosautoraid.pl */
128 #ifndef STRIP_BOOT_HEADER
139 ljmp $0x7C0/*segment*/ , $InitContinue7C0-START/*offset*/
146 /* move to top memory */
147 xorw %dx,%dx /* DX=null */
149 movw %ds:MEM_KBYTES,%ax
150 decw %ax /* Allocation size: 1KB */
151 movw %ax,%ds:MEM_KBYTES
155 xorw %di,%di /* buffer=ES:DI */
161 movw $InitContinueTop-START,%ax
166 movw $TrailNL_Msg-START,%si
167 jmp PrintString_noPref
169 /* String is given in SI, returns updated SI */
181 movw $PrintString_loop-START,%bx /* from now do just 'ret' to close the loop */
185 /* Character is given in AL
186 * Preserves: DS, ES, SI, DI
187 * Destroys: AX (even AL!), BX, CX, DX
188 * DS is sometimes left preserved, sometimes set to DS=CS
191 movb $0x0E,%ah /* print character */
208 /* Main initialization */
209 /***********************/
210 /* DS invalid, ES==CS */
219 movw $1*1024,%sp /* Allocated 1 KB */
222 movw $HelloMsg-START,%si
225 /* now install our SniffFunction0x13 sniffer */
232 movw $OrigVector0x13-START,%di
234 movw $SniffFunction0x13-START,%ax
239 popw %di /* = $0x13*4 */
241 popw %es /* = null */
242 stosw /* $SniffFunction0x13-START */
247 movw $0x18*4,%di /* ROM basic - failed boot */
248 movw $SniffFunction0x18-START,%ax
253 #endif /* !STRIP_INT18 */
255 /* we WANT DS left with 0x0000 */
256 /* we WANT ES left with 0x0000 */
258 /* and give the system control to disk=0x80/masterboot */
259 movw $0x0201,%ax /* READ16 1 sector */
260 movw $0x7C00,%bx /* buffer=ES:BX= 0x0000:0x7C00 */
262 pushw %bx /* BX/DS on stack for later 'lret', S=2, prepared for far ret */
263 /* Interface to retry-capable INT13, set everything except CX */
264 /* function may destroy DS value! */
266 /* These two numbers get remapped to: BACKUP_SECTOR */
267 movw $0x0080,%dx /* Head 0, Drive 0x80 */
268 movw $0x0001,%cx /* Cylinder 0, Sector 1 */
271 pushw %dx /* save drive for resetting the controller */
272 movw $SF13_02_Err_Msg-START,%si
274 movb $0x00,%ah /* reset controller - FDC or HDC */
275 popw %dx /* restore the drive */
280 cmpw $0xAA55,%es:(0x7C00+0x1FE) /* 0x55,0xAA */
281 movw $BadSignatureMsg-START,%si
283 cli /* IMPORTANT: Boot sectors must be run with CLI! */
284 lret /* lret to 0x0000:0x7C00 */
288 movw $Interrupt0x18Msg-START,%si /* %ds gets fixed in PrintFatal */
289 #endif /* !STRIP_INT18 */
297 /**************************************************************/
298 /* Section for INT13 sniffing */
299 /* THIS point may start to be after 0x200 boundary */
300 /**************************************************************/
303 cmpb $0x41,%ah /* presence32 */
304 jne JumpVector0x13popa
306 jne JumpVector0x13popa
314 incw %sp /* trash discarded */
316 incw %sp /* original %ax discarded */
319 .byte 0xEA /* ljmp */
325 pushw %dx /* original %dx */
326 pushw %ax /* original %ax */
327 pushw %ax /* trash */
343 cmpb $0x02,%ah /* read16 */
361 movb /*orig-%dl:*/ %ss:2/*%bp*/+PUSHALL_SIZE+2/*%ds*/+2/*trash*/+2/*orig-%ax*/(%bp),%dl
362 xorb %cs:DriveFlipFlag-START,%dl /* %ds not yet initialized by: PrintString */
363 movb %dl,/*%dl:*/ %ss:2/*%bp*/+2/*%bp*/+2/*%di*/+2/*%si*/(%bp)
367 movw $SF13_02_Err_Msg-START,%si
372 jz SF13_leave /* just a floppy? */
374 jnz SF13_leave /* 0x82+ disk? It may be correct unsuccessful read. */
375 xorb $0x01,%ds:DriveFlipFlag-START /* %ds already initialized by: PrintString */
379 * as we must hide ourselves to let read GRUB itself frmo the masterboot.
383 jz SF13_leave /* just a floppy? */
385 jnz SF13_leave /* 0x82+ disk? It may be correct unsuccessful read. */
386 cmpw $0x0001,%cx /* Cylinder 0, Sector 1 ? */
388 cmpb $0x00,%dh /* Head 0 ? */
390 movb $BACKUP_SECTOR/63,%dh
391 movb $1+(BACKUP_SECTOR%63),%cl
394 xorb %cs:DriveFlipFlag-START,%dl /* %ds not yet initialized by: PrintString */
399 xorb $0x01,%cs:DriveFlipFlag-START /* %ds not yet initialized by: PrintString */
405 andb $0xFE,%ss:2/*%bp*/+PUSHALL_SIZE+2/*%ds*/+2/*trash*/+2/*orig-%ax*/+2/*orig-%dx*/+4/*ret-seg:offs*/(%bp) /* flags; clear CF */
412 movb /*%al:*/ %ss:2/*%bp*/+2/*%bp*/+2/*%di*/+2/*%si*/+2/*%dx*/+2/*%cx*/+2/*%bx*/(%bp),%al /* count */
413 movw /*%cx:*/ %ss:2/*%bp*/+2/*%bp*/+2/*%di*/+2/*%si*/+2/*%dx*/(%bp),%cx /* cylinder, sector */
414 cmpb $BACKUP_SECTOR/63,/*%dh:*/ %ss:2/*%bp*/+2/*%bp*/+2/*%di*/+2/*%si*/+1/*%dl*/(%bp) /* head */
417 SF13_leave_zero_loop:
420 cmpw $1+(BACKUP_SECTOR%63),%cx
421 je SF13_leave_zero_found
424 decb %al /* --count */
425 jmp SF13_leave_zero_loop
427 SF13_leave_zero_found:
438 incw %sp /* trash discarded */
440 incw %sp /* original %ax discarded */
445 popw %ax /* return address */
448 movw %ax,%ss:2/*%bp*/+PUSHALL_SIZE+2/*%ds*/(%bp) /* store %ax to 'trash' */
449 movw %ss:2/*%bp*/+PUSHALL_SIZE+2/*%ds*/+2/*trash*/(%bp),%ax /* restore original %ax */
450 movw %ax,%ss:2/*%bp*/+2/*%bp*/+2/*%di*/+2/*%si*/+2/*%dx*/+2/*%cx*/+2/*%bx*/(%bp) /* rewrite from original %ax */
456 pushALL /* stack is back to normal NOW */
457 pushw %bp /* trash - just to prepare return address16 */
461 movw %ss:2/*%bp*/+2/*%ax*/+2/*return16*/+PUSHALL_SIZE+2/*%ds*/(%bp),%ax
462 movw %ax,%ss:2/*%bp*/+2/*ax*/(%bp)
465 movw %ax,%ss:2/*%bp*/+2/*%ax*/+2/*return16*/+PUSHALL_SIZE+2/*%ds*/+2/*trash*/+2/*orig-%ax*/+2/*orig-%dx*/+4/*ret-seg:offs*/(%bp)
468 ret /* to prepared return16 and now will be stack in normal again */
470 /* Main upper half initialization messages */
471 /*******************************************/
475 .ascii "BIOSautoRAID, $Id$"
484 .asciz "Disk 0x80 has invalid signature!"
490 /* Interrupt sniffing messages */
491 /*******************************/
496 .asciz "Interrupt 0x18 - Failed boot!"
500 #endif /* !STRIP_INT18 */
503 /**************************************************************/
504 /* Final sector signature */
505 /**************************************************************/
508 /* Partition table */