source: trunk/hal/tsar_mips32/core/hal_user.c @ 411

Last change on this file since 411 was 407, checked in by alain, 6 years ago

First implementation of fork/exec.

File size: 2.6 KB
Line 
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/////////////////////////////////////////////
26inline int hal_user_syscall( int service_num,
27                             int arg0,
28                             int arg1,
29                             int arg2,
30                             int arg3 )
31{
32    register int reg_num_and_ret __asm__("v0") = service_num;
33    register int reg_a0          __asm__("a0") = arg0;
34    register int reg_a1          __asm__("a1") = arg1;
35    register int reg_a2          __asm__("a2") = arg2;
36    register int reg_a3          __asm__("a3") = arg3;
37
38    __asm__ volatile(
39            "syscall"
40            : "+r" (reg_num_and_ret),
41              "+r" (reg_a0),             
42              "+r" (reg_a1),
43              "+r" (reg_a2),
44              "+r" (reg_a3)
45            : 
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
62    return (volatile int)reg_num_and_ret;
63}
64
65///////////////////////////////////
66int 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/////////////////////
87void hal_user_fence()
88{
89        asm volatile ( "sync" );
90}
Note: See TracBrowser for help on using the repository browser.