2022-11-20 19:48:55 +03:00
|
|
|
#include "console.h"
|
2022-11-20 18:59:53 +03:00
|
|
|
#include "cpu/isr.h"
|
2022-11-22 21:24:49 +03:00
|
|
|
#include "cpu/gdt.h"
|
2025-01-17 23:29:01 +04:00
|
|
|
#include "cpu/memlayout.h"
|
2022-11-20 19:48:55 +03:00
|
|
|
#include "drivers/keyboard.h"
|
2022-11-20 16:06:32 +03:00
|
|
|
#include "drivers/vga.h"
|
2022-11-18 22:58:49 +03:00
|
|
|
#include "drivers/ata.h"
|
|
|
|
|
#include "drivers/misc.h"
|
2023-01-25 14:56:38 +04:00
|
|
|
#include "drivers/pit.h"
|
2022-11-21 00:53:29 +03:00
|
|
|
#include "drivers/uart.h"
|
2022-12-13 00:50:28 +03:00
|
|
|
#include "fs/fs.h"
|
2022-12-13 19:06:51 +03:00
|
|
|
#include "lib/string.h"
|
2022-12-14 09:00:32 +03:00
|
|
|
#include "proc.h"
|
2025-01-17 23:29:01 +04:00
|
|
|
#include "kernel/mem.h"
|
2022-12-14 09:00:32 +03:00
|
|
|
|
2025-02-01 17:25:59 +04:00
|
|
|
void vga_set_pixel(int x, int y, int color) {
|
|
|
|
|
unsigned char* pixel = (unsigned char*) (KERNBASE + 0xA0000 + 320 * y + x);
|
|
|
|
|
*pixel = color;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void graphtest() {
|
|
|
|
|
vgaMode13();
|
|
|
|
|
for (int i = 0; i < 320; ++i) {
|
|
|
|
|
for (int j = 0; j < 200; ++j) {
|
|
|
|
|
vga_set_pixel(i, j, (i+j)/2);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
msleep(5000);
|
|
|
|
|
vgaMode3();
|
|
|
|
|
vga_clear_screen();
|
|
|
|
|
}
|
2022-11-14 00:23:42 +03:00
|
|
|
|
2025-01-17 20:44:33 +04:00
|
|
|
void kmain() {
|
2025-01-17 23:29:01 +04:00
|
|
|
freerange(P2V(1u<<20), P2V(2u<<20)); // 1MB - 2MB
|
|
|
|
|
kvmalloc(); // map all of physical memory at KERNBASE
|
|
|
|
|
freerange(P2V(2u<<20), P2V(PHYSTOP));
|
|
|
|
|
|
2022-11-22 21:24:49 +03:00
|
|
|
load_gdt();
|
2022-11-20 19:48:55 +03:00
|
|
|
init_keyboard();
|
2023-01-25 14:56:38 +04:00
|
|
|
init_pit();
|
2022-11-21 00:53:29 +03:00
|
|
|
uartinit();
|
2022-11-20 18:59:53 +03:00
|
|
|
load_idt();
|
|
|
|
|
sti();
|
2022-12-13 01:18:30 +03:00
|
|
|
|
2022-11-14 00:23:42 +03:00
|
|
|
vga_clear_screen();
|
2022-11-20 19:48:55 +03:00
|
|
|
printk("YABLOKO\n");
|
2022-11-18 22:58:49 +03:00
|
|
|
|
2022-12-14 17:17:27 +03:00
|
|
|
printk("\n> ");
|
2022-11-20 19:48:55 +03:00
|
|
|
while (1) {
|
2022-12-13 01:18:30 +03:00
|
|
|
if (kbd_buf_size > 0 && kbd_buf[kbd_buf_size-1] == '\n') {
|
|
|
|
|
if (!strncmp("halt\n", kbd_buf, kbd_buf_size)) {
|
|
|
|
|
qemu_shutdown();
|
2023-01-25 14:56:38 +04:00
|
|
|
} else if (!strncmp("work\n", kbd_buf, kbd_buf_size)) {
|
|
|
|
|
for (int i = 0; i < 5; ++i) {
|
|
|
|
|
msleep(1000);
|
|
|
|
|
printk(".");
|
|
|
|
|
}
|
2022-12-14 09:00:32 +03:00
|
|
|
} else if (!strncmp("run ", kbd_buf, 4)) {
|
2022-12-13 19:06:51 +03:00
|
|
|
kbd_buf[kbd_buf_size-1] = '\0';
|
2022-12-14 09:00:32 +03:00
|
|
|
const char* cmd = kbd_buf + 4;
|
|
|
|
|
run_elf(cmd);
|
2025-02-01 17:25:59 +04:00
|
|
|
} else if (!strncmp("graphtest", kbd_buf, 9)) {
|
|
|
|
|
graphtest();
|
2022-12-13 01:18:30 +03:00
|
|
|
} else {
|
2022-12-14 17:17:27 +03:00
|
|
|
printk("unknown command, try: halt | run CMD");
|
2022-12-13 01:18:30 +03:00
|
|
|
}
|
|
|
|
|
kbd_buf_size = 0;
|
2022-12-14 09:00:32 +03:00
|
|
|
printk("\n> ");
|
2022-12-13 01:18:30 +03:00
|
|
|
}
|
2022-11-21 00:53:29 +03:00
|
|
|
asm("hlt");
|
2022-11-20 19:48:55 +03:00
|
|
|
}
|
2022-09-21 18:25:06 +03:00
|
|
|
}
|