[1] | 1 | /* |
---|
| 2 | * syscall.c - kernel unified syscall entry-point |
---|
| 3 | * |
---|
| 4 | * Author Ghassan Almaless (2008,2009,2010,2011,2012) |
---|
| 5 | * |
---|
| 6 | * Copyright (c) UPMC Sorbonne Universites |
---|
| 7 | * |
---|
| 8 | * This file is part of ALMOS-MKH. |
---|
| 9 | * |
---|
| 10 | * ALMOS-MKH.is free software; you can redistribute it and/or modify it |
---|
| 11 | * under the terms of the GNU General Public License as published by |
---|
| 12 | * the Free Software Foundation; version 2.0 of the License. |
---|
| 13 | * |
---|
| 14 | * ALMOS-MKH.is distributed in the hope that it will be useful, but |
---|
| 15 | * WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
| 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
---|
| 17 | * General Public License for more details. |
---|
| 18 | * |
---|
| 19 | * You should have received a copy of the GNU General Public License |
---|
| 20 | * along with ALMOS-MKH.; if not, write to the Free Software Foundation, |
---|
| 21 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
---|
| 22 | */ |
---|
| 23 | |
---|
| 24 | #include <syscall.h> |
---|
| 25 | #include <errno.h> |
---|
| 26 | #include <time.h> |
---|
| 27 | #include <cpu.h> |
---|
| 28 | #include <dma.h> |
---|
| 29 | #include <thread.h> |
---|
| 30 | #include <process.h> |
---|
| 31 | #include <scheduler.h> |
---|
| 32 | #include <kmem.h> |
---|
| 33 | #include <kdmsg.h> |
---|
| 34 | #include <sys-vfs.h> |
---|
| 35 | #include <cpu-trace.h> |
---|
| 36 | #include <semaphore.h> |
---|
| 37 | #include <cond_var.h> |
---|
| 38 | #include <barrier.h> |
---|
| 39 | #include <rwlock.h> |
---|
| 40 | #include <vmm.h> |
---|
| 41 | #include <signal.h> |
---|
| 42 | #include <page.h> |
---|
| 43 | |
---|
| 44 | ///////////////////////////////// |
---|
| 45 | static error_t sys_notAvailable() |
---|
| 46 | { |
---|
| 47 | printk(WARNING, "WARNING: Undefined system call\n"); |
---|
| 48 | return ENOSYS; |
---|
| 49 | } |
---|
| 50 | |
---|
| 51 | ////////////////////////////////////////////////////////////////////////// |
---|
| 52 | // Syscall vector definition |
---|
| 53 | ////////////////////////////////////////////////////////////////////////// |
---|
| 54 | |
---|
| 55 | typedef int (*sys_func_t) (); |
---|
| 56 | |
---|
| 57 | static const sys_func_t sys_call_tbl[SYSCALLS_NR] = |
---|
| 58 | { |
---|
| 59 | sys_thread_exit, // 0 |
---|
| 60 | sys_mmap, // 1 |
---|
| 61 | sys_thread_create, // 2 |
---|
| 62 | sys_thread_join, // 3 |
---|
| 63 | sys_thread_detach, // 4 |
---|
| 64 | sys_thread_yield, // 5 |
---|
| 65 | sys_sem, // 6 |
---|
| 66 | sys_cond_var, // 7 |
---|
| 67 | sys_barrier, // 8 |
---|
| 68 | sys_rwlock, // 9 |
---|
| 69 | sys_thread_sleep, // 10 |
---|
| 70 | sys_thread_wakeup, // 11 |
---|
| 71 | sys_open, // 12 |
---|
| 72 | sys_creat, // 13 |
---|
| 73 | sys_read, // 14 |
---|
| 74 | sys_write, // 15 |
---|
| 75 | sys_lseek, // 16 |
---|
| 76 | sys_close, // 17 |
---|
| 77 | sys_unlink, // 18 |
---|
| 78 | sys_pipe, // 19 |
---|
| 79 | sys_chdir, // 20 |
---|
| 80 | sys_mkdir, // 21 |
---|
| 81 | sys_mkfifo, // 22 |
---|
| 82 | sys_opendir, // 23 |
---|
| 83 | sys_readdir, // 24 |
---|
| 84 | sys_closedir, // 25 |
---|
| 85 | sys_getcwd, // 26 |
---|
| 86 | sys_clock, // 27 |
---|
| 87 | sys_alarm, // 28 |
---|
| 88 | sys_dma_memcpy, // 29 |
---|
| 89 | sys_utls, // 30 |
---|
| 90 | sys_notAvailable, // 31 reserved for sigreturn TODO ??? [AG] |
---|
| 91 | sys_signal, // 32 |
---|
| 92 | sys_sigreturn_setup, // 33 |
---|
| 93 | sys_kill, // 34 |
---|
| 94 | sys_getpid, // 35 |
---|
| 95 | sys_fork, // 36 |
---|
| 96 | sys_exec, // 37 |
---|
| 97 | sys_thread_getattr, // 38 |
---|
| 98 | sys_ps, // 39 |
---|
| 99 | sys_madvise, // 40 |
---|
| 100 | sys_mcntl, // 41 |
---|
| 101 | sys_stat, // 42 |
---|
| 102 | sys_thread_migrate, // 43 |
---|
| 103 | sys_sbrk, // 44 |
---|
| 104 | sys_rmdir, // 45 |
---|
| 105 | sys_ftime, // 46 |
---|
| 106 | sys_chmod, // 47 |
---|
| 107 | sys_fsync, // 48 |
---|
| 108 | sys_gettimeofday, // 49 |
---|
| 109 | sys_times // 50 |
---|
| 110 | }; |
---|
| 111 | |
---|
| 112 | ///////////////////////////// |
---|
| 113 | reg_t do_syscall ( reg_t arg0, |
---|
| 114 | reg_t arg1, |
---|
| 115 | reg_t arg2, |
---|
| 116 | reg_t arg3, |
---|
| 117 | reg_t service_num ) |
---|
| 118 | |
---|
| 119 | { |
---|
| 120 | int32_t return_val = 0; // default value |
---|
| 121 | thread_t * this = CURRENT_THREAD; |
---|
| 122 | cpu_t * cpu = thread_current_cpu( this ); |
---|
| 123 | |
---|
| 124 | // change thread state |
---|
| 125 | this->state = S_KERNEL; |
---|
| 126 | |
---|
| 127 | // prepare kernel time computation |
---|
| 128 | tm_usr_compute( this ); |
---|
| 129 | |
---|
| 130 | /* TODO Pourqoi cette sauvegarde ? [AG] |
---|
| 131 | return_val = cpu_context_save( &this->info.pss ); |
---|
| 132 | |
---|
| 133 | if(return_val != 0) |
---|
| 134 | { |
---|
| 135 | // Reload these pointers as the process may be forked |
---|
| 136 | this = CURRENT_THREAD; |
---|
| 137 | cpu = current_cpu; |
---|
| 138 | cpu_wbflush(); |
---|
| 139 | |
---|
| 140 | return_val = this->info.retval; |
---|
| 141 | goto END_DO_SYSCALL; |
---|
| 142 | } |
---|
| 143 | */ |
---|
| 144 | |
---|
| 145 | // check syscall index |
---|
| 146 | if( service_num >= SYSCALLS_NR ) |
---|
| 147 | { |
---|
| 148 | printk(INFO, "INFO %s : Undefined sysccall %d / thread = %x in cluster %x\n", |
---|
| 149 | __FUNCTION__, service_num, this, cluster_cxy ); |
---|
| 150 | |
---|
| 151 | this->info.errno = ENOSYS; |
---|
| 152 | goto END_DO_SYSCALL; |
---|
| 153 | } |
---|
| 154 | |
---|
| 155 | // debug message before syscall execution |
---|
| 156 | if( this->info.isTraced == true ) |
---|
| 157 | { |
---|
| 158 | printk(DEBUG, "DEBUG %s : Pid %d / Tid %d / CPU %d in cluster %x\n" |
---|
| 159 | " Service %d / Arg0 %x / Arg1 %x / Arg2 %x / Arg3 %x\n", |
---|
| 160 | __FUNCTION__, this->process->pid, this->info.order, cpu->lid, cluster_cxy, |
---|
| 161 | service_num, arg0, arg1, arg2, arg3); |
---|
| 162 | } |
---|
| 163 | |
---|
| 164 | // reset errno |
---|
| 165 | this->info.errno = 0; |
---|
| 166 | |
---|
| 167 | // enable interrupts |
---|
| 168 | cpu_enable_all_irq( NULL ); |
---|
| 169 | |
---|
| 170 | // call the proper kernel function |
---|
| 171 | return_val = sys_call_tbl[service_num] (arg0,arg1,arg2,arg3); |
---|
| 172 | |
---|
| 173 | // disable interrupts |
---|
| 174 | cpu_disable_all_irq(NULL); |
---|
| 175 | |
---|
| 176 | // debug message after syscall execution |
---|
| 177 | if(this->info.isTraced == true) |
---|
| 178 | { |
---|
| 179 | printk(DEBUG, "DEBUG %s : Pid %d / Tid %d / CPU %d in cluster %x\n" |
---|
| 180 | " Service %d / Return = %x / Error = %d\n", |
---|
| 181 | __FUNCTION__, this->process->pid, this->info.order, cpu->lid, cluster_cxy, |
---|
| 182 | service_num, return_val, this->info.errno ); |
---|
| 183 | } |
---|
| 184 | |
---|
| 185 | END_DO_SYSCALL: |
---|
| 186 | |
---|
| 187 | // compute kernel time |
---|
| 188 | tm_sys_compute(this); |
---|
| 189 | |
---|
| 190 | // update thread state |
---|
| 191 | this->info.retval = return_val; |
---|
| 192 | this->state = S_USER; |
---|
| 193 | |
---|
| 194 | // notify syscall completion |
---|
| 195 | signal_notify( this ); |
---|
| 196 | |
---|
| 197 | return return_val; |
---|
| 198 | } // end do_syscall() |
---|