mirror of
https://gitlab.os-k.eu/os-k-team/os-k.git
synced 2023-08-25 14:03:10 +02:00
WIP : gdt problem ?
This commit is contained in:
parent
d3db4efba4
commit
b57ed861ff
@ -34,15 +34,15 @@ KeJumpToUserspace:
|
|||||||
; rsi = entry point in user space
|
; rsi = entry point in user space
|
||||||
; rdx = user space stack
|
; rdx = user space stack
|
||||||
|
|
||||||
mov rax, 0x1b ; Selector 0x18 (User Data) + RPL 3
|
mov rax, 0x10 ; Selector 0x10 (User Data) + RPL 3
|
||||||
mov ds, ax
|
mov ds, ax
|
||||||
mov es, ax
|
mov es, ax
|
||||||
|
|
||||||
; Build a fake iret frame
|
; Build a fake iret frame
|
||||||
push rax ; Selector 0x18 (User Data) + RPL 3
|
push rax ; Selector 0x10 (User Data) + RPL 3
|
||||||
push rdx ; User space stack
|
push rdx ; User space stack
|
||||||
push 0x202 ; rflags = interrupt enable + reserved bit
|
push 0x202 ; rflags = interrupt enable + reserved bit
|
||||||
push 0x23 ; Selector 0x20 (User Code) + RPL 3
|
push 0x10 ; Selector 0x10 (User Code) + RPL 3
|
||||||
push rsi ; Entry point in user space
|
push rsi ; Entry point in user space
|
||||||
|
|
||||||
xor rax, rax
|
xor rax, rax
|
||||||
|
@ -41,7 +41,7 @@ void MmInitGdt(void)
|
|||||||
memzero((void *)&gdt[0], sizeof(gdt));
|
memzero((void *)&gdt[0], sizeof(gdt));
|
||||||
memzero((void *)&tssDesc, sizeof(tssDesc));
|
memzero((void *)&tssDesc, sizeof(tssDesc));
|
||||||
memzero((void *)&tss, sizeof(tss));
|
memzero((void *)&tss, sizeof(tss));
|
||||||
|
|
||||||
// Kernel codeseg
|
// Kernel codeseg
|
||||||
gdt[1].lowLimit = 0xFFFF;
|
gdt[1].lowLimit = 0xFFFF;
|
||||||
gdt[1].access = 0x98;
|
gdt[1].access = 0x98;
|
||||||
@ -74,14 +74,14 @@ void MmInitGdt(void)
|
|||||||
memmove(&gdt[3], &tssDesc, sizeof(TssDescriptor_t));
|
memmove(&gdt[3], &tssDesc, sizeof(TssDescriptor_t));
|
||||||
|
|
||||||
DebugLog("GDT & TSS initialized\n");
|
DebugLog("GDT & TSS initialized\n");
|
||||||
DebugLog("gdt[0] : %#x\n", &gdt[0]);
|
DebugLog("gdt[0] : %#b\n", gdt[0]);
|
||||||
DebugLog("gdt[1] : %#x\n", &gdt[1]);
|
DebugLog("gdt[1] : %#b\n", gdt[1]);
|
||||||
DebugLog("gdt[2] : %#x\n", &gdt[2]);
|
DebugLog("gdt[2] : %#b\n", gdt[2]);
|
||||||
DebugLog("tss : %#x\n", &gdt[3]);
|
DebugLog("tss : %#b\n", gdt[3]);
|
||||||
DebugLog("ist1 : %#x\n", tss.ist1);
|
DebugLog("ist1 : %#p\n", tss.ist1);
|
||||||
DebugLog("ist2 : %#x\n", tss.ist2);
|
DebugLog("ist2 : %#p\n", tss.ist2);
|
||||||
DebugLog("ist3 : %#x\n", tss.ist3);
|
DebugLog("ist3 : %#p\n", tss.ist3);
|
||||||
DebugLog("rsp0 : %#x\n", tss.ist1);
|
DebugLog("rsp0 : %#p\n", tss.ist1);
|
||||||
|
|
||||||
MmLoadGdt(&gdtPtr, tssOffset);
|
MmLoadGdt(&gdtPtr, tssOffset);
|
||||||
}
|
}
|
||||||
|
@ -30,6 +30,7 @@
|
|||||||
#include <io/vga.h>
|
#include <io/vga.h>
|
||||||
#include <io/spkr.h>
|
#include <io/spkr.h>
|
||||||
#include <ke/time.h>
|
#include <ke/time.h>
|
||||||
|
#include <ke/syscall.h>
|
||||||
#include <libbuf.h>
|
#include <libbuf.h>
|
||||||
#include <sh/shell.h>
|
#include <sh/shell.h>
|
||||||
#include <po/shtdwn.h>
|
#include <po/shtdwn.h>
|
||||||
@ -330,7 +331,41 @@ error_t CmdSyscallTest(int argc, char **argv, char *cmdline)
|
|||||||
|
|
||||||
error_t CmdRing3Test(int argc, char **argv, char *cmdline)
|
error_t CmdRing3Test(int argc, char **argv, char *cmdline)
|
||||||
{
|
{
|
||||||
// TODO
|
size_t size = 50*MB;
|
||||||
|
void *entryPoint = (void*)USERSPACE + 51*KB;
|
||||||
|
ulong flags = PRESENT | READWRITE | USERMODE;
|
||||||
|
|
||||||
|
KernLog("Allocating %u o...\n", size);
|
||||||
|
ulong id = MmAllocPageFrame(size, false);
|
||||||
|
KernLog("Allocated with id : %lu\n", id);
|
||||||
|
|
||||||
|
KernLog("Mapping pages id %d at %p (flags %#x)...\n", id, entryPoint, flags);
|
||||||
|
error_t err = MmMapPageFrame(id, entryPoint, flags);
|
||||||
|
if (err == EOK)
|
||||||
|
KernLog("Successfully mapped.\n");
|
||||||
|
else {
|
||||||
|
KernLog("Failed to map !\n");
|
||||||
|
return ENOMEM;
|
||||||
|
}
|
||||||
|
|
||||||
|
size = 50*KB;
|
||||||
|
void *stackAddr = (void*)USERSPACE;
|
||||||
|
flags = PRESENT | READWRITE | USERMODE;
|
||||||
|
|
||||||
|
KernLog("Allocating %u o...\n", size);
|
||||||
|
id = MmAllocPageFrame(size, false);
|
||||||
|
KernLog("Allocated with id : %lu\n", id);
|
||||||
|
|
||||||
|
KernLog("Mapping pages id %d at %p (flags %#x)...\n", id, stackAddr, flags);
|
||||||
|
err = MmMapPageFrame(id, stackAddr, flags);
|
||||||
|
if (err == EOK)
|
||||||
|
KernLog("Successfully mapped.\n");
|
||||||
|
else {
|
||||||
|
KernLog("Failed to map !\n");
|
||||||
|
return ENOMEM;
|
||||||
|
}
|
||||||
|
|
||||||
|
KeJumpToUserspace(0, entryPoint, stackAddr);
|
||||||
|
|
||||||
return EOK;
|
return EOK;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user