Loading...
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 | /* asm_inline_gcc.h - ARC inline assembler and macros for public functions */ /* * Copyright (c) 2015 Intel Corporation. * * SPDX-License-Identifier: Apache-2.0 */ #ifndef __ASM_INLINE_GCC_H__ #define __ASM_INLINE_GCC_H__ #ifdef __cplusplus extern "C" { #endif #ifndef _ASMLANGUAGE #include <sys_io.h> #include <arch/arc/v2/aux_regs.h> #include <zephyr/types.h> #include <stddef.h> /** * @brief read timestamp register (CPU frequency) */ extern u64_t _tsc_read(void); /* Implementation of sys_io.h's documented functions */ static ALWAYS_INLINE void sys_out8(u8_t data, io_port_t port) { _arc_v2_aux_reg_write(port, data); } static ALWAYS_INLINE u8_t sys_in8(io_port_t port) { return (u8_t)(_arc_v2_aux_reg_read(port) & 0x000000ff); } static ALWAYS_INLINE void sys_out16(u16_t data, io_port_t port) { _arc_v2_aux_reg_write(port, data); } static ALWAYS_INLINE u16_t sys_in16(io_port_t port) { return (u16_t)(_arc_v2_aux_reg_read(port) & 0x0000ffff); } static ALWAYS_INLINE void sys_out32(u32_t data, io_port_t port) { _arc_v2_aux_reg_write(port, data); } static ALWAYS_INLINE u32_t sys_in32(io_port_t port) { return _arc_v2_aux_reg_read(port); } static ALWAYS_INLINE void sys_io_set_bit(io_port_t port, unsigned int bit) { u32_t reg = 0; __asm__ volatile("lr %1, [%0]\n" "bset %1, %1, %2\n" "sr %1, [%0];\n\t" : : "ir" (port), "r" (reg), "Mr" (bit) : "memory", "cc"); } static ALWAYS_INLINE void sys_io_clear_bit(io_port_t port, unsigned int bit) { u32_t reg = 0; __asm__ volatile("lr %1, [%0]\n" "bclr %1, %1, %2\n" "sr %1, [%0];\n\t" : : "ir" (port), "r" (reg), "Mr" (bit) : "memory", "cc"); } static ALWAYS_INLINE int sys_io_test_bit(io_port_t port, unsigned int bit) { u32_t status = _ARC_V2_STATUS32; u32_t reg = 0; u32_t ret; __asm__ volatile("lr %2, [%1]\n" "btst %2, %3\n" "lr %0, [%4];\n\t" : "=r" (ret) : "ir" (port), "r" (reg), "Mr" (bit), "i" (status) : "memory", "cc"); return !(ret & _ARC_V2_STATUS32_Z); } static ALWAYS_INLINE int sys_io_test_and_set_bit(io_port_t port, unsigned int bit) { int ret; ret = sys_io_test_bit(port, bit); sys_io_set_bit(port, bit); return ret; } static ALWAYS_INLINE int sys_io_test_and_clear_bit(io_port_t port, unsigned int bit) { int ret; ret = sys_io_test_bit(port, bit); sys_io_clear_bit(port, bit); return ret; } static ALWAYS_INLINE void sys_write8(u8_t data, mm_reg_t addr) { __asm__ volatile("stb%U1 %0, %1;\n\t" : : "r" (data), "m" (*(volatile u8_t *) addr) : "memory"); } static ALWAYS_INLINE u8_t sys_read8(mm_reg_t addr) { u8_t ret; __asm__ volatile("ldb%U1 %0, %1;\n\t" : "=r" (ret) : "m" (*(volatile u8_t *) addr) : "memory"); return ret; } static ALWAYS_INLINE void sys_write16(u16_t data, mm_reg_t addr) { __asm__ volatile("sth%U1 %0, %1;\n\t" : : "r" (data), "m" (*(volatile u16_t *) addr) : "memory"); } static ALWAYS_INLINE u16_t sys_read16(mm_reg_t addr) { u16_t ret; __asm__ volatile("ldh%U1 %0, %1;\n\t" : "=r" (ret) : "m" (*(volatile u16_t *) addr) : "memory"); return ret; } static ALWAYS_INLINE void sys_write32(u32_t data, mm_reg_t addr) { __asm__ volatile("st%U1 %0, %1;\n\t" : : "r" (data), "m" (*(volatile u32_t *) addr) : "memory"); } static ALWAYS_INLINE u32_t sys_read32(mm_reg_t addr) { u32_t ret; __asm__ volatile("ld%U1 %0, %1;\n\t" : "=r" (ret) : "m" (*(volatile u32_t *) addr) : "memory"); return ret; } static ALWAYS_INLINE void sys_set_bit(mem_addr_t addr, unsigned int bit) { u32_t reg = 0; __asm__ volatile("ld %1, %0\n" "bset %1, %1, %2\n" "st %1, %0;\n\t" : "+m" (*(volatile u32_t *) addr) : "r" (reg), "Mr" (bit) : "memory", "cc"); } static ALWAYS_INLINE void sys_clear_bit(mem_addr_t addr, unsigned int bit) { u32_t reg = 0; __asm__ volatile("ld %1, %0\n" "bclr %1, %1, %2\n" "st %1, %0;\n\t" : "+m" (*(volatile u32_t *) addr) : "r" (reg), "Mr" (bit) : "memory", "cc"); } static ALWAYS_INLINE int sys_test_bit(mem_addr_t addr, unsigned int bit) { u32_t status = _ARC_V2_STATUS32; u32_t reg = 0; u32_t ret; __asm__ volatile("ld %2, %1\n" "btst %2, %3\n" "lr %0, [%4];\n\t" : "=r" (ret) : "m" (*(volatile u32_t *) addr), "r" (reg), "Mr" (bit), "i" (status) : "memory", "cc"); return !(ret & _ARC_V2_STATUS32_Z); } static ALWAYS_INLINE int sys_test_and_set_bit(mem_addr_t addr, unsigned int bit) { int ret; ret = sys_test_bit(addr, bit); sys_set_bit(addr, bit); return ret; } static ALWAYS_INLINE int sys_test_and_clear_bit(mem_addr_t addr, unsigned int bit) { int ret; ret = sys_test_bit(addr, bit); sys_clear_bit(addr, bit); return ret; } static ALWAYS_INLINE void sys_bitfield_set_bit(mem_addr_t addr, unsigned int bit) { /* Doing memory offsets in terms of 32-bit values to prevent * alignment issues */ sys_set_bit(addr + ((bit >> 5) << 2), bit & 0x1F); } static ALWAYS_INLINE void sys_bitfield_clear_bit(mem_addr_t addr, unsigned int bit) { sys_clear_bit(addr + ((bit >> 5) << 2), bit & 0x1F); } static ALWAYS_INLINE int sys_bitfield_test_bit(mem_addr_t addr, unsigned int bit) { return sys_test_bit(addr + ((bit >> 5) << 2), bit & 0x1F); } static ALWAYS_INLINE int sys_bitfield_test_and_set_bit(mem_addr_t addr, unsigned int bit) { int ret; ret = sys_bitfield_test_bit(addr, bit); sys_bitfield_set_bit(addr, bit); return ret; } static ALWAYS_INLINE int sys_bitfield_test_and_clear_bit(mem_addr_t addr, unsigned int bit) { int ret; ret = sys_bitfield_test_bit(addr, bit); sys_bitfield_clear_bit(addr, bit); return ret; } #endif /* _ASMLANGUAGE */ #ifdef __cplusplus } #endif #endif /* __ASM_INLINE_GCC_H__ */ |