[25] | 1 | /* |
---|
[105] | 2 | * hal_remote.c - implementation of Generic Remote Access API x86 |
---|
[25] | 3 | * |
---|
[105] | 4 | * Copyright (c) 2017 Maxime Villard |
---|
[25] | 5 | * |
---|
[105] | 6 | * This file is part of ALMOS-MKH. |
---|
| 7 | * |
---|
| 8 | * ALMOS-MKH is free software; you can redistribute it and/or modify it |
---|
[25] | 9 | * under the terms of the GNU General Public License as published by |
---|
| 10 | * the Free Software Foundation; version 2.0 of the License. |
---|
| 11 | * |
---|
[105] | 12 | * ALMOS-MKH is distributed in the hope that it will be useful, but |
---|
[25] | 13 | * WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
| 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
---|
| 15 | * General Public License for more details. |
---|
| 16 | * |
---|
| 17 | * You should have received a copy of the GNU General Public License |
---|
| 18 | * along with ALMOS-MKH.; if not, write to the Free Software Foundation, |
---|
| 19 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
---|
| 20 | */ |
---|
| 21 | |
---|
| 22 | #include <hal_types.h> |
---|
[48] | 23 | #include <hal_internal.h> |
---|
[25] | 24 | |
---|
[145] | 25 | void hal_remote_sb(xptr_t xp, uint8_t data) |
---|
[25] | 26 | { |
---|
[72] | 27 | *(uint8_t *)xp = data; |
---|
[25] | 28 | } |
---|
| 29 | |
---|
[145] | 30 | void hal_remote_sw(xptr_t xp, uint32_t data) |
---|
[25] | 31 | { |
---|
[72] | 32 | *(uint32_t *)xp = data; |
---|
[25] | 33 | } |
---|
| 34 | |
---|
[145] | 35 | void hal_remote_swd(xptr_t xp, uint64_t data) |
---|
[25] | 36 | { |
---|
[72] | 37 | *(uint64_t *)xp = data; |
---|
[25] | 38 | } |
---|
| 39 | |
---|
[145] | 40 | void hal_remote_spt(xptr_t xp, void *pt) |
---|
[25] | 41 | { |
---|
[145] | 42 | hal_remote_swd(xp, (uint64_t)pt); |
---|
[25] | 43 | } |
---|
| 44 | |
---|
[145] | 45 | uint8_t hal_remote_lb(xptr_t xp) |
---|
[25] | 46 | { |
---|
[72] | 47 | return *(uint8_t *)xp; |
---|
[25] | 48 | } |
---|
| 49 | |
---|
[145] | 50 | uint32_t hal_remote_lw(xptr_t xp) |
---|
[25] | 51 | { |
---|
[72] | 52 | return *(uint32_t *)xp; |
---|
[25] | 53 | } |
---|
| 54 | |
---|
[145] | 55 | uint64_t hal_remote_lwd(xptr_t xp) |
---|
[25] | 56 | { |
---|
[72] | 57 | return *(uint64_t *)xp; |
---|
[25] | 58 | } |
---|
| 59 | |
---|
[145] | 60 | void *hal_remote_lpt(xptr_t xp) |
---|
[25] | 61 | { |
---|
[145] | 62 | return (void *)hal_remote_lwd(xp); |
---|
[25] | 63 | } |
---|
| 64 | |
---|
[145] | 65 | bool_t hal_remote_atomic_cas(xptr_t xp, uint32_t old, uint32_t new) |
---|
[25] | 66 | { |
---|
[96] | 67 | return (atomic_cas_32((volatile uint32_t *)xp, old, new) == old); |
---|
[25] | 68 | } |
---|
| 69 | |
---|
[145] | 70 | uint32_t hal_remote_atomic_add(xptr_t xp, uint32_t incr) |
---|
[48] | 71 | { |
---|
[96] | 72 | return atomic_add_32((volatile uint32_t *)xp, incr); |
---|
[25] | 73 | } |
---|
| 74 | |
---|
[145] | 75 | uint32_t hal_remote_atomic_and(xptr_t xp, uint32_t mask) |
---|
[48] | 76 | { |
---|
[98] | 77 | return atomic_and_32((volatile uint32_t *)xp, mask); |
---|
[25] | 78 | } |
---|
| 79 | |
---|
[145] | 80 | uint32_t hal_remote_atomic_or(xptr_t xp, uint32_t mask) |
---|
[48] | 81 | { |
---|
[98] | 82 | return atomic_or_32((volatile uint32_t *)xp, mask); |
---|
[25] | 83 | } |
---|
| 84 | |
---|
[145] | 85 | error_t hal_remote_atomic_try_add(xptr_t xp, uint32_t incr, uint32_t *old) |
---|
[25] | 86 | { |
---|
[48] | 87 | x86_panic((char *)__func__); |
---|
[25] | 88 | return 0; |
---|
| 89 | } |
---|
| 90 | |
---|
[145] | 91 | void hal_remote_memcpy(xptr_t dst, xptr_t src, uint32_t size) |
---|
[25] | 92 | { |
---|
[124] | 93 | memcpy((void *)dst, (void *)src, size); |
---|
[25] | 94 | } |
---|
| 95 | |
---|