diff options
| author | Miguel <m.i@gmx.at> | 2018-10-12 00:30:44 +0200 |
|---|---|---|
| committer | Miguel <m.i@gmx.at> | 2018-10-12 00:30:44 +0200 |
| commit | b461c3558b2fe765a4bac512638b0acf5185b4bb (patch) | |
| tree | 62d025135865f1752c7d884ac92fdcdd39b21654 | |
| parent | 2e8d1bc3b6aa0671995860ca8a09c97523f3538d (diff) | |
imeplemented /dev/tty and minimalistic "less"
| -rw-r--r-- | README.md | 3 | ||||
| -rw-r--r-- | interface/crt0.s | 40 | ||||
| -rw-r--r-- | kernel/syscalls.c | 51 | ||||
| -rw-r--r-- | kernel/syscalls.h | 2 | ||||
| -rw-r--r-- | userspace/less.c | 41 | ||||
| -rw-r--r-- | userspace/xterm/xterm.c | 32 | ||||
| -rw-r--r-- | video/compositor.c | 2 |
7 files changed, 100 insertions, 71 deletions
@@ -93,6 +93,7 @@ Todos * PRIO: Writing to ext2 RAM-image!!!! * PRIO: Fix scheduler. use all cpus! / accounting/bookkeppiung x86: tsc /rdtscp? / load bareer / queues? * PRIO: gcc toolchain +* PRIO: /dev/tty * PRIO: semaphores/ mutexes * PRIO: return value / argv / env @@ -108,6 +109,8 @@ Todos * TODO: GCC optimizations (break kernel?) / volatile keyword etc? * TODO: gcc-foolos (Porting (ncurses, gcc, binutils, vim, apache...) * TODO: why do we provide 2 versions of syscalls (underscore and no underscore?) for newlib (non underscore collide with standard!) +* TODO: flush open streams on exit as discussed in 7.21.3 : n1570, c11: https://port70.net/~nsz/c/c11/n1570.html#7.21.3 +* TODO: signals * EXTRA: fallback to pic/pit diff --git a/interface/crt0.s b/interface/crt0.s index 914a99d..88e316e 100644 --- a/interface/crt0.s +++ b/interface/crt0.s @@ -1,6 +1,6 @@ .global _start -_start: +_start: // in the beginning... //push %ebx // do we need to persist them??? //push %ecx @@ -19,11 +19,10 @@ _start: //skipzero: -// move impure pointer to our special page (check if not htere already!) - +/////////////////////////////////////////////////////////////////////// +// move impure pointer to our special page (todo: check if not htere already!) mov _impure_ptr,%eax mov $0xf5000000,%ebx - copy: mov (%eax),%ecx mov %ecx,(%ebx) @@ -31,16 +30,16 @@ add $4, %ebx add $4, %eax cmp $0xf5001000,%ebx jne copy - movl $0xf5000000, _impure_ptr +//////////////////////////////////////////////////////////////////////// -call _init // constructors +call _init // constructors from .ctors -// constructors from array_init +/////////////////////////////////////////////////////////////////////// +// constructors from array_init //////////////////////////// mov $__init_array_start,%eax nextctor: - //cmp (__init_array_end),%eax cmp $__init_array_end,%eax je finctor @@ -52,40 +51,41 @@ pop %eax add $4, %eax jmp nextctor -finctor: +finctor: // ready with global ctors +//////////////////////////////////////////////////////////////////////// //pop %ecx //pop %ebx +############################################### # environment adress was passed on stack - pop %eax mov %eax, environ +############################################### -pop %ecx -pop %ebx +pop %ecx //argc +pop %ebx //& argv -and $-16,%esp +and $-16,%esp //align stack sub $8,%esp -push %ebx -push %ecx +push %ebx //argv +push %ecx //& argc -# call main (argc and argv are on the stack) +# call main (argc and argv are on the (realigned) tack) call main -// ALIGN stack +// ALIGN stack again (todo: do we need this!??!!) and $-16,%esp sub $4,%esp push %eax - -call _fini //desctructors +call _fini //desctructors from .dtors // pop programmm return value pop %eax -// ALIGN stack +// ALIGN stack (???) and $-16,%esp sub $4,%esp diff --git a/kernel/syscalls.c b/kernel/syscalls.c index 29b5b6b..507be13 100644 --- a/kernel/syscalls.c +++ b/kernel/syscalls.c @@ -28,12 +28,14 @@ #define MAX_PID 200 //TODO move to process.c and implement per process // -static fd fds[MAX_PID][MAX_FD]; +static fd fds[MAX_PID][MAX_FD]; +static int tty[MAX_PID]; // keep track of /dev/tty fd for each process :P + static bool open_fd[MAX_PID][MAX_FD]; -fd *get_fd(uint32_t pid,uint32_t file) +fd *get_tty(uint32_t pid) { - return &(fds[pid][file]); + return &(fds[pid][tty[pid]]); } void fd_init_std_streams(uint32_t pid) @@ -48,37 +50,6 @@ void fd_init_std_streams(uint32_t pid) open_fd[pid][2]=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 - { - // fds[0][1]=fd_from_term(); - // fds[0][2]=fd_from_term(); - } -// else - { - //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; - } - else - { - fds[pid][0]=fds[0][0]; -// 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; - } } // @@ -308,6 +279,8 @@ int nextfd(int pid) int syscall_open(char *name, int flags, int mode,uint32_t pid) { + if(!strcmp("/dev/tty",name))return tty[pid]; + uint32_t fdn=nextfd(pid); fds[pid][fdn]=mount_file_open(name); if(*(uint32_t *)fds[pid][fdn].data==0)return -1; @@ -325,8 +298,9 @@ uint32_t syscall_fork(int none1, int none2, int none3, int pid) fds[newpid][i]=fd_dupl(&fds[pid][i]); open_fd[newpid][i]=true; } + tty[newpid]=tty[pid]; // fds[newpid][0]=fd_from_ringbuffer(); // TODO fix - open_fd[newpid][0]=true; +// open_fd[newpid][0]=true; return newpid; } @@ -341,6 +315,7 @@ uint32_t syscall_clone(int none1, int none2, int none3, int pid) fds[newpid][i]=fd_dupl(&fds[pid][i]); open_fd[newpid][i]=true; } + tty[newpid]=tty[pid]; return newpid; } @@ -383,6 +358,7 @@ int syscall_close(int file,int none1,int none2,int pid) // TODO: check if file is a termminal! int syscall_isatty(int file,int none1,int none2,int pid) { + return 1; if(fds[pid][file].type==FD_TYPE_FIFO)return 1; return 0; } @@ -438,7 +414,12 @@ uint32_t syscall_gui_rect(uint32_t p1, uint32_t p2, uint32_t p3, uint32_t pid) } uint32_t syscall_gui_win(uint32_t p1, uint32_t p2, uint32_t p3, uint32_t pid) { + uint32_t fdn=nextfd(pid); + fds[pid][fdn]=fd_from_ringbuffer(); + tty[pid]=fdn; + task_add_win(pid); + return 1; } diff --git a/kernel/syscalls.h b/kernel/syscalls.h index b79e6b3..5579dd7 100644 --- a/kernel/syscalls.h +++ b/kernel/syscalls.h @@ -48,7 +48,7 @@ /** Todo move somewhere else and init per process , think how to make thread safe */ void fd_init_std_streams(uint32_t pid); -fd *get_fd(uint32_t pid,uint32_t file); +fd *get_tty(uint32_t pid); /** returns string representation of the syscall from its number */ char* syscall_get_name(uint32_t num); diff --git a/userspace/less.c b/userspace/less.c new file mode 100644 index 0000000..c1792ae --- /dev/null +++ b/userspace/less.c @@ -0,0 +1,41 @@ +#include <stdio.h> +#include <stdlib.h> + +#define VERSION "0.1" +int main(int argc, char **argv) +{ + printf("--== fool's %s - version %s ==-\n",argv[0],VERSION); + + // keyboard + int ctrl_fd=_open("/dev/tty"); + + // Input (default stdin) + FILE *in=stdin; + + // Output + FILE *out=stdout; + + // In case a Filename was supplied (TODO: getcwd / setcwd , chdir, open realative to dir. + if(argc>1){ + { + in=fopen(argv[1],"r"); + } + } + + char buf[256]; + + for(int i=0;i<20;i++) + { + if(fgets(buf,256,in)==NULL)return EXIT_SUCCESS; + fputs(buf,out); + } + + while(1) + { + if(fgets(buf,256,in)==NULL)break; + fputs(buf,out); + _read(ctrl_fd,buf,1); // wait for any key + } + + return EXIT_SUCCESS; +} diff --git a/userspace/xterm/xterm.c b/userspace/xterm/xterm.c index 4680ab8..fdee768 100644 --- a/userspace/xterm/xterm.c +++ b/userspace/xterm/xterm.c @@ -1,47 +1,51 @@ +#include <stdlib.h> +#include <stdio.h> + extern char**environ; int main(int argc, char **argv) { _gui_win(); - int xterm_in[2]; - int xterm_out[2]; - - _pipe(xterm_in); - _pipe(xterm_out); vesa_init(); void *tty=terminal_init_vesa(); + //int xterm_in[2]; + int xterm_out[2]; + + //_pipe(xterm_in); + _pipe(xterm_out); + int pid=_fork(); if(!pid) { - _close(xterm_in[1]); + int tty_fd=_open("/dev/tty"); + + //_close(xterm_in[1]); _close(xterm_out[0]); - _dup2(xterm_in[0],0);// stdin + _dup2(tty_fd,0);// stdin _dup2(xterm_out[1],1);// stdout _dup2(xterm_out[1],2);// stderr - _close(xterm_in[0]); - _close(xterm_out[1]); - _execve(argv[1],argv,environ); // replace process with our foolshell or whatever + + while(1); } - _close(xterm_in[0]); + //_close(xterm_in[0]); _close(xterm_out[1]); - _dup2(xterm_in[1],0); // compositor writes here. - _close(xterm_in[1]); + //_dup2(xterm_in[1],0); // compositor writes here. + //_close(xterm_in[1]); while(1) { char buf[1]; _read(xterm_out[0],buf,1); // show what foolshell writes to its stdout/stderr - terminal_put(tty,buf[0]); _gui_rect(); } diff --git a/video/compositor.c b/video/compositor.c index 192feea..4debe9a 100644 --- a/video/compositor.c +++ b/video/compositor.c @@ -254,7 +254,7 @@ void compositor_kb_handle(char c) if(w->active) { // klog("writing [%c] to window with pid [%d]",c,w->pid); - fd_write(get_fd(w->pid,0),c); + fd_write(get_tty(w->pid),c); } } } |
