From 5f6c2bcf0d2f9c416134aba224d90a605f216818 Mon Sep 17 00:00:00 2001 From: Miguel Date: Fri, 28 Sep 2018 11:13:06 +0200 Subject: struggling with scheduler and userprog to view ppm files --- README.md | 7 ++++--- kernel/interrupts.c | 4 ++++ kernel/kernel.c | 2 +- kernel/scheduler.c | 30 +++++++++++++++++++++++++----- kernel/smp.c | 3 +-- userspace/fsh.c | 1 + userspace/paint.c | 35 +++++++++++++++++++++++++++++++++++ userspace/put_pixel.h | 21 +++++++++++++++++++++ userspace/threading.c | 20 +++++++++++++++++--- 9 files changed, 109 insertions(+), 14 deletions(-) create mode 100644 userspace/paint.c create mode 100644 userspace/put_pixel.h diff --git a/README.md b/README.md index c354dd2..4b09107 100644 --- a/README.md +++ b/README.md @@ -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 +#include + +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 + +#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 #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); } } -- cgit v1.2.3