diff options
author | Marvin Borner | 2019-09-25 19:33:29 +0200 |
---|---|---|
committer | Marvin Borner | 2019-09-25 19:33:29 +0200 |
commit | 16b8a48d1de16a5982cf983a282832fd4ed01f85 (patch) | |
tree | 1a0294b9f96fe8ffc788ce7ef600c9ff8eb4f856 | |
parent | 64ec44ba4575686849ba2597cf8bc9054af3d376 (diff) |
Started integrating vesa resolution finder
-rw-r--r-- | src/kernel/boot.asm | 5 | ||||
-rw-r--r-- | src/kernel/graphics/vesa.c | 39 | ||||
-rw-r--r-- | src/kernel/graphics/vesa.h | 17 | ||||
-rw-r--r-- | src/kernel/kernel.c | 11 |
4 files changed, 65 insertions, 7 deletions
diff --git a/src/kernel/boot.asm b/src/kernel/boot.asm index c0b3735..7c7f5d9 100644 --- a/src/kernel/boot.asm +++ b/src/kernel/boot.asm @@ -1,5 +1,6 @@ [bits 32] global start +global vbe_init_structure start: mov esp, _sys_stack ; Points stack to stack area jmp stublet @@ -44,6 +45,10 @@ stublet: %include "src/kernel/interact.asm" +vbe_init_structure: + .signature db "VBE2" + .table_data: resb 512-4 + ; Store the stack SECTION .bss resb 8192 ; Reserve 8KiB diff --git a/src/kernel/graphics/vesa.c b/src/kernel/graphics/vesa.c index af2502b..cab6c70 100644 --- a/src/kernel/graphics/vesa.c +++ b/src/kernel/graphics/vesa.c @@ -1,4 +1,12 @@ #include "vesa.h" +#include "graphics.h" +#include "../sound/sound.h" +#include "../lib/lib.h" +#include "../acpi/acpi.h" + +void switch_to_vga() { + terminal_initialize(); +} vbe_mode_info *vbe_set_mode(unsigned short mode) { regs16_t regs; @@ -13,7 +21,7 @@ vbe_mode_info *vbe_set_mode(unsigned short mode) { regs.es = 0xA000; int32(0x10, ®s); if (regs.ax != 0x004F) { - // Add VGA redirect + switch_to_vga(); } vbe_mode_info *vbe_info = (vbe_mode_info *) 0xA0000; @@ -24,8 +32,10 @@ vbe_mode_info *vbe_set_mode(unsigned short mode) { vbe_pitch = vbe_info->pitch; char *fb = (char *) vbe_info->framebuffer; - for (int i = 0; i < 640 * 480 * 3; i++) { + for (int i = 0; i < vbe_width * vbe_height * vbe_bpp; i++) { fb[i] = 100; + fb[i + 1] = 100; + fb[i + 2] = 100; } regs.ax = 0x0000; int32(0x16, ®s); @@ -34,9 +44,32 @@ vbe_mode_info *vbe_set_mode(unsigned short mode) { return vbe_info; } else { - // Add VGA redirect + switch_to_vga(); } vbe_mode_info vbe_info; return &vbe_info; } + +void set_optimal_resolution() { + extern vbe_info *vbe_init_structure; + regs16_t regs; + regs.ax = 0x4F01; + regs.cx = vbe_init_structure; + regs.di = 0x0000; + regs.es = 0xA000; + int32(0x10, ®s); + + if (regs.ax != 0x004F) { + switch_to_vga(); + } + + vbe_info *vbe_modes = (vbe_info *) 0xA0000; + if (strcmp(vbe_modes->signature, "VESA") == 0) { + loop: + asm volatile ("hlt"); + goto loop; + } else { + acpi_poweroff(); + } +}
\ No newline at end of file diff --git a/src/kernel/graphics/vesa.h b/src/kernel/graphics/vesa.h index fb9ff54..dd67123 100644 --- a/src/kernel/graphics/vesa.h +++ b/src/kernel/graphics/vesa.h @@ -4,6 +4,21 @@ #include <stdint.h> typedef struct __attribute__ ((packed)) { + char signature[4]; // must be "VESA" to indicate valid VBE support + uint32_t version; // VBE version; high byte is major version, low byte is minor version + uint32_t oem; // segment:offset pointer to OEM + uint32_t capabilities; // bitfield that describes card capabilities + uint32_t video_modes; // segment:offset pointer to list of supported video modes + uint32_t video_memory; // amount of video memory in 64KB blocks + uint32_t software_rev; // software revision + uint32_t vendor; // segment:offset to card vendor string + uint32_t product_name; // segment:offset to card model name + uint32_t product_rev; // segment:offset pointer to product revision + char reserved[222]; // reserved for future expansion + char oem_data[256]; // OEM BIOSes store their strings in this area +} vbe_info; + +typedef struct __attribute__ ((packed)) { uint16_t attributes; // deprecated, only bit 7 should be of interest to you, and it indicates the mode supports a linear frame buffer. uint8_t window_a; // deprecated uint8_t window_b; // deprecated @@ -43,6 +58,8 @@ typedef struct __attribute__ ((packed)) { vbe_mode_info *vbe_set_mode(unsigned short mode); +void set_optimal_resolution(); + typedef struct __attribute__ ((packed)) { unsigned short di, si, bp, sp, bx, dx, cx, ax; unsigned short gs, fs, es, ds, eflags; diff --git a/src/kernel/kernel.c b/src/kernel/kernel.c index d0356f4..26eee7c 100644 --- a/src/kernel/kernel.c +++ b/src/kernel/kernel.c @@ -1,3 +1,4 @@ +#include "graphics/vesa.h" #include "graphics/graphics.h" #include "gdt/gdt.h" #include "interrupts/interrupts.h" @@ -10,14 +11,16 @@ void kernel_main(void) { idt_install(); isrs_install(); irq_install(); + timer_install(); - vbe_set_mode(0x11B); // 1280x1024 + // vbe_set_mode(0x11B); // 1280x1024 - // terminal_initialize(); - // terminal_write_string("Melvix loaded successfully!\n"); + terminal_initialize(); + terminal_write_string("Melvix loaded successfully!\n"); - timer_install(); + set_optimal_resolution(); keyboard_install(); // mouse_install(); + // __asm__ ("div %0" :: "r"(0)); // Exception testing x/0 }
\ No newline at end of file |