[407] | 1 | /* |
---|
| 2 | * hal_user_syscall.c - Implementation of user-side HAL API 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 | |
---|
[505] | 24 | #include <hal_user.h> |
---|
[407] | 25 | |
---|
| 26 | ///////////////////////////////////////////// |
---|
[505] | 27 | inline int hal_user_syscall( reg_t service_num, |
---|
| 28 | reg_t arg0, |
---|
| 29 | reg_t arg1, |
---|
| 30 | reg_t arg2, |
---|
| 31 | reg_t arg3 ) |
---|
[407] | 32 | { |
---|
[425] | 33 | register int num_and_ret __asm__("v0") = service_num; |
---|
| 34 | register int a0 __asm__("a0") = arg0; |
---|
| 35 | register int a1 __asm__("a1") = arg1; |
---|
| 36 | register int a2 __asm__("a2") = arg2; |
---|
| 37 | register int a3 __asm__("a3") = arg3; |
---|
[407] | 38 | |
---|
[425] | 39 | asm volatile( |
---|
[407] | 40 | "syscall" |
---|
[425] | 41 | : "+r" (num_and_ret) |
---|
| 42 | : "r" (a0), |
---|
| 43 | "r" (a1), |
---|
| 44 | "r" (a2), |
---|
| 45 | "r" (a3) |
---|
[407] | 46 | : "memory", |
---|
| 47 | "at", |
---|
| 48 | "v1", |
---|
| 49 | "ra", |
---|
| 50 | "t0", |
---|
| 51 | "t1", |
---|
| 52 | "t2", |
---|
| 53 | "t3", |
---|
| 54 | "t4", |
---|
| 55 | "t5", |
---|
| 56 | "t6", |
---|
| 57 | "t7", |
---|
| 58 | "t8", |
---|
| 59 | "t9" |
---|
| 60 | ); |
---|
| 61 | |
---|
[425] | 62 | return (volatile int)num_and_ret; |
---|
[407] | 63 | } |
---|
| 64 | |
---|
| 65 | /////////////////////////////////// |
---|
| 66 | int hal_user_atomic_add( int * ptr, |
---|
| 67 | int val ) |
---|
| 68 | { |
---|
| 69 | int current; |
---|
| 70 | |
---|
| 71 | asm volatile ( |
---|
| 72 | ".set noreorder \n" |
---|
| 73 | "1: \n" |
---|
| 74 | "ll %0, (%1) \n" |
---|
| 75 | "addu $3, %0, %2 \n" |
---|
| 76 | "sc $3, (%1) \n" |
---|
| 77 | "beq $3, $0, 1b \n" |
---|
| 78 | "nop \n" |
---|
| 79 | "sync \n" |
---|
| 80 | ".set reorder \n" |
---|
| 81 | :"=&r"(current) : "r" (ptr), "r" (val) : "$3" , "memory" ); |
---|
| 82 | |
---|
| 83 | return current; |
---|
| 84 | } |
---|
| 85 | |
---|
| 86 | ///////////////////// |
---|
[481] | 87 | void hal_user_fence( void ) |
---|
[407] | 88 | { |
---|
| 89 | asm volatile ( "sync" ); |
---|
| 90 | } |
---|