diff options
author | Simon <sgkadesh@icloud.com> | 2024-01-27 18:36:44 -0500 |
---|---|---|
committer | Simon <sgkadesh@icloud.com> | 2024-01-27 18:36:44 -0500 |
commit | cfdc91ad07cee684eb7eeeb7dcdcc993609dd040 (patch) | |
tree | 505b36f5afdeaf9c1e572e0224070f814c6c13e2 /src/arch | |
parent | Did some preliminary work on memory management (diff) | |
parent | qemu fb (diff) | |
download | corn-cfdc91ad07cee684eb7eeeb7dcdcc993609dd040.tar.gz corn-cfdc91ad07cee684eb7eeeb7dcdcc993609dd040.tar.bz2 corn-cfdc91ad07cee684eb7eeeb7dcdcc993609dd040.zip |
Merge remote-tracking branch 'origin/main'
Diffstat (limited to 'src/arch')
-rw-r--r-- | src/arch/amd64/fb.c | 68 | ||||
-rw-r--r-- | src/arch/amd64/fb.h | 0 |
2 files changed, 68 insertions, 0 deletions
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 <stdint.h> +#include <stddef.h> + +#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 --- /dev/null +++ b/src/arch/amd64/fb.h |