1 /* 2 * PowerPC emulation helpers for QEMU. 3 * 4 * Copyright (c) 2003-2007 Jocelyn Mayer 5 * 6 * This library is free software; you can redistribute it and/or 7 * modify it under the terms of the GNU Lesser General Public 8 * License as published by the Free Software Foundation; either 9 * version 2 of the License, or (at your option) any later version. 10 * 11 * This library is distributed in the hope that it will be useful, 12 * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 * Lesser General Public License for more details. 15 * 16 * You should have received a copy of the GNU Lesser General Public 17 * License along with this library; if not, see <http://www.gnu.org/licenses/>. 18 */ 19 #include "qemu/osdep.h" 20 #include "cpu.h" 21 #include "exec/helper-proto.h" 22 #include "exec/exec-all.h" 23 #include "qemu/log.h" 24 25 /*****************************************************************************/ 26 /* SPR accesses */ 27 28 target_ulong helper_load_tbl(CPUPPCState *env) 29 { 30 return (target_ulong)cpu_ppc_load_tbl(env); 31 } 32 33 target_ulong helper_load_tbu(CPUPPCState *env) 34 { 35 return cpu_ppc_load_tbu(env); 36 } 37 38 target_ulong helper_load_atbl(CPUPPCState *env) 39 { 40 return (target_ulong)cpu_ppc_load_atbl(env); 41 } 42 43 target_ulong helper_load_atbu(CPUPPCState *env) 44 { 45 return cpu_ppc_load_atbu(env); 46 } 47 48 target_ulong helper_load_vtb(CPUPPCState *env) 49 { 50 return cpu_ppc_load_vtb(env); 51 } 52 53 #if defined(TARGET_PPC64) && !defined(CONFIG_USER_ONLY) 54 target_ulong helper_load_purr(CPUPPCState *env) 55 { 56 return (target_ulong)cpu_ppc_load_purr(env); 57 } 58 #endif 59 60 target_ulong helper_load_601_rtcl(CPUPPCState *env) 61 { 62 return cpu_ppc601_load_rtcl(env); 63 } 64 65 target_ulong helper_load_601_rtcu(CPUPPCState *env) 66 { 67 return cpu_ppc601_load_rtcu(env); 68 } 69 70 #if !defined(CONFIG_USER_ONLY) 71 void helper_store_tbl(CPUPPCState *env, target_ulong val) 72 { 73 cpu_ppc_store_tbl(env, val); 74 } 75 76 void helper_store_tbu(CPUPPCState *env, target_ulong val) 77 { 78 cpu_ppc_store_tbu(env, val); 79 } 80 81 void helper_store_atbl(CPUPPCState *env, target_ulong val) 82 { 83 cpu_ppc_store_atbl(env, val); 84 } 85 86 void helper_store_atbu(CPUPPCState *env, target_ulong val) 87 { 88 cpu_ppc_store_atbu(env, val); 89 } 90 91 void helper_store_601_rtcl(CPUPPCState *env, target_ulong val) 92 { 93 cpu_ppc601_store_rtcl(env, val); 94 } 95 96 void helper_store_601_rtcu(CPUPPCState *env, target_ulong val) 97 { 98 cpu_ppc601_store_rtcu(env, val); 99 } 100 101 target_ulong helper_load_decr(CPUPPCState *env) 102 { 103 return cpu_ppc_load_decr(env); 104 } 105 106 void helper_store_decr(CPUPPCState *env, target_ulong val) 107 { 108 cpu_ppc_store_decr(env, val); 109 } 110 111 target_ulong helper_load_hdecr(CPUPPCState *env) 112 { 113 return cpu_ppc_load_hdecr(env); 114 } 115 116 void helper_store_hdecr(CPUPPCState *env, target_ulong val) 117 { 118 cpu_ppc_store_hdecr(env, val); 119 } 120 121 void helper_store_vtb(CPUPPCState *env, target_ulong val) 122 { 123 cpu_ppc_store_vtb(env, val); 124 } 125 126 target_ulong helper_load_40x_pit(CPUPPCState *env) 127 { 128 return load_40x_pit(env); 129 } 130 131 void helper_store_40x_pit(CPUPPCState *env, target_ulong val) 132 { 133 store_40x_pit(env, val); 134 } 135 136 void helper_store_booke_tcr(CPUPPCState *env, target_ulong val) 137 { 138 store_booke_tcr(env, val); 139 } 140 141 void helper_store_booke_tsr(CPUPPCState *env, target_ulong val) 142 { 143 store_booke_tsr(env, val); 144 } 145 #endif 146 147 /*****************************************************************************/ 148 /* Embedded PowerPC specific helpers */ 149 150 /* XXX: to be improved to check access rights when in user-mode */ 151 target_ulong helper_load_dcr(CPUPPCState *env, target_ulong dcrn) 152 { 153 uint32_t val = 0; 154 155 if (unlikely(env->dcr_env == NULL)) { 156 qemu_log_mask(LOG_GUEST_ERROR, "No DCR environment\n"); 157 raise_exception_err_ra(env, POWERPC_EXCP_PROGRAM, 158 POWERPC_EXCP_INVAL | 159 POWERPC_EXCP_INVAL_INVAL, GETPC()); 160 } else if (unlikely(ppc_dcr_read(env->dcr_env, 161 (uint32_t)dcrn, &val) != 0)) { 162 qemu_log_mask(LOG_GUEST_ERROR, "DCR read error %d %03x\n", 163 (uint32_t)dcrn, (uint32_t)dcrn); 164 raise_exception_err_ra(env, POWERPC_EXCP_PROGRAM, 165 POWERPC_EXCP_INVAL | 166 POWERPC_EXCP_PRIV_REG, GETPC()); 167 } 168 return val; 169 } 170 171 void helper_store_dcr(CPUPPCState *env, target_ulong dcrn, target_ulong val) 172 { 173 if (unlikely(env->dcr_env == NULL)) { 174 qemu_log_mask(LOG_GUEST_ERROR, "No DCR environment\n"); 175 raise_exception_err_ra(env, POWERPC_EXCP_PROGRAM, 176 POWERPC_EXCP_INVAL | 177 POWERPC_EXCP_INVAL_INVAL, GETPC()); 178 } else if (unlikely(ppc_dcr_write(env->dcr_env, (uint32_t)dcrn, 179 (uint32_t)val) != 0)) { 180 qemu_log_mask(LOG_GUEST_ERROR, "DCR write error %d %03x\n", 181 (uint32_t)dcrn, (uint32_t)dcrn); 182 raise_exception_err_ra(env, POWERPC_EXCP_PROGRAM, 183 POWERPC_EXCP_INVAL | 184 POWERPC_EXCP_PRIV_REG, GETPC()); 185 } 186 } 187