feat: panic, printf, logo and something i dont remember
This commit is contained in:
+10
-5
@@ -4,22 +4,27 @@
|
||||
|
||||
#include "shitgui.h"
|
||||
#include "serial.h"
|
||||
#include "panic.h" // IWYU pragma: keep
|
||||
#include "../data/logo.h"
|
||||
|
||||
void kmain(Bootinfo* info) {
|
||||
u32 *fb = (u32*)info->base;
|
||||
u32 *fb = (u32*)info->framebuffer.base;
|
||||
if (!fb) return;
|
||||
|
||||
SG_Context sg_ctx = {0};
|
||||
sg_ctx.fb = fb;
|
||||
sg_ctx.height = info->height;
|
||||
sg_ctx.width = info->width;
|
||||
sg_ctx.pitch = info->pitch;
|
||||
sg_ctx.height = info->framebuffer.height;
|
||||
sg_ctx.width = info->framebuffer.width;
|
||||
sg_ctx.pitch = info->framebuffer.pitch;
|
||||
|
||||
serial_init();
|
||||
console_init(&sg_ctx);
|
||||
console_clear(0xFFFFFF);
|
||||
console_set_color(0x000000);
|
||||
kprint("Welcome to termOS!!!");
|
||||
SG_Point logo_point = {sg_ctx.width-100, 100};
|
||||
sg_put_img(&sg_ctx, &logo_point, &logo_img);
|
||||
kprint("Welcome to termOS!!!\n");
|
||||
kprintf("MemoryMap located at %x; \nMemory map size is %d", (u64)info->mem.map, (u64)info->mem.map_size);
|
||||
|
||||
while (1) { __asm__("hlt"); }
|
||||
}
|
||||
@@ -2,6 +2,10 @@
|
||||
#include "serial.h"
|
||||
#include "font.h"
|
||||
#include "shitgui.h"
|
||||
#include "math.h"
|
||||
#include "types.h"
|
||||
#include <stdarg.h>
|
||||
|
||||
|
||||
static SG_Context *ctx_ptr = nullptr;
|
||||
static SG_Point s_cursor_pos = {0};
|
||||
@@ -28,6 +32,12 @@ void console_clear(u32 color) {
|
||||
s_cursor_pos.y = 0;
|
||||
}
|
||||
|
||||
void console_set_cursor_pos(SG_Point *p) {
|
||||
if (!p) return;
|
||||
s_cursor_pos.x = p->x;
|
||||
s_cursor_pos.y = p->y;
|
||||
}
|
||||
|
||||
static void console_putc(char c) {
|
||||
serial_writec(c);
|
||||
if (!ctx_ptr) return;
|
||||
@@ -48,7 +58,91 @@ static void console_putc(char c) {
|
||||
|
||||
|
||||
void kprint(const char *str) {
|
||||
for (int i = 0; str[i] != '\0'; i++) console_putc(str[i]);
|
||||
for (i32 i = 0; str[i] != '\0'; i++) console_putc(str[i]);
|
||||
}
|
||||
|
||||
static void print_dec(const i64 n) {
|
||||
if (n < 0) console_putc('-');
|
||||
u64 u = abs(n);
|
||||
char buffer[32];
|
||||
i32 i = 0;
|
||||
|
||||
do {
|
||||
buffer[i] = (u % 10) + '0';
|
||||
u /= 10;
|
||||
i++;
|
||||
} while (u > 0);
|
||||
|
||||
while (--i >= 0) {
|
||||
console_putc(buffer[i]);
|
||||
}
|
||||
}
|
||||
|
||||
static void print_hex(u64 u) {
|
||||
console_putc('0');
|
||||
console_putc('x');
|
||||
|
||||
if (u == 0) {
|
||||
console_putc('0');
|
||||
return;
|
||||
}
|
||||
|
||||
char buffer[16];
|
||||
i32 i = 0;
|
||||
|
||||
while (u > 0) {
|
||||
i32 digit = u % 16;
|
||||
if (digit < 10) { buffer[i] = digit + '0'; }
|
||||
else { buffer[i] = digit - 10 + 'a'; }
|
||||
u /= 16;
|
||||
i++;
|
||||
}
|
||||
|
||||
while (--i >= 0) {
|
||||
console_putc(buffer[i]);
|
||||
}
|
||||
}
|
||||
|
||||
void kprintf(const char *fmt, ...) {
|
||||
va_list args;
|
||||
va_start(args, fmt);
|
||||
|
||||
for (i32 i = 0; fmt[i] != '\0'; i++) {
|
||||
if (fmt[i] == '%') {
|
||||
i++;
|
||||
switch (fmt[i]) {
|
||||
case 's': {
|
||||
const char *str = va_arg(args, const char*);
|
||||
if (!str) str = "undefined";
|
||||
kprint(str);
|
||||
break;
|
||||
}
|
||||
case 'c': {
|
||||
char c = (char)va_arg(args, int);
|
||||
console_putc(c);
|
||||
break;
|
||||
}
|
||||
case 'd': {
|
||||
i32 num = va_arg(args, i32);
|
||||
print_dec(num);
|
||||
break;
|
||||
}
|
||||
case 'x': {
|
||||
u64 num = va_arg(args, u64);
|
||||
print_hex(num);
|
||||
break;
|
||||
}
|
||||
default: {
|
||||
console_putc(fmt[i]);
|
||||
break;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
console_putc(fmt[i]);
|
||||
}
|
||||
}
|
||||
|
||||
va_end(args);
|
||||
}
|
||||
|
||||
void console_set_color(u32 color) {
|
||||
|
||||
@@ -0,0 +1,24 @@
|
||||
#include "panic.h"
|
||||
#include "console.h"
|
||||
#include "shitgui.h"
|
||||
|
||||
static void hlt_loop() {
|
||||
while (1) {
|
||||
__asm__ volatile ("cli; hlt");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
__attribute__((noreturn)) void panic(const char *msg) {
|
||||
console_clear(0xFF0000);
|
||||
console_set_color(0xFFFFFF);
|
||||
|
||||
kprintf("\n\n");
|
||||
kprintf(" KERNEL PANIC \n");
|
||||
kprintf("-------------------\n");
|
||||
kprintf(" Reason: %s\n", msg);
|
||||
kprintf("-------------------\n");
|
||||
kprintf(" System halted.\n");
|
||||
|
||||
hlt_loop();
|
||||
}
|
||||
@@ -1,5 +1,6 @@
|
||||
#include "shitgui.h"
|
||||
|
||||
#define SHITGUI_TRANSPARENCY_KEY 0xFF00FF
|
||||
|
||||
void sg_put_img(SG_Context *ctx, SG_Point *p, SG_Image *img) {
|
||||
if (!ctx->fb || !img) return;
|
||||
@@ -17,7 +18,8 @@ void sg_put_img(SG_Context *ctx, SG_Point *p, SG_Image *img) {
|
||||
volatile u32 *dest_ptr = &ctx->fb[(start_y + y) * ctx->pitch + start_x];
|
||||
u32 *src_ptr = &img->buffer[y * img->width];
|
||||
for (u32 x = 0; x < draw_w; x++) {
|
||||
dest_ptr[x] = src_ptr[x];
|
||||
u32 color = src_ptr[x];
|
||||
if (color != SHITGUI_TRANSPARENCY_KEY) dest_ptr[x] = color;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user