Kernel/Userspace: Start initial work on userspace and syscalls
This commit is contained in:
@@ -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();
|
||||
}
|
||||
|
||||
|
||||
@@ -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 = .;
|
||||
}
|
||||
@@ -148,6 +148,12 @@ namespace IDT
|
||||
descriptor.flags = 0x8E;
|
||||
}
|
||||
|
||||
static void register_syscall_handler(uint8_t index, void(*handler)())
|
||||
{
|
||||
register_interrupt_handler(index, handler);
|
||||
s_idt[index].flags = 0xEE;
|
||||
}
|
||||
|
||||
void register_irq_handler(uint8_t irq, void(*handler)())
|
||||
{
|
||||
s_irq_handlers[irq] = handler;
|
||||
@@ -203,6 +209,8 @@ namespace IDT
|
||||
extern "C" void irq14();
|
||||
extern "C" void irq15();
|
||||
|
||||
extern "C" void syscall_asm();
|
||||
|
||||
void initialize()
|
||||
{
|
||||
s_idt = (GateDescriptor*)kmalloc(0x100 * sizeof(GateDescriptor));
|
||||
@@ -262,6 +270,8 @@ namespace IDT
|
||||
REGISTER_IRQ_HANDLER(14);
|
||||
REGISTER_IRQ_HANDLER(15);
|
||||
|
||||
register_syscall_handler(0x80, syscall_asm);
|
||||
|
||||
flush_idt();
|
||||
}
|
||||
|
||||
|
||||
@@ -34,6 +34,23 @@
|
||||
popq %rax
|
||||
.endm
|
||||
|
||||
.macro popaq_no_rax
|
||||
popq %r15
|
||||
popq %r14
|
||||
popq %r13
|
||||
popq %r12
|
||||
popq %r11
|
||||
popq %r10
|
||||
popq %r9
|
||||
popq %r8
|
||||
popq %rsi
|
||||
popq %rdi
|
||||
popq %rbp
|
||||
popq %rdx
|
||||
popq %rcx
|
||||
popq %rbx
|
||||
.endm
|
||||
|
||||
isr_stub:
|
||||
pushaq
|
||||
|
||||
@@ -138,3 +155,15 @@ irq 12
|
||||
irq 13
|
||||
irq 14
|
||||
irq 15
|
||||
|
||||
.global syscall_asm
|
||||
syscall_asm:
|
||||
cli
|
||||
pushaq
|
||||
movq %rax, %rdi
|
||||
movq %rbx, %rsi
|
||||
xchgq %rcx, %rdx
|
||||
call cpp_syscall_handler
|
||||
popaq_no_rax
|
||||
addq $8, %rsp
|
||||
iretq
|
||||
@@ -11,7 +11,9 @@ SECTIONS
|
||||
}
|
||||
.rodata BLOCK(4K) : ALIGN(4K)
|
||||
{
|
||||
*(.rodata)
|
||||
g_rodata_start = .;
|
||||
*(.rodata.*)
|
||||
g_rodata_end = .;
|
||||
}
|
||||
.data BLOCK(4K) : ALIGN(4K)
|
||||
{
|
||||
@@ -22,6 +24,15 @@ SECTIONS
|
||||
*(COMMON)
|
||||
*(.bss)
|
||||
}
|
||||
|
||||
g_kernel_end = .;
|
||||
|
||||
. = 0x00A00000;
|
||||
|
||||
g_userspace_start = .;
|
||||
.userspace BLOCK(4K) : ALIGN(4K)
|
||||
{
|
||||
*(.userspace)
|
||||
}
|
||||
g_userspace_end = .;
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user