1/* $NetBSD: fusu.S,v 1.8 2019/10/28 18:14:38 joerg Exp $ */ 2 3/*- 4 * Copyright (c) 2019 The NetBSD Foundation, Inc. 5 * All rights reserved. 6 * 7 * This code is derived from software contributed to The NetBSD Foundation 8 * by Jason R. Thorpe. 9 * 10 * Redistribution and use in source and binary forms, with or without 11 * modification, are permitted provided that the following conditions 12 * are met: 13 * 1. Redistributions of source code must retain the above copyright 14 * notice, this list of conditions and the following disclaimer. 15 * 2. Redistributions in binary form must reproduce the above copyright 16 * notice, this list of conditions and the following disclaimer in the 17 * documentation and/or other materials provided with the distribution. 18 * 19 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS 20 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 21 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 22 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 23 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 24 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 25 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 26 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 27 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 28 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 29 * POSSIBILITY OF SUCH DAMAGE. 30 */ 31 32/* 33 * Copyright (c) 1996-1998 Mark Brinicombe. 34 * All rights reserved. 35 * 36 * Redistribution and use in source and binary forms, with or without 37 * modification, are permitted provided that the following conditions 38 * are met: 39 * 1. Redistributions of source code must retain the above copyright 40 * notice, this list of conditions and the following disclaimer. 41 * 2. Redistributions in binary form must reproduce the above copyright 42 * notice, this list of conditions and the following disclaimer in the 43 * documentation and/or other materials provided with the distribution. 44 * 3. All advertising materials mentioning features or use of this software 45 * must display the following acknowledgement: 46 * This product includes software developed by Mark Brinicombe 47 * 4. The name of the company nor the name of the author may be used to 48 * endorse or promote products derived from this software without specific 49 * prior written permission. 50 * 51 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED 52 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 53 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 54 * IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, 55 * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 56 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 57 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 58 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 59 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 60 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 61 * SUCH DAMAGE. 62 */ 63 64#include "opt_multiprocessor.h" 65#include "opt_cpuoptions.h" 66 67#include "assym.h" 68 69#include <machine/asm.h> 70 71#include <arm/locore.h> 72 73#if (ARM_ARCH_2 + ARM_ARCH_3 + ARM_ARCH_4 + ARM_ARCH_5 + ARM_ARCH_6) > 0 74#define NO_LDRHT_STRHT 75#endif 76 77#define RETURN_SUCCESS \ 78 mov r0, #0x00000000 ; \ 79 mov pc, lr 80 81#define RETURN_ERROR_ALREADY_IN_R0 \ 82 mov pc, lr 83 84#define UFETCHSTORE_PROLOGUE \ 85 GET_CURPCB(r2) ; \ 86 adr r3, _C_LABEL(ufetchstore_fault) ; \ 87 str r3, [r2, #PCB_ONFAULT] 88 89#define UFETCHSTORE_EPILOGUE \ 90 mov r3, #0x00000000 ; \ 91 str r3, [r2, #PCB_ONFAULT] 92 93 94/* LINTSTUB: int _ufetch_8(const uint8_t *uaddr, uint8_t *valp); */ 95 96ENTRY(_ufetch_8) 97 UFETCHSTORE_PROLOGUE 98 99 ldrbt r3, [r0] 100 strb r3, [r1] 101 102 UFETCHSTORE_EPILOGUE 103 RETURN_SUCCESS 104END(_ufetch_8) 105 106#ifdef NO_LDRHT_STRHT 107/* LINTSTUB: int _ufetch_16_no_ldrht(const uint16_t *uaddr, uint16_t *valp); */ 108ENTRY(_ufetch_16_no_ldrht) 109 UFETCHSTORE_PROLOGUE 110 111 ldrbt r3, [r0], #1 112 strb r3, [r1], #1 113 114 ldrbt r3, [r0] 115 strb r3, [r1] 116 117 UFETCHSTORE_EPILOGUE 118 RETURN_SUCCESS 119END(_ufetch_16_no_ldrht) 120 121/* LINTSTUB: int _ufetch_16(const uint16_t *uaddr, uint16_t *valp); */ 122STRONG_ALIAS(_ufetch_16,_ufetch_16_no_ldrht) 123 124#else /* XXX */ 125 126/* LINTSTUB: int _ufetch_16_ldrht(const uint16_t *uaddr, uint16_t *valp); */ 127ENTRY(_ufetch_16_ldrht) 128 UFETCHSTORE_PROLOGUE 129 130 ldrht r3, [r0], #0 131 strh r3, [r1] 132 133 UFETCHSTORE_EPILOGUE 134 RETURN_SUCCESS 135END(_ufetch_16_ldrht) 136 137/* LINTSTUB: int _ufetch_16(const uint16_t *uaddr, uint16_t *valp); */ 138STRONG_ALIAS(_ufetch_16,_ufetch_16_ldrht) 139#endif /* NO_LDRHT_STRHT */ 140 141/* LINTSTUB: int _ufetch_32(const uint32_t *uaddr, uint32_t *valp); */ 142ENTRY(_ufetch_32) 143 UFETCHSTORE_PROLOGUE 144 145 ldrt r3, [r0] 146 str r3, [r1] 147 148 UFETCHSTORE_EPILOGUE 149 RETURN_SUCCESS 150END(_ufetch_32) 151 152/* LINTSTUB: int _ustore_8(uint8_t *uaddr, uint8_t val); */ 153ENTRY(_ustore_8) 154 UFETCHSTORE_PROLOGUE 155 156 strbt r1, [r0] 157 158 UFETCHSTORE_EPILOGUE 159 RETURN_SUCCESS 160END(_ustore_8) 161 162#ifdef NO_LDRHT_STRHT 163/* LINTSTUB: int _ustore_16_no_strht(uint16_t *uaddr, uint16_t val); */ 164ENTRY(_ustore_16_no_strht) 165 UFETCHSTORE_PROLOGUE 166 167#ifdef __ARMEB__ 168 mov r3, r1, lsr #8 169 strbt r3, [r0], #1 170#else 171 strbt r1, [r0], #1 172 mov r1, r1, lsr #8 173#endif 174 strbt r1, [r0] 175 176 UFETCHSTORE_EPILOGUE 177 RETURN_SUCCESS 178END(_ustore_16_no_strht) 179 180/* LINTSTUB: int _ustore_16(uint16_t *uaddr, uint16_t val); */ 181STRONG_ALIAS(_ustore_16,_ustore_16_no_strht) 182 183#else /* XXX */ 184 185/* LINTSTUB: int _ustore_16_strht(uint16_t *uaddr, uint16_t val); */ 186ENTRY(_ustore_16_strht) 187 UFETCHSTORE_PROLOGUE 188 189 strht r1, [r0], #0 190 191 UFETCHSTORE_EPILOGUE 192 RETURN_SUCCESS 193END(_ustore_16_strht) 194 195/* LINTSTUB: int _ustore_16(uint16_t *uaddr, uint16_t val); */ 196STRONG_ALIAS(_ustore_16,_ustore_16_strht) 197#endif /* NO_LDRHT_STRHT */ 198 199/* LINTSTUB: int _ustore_32(uint32_t *uaddr, uint32_t val); */ 200ENTRY(_ustore_32) 201 UFETCHSTORE_PROLOGUE 202 203 strt r1, [r0] 204 205 UFETCHSTORE_EPILOGUE 206 RETURN_SUCCESS 207END(_ustore_32) 208 209ENTRY_NP(ufetchstore_fault) 210 UFETCHSTORE_EPILOGUE 211 RETURN_ERROR_ALREADY_IN_R0 212END(ufetchstore_fault) 213 214/* XXXJRT Can we G/C this? */ 215 .data 216 .align 0 217 .global _C_LABEL(block_userspace_access) 218_C_LABEL(block_userspace_access): 219 .word 0 220