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"
|
2018-10-28 13:01:00 -05:00
|
|
|
#include "../drivers/serial.h"
|
2018-10-21 17:45:12 -05:00
|
|
|
#include "syscalls.h"
|
2018-10-22 06:44:17 -05:00
|
|
|
|
2018-10-28 13:01:00 -05:00
|
|
|
char line[256];
|
|
|
|
char input=0;
|
2018-10-22 06:44:17 -05:00
|
|
|
|
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; \
|
2018-10-21 17:45:12 -05:00
|
|
|
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() {
|
2018-10-21 17:45:12 -05:00
|
|
|
init_vga(WHITE,BLACK);
|
2018-10-19 07:59:38 -05:00
|
|
|
write_string("Initialized VGA\n");
|
2018-10-28 13:01:00 -05:00
|
|
|
serial_full_configure(SERIAL_COM1_BASE,12);
|
|
|
|
write_string("Initialized COM1 at 9600 baud\n");
|
2018-10-19 07:59:38 -05:00
|
|
|
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");
|
2018-10-21 17:45:12 -05:00
|
|
|
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 06:44:17 -05:00
|
|
|
syscall_write_string("MYOS V 1.0\n");
|
2018-10-28 13:01:00 -05:00
|
|
|
int mb=8;
|
|
|
|
while (1) {
|
|
|
|
syscall_write_string(">");
|
|
|
|
char buf[256];
|
|
|
|
do {
|
|
|
|
syscall_gets(buf);
|
|
|
|
} while (buf[0]=='\0');
|
|
|
|
if (strcmp("pf\n",buf)==0) {
|
|
|
|
int* ptr=(int*)(mb*1048576);
|
|
|
|
char str[20];
|
|
|
|
int_to_ascii(mb,str);
|
|
|
|
write_string("Storing ");
|
|
|
|
write_string(str);
|
|
|
|
str[0]='\0';
|
|
|
|
hex_to_ascii(ptr,str);
|
|
|
|
write_string(" into ");
|
|
|
|
write_string(str);
|
|
|
|
write_string("\n");
|
|
|
|
*ptr=mb;
|
|
|
|
write_string("Loading value\n");
|
|
|
|
int x=*ptr;
|
|
|
|
write_string("Got ");
|
|
|
|
str[0]='\0';
|
|
|
|
int_to_ascii(x,str);
|
|
|
|
write_string(str);
|
|
|
|
write_string("\n");
|
|
|
|
mb+=1;
|
|
|
|
}
|
|
|
|
}
|
2018-10-21 17:45:12 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
void user_input(char* str) {
|
2018-10-28 13:01:00 -05:00
|
|
|
strcpy(line,str);
|
|
|
|
input=1;
|
2018-10-22 06:44:17 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
void kgets(char* buf) {
|
2018-10-28 13:01:00 -05:00
|
|
|
if (input) {
|
|
|
|
strcpy(buf,line);
|
|
|
|
input=0;
|
|
|
|
} else {
|
2018-10-22 06:44:17 -05:00
|
|
|
buf[0]='\0';
|
|
|
|
return;
|
|
|
|
}
|
2018-10-19 07:59:38 -05:00
|
|
|
}
|