limine/common/pxe/pxe_asm.s2.asm_bios_ia32

98 lines
1.3 KiB
Plaintext
Raw Normal View History

2020-11-05 03:37:45 +03:00
section .realmode
global pxe_call
global set_pxe_fp
set_pxe_fp:
mov eax, [esp + 4]
mov [pxe_call.pxe_fp], eax
ret
pxe_call:
2021-08-12 08:40:29 +03:00
; Save GDT in case BIOS overwrites it
2020-11-05 03:37:45 +03:00
sgdt [.gdt]
2021-08-12 08:40:29 +03:00
; Save IDT
sidt [.idt]
; Load BIOS IVT
lidt [.rm_idt]
2020-11-05 03:37:45 +03:00
; Save non-scratch GPRs
push ebx
push esi
push edi
push ebp
2021-08-12 08:40:29 +03:00
lea ebp, [esp + 20]
2020-11-05 03:37:45 +03:00
; Jump to real mode
jmp 0x08:.bits16
.bits16:
bits 16
mov ax, 0x10
mov ds, ax
mov es, ax
mov fs, ax
mov gs, ax
mov ss, ax
mov eax, cr0
and al, 0xfe
mov cr0, eax
jmp 0x00:.cszero
.cszero:
xor ax, ax
mov ss, ax
mov ds, ax
mov es, ax
mov fs, ax
mov gs, ax
sti
2021-08-12 08:40:29 +03:00
push word [bp + 4]
push word [bp + 8]
push word [bp + 0]
2020-11-05 03:37:45 +03:00
call far [.pxe_fp]
add sp, 6
cli
2021-08-12 08:40:29 +03:00
; Restore GDT
o32 lgdt [cs:.gdt]
; Restore IDT
o32 lidt [cs:.idt]
2020-11-05 03:37:45 +03:00
; Jump back to pmode
2021-08-12 08:40:29 +03:00
mov ebx, cr0
or bl, 1
mov cr0, ebx
2020-11-05 03:37:45 +03:00
jmp 0x18:.bits32
.bits32:
bits 32
2021-08-12 08:40:29 +03:00
mov bx, 0x20
mov ds, bx
mov es, bx
mov fs, bx
mov gs, bx
mov ss, bx
and eax, 0xffff
2020-11-05 03:37:45 +03:00
; Restore non-scratch GPRs
pop ebp
pop edi
pop esi
pop ebx
; Exit
ret
align 16
.pxe_fp: dd 0
.gdt: dq 0
2021-08-12 08:40:29 +03:00
.idt: dq 0
.rm_idt: dw 0x3ff
dd 0