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