[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 | |
---|
| 25 | void hal_remote_sb( xptr_t xp, |
---|
[69] | 26 | uint8_t data ) |
---|
[25] | 27 | { |
---|
[72] | 28 | *(uint8_t *)xp = data; |
---|
[25] | 29 | } |
---|
| 30 | |
---|
| 31 | void hal_remote_sw( xptr_t xp, |
---|
| 32 | uint32_t data ) |
---|
| 33 | { |
---|
[72] | 34 | *(uint32_t *)xp = data; |
---|
[25] | 35 | } |
---|
| 36 | |
---|
| 37 | void hal_remote_swd( xptr_t xp, |
---|
| 38 | uint64_t data ) |
---|
| 39 | { |
---|
[72] | 40 | *(uint64_t *)xp = data; |
---|
[25] | 41 | } |
---|
| 42 | |
---|
| 43 | void hal_remote_spt( xptr_t xp, |
---|
| 44 | void * pt ) |
---|
| 45 | { |
---|
[92] | 46 | hal_remote_swd( xp , (uint64_t)pt ); |
---|
[25] | 47 | } |
---|
| 48 | |
---|
[72] | 49 | uint8_t hal_remote_lb( xptr_t xp ) |
---|
[25] | 50 | { |
---|
[72] | 51 | return *(uint8_t *)xp; |
---|
[25] | 52 | } |
---|
| 53 | |
---|
| 54 | uint32_t hal_remote_lw( xptr_t xp ) |
---|
| 55 | { |
---|
[72] | 56 | return *(uint32_t *)xp; |
---|
[25] | 57 | } |
---|
| 58 | |
---|
| 59 | uint64_t hal_remote_lwd( xptr_t xp ) |
---|
| 60 | { |
---|
[72] | 61 | return *(uint64_t *)xp; |
---|
[25] | 62 | } |
---|
| 63 | |
---|
[92] | 64 | void *hal_remote_lpt( xptr_t xp ) |
---|
[25] | 65 | { |
---|
[92] | 66 | return (void *)hal_remote_lwd( xp ); |
---|
[25] | 67 | } |
---|
| 68 | |
---|
| 69 | bool_t hal_remote_atomic_cas( xptr_t xp, |
---|
| 70 | uint32_t old, |
---|
| 71 | uint32_t new ) |
---|
| 72 | { |
---|
[96] | 73 | return (atomic_cas_32((volatile uint32_t *)xp, old, new) == old); |
---|
[25] | 74 | } |
---|
| 75 | |
---|
| 76 | uint32_t hal_remote_atomic_add( xptr_t xp, |
---|
[94] | 77 | uint32_t incr ) // XXX define as signed |
---|
[48] | 78 | { |
---|
[96] | 79 | return atomic_add_32((volatile uint32_t *)xp, incr); |
---|
[25] | 80 | } |
---|
| 81 | |
---|
| 82 | uint32_t hal_remote_atomic_and( xptr_t xp, |
---|
| 83 | uint32_t mask ) |
---|
[48] | 84 | { |
---|
[98] | 85 | return atomic_and_32((volatile uint32_t *)xp, mask); |
---|
[25] | 86 | } |
---|
| 87 | |
---|
| 88 | uint32_t hal_remote_atomic_or( xptr_t xp, |
---|
| 89 | uint32_t mask ) |
---|
[48] | 90 | { |
---|
[98] | 91 | return atomic_or_32((volatile uint32_t *)xp, mask); |
---|
[25] | 92 | } |
---|
| 93 | |
---|
| 94 | error_t hal_remote_atomic_try_add( xptr_t xp, |
---|
| 95 | uint32_t incr, |
---|
| 96 | uint32_t * old ) |
---|
| 97 | { |
---|
[48] | 98 | x86_panic((char *)__func__); |
---|
[25] | 99 | return 0; |
---|
| 100 | } |
---|
| 101 | |
---|
| 102 | void hal_remote_memcpy( xptr_t dst, |
---|
| 103 | xptr_t src, |
---|
| 104 | uint32_t size ) |
---|
| 105 | { |
---|
[124] | 106 | memcpy((void *)dst, (void *)src, size); |
---|
[25] | 107 | } |
---|
| 108 | |
---|