source: trunk/hal/tsar_mips32/core/hal_atomic.c @ 506

Last change on this file since 506 was 505, checked in by viala@…, 6 years ago

[hal] Fix protoypes and add headers in hal mips32 implementation.

Fix types mismatch between implementation and interface in .h.
Add header where they were absent.

File size: 3.6 KB
Line 
1/*
2 * hal_atomic.c - implementation of Generic Atomic Operations API for TSAR-MIPS32
3 *
4 * Author  Alain Greiner (2016)
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_kernel_types.h>
25#include <hal_atomic.h>
26
27////////////////////////////////////
28void hal_atomic_and( uint32_t * ptr,
29                     uint32_t   val )
30{
31        asm volatile (
32                 ".set noreorder                             \n"       
33                 "1:                                 \n"
34                 "ll      $3,      (%0)              \n"
35                 "and     $3,      $3,       %1      \n"
36                 "sc      $3,      (%0)              \n"
37                 "beq     $3,      $0,       1b      \n"
38                 "nop                                \n"
39                 "sync                               \n"
40                 ".set reorder                               \n"       
41                 : : "r" (ptr), "r" (val) : "$3" , "memory" );
42}
43
44///////////////////////////////////
45void hal_atomic_or( uint32_t * ptr,
46                    uint32_t   val )
47{
48        asm volatile (
49                 ".set noreorder                             \n"       
50                 "1:                                 \n"
51                 "ll      $3,      (%0)              \n"
52                 "or      $3,      $3,       %1      \n"
53                 "sc      $3,      (%0)              \n"
54                 "beq     $3,      $0,       1b      \n"
55                 "nop                                \n"
56                 "sync                               \n"
57                 ".set reorder                               \n"       
58                 : : "r" (ptr), "r" (val) : "$3" , "memory" );
59}
60
61///////////////////////////////////////
62int32_t hal_atomic_add( void     * ptr,
63                        int32_t   val )
64{
65        int32_t current;
66 
67        asm volatile (
68                 ".set noreorder                             \n"       
69                 "1:                                 \n"
70                 "ll      %0,      (%1)              \n"
71                 "addu    $3,      %0,       %2      \n"
72                 "sc      $3,      (%1)              \n"
73                 "beq     $3,      $0,       1b      \n"
74                 "nop                                \n"
75                 "sync                               \n"
76                 ".set reorder                               \n"       
77                 :"=&r"(current) : "r" (ptr), "r" (val) : "$3" , "memory" );
78
79        return current;
80}
81
82//////////////////////////////////////
83bool_t hal_atomic_cas( uint32_t * ptr,
84                       uint32_t   old, 
85                       uint32_t   new )
86{
87        bool_t isAtomic;
88 
89        asm volatile (
90                 ".set noreorder                     \n"
91                 "sync                               \n"
92                 "or      $8,      $0,       %3      \n"
93                 "ll      $3,      (%1)              \n"
94                 "bne     $3,      %2,       1f      \n"
95                 "li      $7,      0                 \n"
96                 "sc      $8,      (%1)              \n"
97                 "or      $7,      $8,       $0      \n"
98                 "sync                               \n"
99                 ".set reorder                       \n"
100                 "1:                                 \n"
101                 "or      %0,      $7,       $0      \n"
102                 : "=&r" (isAtomic): "r" (ptr), "r" (old) , "r" (new) : "$3", "$7", "$8");
103
104        return isAtomic;
105}
106
107///////////////////////////////////////////
108bool_t hal_atomic_test_set( uint32_t * ptr,
109                            uint32_t   val )
110{
111        return hal_atomic_cas( ptr , 0 , val );
112}
113
Note: See TracBrowser for help on using the repository browser.