diff options
-rw-r--r-- | src/kernel/graphics/graphics.h | 2 | ||||
-rw-r--r-- | src/kernel/graphics/vesa.c | 27 | ||||
-rw-r--r-- | src/kernel/graphics/vesa.h | 54 | ||||
-rw-r--r-- | src/kernel/graphics/vga.c | 22 | ||||
-rw-r--r-- | src/kernel/input/ps2/keyboard.c | 6 | ||||
-rw-r--r-- | src/kernel/kernel.c | 15 | ||||
-rw-r--r-- | src/kernel/lib/lib.h | 4 | ||||
-rw-r--r-- | src/kernel/lib/string.c | 29 | ||||
-rw-r--r-- | src/kernel/sound/frequency.c | 4 | ||||
-rw-r--r-- | src/kernel/sound/sound.h | 2 | ||||
-rw-r--r-- | src/kernel/system.h | 6 |
11 files changed, 114 insertions, 57 deletions
diff --git a/src/kernel/graphics/graphics.h b/src/kernel/graphics/graphics.h index b28b550..3136b1e 100644 --- a/src/kernel/graphics/graphics.h +++ b/src/kernel/graphics/graphics.h @@ -18,6 +18,8 @@ void terminal_write_string(const char *data); void terminal_put_char(char c); +void terminal_put_keyboard_char(char c); + void terminal_write_line(const char *data); #endif
\ No newline at end of file diff --git a/src/kernel/graphics/vesa.c b/src/kernel/graphics/vesa.c index cab6c70..35e96c6 100644 --- a/src/kernel/graphics/vesa.c +++ b/src/kernel/graphics/vesa.c @@ -1,11 +1,16 @@ #include "vesa.h" #include "graphics.h" -#include "../sound/sound.h" #include "../lib/lib.h" -#include "../acpi/acpi.h" +#include "../input/input.h" +#include "../system.h" void switch_to_vga() { - terminal_initialize(); + regs16_t regs; + regs.ax = 0x0003; + int32(0x10, ®s); + init(); + terminal_write_line("FAILED!"); + keyboard_install(); } vbe_mode_info *vbe_set_mode(unsigned short mode) { @@ -54,9 +59,8 @@ vbe_mode_info *vbe_set_mode(unsigned short mode) { 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.ax = 0x4F00; + regs.di = vbe_init_structure; regs.es = 0xA000; int32(0x10, ®s); @@ -65,11 +69,14 @@ void set_optimal_resolution() { } vbe_info *vbe_modes = (vbe_info *) 0xA0000; + if (strcmp(vbe_modes->signature, "VESA") == 0) { - loop: - asm volatile ("hlt"); - goto loop; + init(); + terminal_write_string("SUCCESS!\n"); + keyboard_install(); } else { - acpi_poweroff(); + init(); + terminal_write_string("FAILED!\n"); + keyboard_install(); } }
\ No newline at end of file diff --git a/src/kernel/graphics/vesa.h b/src/kernel/graphics/vesa.h index dd67123..7458a47 100644 --- a/src/kernel/graphics/vesa.h +++ b/src/kernel/graphics/vesa.h @@ -4,39 +4,39 @@ #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 + char signature[4]; + uint32_t version; + uint32_t oem; + uint32_t capabilities; + uint32_t video_modes; + uint32_t video_memory; + uint32_t software_rev; + uint32_t vendor; + uint32_t product_name; + uint32_t product_rev; + char reserved[222]; + char oem_data[256]; } 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 - uint16_t granularity; // deprecated; used while calculating bank numbers + uint16_t attributes; + uint8_t window_a; + uint8_t window_b; + uint16_t granularity; uint16_t window_size; uint16_t segment_a; uint16_t segment_b; - uint32_t win_func_ptr; // deprecated; used to switch banks from protected mode without returning to real mode - uint16_t pitch; // number of bytes per horizontal line - uint16_t width; // width in pixels - uint16_t height; // height in pixels - uint8_t w_char; // unused... - uint8_t y_char; // ... + uint32_t win_func_ptr; + uint16_t pitch; + uint16_t width; + uint16_t height; + uint8_t w_char; + uint8_t y_char; uint8_t planes; - uint8_t bpp; // bits per pixel in this mode - uint8_t banks; // deprecated; total number of banks in this mode + uint8_t bpp; + uint8_t banks; uint8_t memory_model; - uint8_t bank_size; // deprecated; size of a bank, almost always 64 KB but may be 16 KB... + uint8_t bank_size; uint8_t image_pages; uint8_t reserved0; @@ -50,9 +50,9 @@ typedef struct __attribute__ ((packed)) { uint8_t reserved_position; uint8_t direct_color_attributes; - uint32_t framebuffer; // physical address of the linear frame buffer; write here to draw to the screen + uint32_t framebuffer; uint32_t off_screen_mem_off; - uint16_t off_screen_mem_size; // size of memory in the framebuffer but not being displayed on the screen + uint16_t off_screen_mem_size; uint8_t reserved1[206]; } vbe_mode_info; diff --git a/src/kernel/graphics/vga.c b/src/kernel/graphics/vga.c index 3e910f1..fa1f330 100644 --- a/src/kernel/graphics/vga.c +++ b/src/kernel/graphics/vga.c @@ -107,15 +107,10 @@ void terminal_put_char(char c) { } else if (c == '\r') { terminal_column = 0; } else if (c == '\n') { - if (irq_is_installed(1)) exec_command(text); - memory_set(text, 0, sizeof(text)); - terminal_column = 0; terminal_row++; + terminal_column = 0; terminal_scroll(); - terminal_put_entry_at('$', terminal_color, terminal_column, terminal_row); - terminal_column = 2; } else if (c >= ' ') { // Any printable character - strcat(text, &c); terminal_put_entry_at(c, terminal_color, terminal_column, terminal_row); terminal_column++; } @@ -135,12 +130,25 @@ void terminal_write(const char *data, size_t size) { terminal_put_char(data[i]); } +void terminal_put_keyboard_char(char c) { + terminal_put_char(c); + if (c == '\n' && irq_is_installed(1)) { + exec_command(text); + memory_set(text, 0, sizeof(text)); + terminal_column = 0; + terminal_row++; + terminal_scroll(); + terminal_put_entry_at('$', terminal_color, terminal_column, terminal_row); + terminal_column = 2; + terminal_update_cursor(); + } else if (c >= ' ' && irq_is_installed(1)) strcat(text, &c); +} + void terminal_write_string(const char *data) { terminal_write(data, strlen(data)); } void terminal_write_line(const char *data) { - terminal_row++; terminal_column = 0; terminal_write_string(data); terminal_column = 0; diff --git a/src/kernel/input/ps2/keyboard.c b/src/kernel/input/ps2/keyboard.c index e092630..100c0d8 100644 --- a/src/kernel/input/ps2/keyboard.c +++ b/src/kernel/input/ps2/keyboard.c @@ -37,10 +37,8 @@ void keyboard_handler(struct regs *r) { scan_code = receive_b(0x60); - if (scan_code & 0x80) { - // Release - } else { - terminal_put_char(keymap[scan_code]); + if (!(scan_code & 0x80)) { + terminal_put_keyboard_char(keymap[scan_code]); } } diff --git a/src/kernel/kernel.c b/src/kernel/kernel.c index 26eee7c..dd68536 100644 --- a/src/kernel/kernel.c +++ b/src/kernel/kernel.c @@ -5,22 +5,23 @@ #include "input/input.h" #include "timer/timer.h" -void kernel_main(void) { +void init() { asm volatile ("sti"); gdt_install(); idt_install(); isrs_install(); irq_install(); timer_install(); - - // vbe_set_mode(0x11B); // 1280x1024 - terminal_initialize(); - terminal_write_string("Melvix loaded successfully!\n"); - - set_optimal_resolution(); keyboard_install(); // mouse_install(); +} + +void kernel_main(void) { + // vbe_set_mode(0x11B); + set_optimal_resolution(); + + terminal_write_string("Melvix loaded successfully!\n"); // __asm__ ("div %0" :: "r"(0)); // Exception testing x/0 }
\ No newline at end of file diff --git a/src/kernel/lib/lib.h b/src/kernel/lib/lib.h index f0d7d1b..f83c7d5 100644 --- a/src/kernel/lib/lib.h +++ b/src/kernel/lib/lib.h @@ -9,10 +9,14 @@ size_t strcmp(const char *s1, const char *s2); char *strcat(char *dst, const char *src); +char *strcpy(char *dst, const char *src); + void *memory_copy(void *dest, const void *src, size_t count); void *memory_set(void *dest, char val, size_t count); int memory_compare(const void *a_ptr, const void *b_ptr, size_t size); +char *itoa(int i, char b[]); + #endif diff --git a/src/kernel/lib/string.c b/src/kernel/lib/string.c index 6ef0316..2b8cdfb 100644 --- a/src/kernel/lib/string.c +++ b/src/kernel/lib/string.c @@ -25,3 +25,32 @@ char *strcat(char *dst, const char *src) { dst[i + j] = 0; return dst; } + +char *strcpy(char *dst, const char *src) { + unsigned int i = 0; + for (i = 0; src[i] != 0; i++) { + dst[i] = src[i]; + } + dst[i] = 0; + return dst; +} + +char *itoa(int i, char b[]) { + char const digit[] = "0123456789"; + char *p = b; + if (i < 0) { + *p++ = '-'; + i *= -1; + } + int shifter = i; + do { + ++p; + shifter = shifter / 10; + } while (shifter); + *p = '\0'; + do { + *--p = digit[i % 10]; + i = i / 10; + } while (i); + return b; +}
\ No newline at end of file diff --git a/src/kernel/sound/frequency.c b/src/kernel/sound/frequency.c index fdc32e4..367e2e8 100644 --- a/src/kernel/sound/frequency.c +++ b/src/kernel/sound/frequency.c @@ -2,7 +2,7 @@ #include "../io/io.h" #include "../timer/timer.h" -static void play_sound(uint32_t frequency) { +void play_sound(uint32_t frequency) { uint32_t divided; uint8_t tmp; @@ -23,7 +23,7 @@ static void shut_up() { send_b(0x61, tmp); } -//Make a beep +// Make a beep void beep(uint32_t frequency, uint32_t ticks) { play_sound(frequency); timer_wait(ticks); diff --git a/src/kernel/sound/sound.h b/src/kernel/sound/sound.h index baf70b2..15c67c5 100644 --- a/src/kernel/sound/sound.h +++ b/src/kernel/sound/sound.h @@ -1,6 +1,8 @@ #ifndef MELVIX_SOUND_H #define MELVIX_SOUND_H +#include <stdint.h> + void beep(uint32_t frequency, uint32_t ticks); #endif diff --git a/src/kernel/system.h b/src/kernel/system.h new file mode 100644 index 0000000..6044570 --- /dev/null +++ b/src/kernel/system.h @@ -0,0 +1,6 @@ +#ifndef MELVIX_SYSTEM_H +#define MELVIX_SYSTEM_H + +void init(); + +#endif |