bootsector.c
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019 FILE_LICENCE ( GPL2_OR_LATER );
00020
00021
00022
00023
00024
00025
00026
00027
00028 #include <errno.h>
00029 #include <realmode.h>
00030 #include <biosint.h>
00031 #include <bootsector.h>
00032
00033
00034
00035
00036
00037
00038 static struct segoff int18_vector;
00039
00040
00041
00042
00043
00044
00045 static struct segoff int19_vector;
00046
00047
00048 extern void bootsector_exec_fail ( void );
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058 int call_bootsector ( unsigned int segment, unsigned int offset,
00059 unsigned int drive ) {
00060 int discard_b, discard_D, discard_d;
00061
00062 DBG ( "Booting from boot sector at %04x:%04x\n", segment, offset );
00063
00064
00065 hook_bios_interrupt ( 0x18, ( unsigned int ) bootsector_exec_fail,
00066 &int18_vector );
00067 hook_bios_interrupt ( 0x19, ( unsigned int ) bootsector_exec_fail,
00068 &int19_vector );
00069
00070
00071
00072
00073
00074
00075
00076 __asm__ __volatile__ ( REAL_CODE (
00077 "popw %%cs:saved_retaddr\n\t"
00078
00079 "movw %%ss, %%ax\n\t"
00080 "movw %%ax, %%cs:saved_ss\n\t"
00081 "movw %%sp, %%cs:saved_sp\n\t"
00082
00083 "pushw %%bx\n\t"
00084 "pushw %%di\n\t"
00085 "sti\n\t"
00086 "lret\n\t"
00087
00088 "\nsaved_ss: .word 0\n\t"
00089 "\nsaved_sp: .word 0\n\t"
00090 "\nsaved_retaddr: .word 0\n\t"
00091
00092 "\nbootsector_exec_fail:\n\t"
00093
00094 "movw %%cs:saved_ss, %%ax\n\t"
00095 "movw %%ax, %%ss\n\t"
00096 "movw %%cs:saved_sp, %%sp\n\t"
00097
00098 "jmp *%%cs:saved_retaddr\n\t" )
00099 : "=b" ( discard_b ), "=D" ( discard_D ),
00100 "=d" ( discard_d )
00101 : "b" ( segment ), "D" ( offset ),
00102 "d" ( drive )
00103 : "eax", "ecx", "esi", "ebp" );
00104
00105 DBG ( "Booted disk returned via INT 18 or 19\n" );
00106
00107
00108 unhook_bios_interrupt ( 0x18, ( unsigned int ) bootsector_exec_fail,
00109 &int18_vector );
00110 unhook_bios_interrupt ( 0x19, ( unsigned int ) bootsector_exec_fail,
00111 &int19_vector );
00112
00113 return -ECANCELED;
00114 }