From f77524c1154177dcbb0fb19d83de71c2a93d40e3 Mon Sep 17 00:00:00 2001 From: Andrew Price Date: Mon, 1 Dec 2014 15:50:57 -0600 Subject: [PATCH] PS/2 mouse, VESA and VGA graphics, start of a window manager --- fs/boot/grub/grub.cfg | 9 ++++++++- kernel/build.sh | 5 +++++ kernel/ide.c | 2 +- kernel/io.c | 9 ++++++++- kernel/io.h | 3 ++- kernel/isr.c | 1 - kernel/keyboard.c | 8 ++++---- kernel/liballoc_hooks.c | 1 - kernel/main.c | 17 +++++++++++++++-- kernel/multiboot.asm | 21 +++++++++++---------- kernel/pci.c | 16 ++++++++++++++-- kernel/physical_allocator.c | 8 ++++++++ kernel/shell.c | 10 ++++++---- kernel/types.h | 5 +++++ 14 files changed, 87 insertions(+), 28 deletions(-) diff --git a/fs/boot/grub/grub.cfg b/fs/boot/grub/grub.cfg index e0020be2..db0160c1 100644 --- a/fs/boot/grub/grub.cfg +++ b/fs/boot/grub/grub.cfg @@ -1,6 +1,13 @@ set timeout=3 set default=0 + menuentry "Perception" { + insmod all_video multiboot2 /boot/kernel.sys - boot + set gfxpayload=auto +} + +menuentry "Perception (VGA fallback)" { + multiboot2 /boot/kernel.sys + set gfxpayload=text } diff --git a/kernel/build.sh b/kernel/build.sh index 6008c067..9fbe0112 100755 --- a/kernel/build.sh +++ b/kernel/build.sh @@ -20,6 +20,7 @@ $GCC_CMD liballoc.o liballoc.c $GCC_CMD liballoc_hooks.o liballoc_hooks.c $GCC_CMD main.o main.c $GCC_CMD messages.o messages.c +$GCC_CMD mouse.o mouse.c $NASM_CMD multiboot.o multiboot.asm $GCC_CMD pci.o pci.c $GCC_CMD physical_allocator.o physical_allocator.c @@ -32,7 +33,11 @@ $GCC_CMD syscall.o syscall.c $GCC_CMD thread.o thread.c $GCC_CMD text_terminal.o text_terminal.c $GCC_CMD timer.o timer.c +$GCC_CMD vesa.o vesa.c $GCC_CMD vfs.o vfs.c +$GCC_CMD vga.o vga.c +$GCC_CMD video.o video.c $GCC_CMD virtual_allocator.o virtual_allocator.c +$GCC_CMD window_manager.o window_manager.c ld -nodefaultlibs -T linker.ld -Map map.txt -o ../fs/boot/kernel.sys *.o rm *.o diff --git a/kernel/ide.c b/kernel/ide.c index e466bbd4..1bcef3ec 100644 --- a/kernel/ide.c +++ b/kernel/ide.c @@ -461,7 +461,7 @@ void ide_thread_entry(struct IDEController *controller) { } /* todo - wait for an irq */ - for(status = 0; status < 15; status++) asm volatile ("hlt"); + for(status = 0; status < 5; status++) asm volatile ("hlt"); /* read 4 words (8 bytes) from the data register */ uint32 returnLba = diff --git a/kernel/io.c b/kernel/io.c index 307e1c2a..d14e6321 100644 --- a/kernel/io.c +++ b/kernel/io.c @@ -42,7 +42,7 @@ size_t strlen(const char *str) { return count; } -unsigned char inportb (unsigned short _port) +uint8 inportb (unsigned short _port) { unsigned char rv; __asm__ __volatile__ ("inb %1, %0" : "=a" (rv) : "dN" (_port)); @@ -54,6 +54,13 @@ void outportb (unsigned short _port, unsigned char _data) __asm__ __volatile__ ("outb %1, %0" : : "dN" (_port), "a" (_data)); } +int8 inportsb (unsigned short _port) +{ + int8 rv; + __asm__ __volatile__ ("inb %1, %0" : "=a" (rv) : "dN" (_port)); + return rv; +} + uint16 inportw (unsigned short _port) { uint16 rv; __asm__ __volatile__ ("inw %1, %0" : "=a" (rv) : "dN" (_port)); diff --git a/kernel/io.h b/kernel/io.h index cf4b518e..5a2b4062 100644 --- a/kernel/io.h +++ b/kernel/io.h @@ -5,8 +5,9 @@ extern void memcpy(unsigned char *dest, const unsigned char *src, size_t count); extern void memset(unsigned char *dest, unsigned char val, size_t count); extern bool strcmp(void *a, void *b, size_t count); extern size_t strlen(const char *str); -extern unsigned char inportb (unsigned short _port); +extern uint8 inportb (unsigned short _port); extern void outportb (unsigned short _port, unsigned char _data); +extern int8 inportsb (unsigned short _port); extern uint16 inportw (unsigned short _port); extern void outportw (unsigned short _port, uint16 _data); extern uint32 inportdw (unsigned short _port); diff --git a/kernel/isr.c b/kernel/isr.c index b6da1f08..502c7279 100644 --- a/kernel/isr.c +++ b/kernel/isr.c @@ -39,7 +39,6 @@ unsigned char in_interrupt; int interrupt_locks; void init_isrs() { - in_interrupt = 0; interrupt_locks = 0; idt_set_gate(0, (size_t)isr0, 0x08, 0x8E); diff --git a/kernel/keyboard.c b/kernel/keyboard.c index 9e0b2a99..08500416 100644 --- a/kernel/keyboard.c +++ b/kernel/keyboard.c @@ -1,9 +1,9 @@ -#include "keyboard.h" -#include "isr.h" -#include "irq.h" -#include "text_terminal.h" #include "io.h" +#include "irq.h" +#include "isr.h" +#include "keyboard.h" #include "messages.h" +#include "text_terminal.h" #if 0 unsigned char kbdus_unshift[128] = diff --git a/kernel/liballoc_hooks.c b/kernel/liballoc_hooks.c index 1c461ff6..6ce1831b 100644 --- a/kernel/liballoc_hooks.c +++ b/kernel/liballoc_hooks.c @@ -59,7 +59,6 @@ void* liballoc_alloc(size_t pages) { flush_virtual_page(addr); } - return (void *)start; } diff --git a/kernel/main.c b/kernel/main.c index cf11992a..e175c12a 100644 --- a/kernel/main.c +++ b/kernel/main.c @@ -6,6 +6,7 @@ #include "isr.h" #include "keyboard.h" #include "messages.h" +#include "mouse.h" #include "multiboot2.h" #include "pci.h" #include "physical_allocator.h" @@ -18,7 +19,9 @@ #include "thread.h" #include "timer.h" #include "vfs.h" +#include "video.h" #include "virtual_allocator.h" +#include "window_manager.h" void kmain() { /* make sure we were booted with a multiboot2 bootloader - we need this because we depend on GRUB for @@ -29,10 +32,10 @@ void kmain() { for(;;) __asm__ __volatile__ ("hlt"); } + enter_text_mode(); + enter_interrupt(); /* pretend we're in an interrupt so sti isn't enabled */ - enter_text_mode(); - print_string("Welcome to Perception...\n"); init_physical_allocator(); init_virtual_allocator(); @@ -49,15 +52,25 @@ void kmain() { init_timer(); init_keyboard(); + init_mouse(); init_fs(); init_storage_devices(); init_vfs(); + init_video(); /* scan the pci bus, devices will be initialized as they're discovered */ init_pci(); init_syscalls(); + check_for_video(); /* makes sure we have video */ + + window_manager_init(); + + enter_text_mode(); + print_string("Welcome to Perception...\n"); + + /* Create the shell thread */ schedule_thread(create_thread(0, (size_t)shell_entry, 0)); /* enable interrupts, this will enter us into our threads */ diff --git a/kernel/multiboot.asm b/kernel/multiboot.asm index c606e19a..84f226e2 100644 --- a/kernel/multiboot.asm +++ b/kernel/multiboot.asm @@ -15,25 +15,26 @@ MbHdr: dd -(0xE85250D6 + 0 + (HdrEnd - MbHdr)) ; checksum ; tags - - ; sections override -; dw 2, 0 ; multiboot_header_tag_address -; dd 24 -; dd MbHdr -; dd _loadStart -; dd _loadEnd -; dd _bssEnd - ; entry point override dw 3, 0 ; multiboot_header_tag_entry_address dd 12 dd EntryPoint + dd 0 ; align next tag to 8 byte boundry ; request some information from GRUB for the kernel dw 1, 0 ; multiboot_header_tag_information_request - dd 12 + dd 16 dd 6 ; request multiboot_tag_type_mmap + dd 8 ; request MULTIBOOT_TAG_TYPE_FRAMEBUFFER + + ; request a video mode + dw 5, 0 ; MULTIBOOT_HEADER_TAG_FRAMEBUFFER + dd 20 + dd 0 ; width + dd 0 ; height + dd 0 ; depth + dd 0 ; align next tag to 8 byte boundry ; end of tags diff --git a/kernel/pci.c b/kernel/pci.c index ee10dba5..e9c3a533 100644 --- a/kernel/pci.c +++ b/kernel/pci.c @@ -3,6 +3,7 @@ #include "text_terminal.h" #include "liballoc.h" #include "ide.h" +#include "video.h" uint32 pci_config_read_dword(uint8 bus, uint8 slot, uint8 func, uint8 offset) { uint32 lbus = (uint32)bus; @@ -103,12 +104,23 @@ void pci_check_function(uint8 bus, uint8 slot, uint8 function) { switch(device->base_class) { + case 0x00: switch(device->sub_class) { + case 0x01: /* VGA-Compatible Device */ + init_video_device(device); + break; + } case 0x01: /* mass storage controller */ switch(device->sub_class) { case 0x01: /* IDE controller */ init_ide(device); break; } break; + case 0x03: /* display controller */ + switch(device->sub_class) { + case 0x00: /* VGA-Compatible Controller */ + init_video_device(device); + break; + } break; case 0x06: /* bridge device */ switch(device->sub_class) { case 0x04: { /* PCI-to-PCI Bridge */ @@ -142,7 +154,7 @@ void init_pci() { } /* iterate over found devices */ - print_string("PCI Devices:\n"); + /*print_string("PCI Devices:\n"); struct PCIDevice *device = pci_devices; while(device) { print_string("Address: "); @@ -161,7 +173,7 @@ void init_pci() { print_string(" (no driver)"); print_char('\n'); device = device->next; - } + }*/ } const char *pci_class_to_string(uint8 baseclass, uint8 subclass) { diff --git a/kernel/physical_allocator.c b/kernel/physical_allocator.c index 41f07e82..66878d5b 100644 --- a/kernel/physical_allocator.c +++ b/kernel/physical_allocator.c @@ -2,6 +2,7 @@ #include "virtual_allocator.h" #include "multiboot2.h" #include "text_terminal.h" +#include "vesa.h" size_t total_system_memory; size_t free_pages; @@ -26,6 +27,10 @@ void init_physical_allocator() { tag->type != MULTIBOOT_TAG_TYPE_END; tag = (struct multiboot_tag *)((size_t) tag + (size_t)((tag->size + 7) & ~7))) { + if(tag->size == 0) + return; + + if(tag->type == MULTIBOOT_TAG_TYPE_MMAP) { /* found the memory map */ struct multiboot_tag_mmap *mmap_tag = (struct multiboot_tag_mmap *)tag; @@ -81,6 +86,9 @@ void init_physical_allocator() { } } + } else if(tag->type == MULTIBOOT_TAG_TYPE_FRAMEBUFFER) { + /* not related to the physical memory manager, but since we're iterating through, we've found something interesting! */ + handle_vesa_multiboot_header(tag); } } } diff --git a/kernel/shell.c b/kernel/shell.c index 132cb95c..0c1ffe9f 100644 --- a/kernel/shell.c +++ b/kernel/shell.c @@ -78,6 +78,7 @@ void print_out_file() { } #endif +#if 0 void print_out_directory() { char *path = "/cd1/boot/"; print_string("\nDIRECTORY LISTING TEST\n\nPath: "); @@ -129,9 +130,10 @@ void print_out_directory() { } free(dir_entries); } +#endif void shell_entry() { - print_string("Total memory:"); + print_string("Perception - Total memory:"); print_size(total_system_memory); size_t free_mem = free_pages * page_size; @@ -144,10 +146,10 @@ void shell_entry() { print_char('\n'); // wait a little bit for stuff to be mounted - size_t i; for (i = 0; i < 50; i++) - asm("hlt"); + //size_t i; for (i = 0; i < 50; i++) + // asm("hlt"); - print_out_directory(); + //print_out_directory(); while(true) { sleep_thread(); asm("hlt");}; } \ No newline at end of file diff --git a/kernel/types.h b/kernel/types.h index 6dc2936e..5c8c5156 100644 --- a/kernel/types.h +++ b/kernel/types.h @@ -6,6 +6,11 @@ typedef unsigned int uint32; typedef unsigned short uint16; typedef unsigned char uint8; +typedef signed long long int int64; +typedef signed int int32; +typedef signed short int16; +typedef signed char int8; + #define NULL 0 #define false 0 #define true 1