From ede53ae4f99112627c356a419ab48c070d37db4e Mon Sep 17 00:00:00 2001 From: Mathieu Maret Date: Mon, 25 Jan 2021 14:00:06 +0100 Subject: [PATCH] VGA renaming --- arch/x86/exception_handler.c | 4 ++-- arch/x86/irq_handler.c | 2 +- core/alloc.c | 4 ++-- core/klibc.c | 3 +-- core/main.c | 11 +++++++++-- drivers/vga.c | 22 +++++++++++++--------- drivers/vga.h | 12 ++++-------- 7 files changed, 32 insertions(+), 26 deletions(-) diff --git a/arch/x86/exception_handler.c b/arch/x86/exception_handler.c index 0414fcd..7cb9040 100644 --- a/arch/x86/exception_handler.c +++ b/arch/x86/exception_handler.c @@ -11,7 +11,7 @@ ulong error_code) \ { \ int intNbInt = int_nb; \ - VGAprintf(RED, BLACK, 0, VGA_HEIGHT - 1, "EXCEPTION %d %d", intNbInt, error_code); \ + VGAPrintf(RED, BLACK, 0, VGA_HEIGHT - 1, "EXCEPTION %d %d", intNbInt, error_code); \ printf("Exception %d (Err %d) at 0x%x\n", int_nb, error_code, frame->eip); \ asm("hlt"); \ } @@ -62,7 +62,7 @@ __attribute__((interrupt)) void pagefault_handler(struct interrupt_frame *frame, struct kthread *current = getCurrentThread(); printf("page fault while in thread %s\n", current->name); - VGAprintf(RED, BLACK, 0, VGA_HEIGHT - 1, "PAGE FAULT %d", error_code); + VGAPrintf(RED, BLACK, 0, VGA_HEIGHT - 1, "PAGE FAULT %d", error_code); (void)faulting_address; (void)frame; (void)error_code; diff --git a/arch/x86/irq_handler.c b/arch/x86/irq_handler.c index ca8c0b4..77b9a41 100644 --- a/arch/x86/irq_handler.c +++ b/arch/x86/irq_handler.c @@ -18,7 +18,7 @@ __attribute__((interrupt)) void timer_handler(struct interrupt_frame *frame) { static int timeCnt = 0; EOIIrq(IRQ_TIMER); - VGAprintf(RED, BLACK, 20, VGA_HEIGHT - 1, "IRQ %d", timeCnt++); + VGAPrintf(RED, BLACK, 20, VGA_HEIGHT - 1, "IRQ %d", timeCnt++); (void)frame; } diff --git a/core/alloc.c b/core/alloc.c index 3d3410c..91442ef 100644 --- a/core/alloc.c +++ b/core/alloc.c @@ -98,7 +98,7 @@ int allocSlab(struct slabDesc **desc, size_t size, size_t sizeSlab, int selfCont pr_devel("%s for size %d is self %d\n", __func__, size, selfContained); sizeSlab = MAX(sizeSlab, PAGE_SIZE); if (size > sizeSlab) { - pr_devel("%s size of element %d are bigger than slab size %d\n", size, sizeSlab); + pr_devel("size of element %d are bigger than slab size %d\n", size, sizeSlab); return -ENOENT; } @@ -141,7 +141,7 @@ int allocSlabEntry(struct slabEntry **desc, size_t size, size_t sizeSlab, int se pr_devel("%s for size %d is self %d\n", __func__, size, selfContained); sizeSlab = MAX(sizeSlab, PAGE_SIZE); if (size > sizeSlab) { - pr_devel("%s size of element %d are bigger than slab size %d\n", size, sizeSlab); + pr_devel("size of element %d are bigger than slab size %d\n", size, sizeSlab); return -ENOENT; } diff --git a/core/klibc.c b/core/klibc.c index ac17d73..1a928e2 100644 --- a/core/klibc.c +++ b/core/klibc.c @@ -152,7 +152,7 @@ int puts(const char *str) int putc(const char c) { - VGAputc(c); + VGAPutc(c); serialPutc(c); return (unsigned char)c; } @@ -404,7 +404,6 @@ int vasprintf(char **strp, const char *fmt, va_list ap) /* Determine required size */ n = vsnprintf(p, size, fmt, ap); - printf("Found length %d\n", n); if (n < 0) return -1; diff --git a/core/main.c b/core/main.c index 4974925..c83d8b0 100644 --- a/core/main.c +++ b/core/main.c @@ -27,7 +27,7 @@ void idleThread(void *arg) { (void)arg; while (1) { - VGAprintf(GREEN, BLACK, 0, VGA_HEIGHT - 1, "%d", (jiffies / HZ)); + VGAPrintf(GREEN, BLACK, 0, VGA_HEIGHT - 1, "%d", (jiffies / HZ)); kthreadYield(); } } @@ -42,7 +42,6 @@ void kmain(unsigned long magic, unsigned long addr) paddr_t lastUsedByMem; VGASetup(BLACK, GREEN); - cursorEnable(14, 15); printf("Setting up Interruptions\n"); gdtSetup(); @@ -97,7 +96,9 @@ void kmain(unsigned long magic, unsigned long addr) multiboot_info_t *mbi = (multiboot_info_t *)addr; struct multiboot_mmap_entry *mmap = (struct multiboot_mmap_entry *)mbi->mmap_addr; uint size = mbi->mmap_length / sizeof(struct multiboot_mmap_entry); + pr_devel("mmap buffer at 0x%x with %d entries\n", mbi->mmap_addr, size); + for (uint i = 0; i < size; i++) { printf(" base_addr 0x%llx, length = 0x%llx, type = 0x%x\n", mmap[i].addr, mmap[i].len, (uint32_t)mmap[i].type); @@ -109,6 +110,7 @@ void kmain(unsigned long magic, unsigned long addr) memAddBank(0, lastUsedByMem, 0); memAddBank(lastUsedByMem, upperMemKB * 1024, 1); } + #ifdef RUN_TEST testPhymem(); #endif @@ -125,9 +127,14 @@ void kmain(unsigned long magic, unsigned long addr) printf("Setting up Serial link (115200)\n"); serialSetup(115200); + + printf("Setting up allocation system\n"); allocSetup(); + + printf("Setting up thread system\n"); kthreadSetup(_stack_bottom, (_stack_top - _stack_bottom + 1)); kthreadCreate("idle ", idleThread, NULL); + irqSetRoutine(IRQ_TIMER, pit_handler); #ifdef RUN_TEST run_test(); diff --git a/drivers/vga.c b/drivers/vga.c index 6cd950d..8953273 100644 --- a/drivers/vga.c +++ b/drivers/vga.c @@ -9,6 +9,9 @@ static int line, col; static volatile short *vga = (short *)VGA_ADDR; static void clearScreen(uint bgColor); +static void cursorMove(int x, int y); +static void cursorEnable(uint8_t cursor_start, uint8_t cursor_end); +static void printCharDetails(char str, uint color, uint bgColor, int startX, int startY); int VGASetup(uint bgColor, uint color) { @@ -17,6 +20,7 @@ int VGASetup(uint bgColor, uint color) line = 0; col = 0; clearScreen(bgColor); + cursorEnable(14, 15); return 0; } @@ -32,7 +36,7 @@ static void clearScreen(uint bgColor) restore_IRQs(flags); } -void clearScreenLine(uint bgColor, uint line) +void VGAclearLine(uint bgColor, uint line) { uint32_t flags; long int colorAttr = bgColor << 12; @@ -47,7 +51,7 @@ void clearScreenLine(uint bgColor, uint line) restore_IRQs(flags); } -void VGAprintf(uint color, uint bgColor, int startX, int startY, const char *format, ...) +void VGAPrintf(uint color, uint bgColor, int startX, int startY, const char *format, ...) { int flags; char tmp[VGA_WIDTH]; @@ -68,13 +72,13 @@ void VGAprintf(uint color, uint bgColor, int startX, int startY, const char *for restore_IRQs(flags); } -void printCharDetails(const char str, uint color, uint bgColor, int startX, int startY) +static void printCharDetails(const char str, uint color, uint bgColor, int startX, int startY) { long int colorAttr = (bgColor << 4 | (color & 0x0f)) << 8; vga[VGA_WIDTH * startY + startX] = colorAttr | str; } -void vgaScrollUp(void) +void VGAScrollUp(void) { long int colorAttr = vgaBgColor << 12; int flags; @@ -90,7 +94,7 @@ void vgaScrollUp(void) restore_IRQs(flags); } -void VGAputc(const char str) +void VGAPutc(const char str) { int flags; @@ -99,7 +103,7 @@ void VGAputc(const char str) line++; col = 0; if (line >= VGA_HEIGHT - 1) { - vgaScrollUp(); + VGAScrollUp(); line--; } } else if (str == '\r') { @@ -118,7 +122,7 @@ void VGAputc(const char str) line++; } if (line >= VGA_HEIGHT - 1) { - vgaScrollUp(); + VGAScrollUp(); line--; } } @@ -127,7 +131,7 @@ void VGAputc(const char str) restore_IRQs(flags); } -void cursorEnable(uint8_t cursor_start, uint8_t cursor_end) +static void cursorEnable(uint8_t cursor_start, uint8_t cursor_end) { outb(0x3D4, 0x0A); outb(0x3D5, (inb(0x3D5) & 0xC0) | cursor_start); @@ -142,7 +146,7 @@ void cursorDisable(void) outb(0x3D5, 0x20); } -void cursorMove(int x, int y) +static void cursorMove(int x, int y) { long int colorAttr = (vgaBgColor << 4 | (vgaColor & 0x0f)) << 8; uint16_t pos = y * VGA_WIDTH + x; diff --git a/drivers/vga.h b/drivers/vga.h index a861b3c..d9f47a4 100644 --- a/drivers/vga.h +++ b/drivers/vga.h @@ -18,11 +18,7 @@ #define VGA_HEIGHT 25 int VGASetup(uint bgColor, uint color); -void VGAputc(const char str); -void VGAprintf(uint color, uint bgColor, int startX, int startY, const char *format, ...); -void clearScreenLine(uint bgColor, uint line); -void printCharDetails(char str, uint color, uint bgColor, int startX, int startY); -void vgaScrollUp(void); -void cursorEnable(uint8_t cursor_start, uint8_t cursor_end); -void cursorDisable(void); -void cursorMove(int x, int y); +void VGAPutc(const char str); +void VGAPrintf(uint color, uint bgColor, int startX, int startY, const char *format, ...); +void VGAClearLine(uint bgColor, uint line); +void VGAScrollUp(void);