Skip to content

Commit

Permalink
PS/2 mouse, VESA and VGA graphics, start of a window manager
Browse files Browse the repository at this point in the history
  • Loading branch information
AndrewAPrice committed Dec 1, 2014
1 parent c6c6259 commit f77524c
Show file tree
Hide file tree
Showing 14 changed files with 87 additions and 28 deletions.
9 changes: 8 additions & 1 deletion 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
}
5 changes: 5 additions & 0 deletions kernel/build.sh
Expand Up @@ -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
Expand All @@ -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
2 changes: 1 addition & 1 deletion kernel/ide.c
Expand Up @@ -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 =
Expand Down
9 changes: 8 additions & 1 deletion kernel/io.c
Expand Up @@ -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));
Expand All @@ -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));
Expand Down
3 changes: 2 additions & 1 deletion kernel/io.h
Expand Up @@ -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);
Expand Down
1 change: 0 additions & 1 deletion kernel/isr.c
Expand Up @@ -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);
Expand Down
8 changes: 4 additions & 4 deletions 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] =
Expand Down
1 change: 0 additions & 1 deletion kernel/liballoc_hooks.c
Expand Up @@ -59,7 +59,6 @@ void* liballoc_alloc(size_t pages) {
flush_virtual_page(addr);
}


return (void *)start;
}

Expand Down
17 changes: 15 additions & 2 deletions kernel/main.c
Expand Up @@ -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"
Expand All @@ -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
Expand All @@ -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();

Expand All @@ -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 */
Expand Down
21 changes: 11 additions & 10 deletions kernel/multiboot.asm
Expand Up @@ -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
Expand Down
16 changes: 14 additions & 2 deletions kernel/pci.c
Expand Up @@ -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;
Expand Down Expand Up @@ -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 */
Expand Down Expand Up @@ -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: ");
Expand All @@ -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) {
Expand Down
8 changes: 8 additions & 0 deletions kernel/physical_allocator.c
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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);
}
}
}
Expand Down
10 changes: 6 additions & 4 deletions kernel/shell.c
Expand Up @@ -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: ");
Expand Down Expand Up @@ -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;
Expand All @@ -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");};
}
5 changes: 5 additions & 0 deletions kernel/types.h
Expand Up @@ -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

0 comments on commit f77524c

Please sign in to comment.