diff options
| author | Miguel <m.i@gmx.at> | 2018-09-28 11:13:06 +0200 |
|---|---|---|
| committer | Miguel <m.i@gmx.at> | 2018-09-28 11:13:06 +0200 |
| commit | 5f6c2bcf0d2f9c416134aba224d90a605f216818 (patch) | |
| tree | 6fda812ecd1ce06f743c292f3d0495d0b2941bbd | |
| parent | 4ddca59e2c07a98988ffb07571d2b35c4c90f5ac (diff) | |
struggling with scheduler and userprog to view ppm files
| -rw-r--r-- | README.md | 7 | ||||
| -rw-r--r-- | kernel/interrupts.c | 4 | ||||
| -rw-r--r-- | kernel/kernel.c | 2 | ||||
| -rw-r--r-- | kernel/scheduler.c | 30 | ||||
| -rw-r--r-- | kernel/smp.c | 3 | ||||
| -rw-r--r-- | userspace/fsh.c | 1 | ||||
| -rw-r--r-- | userspace/paint.c | 35 | ||||
| -rw-r--r-- | userspace/put_pixel.h | 21 | ||||
| -rw-r--r-- | userspace/threading.c | 20 |
9 files changed, 109 insertions, 14 deletions
@@ -88,13 +88,14 @@ FoolOS was/is tested/developed on the following emulators/machines Todos ----- -* ringbuffers (spinlock on/off, interrupts on/off, read/write blocks of data); +* PRIO: 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 +* PRIO: semaphores/ mutexes * PRIO: return value / argv / env * PRIO: create/remove pages on demand (sbrk, stack, load prog) -* PRIO: grow kernel vmem? +* PRIO: grow kernel memory! + * PRIO: optimized Mouse & KB processing in seperate task. (Kb all chars and different layouts, arrow keys, ctrl-c etc) * NETWORKING: tcp/ip stack/ traceroute / arptables / sockets! / diff --git a/kernel/interrupts.c b/kernel/interrupts.c index 5a788c8..387b822 100644 --- a/kernel/interrupts.c +++ b/kernel/interrupts.c @@ -88,6 +88,10 @@ uint32_t interrupt_handler(uint32_t esp, uint32_t irq) break; case INTERRUPT_APIC_TIMER: // frequency is configured in smp.c + esp=scheduler_run(esp,-1); + apic_eoi(); + break; + case INTERRUPT_IPI: // inter process interrupt esp=scheduler_run(esp,0); apic_eoi(); diff --git a/kernel/kernel.c b/kernel/kernel.c index f926139..e7bef1d 100644 --- a/kernel/kernel.c +++ b/kernel/kernel.c @@ -62,7 +62,7 @@ void kernel_main(uint32_t eax,uint32_t ebx) // -- GET CONFIGS -- // klog("Read Multiboot Structures ..."); multiboot_information *cfg_multiboot; - cfg_multiboot=multiboot_read(eax, ebx,true); // true for silent + cfg_multiboot=multiboot_read(eax, ebx,false); // true for silent // elf_multiboot_read(cfg_multiboot); // just show kernel section headers klog("Read Advanced Power Configuration Interface (ACPI) Structures ..."); diff --git a/kernel/scheduler.c b/kernel/scheduler.c index 0c24f94..23ed7b2 100644 --- a/kernel/scheduler.c +++ b/kernel/scheduler.c @@ -120,8 +120,10 @@ static uint32_t scheduler_schedule(uint32_t idx) if(task_list[cpu][idx].active && !task_list[cpu][idx].syscall) { if(current_task[cpu]!=0)last_task[cpu]=current_task[cpu]; - current_task[cpu]=idx; + + // klog("%d idx %d",last_task[cpu],current_task[cpu]); + install_tss(cpu,task_list[cpu][idx].esp0); x86_set_page_directory(task_list[cpu][idx].vmem); return task_list[cpu][idx].esp; @@ -153,19 +155,36 @@ volatile uint32_t scheduler_run(uint32_t oldesp,uint32_t preference) else task_list[cpu][current_task[cpu]].esp=oldesp; uint32_t esp; - esp=scheduler_schedule(preference); // try preference - if(esp)return esp; + if(preference!=-1) + { + esp=scheduler_schedule(preference); // try preference + if(esp)return esp; + + if(current_task[cpu]==0)// we have interrupted a task with ring1 work + { + esp=scheduler_schedule(last_task[cpu]); // try preference + if(esp)return esp; + } + } + else + { + //klog("preempt %d", last_task[cpu]); + } for(int i=0;i<MAX_TASKS;i++) { int idx=(last_task[cpu]+1+i)%MAX_TASKS; // schedule round robin style + if(preference==-1&&idx==0)continue; if(idx==preference||idx==2)continue;// skip sleeper and preferred tasks here. esp=scheduler_schedule(idx); - if(esp)return esp; + if(esp){ + //klog("%d",idx); + return esp; + } } // force the sleeper task... @@ -349,9 +368,10 @@ void task_syscall_worker() task_list[cpu][0].syscall=true; // sleep (syscall misused) } x86_sti(); + if(nowork) { - __asm__("int $0x81"); // wake scheduler! + __asm__("int $0x81"); // wake scheduler! with IPI } } } diff --git a/kernel/smp.c b/kernel/smp.c index e204b32..f23d15a 100644 --- a/kernel/smp.c +++ b/kernel/smp.c @@ -65,10 +65,9 @@ void run_smp() apic_enable(); klog("Setup the LAPIC Timer on CPU with lapic_id=0x%x ...",apic_id()); - apic_init_timer(2);// freq 2HZ + apic_init_timer(1);// freq x HZ klog("Enable Interrupts on CPU with lapic_id=0x%x ...",apic_id()); - asm_smp_unlock(); smp_set(SMP_APIC_ID,apic_id()); diff --git a/userspace/fsh.c b/userspace/fsh.c index 5609256..81c2bce 100644 --- a/userspace/fsh.c +++ b/userspace/fsh.c @@ -224,6 +224,7 @@ bool process(char *buf) i++; } } + else // otherwise treat command as exectutable and send to execve { int pid=_fork(); diff --git a/userspace/paint.c b/userspace/paint.c new file mode 100644 index 0000000..15f2a5e --- /dev/null +++ b/userspace/paint.c @@ -0,0 +1,35 @@ +#include "put_pixel.h" + +#include <stdlib.h> +#include <stdio.h> + +int main(int argc,char **argv) +{ + const int dimx = 640, dimy = 480; + int i, j; + + FILE *fp = fopen(argv[1], "r"); /* b - binary mode */ + +// (void) fprintf(fp, "P6\n%d %d\n255\n", dimx, dimy); + + for (j = 0; j < dimy; ++j) + { + for (i = 0; i < dimx; ++i) + { + static unsigned char color[3]; +// color[0] = i % 256; /* red */ + // color[1] = j % 256; /* green */ + // color[2] = (i * j) % 256; /* blue */ + // + fread(&color[0], 1, 1, fp); + fread(&color[1], 1, 1, fp); + fread(&color[2], 1, 1, fp); + + put_pixel(i,j,color[0]*256*256+color[1]*256+color[3]); + } + } + + (void) fclose(fp); + return EXIT_SUCCESS; +} + diff --git a/userspace/put_pixel.h b/userspace/put_pixel.h new file mode 100644 index 0000000..f4b9332 --- /dev/null +++ b/userspace/put_pixel.h @@ -0,0 +1,21 @@ +#include <stdint.h> + +#define VESA_FRAMEBUFFER 0xf6000000 +#define VESA_PITCH 2560 +#define VESA_BPP 32 + +// TODO: what will happen in 24bit mode? +static void put_pixel(int x,int y, int color) +{ + //do not write memory outside the screen buffer, check parameters against the VBE mode info +// if (x<0 || x>vesaXres|| y<0 || y>vesaYres) return; + if (x) x = (x*(VESA_BPP>>3)); // get bytes (divide by 8) + if (y) y = (y*VESA_PITCH); + //uint8_t *cTemp=VbeModeInfoBlock->physbase; + uint8_t *cTemp=VESA_FRAMEBUFFER; + + cTemp[x+y] = (uint8_t)(color & 0xff); + cTemp[x+y+1] = (uint8_t)((color>>8) & 0xff); + cTemp[x+y+2] = (uint8_t)((color>>16) & 0xff); +} + diff --git a/userspace/threading.c b/userspace/threading.c index 2ceaad3..2fd3b5e 100644 --- a/userspace/threading.c +++ b/userspace/threading.c @@ -1,17 +1,31 @@ #include <stdio.h> #include "newcalls.h" +volatile unsigned int c=0xbeef; + +int inc(int i) +{ + i++; + if(i==0)i=1; + return i; +} + int main() { - int thread=_clone(); // we want two threads + + int thread=_clone(); if(thread!=0) // thread 1 { - while(1) printf("a\n"); + while(1) + { + c++; + } } + else // thread2 { - while(1) printf("b\n"); + while(1) printf("0x%08x\n",c); } } |
