diff --git a/Makefile b/Makefile index c6a1399..c881590 100644 --- a/Makefile +++ b/Makefile @@ -1,11 +1,10 @@ -SOURCES = src/io/term/flanterm_backends/fb.c src/io/term/flanterm.c src/debug/panic.c src/debug/stacktrace.c src/boot/boot.c src/sched/scheduler.c src/sched/process.c src/mem/heap/kheap.c src/mem/paging/vmm.c src/mem/paging/paging.c src/mem/paging/pmm.c src/string/string.c src/io/kbd/ps2.c src/io/serial/serial.c src/io/term/printf.c src/io/term/term.c src/idt/idt.c src/mem/gdt/gdt.c src/mem/misc/utils.c src/time/timer.c src/kmain.c +SOURCES = src/debug/misc.c src/io/term/flanterm_backends/fb.c src/io/term/flanterm.c src/debug/panic.c src/debug/stacktrace.c src/boot/boot.c src/sched/scheduler.c src/sched/process.c src/mem/heap/kheap.c src/mem/paging/vmm.c src/mem/paging/paging.c src/mem/paging/pmm.c src/string/string.c src/io/kbd/ps2.c src/io/serial/serial.c src/io/term/printf.c src/io/term/term.c src/idt/idt.c src/mem/gdt/gdt.c src/mem/misc/utils.c src/time/timer.c src/kmain.c PROBLEMATIC_FLAGS=-Wno-unused-parameter -Wno-unused-variable build: rm -f *.o x86_64-elf-gcc -g -c -Isrc $(SOURCES) $(PROBLEMATIC_FLAGS) -Wall -Wextra -std=gnu99 -nostdlib -ffreestanding -fno-stack-protector -fno-omit-frame-pointer -fno-stack-check -fno-PIC -ffunction-sections -fdata-sections -mcmodel=kernel - objcopy -O elf64-x86-64 -B i386 -I binary zap-light16.psf zap-light16.o nasm -f elf64 src/idt/idt.S -o idt_stub.o x86_64-elf-ld -o pepperk -T linker.ld *.o nm -n pepperk | awk '$$2 ~ /[TtDdBbRr]/ {print $$1, $$3}' > symbols.map diff --git a/src/debug/misc.c b/src/debug/misc.c new file mode 100644 index 0000000..5cba142 --- /dev/null +++ b/src/debug/misc.c @@ -0,0 +1,61 @@ +#include +#include "limine.h" +#include "string/string.h" + +extern struct boot_context boot_ctx; + +// Display the memmap so we see how the memory is laid out at handoff +void memmap_display(struct limine_memmap_response* response) +{ + DEBUG("Got memory map from Limine: revision %u, %u entries", response->revision, response->entry_count); + + for (size_t i=0; ientry_count; i++) + { + struct limine_memmap_entry* entry = response->entries[i]; + char type[32] = {0}; + switch(entry->type) + { + case LIMINE_MEMMAP_USABLE: + strcpy(type, "USABLE"); + break; + case LIMINE_MEMMAP_RESERVED: + strcpy(type, "RESERVED"); + break; + case LIMINE_MEMMAP_ACPI_RECLAIMABLE: + strcpy(type, "ACPI_RECLAIMABLE"); + break; + case LIMINE_MEMMAP_ACPI_NVS: + strcpy(type, "ACPI_NVS"); + break; + case LIMINE_MEMMAP_BAD_MEMORY: + strcpy(type, "BAD_MEMORY"); + break; + case LIMINE_MEMMAP_BOOTLOADER_RECLAIMABLE: + strcpy(type, "BOOTLOADER_RECLAIMABLE"); + break; + case LIMINE_MEMMAP_KERNEL_AND_MODULES: + strcpy(type, "KERNEL_AND_MODULES"); + break; + case LIMINE_MEMMAP_FRAMEBUFFER: + strcpy(type, "FRAMEBUFFER"); + break; + default: + strcpy(type, "UNKNOWN"); + break; + } + DEBUG("entry %02u: [0x%016x | %016u bytes] - %s", i, entry->base, entry->length, type); + } +} + +// Display the HHDM +void hhdm_display(struct limine_hhdm_response* hhdm) +{ + DEBUG("Got HHDM revision=%u offset=0x%p", hhdm->revision, hhdm->offset); +} + +void boot_mem_display() +{ + memmap_display(boot_ctx.mmap); + hhdm_display(boot_ctx.hhdm); + DEBUG("kernel: phys_base=0x%p virt_base=0x%p", boot_ctx.kaddr->physical_base, boot_ctx.kaddr->virtual_base); +} \ No newline at end of file diff --git a/src/entry.S b/src/entry.S deleted file mode 100644 index 73b6de0..0000000 --- a/src/entry.S +++ /dev/null @@ -1,23 +0,0 @@ -bits 64 -global _start - -extern kmain -extern kernel_stack - -KERNEL_STACK_SIZE equ 65536 - -section .text - -_start: - cli - - ; load kernel stack - lea rsp, [kernel_stack+KERNEL_STACK_SIZE] - - ; rbp=0 so last frame in stack trace - xor rbp, rbp - - ; 16 byte align - and rsp, -16 - - call kmain \ No newline at end of file diff --git a/src/io/term/term.c b/src/io/term/term.c index 8c15caf..56522b0 100644 --- a/src/io/term/term.c +++ b/src/io/term/term.c @@ -11,104 +11,14 @@ because this shitty implementation will be replaced one day by Flanterm (once memory management is okay: paging & kernel malloc) */ -#include #include #include #include "term.h" -#include "mem/misc/utils.h" #include "config.h" #include "flanterm.h" -extern struct boot_context boot_ctx; - -// Importing the PSF object file -extern unsigned char _binary_zap_light16_psf_start[]; -extern unsigned char _binary_zap_light16_psf_end[]; - -PSF1_Header* font = (PSF1_Header*)_binary_zap_light16_psf_start; -uint8_t* glyphs = _binary_zap_light16_psf_start + sizeof(PSF1_Header); - -#define FONT_WIDTH 8 -#define FONT_HEIGHT font->characterSize - extern struct flanterm_context* ft_ctx; -// Character cursor -typedef struct -{ - size_t x; - size_t y; -} Cursor; - -static Cursor cursor = {0, 0}; - -static uint8_t* fb; -static struct limine_framebuffer* framebuffer; - -uint8_t lines_length[TERM_HISTORY_MAX_LINES]; - -static inline size_t term_max_cols(void) -{ - return framebuffer->width / FONT_WIDTH; -} - -static inline size_t term_max_lines(void) -{ - return framebuffer->height / FONT_HEIGHT; -} - -int term_init() -{ - // Get framebuffer address from Limine struct - - if (!boot_ctx.fb) - { - return -ENOMEM; - } - - framebuffer = boot_ctx.fb; - fb = (uint8_t*)framebuffer->address; - - memset(lines_length, 0, sizeof(lines_length)); - - DEBUG("terminal initialized, fb=0x%p (width=%u height=%u pitch=%u bpp=%u)", fb, framebuffer->width, framebuffer->height, framebuffer->pitch, framebuffer->bpp); - return 0; -} - -// These are marked "static" because we don't wanna expose them all around -// AKA they should just be seen here (kind of like private functions in cpp) -static inline void putpixel(size_t x, size_t y, uint32_t color) -{ - // Guard so we don't write past fb boundaries - if (x >= framebuffer->width || y >= framebuffer->height) return; - // Depth isn't part of limine_framebuffer attributes so it will be 4 - size_t pos = x*4 + y*framebuffer->pitch; - fb[pos] = color & 255; // blue channel - fb[pos+1] = (color >> 8) & 255; // green - fb[pos+2] = (color >> 16) & 255; // blue -} - -void term_scroll() -{ - // Erase first text line - memset(fb, 255, FONT_HEIGHT*framebuffer->pitch); - - // Move whole framebuffer up by one text line - memmove(fb, fb+(FONT_HEIGHT*framebuffer->pitch), (framebuffer->height-FONT_HEIGHT)*framebuffer->pitch); - - // Clear last text line - size_t clear_start = (framebuffer->height - FONT_HEIGHT) * framebuffer->pitch; - memset(fb + clear_start, 255, FONT_HEIGHT * framebuffer->pitch); - - // Shift line lengths by 1 (for backspace handling) - size_t max_lines = term_max_lines(); - for (size_t i = 1; i < max_lines; i++) - { - lines_length[i - 1] = lines_length[i]; - } - lines_length[max_lines - 1] = 0; -} - // Overhead that could be avoided, right? (for printf) void _putchar(char character) { diff --git a/src/io/term/term.h b/src/io/term/term.h index 8128381..26e89d0 100644 --- a/src/io/term/term.h +++ b/src/io/term/term.h @@ -7,26 +7,7 @@ #ifndef TERM_H #define TERM_H -int term_init(); void kputs(const char* str); void _putchar(char character); -enum TermColors -{ - BLACK = 0x000000, - WHITE = 0xffffff -}; - -#define PSF1_FONT_MAGIC 0x0436 - -typedef struct -{ - uint16_t magic; - uint8_t fontMode; - uint8_t characterSize; // height -} PSF1_Header; - -// debug -void term_scroll(); - #endif diff --git a/src/kernel.h b/src/kernel.h index e0816ab..d901915 100644 --- a/src/kernel.h +++ b/src/kernel.h @@ -40,6 +40,7 @@ void idle(); void debug_stack_trace(unsigned int max_frames); const char* debug_find_symbol(uintptr_t rip, uintptr_t* offset); +void boot_mem_display(); #define assert(check) do { if(!(check)) hcf(); } while(0) diff --git a/src/kmain.c b/src/kmain.c index a5d0fdb..215893d 100644 --- a/src/kmain.c +++ b/src/kmain.c @@ -70,13 +70,6 @@ void flanterm_free_wrapper(void* ptr, size_t size) kfree(ptr); } -void boot_mem_display() -{ - memmap_display(boot_ctx.mmap); - hhdm_display(boot_ctx.hhdm); - DEBUG("kernel: phys_base=0x%p virt_base=0x%p", boot_ctx.kaddr->physical_base, boot_ctx.kaddr->virtual_base); -} - extern uintptr_t kheap_start; // This is our entry point @@ -139,6 +132,6 @@ void kmain() keyboard_init(FR); - printf(PEPPEROS_SPLASH); + kputs(PEPPEROS_SPLASH); idle(); } diff --git a/src/mem/misc/utils.c b/src/mem/misc/utils.c index 8f7a43f..bdd5f07 100644 --- a/src/mem/misc/utils.c +++ b/src/mem/misc/utils.c @@ -76,53 +76,4 @@ int memcmp(const void* s1, const void* s2, size_t n) } return 0; -} - -// Display the memmap so we see how the memory is laid out at handoff -void memmap_display(struct limine_memmap_response* response) -{ - DEBUG("Got memory map from Limine: revision %u, %u entries", response->revision, response->entry_count); - - for (size_t i=0; ientry_count; i++) - { - struct limine_memmap_entry* entry = response->entries[i]; - char type[32] = {0}; - switch(entry->type) - { - case LIMINE_MEMMAP_USABLE: - strcpy(type, "USABLE"); - break; - case LIMINE_MEMMAP_RESERVED: - strcpy(type, "RESERVED"); - break; - case LIMINE_MEMMAP_ACPI_RECLAIMABLE: - strcpy(type, "ACPI_RECLAIMABLE"); - break; - case LIMINE_MEMMAP_ACPI_NVS: - strcpy(type, "ACPI_NVS"); - break; - case LIMINE_MEMMAP_BAD_MEMORY: - strcpy(type, "BAD_MEMORY"); - break; - case LIMINE_MEMMAP_BOOTLOADER_RECLAIMABLE: - strcpy(type, "BOOTLOADER_RECLAIMABLE"); - break; - case LIMINE_MEMMAP_KERNEL_AND_MODULES: - strcpy(type, "KERNEL_AND_MODULES"); - break; - case LIMINE_MEMMAP_FRAMEBUFFER: - strcpy(type, "FRAMEBUFFER"); - break; - default: - strcpy(type, "UNKNOWN"); - break; - } - DEBUG("entry %02u: [0x%016x | %016u bytes] - %s", i, entry->base, entry->length, type); - } -} - -// Display the HHDM -void hhdm_display(struct limine_hhdm_response* hhdm) -{ - DEBUG("Got HHDM revision=%u offset=0x%p", hhdm->revision, hhdm->offset); } \ No newline at end of file diff --git a/zap-light16.psf b/zap-light16.psf deleted file mode 100644 index 047bd1b..0000000 Binary files a/zap-light16.psf and /dev/null differ