Kernel/Userspace: Start initial work on userspace and syscalls

This commit is contained in:
Bananymous
2023-03-13 15:32:46 +02:00
parent af854ec9e1
commit 8b8e3cbbf0
10 changed files with 231 additions and 5 deletions

View File

@@ -151,6 +151,29 @@ found:
"popa;"
"iret;"
);
extern "C" void syscall_asm();
asm(
".global syscall_asm;"
"syscall_asm:"
"pusha;"
"pushw %ds;"
"pushw %es;"
"pushw %ss;"
"pushw %ss;"
"popw %ds;"
"popw %es;"
"pushl %edx;"
"pushl %ecx;"
"pushl %ebx;"
"pushl %eax;"
"call cpp_syscall_handler;"
"addl $16, %esp;"
"popw %es;"
"popw %ds;"
"popa;"
"iret;"
);
static void flush_idt()
{
@@ -175,6 +198,12 @@ found:
flush_idt();
}
void register_syscall_handler(uint8_t offset, void(*handler)())
{
register_interrupt_handler(offset, handler);
s_idt[offset].DPL = 3;
}
void initialize()
{
constexpr size_t idt_size = 0x100 * sizeof(GateDescriptor);
@@ -219,6 +248,8 @@ found:
REGISTER_HANDLER(0x1E);
REGISTER_HANDLER(0x1F);
register_syscall_handler(0x80, syscall_asm);
flush_idt();
}

View File

@@ -11,7 +11,9 @@ SECTIONS
}
.rodata BLOCK(4K) : ALIGN(4K)
{
*(.rodata)
g_rodata_start = .;
*(.rodata.*)
g_rodata_end = .;
}
.data BLOCK(4K) : ALIGN(4K)
{
@@ -24,4 +26,13 @@ SECTIONS
}
g_kernel_end = .;
. = 0x00A00000;
g_userspace_start = .;
.userspace BLOCK(4K) : ALIGN(4K)
{
*(.userspace)
}
g_userspace_end = .;
}