xref: /qemu/target/ppc/timebase_helper.c (revision b25f2ffa19c0f4a79de0315d4eade36ce76b031c)
16de673d4SBlue Swirl /*
26de673d4SBlue Swirl  *  PowerPC emulation helpers for QEMU.
36de673d4SBlue Swirl  *
46de673d4SBlue Swirl  *  Copyright (c) 2003-2007 Jocelyn Mayer
56de673d4SBlue Swirl  *
66de673d4SBlue Swirl  * This library is free software; you can redistribute it and/or
76de673d4SBlue Swirl  * modify it under the terms of the GNU Lesser General Public
86de673d4SBlue Swirl  * License as published by the Free Software Foundation; either
96bd039cdSChetan Pant  * version 2.1 of the License, or (at your option) any later version.
106de673d4SBlue Swirl  *
116de673d4SBlue Swirl  * This library is distributed in the hope that it will be useful,
126de673d4SBlue Swirl  * but WITHOUT ANY WARRANTY; without even the implied warranty of
136de673d4SBlue Swirl  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
146de673d4SBlue Swirl  * Lesser General Public License for more details.
156de673d4SBlue Swirl  *
166de673d4SBlue Swirl  * You should have received a copy of the GNU Lesser General Public
176de673d4SBlue Swirl  * License along with this library; if not, see <http://www.gnu.org/licenses/>.
186de673d4SBlue Swirl  */
190d75590dSPeter Maydell #include "qemu/osdep.h"
206de673d4SBlue Swirl #include "cpu.h"
212ef6175aSRichard Henderson #include "exec/helper-proto.h"
22a13f0a9bSBenjamin Herrenschmidt #include "exec/exec-all.h"
2363c91552SPaolo Bonzini #include "qemu/log.h"
24235352eeSPeter Maydell #include "qemu/main-loop.h"
256de673d4SBlue Swirl 
266de673d4SBlue Swirl /*****************************************************************************/
276de673d4SBlue Swirl /* SPR accesses */
286de673d4SBlue Swirl 
29d0f1562dSBlue Swirl target_ulong helper_load_tbl(CPUPPCState *env)
306de673d4SBlue Swirl {
316de673d4SBlue Swirl     return (target_ulong)cpu_ppc_load_tbl(env);
326de673d4SBlue Swirl }
336de673d4SBlue Swirl 
34d0f1562dSBlue Swirl target_ulong helper_load_tbu(CPUPPCState *env)
356de673d4SBlue Swirl {
366de673d4SBlue Swirl     return cpu_ppc_load_tbu(env);
376de673d4SBlue Swirl }
386de673d4SBlue Swirl 
39d0f1562dSBlue Swirl target_ulong helper_load_atbl(CPUPPCState *env)
406de673d4SBlue Swirl {
416de673d4SBlue Swirl     return (target_ulong)cpu_ppc_load_atbl(env);
426de673d4SBlue Swirl }
436de673d4SBlue Swirl 
44d0f1562dSBlue Swirl target_ulong helper_load_atbu(CPUPPCState *env)
456de673d4SBlue Swirl {
466de673d4SBlue Swirl     return cpu_ppc_load_atbu(env);
476de673d4SBlue Swirl }
486de673d4SBlue Swirl 
495d62725bSSuraj Jitindar Singh target_ulong helper_load_vtb(CPUPPCState *env)
505d62725bSSuraj Jitindar Singh {
515d62725bSSuraj Jitindar Singh     return cpu_ppc_load_vtb(env);
525d62725bSSuraj Jitindar Singh }
535d62725bSSuraj Jitindar Singh 
546de673d4SBlue Swirl #if defined(TARGET_PPC64) && !defined(CONFIG_USER_ONLY)
55d0f1562dSBlue Swirl target_ulong helper_load_purr(CPUPPCState *env)
566de673d4SBlue Swirl {
576de673d4SBlue Swirl     return (target_ulong)cpu_ppc_load_purr(env);
586de673d4SBlue Swirl }
595cc7e69fSSuraj Jitindar Singh 
605cc7e69fSSuraj Jitindar Singh void helper_store_purr(CPUPPCState *env, target_ulong val)
615cc7e69fSSuraj Jitindar Singh {
625cc7e69fSSuraj Jitindar Singh     cpu_ppc_store_purr(env, val);
635cc7e69fSSuraj Jitindar Singh }
646de673d4SBlue Swirl #endif
656de673d4SBlue Swirl 
666de673d4SBlue Swirl #if !defined(CONFIG_USER_ONLY)
67d0f1562dSBlue Swirl void helper_store_tbl(CPUPPCState *env, target_ulong val)
686de673d4SBlue Swirl {
696de673d4SBlue Swirl     cpu_ppc_store_tbl(env, val);
706de673d4SBlue Swirl }
716de673d4SBlue Swirl 
72d0f1562dSBlue Swirl void helper_store_tbu(CPUPPCState *env, target_ulong val)
736de673d4SBlue Swirl {
746de673d4SBlue Swirl     cpu_ppc_store_tbu(env, val);
756de673d4SBlue Swirl }
766de673d4SBlue Swirl 
77d0f1562dSBlue Swirl void helper_store_atbl(CPUPPCState *env, target_ulong val)
786de673d4SBlue Swirl {
796de673d4SBlue Swirl     cpu_ppc_store_atbl(env, val);
806de673d4SBlue Swirl }
816de673d4SBlue Swirl 
82d0f1562dSBlue Swirl void helper_store_atbu(CPUPPCState *env, target_ulong val)
836de673d4SBlue Swirl {
846de673d4SBlue Swirl     cpu_ppc_store_atbu(env, val);
856de673d4SBlue Swirl }
866de673d4SBlue Swirl 
87d0f1562dSBlue Swirl target_ulong helper_load_decr(CPUPPCState *env)
886de673d4SBlue Swirl {
896de673d4SBlue Swirl     return cpu_ppc_load_decr(env);
906de673d4SBlue Swirl }
916de673d4SBlue Swirl 
92d0f1562dSBlue Swirl void helper_store_decr(CPUPPCState *env, target_ulong val)
936de673d4SBlue Swirl {
946de673d4SBlue Swirl     cpu_ppc_store_decr(env, val);
956de673d4SBlue Swirl }
966de673d4SBlue Swirl 
974b236b62SBenjamin Herrenschmidt target_ulong helper_load_hdecr(CPUPPCState *env)
984b236b62SBenjamin Herrenschmidt {
994b236b62SBenjamin Herrenschmidt     return cpu_ppc_load_hdecr(env);
1004b236b62SBenjamin Herrenschmidt }
1014b236b62SBenjamin Herrenschmidt 
1024b236b62SBenjamin Herrenschmidt void helper_store_hdecr(CPUPPCState *env, target_ulong val)
1034b236b62SBenjamin Herrenschmidt {
1044b236b62SBenjamin Herrenschmidt     cpu_ppc_store_hdecr(env, val);
1054b236b62SBenjamin Herrenschmidt }
1064b236b62SBenjamin Herrenschmidt 
1075d62725bSSuraj Jitindar Singh void helper_store_vtb(CPUPPCState *env, target_ulong val)
1085d62725bSSuraj Jitindar Singh {
1095d62725bSSuraj Jitindar Singh     cpu_ppc_store_vtb(env, val);
1105d62725bSSuraj Jitindar Singh }
1115d62725bSSuraj Jitindar Singh 
112f0ec31b1SSuraj Jitindar Singh void helper_store_tbu40(CPUPPCState *env, target_ulong val)
113f0ec31b1SSuraj Jitindar Singh {
114f0ec31b1SSuraj Jitindar Singh     cpu_ppc_store_tbu40(env, val);
115f0ec31b1SSuraj Jitindar Singh }
116f0ec31b1SSuraj Jitindar Singh 
117d0f1562dSBlue Swirl target_ulong helper_load_40x_pit(CPUPPCState *env)
1186de673d4SBlue Swirl {
1196de673d4SBlue Swirl     return load_40x_pit(env);
1206de673d4SBlue Swirl }
1216de673d4SBlue Swirl 
122d0f1562dSBlue Swirl void helper_store_40x_pit(CPUPPCState *env, target_ulong val)
1236de673d4SBlue Swirl {
1246de673d4SBlue Swirl     store_40x_pit(env, val);
1256de673d4SBlue Swirl }
1266de673d4SBlue Swirl 
127cbd8f17dSCédric Le Goater void helper_store_40x_tcr(CPUPPCState *env, target_ulong val)
128cbd8f17dSCédric Le Goater {
129cbd8f17dSCédric Le Goater     store_40x_tcr(env, val);
130cbd8f17dSCédric Le Goater }
131cbd8f17dSCédric Le Goater 
132cbd8f17dSCédric Le Goater void helper_store_40x_tsr(CPUPPCState *env, target_ulong val)
133cbd8f17dSCédric Le Goater {
134cbd8f17dSCédric Le Goater     store_40x_tsr(env, val);
135cbd8f17dSCédric Le Goater }
136cbd8f17dSCédric Le Goater 
137d0f1562dSBlue Swirl void helper_store_booke_tcr(CPUPPCState *env, target_ulong val)
1386de673d4SBlue Swirl {
1396de673d4SBlue Swirl     store_booke_tcr(env, val);
1406de673d4SBlue Swirl }
1416de673d4SBlue Swirl 
142d0f1562dSBlue Swirl void helper_store_booke_tsr(CPUPPCState *env, target_ulong val)
1436de673d4SBlue Swirl {
1446de673d4SBlue Swirl     store_booke_tsr(env, val);
1456de673d4SBlue Swirl }
1466de673d4SBlue Swirl 
147*b25f2ffaSNicholas Piggin #if defined(TARGET_PPC64)
148*b25f2ffaSNicholas Piggin /* POWER processor Timebase Facility */
149*b25f2ffaSNicholas Piggin target_ulong helper_load_tfmr(CPUPPCState *env)
150*b25f2ffaSNicholas Piggin {
151*b25f2ffaSNicholas Piggin     return env->spr[SPR_TFMR];
152*b25f2ffaSNicholas Piggin }
153*b25f2ffaSNicholas Piggin 
154*b25f2ffaSNicholas Piggin void helper_store_tfmr(CPUPPCState *env, target_ulong val)
155*b25f2ffaSNicholas Piggin {
156*b25f2ffaSNicholas Piggin     env->spr[SPR_TFMR] = val;
157*b25f2ffaSNicholas Piggin }
158*b25f2ffaSNicholas Piggin #endif
159*b25f2ffaSNicholas Piggin 
1606de673d4SBlue Swirl /*****************************************************************************/
1616de673d4SBlue Swirl /* Embedded PowerPC specific helpers */
1626de673d4SBlue Swirl 
1636de673d4SBlue Swirl /* XXX: to be improved to check access rights when in user-mode */
164d0f1562dSBlue Swirl target_ulong helper_load_dcr(CPUPPCState *env, target_ulong dcrn)
1656de673d4SBlue Swirl {
1666de673d4SBlue Swirl     uint32_t val = 0;
1676de673d4SBlue Swirl 
1686de673d4SBlue Swirl     if (unlikely(env->dcr_env == NULL)) {
16948880da6SPaolo Bonzini         qemu_log_mask(LOG_GUEST_ERROR, "No DCR environment\n");
170a13f0a9bSBenjamin Herrenschmidt         raise_exception_err_ra(env, POWERPC_EXCP_PROGRAM,
1716de673d4SBlue Swirl                                POWERPC_EXCP_INVAL |
172a13f0a9bSBenjamin Herrenschmidt                                POWERPC_EXCP_INVAL_INVAL, GETPC());
173235352eeSPeter Maydell     } else {
174235352eeSPeter Maydell         int ret;
175235352eeSPeter Maydell 
176235352eeSPeter Maydell         qemu_mutex_lock_iothread();
177235352eeSPeter Maydell         ret = ppc_dcr_read(env->dcr_env, (uint32_t)dcrn, &val);
178235352eeSPeter Maydell         qemu_mutex_unlock_iothread();
179235352eeSPeter Maydell         if (unlikely(ret != 0)) {
18048880da6SPaolo Bonzini             qemu_log_mask(LOG_GUEST_ERROR, "DCR read error %d %03x\n",
18148880da6SPaolo Bonzini                           (uint32_t)dcrn, (uint32_t)dcrn);
182a13f0a9bSBenjamin Herrenschmidt             raise_exception_err_ra(env, POWERPC_EXCP_PROGRAM,
183a13f0a9bSBenjamin Herrenschmidt                                    POWERPC_EXCP_INVAL |
184e8985179SMatheus Ferst                                    POWERPC_EXCP_INVAL_INVAL, GETPC());
1856de673d4SBlue Swirl         }
186235352eeSPeter Maydell     }
1876de673d4SBlue Swirl     return val;
1886de673d4SBlue Swirl }
1896de673d4SBlue Swirl 
190d0f1562dSBlue Swirl void helper_store_dcr(CPUPPCState *env, target_ulong dcrn, target_ulong val)
1916de673d4SBlue Swirl {
1926de673d4SBlue Swirl     if (unlikely(env->dcr_env == NULL)) {
19348880da6SPaolo Bonzini         qemu_log_mask(LOG_GUEST_ERROR, "No DCR environment\n");
194a13f0a9bSBenjamin Herrenschmidt         raise_exception_err_ra(env, POWERPC_EXCP_PROGRAM,
1956de673d4SBlue Swirl                                POWERPC_EXCP_INVAL |
196a13f0a9bSBenjamin Herrenschmidt                                POWERPC_EXCP_INVAL_INVAL, GETPC());
197235352eeSPeter Maydell     } else {
198235352eeSPeter Maydell         int ret;
199235352eeSPeter Maydell         qemu_mutex_lock_iothread();
200235352eeSPeter Maydell         ret = ppc_dcr_write(env->dcr_env, (uint32_t)dcrn, (uint32_t)val);
201235352eeSPeter Maydell         qemu_mutex_unlock_iothread();
202235352eeSPeter Maydell         if (unlikely(ret != 0)) {
20348880da6SPaolo Bonzini             qemu_log_mask(LOG_GUEST_ERROR, "DCR write error %d %03x\n",
20448880da6SPaolo Bonzini                           (uint32_t)dcrn, (uint32_t)dcrn);
205a13f0a9bSBenjamin Herrenschmidt             raise_exception_err_ra(env, POWERPC_EXCP_PROGRAM,
206a13f0a9bSBenjamin Herrenschmidt                                    POWERPC_EXCP_INVAL |
207e8985179SMatheus Ferst                                    POWERPC_EXCP_INVAL_INVAL, GETPC());
2086de673d4SBlue Swirl         }
2096de673d4SBlue Swirl     }
210235352eeSPeter Maydell }
211e8985179SMatheus Ferst #endif
212