[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 | |
---|
| 24 | #include <hal_types.h> |
---|
| 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 | |
---|
[418] | 31 | // @@@ |
---|
| 32 | // __attribute__((section(".kdata"))) uint32_t * enter_uzone; |
---|
| 33 | // __attribute__((section(".kdata"))) uint32_t * exit_uzone; |
---|
| 34 | // @@@ |
---|
[16] | 35 | |
---|
[408] | 36 | ///////////////////// |
---|
| 37 | void hal_do_syscall() |
---|
[16] | 38 | { |
---|
[408] | 39 | thread_t * this; |
---|
[407] | 40 | |
---|
[408] | 41 | uint32_t * enter_uzone; |
---|
| 42 | uint32_t * exit_uzone; |
---|
[407] | 43 | |
---|
[408] | 44 | uint32_t arg0; |
---|
| 45 | uint32_t arg1; |
---|
| 46 | uint32_t arg2; |
---|
| 47 | uint32_t arg3; |
---|
| 48 | uint32_t service_num; |
---|
| 49 | uint32_t retval; |
---|
[16] | 50 | |
---|
[408] | 51 | // get pointer on enter_thread uzone |
---|
| 52 | this = CURRENT_THREAD; |
---|
| 53 | enter_uzone = (uint32_t *)this->uzone; |
---|
[16] | 54 | |
---|
[408] | 55 | // get syscall arguments from uzone |
---|
| 56 | service_num = enter_uzone[UZ_V0]; |
---|
| 57 | arg0 = enter_uzone[UZ_A0]; |
---|
| 58 | arg1 = enter_uzone[UZ_A1]; |
---|
| 59 | arg2 = enter_uzone[UZ_A2]; |
---|
| 60 | arg3 = enter_uzone[UZ_A3]; |
---|
[16] | 61 | |
---|
| 62 | // call architecture independant syscall handler |
---|
| 63 | retval = do_syscall( this, |
---|
| 64 | arg0, |
---|
| 65 | arg1, |
---|
| 66 | arg2, |
---|
| 67 | arg3, |
---|
| 68 | service_num ); |
---|
| 69 | |
---|
[408] | 70 | // get pointer on exit_thread uzone, |
---|
| 71 | // exit_thread can be different from enter_thread |
---|
| 72 | this = CURRENT_THREAD; |
---|
| 73 | exit_uzone = (uint32_t *)this->uzone; |
---|
[407] | 74 | |
---|
[418] | 75 | // printk("\n@@@ %s exit : enter_uzone = %x / exit_uzone = %x\n", |
---|
| 76 | // __FUNCTION__ , enter_uzone , exit_uzone ); |
---|
| 77 | |
---|
[408] | 78 | // set syscall return value to uzone |
---|
| 79 | exit_uzone[UZ_V0] = retval; |
---|
[407] | 80 | |
---|
[408] | 81 | // update EPC in uzone |
---|
| 82 | exit_uzone[UZ_EPC] += 4; |
---|
| 83 | |
---|
[418] | 84 | hal_fence(); |
---|
[16] | 85 | } |
---|