diff options
author | Marvin Borner | 2019-10-26 22:15:29 +0200 |
---|---|---|
committer | Marvin Borner | 2019-10-26 22:15:29 +0200 |
commit | 5d4180c67cea08bb76eebde6b41b8935e60fed98 (patch) | |
tree | 1f3bd2be8e20dc754dcc73af36684fdc3642d7ba | |
parent | b2cf27bb1d8239a7ccc55c29df996370c8f1bed6 (diff) |
Improved VESA and fixed warnings
-rw-r--r-- | src/kernel/graphics/vesa.c | 23 | ||||
-rw-r--r-- | src/kernel/graphics/vesa.h | 2 | ||||
-rw-r--r-- | src/kernel/interrupts/isr.c | 2 | ||||
-rw-r--r-- | src/kernel/io/io.h | 16 | ||||
-rw-r--r-- | src/kernel/lib/lib.h | 2 | ||||
-rw-r--r-- | src/kernel/lib/string.c | 1 | ||||
-rw-r--r-- | src/kernel/system.c | 52 | ||||
-rw-r--r-- | src/kernel/system.h | 96 |
8 files changed, 84 insertions, 110 deletions
diff --git a/src/kernel/graphics/vesa.c b/src/kernel/graphics/vesa.c index 02b5566..022aec0 100644 --- a/src/kernel/graphics/vesa.c +++ b/src/kernel/graphics/vesa.c @@ -5,6 +5,7 @@ #include "../paging/paging.h" #include "../system.h" #include "../lib/alloc.h" +#include "../commands/command.h" void switch_to_vga() { serial_write("Force switch to VGA!\n"); @@ -28,8 +29,8 @@ struct edid_data get_edid() { regs16_t regs; regs.ax = 0x4F15; regs.bx = 0x01; // BL - regs.es = get_segment(edid); - regs.di = get_offset(edid); + regs.es = 0; + regs.di = (unsigned short) edid; paging_disable(); int32(0x10, ®s); paging_enable(); @@ -112,7 +113,7 @@ struct vbe_mode_info *vbe_get_mode_info(uint16_t mode) { } void set_optimal_resolution() { - uint16_t *video_modes = vbe_get_modes(); + // uint16_t *video_modes = vbe_get_modes(); // TODO: Fix mode getting and optimal resolution finder uint16_t highest = 0; @@ -149,6 +150,7 @@ void set_optimal_resolution() { kfree(video_modes);*/ if (highest == 0) { + serial_write("Mode detection failed\n"); struct vbe_mode_info *mode_info = vbe_get_mode_info(0x577); highest = 0x577; vbe_width = mode_info->width; @@ -174,7 +176,6 @@ void set_optimal_resolution() { paging_map((uint32_t) fb + z, (uint32_t) fb + z, PT_PRESENT | PT_RW | PT_USED); vbe_set_mode(highest); - text = (char *) kmalloc(1024); } uint16_t terminal_x = 1; @@ -221,7 +222,7 @@ void vesa_draw_char(char ch) { for (int cy = 0; cy < 13; cy++) { for (int cx = 0; cx < 8; cx++) { if (glyph[cy] & mask[cx]) { - vesa_set_pixel(terminal_x + 8 - cx, terminal_y + 13 - cy, terminal_color); + vesa_set_pixel(terminal_x + 8 - cx, terminal_y + 16 - cy, terminal_color); } } } @@ -229,17 +230,17 @@ void vesa_draw_char(char ch) { terminal_x += 10; } else if (ch == '\n') { terminal_x = 0; - terminal_y += 15; + terminal_y += 16; } if (terminal_x >= vbe_width) { terminal_x = 0; - terminal_y += 15; + terminal_y += 16; } } void vesa_keyboard_char(char ch) { - vesa_draw_rectangle(terminal_x, terminal_y, terminal_x + 10, terminal_y + 16, 0x0); + vesa_draw_rectangle(terminal_x, terminal_y, terminal_x + 8, terminal_y + 16, 0x0); if (ch == 0x08) { if (terminal_x != 0) terminal_x -= 10; @@ -248,9 +249,7 @@ void vesa_keyboard_char(char ch) { } else if (ch == '\r') { terminal_x = 0; } else if (ch == '\n') { - terminal_x = 0; - terminal_y += 15; - serial_write(text); + vesa_draw_char(ch); exec_command(text); memory_set(text, 0, sizeof(text)); // terminal_scroll(); @@ -260,7 +259,7 @@ void vesa_keyboard_char(char ch) { } // terminal_scroll(); - vesa_draw_rectangle(terminal_x, terminal_y, terminal_x + 10, terminal_y + 16, terminal_color); + vesa_draw_rectangle(terminal_x, terminal_y, terminal_x + 8, terminal_y + 16, terminal_color); } void vesa_draw_string(char *data) { diff --git a/src/kernel/graphics/vesa.h b/src/kernel/graphics/vesa.h index f3bf136..00e058e 100644 --- a/src/kernel/graphics/vesa.h +++ b/src/kernel/graphics/vesa.h @@ -159,7 +159,7 @@ void vesa_draw_number(int n); /** * The current input */ -char *text; +char text[1024]; /** * The current video mode diff --git a/src/kernel/interrupts/isr.c b/src/kernel/interrupts/isr.c index b615816..f6e94a5 100644 --- a/src/kernel/interrupts/isr.c +++ b/src/kernel/interrupts/isr.c @@ -1,6 +1,8 @@ +#include <stdint.h> #include "interrupts.h" #include "../lib/lib.h" #include "../system.h" +#include "../io/io.h" // Defined in isr.asm extern void isr0(); diff --git a/src/kernel/io/io.h b/src/kernel/io/io.h index a145319..3c618d6 100644 --- a/src/kernel/io/io.h +++ b/src/kernel/io/io.h @@ -51,20 +51,26 @@ void send_l(uint16_t port, uint32_t data); void init_serial(); /** + * Write a single char to the serial port (QEMU logging) + * @param ch The char + */ +void serial_put(char ch); + +/** * Write a string to the serial port (QEMU logging) - * @param data The string that should get transmitted + * @param data The string */ void serial_write(const char *data); /** - * Write a hex number to the serial port (QEMU logging) - * @param n The hex number that should get transmitted + * Write a hexadecimal formatted int to the serial port (QEMU logging) + * @param n The decimal number */ void serial_write_hex(int n); /** - * Write a dec number to the serial port (QEMU logging) - * @param n The dec number that should get transmitted + * Write a decimal number to the serial port (QEMU logging) + * @param n The decimal number */ void serial_write_dec(int n); diff --git a/src/kernel/lib/lib.h b/src/kernel/lib/lib.h index 6963498..de09e0f 100644 --- a/src/kernel/lib/lib.h +++ b/src/kernel/lib/lib.h @@ -14,7 +14,7 @@ size_t strlen(const char *str); * Compare two strings * @param s1 The first string pointer * @param s2 The second string pointer - * @return The length difference between s1 and s2 + * @return Non-zero if not equal */ size_t strcmp(const char *s1, const char *s2); diff --git a/src/kernel/lib/string.c b/src/kernel/lib/string.c index f9dfb99..0ca04ee 100644 --- a/src/kernel/lib/string.c +++ b/src/kernel/lib/string.c @@ -1,4 +1,5 @@ #include <stddef.h> +#include "../io/io.h" size_t strlen(const char *str) { size_t len = 0; diff --git a/src/kernel/system.c b/src/kernel/system.c new file mode 100644 index 0000000..b0ad429 --- /dev/null +++ b/src/kernel/system.c @@ -0,0 +1,52 @@ +#ifndef MELVIX_SYSTEM_H +#define MELVIX_SYSTEM_H + +#include "timer/timer.h" +#include "io/io.h" +#include "graphics/vesa.h" +#include "system.h" + +void kernel_time() { + vesa_draw_string("\n"); + vesa_draw_string("["); + vesa_draw_number(get_time()); + vesa_draw_string("] "); +} + +void info(char *msg) { + // terminal_set_color(9); + kernel_time(); + vesa_draw_string("INFO: "); + vesa_draw_string(msg); + vesa_draw_string("\n"); + // terminal_set_color(7); +} + +void warn(char *msg) { + // terminal_set_color(6); + kernel_time(); + vesa_draw_string("WARNING: "); + vesa_draw_string(msg); + vesa_draw_string("\n"); + // terminal_set_color(7); +} + +void panic(char *msg) { + asm volatile ("cli"); + // terminal_set_color(4); + kernel_time(); + serial_write("PANIC: "); + serial_write(msg); + serial_write(" - System Halted!\n"); + loop: + asm volatile ("hlt"); + goto loop; +} + +void assert(int x) { + if (x == 0) { + panic("Assertion failed"); + } +} + +#endif diff --git a/src/kernel/system.h b/src/kernel/system.h index c80b6ee..45e88de 100644 --- a/src/kernel/system.h +++ b/src/kernel/system.h @@ -1,12 +1,6 @@ #ifndef MELVIX_SYSTEM_H #define MELVIX_SYSTEM_H -#include <stdint.h> -#include "timer/timer.h" -#include "lib/lib.h" -#include "graphics/vesa.h" -#include "io/io.h" - /** * Initialize the basic features of the OS */ @@ -28,115 +22,35 @@ typedef struct __attribute__ ((packed)) { extern void int32(unsigned char intnum, regs16_t *regs); /** - * ASM segment:offset pointer - */ -struct far_ptr { - union { - uint32_t ptr; - struct { - uint16_t offset, segment; - }; - }; -} __attribute__ ((packed)); - -/** - * Get offset from ASM segment:offset pointer - */ -static inline uint16_t get_offset(const volatile void *p) { - return (uint16_t) (uintptr_t) p & 0x000F; -} - -/** - * Get segment from ASM segment:offset pointer - */ -static inline uint16_t get_segment(const volatile void *p) { - return (uint16_t) (((uintptr_t) p) >> 4); -} - -/** - * Convert pointer to far_ptr - * @param __ptr The ASM segment:offset pointer - * @return The new far pointer - */ -static inline struct far_ptr FAR_PTR(void *__ptr) { - struct far_ptr __fptr; - __fptr.offset = get_offset(__ptr); - __fptr.segment = get_segment(__ptr); - return __fptr; -} - -/** - * Get pointer from ASM segment:offset far pointer - * @param fptr The ASM far pointer - * @return The normalized pointer - */ -static inline void *get_ptr(struct far_ptr fptr) { - return (void *) (unsigned long) ((fptr.segment << 4) + fptr.offset); -} - -/** * Print the current kernel time */ -static inline void kernel_time() { - vesa_draw_string("\n"); - vesa_draw_string("["); - vesa_draw_number(get_time()); - vesa_draw_string("] "); -} +void kernel_time(); /** * Display an information message * @param msg The information */ -static inline void info(char *msg) { - // terminal_set_color(9); - kernel_time(); - vesa_draw_string("INFO: "); - vesa_draw_string(msg); - vesa_draw_string("\r"); - // terminal_set_color(7); -} +void info(char *msg); /** * Display a warning message * TODO: Add line number and file name * @param msg The warning cause/reason */ -static inline void warn(char *msg) { - // terminal_set_color(6); - kernel_time(); - vesa_draw_string("WARNING: "); - vesa_draw_string(msg); - vesa_draw_string("\r"); - // terminal_set_color(7); -} +void warn(char *msg); /** * Halt the entire system and display a message * TODO: Add line number and file name * @param msg The error cause/reason */ -static inline void panic(char *msg) { - asm volatile ("cli"); - // terminal_set_color(4); - kernel_time(); - serial_write("PANIC: "); - serial_write(msg); - serial_write(" - System Halted!\n"); - loop: - asm volatile ("hlt"); - goto loop; -} +void panic(char *msg); /** * Assert that a value is non-zero, else panic * TODO: Add line number and file name * @param x The value */ -static inline void assert(int x) { - if (x == 0) { - panic("Assertion failed"); - } -} +void assert(int x); #endif |