diff options
| -rw-r--r-- | Makefile | 5 | ||||
| -rw-r--r-- | README.md | 4 | ||||
| -rw-r--r-- | kernel/kernel.c | 15 | ||||
| -rw-r--r-- | kernel/kernel.h | 6 | ||||
| -rw-r--r-- | kernel/syscalls.c | 2 | ||||
| -rw-r--r-- | kernel/vmem.c | 2 | ||||
| -rw-r--r-- | userspace/paint.c | 93 | ||||
| -rw-r--r-- | userspace/put_pixel.h | 31 | ||||
| -rw-r--r-- | video/compositor.c | 27 | ||||
| -rw-r--r-- | video/compositor.h | 3 |
10 files changed, 163 insertions, 25 deletions
@@ -43,6 +43,7 @@ CFLAGS+=-I./kernel CFLAGS+=-I./driver CFLAGS+=-I./fs CFLAGS+=-I./net +CFLAGS+=-I./video CFLAGS+=-gstabs #CFLAGS+=-fstack-protector-all @@ -93,6 +94,7 @@ SOURCES+=$(wildcard ./terminal/*.c) SOURCES+=$(wildcard ./lib/*/*.c) SOURCES+=$(wildcard ./testing/*.c) SOURCES+=$(wildcard ./net/*.c) +SOURCES+=$(wildcard ./video/*.c) #derive kernel object files OBJECTS=$(patsubst %.c, %.o, $(SOURCES)) @@ -192,7 +194,8 @@ run-qemu: all echo XDOTOOL HACK...&& sleep 0.2 && xdotool search --name "QEMU" windowsize 100 100 && echo XDOTOOL HACK END. & $(QEMU) -enable-kvm $(FOOLOS_ISO) -smp 4 -serial stdio \ -net nic,model=e1000 \ - -net tap,ifname=tap0,script=no,downscript=no + -net tap,ifname=tap0,script=no,downscript=no \ + -vga virtio #-net dump,file=./netfool run-qemu-16: all @@ -107,7 +107,9 @@ Todos * EXTRA: switch to DMA where possible!? * EXTRA: Unit Testing -* EXTRA: GUI / Window Manager (update\_rect, etc..) / double buffering / physical, virtual sizE? virtio ? +* EXTRA: GUI / Window Manager (update\_rect, etc..) / double buffering / physical, virtual sizE? virtio ? / Cairo library + /forum.osdev.org/viewtopic.php?t=10018&p=64358 / vsync +* EXTRA: qemu tcg , slower other cpus * EXTRA: Crazy & Funny terminal effects while typing (idea) * EXTRA: port to arm and berryboot / minicom? diff --git a/kernel/kernel.c b/kernel/kernel.c index e7bef1d..e37f76f 100644 --- a/kernel/kernel.c +++ b/kernel/kernel.c @@ -13,6 +13,7 @@ #include "vmem.h" //-- clean below headers --// +#include "compositor.h" #include "sysfs.h" #include "pci.h" #include "e1000.h" @@ -39,6 +40,12 @@ #include "driver/vesa.h" #include "asm_pit.h" +//ugly? +extern uint32_t kernel_end[]; +extern uint32_t kernel_start[]; + +//TODO: we fear overrun of the initial buffer! +// /* F00L 0S Entry point (called directly from asm/multiboot.asm */ void kernel_main(uint32_t eax,uint32_t ebx) { @@ -54,6 +61,11 @@ void kernel_main(uint32_t eax,uint32_t ebx) klog("Version: git-commit: %s",GIT_REVISION); klog("======================================"); + uint32_t *top_kernel_vmem=VMEM_KERNEL+VMEM_KERNEL_PAGES*4096; + klog("The Kernel was loaded at: 0x%08X - 0x%08X",kernel_start,kernel_end); + klog("0x00000000 - 0x%08X will get identity mapped", VMEM_KERNEL_PAGES*4096); + if(kernel_end>=top_kernel_vmem)kpanic("kernel to big. increase VMEM_KERNEL_PAGES"); + // -- DISABLE LEGACY PIC -- // klog("Remapping & Disabling Programmable Interrupt Controller (PIC) ..."); fixme("io_wait & spurious interrupts"); @@ -122,6 +134,9 @@ void kernel_main(uint32_t eax,uint32_t ebx) uint32_t addr= ext2_inode_blockstart( VMEM_EXT2_RAMIMAGE,inode,0); vesa_init(cfg_multiboot,addr); + klog("Compositor init ..."); + compositor_init(cfg_multiboot->framebuffer_width,cfg_multiboot->framebuffer_height,cfg_multiboot->framebuffer_pitch); + // -- STD STREAMS -- // klog("Standard Streams init ..."); fd_init_std_streams(0,cfg_multiboot->framebuffer_type!=2); diff --git a/kernel/kernel.h b/kernel/kernel.h index 5546071..1dcfb60 100644 --- a/kernel/kernel.h +++ b/kernel/kernel.h @@ -22,6 +22,9 @@ REFERENCES #ifndef FOOLOS_CONFIG_H #define FOOLOS_CONFIG_H +#define VESA_MAX_WIDTH 1920 +#define VESA_MAX_HEIGHT 1080 + //#define FOOLOS_UNIT_TESTING // Run Unit Tests //#define FOOLOS_LOG_OFF // Turn off logging (disables serial port alltogether) //#define FOOLOS_COLORLESS // Turn off colors in log @@ -57,11 +60,12 @@ REFERENCES // minimal space between user and kernel pages 1024 pages! #define VMEM_KERNEL 0x00000000 // 8192 pages (32megs) / identity mapped +#define VMEM_KERNEL_PAGES (1024*8) // VMEM_KERNEL END 0x02000000 #define VMEM_USER_ENV 0x07000000 // 1 page / per user process -#define VMEM_USER_PROG_PAGES 256 +#define VMEM_USER_PROG_PAGES 256*16 #define VMEM_USER_PROG 0x08048000 // ? pages / per user process (usual entry: 0x8048080) #define VMEM_USER_STACK_PAGES 4 // 4 pages / per thread diff --git a/kernel/syscalls.c b/kernel/syscalls.c index 01bc7a5..5bdb76e 100644 --- a/kernel/syscalls.c +++ b/kernel/syscalls.c @@ -134,7 +134,7 @@ int syscall_gettimeofday(struct timeval *tv, struct timezone *tz,uint32_t none1, { uint64_t t=timer_get_ms(); tv->tv_sec=t/1000+2*3600; // add gmt+2 - tv->tv_usec=0;//t-tv->tv_sec*1000; + tv->tv_usec=1000*(t%1000); } // tz struct is obsolote diff --git a/kernel/vmem.c b/kernel/vmem.c index 4af596d..1eaf291 100644 --- a/kernel/vmem.c +++ b/kernel/vmem.c @@ -296,7 +296,7 @@ pdirectory* vmem_kernel_dir() pdirectory* dir = vmem_clean_dir(); - vmem_add_identity(dir,0,1024*8,false);//identity map first 32 megs... + vmem_add_identity(dir,VMEM_KERNEL,VMEM_KERNEL_PAGES,false);//identity map first 32 megs... vmem_add_identity(dir,e1000_addr,32,false);//identity map 32 pages for e1000 vmem_add_remap(dir,fb_addr,VMEM_FRAMEBUFFER,VMEM_FRAMEBUFFER_PAGES,true);//32megs should be enough for 4k (think about pitch) diff --git a/userspace/paint.c b/userspace/paint.c index 15f2a5e..a734ea6 100644 --- a/userspace/paint.c +++ b/userspace/paint.c @@ -3,32 +3,93 @@ #include <stdlib.h> #include <stdio.h> -int main(int argc,char **argv) +#define dimx 640 +#define dimy 480 + +uint32_t backbuffer[dimx*dimy]; + +void paintbuffer() +{ + for (int x = 100; x < dimx-100; x++) + for (int y = 100; y < dimy-100; y++) + { + { + put_pixel(x,y,backbuffer[x+y*640]); + } + } +} + +void unicolor(int color) { - const int dimx = 640, dimy = 480; - int i, j; + for (int x = 100; x < dimx-100; x++) + for (int y = 100; y < dimy-100; y++) + { + { + put_pixel(x,y,color); + } + } +} - FILE *fp = fopen(argv[1], "r"); /* b - binary mode */ +void doscolor(int color,int color2) +{ + int i=0; + + for (int y = 100; y < dimy-100; y++) + for (int x = 100; x < dimx-100; x++) + { + { + if(x%2&&y%2)put_pixel(x,y,color); + else put_pixel(x,y,color2); + } + } +} + +int main(int argc,char **argv) +{ + FILE *fp = fopen("/home/miguel/bg.ppm", "r"); /* b - binary mode */ // (void) fprintf(fp, "P6\n%d %d\n255\n", dimx, dimy); - for (j = 0; j < dimy; ++j) + int i=0; + for (int y = 0; y < dimy; y++) + for (int x = 0; x < dimx; x++) { - 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]); + static unsigned char color[3]; + fread(&color[0], 1, 1, fp); //red + fread(&color[1], 1, 1, fp); //green + fread(&color[2], 1, 1, fp); //blue + + backbuffer[i++]=color[0]*256*256+color[1]*256+color[2]; + + + // if(x<100||x>dimx-100)continue; + // if(y<100||y>dimy-100)continue; + + // put_pixel(x,y,color[0]*256*256+color[1]*256+color[2]);//*256*256+color[1]*256+color[3]); } } + if(argc==2&&!strcmp(argv[1],"demo")) + { + for(int i=0;i<10000;i++) +// while(1) + { + unicolor(0xffffff); + unicolor(0x000000); + doscolor(0x0,0xffffff); + paintbuffer(); + } + return EXIT_SUCCESS; + } + + for(int i=0;i<argc-1;i++) + { + unicolor(strtol(argv[1+i],NULL,16)); + } + if(argc>1) return EXIT_SUCCESS; + + (void) fclose(fp); return EXIT_SUCCESS; } diff --git a/userspace/put_pixel.h b/userspace/put_pixel.h index f4b9332..f879772 100644 --- a/userspace/put_pixel.h +++ b/userspace/put_pixel.h @@ -2,14 +2,38 @@ #define VESA_FRAMEBUFFER 0xf6000000 #define VESA_PITCH 2560 -#define VESA_BPP 32 +#define VESA_BPP 4 +//https://forum.osdev.org/viewtopic.php?t=10018&p=64358 // TODO: what will happen in 24bit mode? -static void put_pixel(int x,int y, int color) + +volatile int c; +int delay() +{ + c++; +} +void put_pixel(int x,int y, uint32_t 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 *p=VESA_FRAMEBUFFER+y*VESA_PITCH+x*VESA_BPP; + uint32_t *pix=p; + *pix=color; + +// for(int i=0;i<100;i++)delay(); +} + + + +void put_pixel_old(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 (x) x = (x*VESA_BPP); // get bytes (divide by 8) if (y) y = (y*VESA_PITCH); //uint8_t *cTemp=VbeModeInfoBlock->physbase; uint8_t *cTemp=VESA_FRAMEBUFFER; @@ -18,4 +42,3 @@ static void put_pixel(int x,int y, int color) cTemp[x+y+1] = (uint8_t)((color>>8) & 0xff); cTemp[x+y+2] = (uint8_t)((color>>16) & 0xff); } - diff --git a/video/compositor.c b/video/compositor.c new file mode 100644 index 0000000..6ca6bd2 --- /dev/null +++ b/video/compositor.c @@ -0,0 +1,27 @@ +#include "compositor.h" + +#include "kernel.h" +#include "kmalloc.h" +#include "log.h" + +#include "lib/string/string.h" + +static uint32_t backbuffer[VESA_MAX_WIDTH*VESA_MAX_HEIGHT]; + +static uint16_t vesa_width; +static uint16_t vesa_height; +static uint16_t vesa_pitch; + +void compositor_init(uint16_t width, uint16_t height, uint16_t pitch) +{ + vesa_width=width; + vesa_height=height; + klog("initialized composing window manager to %d x %d",width,height); +} + +void compositor_swap_buffers() +{ + memcpy(VMEM_FRAMEBUFFER,backbuffer,vesa_height*vesa_pitch/4);// TODO optimize? rects only too? +} + + diff --git a/video/compositor.h b/video/compositor.h new file mode 100644 index 0000000..cef0c47 --- /dev/null +++ b/video/compositor.h @@ -0,0 +1,3 @@ +#include <stdint.h> + +void compositor_init(uint16_t width, uint16_t height, uint16_t pitch); |
