From eec8119eeea0ef0e226bd3541eebc9294cdd79b1 Mon Sep 17 00:00:00 2001 From: Freya Murphy Date: Sat, 27 Jan 2024 03:38:27 -0500 Subject: [PATCH 1/2] more lib fns --- include/lib.h | 12 ++++++++++++ src/lib.c | 11 +++++++++++ 2 files changed, 23 insertions(+) diff --git a/include/lib.h b/include/lib.h index b368636..43b95a6 100644 --- a/include/lib.h +++ b/include/lib.h @@ -31,6 +31,18 @@ extern void *memset(void *restrict dest, int c, unsigned long n); */ extern int strncmp(const char *restrict s1, const char *restrict s2, unsigned long n); +/** + * Copys the string pointed to by src , into a string at the buffer pointer to by dest. + * The dest buffer must be long enough to hold src. + */ +extern char *strcpy(char *restrict dest, const char *restrict src); + +/** + * Copys the string pointed to by src , into a string at the buffer pointer to by dest. + * The dest buffer must be long enough to hold src or size n. + */ +extern char *strncpy(char *restrict dest, const char *restrict src, unsigned long n); + /** * @returns 1 if c is a space */ diff --git a/src/lib.c b/src/lib.c index 66bd0c2..1f57f83 100644 --- a/src/lib.c +++ b/src/lib.c @@ -43,6 +43,17 @@ int strncmp(const char *restrict lhs, const char *restrict rhs, unsigned long n) return *l - *r; } +char *strcpy(char *restrict dest, const char *restrict src) { + for(; (*dest = *src); dest++, src++); + return dest; +} + +char *strncpy(char *restrict dest, const char *restrict src, unsigned long n) { + for(; (*dest = *src) && n; dest++, src++, n--); + memset(dest, 0, n); + return dest; +} + int isspace(int c) { switch (c) { case ' ': From 09b43900045e256c8907d048063e6a8d3c638f69 Mon Sep 17 00:00:00 2001 From: Freya Murphy Date: Sat, 27 Jan 2024 05:16:57 -0500 Subject: [PATCH 2/2] qemu fb --- include/fb.h | 5 ++++ src/arch/amd64/fb.c | 68 +++++++++++++++++++++++++++++++++++++++++++ src/arch/amd64/fb.h | 0 src/arch/amd64/shim.c | 3 +- src/kmain.c | 3 ++ 5 files changed, 78 insertions(+), 1 deletion(-) create mode 100644 include/fb.h create mode 100644 src/arch/amd64/fb.c create mode 100644 src/arch/amd64/fb.h diff --git a/include/fb.h b/include/fb.h new file mode 100644 index 0000000..2c5ea13 --- /dev/null +++ b/include/fb.h @@ -0,0 +1,5 @@ +#pragma once + +#include + +int fb_init(uint16_t res_x, uint16_t res_y); diff --git a/src/arch/amd64/fb.c b/src/arch/amd64/fb.c new file mode 100644 index 0000000..f27b890 --- /dev/null +++ b/src/arch/amd64/fb.c @@ -0,0 +1,68 @@ +#include "bindings.h" + +#include +#include + +#define PREFERRED_VY 4096 +#define PREFERRED_B 32 + +uint16_t fb_res_x = 0; +uint16_t fb_res_y = 0; +uint16_t fb_res_b = 0; + +uint8_t *fb_buffer = NULL; + +int fb_init(uint16_t res_x, uint16_t res_y) { + + outw(0x1CE, 0x00); + uint16_t i = inw(0x1CF); + if (i < 0xB0C0 || i > 0xB0C6) { + return -1; + } + outw(0x1CF, 0xB0C4); + i = inw(0x1CF); + /* Disable VBE */ + outw(0x1CE, 0x04); + outw(0x1CF, 0x00); + /* Set X resolution to 1024 */ + outw(0x1CE, 0x01); + outw(0x1CF, res_x); + /* Set Y resolution to 768 */ + outw(0x1CE, 0x02); + outw(0x1CF, res_y); + /* Set bpp to 32 */ + outw(0x1CE, 0x03); + outw(0x1CF, PREFERRED_B); + /* Set Virtual Height to stuff */ + outw(0x1CE, 0x07); + outw(0x1CF, PREFERRED_VY); + /* Re-enable VBE */ + outw(0x1CE, 0x04); + outw(0x1CF, 0x41); + + uint32_t * text_vid_mem = (uint32_t *)0xA0000; + text_vid_mem[0] = 0xA5ADFACE; + + for (uintptr_t fb_offset = 0xE0000000; fb_offset < 0xFF000000; fb_offset += 0x01000000) { + /* Enable the higher memory */ + for (uintptr_t i = fb_offset; i < fb_offset; i += 0x1000) { + // todo ident map fb + } + + /* Go find it */ + for (uintptr_t x = fb_offset; x < fb_offset + 0xFF0000; x += 0x1000) { + if (((uintptr_t *)x)[0] == 0xA5ADFACE) { + fb_buffer = (uint8_t *) x; + goto mem_found; + } + } + } + +mem_found: + + fb_res_x = res_x; + fb_res_y = res_y; + fb_res_b = PREFERRED_B; + + return 0; +} diff --git a/src/arch/amd64/fb.h b/src/arch/amd64/fb.h new file mode 100644 index 0000000..e69de29 diff --git a/src/arch/amd64/shim.c b/src/arch/amd64/shim.c index 1e73525..cb0b1d5 100644 --- a/src/arch/amd64/shim.c +++ b/src/arch/amd64/shim.c @@ -57,7 +57,8 @@ static int get_maxphysaddr() { __cpuid(0x80000008, eax, ebx, ecx, edx); return eax & 0xFF; } - +#define PREFERRED_VY 4096 +#define PREFERRED_B 32 // entry point for amd64 void* amd64_shim(void *boot_info) { struct pml4e *pml4 = (struct pml4e *)0x1000; diff --git a/src/kmain.c b/src/kmain.c index 381ceb9..145ffdb 100644 --- a/src/kmain.c +++ b/src/kmain.c @@ -1,9 +1,12 @@ #include #include +#include + void kmain(void *info) { char buf[20]; *(char*)0xB8000 = 'c'; *(char*)(0xB8002 + 0x20'0000) = 'd'; itoa((long)info, buf, 10); + fb_init(1024, 768); serial_out_str(buf); }