From 0d594ecd85aaf654b815ce983852d464ed4efc0d Mon Sep 17 00:00:00 2001 From: tkchia Date: Sun, 25 Sep 2022 13:17:33 +0000 Subject: [PATCH] Bare metal VGA: allow for 64-bit video frame buffer address --- libc/runtime/mman.internal.h | 5 +++-- libc/vga/rlinit-vga.S | 3 +++ libc/vga/writev-vga.c | 6 +++--- 3 files changed, 9 insertions(+), 5 deletions(-) diff --git a/libc/runtime/mman.internal.h b/libc/runtime/mman.internal.h index 0af3bb84e..9f96ed695 100644 --- a/libc/runtime/mman.internal.h +++ b/libc/runtime/mman.internal.h @@ -26,8 +26,9 @@ struct mman { or pixels (graphics) */ unsigned short pc_video_height; /* 0x1d2e — height in chars. (text) or pixels (graphics) */ - uint32_t pc_video_framebuffer; /* 0x1d30 */ - uint32_t pc_video_framebuffer_size; /* 0x1d34 */ + uint64_t pc_video_framebuffer; /* 0x1d30 — physical address of + video frame buffer */ + uint64_t pc_video_framebuffer_size; /* 0x1d38 */ }; COSMOPOLITAN_C_END_ diff --git a/libc/vga/rlinit-vga.S b/libc/vga/rlinit-vga.S index 914b2a4fa..e61b6b438 100644 --- a/libc/vga/rlinit-vga.S +++ b/libc/vga/rlinit-vga.S @@ -66,6 +66,9 @@ movw $25,mm+"struct mman::pc_video_height" movl $0xb8000,mm+"struct mman::pc_video_framebuffer" movl $0x8000,mm+"struct mman::pc_video_framebuffer_size" + xor %eax,%eax + mov %eax,mm+"struct mman::pc_video_framebuffer"+4 + mov %eax,mm+"struct mman::pc_video_framebuffer_size"+4 mov $0x1003,%ax # enable/disable VGA text blinking #ifdef VGA_USE_BLINK mov $1,%bx diff --git a/libc/vga/writev-vga.c b/libc/vga/writev-vga.c index 4eb6650c2..894120fbb 100644 --- a/libc/vga/writev-vga.c +++ b/libc/vga/writev-vga.c @@ -62,7 +62,8 @@ __attribute__((__constructor__)) static textstartup void _vga_init(void) { if (IsMetal()) { struct mman *mm = (struct mman *)(BANE + 0x0500); unsigned short height = mm->pc_video_height, width = mm->pc_video_width; - void * vid_buf = (void *)(BANE + mm->pc_video_framebuffer); + uint64_t vid_buf_phy = mm->pc_video_framebuffer; + void *vid_buf = (void *)(BANE + vid_buf_phy); size_t vid_buf_sz = mm->pc_video_framebuffer_size; /* * Get the initial cursor position from the BIOS data area. Also get @@ -78,8 +79,7 @@ __attribute__((__constructor__)) static textstartup void _vga_init(void) { if (chr_ht_hi != 0 || chr_ht > 32) chr_ht = 32; /* Make sure the video buffer is mapped into virtual memory. */ - __invert_memory_area(mm, __get_pml4t(), (uint64_t)vid_buf, vid_buf_sz, - PAGE_RW); + __invert_memory_area(mm, __get_pml4t(), vid_buf_phy, vid_buf_sz, PAGE_RW); /* * Initialize our tty structure from the current screen contents, * current cursor position, & character height.