The BIOS was designed for 16-bit machines. However, you have three options for invoking BIOS interrupts in protected mode.
- Return to real mode and re-enter protected mode (easy approach).
- Use v86 mode (not available in 64-bit mode).
- Write your own 16-bit x86 processor emulator (the toughest approach).
I used the first approach in my operating system for VBE and disk access via BIOS.
The code used for this purpose in my operating system is:
;______________________________________________________________________________________________________ ;Switch to 16-bit real Mode ;IN/OUT: nothing go16: [BITS 32] cli ;Clear interrupts pop edx ;save return location in edx jmp 0x20:PM16 ;Load CS with selector 0x20 ;For go to 16-bit real mode, first we have to go to 16-bit protected mode [BITS 16] PM16: mov ax, 0x28 ;0x28 is 16-bit protected mode selector. mov ss, ax mov ds, ax mov es, ax mov gs, ax mov fs, ax mov sp, 0x7c00+0x200 ;Stack hase base at 0x7c00+0x200 mov eax, cr0 and eax, 0xfffffffe ;Clear protected enable bit in cr0 mov cr0, eax jmp 0x50:realMode ;Load CS and IP realMode: ;Load segment registers with 16-bit Values. mov ax, 0x50 mov ds, ax mov fs, ax mov gs, ax mov ax, 0 mov ss, ax mov ax, 0 mov es, ax mov sp, 0x7c00+0x200 cli lidt[.idtR] ;Load real mode interrupt vector table sti push 0x50 ;New CS push dx ;New IP (saved in edx) retf ;Load CS, IP and Start real mode ;Real mode interrupt vector table .idtR: dw 0xffff ;Limit dd 0 ;Base
user2699357
source share