2021-10-10 14:39:17 +08:00
|
|
|
format elf64
|
|
|
|
|
|
|
|
public interrupt_ReloadSegments
|
2021-10-14 15:51:50 +08:00
|
|
|
public interrupt_LoadGDT
|
|
|
|
public interrupt_LoadIDT
|
2021-10-10 14:39:17 +08:00
|
|
|
|
|
|
|
|
|
|
|
section '.text' executable
|
|
|
|
|
|
|
|
; sysvx64call void interrupt_ReloadSegments()
|
|
|
|
;
|
|
|
|
; Clobbers: rax
|
|
|
|
interrupt_ReloadSegments:
|
2021-11-14 17:31:11 +08:00
|
|
|
mov ax, 0x08 ; my data segment
|
2021-10-10 14:39:17 +08:00
|
|
|
mov ds, ax
|
|
|
|
mov es, ax
|
|
|
|
mov fs, ax
|
|
|
|
mov gs, ax
|
|
|
|
mov ss, ax
|
|
|
|
|
2021-11-14 17:31:11 +08:00
|
|
|
;jmp 0x10:.flush
|
2021-10-10 14:39:17 +08:00
|
|
|
; as in https://forum.osdev.org/viewtopic.php?f=1&t=30739
|
|
|
|
; farjump does not work in long mode, you need to do a far return:
|
|
|
|
pop rax
|
2021-11-14 17:31:11 +08:00
|
|
|
push qword 0x10 ; my code segment
|
2021-10-10 14:39:17 +08:00
|
|
|
push rax
|
|
|
|
retfq
|
|
|
|
|
2021-10-14 15:51:50 +08:00
|
|
|
; sysvx64call void interrupt_LoadGDT(uint16_t length_sub1, void* base_ptr)
|
|
|
|
;
|
|
|
|
; Input: (uint16_t di, void* rsi)
|
|
|
|
; Clobbers: rax, flags
|
|
|
|
interrupt_LoadGDT:
|
|
|
|
mov rax, rsp ; save old RSP
|
|
|
|
sub rsp, 10
|
|
|
|
and rsp, 0xfffffffffffffffc ; align RSP to 4-byte
|
|
|
|
mov [rsp], di
|
|
|
|
mov [rsp+2], rsi
|
|
|
|
lgdt [rsp]
|
|
|
|
mov rsp, rax ; restore old RSP
|
|
|
|
ret
|
|
|
|
|
|
|
|
; sysvx64call void interrupt_LoadIDT(uint16_t length_sub1, void* base_ptr)
|
|
|
|
;
|
|
|
|
; Input: (uint16_t di, void* rsi)
|
|
|
|
; Clobbers: rax, flags
|
|
|
|
interrupt_LoadIDT:
|
|
|
|
mov rax, rsp ; save old RSP
|
|
|
|
sub rsp, 10
|
|
|
|
and rsp, 0xfffffffffffffffc ; align RSP to 4-byte
|
|
|
|
mov [rsp], di
|
|
|
|
mov [rsp+2], rsi
|
|
|
|
lidt [rsp]
|
|
|
|
mov rsp, rax ; restore old RSP
|
|
|
|
ret
|