feat: basic ksh
This commit is contained in:
+1
-1
@@ -1,3 +1,3 @@
|
|||||||
.cache
|
.cache
|
||||||
build
|
build*
|
||||||
.venv
|
.venv
|
||||||
@@ -51,7 +51,6 @@ target_link_options(kernel PRIVATE
|
|||||||
-static
|
-static
|
||||||
-no-pie
|
-no-pie
|
||||||
-T "${CMAKE_CURRENT_SOURCE_DIR}/linker.ld"
|
-T "${CMAKE_CURRENT_SOURCE_DIR}/linker.ld"
|
||||||
-Wl,-Map,"${CMAKE_BINARY_DIR}/kernel.map"
|
|
||||||
-z max-page-size=0x1000
|
-z max-page-size=0x1000
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,10 @@
|
|||||||
|
// SPDX-License-Identifier: GPL-3.0-or-later
|
||||||
|
// Copyright (c) 2025 0xKarinyash
|
||||||
|
|
||||||
|
#ifndef STRING_H
|
||||||
|
#define STRING_H
|
||||||
|
#include <types.h>
|
||||||
|
|
||||||
|
i32 strcmp(const char* s1, const char* s2);
|
||||||
|
|
||||||
|
#endif
|
||||||
@@ -7,6 +7,7 @@
|
|||||||
#include <drivers/shitgui.h>
|
#include <drivers/shitgui.h>
|
||||||
|
|
||||||
void console_init(SG_Context *ctx);
|
void console_init(SG_Context *ctx);
|
||||||
|
u64 console_get_colors();
|
||||||
void console_clear(u32 color);
|
void console_clear(u32 color);
|
||||||
SG_Context* console_get_context();
|
SG_Context* console_get_context();
|
||||||
SG_Point console_get_dimensions();
|
SG_Point console_get_dimensions();
|
||||||
|
|||||||
@@ -0,0 +1,8 @@
|
|||||||
|
// SPDX-License-Identifier: GPL-3.0-or-later
|
||||||
|
// Copyright (c) 2025 0xKarinyash
|
||||||
|
#ifndef KSH_H
|
||||||
|
#define KSH_H
|
||||||
|
|
||||||
|
void ksh();
|
||||||
|
|
||||||
|
#endif
|
||||||
@@ -0,0 +1,12 @@
|
|||||||
|
// SPDX-License-Identifier: GPL-3.0-or-later
|
||||||
|
// Copyright (c) 2025 0xKarinyash
|
||||||
|
|
||||||
|
#include <core/string.h>
|
||||||
|
|
||||||
|
i32 strcmp(const char* s1, const char* s2) {
|
||||||
|
while (*s1 && (*s1 == *s2)) {
|
||||||
|
s1++;
|
||||||
|
s2++;
|
||||||
|
}
|
||||||
|
return *(const unsigned char*)s1 - *(const unsigned char*)s2;
|
||||||
|
}
|
||||||
@@ -43,6 +43,10 @@ void console_init(SG_Context *ctx) {
|
|||||||
s_font.base = (const unsigned char*)font8x16;
|
s_font.base = (const unsigned char*)font8x16;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
u64 console_get_colors() {
|
||||||
|
return ((u64) s_color << 32) | s_bg_color;
|
||||||
|
}
|
||||||
|
|
||||||
void console_clear(u32 color) {
|
void console_clear(u32 color) {
|
||||||
if (!ctx_ptr) return;
|
if (!ctx_ptr) return;
|
||||||
|
|
||||||
|
|||||||
+5
-7
@@ -3,6 +3,7 @@
|
|||||||
|
|
||||||
#include "bootinfo.h"
|
#include "bootinfo.h"
|
||||||
#include "../data/logo.h"
|
#include "../data/logo.h"
|
||||||
|
#include "shell/ksh.h"
|
||||||
|
|
||||||
#include <types.h>
|
#include <types.h>
|
||||||
|
|
||||||
@@ -10,6 +11,8 @@
|
|||||||
#include <drivers/serial.h>
|
#include <drivers/serial.h>
|
||||||
#include <drivers/console.h>
|
#include <drivers/console.h>
|
||||||
|
|
||||||
|
#include <core/panic.h>
|
||||||
|
|
||||||
#include <gdt.h>
|
#include <gdt.h>
|
||||||
#include <idt.h>
|
#include <idt.h>
|
||||||
#include <pic.h>
|
#include <pic.h>
|
||||||
@@ -49,12 +52,7 @@ void kmain(Bootinfo* info) {
|
|||||||
SG_Point text_normal_point = {0, 120}; // not nice to hardcode nums like that but we have what we have
|
SG_Point text_normal_point = {0, 120}; // not nice to hardcode nums like that but we have what we have
|
||||||
console_set_cursor_pos(&text_normal_point);
|
console_set_cursor_pos(&text_normal_point);
|
||||||
|
|
||||||
kprintf("ksh_> ");
|
ksh();
|
||||||
char buff[32];
|
|
||||||
kgets(buff, 32);
|
|
||||||
kprintf("You typed: %s", buff);
|
|
||||||
|
|
||||||
__asm__ volatile ("sti");
|
panic("Kernel main loop exited");
|
||||||
|
|
||||||
while (1) { __asm__("hlt"); }
|
|
||||||
}
|
}
|
||||||
@@ -1,3 +1,58 @@
|
|||||||
// SPDX-License-Identifier: GPL-3.0-or-later
|
// SPDX-License-Identifier: GPL-3.0-or-later
|
||||||
// Copyright (c) 2025 0xKarinyash
|
// Copyright (c) 2025 0xKarinyash
|
||||||
|
#include <shell/ksh.h>
|
||||||
|
#include <drivers/console.h>
|
||||||
|
#include <core/string.h>
|
||||||
|
|
||||||
|
typedef enum {
|
||||||
|
TOKEN_NULL,
|
||||||
|
TOKEN_ILLEGAL,
|
||||||
|
|
||||||
|
TOKEN_HELP,
|
||||||
|
|
||||||
|
TOKEN_QUIT,
|
||||||
|
TOKEN_CLEAR
|
||||||
|
} ksh_token;
|
||||||
|
|
||||||
|
typedef struct {
|
||||||
|
char* str;
|
||||||
|
ksh_token token;
|
||||||
|
} ksh_command_map;
|
||||||
|
|
||||||
|
static const ksh_command_map token_map[] = {
|
||||||
|
{"q", TOKEN_QUIT},
|
||||||
|
{"quit", TOKEN_QUIT},
|
||||||
|
{"exit", TOKEN_QUIT},
|
||||||
|
|
||||||
|
{"cls", TOKEN_CLEAR},
|
||||||
|
{"clear", TOKEN_CLEAR},
|
||||||
|
|
||||||
|
{"help", TOKEN_HELP},
|
||||||
|
{nullptr, TOKEN_NULL}
|
||||||
|
};
|
||||||
|
|
||||||
|
ksh_token char2token(char* token) {
|
||||||
|
for (i32 i = 0; token_map[i].str != nullptr; i++) {
|
||||||
|
if (strcmp(token, token_map[i].str) == 0) return token_map[i].token;
|
||||||
|
}
|
||||||
|
return TOKEN_ILLEGAL;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void print_help() {
|
||||||
|
kprintf("\tWelcome to ^ptermOS^0's kernel shell!\n");
|
||||||
|
kprintf("\tIt can almost nothing! yet.");
|
||||||
|
}
|
||||||
|
|
||||||
|
void ksh() {
|
||||||
|
while (true) {
|
||||||
|
kprintf("\nksh_> ");
|
||||||
|
char cmdbuff[256];
|
||||||
|
kgets(cmdbuff, 256);
|
||||||
|
switch(char2token(cmdbuff)) {
|
||||||
|
case TOKEN_QUIT: return; // that'll cause panic lol
|
||||||
|
case TOKEN_CLEAR: console_clear((u32) console_get_colors() & 0xFFFFFFFF); break;
|
||||||
|
case TOKEN_HELP: print_help(); break;
|
||||||
|
default: kprintf("Unknown command!!"); break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user