From fe8180d88540bfa96595dcc58290de5425e534e3 Mon Sep 17 00:00:00 2001 From: Miguel Date: Fri, 5 Oct 2018 23:41:51 +0200 Subject: drunken proggin --- driver/keyboard.c | 2 ++ driver/mouse.c | 1 - fs/fd.c | 6 ++++++ kernel/interrupts.c | 7 +++++-- kernel/scheduler.c | 10 +++++----- kernel/syscalls.c | 46 ++++++++++++++++++++++++++++++++-------------- kernel/syscalls.h | 4 +++- userspace/init.c | 18 +++++++++++++----- userspace/xterm/terminal.c | 16 ++++++++++++++++ userspace/xterm/vesa.c | 21 ++++----------------- userspace/xterm/vesa.h | 2 ++ userspace/xterm/xterm.c | 46 ++++++++++++++++++++++++++++++++++++++++++++++ video/compositor.c | 31 ++++++++++++++++++++++++++++--- video/compositor.h | 4 +++- 14 files changed, 165 insertions(+), 49 deletions(-) create mode 100644 userspace/xterm/vesa.h diff --git a/driver/keyboard.c b/driver/keyboard.c index 2be9c12..87cd7d7 100644 --- a/driver/keyboard.c +++ b/driver/keyboard.c @@ -5,6 +5,7 @@ #include "e1000.h" #include "kmalloc.h" #include "interrupts.h" +#include "compositor.h" #include @@ -30,6 +31,7 @@ extern struct netdev e1000_dev; static void put(uint8_t c) { // syscall_generic(SYSCALL_WRITE,kb_stream, (char *)&c , 1, 0); + compositor_kb_handle(c); } uint32_t keyboard_interrupt(uint32_t esp) diff --git a/driver/mouse.c b/driver/mouse.c index 274c9a5..0c48a5f 100644 --- a/driver/mouse.c +++ b/driver/mouse.c @@ -155,7 +155,6 @@ void mouse_action() if(mouse_y>=1080)mouse_y=1080-1; compositor_mouse_handle(mouse_x,1080-mouse_y, mouse_byte[0]); - } void mouse_handler(uint8_t byte)//struct regs *a_r) //struct regs *a_r (not used but just there) diff --git a/fs/fd.c b/fs/fd.c index 1215679..2964883 100644 --- a/fs/fd.c +++ b/fs/fd.c @@ -10,31 +10,37 @@ bool fd_write(fd* f,uint8_t c) { + if(!f->write)kpanic("no write func") return f->write(f->data,c); } uint8_t fd_read(fd* f) { + if(!f->read)kpanic("no read func") return f->read(f->data); } bool fd_has(fd* f) { + if(!f->has)kpanic("no has func") return f->has(f->data); } bool fd_eof(fd* f) { + if(!f->eof)kpanic("no eof func") return f->eof(f->data); } bool fd_close(fd* f) { + if(!f->close)kpanic("no close func") return f->close(f->data); } fd fd_dupl(fd* f) { + if(!f->dupl)kpanic("no dupl func") return f->dupl(f); } diff --git a/kernel/interrupts.c b/kernel/interrupts.c index 94ed54a..ce1d7c7 100644 --- a/kernel/interrupts.c +++ b/kernel/interrupts.c @@ -74,6 +74,11 @@ uint32_t interrupt_handler(uint32_t esp, uint32_t irq) return esp; } + if(irq==INTERRUPT_APIC_TIMER) + { + compositor_wake(); + } + if(irq==INTERRUPT_APIC_TIMER || irq==INTERRUPT_IPI) { esp=scheduler_run(esp,-1); @@ -93,8 +98,6 @@ uint32_t interrupt_handler(uint32_t esp, uint32_t irq) kpanic("unhandled interrupt %d",irq); - - /* if(handlers[irq]!=0) { diff --git a/kernel/scheduler.c b/kernel/scheduler.c index 678b418..6ee4416 100644 --- a/kernel/scheduler.c +++ b/kernel/scheduler.c @@ -101,7 +101,7 @@ volatile void scheduler_init(uint32_t cpu, void *dir) task_list[cpu][1].esp = VMEM_USER_STACK_TOP-0x200-8; task_list[cpu][1].esp0 = kballoc(4)+4*4096; // esp0 needed by user space tasks strcpy(task_list[cpu][1].name,"userspace init"); - //fd_init_std_streams(task_list[cpu][1].pid,0); + fd_init_std_streams(task_list[cpu][1].pid); // sleeper task_list[cpu][2].parent=0; @@ -333,14 +333,14 @@ void task_syscall_worker() bool wake_mouse=false; //TODO: would be enough only to lock during ringbuffer acces!? + //TODO: no locking should be required at all!!! //x86_cli(); // disable temporarily mouse/kb/timer interrupts. - //wake|=keyboard_worker(); + wake|=keyboard_worker(); wake_mouse|=mouse_worker(); //x86_sti(); if(wake_mouse)compositor_swap_buffers(); - - //if(wake)scheduler_wake_all(); + if(wake)scheduler_wake_all(); //if(cpu==0)compositor_swap_buffers(); @@ -484,7 +484,7 @@ volatile int task_add_win(uint32_t pid) struct pdirectory *vmem=x86_get_page_directory();//task_list[cpu][idx].vmem; vmem_add_framebuffer(vmem); klog("add win to compositor"); - compositor_add_window(vmem); + compositor_add_window(vmem,pid); return 0; } diff --git a/kernel/syscalls.c b/kernel/syscalls.c index 4bf63fc..130e6dd 100644 --- a/kernel/syscalls.c +++ b/kernel/syscalls.c @@ -31,36 +31,46 @@ static fd fds[MAX_PID][MAX_FD]; static bool open_fd[MAX_PID][MAX_FD]; -void fd_init_std_streams(uint32_t pid,bool fb) +fd *get_fd(uint32_t pid,uint32_t file) { + return &(fds[pid][file]); +} + +void fd_init_std_streams(uint32_t pid) +{ + // fds[pid][0]=fd_from_ringbuffer(); + // open_fd[pid][0]=true; + return; + static bool first=true; if(pid==0&&first) { first=false; //stdin / stdout /stderr fds[0][0]=fd_from_ringbuffer(); - if(!fb) // ega text mode + +// if(!fb) // ega text mode { - fds[0][1]=fd_from_term(); - fds[0][2]=fd_from_term(); + // fds[0][1]=fd_from_term(); + // fds[0][2]=fd_from_term(); } - else +// else { - fds[0][1]=fd_from_fb_term(); - fds[0][2]=fd_from_fb_term(); + //fds[0][1]=fd_from_fb_term(); + //fds[0][2]=fd_from_fb_term(); } open_fd[0][0]=true; - open_fd[0][1]=true; - open_fd[0][2]=true; +// open_fd[0][1]=true; +// open_fd[0][2]=true; } else { fds[pid][0]=fds[0][0]; - fds[pid][1]=fds[0][1]; - fds[pid][2]=fds[0][2]; +// fds[pid][1]=fds[0][1]; +// fds[pid][2]=fds[0][2]; open_fd[pid][0]=true; - open_fd[pid][1]=true; - open_fd[pid][2]=true; +// open_fd[pid][1]=true; +// open_fd[pid][2]=true; } } // @@ -178,6 +188,7 @@ int syscall_lseek(int file,int ptr,int dir,uint32_t pid) // TODO: /dev/console or /dev/tty1 - /dev/ttyN int syscall_write(int file, char *buf, int len,uint32_t pid) { + if(!open_fd[pid][file])kpanic("writing to closed file descriptor"); for(int i=0;i #include +#include "fd.h" #define SYSCALL_EXIT 60 #define SYSCALL_EXECVE 64 @@ -46,7 +47,8 @@ #define SYSCALL_GUI_WIN 88 /** Todo move somewhere else and init per process , think how to make thread safe */ -void fd_init_std_streams(uint32_t pid, bool use_framebuffer); +void fd_init_std_streams(uint32_t pid); +fd *get_fd(uint32_t pid,uint32_t file); /** returns string representation of the syscall from its number */ char* syscall_get_name(uint32_t num); diff --git a/userspace/init.c b/userspace/init.c index d07942b..645acd9 100644 --- a/userspace/init.c +++ b/userspace/init.c @@ -1,31 +1,38 @@ #include #include #include "put_pixel.h" +#include "newcalls.h" + int main(int argc, char **argv) { // loop forever and spawn shells if the top-shell exits - _execve("/bin/xterm",NULL,NULL); + int fds[2]; + _pipe(fds); - _execve("/bin/vesa",NULL,NULL); int pid=_fork(); if(pid==0) { + _execve("/bin/xterm",NULL,NULL); int pid=_fork(); + if(pid==0) { - _execve("/bin/pain1",NULL,NULL); + _execve("/bin/xterm",NULL,NULL); } else { - _execve("/bin/vesa",NULL,NULL); + _execve("/bin/xterm",NULL,NULL); } } else { + _execve("/bin/xterm",NULL,NULL); + while(1); // block + int pid=_fork(); if(pid==0) { @@ -33,7 +40,8 @@ int main(int argc, char **argv) } else { - _execve("/bin/pain3",NULL,NULL); + _execve("/bin/pain1",NULL,NULL); + //_execve("/bin/pain3",NULL,NULL); } } diff --git a/userspace/xterm/terminal.c b/userspace/xterm/terminal.c index 4f321dd..ba7986e 100644 --- a/userspace/xterm/terminal.c +++ b/userspace/xterm/terminal.c @@ -6,6 +6,8 @@ #include #include +#include "vesa.h" + #define NPAR_START 1000 #define TERM_WIDTH 80 #define TERM_HEIGHT 24 @@ -290,6 +292,7 @@ static void reset(terminal_tty *tty) tty->command_l=0; } + terminal_tty terminal_init(term_out *screen,term_in *input) { terminal_tty tty; @@ -326,6 +329,19 @@ terminal_tty terminal_init(term_out *screen,term_in *input) return tty; } +term_out tout; +terminal_tty tty; +terminal_tty* terminal_init_vesa() +{ + + tout.put_char=vesa_console_put_char; + tout.update_cursor=vesa_update_cursor; + + tty=(terminal_init(&tout,NULL)); + return &tty; + + +} // send one ASCII character to the terminal void terminal_put(terminal_tty *tty, uint8_t c) diff --git a/userspace/xterm/vesa.c b/userspace/xterm/vesa.c index d38f3f2..e795cc8 100644 --- a/userspace/xterm/vesa.c +++ b/userspace/xterm/vesa.c @@ -2,6 +2,7 @@ #include #include #include "../newcalls.h" +#include "vesa.h" #define VMEM_USER_FRAMEBUFFER 0xfa000000 @@ -134,6 +135,9 @@ void vesa_set_physbase(uint32_t addr) uint32_t vesa_init() { + + FILE *f=fopen("/doc/fonts/binfont.bin","r"); + fread(deffont,10,95,f); //inf->framebuffer_type /* @@ -351,20 +355,3 @@ void vesa_init_doublebuff() VbeModeInfoBlock->physbase=buffer; } */ - -int main() -{ - FILE *f=fopen("/doc/fonts/binfont.bin","r"); - fread(deffont,10,95,f); - - vesa_init(); - - _gui_win(); - - while(1) - { - vesa_console_put_char('X' ,15, 0, 5, 5); - _gui_rect(); - } - -} diff --git a/userspace/xterm/vesa.h b/userspace/xterm/vesa.h new file mode 100644 index 0000000..16a52f1 --- /dev/null +++ b/userspace/xterm/vesa.h @@ -0,0 +1,2 @@ +void vesa_update_cursor(uint32_t col,uint32_t row); +void vesa_console_put_char(uint8_t c,uint8_t color_bg, uint8_t color_fg, uint32_t x, uint32_t y); diff --git a/userspace/xterm/xterm.c b/userspace/xterm/xterm.c index 10b222c..96389a9 100644 --- a/userspace/xterm/xterm.c +++ b/userspace/xterm/xterm.c @@ -1,2 +1,48 @@ #include +int main() +{ + _gui_win(); + + int xterm_in[2]; + int xterm_out[2]; + + _pipe(xterm_in); + _pipe(xterm_out); + + + vesa_init(); + void *tty=terminal_init_vesa(); + + int pid=_fork(); + + if(!pid) + { + _close(xterm_in[1]); + _close(xterm_out[0]); + + _dup2(xterm_in[0],0);// stdin + _dup2(xterm_out[1],1);// stdout + _dup2(xterm_out[1],2);// stderr + + char *argv1[]={"/bin/fsh",0}; + char *env1[]={"HOME=/home/miguel","PS1=\033[34m$\033[37m","PWD=/home/miguel","PATH=/bin","TERM=fool-term",0}; + + _execve("/bin/fsh",argv1,env1); // replace process with our foolshell :) + } + + _close(xterm_in[0]); + _close(xterm_out[1]); + + _dup2(xterm_in[1],1); // compositor writes here. + + while(1) + { + char buf[1]; + _read(xterm_out[0],buf,1); // show what foolshell writes to its stdout/stderr + + _gui_rect(); //lock + terminal_put(tty,buf[0]); + _gui_rect(); //unlock + } +} diff --git a/video/compositor.c b/video/compositor.c index d0d5bfa..5dca7bd 100644 --- a/video/compositor.c +++ b/video/compositor.c @@ -1,5 +1,6 @@ #include "compositor.h" +#include "syscalls.h" #include "kernel.h" #include "kmalloc.h" #include "log.h" @@ -25,6 +26,7 @@ struct window uint16_t height; uint32_t color; uint16_t active; + uint32_t pid; struct pdirectory *vmem; }; @@ -42,6 +44,8 @@ static uint16_t mouse_x=100; static uint16_t mouse_y=100; static uint16_t mouse_k; +static bool skip_render; + static void put_pixel(int x,int y, uint32_t color) { vmem[y*vesa_width+x]=color; @@ -49,11 +53,11 @@ static void put_pixel(int x,int y, uint32_t color) static void put_win(struct window *win) { - struct pdirectory* mydir=x86_get_page_directory(); - + struct pdirectory* mydir; if(win->vmem) { x86_cli();// do not reschedule us til ready! + mydir=x86_get_page_directory(); x86_set_page_directory(win->vmem); } @@ -179,7 +183,7 @@ void compositor_del_window(uint32_t addr) } } -void compositor_add_window(uint32_t addr) +void compositor_add_window(uint32_t addr,uint32_t pid) { klog("window added"); if (next_window>=MAX_WINDOWS)kpanic("max number of windows reached. increase MAX_WINDOWS"); @@ -198,6 +202,7 @@ void compositor_add_window(uint32_t addr) windows[0].color=0xAAAA00AA; windows[0].active=0; windows[0].vmem=addr; + windows[0].pid=pid; next_window++; } @@ -209,8 +214,16 @@ void compositor_init(uint16_t width, uint16_t height, uint16_t pitch) klog("initialized composing window manager to %d x %d",width,height); } +void compositor_wake() +{ + skip_render=false; +} + void compositor_swap_buffers() { + if(skip_render)return; + skip_render=true; + static bool first=true; // if(!first)return; // klog("swap"); @@ -226,6 +239,18 @@ void compositor_swap_buffers() memcpy(VMEM_FRAMEBUFFER,backbuffer,vesa_height*vesa_width*4);// TODO optimize? rects only too? first=false; } +void compositor_kb_handle(char c) +{ + for(int i=0;iactive) + { +// klog("writing [%c] to window with pid [%d]",c,w->pid); + fd_write(get_fd(w->pid,1),c); + } + } +} void compositor_mouse_handle(uint16_t x,uint16_t y, uint8_t key) { diff --git a/video/compositor.h b/video/compositor.h index b8710b6..f109018 100644 --- a/video/compositor.h +++ b/video/compositor.h @@ -1,8 +1,10 @@ #include +void compositor_wake(); void compositor_init(uint16_t width, uint16_t height, uint16_t pitch); void compositor_set_background(char *ppm_raw_filename); void compositor_swap_buffers(); void compositor_mouse_handle(uint16_t x,uint16_t y, uint8_t key); -void compositor_add_window(uint32_t addr); +void compositor_kb_handle(char c); +void compositor_add_window(uint32_t addr,uint32_t pid); void compositor_del_window(uint32_t addr); -- cgit v1.2.3