diff options
author | Marvin Borner | 2019-10-02 20:01:17 +0200 |
---|---|---|
committer | Marvin Borner | 2019-10-02 20:01:17 +0200 |
commit | 3238ced93283a167675f20244ec9fd6310eb8002 (patch) | |
tree | 288078ca30e9e4b5d5ba9a178315cb5ee9f6a2d8 | |
parent | 682c47a98844ffec3f3129160e9cdb98ba129989 (diff) |
Finally fixed VESA auto resolution finder
This was quite hard and strange but it works now!
-rw-r--r-- | src/kernel/graphics/graphics.h | 6 | ||||
-rw-r--r-- | src/kernel/graphics/vesa.c | 41 | ||||
-rw-r--r-- | src/kernel/graphics/vga.c | 6 | ||||
-rw-r--r-- | src/kernel/interrupts/isr.c | 8 | ||||
-rw-r--r-- | src/kernel/kernel.c | 12 | ||||
-rw-r--r-- | src/kernel/lib/lib.h | 4 | ||||
-rw-r--r-- | src/kernel/lib/string.c | 29 | ||||
-rw-r--r-- | src/kernel/paging/kheap.c | 2 | ||||
-rw-r--r-- | src/kernel/paging/paging.c | 1 | ||||
-rw-r--r-- | src/kernel/system.h | 34 | ||||
-rw-r--r-- | src/kernel/timer/timer.c | 6 | ||||
-rw-r--r-- | src/kernel/timer/timer.h | 6 |
12 files changed, 92 insertions, 63 deletions
diff --git a/src/kernel/graphics/graphics.h b/src/kernel/graphics/graphics.h index e20d1ed..118fe50 100644 --- a/src/kernel/graphics/graphics.h +++ b/src/kernel/graphics/graphics.h @@ -34,6 +34,12 @@ void terminal_clear(); void terminal_write_string(const char *data); /** + * Write an integer to the terminal + * @param data The integer that should be written + */ +void terminal_write_number(int data); + +/** * Put a new char at the x+1 cursor position and * handle according events (e.g. overflow, linebreak) * @param c The character (can also be \n or \r) diff --git a/src/kernel/graphics/vesa.c b/src/kernel/graphics/vesa.c index 32bc0e9..9ea83aa 100644 --- a/src/kernel/graphics/vesa.c +++ b/src/kernel/graphics/vesa.c @@ -2,7 +2,7 @@ #include "graphics.h" #include "../input/input.h" #include "../system.h" -#include "../paging/kheap.h" +#include "../lib/lib.h" void switch_to_vga() { regs16_t regs; @@ -57,21 +57,15 @@ struct vbe_mode_info *vbe_set_mode(unsigned short mode) { } void set_optimal_resolution() { - struct vbe_info *info; - struct vbe_mode_info *mode_info; + struct vbe_info *info = (struct vbe_info *) 0x2000; + struct vbe_mode_info *mode_info = (struct vbe_mode_info *) 0x3000; - info = kmalloc(sizeof(struct vbe_info)); - mode_info = kmalloc(sizeof(struct vbe_mode_info)); - - info->signature[0] = 'V'; - info->signature[1] = 'B'; - info->signature[2] = 'E'; - info->signature[3] = '2'; + memory_copy(info->signature, "VBE2", 4); regs16_t regs; regs.ax = 0x4F00; - regs.es = get_segment(info); - regs.di = get_offset(info); + regs.es = 0; + regs.di = info; int32(0x10, ®s); if (regs.ax != 0x004F) { @@ -81,7 +75,8 @@ void set_optimal_resolution() { uint16_t *mode_ptr = get_ptr(info->video_modes); uint16_t mode; uint16_t highest = 0x11B; - uint16_t highest_height = 0; + uint16_t highest_width = 0; + while ((mode = *mode_ptr++) != 0xFFFF) { mode &= 0x1FF; regs16_t regs2; @@ -92,24 +87,12 @@ void set_optimal_resolution() { int32(0x10, ®s2); if ((mode_info->attributes & 0x90) != 0x90) continue; - if (mode_info->height >= highest_height) { + + if (mode_info->width >= highest_width && (float) mode_info->width / (float) mode_info->height < 2.0) { highest = mode; - highest_height = mode_info->height; + highest_width = mode_info->width; } } - vbe_set_mode(0x11B); - - kfree(info); - - /*if (strcmp((const char *) info->version, (const char *) 0x300) == 0) { - init(); - terminal_write_string("SUCCESS!\n"); - terminal_write_line((const char *) &info->vendor); - keyboard_install(); - } else { - init(); - terminal_write_string("FAILED!\n"); - keyboard_install(); // Find out why commands only work when keyboard gets reinstalled after write - }*/ + vbe_set_mode(highest); }
\ No newline at end of file diff --git a/src/kernel/graphics/vga.c b/src/kernel/graphics/vga.c index 8fde84f..cf1888b 100644 --- a/src/kernel/graphics/vga.c +++ b/src/kernel/graphics/vga.c @@ -148,6 +148,12 @@ void terminal_write_string(const char *data) { terminal_write(data, strlen(data)); } +void terminal_write_number(int data) { + char converted[128]; + itoa(data, converted, 10); + terminal_write(converted, strlen(converted)); +} + void terminal_write_line(const char *data) { terminal_column = 0; terminal_write_string(data); diff --git a/src/kernel/interrupts/isr.c b/src/kernel/interrupts/isr.c index 8da7919..3567acf 100644 --- a/src/kernel/interrupts/isr.c +++ b/src/kernel/interrupts/isr.c @@ -1,5 +1,6 @@ #include "../graphics/graphics.h" #include "interrupts.h" +#include "../lib/lib.h" // Defined in isr.asm extern void isr0(); @@ -147,9 +148,8 @@ const char *exception_messages[] = { // Master exception handler - halt via endless loop void fault_handler(struct regs *r) { if (r->int_no < 32) { - terminal_write_string("\n"); - terminal_write_string(exception_messages[r->int_no]); - terminal_write_string(" Exception. System Halted!\n"); - for (;;); + char *message = (char *) exception_messages[r->int_no]; + strcat(message, " Exception"); + panic(message); } } diff --git a/src/kernel/kernel.c b/src/kernel/kernel.c index 013f7d5..6b1faf7 100644 --- a/src/kernel/kernel.c +++ b/src/kernel/kernel.c @@ -12,21 +12,21 @@ void init() { idt_install(); isrs_install(); irq_install(); - init_kheap(); - page_init(); timer_install(); - // terminal_initialize(); + terminal_initialize(); + // init_kheap(); + // page_init(); keyboard_install(); // mouse_install(); asm volatile ("sti"); } void kernel_main(void) { - // vbe_set_mode(0x11B); set_optimal_resolution(); + // vbe_set_mode(0x11B); init(); - - // terminal_write_string("Melvix loaded successfully!\n"); + terminal_write_string("Melvix loaded successfully!\n"); + terminal_write_string("Loading VESA!\n"); // __asm__ ("div %0" :: "r"(0)); // Exception testing x/0 for (;;); diff --git a/src/kernel/lib/lib.h b/src/kernel/lib/lib.h index d6cc09e..0292cc3 100644 --- a/src/kernel/lib/lib.h +++ b/src/kernel/lib/lib.h @@ -65,8 +65,8 @@ int memory_compare(const void *a_ptr, const void *b_ptr, size_t size); * Convert an int into a string * @param i The integer which should be converted * @param b The converted int as string - * @return The converted string (b) + * @param base The desired base */ -char *itoa(int i, char b[]); +void *itoa(int i, char *b, int base); #endif diff --git a/src/kernel/lib/string.c b/src/kernel/lib/string.c index f07697d..ef746d6 100644 --- a/src/kernel/lib/string.c +++ b/src/kernel/lib/string.c @@ -35,22 +35,19 @@ char *strcpy(char *dest, const char *src) { return dest; } -char *itoa(int i, char b[]) { - char const digit[] = "0123456789"; - char *p = b; - if (i < 0) { - *p++ = '-'; - i *= -1; +void *itoa(int i, char *b, int base) { + int temp_i; + temp_i = i; + int stringLen = 1; + + while ((int) temp_i / base != 0) { + temp_i = (int) temp_i / base; + stringLen++; } - int shifter = i; - do { - ++p; - shifter = shifter / 10; - } while (shifter); - *p = '\0'; + + temp_i = i; do { - *--p = digit[i % 10]; - i = i / 10; - } while (i); - return b; + *(b + stringLen - 1) = (temp_i % base) + '0'; + temp_i = (int) temp_i / base; + } while (stringLen--); }
\ No newline at end of file diff --git a/src/kernel/paging/kheap.c b/src/kernel/paging/kheap.c index 13f8ab2..2004cb8 100644 --- a/src/kernel/paging/kheap.c +++ b/src/kernel/paging/kheap.c @@ -21,7 +21,7 @@ void init_kheap() { } void *fmalloc(unsigned int size) { - //assert(placement_address + size < MEM_END); + assert(placement_address + size < MEM_END); unsigned int hold = placement_address; memory_set((void *) hold, 0, size); placement_address += size; diff --git a/src/kernel/paging/paging.c b/src/kernel/paging/paging.c index 6282953..122e4c0 100644 --- a/src/kernel/paging/paging.c +++ b/src/kernel/paging/paging.c @@ -8,7 +8,6 @@ vpage_dir_t *current_vpage_dir = NULL; vpage_dir_t *root_vpage_dir = NULL; -//Assembly abstraction for more maintainable code page_table_t *get_cr3() { unsigned int cr3; diff --git a/src/kernel/system.h b/src/kernel/system.h index d41b7bc..57db4c9 100644 --- a/src/kernel/system.h +++ b/src/kernel/system.h @@ -2,6 +2,8 @@ #define MELVIX_SYSTEM_H #include <stdint.h> +#include "timer/timer.h" +#include "lib/lib.h" /** * Initialize the basic features of the OS @@ -71,15 +73,39 @@ static inline void *get_ptr(struct far_ptr fptr) { } /** + * Print the current kernel time + */ +static inline void kernel_time() { + terminal_write_string("\n"); + terminal_write_string("["); + terminal_write_number(get_time()); + terminal_write_string("] "); +} + +/** + * Display an information message + * @param msg The information + */ +static inline void info(char *msg) { + terminal_set_color(10); + kernel_time(); + terminal_write_string("INFO: "); + terminal_write_string(msg); + terminal_write_string("\n"); + terminal_set_color(7); +} + +/** * Display a warning message * TODO: Add line number and file name * @param msg The warning cause/reason */ static inline void warn(char *msg) { - asm volatile ("cli"); terminal_set_color(6); - terminal_write_line("WARNING"); + kernel_time(); + terminal_write_string("WARNING: "); terminal_write_string(msg); + terminal_write_string("\n"); terminal_set_color(7); } @@ -91,8 +117,10 @@ static inline void warn(char *msg) { static inline void panic(char *msg) { asm volatile ("cli"); terminal_set_color(4); - terminal_write_line("PANIC"); + kernel_time(); + terminal_write_string("PANIC: "); terminal_write_string(msg); + terminal_write_string(" - System Halted!"); loop: asm volatile ("hlt"); goto loop; diff --git a/src/kernel/timer/timer.c b/src/kernel/timer/timer.c index 45b254e..f332429 100644 --- a/src/kernel/timer/timer.c +++ b/src/kernel/timer/timer.c @@ -1,7 +1,7 @@ #include "../interrupts/interrupts.h" #include "../io/io.h" -volatile unsigned int timer_ticks = 0; +static unsigned int timer_ticks = 0; void timer_phase(int hz) { int divisor = 1193180 / hz; @@ -25,6 +25,10 @@ void timer_wait(int ticks) { } } +unsigned int get_time() { + return timer_ticks; +} + // Install timer handler into IRQ0 void timer_install() { timer_phase(100); diff --git a/src/kernel/timer/timer.h b/src/kernel/timer/timer.h index 635c996..309896a 100644 --- a/src/kernel/timer/timer.h +++ b/src/kernel/timer/timer.h @@ -12,4 +12,10 @@ void timer_install(); */ void timer_wait(int ticks); +/** + * Get the current timer ticks + * @return The current timer ticks (100 ticks = 1 second) + */ +unsigned int get_time(); + #endif |