os/kernel/kernel.c

44 lines
832 B
C
Raw Normal View History

2018-10-19 07:59:38 -05:00
#include "../drivers/vga.h"
#include "../drivers/isr.h"
#include "../drivers/idt.h"
2018-10-20 11:32:14 -05:00
#include "../drivers/gdt.h"
2018-10-19 07:59:38 -05:00
/*
pop %eax; \
or $0x200,%eax; \
push %eax; \
*/
void switch_to_user_mode() {
2018-10-20 11:32:14 -05:00
// set_kernel_stack(0x80000);
// Set up a stack structure for switching to user mode.
asm volatile(" \
cli; \
mov $0x23, %ax; \
mov %ax, %ds; \
mov %ax, %es; \
mov %ax, %fs; \
mov %ax, %gs; \
\
mov %esp, %eax; \
pushl $0x23; \
pushl %eax; \
pushf; \
pushl $0x1B; \
push $1f; \
iret; \
1: \
");
2018-10-19 07:59:38 -05:00
}
void main() {
init_vga(GRAY,BLACK);
write_string("Initialized VGA\n");
isr_install();
asm volatile("sti");
write_string("Setup interrupts\n");
2018-10-20 11:32:14 -05:00
init_gdt();
write_string("Setup new GDT\n");
2018-10-19 07:59:38 -05:00
switch_to_user_mode();
2018-10-20 11:32:14 -05:00
write_string("User mode!\n");
2018-10-19 07:59:38 -05:00
}