void tst_shm2(void) { int r; int shmid; syscall_wait(10); shmid=shm_lookup(SHRMEMNAME); display_puts("shm2 lookup="); sint2dec(shmid,s); display_puts(s); r=shm_map(shmid,(void*)SHRMEMADDR); display_puts(" shm2 map="); sint2dec(r,s); display_puts(s); // display_puts("\n"); syscall_wait(50); syscall_mtx_lock((int*)SHRMEMADDR); memcpy(s,(void*)(SHRMEMADDR+sizeof(int)),4); syscall_mtx_unlock((int*)SHRMEMADDR); s[4]=0; display_puts(" shm2 shrstr="); display_puts(s); // display_puts("\n"); r=shm_unmap(shmid); display_puts(" shm2 unmap="); sint2dec(r,s); display_puts(s); display_puts("\n"); }
int main(int argc, char * argv[]) { /* Starts a graphical session and then spins waiting for a kill (logout) signal */ /* Load some session variables */ set_username(); set_homedir(); set_path(); int _wallpaper_pid = fork(); if (!_wallpaper_pid) { char * args[] = {"/bin/wallpaper", NULL}; execvp(args[0], args); } int _panel_pid = fork(); if (!_panel_pid) { char * args[] = {"/bin/panel", NULL}; execvp(args[0], args); } syscall_wait(_panel_pid); printf("Session leader has exited. Sending INT signals to %d.\n", _wallpaper_pid); syscall_send_signal(_wallpaper_pid, 2); printf("Waiting on wallpaper.\n"); syscall_wait(_wallpaper_pid); printf("Session has ended.\n"); }
/* Write a block of data on the socket to the nano-X server */ void nxWriteSocket(char *buf, int todo) { int written; ACCESS_PER_THREAD_DATA(); do { #if !HELLOOS written = write(nxSocket, buf, todo); #else int retry; for(retry=0;retry<100;retry++) { written = bucket_send(nxSocket, buf, todo); if(written!=ERRNO_OVER) break; syscall_wait(10); } #endif if ( written < 0 ) { #if !HELLOOS if ( errno == EAGAIN || errno == EINTR ) continue; #endif EPRINTF("nxFlushReq: write failed: %m\n"); exit(1); } buf += written; todo -= written; } while ( todo > 0 ); }
int cdfs_init(void) { int rc; if(cdfs_queid != 0) return 0; for(;;) { rc = syscall_que_lookup(CDFS_QNM_CDFS); if(rc==ERRNO_NOTEXIST) { syscall_wait(10); continue; } if(rc<0) { cdfs_queid = 0; display_puts("cdfs_init srvq="); long2hex(-rc,s); display_puts(s); display_puts("\n"); return rc; } cdfs_queid = rc; break; } //display_puts("cdfs_init done\n"); return 0; }
int tst_alarm(void) { int i; //int rc; //int alarm; struct msg_head selected_msg; for(i=0;i<10;i++) { display_puts("@"); syscall_wait(50); } display_puts("\n"); for(i=0;i<10;i++) { display_puts("@"); syscall_alarm_set(50,environment_getqueid(),0x00010000); selected_msg.size=sizeof(selected_msg); message_poll(MESSAGE_MODE_WAIT, 0, 0, &selected_msg); message_receive(MESSAGE_MODE_TRY, 0, 0, &selected_msg); } display_puts("\n"); return 0; }
void tst_console(void) { // int a; // int i,j; // int size; // a = display_putc('H'); // a = display_putc('E'); // a = display_putc('L'); // display_putc(a); //syscall_tst3(12,34,56); // exit(123); /* for(i=0;i<5;i++) { for(j=0;j<i;j++) puts("."); puts("Hello World\n"); } */ for(;;) { puts("1"); syscall_wait(1000); } // cpu_halt(); }
void tst_que(void) { int r,q; char str[]="ABCD\n"; struct msg_head msg; char *c; syscall_wait(10); q = syscall_que_lookup(QUENAME); if(q<0) { display_puts("que lookup="); long2hex(-q,s); display_puts(s); display_puts("\n"); return; } for(c=str;;c++) { msg.size=msg_sizeof(msg); msg.service=0; msg.command=0; msg.arg=*c; r = syscall_que_put(q, &msg); if(r<0) { display_puts("que put="); long2hex(-r,s); display_puts(s); display_puts("\n"); break; } if(*c=='\n') break; } }
int display_putc(int chr) { struct msg_head msg; int r; if(display_queid==0) { r=display_init(); if(r<0) return r; } msg.size=sizeof(struct msg_head); msg.service=DISPLAY_SRV_DISPLAY; msg.command=DISPLAY_CMD_PUTC; msg.arg=chr; for(;;) { r=message_send(display_queid, &msg); if(r!=ERRNO_OVER) break; syscall_wait(10); } if(r<0) { syscall_puts("putc sndcmd="); long2hex(-r,s); syscall_puts(s); syscall_puts("\n"); return r; } return 0; }
int main(int argc, char ** argv) { /* TODO: uname() */ char * _uname = malloc(sizeof(char) * 1024); syscall_kernel_string_XXX(_uname); fprintf(stdout, "\n%s\n\n", _uname); syscall_signal(2, sig_int); syscall_signal(11, sig_segv); while (1) { char * username = malloc(sizeof(char) * 1024); char * password = malloc(sizeof(char) * 1024); /* TODO: gethostname() */ char _hostname[256]; syscall_gethostname(_hostname); fprintf(stdout, "%s login: "******"password: \033[1001z"); fflush(stdout); fgets(password, 1024, stdin); password[strlen(password)-1] = '\0'; fprintf(stdout, "\033[1002z\n"); int uid = checkUserPass(username, password); if (uid < 0) { fprintf(stdout, "\nLogin failed.\n"); continue; } pid_t pid = getpid(); uint32_t f = fork(); if (getpid() != pid) { /* TODO: Read appropriate shell from /etc/passwd */ char * args[] = { "/bin/esh", NULL }; syscall_setuid(uid); int i = execve(args[0], args, NULL); } else { child = f; syscall_wait(f); } child = 0; free(username); free(password); } return 0; }
void start_compositor() { int pid = fork(); if (!pid) { char * _tokens[] = { "/bin/compositor", NULL }; execvp(_tokens[0], _tokens); exit(0); } else { syscall_wait(pid); } }
void start_terminal_no_freetype(char * arg) { int pid = fork(); if (!pid) { char * tokens[] = { "/bin/terminal", "-Fkb", arg, NULL }; int i = execv(tokens[0], tokens); exit(0); } else { syscall_wait(pid); } }
void start_vga_terminal(char * arg) { int pid = fork(); if (!pid) { char * tokens[] = { "/bin/terminal", "-Vl", arg, NULL }; int i = execvp(tokens[0], tokens); exit(0); } else { syscall_wait(pid); } }
int main(int argc, char *argv[]) { FILE *fp; fp = fopen("/init.ini", "rb"); if(fp == NULL) printf("Konnte keine Init-Datei laden\n"); else { parseFile(fp); } fclose(fp); while(1) syscall_wait(0, NULL); //Dieser Prozess darf nicht beendet werden }
static void dump(char *addr) { int i,j; for(j=0;j<2;j++) { long2hex((unsigned long)addr,s); display_puts(s); for(i=0;i<16;i++,addr++) { byte2hex(*addr,s); display_puts(" "); display_puts(s); } display_puts("\n"); syscall_wait(50); } }
/* * get system call */ static void syscall_handler (struct intr_frame *f) { int *esp = (int *)syscall_user_to_kernel_vaddr(f->esp); switch(*esp) { case SYS_WRITE: syscall_write(f); break; case SYS_EXIT: syscall_exit(f); break; case SYS_HALT: syscall_halt(f); break; case SYS_EXEC: syscall_exec(f); break; case SYS_CREATE: syscall_create(f); break; case SYS_REMOVE: syscall_remove(f); break; case SYS_OPEN: syscall_open(f); break; case SYS_FILESIZE: syscall_filesize(f); break; case SYS_READ: syscall_read(f); break; case SYS_SEEK: syscall_seek(f); break; case SYS_TELL: syscall_tell(f); break; case SYS_CLOSE: syscall_close(f); break; case SYS_WAIT: syscall_wait(f); break; } }
void tst_mutex(void) { int r,r1; char *ctl; int *mutex; char *m1; r1=shm_create(SHRMEMNAME,8*1024); display_puts("shm create="); sint2dec(r1,s); display_puts(s); r=shm_map(SHRMEMNAME,SHRMEMHEAP); display_puts(" shm map="); sint2dec(r,s); display_puts(s); display_puts("\n"); mutex = SHRMEMHEAP; ctl = (void*)((unsigned long)SHRMEMHEAP+sizeof(int)); if(r1==0) { *mutex=0; syscall_mtx_lock(mutex); memory_init(ctl,8*1024-sizeof(int)); display_puts(" init heap\n"); syscall_mtx_unlock(mutex); } syscall_mtx_lock(mutex); display_puts("lock tst2\n"); m1 = memory_alloc(10,ctl); display_puts("alloc tst2\n"); syscall_mtx_unlock(mutex); display_puts("unlock tst2\n"); memcpy(m1,"efgh",5); display_puts("memcpy tst2\n"); syscall_wait(1000); display_puts("sleeping tst2\n"); display_puts("dump tst2="); display_puts(m1); display_puts("\n"); }
void GsSelect(void) { int m,k; // If mouse data present, service it m=mousedev.Poll(); if(m) GsCheckMouseEvent(); // If keyboard data present, service it k=kbddev.Poll(); if(k) GsCheckKeyboardEvent(); if((!m) && (!k)) { syscall_wait(1); } }
int display_init(void) { int r; if(display_queid != 0) return 0; display_queid = environment_get_display((void*)CFG_MEM_USERARGUMENT); if(display_queid != 0) return 0; for(;;) { r = syscall_que_lookup(DISPLAY_QNM_DISPLAY); if(r==ERRNO_NOTEXIST) { syscall_wait(10); continue; } if(r<0) { syscall_puts("dsp_init srvq err="); long2hex(-r,s); syscall_puts(s); syscall_puts("\n"); return r; } display_queid = r; environment_make_display((void*)CFG_MEM_USERARGUMENT, display_queid); break; } /* syscall_puts("dspqids q="); int2dec(display_queid,s); syscall_puts(s); syscall_puts(","); int2dec(display_clientq,s); syscall_puts(s); syscall_puts("\n"); */ return 0; }
int mouse_init(void) { int r; int retry=100; if(mou_queid != 0) return 0; for(;;) { r = syscall_que_lookup(MOU_QNM_MOUSE); if(r==ERRNO_NOTEXIST) { syscall_wait(10); if(retry--) continue; return -1; } if(r<0) { mou_queid = 0; display_puts("Cmou_init srvq="); long2hex(-r,s); display_puts(s); display_puts("\n"); return r; } mou_queid = r; break; } mou_clientq=environment_getqueid(); /* display_puts("Ckbdqids q="); int2dec(mou_queid,s); display_puts(s); display_puts(","); int2dec(mou_clientq,s); display_puts(s); display_puts("\n"); */ return 0; }
int test_engine() { MWCOORD x1,x2,y1,y2; unsigned long mask=0; int count=0; int y; psd = GdOpenScreen(); if(psd==NULL) { syscall_puts("GdOpenScreen error\n"); return 0; } GdSetForegroundPixelVal(psd, 7); GdSetBackgroundPixelVal(psd, 0); GdSetDash(&mask, &count); x1=100; x2=540; y1=100; y2= 380; GdLine(psd, x1, y1, x2, y1, 0); GdLine(psd, x2, y1, x2, y2, 0); GdLine(psd, x1, y2, x2, y2, 0); GdLine(psd, x1, y1, x1, y2, 0); for(y=0;y<8;y++) { GdSetForegroundPixelVal(psd, y); GdLine(psd, x1, y1+y, x2, y1+y, 0); } GdSetForegroundPixelVal(psd, 7); GdLine(psd, x1, y1, x2, y2, 0); syscall_wait(1000); GdCloseScreen(psd); return 0; }
int tst_bucket() { int fd; char s[16]; int rc; char *buffer; int j; fd_set fdset; int fdsize=0; rc=fd=bucket_open(); if(rc<0) { display_puts("open error="); int2dec(-rc,s); display_puts(s); display_puts("\n"); return 1; } rc=bucket_connect(fd, BKT_QNM_BUCKET, BKT_SRV_BUCKET); if(rc<0) { display_puts("connect error="); int2dec(-rc,s); display_puts(s); display_puts("\n"); return 1; } buffer=malloc(4096); memcpy(buffer,"ABC",3); rc=bucket_send(fd, buffer, 3); if(rc<0) { display_puts("send error="); int2dec(-rc,s); display_puts(s); display_puts("\n"); return 1; } memcpy(buffer,"DEF",3); rc=bucket_send(fd, buffer, 3); if(rc<0) { display_puts("send error="); int2dec(-rc,s); display_puts(s); display_puts("\n"); return 1; } // rc=bucket_shutdown(fd); // if(rc<0) { // display_puts("shutdown error="); // int2dec(-rc,s); // display_puts(s); // display_puts("\n"); // return 1; // } rc=bucket_shutdown(fd); j=0; while(j<5) { display_puts("receiving(client)..."); fdsize=max(fdsize,fd); FD_ZERO(&fdset); FD_SET(fd,&fdset); rc=bucket_select(fdsize+1,&fdset, 0); if(rc<0) { display_puts("select error="); int2dec(-rc,s); display_puts(s); display_puts("\n"); return 1; } display_puts("\n"); rc=bucket_recv(fd, buffer, 6); if(rc<0) { display_puts("recv error="); int2dec(-rc,s); display_puts(s); display_puts("\n"); return 1; } display_puts("received(client) bucket:"); int2dec(rc,s); display_puts(s); display_puts("byte.("); buffer[rc]=0; display_puts(buffer); display_puts(")\n"); if(rc==0) break; syscall_wait(100); j++; } rc=bucket_close(fd); display_puts("done(client)\n"); return 0; }
int display_puts(char *chr) { union display_msg msg; short len; int r; if(display_queid==0) { r=display_init(); if(r<0) return r; } /* if(display_queid<100) { syscall_puts(" qid="); int2dec(display_queid,s); syscall_puts(s); syscall_puts("\n"); } */ len=strlen(chr); if(len>=DISPLAY_STRLEN-1) len=DISPLAY_STRLEN-1; // msg.h.size=msg_size(sizeof(struct msg_head)+len+1); msg.h.size=sizeof(struct msg_head)+len+1; msg.h.service=DISPLAY_SRV_DISPLAY; msg.h.command=DISPLAY_CMD_PUTS; msg.h.arg=len; strncpy(msg.s.s, chr, DISPLAY_STRLEN); /* { char *ms=(char *)&msg; syscall_puts("sz="); int2dec(msg.h.size,s); syscall_puts(s); syscall_puts("arg="); int2dec(msg.h.arg,s); syscall_puts(s); syscall_puts("str="); byte2hex(ms[8],&s[0]); byte2hex(ms[9],&s[2]); syscall_puts(s); } */ for(;;) { r=message_send(display_queid, &msg); if(r!=ERRNO_OVER) break; syscall_wait(10); } if(r<0) { syscall_puts("puts sndcmd="); int2dec(-r,s); syscall_puts(s); syscall_puts(" qid="); int2dec(display_queid,s); syscall_puts(s); syscall_puts(" str="); syscall_puts(chr); syscall_puts("\n"); return r; } return 0; }
static void syscall_handler (struct intr_frame *f) { int syscall_num; VALIDATE_AND_GET_ARG (f->esp, syscall_num, f); void *cur_sp = f->esp + sizeof (void *); /* store user program stack pointer to the thread's user_esp before changing to kernel mode */ struct thread *t = thread_current (); t->user_esp = f->esp; switch (syscall_num) { case SYS_HALT: syscall_halt (f, cur_sp); break; case SYS_EXIT: syscall_exit (f, cur_sp); break; case SYS_EXEC: syscall_exec (f, cur_sp); break; case SYS_WAIT: syscall_wait (f, cur_sp); break; case SYS_CREATE: syscall_create (f, cur_sp); break; case SYS_REMOVE: syscall_remove (f, cur_sp); break; case SYS_OPEN: syscall_open (f, cur_sp); break; case SYS_FILESIZE: syscall_filesize (f, cur_sp); break; case SYS_READ: syscall_read (f, cur_sp); break; case SYS_WRITE: syscall_write (f, cur_sp); break; case SYS_SEEK: syscall_seek (f, cur_sp); break; case SYS_TELL: syscall_tell (f, cur_sp); break; case SYS_CLOSE: syscall_close (f, cur_sp); break; case SYS_MMAP: syscall_mmap (f, cur_sp); break; case SYS_MUNMAP: syscall_unmmap (f, cur_sp); break; default : printf ("Invalid system call! #%d\n", syscall_num); syscall_thread_exit (f, -1); break; } }
int systemcall(struct PAR_REGS *regs) { char *cpp1, *cpp2, **cppp1; //3, *cpp4, *cpp5, *cpp6, **cppp1, **cppp2; int i, ip1, ip2; //unsigned long old_cr0; switch (regs->eax) // Sys call number ? { case 0: return syscall_test(); case 1: cpp1 = CHARPPAR(regs->ebx); if (cpp1 < KERNELEND) return EINVALIDPTR; return syscall_open(CHARPPAR(regs->ebx), INTPAR(regs->ebx+4), INTPAR(regs+4+4)); case 2: return syscall_close(INTPAR(regs->ebx)); case 3: cpp1 = CHARPPAR(regs->ebx+4); if (cpp1 < KERNELEND) return EINVALIDPTR; return syscall_read(INTPAR(regs->ebx), cpp1, INTPAR(regs->ebx+4+4)); case 4: cpp1 = CHARPPAR(regs->ebx+4); if (cpp1 < KERNELEND) return EINVALIDPTR; return syscall_write(INTPAR(regs->ebx), cpp1, INTPAR(regs->ebx+4+4)); case 5: return syscall_lseek(INTPAR(regs->ebx), INTPAR(regs->ebx+4), INTPAR(regs->ebx+4+4)); case 6: cpp1 = CHARPPAR(regs->ebx); if (cpp1 < KERNELEND) return EINVALIDPTR; return syscall_mkdir(cpp1, INTPAR(regs->ebx+4)); case 7: cpp1 = CHARPPAR(regs->ebx); if (cpp1 < KERNELEND) return EINVALIDPTR; return syscall_rmdir(cpp1); case 8: cpp1 = CHARPPAR(regs->ebx); if (cpp1 < KERNELEND) return EINVALIDPTR; return syscall_chdir(cpp1); case 9: cpp1 = CHARPPAR(regs->ebx); if (cpp1 < KERNELEND) return EINVALIDPTR; return syscall_creat(cpp1, INTPAR(regs->ebx+4)); case 10: cpp1 = CHARPPAR(regs->ebx); if (cpp1 < KERNELEND) return EINVALIDPTR; cpp1 = CHARPPAR(regs->ebx+4); if (cpp1 < KERNELEND) return EINVALIDPTR; return syscall_rename(CHARPPAR(regs->ebx), CHARPPAR(regs->ebx+4)); case 11: cpp1 = CHARPPAR(regs->ebx); if (cpp1 < KERNELEND) return EINVALIDPTR; cpp1 = CHARPPAR(regs->ebx+4); if (cpp1 < KERNELEND) return EINVALIDPTR; return (int) syscall_opendir(CHARPPAR(regs->ebx), (DIR *)CHARPPAR(regs->ebx+4)); case 12: cpp1 = CHARPPAR(regs->ebx); if (cpp1 < KERNELEND) return EINVALIDPTR; return syscall_closedir((DIR *) CHARPPAR(regs->ebx)); case 13: cpp1 = CHARPPAR(regs->ebx); if (cpp1 < KERNELEND) return EINVALIDPTR; return (int) syscall_readdir((DIR *)CHARPPAR(regs->ebx)); case 14: cpp1 = CHARPPAR(regs->ebx); if (cpp1 < KERNELEND) return EINVALIDPTR; cpp1 = CHARPPAR(regs->ebx+4); if (cpp1 < KERNELEND) return EINVALIDPTR; return syscall_stat(CHARPPAR(regs->ebx),(struct stat *)CHARPPAR(regs->ebx+4)); case 15: cpp1 = CHARPPAR(regs->ebx); if (cpp1 < KERNELEND) return EINVALIDPTR; return syscall_unlink(CHARPPAR(regs->ebx)); case 16: cpp1 = CHARPPAR(regs->ebx); if (cpp1 < KERNELEND) return EINVALIDPTR; return syscall_chmod(CHARPPAR(regs->ebx),(mode_t)INTPAR(regs->ebx+4)); case 17: ip1 = INTPAR(regs->ebx); return syscall_dup(ip1); case 18: ip1 = INTPAR(regs->ebx); ip2 = INTPAR(regs->ebx + 4); return syscall_dup2(ip1, ip2); case 19: syscall_setcursor( INTPAR(regs->ebx),INTPAR(regs->ebx+4)); return 0; case 20: return syscall_getchar(); case 21: return syscall_getchare(); case 22: return syscall_getscanchar(); case 23: return syscall_putchar(CHARPAR(regs->ebx)); case 24: cpp1 = CHARPPAR(regs->ebx); if (cpp1 < KERNELEND) return EINVALIDPTR; return syscall_puts(CHARPPAR(regs->ebx)); case 25: cpp1 = CHARPPAR(regs->ebx); ip1 = INTPAR(regs->ebx + 4); syscall_seekdir((DIR *)cpp1, ip1); return 0; case 26: cpp1 = CHARPPAR(regs->ebx); return syscall_telldir((DIR *)cpp1); case 27: cpp1 = CHARPPAR(regs->ebx); syscall_rewinddir((DIR *)cpp1); return 0; case 32: cpp1 = CHARPPAR(regs->ebx+12); if (cpp1 < KERNELEND) return EINVALIDPTR; return syscall_readblocks(INTPAR(regs->ebx), INTPAR(regs->ebx+4), INTPAR(regs->ebx+8), CHARPPAR(regs->ebx+12)); case 33: cpp1 = CHARPPAR(regs->ebx+12); if (cpp1 < KERNELEND) return EINVALIDPTR; return syscall_writeblocks(INTPAR(regs->ebx), INTPAR(regs->ebx+4), INTPAR(regs->ebx+8), CHARPPAR(regs->ebx+12)); case 34: syscall_sync(0); return 0; case 50: syscall_tsleep(INTPAR(regs->ebx)); return 0; case 60: cpp1 = CHARPPAR(regs->ebx + 4); if (cpp1 < KERNELEND) return EINVALIDPTR; return syscall_tsendto(SHORTPAR(regs->ebx), CHARPPAR(regs->ebx+4), INTPAR(regs->ebx+8), INTPAR(regs->ebx+12), INTPAR(regs->ebx+16), SHORTPAR(regs->ebx+20)); case 62: cpp1 = CHARPPAR(regs->ebx); if (cpp1 < KERNELEND) return EINVALIDPTR; cpp1 = CHARPPAR(regs->ebx + 8); if (cpp1 < KERNELEND) return EINVALIDPTR; return syscall_trecvfrom(CHARPPAR(regs->ebx), INTPAR(regs->ebx+4), SHORTPPAR(regs->ebx+8), INTPAR(regs->ebx+12)); case 65: cpp1 = CHARPPAR(regs->ebx); if (cpp1 < KERNELEND) return EINVALIDPTR; cppp1 = (char **)CHARPPAR(regs->ebx+4); i = 0; while (cppp1[i] != NULL) { if (cppp1[i] < KERNELEND) return EINVALIDPTR; i++; } cppp1 = (char **)CHARPPAR(regs->ebx+8); i = 0; while (cppp1[i] != NULL) { if (cppp1[i] < KERNELEND) return EINVALIDPTR; i++; } return syscall_exectask(CHARPPAR(regs->ebx), (char **)CHARPPAR(regs->ebx+4), (char **)CHARPPAR(regs->ebx+8), INTPAR(regs->ebx+12)); case 66: syscall_exit(INTPAR(regs->ebx)); return 0; case 70: cpp1 = CHARPPAR(regs->ebx); if (cpp1 < KERNELEND) return EINVALIDPTR; cpp1 = CHARPPAR(regs->ebx+4); if (cpp1 < KERNELEND && cpp1 != NULL) return EINVALIDPTR; cpp1 = CHARPPAR(regs->ebx+8); if (cpp1 < KERNELEND) return EINVALIDPTR; cpp1 = CHARPPAR(regs->ebx+12); if (cpp1 < KERNELEND && cpp1 != NULL) return EINVALIDPTR; return syscall_pthread_create((pthread_t *)INTPPAR(regs->ebx), (pthread_attr_t *)CHARPPAR(regs->ebx+4), (void *(*)(void *))INTPPAR(regs->ebx+8), (void *)CHARPPAR(regs->ebx+12)); case 71: cpp1 = CHARPPAR(regs->ebx); if (cpp1 < KERNELEND && cpp1 != NULL) return EINVALIDPTR; syscall_pthread_exit((void *)CHARPPAR(regs->ebx)); return 0; case 72: cpp1 = CHARPPAR(regs->ebx+4); if (cpp1 < KERNELEND && cpp1 != NULL) return EINVALIDPTR; return syscall_pthread_join((pthread_t)INTPAR(regs->ebx), (void **)CHARPPAR(regs->ebx+4)); case 73: return syscall_pthread_detach((pthread_t)INTPAR(regs->ebx)); case 74: return syscall_pthread_yield(); case 75: cpp1 = CHARPPAR(regs->ebx); if (cpp1 < KERNELEND) return EINVALIDPTR; cpp1 = CHARPPAR(regs->ebx+4); if (cpp1 < KERNELEND && cpp1 != NULL) return EINVALIDPTR; return syscall_pthread_mutex_init((pthread_mutex_t *)INTPAR(regs->ebx), (pthread_mutexattr_t *)CHARPPAR(regs->ebx+4)); case 76: cpp1 = CHARPPAR(regs->ebx); if (cpp1 < KERNELEND) return EINVALIDPTR; return syscall_pthread_mutex_trylock((pthread_mutex_t *)INTPAR(regs->ebx)); case 77: cpp1 = CHARPPAR(regs->ebx); if (cpp1 < KERNELEND) return EINVALIDPTR; return syscall_pthread_mutex_lock((pthread_mutex_t *)INTPAR(regs->ebx)); case 78: cpp1 = CHARPPAR(regs->ebx); if (cpp1 < KERNELEND) return EINVALIDPTR; return syscall_pthread_mutex_unlock((pthread_mutex_t *)INTPAR(regs->ebx)); case 79: cpp1 = CHARPPAR(regs->ebx); if (cpp1 < KERNELEND) return EINVALIDPTR; cpp1 = CHARPPAR(regs->ebx+4); if (cpp1 < KERNELEND && cpp1 != NULL) return EINVALIDPTR; return syscall_pthread_cond_init((pthread_cond_t *)INTPAR(regs->ebx), (pthread_condattr_t *)CHARPPAR(regs->ebx+4)); case 80: cpp1 = CHARPPAR(regs->ebx); if (cpp1 < KERNELEND) return EINVALIDPTR; cpp1 = CHARPPAR(regs->ebx+4); if (cpp1 < KERNELEND && cpp1 != NULL) return EINVALIDPTR; return syscall_pthread_cond_wait((pthread_cond_t *)INTPAR(regs->ebx), (pthread_mutex_t *)INTPPAR(regs->ebx+4)); case 81: cpp1 = CHARPPAR(regs->ebx); if (cpp1 < KERNELEND) return EINVALIDPTR; return syscall_pthread_cond_signal((pthread_cond_t *)INTPAR(regs->ebx)); case 82: cpp1 = CHARPPAR(regs->ebx); if (cpp1 < KERNELEND) return EINVALIDPTR; return syscall_pthread_cond_broadcast((pthread_cond_t *)INTPAR(regs->ebx)); case 83: cpp1 = CHARPPAR(regs->ebx); if (cpp1 < KERNELEND) return EINVALIDPTR; cpp1 = CHARPPAR(regs->ebx+4); if (cpp1 < KERNELEND && cpp1 != NULL) return EINVALIDPTR; return syscall_pthread_barrier_init((pthread_barrier_t *)INTPAR(regs->ebx), (pthread_barrierattr_t *)INTPPAR(regs->ebx+4), INTPAR(regs->ebx+8)); case 84: cpp1 = CHARPPAR(regs->ebx); if (cpp1 < KERNELEND) return EINVALIDPTR; return syscall_pthread_barrier_wait((pthread_barrier_t *)INTPAR(regs->ebx)); case 90: return syscall_socket(INTPAR(regs->ebx), INTPAR(regs->ebx+4), INTPAR(regs->ebx+8)); case 91: cpp1 = CHARPPAR(regs->ebx+4); if (cpp1 < KERNELEND) return EINVALIDPTR; return syscall_bind(INTPAR(regs->ebx), (struct sockaddr *)INTPPAR(regs->ebx+4), SHORTPAR(regs->ebx+8)); case 92: cpp1 = CHARPPAR(regs->ebx + 4); if (cpp1 < KERNELEND) return EINVALIDPTR; return syscall_recv(INTPAR(regs->ebx), (void *)CHARPPAR(regs->ebx+4), (size_t)INTPAR(regs->ebx+8), INTPAR(regs->ebx+12)); case 93: cpp1 = CHARPPAR(regs->ebx + 4); if (cpp1 < KERNELEND) return EINVALIDPTR; cpp1 = CHARPPAR(regs->ebx+16); if (cpp1 < KERNELEND && cpp1 != NULL) return EINVALIDPTR; cpp1 = CHARPPAR(regs->ebx+20); if (cpp1 < KERNELEND && cpp1 != NULL) return EINVALIDPTR; return syscall_recvfrom(INTPAR(regs->ebx), (void *)CHARPPAR(regs->ebx+4), (size_t)INTPAR(regs->ebx+8), INTPAR(regs->ebx+12), (struct sockaddr *)CHARPPAR(regs->ebx+16), (socklen_t *)SHORTPPAR(regs->ebx+20)); case 94: cpp1 = CHARPPAR(regs->ebx + 4); if (cpp1 < KERNELEND) return EINVALIDPTR; return syscall_send(INTPAR(regs->ebx), (void *)CHARPPAR(regs->ebx+4), (size_t)INTPAR(regs->ebx+8), INTPAR(regs->ebx+12)); case 95: cpp1 = CHARPPAR(regs->ebx + 4); if (cpp1 < KERNELEND) return EINVALIDPTR; cpp1 = CHARPPAR(regs->ebx + 16); if (cpp1 < KERNELEND) return EINVALIDPTR; return syscall_sendto(INTPAR(regs->ebx), (void *)CHARPPAR(regs->ebx+4), (size_t)INTPAR(regs->ebx+8), INTPAR(regs->ebx+12), (struct sockaddr *)CHARPPAR(regs->ebx+16), (socklen_t)SHORTPAR(regs->ebx+20)); case 96: cpp1 = CHARPPAR(regs->ebx + 4); if (cpp1 < KERNELEND) return EINVALIDPTR; return syscall_connect(INTPAR(regs->ebx), (struct sockaddr *)CHARPPAR(regs->ebx+4), (socklen_t)SHORTPAR(regs->ebx+8)); case 97: cpp1 = CHARPPAR(regs->ebx + 4); if (cpp1 < KERNELEND) return EINVALIDPTR; cpp1 = CHARPPAR(regs->ebx + 8); if (cpp1 < KERNELEND) return EINVALIDPTR; return syscall_accept(INTPAR(regs->ebx), (struct sockaddr *)CHARPPAR(regs->ebx+4), (socklen_t *)CHARPPAR(regs->ebx+8)); case 98: return syscall_listen(INTPAR(regs->ebx), INTPAR(regs->ebx+4)); case 99: return syscall_kill(INTPAR(regs->ebx)); case 100: cpp1 = CHARPPAR(regs->ebx + 4); if (cpp1 < KERNELEND) return EINVALIDPTR; return syscall_getprocinfo(INTPAR(regs->ebx), (struct uprocinfo *)INTPPAR(regs->ebx+4)); case 101: cpp1 = CHARPPAR(regs->ebx); if (cpp1 < KERNELEND) return EINVALIDPTR; return syscall_getpids(INTPPAR(regs->ebx), INTPAR(regs->ebx+4)); case 102: cpp1 = CHARPPAR(regs->ebx); if (cpp1 < KERNELEND) return EINVALIDPTR; return syscall_sem_init((sem_t *)(CHARPPAR(regs->ebx)), INTPAR(regs->ebx+4), (unsigned int)INTPAR(regs->ebx+8)); case 103: cpp1 = CHARPPAR(regs->ebx); if (cpp1 < KERNELEND) return EINVALIDPTR; return syscall_sem_destroy((sem_t *)(CHARPPAR(regs->ebx))); case 104: cpp1 = CHARPPAR(regs->ebx); if (cpp1 < KERNELEND) return EINVALIDPTR; cpp1 = CHARPPAR(regs->ebx+16); if (cpp1 < KERNELEND) return EINVALIDPTR; return (int)syscall_sem_open(CHARPPAR(regs->ebx), INTPAR(regs->ebx+4), (mode_t)INTPAR(regs->ebx+8), INTPAR(regs->ebx+12), (sem_t *)CHARPPAR(regs->ebx+16)); case 105: cpp1 = CHARPPAR(regs->ebx); if (cpp1 < KERNELEND) return EINVALIDPTR; return syscall_sem_close((sem_t *)(CHARPPAR(regs->ebx))); case 106: cpp1 = CHARPPAR(regs->ebx); if (cpp1 < KERNELEND) return EINVALIDPTR; return syscall_sem_unlink(CHARPPAR(regs->ebx)); case 107: cpp1 = CHARPPAR(regs->ebx); if (cpp1 < KERNELEND) return EINVALIDPTR; return syscall_sem_wait((sem_t *)(CHARPPAR(regs->ebx))); case 108: cpp1 = CHARPPAR(regs->ebx); if (cpp1 < KERNELEND) return EINVALIDPTR; return syscall_sem_trywait((sem_t *)(CHARPPAR(regs->ebx))); case 109: cpp1 = CHARPPAR(regs->ebx); if (cpp1 < KERNELEND) return EINVALIDPTR; cpp1 = CHARPPAR(regs->ebx+4); if (cpp1 < KERNELEND) return EINVALIDPTR; return syscall_sem_timedwait((sem_t *)(CHARPPAR(regs->ebx)), (const struct timespec *)CHARPPAR(regs->ebx+4)); case 110: cpp1 = CHARPPAR(regs->ebx); if (cpp1 < KERNELEND) return EINVALIDPTR; return syscall_sem_post((sem_t *)(CHARPPAR(regs->ebx))); case 111: cpp1 = CHARPPAR(regs->ebx); if (cpp1 < KERNELEND) return EINVALIDPTR; cpp1 = CHARPPAR(regs->ebx+4); if (cpp1 < KERNELEND) return EINVALIDPTR; return syscall_sem_getvalue((sem_t *)(CHARPPAR(regs->ebx)), INTPPAR(regs->ebx+4)); case 112: cpp1 = CHARPPAR(regs->ebx); if (cpp1 < KERNELEND && cpp1 != NULL) return EINVALIDPTR; return (int)syscall_time((time_t *)(CHARPPAR(regs->ebx))); case 113: return (int)syscall_pthread_self(); case 114: cpp1 = CHARPPAR(regs->ebx); if (cpp1 < KERNELEND && cpp1 != NULL) return EINVALIDPTR; return syscall_brk((void *)CHARPPAR(regs->ebx)); case 115: cpp1 = CHARPPAR(regs->ebx); if (cpp1 < KERNELEND) return EINVALIDPTR; cpp1 = CHARPPAR(regs->ebx+4); if (cpp1 < KERNELEND) return EINVALIDPTR; cpp1 = CHARPPAR(regs->ebx+8); if (cpp1 < KERNELEND) return EINVALIDPTR; return syscall_gettsc((unsigned int *)INTPPAR(regs->ebx), (unsigned int *)INTPPAR(regs->ebx+4), (unsigned int *)INTPPAR(regs->ebx+8)); case 140: print_core_info(); print_minf_statistics(); return 0; case 147: cpp1 = CHARPPAR(regs->ebx); if (cpp1 < KERNELEND) return EINVALIDPTR; return syscall_wait(INTPPAR(regs->ebx)); case 148: return syscall_pageinfo(INTPAR(regs->ebx), INTPAR(regs->ebx+4)); case 153: syscall_machid(); return 0; case 154: return syscall_getcharf(INTPAR(regs->ebx)); case 155: return syscall_ungetcharf(INTPAR(regs->ebx), INTPAR(regs->ebx+4)); case 156: printk("broadcast called\n"); return syscall_broadcast(INTPAR(regs->ebx), CHARPPAR(regs->ebx+4), INTPAR(regs->ebx+8)); case 157: return syscall_primalloc((unsigned int)INTPAR(regs->ebx)); case 158: cpp1 = CHARPPAR(regs->ebx); if (cpp1 < KERNELEND) return EINVALIDPTR; return syscall_prifree((void *)CHARPPAR(regs->ebx), (unsigned int)INTPAR(regs->ebx+4)); case 202: cpp1 = CHARPPAR(regs->ebx); if (cpp1 < KERNELEND) return EINVALIDPTR; cpp2 = CHARPPAR(regs->ebx + 4); if (cpp2 < KERNELEND) return EINVALIDPTR; mark_tsc((unsigned int *)cpp1, (unsigned int *)cpp2); return 0; case 203: return (secs * 1000 + millesecs); case 204: cpp1 = CHARPPAR(regs->ebx); if (cpp1 < KERNELEND) return EINVALIDPTR; return syscall_pthread_mutex_destroy((pthread_mutex_t *) cpp1); default: return syscall_notimplemented(regs->eax); } }
int main (int argc, char ** argv) { init_sprite_png(0, "/usr/share/logo_login.png"); init_shmemfonts(); while (1) { syscall_print("Setup...\n"); setup_windowing(); int width = wins_globals->server_width; int height = wins_globals->server_height; win_width = width; win_height = height; /* Do something with a window */ window_t * wina = window_create(0,0, width, height); assert(wina); window_reorder (wina, 0); /* Disables movement */ ctx = init_graphics_window_double_buffer(wina); for (int i = 0; i < LOGO_FINAL_OFFSET; ++i) { draw_fill(ctx, rgb(39,55,113)); draw_sprite(ctx, sprites[0], center_x(sprites[0]->width), center_y(sprites[0]->height) - i); flip(ctx); } size_t buf_size = wina->width * wina->height * sizeof(uint32_t); char * buf = malloc(buf_size); uint32_t i = 0; uint32_t black = rgb(0,0,0); uint32_t white = rgb(255,255,255); uint32_t red = rgb(240, 20, 20); int x_offset = 65; int y_offset = 64; int fuzz = 3; char username[INPUT_SIZE] = {0}; char password[INPUT_SIZE] = {0}; char hostname[512]; { char _hostname[256]; syscall_gethostname(_hostname); struct tm * timeinfo; struct timeval now; syscall_gettimeofday(&now, NULL); //time(NULL); timeinfo = localtime((time_t *)&now.tv_sec); char _date[256]; strftime(_date, 256, "%a %B %d %Y", timeinfo); sprintf(hostname, "%s // %s", _hostname, _date); } char kernel_v[512]; { struct utsname u; uname(&u); /* UTF-8 Strings FTW! */ uint8_t * os_name_ = "PonyOS"; uint32_t l = snprintf(kernel_v, 512, "%s %s", os_name_, u.release); } uid = 0; #define BOX_WIDTH 272 #define BOX_HEIGHT 104 #define USERNAME_BOX 1 #define PASSWORD_BOX 2 #define EXTRA_TEXT_OFFSET 12 #define TEXTBOX_INTERIOR_LEFT 4 #define LEFT_OFFSET 80 int box_x = center_x(BOX_WIDTH); int box_y = center_y(0) + 8; int focus = USERNAME_BOX; set_font_size(11); int username_label_left = LEFT_OFFSET - 2 - draw_string_width("Username:"******"Password:"******""); for (int i = 0; i < strlen(password); ++i) { strcat(password_circles, "●"); } /* Redraw the background */ draw_fill(ctx, rgb(39,55,113)); draw_sprite(ctx, sprites[0], center_x(sprites[0]->width), center_y(sprites[0]->height) - LOGO_FINAL_OFFSET); draw_string(ctx, hostname_label_left, height - 12, white, hostname); draw_string(ctx, kernel_v_label_left, height - 12, white, kernel_v); /* Draw backdrops */ draw_box(ctx, box_x, box_y, BOX_WIDTH, BOX_HEIGHT, rgb(180,124,205)); draw_box(ctx, box_x + LEFT_OFFSET, box_y + 32, 168, 16, rgb(255,255,255)); draw_box(ctx, box_x + LEFT_OFFSET, box_y + 56, 168, 16, rgb(255,255,255)); /* Draw labels */ draw_string(ctx, box_x + username_label_left, box_y + 32 + EXTRA_TEXT_OFFSET, white, "Username:"******"Password:"******"Incorrect username or password."; draw_string(ctx, box_x + (BOX_WIDTH - draw_string_width(error_message)) / 2, box_y + 8 + EXTRA_TEXT_OFFSET, red, error_message); } if (focus == USERNAME_BOX) { draw_box_border(ctx, box_x + LEFT_OFFSET, box_y + 32, 168, 16, rgb(229, 68, 138)); } else if (focus == PASSWORD_BOX) { draw_box_border(ctx, box_x + LEFT_OFFSET, box_y + 56, 168, 16, rgb(229, 68, 138)); } flip(ctx); w_keyboard_t * kbd = NULL; do { kbd = poll_keyboard(); } while (!kbd); if (kbd->key == '\n') { if (focus == USERNAME_BOX) { free(kbd); focus = PASSWORD_BOX; continue; } else if (focus == PASSWORD_BOX) { free(kbd); break; } } if (kbd->key == '\t') { if (focus == USERNAME_BOX) { focus = PASSWORD_BOX; } else if (focus == PASSWORD_BOX) { focus = USERNAME_BOX; } free(kbd); continue; } if (focus == USERNAME_BOX) { buffer_put(username, kbd->key); } else if (focus == PASSWORD_BOX) { buffer_put(password, kbd->key); } free(kbd); } uid = checkUserPass(username, password); if (uid >= 0) { break; } show_error = 1; } draw_fill(ctx, rgb(39,55,113)); draw_sprite(ctx, sprites[0], center_x(sprites[0]->width), center_y(sprites[0]->height) - LOGO_FINAL_OFFSET); flip(ctx); teardown_windowing(); pid_t _session_pid = fork(); if (!_session_pid) { setenv("PATH", "/usr/bin:/bin", 0); syscall_setuid(uid); char * args[] = {"/bin/gsession", NULL}; execvp(args[0], args); } free(buf); free(ctx->backbuffer); free(ctx); syscall_wait(_session_pid); } return 0; }
static void syscall_handler (struct intr_frame *f) { // XXX : EDIT WITH 'syscall.h' 'lib/user/syscall.c' 'lib/syscall-nr.h //printf ("system call!\n"); void *now = f->esp; // XXX : Check PTR Range, and bash to syscall_exit(-1); if(!is_valid_ptr(now)) syscall_exit(-1); int syscall_number = *(int *)(f->esp); int argc_size_table[22] = { // CHECK syscall-nr.h 0, // SYS_HALT (*) :0 1, // SYS_EXIT (*) :1 1, // SYS_EXEC (*) :2 1, // SYS_WAIT (*) :3 2, // SYS_CREATE :4 1, // SYS_REMOVE :5 1, // SYS_OPEN :6 1, // SYS_FILESIZE :7 3, // SYS_READ (*) :8 3, // SYS_WRITE (*):9 2, // SYS_SEEK :10 1, // SYS_TELL :11 1, // SYS_CLOSE :12 (proj 2-2) 2, // SYS_MMAP 1, // SYS_MUNMAP 1, // SYS_CHDIR 1, // SYS_MKDIR 2, // SYS_READDIR 1, // SYS_ISDIR 1, // SYS_INUMBER 1, // SYS_PIBONACCI 4 // SYS_SUM_OF_FOUR_INTEGERS }; int argc_size = argc_size_table[syscall_number]; //printf("SYSCALL %d SIZE %d\n", syscall_number, argc_size); void *argc[4] = {NULL,}; { int i; for(i = 0; i < argc_size; i++){ now += 4; // sizeof(void *); // IT WILL USE 4 Bytes. (ref:man38). argc[i] = now; // XXX : Check argument's ptr; if(!is_valid_ptr(argc[i])) syscall_exit(-1); // printf("%x\n", now); } } switch(syscall_number){ default: case -1: break; case 0: // SYS_HALT syscall_halt(); break; case 1: // SYS_EXIT syscall_exit(*(int *)argc[0]); break; case 2: // SYS_EXEC f->eax = syscall_exec(*(const char **)argc[0]); break; case 3: // SYS_WAIT //printf("CALLED SYS_WAIT!\n"); f->eax = syscall_wait(*(pid_t *)argc[0]); break; case 4: // SYS_CREATE f->eax = syscall_create(*(const char **)argc[0], *(unsigned *)argc[1]); break; case 5: // SYS_REMOVE f->eax = syscall_remove(*(const char **)argc[0]); break; case 6: // SYS_OPEN f->eax = syscall_open(*(const char **)argc[0]); break; case 7: // SYS_FILESIZE f->eax = syscall_filesize(*(int *)argc[0]); break; case 8: // SYS_READ f->eax = syscall_read( *(int *)argc[0], *(void **)argc[1], *(unsigned *)argc[2] ); break; case 9: // SYS_WRITE //printf("CALLED WRITE! %d %x %u\n", *(int *)argc[0], argc[1], *(unsigned *)argc[2]); f->eax = syscall_write( *(int *)argc[0], *(const void **)argc[1], *(unsigned *)argc[2] ); break; case 10: // SYS_SEEK syscall_seek(*(int *)argc[0], *(unsigned *)argc[1] ); break; case 11: // SYS_TELL f->eax = syscall_tell(*(int *)argc[0]); break; case 12: // SYS_CLOSE syscall_close(*(int *)argc[0]); break; case 20: // SYS_PIBONACCI f->eax = syscall_pibonacci(*(int *)argc[0]); break; case 21: // SYS_SUM_OF_FOUR_INTEGERS f->eax = syscall_sum_of_four_integers( *(int *)argc[0], *(int *)argc[1], *(int *)argc[2], *(int *)argc[3] ); break; // case *: } // printf("SYSCALL_RETURN: %d\n", f->eax); // thread_exit (); // XXX }
static void syscall_handler (struct intr_frame *f) { /* Validate the first addr of the stack frame */ void *esp = utok_addr (f->esp, NULL); if (esp == NULL) { syscall_exit (-1); return; } enum SYSCALL_NUMBER call_number = *(enum SYSCALL_NUMBER *) esp; if (call_number < syscall_first_call || call_number > syscall_last_call) { syscall_exit (-1); return; } /* Buffer the arguments for validation */ int argc = syscall_argc[call_number]; uint32_t argbuf[3]; int i = 0; for (; i < argc; i++) { /* Validate each argument */ void *vaddr = uptr_valid((uint32_t *) f->esp + 1 + i, f->esp); if (vaddr == NULL) { syscall_exit (-1); return; } /* Translate the argument to kernel virtual (== physical) memory */ argbuf[i] = *(uint32_t *) vaddr; } int retval = 0; /* Switch based on call_number to delegate to corresponding syscall. Have not implemented several syscalls as of this project. Use validation methods to check user-provided arguments. */ switch (call_number) { case SYS_HALT: syscall_halt (); break; case SYS_EXIT: syscall_exit ((int) argbuf[0]); break; case SYS_EXEC: if (str_valid ((void *) argbuf[0], f->esp) == NULL) { syscall_exit (-1); return; } retval = syscall_exec ((char *) argbuf[0]); break; case SYS_WAIT: retval = syscall_wait ((int) argbuf[0]); break; case SYS_CREATE: if (str_valid ((char *) argbuf[0], f->esp) == NULL) { syscall_exit (-1); return; } retval = (int) syscall_create ((char *) argbuf[0], (unsigned) argbuf[1]); break; case SYS_REMOVE: if (!uptr_valid ((char *) argbuf[0], f->esp)) { syscall_exit (-1); return; } retval = (int) syscall_remove ((char *) argbuf[0]); break; case SYS_OPEN: if (str_valid ((char *) argbuf[0], f->esp) == NULL) { syscall_exit (-1); return; } retval = (int) syscall_open ((char *) argbuf[0]); break; case SYS_FILESIZE: retval = syscall_filesize ((int) argbuf[0]); break; case SYS_READ: if (buffer_valid ((void *) argbuf[1], f->esp, (unsigned) argbuf[2]) == NULL) { syscall_exit (-1); return; } retval = syscall_read ((int) argbuf[0], (void *) argbuf[1], (unsigned) argbuf[2]); break; case SYS_WRITE: if (buffer_valid ((void *) argbuf[1], f->esp, (unsigned) argbuf[2]) == NULL) { syscall_exit (-1); return; } retval = syscall_write ((int) argbuf[0], (void *) argbuf[1], (unsigned) argbuf[2]); break; case SYS_SEEK: syscall_seek ((int) argbuf[0], (unsigned) argbuf[1]); break; case SYS_TELL: retval = (int) syscall_tell ((int) argbuf[0]); break; case SYS_CLOSE: syscall_close ((int) argbuf[0]); break; #ifdef VM case SYS_MMAP: // addr will be checked internally inside mmap retval = (int) syscall_mmap ((int) argbuf[0], (void *) argbuf[1]); break; case SYS_MUNMAP: syscall_munmap ((int) argbuf[0]); break; #endif default: printf("unhandled system call!\n"); thread_exit(); } f->eax = retval; }
int syscall_entry(int eax,int ebx,int ecx,int edx) { /* console_puts("[a="); int2str(eax,s); console_puts(s); console_puts(",b="); int2str(ebx,s); console_puts(s); console_puts(",c="); int2str(ecx,s); console_puts(s); console_puts(",d="); int2str(edx,s); console_puts(s); console_puts("]"); */ cpu_unlock(); task_set_lastfunc(eax); switch(eax) { case SYSCALL_FN_PUTC: eax = syscall_putc(ebx); break; case SYSCALL_FN_PUTS: eax = syscall_puts((char*)ebx); break; case SYSCALL_FN_GETCURSOR: eax = syscall_getcursor(); break; case SYSCALL_FN_SETCURSOR: eax = syscall_setcursor(ebx); break; case SYSCALL_FN_EXIT: eax = syscall_exit(ebx); break; case SYSCALL_FN_WAIT: eax = syscall_wait(ebx); break; case SYSCALL_FN_SHM_CREATE: eax = syscall_shm_create((unsigned int)ebx, (unsigned long)ecx, (unsigned int)edx); break; case SYSCALL_FN_SHM_SETNAME: eax = syscall_shm_setname(ebx, (unsigned int)ecx); break; case SYSCALL_FN_SHM_LOOKUP: eax = syscall_shm_lookup((unsigned int)ebx); break; case SYSCALL_FN_SHM_DELETE: eax = syscall_shm_delete(ebx); break; case SYSCALL_FN_SHM_GETSIZE: eax = syscall_shm_getsize(ebx, (unsigned long *)ecx); break; case SYSCALL_FN_SHM_MAP: eax = syscall_shm_map(ebx, (void *)ecx); break; case SYSCALL_FN_SHM_UNMAP: eax = syscall_shm_unmap(ebx, (void *)ecx); break; case SYSCALL_FN_SHM_GETPHYSICAL: eax = syscall_shm_getphysical(ebx, (unsigned int)ecx, (unsigned long *)edx); break; case SYSCALL_FN_SHM_PULL: eax = syscall_shm_pull(ebx, (unsigned int)ecx, (void *)edx); break; case SYSCALL_FN_QUE_CREATE: eax = syscall_que_create((unsigned int)ebx); break; case SYSCALL_FN_QUE_SETNAME: eax = syscall_que_setname(ebx, (unsigned int)ecx); break; case SYSCALL_FN_QUE_DELETE: eax = syscall_que_delete(ebx); break; case SYSCALL_FN_QUE_PUT: eax = syscall_que_put(ebx, (void *)ecx); break; case SYSCALL_FN_QUE_GET: eax = syscall_que_get(ebx, (void *)ecx); break; case SYSCALL_FN_QUE_TRYGET: eax = syscall_que_tryget(ebx, (void *)ecx); break; case SYSCALL_FN_QUE_PEEKSIZE: eax = syscall_que_peeksize(ebx); break; case SYSCALL_FN_QUE_TRYPEEKSIZE: eax = syscall_que_trypeeksize(ebx); break; case SYSCALL_FN_QUE_LOOKUP: eax = syscall_que_lookup((unsigned int)ebx); break; case SYSCALL_FN_QUE_LIST: eax = syscall_que_list(ebx, ecx, (void*)edx); break; case SYSCALL_FN_INTR_REGIST: eax = syscall_intr_regist(ebx, ecx); break; case SYSCALL_FN_DBG_LOCPUTS: eax = syscall_dbg_locputs(ebx, ecx, (char *)edx); break; case SYSCALL_FN_PGM_LOAD: eax = syscall_pgm_load((char *)ebx, ecx); break; case SYSCALL_FN_PGM_ALLOCATE: eax = syscall_pgm_allocate((char *)ebx, ecx, (unsigned long)edx); break; case SYSCALL_FN_PGM_LOADIMAGE: eax = syscall_pgm_loadimage(ebx, (void *)ecx, (unsigned long)edx); break; case SYSCALL_FN_PGM_SETARGS: eax = syscall_pgm_setargs(ebx, (char *)ecx, edx); break; case SYSCALL_FN_PGM_GETARGS: eax = syscall_pgm_getargs(ebx, (char *)ecx, edx); break; case SYSCALL_FN_PGM_START: eax = syscall_pgm_start(ebx, ecx); break; case SYSCALL_FN_PGM_DELETE: eax = syscall_pgm_delete(ebx); break; case SYSCALL_FN_PGM_SETTASKQ: eax = syscall_pgm_settaskq(ebx); break; case SYSCALL_FN_PGM_GETTASKQ: eax = syscall_pgm_gettaskq(ebx); break; case SYSCALL_FN_PGM_GETEXITCODE: eax = syscall_pgm_getexitcode(ebx); break; case SYSCALL_FN_PGM_LIST: eax = syscall_pgm_list(ebx, ecx, (void*)edx); break; case SYSCALL_FN_FILE_OPEN: eax = syscall_file_open((char *)ebx, ecx); break; case SYSCALL_FN_FILE_CLOSE: eax = syscall_file_close(ebx); break; case SYSCALL_FN_FILE_READ: eax = syscall_file_read(ebx, (void*)ecx, edx); break; case SYSCALL_FN_FILE_SIZE: eax = syscall_file_size(ebx, (unsigned int *)ecx); break; case SYSCALL_FN_FILE_DIROPEN: eax = syscall_file_opendir((unsigned long *)ebx, (char *)ecx); break; case SYSCALL_FN_FILE_DIRREAD: eax = syscall_file_readdir((unsigned long *)ebx, (char *)ecx); break; case SYSCALL_FN_FILE_DIRCLOSE: eax = syscall_file_closedir((unsigned long *)ebx); break; case SYSCALL_FN_KRN_GET_BIOS_INFO: eax = syscall_krn_get_bios_info((char *)ebx); break; case SYSCALL_FN_KRN_MEMORY_STATUS: eax = syscall_krn_memory_status((unsigned long *)ebx); break; case SYSCALL_FN_KRN_GET_SYSTIME: eax = syscall_krn_get_systime((void *)ebx); break; case SYSCALL_FN_ALARM_SET: eax = syscall_alarm_set((unsigned int)ebx, ecx, edx); break; case SYSCALL_FN_ALARM_UNSET: eax = syscall_alarm_unset(ebx, ecx); break; case SYSCALL_FN_MTX_LOCK: eax = syscall_mtx_lock((int *)ebx); break; case SYSCALL_FN_MTX_TRYLOCK: eax = syscall_mtx_trylock((int *)ebx); break; case SYSCALL_FN_MTX_UNLOCK: eax = syscall_mtx_unlock((int *)ebx); break; case SYSCALL_FN_DMA_SETMODE: eax = syscall_dma_setmode( (unsigned int)ebx, (unsigned int)ecx ); break; case SYSCALL_FN_DMA_ENABLE: eax = syscall_dma_enable( (unsigned int)ebx, (unsigned int)ecx ); break; case SYSCALL_FN_DMA_ALLOCBUFFER: eax = syscall_dma_allocbuffer( (unsigned int)ebx, (unsigned long)ecx ); break; case SYSCALL_FN_DMA_FREEBUFFER: eax = syscall_dma_freebuffer( (unsigned int)ebx ); break; case SYSCALL_FN_DMA_SETBUFFER: eax = syscall_dma_setbuffer( (unsigned int)ebx ); break; case SYSCALL_FN_DMA_PUSHBUFFER: eax = syscall_dma_pushbuffer( (unsigned int)ebx, (void*)ecx ); break; case SYSCALL_FN_DMA_PULLBUFFER: eax = syscall_dma_pullbuffer( (unsigned int)ebx, (void*)ecx ); break; default: eax = -1; } return eax; }