diff --git a/Makefile b/Makefile index 8f197e4..4b0de63 100644 --- a/Makefile +++ b/Makefile @@ -25,6 +25,19 @@ OBJECTS := $(OBJECTS:.s=.o) OUT_ELF := $(BIN_DIR)/ukern.elf OUT_ISO := $(BIN_DIR)/uOS.iso +###QEMU CONFIG +QEMU_FLAGS := + +VGA ?= 1 +SERIAL ?= 0 + +ifeq ($(VGA), 0) + QEMU_FLAGS += -display none +endif + +ifeq ($(SERIAL), 1) + QEMU_FLAGS += -serial stdio +endif ###RULES .PHONY: all @@ -61,16 +74,16 @@ iso: $(OUT_ISO) .PHONY: run run: $(OUT_ELF) - $(QEMU) -kernel $(OUT_ELF) + $(QEMU) $(QEMU_FLAGS) -kernel $(OUT_ELF) .PHONY: debug debug: - $(QEMU) -s -S -kernel $(OUT_ELF) + $(QEMU) $(QEMU_FLAGS) -s -S -kernel $(OUT_ELF) .PHONY: run_iso run_iso: - $(QEMU) -cdrom $(OUT_ISO) + $(QEMU) $(QEMU_FLAGS) -cdrom $(OUT_ISO) .PHONY: debug_iso debug_iso: - $(QEMU) -s -S -cdrom $(OUT_ISO) + $(QEMU) $(QEMU_FLAGS) -s -S -cdrom $(OUT_ISO) diff --git a/include/io.h b/include/io.h index d6890f3..bab752c 100644 --- a/include/io.h +++ b/include/io.h @@ -14,6 +14,8 @@ struct char_writer_s { void* ctx; }; +extern char_writer_t* default_output; + int putc(char_writer_t*, char); int print(char_writer_t*, const char*); int println(char_writer_t*, const char*); diff --git a/src/interrupt_handlers.c b/src/interrupt_handlers.c index 67a45a5..a799937 100644 --- a/src/interrupt_handlers.c +++ b/src/interrupt_handlers.c @@ -4,21 +4,13 @@ #include "serial.h" void generic_isr_handler(StateSnapshot_t* cpu_state) { //We made it to C for our interrupt! For now, let's just print our interrupt to the screen. - //What's cookin for outputs? - char_writer_t* out = 0; - if(default_COM) { - out = default_COM; - } else if(default_vga) { - out = default_vga; - vga_clear_ctx(default_vga->ctx); - } switch(cpu_state->interrupt_id) { default: - if(out){ - printf(out, "INTERRUPT TRIGGERED! Info below.\n"); - printf(out, "Int_ID|ERR: %X|%X\n", cpu_state->interrupt_id, cpu_state->error_code); - printf(out, "EFLAGS|CS|EIP: %X|%X|%X\n", cpu_state->eflags, cpu_state->cs,cpu_state->eip); - printf(out, "GP Registers:\neax:%X\nebx:%X\necx:%X\nedx:%X\nesp:%X\nebp:%X\nesi:%X\nedi:%X\n", + if(default_output){ + printf(default_output, "INTERRUPT TRIGGERED! Info below.\n"); + printf(default_output, "Int_ID|ERR: %X|%X\n", cpu_state->interrupt_id, cpu_state->error_code); + printf(default_output, "EFLAGS|CS|EIP: %X|%X|%X\n", cpu_state->eflags, cpu_state->cs,cpu_state->eip); + printf(default_output, "GP Registers:\neax:%X\nebx:%X\necx:%X\nedx:%X\nesp:%X\nebp:%X\nesi:%X\nedi:%X\n", cpu_state->eax, cpu_state->ebx, cpu_state->ecx, @@ -27,7 +19,7 @@ void generic_isr_handler(StateSnapshot_t* cpu_state) { cpu_state->ebp, cpu_state->esi, cpu_state->edi); - printf(out, "HALT!"); + printf(default_output, "HALT!"); while(1); } } diff --git a/src/io.c b/src/io.c index acd07ed..c1e2bfc 100644 --- a/src/io.c +++ b/src/io.c @@ -2,6 +2,8 @@ #include "kttools.h" #include +char_writer_t* default_output = 0; + int printhex(char_writer_t* writer, uint32_t out) { char buff[9]; i_to_str(out, buff, 9, 0x10); diff --git a/src/main.c b/src/main.c index 3cbfbf2..534b79c 100644 --- a/src/main.c +++ b/src/main.c @@ -34,16 +34,18 @@ void kern_main(uint32_t multiboot_magic, mb_info_t* multiboot_info) default_COM = &serial_writer; serial_init(&serial_ctx); + //AND OUR DEFAULT OUTPUT IS: + default_output = default_vga; - printf(&vga_writer, "Entry eax:%X\n", multiboot_magic); + printf(default_output, "Entry eax:%X\n", multiboot_magic); if(multiboot_magic != 0x2BADB002) { - println(&vga_writer, "Bootloader not multiboot1 compliant! Needed for mmap, etc. Can't work without it, kthxbye!"); + println(default_output, "Bootloader not multiboot1 compliant! Needed for mmap, etc. Can't work without it, kthxbye!"); return; } else { - println(&vga_writer, "Multiboot detected! Continuing..."); + println(default_output, "Multiboot detected! Continuing..."); } - printf(&vga_writer, "MEM_LOWER:%X\n", multiboot_info->mem_lower); - printf(&vga_writer, "MEM_UPPER:%X\n", multiboot_info->mem_upper); + printf(default_output, "MEM_LOWER:%X\n", multiboot_info->mem_lower); + printf(default_output, "MEM_UPPER:%X\n", multiboot_info->mem_upper); }