diff options
| -rw-r--r-- | Makefile | 4 | ||||
| -rw-r--r-- | README.md | 4 | ||||
| -rw-r--r-- | driver/keyboard.c | 13 | ||||
| -rw-r--r-- | driver/keyboard.h | 4 | ||||
| -rw-r--r-- | driver/mouse.c | 89 | ||||
| -rw-r--r-- | driver/mouse.h | 15 | ||||
| -rw-r--r-- | driver/timer.c | 2 | ||||
| -rw-r--r-- | driver/vesa.c | 6 | ||||
| -rw-r--r-- | driver/vesa.h | 2 | ||||
| -rw-r--r-- | fs/ext2.c | 8 | ||||
| -rw-r--r-- | fs/ext2.h | 3 | ||||
| -rw-r--r-- | fs/mount.c | 16 | ||||
| -rw-r--r-- | fs/mount.h | 29 | ||||
| -rw-r--r-- | fs/pipe.c | 4 | ||||
| -rw-r--r-- | fs/sysfs.c | 1 | ||||
| -rw-r--r-- | interface/fs.h | 2 | ||||
| -rw-r--r-- | kernel/scheduler.c | 19 | ||||
| -rw-r--r-- | testing/testing.c | 6 |
18 files changed, 126 insertions, 101 deletions
@@ -20,6 +20,10 @@ AS=i686-foolos-as CC=i686-elf-gcc AS=i686-elf-as +#try arm +#CC=arm-none-eabi-gcc +#CC=arm-none-eabi-as + ############ compiler flags ############ #https://gcc.gnu.org/onlinedocs/gcc/Optimize-Options.html @@ -88,6 +88,7 @@ FoolOS was/is tested/developed on the following emulators/machines Todos ----- +* ringbuffers (spinlock on/off, interrupts on/off, read/write blocks of data); * PRIO: Writing to ext2 RAM-image!!!! * PRIO: Fix scheduler. use all cpus! / accounting / queues? * PRIO: threads! semaphores/ mutexes @@ -105,8 +106,9 @@ Todos * EXTRA: switch to DMA where possible!? * EXTRA: Unit Testing -* EXTRA: GUI / Window Manager (update\_rect, etc..) +* EXTRA: GUI / Window Manager (update\_rect, etc..) / double buffering / physical, virtual sizE? virtio ? * EXTRA: Crazy & Funny terminal effects while typing (idea) +* EXTRA: port to arm and berryboot / minicom? Disclaimer ---------- diff --git a/driver/keyboard.c b/driver/keyboard.c index efbcc53..757bbb8 100644 --- a/driver/keyboard.c +++ b/driver/keyboard.c @@ -10,7 +10,7 @@ #include "net/inet.h" -ringbuffer kb_in; +static ringbuffer kb_in; static bool ctrl_l=false; static bool shift_l=false; @@ -41,6 +41,17 @@ uint32_t keyboard_interrupt(uint32_t esp) return esp; } +bool keyboard_worker() +{ + bool wake=false; + while(ringbuffer_has(&kb_in)){ + keyboard_handle(ringbuffer_get(&kb_in)); + wake=true; + } + return wake; +} + + void keyboard_init(uint32_t s) { kb_in=ringbuffer_init(1);// 4096 bytes ringbuffer; diff --git a/driver/keyboard.h b/driver/keyboard.h index 0e746ba..98f1f4e 100644 --- a/driver/keyboard.h +++ b/driver/keyboard.h @@ -5,5 +5,9 @@ // http://www.computer-engineering.org/ps2keyboard/scancodes1.html // */ + +#include <stdbool.h> + void keyboard_init(uint32_t s); void keyboard_handle(uint8_t in); +bool keyboard_worker(); diff --git a/driver/mouse.c b/driver/mouse.c index cebafed..0485096 100644 --- a/driver/mouse.c +++ b/driver/mouse.c @@ -1,3 +1,5 @@ +#include <stdint.h> + #include "mouse.h" #include "ringbuffer.h" @@ -5,24 +7,25 @@ #include "kernel/kernel.h" #include "log.h" #include "driver/vesa.h" - -//http://forum.osdev.org/viewtopic.php?t=10247 -//based on Mouse.inc by SANiK -//License: Use as you wish, except to cause damage - -#include <stdint.h> - #include "asm_x86.h" static volatile uint8_t mouse_cycle; static volatile uint8_t mouse_byte[3]; -volatile int16_t mouse_x; -volatile int16_t mouse_y; -static volatile uint8_t mouse_a; +static volatile int16_t mouse_x; +static volatile int16_t mouse_y; static ringbuffer mouse_in; -uint8_t mouse_read(); +bool mouse_worker() +{ + bool wake=false; + while(ringbuffer_has(&mouse_in)){ + mouse_handler(ringbuffer_get(&mouse_in)); + wake=true; + } + return wake; +} + void mouse_wait(uint8_t a_type) //unsigned char { @@ -51,6 +54,13 @@ void mouse_wait(uint8_t a_type) //unsigned char } } +static uint8_t mouse_read() +{ + //Get's response from mouse + mouse_wait(0); + return x86_inb(0x60); +} + static void mouse_write(uint8_t a_write) { //Wait to be able to send a command @@ -63,31 +73,17 @@ static void mouse_write(uint8_t a_write) x86_outb(0x60, a_write); } -int8_t mouse_get_x() -{ - return mouse_x; -} -int8_t mouse_get_y() -{ - return mouse_y; -} - uint32_t mouse_interrupt(uint32_t esp) { uint8_t b=x86_inb(0x60); ringbuffer_put(&mouse_in,b); - //klog("%d",b); return esp; } void mouse_init() { - interrupt_register(INTERRUPT_MOUSE,&mouse_interrupt); - mouse_in=ringbuffer_init(1);// 4096 bytes ringbuffer; - - mouse_x=mouse_y=0; - mouse_cycle=0; + mouse_in=ringbuffer_init(1);// 4096 bytes ringbuffer; uint8_t _status; //unsigned char @@ -112,18 +108,23 @@ void mouse_init() //Enable the mouse mouse_write(0xF4); mouse_read(); //Acknowledge - + + interrupt_register(INTERRUPT_MOUSE,&mouse_interrupt); } -void mouse_log() +// called as we filled the 3 bytes, everytime. +void mouse_action() { - //klog("%02x / %02x / %02x ",mouse_byte[0], mouse_byte[1],mouse_byte[2]); + //klog("mouse %02x / %02x / %02x ",mouse_byte[0], mouse_byte[1],mouse_byte[2]); //TODO: ignore last packet for 4packets mouse and resync if you get out of sync - if(mouse_byte[0]&0x80||mouse_byte[0]&0x40)return; //skip packet on overflow - if(!(mouse_byte[0]&0x8))kpanic("mouse packets out of sync!?"); // this bit is always 1, otherwise panic! + if(mouse_byte[0]&0x80||mouse_byte[0]&0x40) + { + klog("mouse overflow, skipping packet"); + return; //skip packet on overflow + } - // + //OOOMG!!// if(mouse_byte[1]>127){ mouse_x-=256; mouse_x+=mouse_byte[1]; @@ -132,6 +133,7 @@ void mouse_log() { mouse_x+=mouse_byte[1]; } + if(mouse_byte[2]>127){ mouse_y-=256; mouse_y+=mouse_byte[2]; @@ -153,35 +155,34 @@ void mouse_log() } -//Mouse functions -void mouse_handler()//struct regs *a_r) //struct regs *a_r (not used but just there) +void mouse_handler(uint8_t byte)//struct regs *a_r) //struct regs *a_r (not used but just there) { // X86_IRQ_BEGIN switch(mouse_cycle) { case 0: - mouse_byte[0]=x86_inb(0x60); + mouse_byte[0]=byte; mouse_cycle++; + if(!(mouse_byte[0]&0x8)) + { + klog("mouse out of sync, try resync"); + mouse_cycle--; + // kpanic("mouse packets out of sync!?"); // this bit is always 1, otherwise panic! + } break; case 1: - mouse_byte[1]=x86_inb(0x60); + mouse_byte[1]=byte; mouse_cycle++; break; case 2: - mouse_byte[2]=x86_inb(0x60); + mouse_byte[2]=byte; mouse_cycle=0; - mouse_log(); + mouse_action(); break; } // X86_IRQ_END } -uint8_t mouse_read() -{ - //Get's response from mouse - mouse_wait(0); - return x86_inb(0x60); -} diff --git a/driver/mouse.h b/driver/mouse.h index 95bf088..77a93b8 100644 --- a/driver/mouse.h +++ b/driver/mouse.h @@ -1,2 +1,15 @@ -void mouse_handler(); +/** + * @file + * +//http://forum.osdev.org/viewtopic.php?t=10247 + +//based on Mouse.inc by SANiK +//License: Use as you wish, except to cause damage + */ + +#include <stdint.h> +#include <stdbool.h> + +void mouse_handler(uint8_t byte); void mouse_init(); +bool mouse_worker(); diff --git a/driver/timer.c b/driver/timer.c index 4b8f050..1c1fc05 100644 --- a/driver/timer.c +++ b/driver/timer.c @@ -149,7 +149,7 @@ static uint64_t get_rtc_time() return epoch_seconds; } -uint32_t timer_interrupt(uint32_t esp) +static uint32_t timer_interrupt(uint32_t esp) { asm_pit_tick(); return esp; diff --git a/driver/vesa.c b/driver/vesa.c index ba87e6d..848b0bf 100644 --- a/driver/vesa.c +++ b/driver/vesa.c @@ -1,6 +1,5 @@ #include "kernel/kernel.h" #include "log.h" -//http://wiki.osdev.org/GUI #include <stdarg.h> #include "kernel/mem.h" @@ -8,9 +7,6 @@ #include "lib/printf/printf.h" - -//#define FOOLSOS_SHOW_VESAMODES - static foolfont *deffont; //static vbemodeinfo *VbeModeInfoBlock; @@ -78,7 +74,7 @@ void vesa_console_put_char(uint8_t c,uint8_t color_bg, uint8_t color_fg, uint32_ //PutFont(c, console_x*10,console_y*12, cols[color_fg],cols[color_bg]); //PutFont(c, x*10,y*12, cols[color_bg],cols[color_fg]); - PutFont(c, x*9,y*11, cols[color_bg],cols[color_fg]); + PutFont(c, x*8,y*11, cols[color_bg],cols[color_fg]); // buf[console_x][console_y]=c; diff --git a/driver/vesa.h b/driver/vesa.h index f98e612..63fbd55 100644 --- a/driver/vesa.h +++ b/driver/vesa.h @@ -1,3 +1,5 @@ +//http://wiki.osdev.org/GUI + #include <stdint.h> #include "lib/printf/printf.h" #include "multiboot.h" @@ -1,9 +1,11 @@ +#include "ext2.h" + #include <stdbool.h> #include <stdint.h> + #include "mount.h" #include "kernel.h" -#include "ext2.h" #include "log.h" @@ -37,7 +39,8 @@ typedef struct ext2_superblock_struct uint16_t gid_reserved; }ext2_superblock; -/* we dont use this +/* we dont use this for now */ +/* typedef struct ext2_superblock_ext_struct { uint32_t first_inode; @@ -268,7 +271,6 @@ uint32_t ext2_read_inode(uint32_t ext2_start_addr, int inode_nr, char *buf, uint } return count; - } int ext2_read_dir(uint32_t ext2_start_addr, int inode_nr, fs_dirent *dirs, uint32_t *pos) @@ -4,7 +4,8 @@ // ======================= // // based on osdev wiki article: http://wiki.osdev.org/Ext2 -// root directory is inode 2 per definition! +// The root directory is inode 2 per definition! +// // we do not care about files >4gb (no triply linked lists and no size_high) // we also use only name_length_low so max length is 255 chars // @@ -6,7 +6,7 @@ #include "log.h" #include "lib/string/string.h" -// temporary + #include "fd.h" static mount mounts[MAX_MOUNTS]; @@ -17,7 +17,7 @@ char *mount_type_to_str(uint32_t t) switch(t) { case MOUNT_TYPE_EXT2: return "EXT2"; - case MOUNT_TYPE_PIPES: return "PIPES"; +// case MOUNT_TYPE_PIPES: return "PIPES"; case MOUNT_TYPE_SYS: return "SYSFS"; } return "UNKNOWN"; @@ -30,22 +30,12 @@ void mount_add(mount mnt) klog("Mounted %s at %s",mount_type_to_str(mnt.type),mnt.path); } -void mount_dump() -{ - for(int i=0;i<mounts_count;i++) - { - mount *m=&mounts[i]; - klog("%s mounted at: %s ",mount_type_to_str(m->type),m->path); - } -} - void mount_sysfs(ringbuffer *r, void (*f)(ringbuffer *r,char *fmt, ...)) { - f(r,"mounts:"); for(int i=0;i<mounts_count;i++) { mount *m=&mounts[i]; - f(r,"%s mounted at: %s ",mount_type_to_str(m->type),m->path); + f(r,"%s at %s",mount_type_to_str(m->type),m->path); } } @@ -1,30 +1,34 @@ /** * @file + * * Simple mount point manager * ========================== * - * Add up to MAX_MOUNTS (as defined in kernel.h) mounts and use - * mount_file_open() and mount_read_dir() to transparently - * be dispatch the underlying commands to them based on the supplied paths. + * Add up to MAX_MOUNTS (as defined in kernel.h) mountpoints and use the + * provided functions to transparently dispatch them to the undelying + * infrastructure provided via the mount_struct structures + * + * unt_file_open() and mount_read_dir() * - * Mount directories should exist on root direcotry '/' + * The mount directories itself should exist inside the + * root direcotry '/'. */ #ifndef MOUNT_H #define MOUNT_H #include <stdint.h> -#include "interface/fs.h" // fs_dirent for read_dir -#include "fd.h" // file descriptor returned by open + +#include "interface/fs.h" // provides fs_dirent structure for read_dir() +#include "fd.h" // file descriptor returned by open /** the possible values for mount_struct.type */ enum MOUNT_TYPE{ MOUNT_TYPE_EXT2 = 1, - MOUNT_TYPE_PIPES = 2, - MOUNT_TYPE_SYS = 3 + MOUNT_TYPE_SYS = 3 }; -/** struct telling all we need about a single mountpoint */ +/** struct providing all the required info, about a single mountpoint */ typedef struct mount_struct { uint32_t type; // MOUNT_TYPE @@ -34,13 +38,10 @@ typedef struct mount_struct fd (*mount_file_open)(struct mount_struct*, char *path); int (*mount_read_dir) (struct mount_struct*, char *path, fs_dirent *dirs, uint32_t *pos); - void *data; //opaque data + void *data; // pointer to some opaque private data }mount; -/** dumps mount info to klog */ -void mount_dump(); - /** adds a new mountpoints */ void mount_add(mount mnt); @@ -50,7 +51,7 @@ fd mount_file_open(char *path); /** TODO: should use fd number instead of PATH on each call*/ int mount_read_dir (char *path, fs_dirent *dirs, uint32_t *pos); -/** sysfs interface */ +/** sysfs interface / exposing status via /sysfs/ file */ void mount_sysfs(ringbuffer *r, void (*f)(ringbuffer *r,char *fmt, ...)); #endif @@ -17,14 +17,13 @@ fd pipe_file_open(mount *m,char *path) return a; } +/* int pipe_read_dir(mount *m,char *path, fs_dirent *dirs, uint32_t *pos) { - /* if(*pos>=count)return 0; memcpy(dirs->name,names[*pos],strlen(names[*pos])+1); *pos+=1; return 1; - */ return 0; } @@ -37,3 +36,4 @@ void pipe_mount(char* path) m.mount_read_dir=pipe_read_dir; mount_add(m); } +*/ @@ -15,6 +15,7 @@ static uint32_t map[]={mem_sysfs,mem_sysfs_set, kmalloc_sysfs,NULL, mount_sysfs,NULL, }; + static uint32_t count=3; /* mount interface */ diff --git a/interface/fs.h b/interface/fs.h index 0a8b59e..5930ffe 100644 --- a/interface/fs.h +++ b/interface/fs.h @@ -17,7 +17,7 @@ typedef struct fs_dirent_struct { uint32_t mount; //mount identifier uint32_t inode; //inode number or similar - uint8_t type; //FILE OR DIR + uint8_t type; //FILE OR DIR (FS_FILE_TYPE) char name[255]; }fs_dirent; diff --git a/kernel/scheduler.c b/kernel/scheduler.c index 5382053..20b69ed 100644 --- a/kernel/scheduler.c +++ b/kernel/scheduler.c @@ -16,15 +16,13 @@ #include "spinlock.h" #include "ringbuffer.h" #include "keyboard.h" +#include "mouse.h" #include "syscalls.h" #include "fs/ext2.h" #define NO_TASK 0xffffffff -//TODO: ugly! -extern ringbuffer kb_in; - -static volatile uint32_t pid=0; +static volatile uint32_t pid=0; // holds next pid, to be assigned to a process. static uint32_t nextPID() { @@ -278,13 +276,12 @@ void task_syscall_worker() while(1) { bool wake=false; - - // TODO: move to user programm! - x86_cli(); // disable temporarily mouse/kb/timer interrupts. - while(ringbuffer_has(&kb_in)){ - wake=true; - keyboard_handle(ringbuffer_get(&kb_in)); - } + + + //TODO: would be enough only to lock during ringbuffer acces!? + x86_cli(); // disable temporarily mouse/kb/timer interrupts. + wake|=keyboard_worker(); + wake|=mouse_worker(); x86_sti(); if(wake)scheduler_wake_all(); diff --git a/testing/testing.c b/testing/testing.c index 7646b95..269774c 100644 --- a/testing/testing.c +++ b/testing/testing.c @@ -36,10 +36,10 @@ void testing_mount() #endif testlog ("= UNIT TESTING MOUNTS ="); testing_mount_add("/",MOUNT_TYPE_EXT2); - testing_mount_add("/pipes/",MOUNT_TYPE_PIPES); - testing_mount_add("/pipes/input/",MOUNT_TYPE_PIPES); +// testing_mount_add("/pipes/",MOUNT_TYPE_PIPES); +// testing_mount_add("/pipes/input/",MOUNT_TYPE_PIPES); testing_mount_add("/sys/",MOUNT_TYPE_SYS); - mount_dump(); +// mount_dump(); // testing_get_mount("pipes/input"); testing_get_mount("/dupa"); testing_get_mount("/pipe"); |
