Browse Source

Allow boot sector to completely destroy real-mode stack, but still

manage to return control.
tags/v0.9.3
Michael Brown 17 years ago
parent
commit
a2ffe8c123
1 changed files with 15 additions and 10 deletions
  1. 15
    10
      src/arch/i386/interface/pcbios/int13.c

+ 15
- 10
src/arch/i386/interface/pcbios/int13.c View File

599
 	hook_bios_interrupt ( 0x19, ( unsigned int ) int13_exec_fail,
599
 	hook_bios_interrupt ( 0x19, ( unsigned int ) int13_exec_fail,
600
 			      &int19_vector );
600
 			      &int19_vector );
601
 
601
 
602
-	/* Boot the loaded sector */
603
-	__asm__ __volatile__ ( REAL_CODE ( /* Save segment registers */
604
-					   "pushw %%ds\n\t"
605
-					   "pushw %%es\n\t"
606
-					   "pushw %%fs\n\t"
607
-					   "pushw %%gs\n\t"
602
+	/* Boot the loaded sector
603
+	 *
604
+	 * We assume that the boot sector may completely destroy our
605
+	 * real-mode stack, so we preserve everything we need in
606
+	 * static storage.
607
+	 */
608
+	__asm__ __volatile__ ( REAL_CODE ( /* Save return address off-stack */
609
+					   "popw %%cs:int13_saved_retaddr\n\t"
608
 					   /* Save stack pointer */
610
 					   /* Save stack pointer */
609
 					   "movw %%ss, %%ax\n\t"
611
 					   "movw %%ss, %%ax\n\t"
610
 					   "movw %%ax, %%cs:int13_saved_ss\n\t"
612
 					   "movw %%ax, %%cs:int13_saved_ss\n\t"
611
 					   "movw %%sp, %%cs:int13_saved_sp\n\t"
613
 					   "movw %%sp, %%cs:int13_saved_sp\n\t"
614
+					   /* Jump to boot sector */
612
 					   "ljmp $0, $0x7c00\n\t"
615
 					   "ljmp $0, $0x7c00\n\t"
616
+					   /* Preserved variables */
613
 					   "\nint13_saved_ss: .word 0\n\t"
617
 					   "\nint13_saved_ss: .word 0\n\t"
614
 					   "\nint13_saved_sp: .word 0\n\t"
618
 					   "\nint13_saved_sp: .word 0\n\t"
619
+					   "\nint13_saved_retaddr: .word 0\n\t"
620
+					   /* Boot failure return point */
615
 					   "\nint13_exec_fail:\n\t"
621
 					   "\nint13_exec_fail:\n\t"
622
+					   /* Restore stack pointer */
616
 					   "movw %%cs:int13_saved_ss, %%ax\n\t"
623
 					   "movw %%cs:int13_saved_ss, %%ax\n\t"
617
 					   "movw %%ax, %%ss\n\t"
624
 					   "movw %%ax, %%ss\n\t"
618
 					   "movw %%cs:int13_saved_sp, %%sp\n\t"
625
 					   "movw %%cs:int13_saved_sp, %%sp\n\t"
619
-					   "popw %%gs\n\t"
620
-					   "popw %%fs\n\t"
621
-					   "popw %%es\n\t"
622
-					   "popw %%ds\n\t" )
626
+					   /* Return via saved address */
627
+					   "jmp *%%cs:int13_saved_retaddr\n\t")
623
 			       : "=d" ( discard_d ) : "d" ( drive )
628
 			       : "=d" ( discard_d ) : "d" ( drive )
624
 			       : "eax", "ebx", "ecx", "esi", "edi", "ebp" );
629
 			       : "eax", "ebx", "ecx", "esi", "edi", "ebp" );
625
 
630
 

Loading…
Cancel
Save