diff options
| author | Miguel <m.i@gmx.at> | 2018-09-16 11:39:36 +0200 |
|---|---|---|
| committer | Miguel <m.i@gmx.at> | 2018-09-16 11:39:36 +0200 |
| commit | 740ae2e69995df37c44fe61f57642ee642982ca2 (patch) | |
| tree | b84ec79e9243fd0fe103fab1c1acc1e91e60f53d | |
| parent | e0449c5adc89eec9f378cb40a56762bf314a80ea (diff) | |
cleanup and starting improve mounts and file access (pipes, sysfiles, ext2)
| -rw-r--r-- | driver/keyboard.c | 6 | ||||
| -rw-r--r-- | driver/keyboard.h | 7 | ||||
| -rw-r--r-- | fs/fd.h | 16 | ||||
| -rw-r--r-- | kernel/exceptions.c | 2 | ||||
| -rw-r--r-- | kernel/interrupts.c | 5 | ||||
| -rw-r--r-- | kernel/scheduler.c | 60 | ||||
| -rw-r--r-- | kernel/scheduler.h | 2 | ||||
| -rw-r--r-- | kernel/smp.c | 2 | ||||
| -rw-r--r-- | xxx/file.c (renamed from fs/file.c) | 0 | ||||
| -rw-r--r-- | xxx/file.h (renamed from fs/file.h) | 0 | ||||
| -rw-r--r-- | xxx/mount.c (renamed from fs/mount.c) | 0 | ||||
| -rw-r--r-- | xxx/mount.h (renamed from fs/mount.h) | 0 |
12 files changed, 75 insertions, 25 deletions
diff --git a/driver/keyboard.c b/driver/keyboard.c index f188cfc..d276f51 100644 --- a/driver/keyboard.c +++ b/driver/keyboard.c @@ -1,10 +1,7 @@ -/// idiots keyboard driver //// -// http://www.computer-engineering.org/ps2keyboard/scancodes1.html - - #include "asm_x86.h" #include "keyboard.h" #include "syscalls.h" +#include "log.h" #include <stdbool.h> @@ -17,6 +14,7 @@ static uint32_t kb_stream; static void put(uint8_t c) { + klog("%c",c); syscall_write(kb_stream,(char *)&c,1); } diff --git a/driver/keyboard.h b/driver/keyboard.h index 03462f3..0e746ba 100644 --- a/driver/keyboard.h +++ b/driver/keyboard.h @@ -1,2 +1,9 @@ +/** + * @file + * +/// idiots keyboard driver //// +// http://www.computer-engineering.org/ps2keyboard/scancodes1.html +// */ + void keyboard_init(uint32_t s); void keyboard_handle(uint8_t in); @@ -8,6 +8,22 @@ #include "fifo.h" +/* +typedef struct +{ + int(* seek)(int offset, int whence); + + int(* read)(char *buf, int len); + int(* wrtie)(char *buf, int len); + + int(* close)(); + int(* stat)(void *buf); + + void *data; //opaque + +}file; +*/ + enum FD_TYPE{ FD_TYPE_FIFO_BUFFERED=1, FD_TYPE_EXT2_FILE=2 diff --git a/kernel/exceptions.c b/kernel/exceptions.c index a69a49e..a092055 100644 --- a/kernel/exceptions.c +++ b/kernel/exceptions.c @@ -127,6 +127,6 @@ uint32_t exception_handle(uint32_t esp, uint32_t irq) task_syscall(SYSCALL_EXIT,task_get_current_pid(),0,0); scheduler_wake_all(); - return scheduler_run(esp); + return scheduler_run(esp,0); } diff --git a/kernel/interrupts.c b/kernel/interrupts.c index 9c485cc..94c1bb1 100644 --- a/kernel/interrupts.c +++ b/kernel/interrupts.c @@ -79,7 +79,7 @@ uint32_t interrupt_handler(uint32_t esp, uint32_t irq) case INTERRUPT_APIC_TIMER: case INTERRUPT_IPI: - esp=scheduler_run(esp); + esp=scheduler_run(esp,0); break; case 255: // default or spurious @@ -89,7 +89,10 @@ uint32_t interrupt_handler(uint32_t esp, uint32_t irq) // reschedule to kernel worker on these if(irq==INTERRUPT_SYSCALL||irq==INTERRUPT_KEYBOARD||irq==INTERRUPT_MOUSE) + { + esp=scheduler_wake_worker(esp); + } // ack all to LAPIC, except software syscalls if(irq!=INTERRUPT_SYSCALL) diff --git a/kernel/scheduler.c b/kernel/scheduler.c index b5d1b34..798d119 100644 --- a/kernel/scheduler.c +++ b/kernel/scheduler.c @@ -13,11 +13,16 @@ #include "vmem.h" #include "spinlock.h" +#include "ringbuffer.h" +#include "keyboard.h" #include "syscalls.h" #include "fs/ext2.h" #define NO_TASK 0xffffffff +//TODO: ugly! +extern ringbuffer kb_in; + static volatile uint32_t pid=1000; static uint32_t nextPID() @@ -105,6 +110,19 @@ volatile void scheduler_init(uint32_t cpu, void *dir) task_pusha(task_list[cpu][2].esp); } +static uint32_t scheduler_schedule(uint32_t idx) +{ + uint32_t cpu=smp_get(SMP_APIC_ID); + if(task_list[cpu][idx].active && !task_list[cpu][idx].syscall) + { + current_task[cpu]=idx; + install_tss(cpu,task_list[cpu][idx].esp0); + x86_set_page_directory(task_list[cpu][idx].vmem); + return task_list[cpu][idx].esp; + } + return 0; +} + // // REMEMBER WE ARE INSIDE AN INTERRUPT HERE - DON'T WASTE TIME! // @@ -115,39 +133,36 @@ volatile void scheduler_init(uint32_t cpu, void *dir) // // we need to return a NEW stack pointer where popa will get the registers the new task requires // -volatile uint32_t scheduler_run(uint32_t oldesp) + +volatile uint32_t scheduler_run(uint32_t oldesp,uint32_t preference) { uint32_t cpu=smp_get(SMP_APIC_ID); uint32_t init=smp_get(SMP_SCHEDULER_INIT); + if(init){ scheduler_init(cpu,x86_get_page_directory()); smp_set(SMP_SCHEDULER_INIT,0); } + else task_list[cpu][current_task[cpu]].esp=oldesp; + uint32_t esp; + esp=scheduler_schedule(preference); // try preference + if(esp)return esp; + for(int i=0;i<MAX_TASKS;i++) { int idx=(current_task[cpu]+1+i)%MAX_TASKS; // schedule round robin style if(idx==2)continue;// skip sleeper here - if(task_list[cpu][idx].active && !task_list[cpu][idx].syscall) // find active non-blocked task - { - //TODO: do NOT do this! deadlock imminent! - //if(cpu==0)klog("schedule %d->%d on cpu %d",current_task[cpu],idx,cpu ); - current_task[cpu]=idx; - install_tss(cpu,task_list[cpu][idx].esp0); - x86_set_page_directory(task_list[cpu][idx].vmem); - return task_list[cpu][idx].esp; - } + esp=scheduler_schedule(idx); // try preference + if(esp)return esp; + } // force the sleeper task - current_task[cpu]=2; - install_tss(cpu,task_list[cpu][2].esp0); - x86_set_page_directory(task_list[cpu][2].vmem); - return task_list[cpu][2].esp; + return scheduler_schedule(2); -// kpanic("nothing to schedule!"); } @@ -232,8 +247,7 @@ uint32_t scheduler_wake_worker(uint32_t oldesp) { uint32_t cpu=smp_get(SMP_APIC_ID); task_list[cpu][0].syscall=false; // wake (syscall misused) - scheduler_wake_all(); - return scheduler_run(oldesp); + return scheduler_run(oldesp,0); } void scheduler_wake_all() @@ -259,6 +273,18 @@ 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)); + } + x86_sti(); + + if(wake)scheduler_wake_all(); + for(int i=0;i<MAX_TASKS;i++) { if(task_list[cpu][i].active,task_list[cpu][i].try&&task_list[cpu][i].syscall) diff --git a/kernel/scheduler.h b/kernel/scheduler.h index fb1f3c8..1911bc6 100644 --- a/kernel/scheduler.h +++ b/kernel/scheduler.h @@ -2,7 +2,7 @@ #include <stdbool.h> // http://hosted.cjmovie.net/TutMultitask.htm -volatile uint32_t scheduler_run(uint32_t oldesp); +volatile uint32_t scheduler_run(uint32_t oldesp,uint32_t preference); volatile uint32_t scheduler_wake_worker(uint32_t oldesp); void scheduler_wake_all(); diff --git a/kernel/smp.c b/kernel/smp.c index a92eee6..d9c994a 100644 --- a/kernel/smp.c +++ b/kernel/smp.c @@ -63,7 +63,7 @@ static void run_smp() apic_enable(); klog("Setup the LAPIC Timer on CPU with lapic_id=0x%x ...",apic_id()); - apic_init_timer(1);// freq 1HZ + apic_init_timer(10);// freq 1HZ klog("Enable Interrupts on CPU with lapic_id=0x%x ...",apic_id()); |
