minor refactor; cats in ksh

This commit is contained in:
Karina
2025-12-28 07:36:04 +04:00
parent 0cf509856e
commit 894c513609
14 changed files with 211 additions and 95 deletions
+4
View File
@@ -4,10 +4,14 @@
#include <io.h>
#include <core/panic.h>
#include <drivers/keyboard.h>
#include <shell/builtins.h>
#include <types.h>
void isr_handler_c(Registers *regs) {
if (regs->int_no == 3) {
return print_regs();
}
panic_exception(regs);
}
+23 -22
View File
@@ -97,8 +97,9 @@ __attribute__((noreturn)) void die() {
}
void draw_panic_bg() {
console_clear(0x101010);
console_clear(0x000000);
console_set_color(0xFFFFFF);
console_set_default_color(0xFFFFFF);
SG_Point p = console_get_dimensions();
p.x /= 2;
@@ -111,39 +112,39 @@ void draw_panic_bg() {
u8 rand_num = shitrand() % msg_count;
kprintf("\n\n");
kprintf("\t\t\t\t^tKERNEL PANIC^w :( \n");
kprintf("\t\t\t\t^tKERNEL PANIC^! :( \n");
kprintf("\t\t--------------------------------\n");
kprintf("\t\t\t\t^r%s^w\n", fun_messages[rand_num]);
kprintf("\t\t\t\t^r%s^!\n", fun_messages[rand_num]);
kprintf("\t\t--------------------------------\n");
}
__attribute__((noreturn)) void panic_exception(Registers *regs) {
draw_panic_bg();
kprintf("\t\t^yCPU EXCEPTION^w: ^m%s^w (%d)\n", exception_messages[regs->int_no], regs->int_no);
if (regs->err_code) kprintf("\t\t^yError Code^w: %X\n", regs->err_code);
kprintf("\t\t^yInstruction Pointer^w (^yRIP^w): %X\n", regs->rip);
kprintf("\t\t^yCode Segment^w (^yCS^w): %X\n", regs->cs);
kprintf("\t\t^yFlags^w (^yRFLAGS^w): %X\n", regs->rflags);
kprintf("\t\t^yStack Pointer^w (^yRSP^w): %X\n", regs->rsp);
kprintf("\t\t^yCPU EXCEPTION^!: ^m%s^! (%d)\n", exception_messages[regs->int_no], regs->int_no);
if (regs->err_code) kprintf("\t\t^yError Code^!: %X\n", regs->err_code);
kprintf("\t\t^yInstruction Pointer^! (^yRIP^!): %X\n", regs->rip);
kprintf("\t\t^yCode Segment^! (^yCS^!): %X\n", regs->cs);
kprintf("\t\t^yFlags^! (^yRFLAGS^!): %X\n", regs->rflags);
kprintf("\t\t^yStack Pointer^! (^yRSP^!): %X\n", regs->rsp);
if (regs->int_no == 14) {
u64 cr2;
__asm__ volatile("mov %%cr2, %0" : "=r"(cr2));
kprintf("\t\t^yFaulting Address^w (^yCR2^w): %X\n", cr2);
kprintf("\t\t^yFaulting Address^! (^yCR2^!): %X\n", cr2);
}
kprintf("\t\t--------------------------------\n");
kprintf("\t\t\t\t^yREGSISTERS^w\n");
kprintf("\t\t\t\t^yREGSISTERS^!\n");
kprintf("\t\t--------------------------------\n");
kprintf("\t\t^yRAX^w=%X, ^yRBX^w=%X\n", regs->rax, regs->rbx);
kprintf("\t\t^yRCX^w=%X, ^yRDX^w=%X\n", regs->rcx, regs->rdx);
kprintf("\t\t^yRSI^w=%X, ^yRDI^w=%X\n", regs->rsi, regs->rdi);
kprintf("\t\t^yRBP^w=%X, ^yR8^w =%X\n", regs->rbp, regs->r8);
kprintf("\t\t^yR9^w =%X, ^yR10^w=%X \n", regs->r9, regs->r10);
kprintf("\t\t^yR11^w=%X, ^yR12^w=%X\n", regs->r11, regs->r12);
kprintf("\t\t^yR13^w=%X, ^yR14^w=%X\n", regs->r13, regs->r14);
kprintf("\t\t^yR15^w=%X\n",regs->r15);
kprintf("\t\t^yRAX^!=%X, ^yRBX^!=%X\n", regs->rax, regs->rbx);
kprintf("\t\t^yRCX^!=%X, ^yRDX^!=%X\n", regs->rcx, regs->rdx);
kprintf("\t\t^yRSI^!=%X, ^yRDI^!=%X\n", regs->rsi, regs->rdi);
kprintf("\t\t^yRBP^!=%X, ^yR8^! =%X\n", regs->rbp, regs->r8);
kprintf("\t\t^yR9^! =%X, ^yR10^!=%X \n", regs->r9, regs->r10);
kprintf("\t\t^yR11^!=%X, ^yR12^!=%X\n", regs->r11, regs->r12);
kprintf("\t\t^yR13^!=%X, ^yR14^!=%X\n", regs->r13, regs->r14);
kprintf("\t\t^yR15^!=%X\n",regs->r15);
kprintf("\t\t--------------------------------\n");
kprintf("\t\t\t\t^tSystem halted.^w\n");
kprintf("\t\t\t\t^tSystem halted.^!\n");
die();
}
@@ -151,9 +152,9 @@ __attribute__((noreturn)) void panic_exception(Registers *regs) {
__attribute__((noreturn)) void panic(const char* msg) {
draw_panic_bg();
kprintf("\t\t^yReason^w: %s\n", msg);
kprintf("\t\t^yReason^!: %s\n", msg);
kprintf("\t\t--------------------------------\n");
kprintf("\t\t\t\t^tSystem halted.^w\n");
kprintf("\t\t\t\t^tSystem halted.^!\n");
die();
}
+16
View File
@@ -0,0 +1,16 @@
// SPDX-License-Identifier: GPL-3.0-or-later
// Copyright (c) 2025 0xKarinyash
#include <drivers/shitgui.h>
#include <drivers/console.h>
#include "../data/logo.h"
void show_splash(SG_Context *sg_ctx) {
SG_Point logo_point = {0, 10};
sg_put_img(sg_ctx, &logo_point, &logo_img);
SG_Point start_pos = {75, 55}; // greeting
console_set_cursor_pos(&start_pos);
kprintf("Welcome to ^ptermOS^!!!!\n");
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);
}
+7
View File
@@ -31,6 +31,7 @@ static SG_Context *ctx_ptr = nullptr;
static SG_Point s_cursor_pos = {0};
static SG_Font s_font = {0};
static u32 s_color = COLOR_WHITE;
static u32 s_def_color = COLOR_WHITE;
static u32 s_bg_color = COLOR_BLACK;
void console_init(SG_Context *ctx) {
@@ -205,6 +206,8 @@ void kprintf(const char *fmt, ...) {
case 'p': console_set_color(COLOR_PINK); break;
case '0': console_set_color(COLOR_BLACK); break;
case 'w': console_set_color(COLOR_WHITE); break;
case '!': console_set_color(s_def_color); break;
case '~': console_set_color(~s_bg_color); break;
case '^': console_putc('^'); break;
default: {
console_putc('^');
@@ -224,6 +227,10 @@ void console_set_color(u32 color) {
s_color = color;
}
void console_set_default_color(u32 color) {
s_def_color = color;
}
static char console_getc() {
while (kb_buf.head == kb_buf.tail) __asm__ volatile ("sti; hlt");
__asm__ volatile ("cli");
+10 -17
View File
@@ -2,8 +2,7 @@
// Copyright (c) 2025 0xKarinyash
#include "bootinfo.h"
#include "../data/logo.h"
#include "shell/ksh.h"
#include <shell/ksh.h>
#include <types.h>
@@ -12,6 +11,7 @@
#include <drivers/console.h>
#include <core/panic.h>
#include <core/splash.h>
#include <gdt.h>
#include <idt.h>
@@ -19,19 +19,11 @@
#include <mm/pmm.h>
#include <mm/vmm.h>
#define FG_COLOR 0xffffff
#define BG_COLOR 0x111111
extern u64 _kernel_end;
void greet(SG_Context *sg_ctx) {
SG_Point logo_point = {0, 10};
sg_put_img(sg_ctx, &logo_point, &logo_img);
SG_Point start_pos = {75, 55}; // greeting
console_set_cursor_pos(&start_pos);
kprintf("Welcome to ^ptermOS^0!!!\n");
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);
}
void kmain(Bootinfo* info) {
u32 *fb = (u32*)info->framebuffer.base;
if (!fb) return;
@@ -44,8 +36,9 @@ void kmain(Bootinfo* info) {
serial_init();
console_init(&sg_ctx);
console_clear(0xFFFFFF);
console_set_color(0x000000);
console_clear(BG_COLOR);
console_set_color(FG_COLOR);
console_set_default_color(FG_COLOR);
gdt_init();
idt_init();
@@ -53,9 +46,9 @@ void kmain(Bootinfo* info) {
pmm_init(info->mem);
vmm_init(info);
greet(&sg_ctx);
show_splash(&sg_ctx);
ksh();
ksh(&sg_ctx);
panic("Kernel main loop exited");
}
+63
View File
@@ -0,0 +1,63 @@
// SPDX-License-Identifier: GPL-3.0-or-later
// Copyright (c) 2025 0xKarinyash
#include <drivers/console.h>
#include <core/rand.h>
#include "../data/cats.h"
#include "types.h"
const char* ascii_logo[] = {
" /\\___/\\ ",
" | > < | ",
" | w | ",
" |=======|__ ",
" | | | ",
" |TERMOS | | ",
" | |__| ",
" |_______| "
};
void cmd_kfetch() {
kprintf("\n\n");
kprintf("^p %s ^0\t\t^g kernel^0@^gtermos\n^0", ascii_logo[0]);
kprintf("^p %s ^0\t\t^0-------------\n^0", ascii_logo[1]);
kprintf("^p %s ^0\t\t^gOS^0: termOS 0.0.1\n^0", ascii_logo[2]);
kprintf("^p %s ^0\t\t^gKernel^0: sucks\n^0", ascii_logo[3]);
kprintf("^p %s ^0\t\t^gUptime^0: 0h 0m\n^0", ascii_logo[4]);
kprintf("^p %s ^0\t\t^gShell^0: termosh\n^0", ascii_logo[5]);
kprintf("^p %s ^p\t\t^gDE^0: shitgui\n^0", ascii_logo[6]);
kprintf("^p %s ^p\t\t^gCPU^0: %s\n^0", ascii_logo[7], "cool one");
kprintf("\n\n");
}
void cmd_meow() {
u64 cats_count = sizeof(cats) / sizeof(cats[0]);
u8 rand_num = shitrand() % cats_count;
kprintf("Nyaaa!!\n\n%s\n\n", cats[rand_num]);
}
void cmd_help() {
kprintf("\tWelcome to ^ptermOS^!'s kernel shell!\n");
kprintf("\tIt can almost nothing! yet.\n");
}
void cmd_regs() {
__asm__ volatile ("int3");
}
void print_regs(Registers *regs) {
kprintf("--------------------------------\n");
kprintf("\t\t^gREGISTERS^!\n");
kprintf("--------------------------------\n");
kprintf("^gRAX^!=%X, ^gRBX^!=%X\n", regs->rax, regs->rbx);
kprintf("^gRCX^!=%X, ^gRDX^!=%X\n", regs->rcx, regs->rdx);
kprintf("^gRSI^!=%X, ^gRDI^!=%X\n", regs->rsi, regs->rdi);
kprintf("^gRBP^!=%X, ^gR8^! =%X\n", regs->rbp, regs->r8);
kprintf("^gR9^! =%X, ^gR10^!=%X \n", regs->r9, regs->r10);
kprintf("^gR11^!=%X, ^gR12^!=%X\n", regs->r11, regs->r12);
kprintf("^gR13^!=%X, ^gR14^!=%X\n", regs->r13, regs->r14);
kprintf("^gR15^!=%X\n",regs->r15);
kprintf("--------------------------------\n");
}
-35
View File
@@ -1,35 +0,0 @@
// SPDX-License-Identifier: GPL-3.0-or-later
// Copyright (c) 2025 0xKarinyash
// yes. *fetch in kernel
// WHY FUCKING NOT?? its my OS, my rules
#include <drivers/console.h>
const char* ascii_logo[] = {
" /\\___/\\ ",
" | > < | ",
" | w | ",
" |=======|__ ",
" | | | ",
" |TERMOS | | ",
" | |__| ",
" |_______| "
};
void kfetch() {
char cpu_brand[49];
//cpu_get_brand_string(cpu_brand);
kprintf("\n\n");
kprintf("^p %s ^0\t\t^g kernel^0@^gtermos\n^0", ascii_logo[0]);
kprintf("^p %s ^0\t\t^0-------------\n^0", ascii_logo[1]);
kprintf("^p %s ^0\t\t^gOS^0: termOS 0.0.1\n^0", ascii_logo[2]);
kprintf("^p %s ^0\t\t^gKernel^0: sucks\n^0", ascii_logo[3]);
kprintf("^p %s ^0\t\t^gUptime^0: 0h 0m\n^0", ascii_logo[4]);
kprintf("^p %s ^0\t\t^gShell^0: termosh\n^0", ascii_logo[5]);
kprintf("^p %s ^p\t\t^gDE^0: shitgui\n^0", ascii_logo[6]);
kprintf("^p %s ^p\t\t^gCPU^0: %s\n^0", ascii_logo[7], cpu_brand);
kprintf("\n\n");
}
+23 -11
View File
@@ -1,10 +1,16 @@
// SPDX-License-Identifier: GPL-3.0-or-later
// Copyright (c) 2025 0xKarinyash
#include "core/panic.h"
#include <shell/ksh.h>
#include <shell/kfetch.h>
#include <shell/builtins.h>
#include <drivers/console.h>
#include <drivers/shitgui.h>
#include <core/string.h>
#include <core/rand.h>
#include <core/splash.h>
#include <core/panic.h>
typedef enum {
TOKEN_EMPTY,
@@ -13,9 +19,12 @@ typedef enum {
TOKEN_ILLEGAL,
TOKEN_HELP,
TOKEN_SPLASH,
TOKEN_KFETCH,
TOKEN_MEOW,
TOKEN_REGS,
TOKEN_PANIC,
TOKEN_PANIC_UD2,
TOKEN_PANIC_PF,
@@ -37,11 +46,15 @@ static const ksh_command_map token_map[] = {
{"cls", TOKEN_CLEAR},
{"clear", TOKEN_CLEAR},
{"meow", TOKEN_MEOW},
{"nya", TOKEN_MEOW},
{"splash", TOKEN_SPLASH},
{"kfetch", TOKEN_KFETCH},
{"fastfetch", TOKEN_KFETCH},
{"neofetch", TOKEN_KFETCH},
{"regs", TOKEN_REGS},
{"panic", TOKEN_PANIC},
{"ud2", TOKEN_PANIC_UD2},
{"pf", TOKEN_PANIC_PF},
@@ -57,12 +70,7 @@ ksh_token char2token(char* token) {
return TOKEN_ILLEGAL;
}
static void print_help() {
kprintf("\tWelcome to ^ptermOS^0's kernel shell!\n");
kprintf("\tIt can almost nothing! yet.\n");
}
void ksh() {
void ksh(SG_Context* sg_ctx) {
while (true) {
kprintf("ksh_> ");
char cmdbuff[256];
@@ -71,13 +79,17 @@ void ksh() {
case TOKEN_EMPTY: continue;
case TOKEN_QUIT: return; // that'll cause panic lol
case TOKEN_REGS: cmd_regs(); break;
case TOKEN_PANIC: panic("Manually initiated panic");
case TOKEN_PANIC_UD2: __asm__ volatile ("ud2");
case TOKEN_PANIC_PF: u64* bad_ptr = (u64*)0xDEADBEEF; *bad_ptr = 666;
case TOKEN_SPLASH: show_splash(sg_ctx); break;
case TOKEN_CLEAR: console_clear((u32) console_get_colors() & 0xFFFFFFFF); break;
case TOKEN_HELP: print_help(); break;
case TOKEN_KFETCH: kfetch(); break;
case TOKEN_HELP: cmd_help(); break;
case TOKEN_KFETCH: cmd_kfetch(); break;
case TOKEN_MEOW: cmd_meow(); break;
default: kprintf("Unknown command!!\n"); break;
}