switch to ring3
This commit is contained in:
parent
269f7f6845
commit
28cd9deb9b
1
Makefile
1
Makefile
|
@ -20,6 +20,7 @@ ISO := Hazel.iso
|
||||||
CFLAGS := -ffreestanding -Wall -Wextra -Werror -I $(INCLUDEDIR) -I lib
|
CFLAGS := -ffreestanding -Wall -Wextra -Werror -I $(INCLUDEDIR) -I lib
|
||||||
LDFLAGS := -ffreestanding -nostdlib -lgcc -T kernel/kernel.ld
|
LDFLAGS := -ffreestanding -nostdlib -lgcc -T kernel/kernel.ld
|
||||||
QEMUFLAGS := -cdrom $(BUILDDIR)/$(ISO) \
|
QEMUFLAGS := -cdrom $(BUILDDIR)/$(ISO) \
|
||||||
|
-d int
|
||||||
-m 512M \
|
-m 512M \
|
||||||
-serial stdio
|
-serial stdio
|
||||||
|
|
||||||
|
|
|
@ -57,6 +57,24 @@ pit_isr:
|
||||||
call pit_handler
|
call pit_handler
|
||||||
iret
|
iret
|
||||||
|
|
||||||
|
global jmp_user_mode
|
||||||
|
jmp_user_mode:
|
||||||
|
mov ax, (4*8) | 3
|
||||||
|
mov ds, ax
|
||||||
|
mov es, ax
|
||||||
|
mov fs, ax
|
||||||
|
mov gs, ax ; SS is handled by iret
|
||||||
|
|
||||||
|
mov eax, esp
|
||||||
|
push (4*8) | 3
|
||||||
|
push eax
|
||||||
|
pushf
|
||||||
|
push (3*8) | 3
|
||||||
|
extern test_entry
|
||||||
|
push test_entry
|
||||||
|
|
||||||
|
iret
|
||||||
|
|
||||||
extern exception_handler
|
extern exception_handler
|
||||||
%macro isr_err_stub 1
|
%macro isr_err_stub 1
|
||||||
isr_stub_%+%1:
|
isr_stub_%+%1:
|
||||||
|
@ -142,6 +160,20 @@ gdt_kern_data:
|
||||||
db 0b10010010
|
db 0b10010010
|
||||||
db 0b11001111
|
db 0b11001111
|
||||||
db 0x00
|
db 0x00
|
||||||
|
gdt_user_code:
|
||||||
|
dw 0xffff
|
||||||
|
dw 0x0000
|
||||||
|
db 0x00
|
||||||
|
db 0b11111010
|
||||||
|
db 0b11001111
|
||||||
|
db 0x00
|
||||||
|
gdt_user_data:
|
||||||
|
dw 0xffff
|
||||||
|
dw 0x0000
|
||||||
|
db 0x00
|
||||||
|
db 0b11110010
|
||||||
|
db 0b11001111
|
||||||
|
db 0x00
|
||||||
gdt_end:
|
gdt_end:
|
||||||
|
|
||||||
gdtp:
|
gdtp:
|
||||||
|
|
|
@ -12,6 +12,12 @@ struct idtr idtr = {0};
|
||||||
|
|
||||||
extern uint32_t isr_stub_table[32];
|
extern uint32_t isr_stub_table[32];
|
||||||
extern void pit_isr(void);
|
extern void pit_isr(void);
|
||||||
|
extern void jmp_user_mode(void);
|
||||||
|
|
||||||
|
void test_entry(void) {
|
||||||
|
asm volatile ("cli" ::);
|
||||||
|
for (;;) {}
|
||||||
|
}
|
||||||
|
|
||||||
void exception_handler(int_stack_frame_t r) {
|
void exception_handler(int_stack_frame_t r) {
|
||||||
LOG("Exception 0x%X (0x%X) has occurred\nEAX: 0x%08X\nECX: 0x%08X\nEDX: 0x%08X\nEBX: 0x%08X\nESI: 0x%08X\nEDI: 0x%08X\nEBP: 0x%08X\nESP: 0x%08X\n",
|
LOG("Exception 0x%X (0x%X) has occurred\nEAX: 0x%08X\nECX: 0x%08X\nEDX: 0x%08X\nEBX: 0x%08X\nESI: 0x%08X\nEDI: 0x%08X\nEBP: 0x%08X\nESP: 0x%08X\n",
|
||||||
|
@ -36,7 +42,7 @@ void kernel(multiboot_info_t *info) {
|
||||||
LOG("Kernel log being sent to COM1\n");
|
LOG("Kernel log being sent to COM1\n");
|
||||||
|
|
||||||
if (!mmap_init()) goto halt;
|
if (!mmap_init()) goto halt;
|
||||||
LOG("%d bytes of RAM detected\nCreated a %d byte large physical memory map at 0x%08X\n", ctx.mmap_size*BLOCK_SIZE*8, ctx.mmap_size, ctx.mmap);
|
LOG("%d bytes of RAM detected\nCreated a %d byte large physical memory map at 0x%08X\n", ctx.mmap_size*BLOCK_SIZE*8, ctx.mmap_size, (uint32_t)ctx.mmap);
|
||||||
|
|
||||||
for (int i = 0; i < 32; i++) {
|
for (int i = 0; i < 32; i++) {
|
||||||
idt_encode_entry(idt, i, isr_stub_table[i], GDT_SEGMENT_SELECTOR(1, 0), TRAP_GATE_32 | INT_RING0 | INT_PRESENT);
|
idt_encode_entry(idt, i, isr_stub_table[i], GDT_SEGMENT_SELECTOR(1, 0), TRAP_GATE_32 | INT_RING0 | INT_PRESENT);
|
||||||
|
@ -48,10 +54,12 @@ void kernel(multiboot_info_t *info) {
|
||||||
|
|
||||||
asm volatile ("lidt %0" :: "m"(idtr));
|
asm volatile ("lidt %0" :: "m"(idtr));
|
||||||
pic_remap(PIC_1_START, PIC_2_START);
|
pic_remap(PIC_1_START, PIC_2_START);
|
||||||
asm volatile ("sti" ::);
|
//asm volatile ("sti" ::);
|
||||||
|
|
||||||
ctx.ticks = 0;
|
ctx.ticks = 0;
|
||||||
pit_init();
|
//pit_init();
|
||||||
|
|
||||||
|
jmp_user_mode();
|
||||||
|
|
||||||
halt:
|
halt:
|
||||||
for (;;) {}
|
for (;;) {}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user