reboot syscall and shell cmd using ps2 controller

This commit is contained in:
rami 2024-07-29 19:43:44 -04:00
parent 352d51f610
commit cf1d99fb79
6 changed files with 30 additions and 8 deletions

Binary file not shown.

View File

@ -5,6 +5,8 @@
#define PS2_8042_STATUS 0x64 #define PS2_8042_STATUS 0x64
#define PS2_8042_COMMAND 0x64 #define PS2_8042_COMMAND 0x64
#define ps2_reboot outb(0x64, 0xFE)
// SCANCODES // SCANCODES
#define KBD_ESC 0x01 #define KBD_ESC 0x01
#define KBD_1 0x02 #define KBD_1 0x02

View File

@ -279,10 +279,12 @@ boot_page_tab: times 1024 dd 0
extern syscall_read extern syscall_read
extern syscall_write extern syscall_write
extern syscall_reboot
global syscall_table global syscall_table
syscall_table: syscall_table:
dd syscall_read dd syscall_read
dd syscall_write dd syscall_write
dd syscall_reboot
section .bss section .bss
align 16 align 16

View File

@ -44,6 +44,7 @@ void syscall_read(stack_frame_t r) {
if (fd == FD_STDOUT) { if (fd == FD_STDOUT) {
// Not yet // Not yet
} else if (fd == FD_STDIN) { } else if (fd == FD_STDIN) {
// for some reason interrupts are disabled
asm volatile ("sti" ::); asm volatile ("sti" ::);
while (ctx.current_task->stdin[ctx.current_task->stdin_len - 1] != '\n') cpu_relax; while (ctx.current_task->stdin[ctx.current_task->stdin_len - 1] != '\n') cpu_relax;
if (ctx.current_task->stdin_len > 0) ctx.current_task->stdin[--ctx.current_task->stdin_len] = 0; if (ctx.current_task->stdin_len > 0) ctx.current_task->stdin[--ctx.current_task->stdin_len] = 0;
@ -53,6 +54,11 @@ void syscall_read(stack_frame_t r) {
} }
} }
void syscall_reboot(stack_frame_t r) {
(void)r;
ps2_reboot;
}
void syscall_uptime(stack_frame_t r) { void syscall_uptime(stack_frame_t r) {
uint64_t *buf = (uint64_t *)r.esi; uint64_t *buf = (uint64_t *)r.esi;
*buf = ctx.ticks; *buf = ctx.ticks;
@ -191,7 +197,6 @@ void kernel(multiboot_info_t *info) {
: "eax", "ecx", "edx" : "eax", "ecx", "edx"
); );
LOG("Switching to ring 3... EIP: 0x%08X ESP: 0x%08X\n", task.eip, task.esp); LOG("Switching to ring 3... EIP: 0x%08X ESP: 0x%08X\n", task.eip, task.esp);
jmp_user_mode(task.esp, task.eip); jmp_user_mode(task.esp, task.eip);

View File

@ -26,6 +26,6 @@ void pic_remap(int pic1_start, int pic2_start) {
outb(PIC_2_DATA, 0x01); outb(PIC_2_DATA, 0x01);
// Unmask // Unmask
outb(PIC_1_DATA, 0b11111101); outb(PIC_1_DATA, 0b11111100);
outb(PIC_2_DATA, 0b11111101); outb(PIC_2_DATA, 0b11111100);
} }

View File

@ -22,6 +22,16 @@ void read(int fd, void *buf, int size) {
); );
} }
void reboot() {
asm volatile (
"movl $2, %%eax\n\t"
"int $0x80"
:
:
: "eax"
);
}
extern char *buf; extern char *buf;
void _start() { void _start() {
@ -30,10 +40,13 @@ void _start() {
while (1) { while (1) {
puts("> "); puts("> ");
read(0, buf1, 256); read(0, buf1, 256);
if (!strcmp(buf1, "SKIBIDI")) { if (!strcmp(buf1, "SKIBIDI")) {
puts("dop dop yes yes!\n"); puts("dop dop yes yes!\n");
} else { } else if (!strcmp(buf1, "REBOOT")) {
puts("unknown command!\n"); reboot();
} }
else {
puts("unknown command!\n");
}
} }
} }