The task switching is inconsistent
This commit is contained in:
parent
98b4afb451
commit
72497974ca
|
@ -28,7 +28,7 @@ undefined behavior.
|
||||||
.section .bss, "aw", @nobits
|
.section .bss, "aw", @nobits
|
||||||
.align 16
|
.align 16
|
||||||
stack_bottom:
|
stack_bottom:
|
||||||
.skip 16384 # 16 KiB
|
.skip (1 << 16) # 16 KiB
|
||||||
stack_top:
|
stack_top:
|
||||||
|
|
||||||
.global boot_page_directory
|
.global boot_page_directory
|
||||||
|
|
|
@ -56,7 +56,7 @@ __attribute__((interrupt)) void exception(struct interrupt_frame*)
|
||||||
while (1) { }
|
while (1) { }
|
||||||
}
|
}
|
||||||
|
|
||||||
__attribute__((interrupt)) void page_fault(struct interrupt_frame*)
|
__attribute__((interrupt)) void page_fault(struct interrupt_frame* frame)
|
||||||
{
|
{
|
||||||
asm("cli");
|
asm("cli");
|
||||||
terminal_writestring("Page Fault\n");
|
terminal_writestring("Page Fault\n");
|
||||||
|
|
|
@ -33,12 +33,11 @@ mov %ax, %es
|
||||||
mov %ax, %fs
|
mov %ax, %fs
|
||||||
mov %ax, %gs
|
mov %ax, %gs
|
||||||
|
|
||||||
|
pop %eax
|
||||||
popa
|
popa
|
||||||
|
|
||||||
mov (esp), %esp
|
mov (esp), %esp
|
||||||
|
|
||||||
push (ss)
|
|
||||||
push (esp)
|
|
||||||
push (eflags)
|
push (eflags)
|
||||||
push (cs)
|
push (cs)
|
||||||
push (eip)
|
push (eip)
|
||||||
|
@ -55,6 +54,7 @@ mov %ax, %es
|
||||||
mov %ax, %fs
|
mov %ax, %fs
|
||||||
mov %ax, %gs
|
mov %ax, %gs
|
||||||
|
|
||||||
|
pop %eax
|
||||||
popa
|
popa
|
||||||
|
|
||||||
push (ss)
|
push (ss)
|
||||||
|
|
|
@ -1,4 +1,12 @@
|
||||||
.extern _syscall
|
.extern _syscall
|
||||||
|
|
||||||
|
.section .bss, "aw", @nobits
|
||||||
|
.align 16
|
||||||
|
syscall_stack_bottom:
|
||||||
|
.skip (1 << 16) # 16 KiB
|
||||||
|
syscall_stack_top:
|
||||||
|
|
||||||
|
.section .text
|
||||||
.global syscall
|
.global syscall
|
||||||
syscall:
|
syscall:
|
||||||
mov $0x10, %edx
|
mov $0x10, %edx
|
||||||
|
@ -8,7 +16,8 @@ mov %ax, %fs
|
||||||
mov %ax, %gs
|
mov %ax, %gs
|
||||||
|
|
||||||
mov %esp, %edx
|
mov %esp, %edx
|
||||||
mov $0x00f00000, %esp
|
|
||||||
|
mov $syscall_stack_top, %esp
|
||||||
push 0x10(%edx)
|
push 0x10(%edx)
|
||||||
push 0x0C(%edx)
|
push 0x0C(%edx)
|
||||||
push 0x08(%edx)
|
push 0x08(%edx)
|
||||||
|
|
|
@ -58,6 +58,7 @@ static void set_page_directory_entry(uintptr_t address, struct x86_Page_Table* t
|
||||||
boot_page_directory[address >> 22].address = ((uintptr_t)(table) - 0xC0000000) >> 12;
|
boot_page_directory[address >> 22].address = ((uintptr_t)(table) - 0xC0000000) >> 12;
|
||||||
boot_page_directory[address >> 22].present = true;
|
boot_page_directory[address >> 22].present = true;
|
||||||
boot_page_directory[address >> 22].read_write = true;
|
boot_page_directory[address >> 22].read_write = true;
|
||||||
|
boot_page_directory[address >> 22].user_supervisor = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -92,5 +93,7 @@ void setup_paging() {
|
||||||
user_data_table.read_write = true;
|
user_data_table.read_write = true;
|
||||||
user_data_table.user_supervisor = true;
|
user_data_table.user_supervisor = true;
|
||||||
|
|
||||||
|
user_data[0] = 'B';
|
||||||
|
|
||||||
reload_pages();
|
reload_pages();
|
||||||
}
|
}
|
||||||
|
|
|
@ -88,6 +88,7 @@ static uint16_t terminal_getentryat(size_t x, size_t y)
|
||||||
|
|
||||||
static void terminal_scroll()
|
static void terminal_scroll()
|
||||||
{
|
{
|
||||||
|
/*
|
||||||
for (size_t y = 0; y < VGA_HEIGHT; y++) {
|
for (size_t y = 0; y < VGA_HEIGHT; y++) {
|
||||||
for (size_t x = 0; x < VGA_WIDTH; x++) {
|
for (size_t x = 0; x < VGA_WIDTH; x++) {
|
||||||
if (y == VGA_HEIGHT - 1) {
|
if (y == VGA_HEIGHT - 1) {
|
||||||
|
@ -99,7 +100,11 @@ static void terminal_scroll()
|
||||||
terminal_putentryat(scrolled, color, x, y);
|
terminal_putentryat(scrolled, color, x, y);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
terminal_row = VGA_HEIGHT - 1;
|
*/
|
||||||
|
|
||||||
|
terminal_initialize();
|
||||||
|
|
||||||
|
terminal_row = 0;
|
||||||
terminal_column = 0;
|
terminal_column = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -18,7 +18,7 @@ extern void jump_to_userspace();
|
||||||
|
|
||||||
void run_program(uint8_t* code, size_t code_length, uint8_t* data, size_t data_length)
|
void run_program(uint8_t* code, size_t code_length, uint8_t* data, size_t data_length)
|
||||||
{
|
{
|
||||||
uint8_t* userland_code = (uint8_t*) 0x00000000;
|
uint8_t* userland_code = (uint8_t*) 0x00000010;
|
||||||
uint8_t* userland_data = (uint8_t*) 0x00400000;
|
uint8_t* userland_data = (uint8_t*) 0x00400000;
|
||||||
|
|
||||||
memcpy(userland_code, code, code_length);
|
memcpy(userland_code, code, code_length);
|
||||||
|
@ -26,7 +26,7 @@ void run_program(uint8_t* code, size_t code_length, uint8_t* data, size_t data_l
|
||||||
|
|
||||||
struct CPUState target = {
|
struct CPUState target = {
|
||||||
.eip = (size_t) userland_code,
|
.eip = (size_t) userland_code,
|
||||||
.esp = 0x00400000,
|
.esp = 0x00401000,
|
||||||
.eax = 0,
|
.eax = 0,
|
||||||
.ebx = 0,
|
.ebx = 0,
|
||||||
.ecx = 0,
|
.ecx = 0,
|
||||||
|
@ -34,7 +34,7 @@ void run_program(uint8_t* code, size_t code_length, uint8_t* data, size_t data_l
|
||||||
.cs = 0x18 | 0x3,
|
.cs = 0x18 | 0x3,
|
||||||
.ds = 0x20 | 0x3,
|
.ds = 0x20 | 0x3,
|
||||||
.eflags = 0x0200,
|
.eflags = 0x0200,
|
||||||
.ebp = 0x00c00f00,
|
.ebp = 0,
|
||||||
};
|
};
|
||||||
|
|
||||||
struct Task task = {
|
struct Task task = {
|
||||||
|
|
|
@ -14,11 +14,15 @@
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
uint8_t program[] = {
|
uint8_t program[] = {
|
||||||
0xcd, 0x80, // int 0x80
|
// 0xcd, 0x80, // int $0x80
|
||||||
|
0xb9, 0x02, 0x00, 0x00, 0x00, // mov $0, %ecx
|
||||||
|
0xff, 0xe1, // jmp *%ecx
|
||||||
};
|
};
|
||||||
|
|
||||||
uint8_t data[] = "Hello From Userspace\n";
|
// uint8_t data[] = "Hello From Userspace\n";
|
||||||
|
uint8_t data[] = {};
|
||||||
|
|
||||||
|
void irq0();
|
||||||
|
|
||||||
void kernel_main(void)
|
void kernel_main(void)
|
||||||
{
|
{
|
||||||
|
@ -38,9 +42,10 @@ void kernel_main(void)
|
||||||
run_program(program, sizeof(program), data, sizeof(data));
|
run_program(program, sizeof(program), data, sizeof(data));
|
||||||
|
|
||||||
asm("sti");
|
asm("sti");
|
||||||
|
asm("int $0x20");
|
||||||
|
|
||||||
while (true) {
|
while (true) {
|
||||||
terminal_writestring("Hello from Kernelspace 1\n");
|
terminal_writestring("Hello from Kernelspace 1\n");
|
||||||
terminal_writestring("Hello from Kernelspace 2\n");
|
// terminal_writestring("Hello from Kernelspace 2\n");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -35,5 +35,5 @@ void _syscall(uint32_t a, uint32_t b, uint32_t c)
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
*/
|
*/
|
||||||
terminal_writestring("waow :3");
|
terminal_writestring("waow :3\n");
|
||||||
}
|
}
|
||||||
|
|
|
@ -118,6 +118,7 @@ void next_task() {
|
||||||
eip = s.eip;
|
eip = s.eip;
|
||||||
|
|
||||||
if ((cs & 3) == 0) {
|
if ((cs & 3) == 0) {
|
||||||
|
// esp -= 4;
|
||||||
jump_kernel(
|
jump_kernel(
|
||||||
s.edi,
|
s.edi,
|
||||||
s.esi,
|
s.esi,
|
||||||
|
|
Loading…
Reference in a new issue