diff --git a/Makefile b/Makefile index 86e0b7a4..95841c39 100644 --- a/Makefile +++ b/Makefile @@ -2,7 +2,7 @@ include Makefile.inc DIRS = core -.PHONY: all clean install core +.PHONY: all clean install core run all: kernel @@ -12,6 +12,9 @@ install: kernel umount /mnt cp kernel /boot/toaruos-kernel +run: bootdisk.img + qemu -fda bootdisk.img + kernel: start.o link.ld main.o core ${LD} -T link.ld -o kernel *.o core/*.o diff --git a/bootdisk.img b/bootdisk.img index 6cc95c04..b1c150c1 100644 Binary files a/bootdisk.img and b/bootdisk.img differ diff --git a/core/timer.c b/core/timer.c index 6dfe18d7..c4f22d64 100644 --- a/core/timer.c +++ b/core/timer.c @@ -19,18 +19,13 @@ timer_handler( ) { ++timer_ticks; if (timer_ticks % 18 == 0) { - ticker++; - puts ("Tick. "); - if (ticker % 4 == 0) { putch('|'); } - else if(ticker % 4 == 1) { putch('/'); } - else if(ticker % 4 == 2) { putch('-'); } - else if(ticker % 4 == 3) { putch('\\'); } - putch('\n'); + ++ticker; } } void timer_install() { irq_install_handler(0, timer_handler); + timer_phase(100); /* 100Hz */ } void diff --git a/core/vga.c b/core/vga.c index fd6ae6e8..ef648142 100644 --- a/core/vga.c +++ b/core/vga.c @@ -130,6 +130,15 @@ settextcolor( attrib = (backcolor << 4) | (forecolor & 0x0F); } +/* + * resettextcolor + * Reset the text color to white on black + */ +void +resettextcolor() { + settextcolor(15,0); +} + /* * init_video * Initialize the VGA driver. diff --git a/include/multiboot.h b/include/multiboot.h new file mode 100644 index 00000000..6dbcd30b --- /dev/null +++ b/include/multiboot.h @@ -0,0 +1,41 @@ +#include + +#define MULTIBOOT_FLAG_MEM 0x001 +#define MULTIBOOT_FLAG_DEVICE 0x002 +#define MULTIBOOT_FLAG_CMDLINE 0x004 +#define MULTIBOOT_FLAG_MODS 0x008 +#define MULTIBOOT_FLAG_AOUT 0x010 +#define MULTIBOOT_FLAG_ELF 0x020 +#define MULTIBOOT_FLAG_MMAP 0x040 +#define MULTIBOOT_FLAG_CONFIG 0x080 +#define MULTIBOOT_FLAG_LOADER 0x100 +#define MULTIBOOT_FLAG_APM 0x200 +#define MULTIBOOT_FLAG_VBE 0x400 + +struct multiboot +{ + uintptr_t flags; + uintptr_t mem_lower; + uintptr_t mem_upper; + uintptr_t boot_device; + uintptr_t cmdline; + uintptr_t mods_count; + uintptr_t mods_addr; + uintptr_t num; + uintptr_t size; + uintptr_t addr; + uintptr_t shndx; + uintptr_t mmap_length; + uintptr_t mmap_addr; + uintptr_t drives_length; + uintptr_t drives_addr; + uintptr_t config_table; + uintptr_t boot_loader_name; + uintptr_t apm_table; + uintptr_t vbe_control_info; + uintptr_t vbe_mode_info; + uintptr_t vbe_mode; + uintptr_t vbe_interface_seg; + uintptr_t vbe_interface_off; + uintptr_t vbe_interface_len; +} __attribute__((packed)); diff --git a/include/system.h b/include/system.h index 68818c8d..53d5df2a 100644 --- a/include/system.h +++ b/include/system.h @@ -1,10 +1,18 @@ #ifndef __SYSTEM_H #define __SYSTEM_H +/* Types */ + #define NULL ((void *)0UL) typedef unsigned long uintptr_t; typedef long size_t; +typedef unsigned int uint32_t; + +/* Unimportant Kernel Strings */ +#define KERNEL_UNAME "ToAruOS" +#define KERNEL_VERSION_STRING "0.0.1" + /* Kernel Main */ extern void *memcpy(void * restrict dest, const void * restrict src, size_t count); @@ -19,6 +27,7 @@ extern void cls(); extern void putch(unsigned char c); extern void puts(char *str); extern void settextcolor(unsigned char forecolor, unsigned char backcolor); +extern void resettextcolor(); extern void init_video(); /* GDT */ diff --git a/main.c b/main.c index bddde7fa..887cff7c 100644 --- a/main.c +++ b/main.c @@ -1,4 +1,5 @@ #include +#include /* * memcpy @@ -96,6 +97,10 @@ outportb( __asm__ __volatile__ ("outb %1, %0" : : "dN" (_port), "a" (_data)); } +/* + * 99 Bottles of Beer on the -Wall + * Sample kernel mode program. + */ void beer() { int i = 99; while (i > 0) { @@ -116,10 +121,10 @@ void beer() { } /* - * Kernel Entry Point + * kernel entry point */ int -main() { +main(struct multiboot *mboot_ptr) { gdt_install(); idt_install(); isrs_install(); @@ -128,8 +133,52 @@ main() { timer_install(); keyboard_install(); init_video(); - puts("Good Morning!\n"); - beer(); - for (;;); + /* Yes, yes, these are #define'd strings, consider this a nice test of kprintf */ + settextcolor(12,0); + kprintf("[%s %s]\n", KERNEL_UNAME, KERNEL_VERSION_STRING); + settextcolor(1,0); + /* Multiboot Debug */ + kprintf("Received the following MULTIBOOT data:\n"); + settextcolor(7,0); + kprintf("Flags: %x\t", mboot_ptr->flags); + kprintf("Mem Lo: %x\t", mboot_ptr->mem_lower); + kprintf("Mem Hi: %x\n", mboot_ptr->mem_upper); + kprintf("Boot dev: %x\t", mboot_ptr->boot_device); + kprintf("cmdline: %x\t", mboot_ptr->cmdline); + kprintf("Mods: %x\n", mboot_ptr->mods_count); + kprintf("Addr: %x\t", mboot_ptr->mods_addr); + kprintf("Syms: %x\t", mboot_ptr->num); + kprintf("Syms: %x\n", mboot_ptr->size); + kprintf("Syms: %x\t", mboot_ptr->addr); + kprintf("Syms: %x\t", mboot_ptr->shndx); + kprintf("MMap: %x\n", mboot_ptr->mmap_length); + kprintf("Addr: %x\t", mboot_ptr->mmap_addr); + kprintf("Drives: %x\t", mboot_ptr->drives_length); + kprintf("Addr: %x\n", mboot_ptr->drives_addr); + kprintf("Config: %x\t", mboot_ptr->config_table); + kprintf("Loader: %x\t", mboot_ptr->boot_loader_name); + kprintf("APM: %x\n", mboot_ptr->apm_table); + kprintf("VBE Control: %x\t", mboot_ptr->vbe_control_info); + kprintf("VBE Mode Info: %x\t", mboot_ptr->vbe_mode_info); + kprintf("VBE Mode: %x\n", mboot_ptr->vbe_mode); + kprintf("VBE seg: %x\t", mboot_ptr->vbe_interface_seg); + kprintf("VBE off: %x\t", mboot_ptr->vbe_interface_off); + kprintf("VBE len: %x\n", mboot_ptr->vbe_interface_len); + resettextcolor(); + kprintf("(End multiboot raw data)\n"); + kprintf("Started with: %s\n", (char *)mboot_ptr->cmdline); + kprintf("Booted from: %s\n", (char *)mboot_ptr->boot_loader_name); + settextcolor(7,0); + kprintf("Testing colors...\n"); + resettextcolor(); + int i; + for (i = 0; i < 256; ++i) { + settextcolor(i,i); + putch(' '); + } + resettextcolor(); + + + //for (;;); return 0; } diff --git a/start.asm b/start.asm index 360f61c1..7740261d 100644 --- a/start.asm +++ b/start.asm @@ -16,10 +16,13 @@ mboot: global start start: mov esp, _sys_stack + push ebx + cli extern main call main jmp $ + ; Global Descriptor Table global gdt_flush extern gp