[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 |
---|
[234] | 18 | * along with ALMOS-MKH; if not, write to the Free Software Foundation, |
---|
[25] | 19 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
---|
| 20 | */ |
---|
| 21 | |
---|
[457] | 22 | #include <hal_kernel_types.h> |
---|
[48] | 23 | #include <hal_internal.h> |
---|
[25] | 24 | |
---|
[209] | 25 | #include <string.h> |
---|
| 26 | |
---|
[145] | 27 | void hal_remote_sb(xptr_t xp, uint8_t data) |
---|
[25] | 28 | { |
---|
[72] | 29 | *(uint8_t *)xp = data; |
---|
[25] | 30 | } |
---|
| 31 | |
---|
[570] | 32 | void hal_remote_s32(xptr_t xp, uint32_t data) |
---|
[25] | 33 | { |
---|
[72] | 34 | *(uint32_t *)xp = data; |
---|
[25] | 35 | } |
---|
| 36 | |
---|
[570] | 37 | void hal_remote_s64(xptr_t xp, uint64_t data) |
---|
[25] | 38 | { |
---|
[72] | 39 | *(uint64_t *)xp = data; |
---|
[25] | 40 | } |
---|
| 41 | |
---|
[145] | 42 | void hal_remote_spt(xptr_t xp, void *pt) |
---|
[25] | 43 | { |
---|
[570] | 44 | hal_remote_s64(xp, (uint64_t)pt); |
---|
[25] | 45 | } |
---|
| 46 | |
---|
[145] | 47 | uint8_t hal_remote_lb(xptr_t xp) |
---|
[25] | 48 | { |
---|
[72] | 49 | return *(uint8_t *)xp; |
---|
[25] | 50 | } |
---|
| 51 | |
---|
[570] | 52 | uint32_t hal_remote_l32(xptr_t xp) |
---|
[25] | 53 | { |
---|
[72] | 54 | return *(uint32_t *)xp; |
---|
[25] | 55 | } |
---|
| 56 | |
---|
[570] | 57 | uint64_t hal_remote_l64(xptr_t xp) |
---|
[25] | 58 | { |
---|
[72] | 59 | return *(uint64_t *)xp; |
---|
[25] | 60 | } |
---|
| 61 | |
---|
[145] | 62 | void *hal_remote_lpt(xptr_t xp) |
---|
[25] | 63 | { |
---|
[570] | 64 | return (void *)hal_remote_l64(xp); |
---|
[25] | 65 | } |
---|
| 66 | |
---|
[145] | 67 | bool_t hal_remote_atomic_cas(xptr_t xp, uint32_t old, uint32_t new) |
---|
[25] | 68 | { |
---|
[96] | 69 | return (atomic_cas_32((volatile uint32_t *)xp, old, new) == old); |
---|
[25] | 70 | } |
---|
| 71 | |
---|
[145] | 72 | uint32_t hal_remote_atomic_add(xptr_t xp, uint32_t incr) |
---|
[48] | 73 | { |
---|
[96] | 74 | return atomic_add_32((volatile uint32_t *)xp, incr); |
---|
[25] | 75 | } |
---|
| 76 | |
---|
[145] | 77 | uint32_t hal_remote_atomic_and(xptr_t xp, uint32_t mask) |
---|
[48] | 78 | { |
---|
[98] | 79 | return atomic_and_32((volatile uint32_t *)xp, mask); |
---|
[25] | 80 | } |
---|
| 81 | |
---|
[145] | 82 | uint32_t hal_remote_atomic_or(xptr_t xp, uint32_t mask) |
---|
[48] | 83 | { |
---|
[98] | 84 | return atomic_or_32((volatile uint32_t *)xp, mask); |
---|
[25] | 85 | } |
---|
| 86 | |
---|
[145] | 87 | error_t hal_remote_atomic_try_add(xptr_t xp, uint32_t incr, uint32_t *old) |
---|
[25] | 88 | { |
---|
[48] | 89 | x86_panic((char *)__func__); |
---|
[25] | 90 | return 0; |
---|
| 91 | } |
---|
| 92 | |
---|
[145] | 93 | void hal_remote_memcpy(xptr_t dst, xptr_t src, uint32_t size) |
---|
[25] | 94 | { |
---|
[124] | 95 | memcpy((void *)dst, (void *)src, size); |
---|
[25] | 96 | } |
---|
| 97 | |
---|
[314] | 98 | void hal_remote_strcpy(xptr_t dst, xptr_t src) |
---|
[189] | 99 | { |
---|
[209] | 100 | strcpy((void *)dst, (void *)src); |
---|
[189] | 101 | } |
---|
| 102 | |
---|
[314] | 103 | void hal_remote_memset(xptr_t buf_xp, uint8_t byte, uint32_t size) |
---|
| 104 | { |
---|
| 105 | memset((void *)buf_xp, byte, size); |
---|
| 106 | } |
---|
| 107 | |
---|