Browse Source

Proof of concept; works, but has several hard-coded hacks.

tags/v0.9.3
Michael Brown 17 years ago
parent
commit
c7d9fdb5b9
1 changed files with 46 additions and 7 deletions
  1. 46
    7
      src/arch/i386/interface/pcbios/int13.c

+ 46
- 7
src/arch/i386/interface/pcbios/int13.c View File

355
  */
355
  */
356
 static void int13 ( struct i386_all_regs *ix86 ) {
356
 static void int13 ( struct i386_all_regs *ix86 ) {
357
 	int command = ix86->regs.ah;
357
 	int command = ix86->regs.ah;
358
+	unsigned int bios_drive = ix86->regs.dl;
359
+	unsigned int original_bios_drive = bios_drive;
358
 	struct int13_drive *drive;
360
 	struct int13_drive *drive;
359
 	int status;
361
 	int status;
360
 
362
 
361
 	list_for_each_entry ( drive, &drives, list ) {
363
 	list_for_each_entry ( drive, &drives, list ) {
362
-		if ( drive->drive != ix86->regs.dl )
364
+		if ( drive->drive > bios_drive )
363
 			continue;
365
 			continue;
366
+		if ( drive->drive < bios_drive ) {
367
+			original_bios_drive--;
368
+			continue;
369
+		}
364
 		
370
 		
365
 		DBG ( "INT 13,%04x (%02x): ", ix86->regs.ax, drive->drive );
371
 		DBG ( "INT 13,%04x (%02x): ", ix86->regs.ax, drive->drive );
366
 
372
 
421
 
427
 
422
 		break;
428
 		break;
423
 	}
429
 	}
430
+
431
+	/* Remap BIOS drive */
432
+	if ( bios_drive != original_bios_drive ) {
433
+		DBG ( "INT 13,%04x (%02x) remapped to (%02x)\n",
434
+		      ix86->regs.ax, bios_drive, original_bios_drive );
435
+	}
436
+	ix86->regs.dl = original_bios_drive;
424
 }
437
 }
425
 
438
 
426
 /**
439
 /**
434
 	 */
447
 	 */
435
 	__asm__  __volatile__ (
448
 	__asm__  __volatile__ (
436
 	       TEXT16_CODE ( "\nint13_wrapper:\n\t"
449
 	       TEXT16_CODE ( "\nint13_wrapper:\n\t"
437
-			     "orb $0, %%al\n\t" /* clear OF */
450
+			     /* Preserve %ax and %dx for future reference */
451
+			     "pushw %%bp\n\t"
452
+			     "movw %%sp, %%bp\n\t"			     
453
+			     "pushw %%ax\n\t"
454
+			     "pushw %%dx\n\t"
455
+			     /* Clear OF, set CF, call int13() */
456
+			     "orb $0, %%al\n\t" 
438
 			     "stc\n\t"
457
 			     "stc\n\t"
439
-			     "pushl %0\n\t" /* call int13() */
458
+			     "pushl %0\n\t"
440
 			     "pushw %%cs\n\t"
459
 			     "pushw %%cs\n\t"
441
 			     "call prot_call\n\t"
460
 			     "call prot_call\n\t"
442
-			     "jo 1f\n\t" /* chain if OF not set */
461
+			     /* Chain if OF not set */
462
+			     "jo 1f\n\t"
443
 			     "pushfw\n\t"
463
 			     "pushfw\n\t"
444
 			     "lcall *%%cs:int13_vector\n\t"
464
 			     "lcall *%%cs:int13_vector\n\t"
445
 			     "\n1:\n\t"
465
 			     "\n1:\n\t"
446
-			     "call 2f\n\t" /* return with flags intact */
447
-			     "lret $2\n\t"
466
+			     /* Overwrite flags for iret */
467
+			     "pushfw\n\t"
468
+			     "popw 6(%%bp)\n\t"
469
+			     /* Restore %dl (except for %ah=0x08 or 0x15) */
470
+			     "cmpb $0x08, -1(%%bp)\n\t"
471
+
472
+			     "jne 7f\n\t"
473
+			     "movb $2, %%dl\n\t"
474
+			     "jmp 2f\n\t"
475
+			     "\n7:\n\t"
476
+
477
+			     "je 2f\n\t"
478
+			     "cmpb $0x15, -1(%%bp)\n\t"
479
+			     "je 2f\n\t"
480
+			     "movb -4(%%bp), %%dl\n\t"
448
 			     "\n2:\n\t"
481
 			     "\n2:\n\t"
449
-			     "ret $4\n\t" ) : : "i" ( int13 ) );
482
+			     /* Return */
483
+			     "movw %%bp, %%sp\n\t"
484
+			     "popw %%bp\n\t"
485
+			     "iret\n\t" ) : : "i" ( int13 ) );
450
 
486
 
451
 	hook_bios_interrupt ( 0x13, ( unsigned int ) int13_wrapper,
487
 	hook_bios_interrupt ( 0x13, ( unsigned int ) int13_wrapper,
452
 			      &int13_vector );
488
 			      &int13_vector );
541
 		drive->drive = ( num_drives | 0x80 );
577
 		drive->drive = ( num_drives | 0x80 );
542
 	if ( num_drives <= ( drive->drive & 0x7f ) )
578
 	if ( num_drives <= ( drive->drive & 0x7f ) )
543
 		num_drives = ( ( drive->drive & 0x7f ) + 1 );
579
 		num_drives = ( ( drive->drive & 0x7f ) + 1 );
580
+
581
+	num_drives = 2;
582
+
544
 	put_real ( num_drives, BDA_SEG, BDA_NUM_DRIVES );
583
 	put_real ( num_drives, BDA_SEG, BDA_NUM_DRIVES );
545
 
584
 
546
 	DBG ( "Registered INT13 drive %02x with C/H/S geometry %d/%d/%d\n",
585
 	DBG ( "Registered INT13 drive %02x with C/H/S geometry %d/%d/%d\n",

Loading…
Cancel
Save