diff options
| author | Miguel <m.i@gmx.at> | 2018-10-15 16:29:50 +0200 |
|---|---|---|
| committer | Miguel <m.i@gmx.at> | 2018-10-15 16:29:50 +0200 |
| commit | e3a8099343aac9d94f411638ad84632d4b620132 (patch) | |
| tree | f0a1f73ab106c17b25fd8a5264a66b6b48e55e48 /kernel | |
| parent | f35d2124c36f8d39a953b76620e081b79c2faffd (diff) | |
cleanup sys/ etc
Diffstat (limited to 'kernel')
| -rw-r--r-- | kernel/kernel.c | 1 | ||||
| -rw-r--r-- | kernel/kernel.h | 12 | ||||
| -rw-r--r-- | kernel/scheduler.c | 4 | ||||
| -rw-r--r-- | kernel/syscalls.c | 139 |
4 files changed, 129 insertions, 27 deletions
diff --git a/kernel/kernel.c b/kernel/kernel.c index 3692b17..a34be42 100644 --- a/kernel/kernel.c +++ b/kernel/kernel.c @@ -148,6 +148,7 @@ void kernel_main(uint32_t eax,uint32_t ebx) klog("Compositor init ..."); compositor_init(cfg_multiboot->framebuffer_width,cfg_multiboot->framebuffer_height,cfg_multiboot->framebuffer_pitch); compositor_set_background("/home/miguel/bg.ppm"); + //compositor_set_background(0); // -- KB DRIVER -- // klog("Keyboard init ..."); diff --git a/kernel/kernel.h b/kernel/kernel.h index 46302ba..cf21c60 100644 --- a/kernel/kernel.h +++ b/kernel/kernel.h @@ -29,6 +29,7 @@ REFERENCES //#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 +//#define LOG_SYSCALLS #define HIDE_FIXME #define FOOLOS_APIC_FREQ 15 // how many apic ticks per second @@ -69,7 +70,8 @@ REFERENCES #define VMEM_USER_ENV 0x07000000 // 1 page / per user process //#define VMEM_USER_PROG_PAGES (256*16) -#define VMEM_USER_PROG_PAGES (1024*16) // 64 megs +//#define VMEM_USER_PROG_PAGES (1024*16) // 64 megs +#define VMEM_USER_PROG_PAGES (1024*8) // 32megs #define VMEM_USER_PROG 0x08048000 // / per user process (usual entry: 0x8048080) #define VMEM_USER_STACK_PAGES (1024*16) // 64 megs / per thread @@ -87,13 +89,13 @@ REFERENCES //TODO: do not hardcode in crt0.s!!!! #define VMEM_USER_NEWLIB 0xF5000000 // 1 page / newlib reentrancy struct. 1 per thread +#define VMEM_USER_FRAMEBUFFER 0xF5100000 +#define VMEM_USER_FRAMEBUFFER_PAGES 300// 4*320*480 bytes per app (one extra?) + #define VMEM_FRAMEBUFFER 0xF6000000 // identity mapped #define VMEM_FRAMEBUFFER_PAGES (1024*8) // 32mb #define VMEM_EXT2_RAMIMAGE 0xF8000000 // identity mapped -#define VMEM_EXT2_PAGES (1024*16) // 64mb - -#define VMEM_USER_FRAMEBUFFER 0xFC000000 -#define VMEM_USER_FRAMEBUFFER_PAGES 300// 4*320*480 bytes per app (one extra?) +#define VMEM_EXT2_PAGES (1024*26) // 128mb #endif diff --git a/kernel/scheduler.c b/kernel/scheduler.c index 2112659..59d26d1 100644 --- a/kernel/scheduler.c +++ b/kernel/scheduler.c @@ -363,11 +363,13 @@ void task_syscall_worker() task_list[cpu][0].vmem=task_list[cpu][i].vmem; // switch syscall worker to pagedir of calling userprog x86_set_page_directory(task_list[cpu][0].vmem); + x86_cli(); // we do not want to be scheduled to other page ... sorry TODO: suuuuckS! uint32_t ok = syscall_generic_test(task_list[cpu][i].eax, task_list[cpu][i].edx, task_list[cpu][i].ecx, task_list[cpu][i].ebx, task_list[cpu][i].pid); + x86_sti(); if(!ok) { @@ -375,11 +377,13 @@ void task_syscall_worker() continue; } + x86_cli(); // we do not want to be scheduled to other page ... sorry TODO: suuuuckS! uint32_t ret = syscall_generic(task_list[cpu][i].eax, task_list[cpu][i].edx, task_list[cpu][i].ecx, task_list[cpu][i].ebx, task_list[cpu][i].pid); + x86_sti(); // klog("... returned : %d",ret); diff --git a/kernel/syscalls.c b/kernel/syscalls.c index 1c1d2c7..e73f89c 100644 --- a/kernel/syscalls.c +++ b/kernel/syscalls.c @@ -31,6 +31,8 @@ //TODO move to process.c and implement per process // static fd fds[MAX_PID][MAX_FD]; +//static uint32_t opendir_pos[MAX_PID][MAX_FD]; +//static char opendir_name[MAX_PID][MAX_FD][256]; static int tty[MAX_PID]; // keep track of /dev/tty fd for each process :P static bool open_fd[MAX_PID][MAX_FD]; @@ -55,6 +57,19 @@ void fd_init_std_streams(uint32_t pid) } // +/** helper */ +int nextfd(int pid) +{ + for(int i=0;i<MAX_FD;i++) + { + if(!open_fd[pid][i]) + { + open_fd[pid][i]=true; + return i; + } + } + return -1; +} /** errno helper */ void set_errno(int no) { @@ -107,6 +122,8 @@ char* syscall_get_name(uint32_t num) return "SYSCALL_GETTIMEOFDAY"; case SYSCALL_READDIR: return "SYSCALL_READDIR"; + case SYSCALL_OPENDIR: + return "SYSCALL_OPENDIR"; case SYSCALL_KILL: return "SYSCALL_KILL"; case SYSCALL_CLONE: @@ -121,8 +138,12 @@ char* syscall_get_name(uint32_t num) return "SYSCALL_GUI_WIN"; case SYSCALL_SELECT: return "SYSCALL_SELECT"; + case SYSCALL_TCGETATTR: + return "SYSCALL_TCGETATTR"; + case SYSCALL_TCSETATTR: + return "SYSCALL_TCSETATTR"; case SYSCALL_UNIMPLEMENTED: - return "SYSCALL_UNKNOWN"; + return "SYSCALL_UNIMPLEMENTED"; } kpanic("UNKNOWN SYSCALL NUM: %d",num); } @@ -154,8 +175,21 @@ int syscall_lseek(int file,int ptr,int dir,uint32_t pid) dat[1]+=ptr; return dat[1]; } + else if(dir==SEEK_SET) + { + uint32_t *dat=fds[pid][file].data; + dat[1]=ptr; + return dat[1]; + } + else if(dir==SEEK_END) + { + kpanic("SEEK_END dir for lseek!"); + } + else + { + kpanic("wrong dir for lseek!"); + } - kpanic("not fully handled lseek! dir=%d",dir); return 0; } @@ -177,12 +211,40 @@ int syscall_write(int file, char *buf, int len,uint32_t pid) */ int syscall_read(int file, char *buf, int len,uint32_t pid) { + int ret=0; + if(!open_fd[pid][file])kpanic("reading from closed file descriptor"); if(fd_eof(&fds[pid][file]))return 0; - *buf=fd_read(&fds[pid][file]); - return 1; + + while((fd_has(&fds[pid][file])||fd_eof(&fds[pid][file]))&&len-->0) + { + if(fd_eof(&fds[pid][file]))return ret; + *buf++=fd_read(&fds[pid][file]); + ret++; + } + return ret; } + /** + * Monitor multiple descriptors + * ============================ + * + * nfds is the MAX file descriptor number +1. + * + * It is possible to provide 3 different sets of filedescriptors + * (they can be NULL as well) + * + * - readfds - reading + * - writefds - writing + * - exceptfds - exceptions (all cleared unless exception occurs) + * + * The call returns the total number of descriptors contained in all + * sets after returning. + * + * This call will block until time (timeout) runs out + * OR a file descriptor becomes ready. + */ + int syscall_select(int maxxfd,struct timeval *tv, fd_set **fd_sets, uint32_t pid, bool test) { int ret=0; @@ -251,15 +313,47 @@ int syscall_select(int maxxfd,struct timeval *tv, fd_set **fd_sets, uint32_t pid } -//TODO: replace with dirent! -int syscall_readdir(const char *name,fs_dirent *dirs,int *pos,uint32_t pid) +//TODO: use fd and inode (instead of path)... now this is a crazy trick how it works.. +//is it that bad??? yes it was bad and vim crashed so we changed to even more hacky approach now.. :( :( +//ok it was other reason but we should not use it ... +//since userspace might zero or reuse dirent* and corrupt our DIR* ! TODO TODO TODO danger! +struct dirent *syscall_opendir(const char *name,struct dirent *dirs,int none,uint32_t pid) { - int ret=mount_read_dir(name, dirs, pos); + strcpy(dirs->dirname,name); + if(dirs->dirname[strlen(dirs->dirname)-1]=='/')dirs->dirname[strlen(dirs->dirname)-1]=0; + klog("syscall to opendir(%s)",dirs->dirname); + + // test if exists.... + struct dirent testdirent; + uint32_t testpos; + int ret=mount_read_dir(dirs->dirname, &testdirent, &testpos); if(ret==-1) { + // no it does not! set_errno(ENOENT); + return NULL; } - return ret; + + dirs->pos=0; + + /* + uint32_t fdn=nextfd(pid); + strcpy(opendir_name[pid][fdn],dirs->dirname); + opendir_pos[pid][fdn]=0; + */ + + return dirs; +} + +struct dirent *syscall_readdir(struct dirent *dirs,int none1, int none2,uint32_t pid) +{ + // this dirent will get filled with next entry... + int ret=mount_read_dir(dirs->dirname, dirs, &dirs->pos); + + // no more entries + if(ret==0)return NULL; + + return dirs; } /** execve helper */ @@ -327,22 +421,10 @@ int syscall_execve(const char *name, char *const argv[], char *const env[], int return 0; } -/** helper */ -int nextfd(int pid) -{ - for(int i=0;i<MAX_FD;i++) - { - if(!open_fd[pid][i]) - { - open_fd[pid][i]=true; - return i; - } - } - return -1; -} int syscall_open(char *name, int flags, int mode,uint32_t pid) { + klog("open %s",name); if(!strcmp("/dev/tty",name))return tty[pid]; uint32_t fdn=nextfd(pid); @@ -434,6 +516,10 @@ uint32_t syscall_sbrk(uint32_t incr, int none1, int none2, uint32_t pid) uint32_t oldalloc=alloc; alloc+=incr; task_set_brk(pid,alloc); + + uint32_t max_addy=VMEM_USER_PROG+VMEM_USER_PROG_PAGES*4096; + + if(alloc>max_addy)kpanic("can not set sbrk . TODO: dynamic allocation!"); fixme("fake syscall_sbrk(0x%08X) return %08X",incr,oldalloc); return oldalloc; } @@ -568,7 +654,9 @@ uint32_t syscall_generic_test(uint32_t nr,uint32_t p1, uint32_t p2, uint32_t p3, uint32_t syscall_generic(uint32_t nr,uint32_t p1, uint32_t p2, uint32_t p3, uint32_t pid) { -// klog("processing syscall [%s] for pid:%d",syscall_get_name(nr),pid); +#ifdef LOG_SYSCALLS + klog("processing syscall [%s] for pid:%d",syscall_get_name(nr),pid); +#endif switch(nr){ case SYSCALL_EXIT : @@ -617,6 +705,8 @@ uint32_t syscall_generic(uint32_t nr,uint32_t p1, uint32_t p2, uint32_t p3, uint return syscall_gettimeofday(p1,p2,p3,pid); case SYSCALL_READDIR : return syscall_readdir(p1,p2,p3,pid); + case SYSCALL_OPENDIR : + return syscall_opendir(p1,p2,p3,pid); case SYSCALL_KILL : // return task_kill(p1,p2,p3); return -1; @@ -634,6 +724,11 @@ uint32_t syscall_generic(uint32_t nr,uint32_t p1, uint32_t p2, uint32_t p3, uint return syscall_tcgetattr(p1,p2,p3,pid); case SYSCALL_TCSETATTR: return syscall_tcsetattr(p1,p2,p3,pid); + case SYSCALL_UNIMPLEMENTED: + if(!strcmp(p1,"fcntl")){ + klog("todo: quickfix hack for fcntl"); + } + } klog("unknown syscall %s / %d we just return 0",p1,nr); return 0; |
