From 26c0353554989679c998498f28dc5345773ca86c Mon Sep 17 00:00:00 2001 From: Karina Date: Sat, 24 Jan 2026 19:26:12 +0400 Subject: [PATCH] feat: blinking cursor minor changes while trying to remember what i even wrote here after month break --- kernel/inc/drivers/console.h | 3 +++ kernel/inc/drivers/shitgui.h | 1 + kernel/src/core/panic.c | 24 +++++++++++++++++++----- kernel/src/drivers/console.c | 35 ++++++++++++++++++++++++++++++++++- kernel/src/drivers/shitgui.c | 5 +++++ kernel/src/mm/heap.c | 2 +- kernel/src/shell/builtins.c | 2 +- kernel/src/shell/ksh.c | 7 ++++++- 8 files changed, 70 insertions(+), 9 deletions(-) diff --git a/kernel/inc/drivers/console.h b/kernel/inc/drivers/console.h index 5a03b36..c02fa9c 100644 --- a/kernel/inc/drivers/console.h +++ b/kernel/inc/drivers/console.h @@ -16,3 +16,6 @@ char console_getc(); void kprint(const char *str); void kprintf(const char *fmt, ...); void kgets(char* buff, u32 lim); +void cursor_blink(); +void cursor_blinker_sched_task(); +void console_toggle_cursor_blink(); diff --git a/kernel/inc/drivers/shitgui.h b/kernel/inc/drivers/shitgui.h index 36a749c..c5e754d 100644 --- a/kernel/inc/drivers/shitgui.h +++ b/kernel/inc/drivers/shitgui.h @@ -33,6 +33,7 @@ typedef struct { } SG_Window; void sg_init(SG_Context *ctx); +u32 sg_get_pixel(SG_Context *ctx, SG_Point *p); void sg_put_img(SG_Context *ctx, SG_Point *p, SG_Image *img); void sg_draw_rect(SG_Context *ctx, SG_Point *p, u32 w, u32 h, u32 color); void sg_draw_char_bitmap(SG_Context *ctx, SG_Point *p, char c, u32 color, SG_Font *font); diff --git a/kernel/src/core/panic.c b/kernel/src/core/panic.c index 4e19bae..759f4e6 100644 --- a/kernel/src/core/panic.c +++ b/kernel/src/core/panic.c @@ -101,12 +101,12 @@ void draw_panic_bg() { console_set_color(0xFFFFFF); console_set_default_color(0xFFFFFF); - SG_Point p = console_get_dimensions(); - p.x /= 2; - p.y /= 2; - p.y -= 200; + // SG_Point p = console_get_dimensions(); + // p.x /= 2; + // p.y /= 2; + // p.y -= 200; - console_set_cursor_pos(&p); + // console_set_cursor_pos(&p); u64 msg_count = sizeof(fun_messages) / sizeof(fun_messages[0]); u8 rand_num = shitrand() % msg_count; @@ -128,9 +128,23 @@ __attribute__((noreturn)) void panic_exception(Registers *regs) { kprintf("\t\t^yFlags^! (^yRFLAGS^!): %X\n", regs->rflags); kprintf("\t\t^yStack Pointer^! (^yRSP^!): %X\n", regs->rsp); if (regs->int_no == 14) { + kprintf("\t\t--------------------------------\n"); + kprintf("\t\t ^yPage Fault Helper^! \n"); + kprintf("\t\t--------------------------------\n"); u64 cr2; __asm__ volatile("mov %%cr2, %0" : "=r"(cr2)); kprintf("\t\t^yFaulting Address^! (^yCR2^!): %X\n", cr2); + kprintf("\t\t^yERRCode^!: %X\n", regs->err_code); + u64 present = (regs->err_code & (1 << 0)) != 0; + u64 write = (regs->err_code & (1 << 1)) != 0; + u64 user = (regs->err_code & (1 << 2)) != 0; + u64 reserved = (regs->err_code & (1 << 3)) != 0; + u64 instruction = (regs->err_code & (1 << 4)) != 0; + kprintf("\t\t\t[^bP^!] ^yReason^! %s\n", present ? "Page Protection violation" : "Non-present page"); + kprintf("\t\t\t[^bW^!] ^yCaused by^! %s\n", write ? "WRITE" : "READ"); + kprintf("\t\t\t[^bU^!] ^yRing^! %s\n", user ? "3" : "0"); + if (reserved) kprintf("\t\t\t[^bR^!] CPU Wrote 1 to a reserved field in page table entry. ^rCorrupt page table?^!\n"); + if (instruction) kprintf("\t\t\t[^bI^!] ^yTried to^! execute ^ycode from^! NX ^ymemory^!\n"); } kprintf("\t\t--------------------------------\n"); kprintf("\t\t\t\t^yREGISTERS^!\n"); diff --git a/kernel/src/drivers/console.c b/kernel/src/drivers/console.c index 5233e5d..d11b9ab 100644 --- a/kernel/src/drivers/console.c +++ b/kernel/src/drivers/console.c @@ -1,6 +1,7 @@ // SPDX-License-Identifier: GPL-3.0-or-later // Copyright (c) 2025 0xKarinyash +#include "core/scheduler.h" #include #include #include @@ -33,6 +34,9 @@ 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; +static bool s_are_we_blinkin = true; +static bool s_waiting_for_input = false; +static bool s_cursor_visible = false; void console_init(SG_Context *ctx) { ctx_ptr = ctx; @@ -235,11 +239,17 @@ void console_set_default_color(u32 color) { } char console_getc() { - while (kb_buf.head == kb_buf.tail) __asm__ volatile ("sti; hlt"); + s_waiting_for_input = true; + while (kb_buf.head == kb_buf.tail) { __asm__ volatile ("sti"); yield(1); } __asm__ volatile ("cli"); + s_waiting_for_input = false; char temp = kb_buf.buffer[kb_buf.tail]; kb_buf.tail = (kb_buf.tail + 1) % KB_BUFF_SIZE; __asm__ volatile ("sti"); + if (s_cursor_visible) { + cursor_blink(); + s_cursor_visible = false; + } return temp; } @@ -270,3 +280,26 @@ void kgets(char* buff, u32 lim) { } } } + +void cursor_blink() { + sg_draw_rect(ctx_ptr, &s_cursor_pos, s_font.w, s_font.h, sg_get_pixel(ctx_ptr, &s_cursor_pos) ^ 0xFFFFFF); +} + +void cursor_blinker_sched_task() { + while (true) { + if (s_are_we_blinkin) { + if (s_waiting_for_input) { + cursor_blink(); + s_cursor_visible = !s_cursor_visible; + } + } else if (s_cursor_visible) { + cursor_blink(); + s_cursor_visible = !s_cursor_visible; + } + yield(500); + } +} + +void console_toggle_cursor_blink() { + s_are_we_blinkin = !s_are_we_blinkin; +} \ No newline at end of file diff --git a/kernel/src/drivers/shitgui.c b/kernel/src/drivers/shitgui.c index 9068277..e3bf7f9 100644 --- a/kernel/src/drivers/shitgui.c +++ b/kernel/src/drivers/shitgui.c @@ -18,6 +18,11 @@ void sg_init(SG_Context *ctx) { main_context = ctx; } +u32 sg_get_pixel(SG_Context *ctx, SG_Point *p) { + if (!ctx->fb || !p || p->x >= ctx->width || p->y >= ctx->height) return 0; + return ctx->fb[p->y * ctx->pitch + p->x]; +} + void sg_put_img(SG_Context *ctx, SG_Point *p, SG_Image *img) { if (!ctx->fb || !img) return; diff --git a/kernel/src/mm/heap.c b/kernel/src/mm/heap.c index 02319ad..32f1c84 100644 --- a/kernel/src/mm/heap.c +++ b/kernel/src/mm/heap.c @@ -90,7 +90,7 @@ void* realloc(void* ptr, u64 new_size) { if (curr->next && curr->next->is_free && - (curr->size + sizeof(block_header) + curr->next->size) >= new_size) { // why ts shit so fucking unreadable + (curr->size + sizeof(block_header) + curr->next->size) >= new_size) { // why ts so fucking unreadable combine_forward(curr); return ptr; } diff --git a/kernel/src/shell/builtins.c b/kernel/src/shell/builtins.c index b230a1e..077c220 100644 --- a/kernel/src/shell/builtins.c +++ b/kernel/src/shell/builtins.c @@ -81,4 +81,4 @@ void cmd_debug() { u64 status = debug(); kprintf("\nDebug ended with code %d\n", status); return; -} \ No newline at end of file +} diff --git a/kernel/src/shell/ksh.c b/kernel/src/shell/ksh.c index d381e2c..eda1f73 100644 --- a/kernel/src/shell/ksh.c +++ b/kernel/src/shell/ksh.c @@ -7,6 +7,7 @@ #include #include +#include #include #include #include @@ -33,7 +34,8 @@ typedef enum { TOKEN_PANIC_UD2, TOKEN_PANIC_PF, - TOKEN_CLEAR + TOKEN_CLEAR, + TOKEN_BLINKING } ksh_token; typedef struct { @@ -46,6 +48,7 @@ static const ksh_command_map token_map[] = { {"cls", TOKEN_CLEAR}, {"clear", TOKEN_CLEAR}, + {"blinking", TOKEN_BLINKING}, {"meow", TOKEN_MEOW}, {"nya", TOKEN_MEOW}, @@ -75,6 +78,7 @@ ksh_token char2token(char* token) { } void ksh() { + sched_spawn(cursor_blinker_sched_task); while (true) { kprintf("ksh_> "); char cmdbuff[256]; @@ -95,6 +99,7 @@ void ksh() { case TOKEN_HELP: cmd_help(); break; case TOKEN_KFETCH: cmd_kfetch(); break; case TOKEN_MEOW: cmd_meow(); break; + case TOKEN_BLINKING: console_toggle_cursor_blink(); break; default: kprintf("Unknown command!!\n"); break; }