[16] | 1 | /* |
---|
| 2 | * hal_syscall.c - Implementation of syscall handler for TSAR-MIPS32. |
---|
| 3 | * |
---|
| 4 | * Author Alain Greiner (2016,2017) |
---|
| 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 | |
---|
[457] | 24 | #include <hal_kernel_types.h> |
---|
[16] | 25 | #include <hal_syscall.h> |
---|
| 26 | #include <do_syscall.h> |
---|
| 27 | #include <thread.h> |
---|
[407] | 28 | #include <printk.h> |
---|
[406] | 29 | #include <hal_kentry.h> |
---|
[16] | 30 | |
---|
[408] | 31 | ///////////////////// |
---|
[481] | 32 | void hal_do_syscall( void ) |
---|
[16] | 33 | { |
---|
[408] | 34 | thread_t * this; |
---|
[407] | 35 | |
---|
[408] | 36 | uint32_t * enter_uzone; |
---|
| 37 | uint32_t * exit_uzone; |
---|
[407] | 38 | |
---|
[408] | 39 | uint32_t arg0; |
---|
| 40 | uint32_t arg1; |
---|
| 41 | uint32_t arg2; |
---|
| 42 | uint32_t arg3; |
---|
| 43 | uint32_t service_num; |
---|
| 44 | uint32_t retval; |
---|
[16] | 45 | |
---|
[408] | 46 | // get pointer on enter_thread uzone |
---|
| 47 | this = CURRENT_THREAD; |
---|
[425] | 48 | enter_uzone = (uint32_t *)this->uzone_current; |
---|
[16] | 49 | |
---|
[408] | 50 | // get syscall arguments from uzone |
---|
| 51 | service_num = enter_uzone[UZ_V0]; |
---|
| 52 | arg0 = enter_uzone[UZ_A0]; |
---|
| 53 | arg1 = enter_uzone[UZ_A1]; |
---|
| 54 | arg2 = enter_uzone[UZ_A2]; |
---|
| 55 | arg3 = enter_uzone[UZ_A3]; |
---|
[16] | 56 | |
---|
| 57 | // call architecture independant syscall handler |
---|
| 58 | retval = do_syscall( this, |
---|
| 59 | arg0, |
---|
| 60 | arg1, |
---|
| 61 | arg2, |
---|
| 62 | arg3, |
---|
| 63 | service_num ); |
---|
| 64 | |
---|
[425] | 65 | // get pointer on exit_thread uzone, because |
---|
[408] | 66 | // exit_thread can be different from enter_thread |
---|
| 67 | this = CURRENT_THREAD; |
---|
[425] | 68 | exit_uzone = (uint32_t *)this->uzone_current; |
---|
[407] | 69 | |
---|
[425] | 70 | // set return value to uzone |
---|
[408] | 71 | exit_uzone[UZ_V0] = retval; |
---|
[407] | 72 | |
---|
[408] | 73 | // update EPC in uzone |
---|
| 74 | exit_uzone[UZ_EPC] += 4; |
---|
| 75 | |
---|
[418] | 76 | hal_fence(); |
---|
[16] | 77 | } |
---|