diff --git a/build_numbers.c b/build_numbers.c index cd99e5f..ffe8d25 100644 --- a/build_numbers.c +++ b/build_numbers.c @@ -1,3 +1,3 @@ #ifndef KERNEL_VERSION_NUMBER -#define KERNEL_VERSION_NUMBER "0.0.3-0" +#define KERNEL_VERSION_NUMBER "0.0.3-2" #endif diff --git a/kernel/idt.c b/kernel/idt.c index 78f7bd1..9a621d4 100644 --- a/kernel/idt.c +++ b/kernel/idt.c @@ -8,7 +8,16 @@ void idt_install() { idt.size = (sizeof (struct idt_entry) * 256) - 1; idt.idt_entries_start = (struct idt_entry *) &idt_entries; - + // IDT Selector value: + // 0x08 is the code segement we want, which, as defined by the GDT, is the kernel code segment entry in the GDT. + // + // IDT Flags value: + // + // Bit: 7 6-5 4-0 + // P DPL Always 01110 (14) + // For the kernel ring 8E is chosen + // 100 for bits 7-5. 1 (present) 00 (the level in this case ring zero) + // 01110 for bits 4-0. This is always set to 14. idt_set_gate(&idt_entries[0], (unsigned int) isr0, 0x08, 0x8E); idt_set_gate(&idt_entries[1], (unsigned int) isr1, 0x08, 0x8E); idt_set_gate(&idt_entries[2], (unsigned int) isr2, 0x08, 0x8E); @@ -41,7 +50,7 @@ void idt_install() idt_set_gate(&idt_entries[29], (unsigned int) isr29, 0x08, 0x8E); idt_set_gate(&idt_entries[30], (unsigned int) isr30, 0x08, 0x8E); idt_set_gate(&idt_entries[31], (unsigned int) isr31, 0x08, 0x8E); - //asm("xchg %bx, %bx"); + load_idt(&idt); } diff --git a/kernel/interrupt_handler.c b/kernel/interrupt_handler.c index 4178c8a..df74742 100644 --- a/kernel/interrupt_handler.c +++ b/kernel/interrupt_handler.c @@ -3,5 +3,8 @@ void interrupt_handler(struct isr_state stack) { - write_to_com(COM1_PORT, "Interrupt detected!\n"); + write_to_com(COM1_PORT, "Divide by zero detected!\n"); + write_to_com(COM1_PORT, "Halting system!\n"); + asm("cli"); + asm("hlt"); } diff --git a/kernel/kmain.c b/kernel/kmain.c index 2fb4ee5..fa9a09e 100644 --- a/kernel/kmain.c +++ b/kernel/kmain.c @@ -11,47 +11,28 @@ void kmain() { set_serial_baud_rate(COM1_PORT, 0x03); configure_serial_line(COM1_PORT); + write_to_com(COM1_PORT, "Set up COM1 for messaging.\n"); clear_screen(); write_to_com(COM1_PORT, "Clearing screen.\n"); print_banner(); - write_to_com(COM1_PORT, "Displaying OS banner.\n"); - //draw_rect(20, 5, 50, 7, 0x4, 0xF); - draw_rect(0, 5, 5, 13, 0xF, 0x4); - draw_rect(5, 8, 10, 10, 0x4, 0xF); - draw_rect(10, 5, 15, 13, 0x8, 0x6); - draw_rect(20, 5, 25, 7, 0xF, 0x1); - draw_rect(20, 8, 25, 13, 0x5, 0x3); - set_cursor(0, 14); - move_cursor(0, 14); - move_cursor(0, 15); - draw_string("Test print", 0x8, 0xF); - move_cursor(0, 16); - draw_string("And now the cursor has been moved to y = 16.", 0x1, 0xF); - move_cursor(5, 20); - draw_string("Cursor moved over 5 cells and down 4 cells.", 0xF, 0x0); - draw_string("And the cursor moves to the end of the string", 0x1, 0xF); - draw_string("Now this string should have a newline now:\nAnd now a new line is here.\n", 0xF, 0x0); - //draw_rect(20, 5, 50, 7, 0x4, 0xF); - //draw_rect(20, 5, 50, 7, 0x4, 0xF); - //draw_rect(20, 5, 50, 7, 0x4, 0xF); - //draw_s("Hello, World!", 2, 9); - //row = 2; - ///column = 80; - //draw_s("And 2nd Row. Now the 3rd row.", 2, 9); - move_cursor(0, 3); - draw_string("Installing GDT...\n", 0xF, 0x0); - write_to_com(COM1_PORT, "Installing the GDT.\n"); + print_message("Displaying OS banner.\n", 0xF, 0x0); + + print_message("Installing GDT...\n", 0xF, 0x0); gdt_install(); - - //move_cursor(0, 4); - //asm("xchg %bx, %bx"); - //write_to_com(COM1_PORT, "GDT installed.\n"); + print_message("GDT installed!\n", 0xF, 0x0); + //asm("xchg %bx, %bx"); // Boch's break point - //draw_string("Installed GDT\n", 0xf, 0x0); - //asm("xchg %bx, %bx"); + print_message("Installing IDT...\n", 0xF, 0x0); idt_install(); - write_to_com(COM1_PORT, "IDT installed.\n"); + print_message("IDT installed.\n", 0xF, 0x0); + int i = 5 / 0; asm("hlt"); } + +void print_message(unsigned char* msg, unsigned char fg, unsigned char bg) +{ + write_to_com(COM1_PORT, msg); + draw_string(msg, fg, bg); +} diff --git a/kernel/screen.c b/kernel/screen.c index 23962a9..c25f532 100644 --- a/kernel/screen.c +++ b/kernel/screen.c @@ -46,6 +46,8 @@ void print_banner(){ } } } + + cursor_y = 3; } //index = (y_value * width_of_screen) + x_value; void draw_rect(int start_x, int start_y, int end_x, int end_y, unsigned char fg, unsigned char bg){ @@ -74,13 +76,14 @@ void draw_string(char* string, unsigned char fg, unsigned char bg) if(current_char == '\n'){ cursor_y++; + cursor_x = 0; continue; } *where = string[i] | attr << 8; } - cursor_x = cursor_x + length + 1; + if(cursor_x != 0) cursor_x = cursor_x + length + 1; } void set_cursor(unsigned char x, unsigned char y){