os/kernel/kernel.c

75 lines
1.4 KiB
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-22 07:43:05 -05:00
#include "../drivers/paging.h"
2018-10-22 06:44:17 -05:00
#include "../drivers/keyboard.h"
#include "../libc/string.h"
#include "syscalls.h"
2018-10-22 06:44:17 -05:00
char* line=0;
2018-10-19 07:59:38 -05:00
void switch_to_user_mode() {
2018-10-20 11:32:14 -05:00
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; \
pop %eax; \
or $0x200,%eax; \
push %eax; \
2018-10-20 11:32:14 -05:00
pushl $0x1B; \
push $1f; \
iret; \
1: \
");
2018-10-19 07:59:38 -05:00
}
void main() {
init_vga(WHITE,BLACK);
2018-10-19 07:59:38 -05:00
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-22 07:43:05 -05:00
init_paging();
write_string("Setup paging\n");
init_keyboard();
2018-10-22 06:44:17 -05:00
write_string("Keyboard initialized\n");
2018-10-19 07:59:38 -05:00
switch_to_user_mode();
2018-10-22 07:43:05 -05:00
volatile int x=*((int*)0xffff0000);
2018-10-22 06:44:17 -05:00
syscall_write_string("MYOS V 1.0\n");
syscall_write_string(">");
char buf[256];
do {
syscall_gets(buf);
2018-10-22 07:43:05 -05:00
syscall_write_string(buf);
2018-10-22 06:44:17 -05:00
} while (buf[0]=='\0');
syscall_write_string(buf);
syscall_write_string("HALTING");
}
void user_input(char* str) {
2018-10-22 07:43:05 -05:00
write_string("GOT INPUT\n");
2018-10-22 06:44:17 -05:00
line=str;
}
void kgets(char* buf) {
if (line==0) {
buf[0]='\0';
return;
}
2018-10-22 07:43:05 -05:00
write_string("NOT ZERO\n");
2018-10-22 06:44:17 -05:00
strcpy(buf,line);
line=0;
2018-10-19 07:59:38 -05:00
}