We now jump to userspace !

This commit is contained in:
Adrien Bourmault 2021-03-01 16:29:37 +01:00
parent 3c1e97c157
commit d0d546e073
Signed by: neox
GPG Key ID: 6EB408FE0ACEC664
2 changed files with 7 additions and 5 deletions

View File

@ -40,11 +40,12 @@ KeJumpToUserspace:
; rdx = user space stack
; Build a fake iret frame
push QWORD 0x10 ; Selector 0x20 (User Data) + RPL 3
push QWORD 0x23 ; Selector 0x20 (User Data) + RPL 3
push rdx ; User space stack
push QWORD 0x202 ; rflags = interrupt enable + reserved bit
push QWORD 0x08 ; Selector 0x18 (User Code) + RPL 3
push QWORD 0x1B ; Selector 0x18 (User Code) + RPL 3
push rsi ; Entry point in user space
iretq

View File

@ -43,18 +43,19 @@ void MmInitGdt(void)
memzero((void *)&tss, sizeof(tss));
// Kernel codeseg
gdt[1].access = PRESENTSEG | RESERVED | RESERVED2;
gdt[1].access = PRESENTSEG | READABLE | RESERVED | RESERVED2;
gdt[1].flags = LONG;
// Kernel dataseg
gdt[2].access = PRESENTSEG;
gdt[2].access = PRESENTSEG | READABLE | RESERVED2;
gdt[2].flags = LONG;
// User codeseg
gdt[3].access = PRESENTSEG | RESERVED | RESERVED2 | USER | USER2;
gdt[3].flags = LONG;
// User dataseg
gdt[4].access = PRESENTSEG | USER | USER2;
gdt[4].access = PRESENTSEG | READABLE | RESERVED2 | USER | USER2;
tssDesc.access = TSS_TYPE | PRESENTSEG;
tssDesc.lowBase = (ulong)&tss & 0xFFFF;