148e06fe0SBastian Koppelmann /* 248e06fe0SBastian Koppelmann * Copyright (c) 2012-2014 Bastian Koppelmann C-Lab/University Paderborn 348e06fe0SBastian Koppelmann * 448e06fe0SBastian Koppelmann * This library is free software; you can redistribute it and/or 548e06fe0SBastian Koppelmann * modify it under the terms of the GNU Lesser General Public 648e06fe0SBastian Koppelmann * License as published by the Free Software Foundation; either 702754acdSThomas Huth * version 2.1 of the License, or (at your option) any later version. 848e06fe0SBastian Koppelmann * 948e06fe0SBastian Koppelmann * This library is distributed in the hope that it will be useful, 1048e06fe0SBastian Koppelmann * but WITHOUT ANY WARRANTY; without even the implied warranty of 1148e06fe0SBastian Koppelmann * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 1248e06fe0SBastian Koppelmann * Lesser General Public License for more details. 1348e06fe0SBastian Koppelmann * 1448e06fe0SBastian Koppelmann * You should have received a copy of the GNU Lesser General Public 1548e06fe0SBastian Koppelmann * License along with this library; if not, see <http://www.gnu.org/licenses/>. 1648e06fe0SBastian Koppelmann */ 1748e06fe0SBastian Koppelmann 1861d9f32bSPeter Maydell #include "qemu/osdep.h" 1948e06fe0SBastian Koppelmann 2048e06fe0SBastian Koppelmann #include "cpu.h" 2163c91552SPaolo Bonzini #include "exec/exec-all.h" 2224f91e81SAlex Bennée #include "fpu/softfloat.h" 230442428aSMarkus Armbruster #include "qemu/qemu-print.h" 2448e06fe0SBastian Koppelmann 252d30267eSBastian Koppelmann enum { 262d30267eSBastian Koppelmann TLBRET_DIRTY = -4, 272d30267eSBastian Koppelmann TLBRET_INVALID = -3, 282d30267eSBastian Koppelmann TLBRET_NOMATCH = -2, 292d30267eSBastian Koppelmann TLBRET_BADADDR = -1, 302d30267eSBastian Koppelmann TLBRET_MATCH = 0 312d30267eSBastian Koppelmann }; 322d30267eSBastian Koppelmann 332d30267eSBastian Koppelmann #if defined(CONFIG_SOFTMMU) 342d30267eSBastian Koppelmann static int get_physical_address(CPUTriCoreState *env, hwaddr *physical, 352d30267eSBastian Koppelmann int *prot, target_ulong address, 362d30267eSBastian Koppelmann int rw, int access_type) 372d30267eSBastian Koppelmann { 382d30267eSBastian Koppelmann int ret = TLBRET_MATCH; 392d30267eSBastian Koppelmann 402d30267eSBastian Koppelmann *physical = address & 0xFFFFFFFF; 412d30267eSBastian Koppelmann *prot = PAGE_READ | PAGE_WRITE | PAGE_EXEC; 422d30267eSBastian Koppelmann 432d30267eSBastian Koppelmann return ret; 442d30267eSBastian Koppelmann } 452d30267eSBastian Koppelmann #endif 462d30267eSBastian Koppelmann 472d30267eSBastian Koppelmann /* TODO: Add exeption support*/ 482d30267eSBastian Koppelmann static void raise_mmu_exception(CPUTriCoreState *env, target_ulong address, 492d30267eSBastian Koppelmann int rw, int tlb_error) 502d30267eSBastian Koppelmann { 512d30267eSBastian Koppelmann } 522d30267eSBastian Koppelmann 53*68d6eee7SRichard Henderson bool tricore_cpu_tlb_fill(CPUState *cs, vaddr address, int size, 54*68d6eee7SRichard Henderson MMUAccessType rw, int mmu_idx, 55*68d6eee7SRichard Henderson bool probe, uintptr_t retaddr) 5648e06fe0SBastian Koppelmann { 572d30267eSBastian Koppelmann TriCoreCPU *cpu = TRICORE_CPU(cs); 582d30267eSBastian Koppelmann CPUTriCoreState *env = &cpu->env; 592d30267eSBastian Koppelmann hwaddr physical; 602d30267eSBastian Koppelmann int prot; 612d30267eSBastian Koppelmann int access_type; 622d30267eSBastian Koppelmann int ret = 0; 632d30267eSBastian Koppelmann 642d30267eSBastian Koppelmann rw &= 1; 652d30267eSBastian Koppelmann access_type = ACCESS_INT; 662d30267eSBastian Koppelmann ret = get_physical_address(env, &physical, &prot, 672d30267eSBastian Koppelmann address, rw, access_type); 68*68d6eee7SRichard Henderson 69*68d6eee7SRichard Henderson qemu_log_mask(CPU_LOG_MMU, "%s address=" TARGET_FMT_lx " ret %d physical " 70*68d6eee7SRichard Henderson TARGET_FMT_plx " prot %d\n", 71*68d6eee7SRichard Henderson __func__, (target_ulong)address, ret, physical, prot); 722d30267eSBastian Koppelmann 732d30267eSBastian Koppelmann if (ret == TLBRET_MATCH) { 742d30267eSBastian Koppelmann tlb_set_page(cs, address & TARGET_PAGE_MASK, 752d30267eSBastian Koppelmann physical & TARGET_PAGE_MASK, prot | PAGE_EXEC, 762d30267eSBastian Koppelmann mmu_idx, TARGET_PAGE_SIZE); 77*68d6eee7SRichard Henderson return true; 78*68d6eee7SRichard Henderson } else { 79*68d6eee7SRichard Henderson assert(ret < 0); 80*68d6eee7SRichard Henderson if (probe) { 81*68d6eee7SRichard Henderson return false; 82*68d6eee7SRichard Henderson } 832d30267eSBastian Koppelmann raise_mmu_exception(env, address, rw, ret); 84*68d6eee7SRichard Henderson cpu_loop_exit_restore(cs, retaddr); 85*68d6eee7SRichard Henderson } 862d30267eSBastian Koppelmann } 872d30267eSBastian Koppelmann 88*68d6eee7SRichard Henderson void tlb_fill(CPUState *cs, target_ulong addr, int size, 89*68d6eee7SRichard Henderson MMUAccessType access_type, int mmu_idx, uintptr_t retaddr) 90*68d6eee7SRichard Henderson { 91*68d6eee7SRichard Henderson tricore_cpu_tlb_fill(cs, addr, size, access_type, mmu_idx, false, retaddr); 9248e06fe0SBastian Koppelmann } 9348e06fe0SBastian Koppelmann 9448e06fe0SBastian Koppelmann static void tricore_cpu_list_entry(gpointer data, gpointer user_data) 9548e06fe0SBastian Koppelmann { 9648e06fe0SBastian Koppelmann ObjectClass *oc = data; 9748e06fe0SBastian Koppelmann const char *typename; 9848e06fe0SBastian Koppelmann char *name; 9948e06fe0SBastian Koppelmann 10048e06fe0SBastian Koppelmann typename = object_class_get_name(oc); 10148e06fe0SBastian Koppelmann name = g_strndup(typename, strlen(typename) - strlen("-" TYPE_TRICORE_CPU)); 1020442428aSMarkus Armbruster qemu_printf(" %s\n", name); 10348e06fe0SBastian Koppelmann g_free(name); 10448e06fe0SBastian Koppelmann } 10548e06fe0SBastian Koppelmann 1060442428aSMarkus Armbruster void tricore_cpu_list(void) 10748e06fe0SBastian Koppelmann { 10848e06fe0SBastian Koppelmann GSList *list; 10948e06fe0SBastian Koppelmann 11047c66009SPaolo Bonzini list = object_class_get_list_sorted(TYPE_TRICORE_CPU, false); 1110442428aSMarkus Armbruster qemu_printf("Available CPUs:\n"); 1120442428aSMarkus Armbruster g_slist_foreach(list, tricore_cpu_list_entry, NULL); 11348e06fe0SBastian Koppelmann g_slist_free(list); 11448e06fe0SBastian Koppelmann } 11548e06fe0SBastian Koppelmann 116996a729fSBastian Koppelmann void fpu_set_state(CPUTriCoreState *env) 117996a729fSBastian Koppelmann { 118996a729fSBastian Koppelmann set_float_rounding_mode(env->PSW & MASK_PSW_FPU_RM, &env->fp_status); 119996a729fSBastian Koppelmann set_flush_inputs_to_zero(1, &env->fp_status); 120996a729fSBastian Koppelmann set_flush_to_zero(1, &env->fp_status); 121996a729fSBastian Koppelmann set_default_nan_mode(1, &env->fp_status); 122996a729fSBastian Koppelmann } 123996a729fSBastian Koppelmann 12448e06fe0SBastian Koppelmann uint32_t psw_read(CPUTriCoreState *env) 12548e06fe0SBastian Koppelmann { 12648e06fe0SBastian Koppelmann /* clear all USB bits */ 1271bd3e2fcSBastian Koppelmann env->PSW &= 0x6ffffff; 12848e06fe0SBastian Koppelmann /* now set them from the cache */ 12948e06fe0SBastian Koppelmann env->PSW |= ((env->PSW_USB_C != 0) << 31); 13048e06fe0SBastian Koppelmann env->PSW |= ((env->PSW_USB_V & (1 << 31)) >> 1); 13148e06fe0SBastian Koppelmann env->PSW |= ((env->PSW_USB_SV & (1 << 31)) >> 2); 13248e06fe0SBastian Koppelmann env->PSW |= ((env->PSW_USB_AV & (1 << 31)) >> 3); 13348e06fe0SBastian Koppelmann env->PSW |= ((env->PSW_USB_SAV & (1 << 31)) >> 4); 13448e06fe0SBastian Koppelmann 13548e06fe0SBastian Koppelmann return env->PSW; 13648e06fe0SBastian Koppelmann } 13748e06fe0SBastian Koppelmann 13848e06fe0SBastian Koppelmann void psw_write(CPUTriCoreState *env, uint32_t val) 13948e06fe0SBastian Koppelmann { 14048e06fe0SBastian Koppelmann env->PSW_USB_C = (val & MASK_USB_C); 1415dc1fbaeSBastian Koppelmann env->PSW_USB_V = (val & MASK_USB_V) << 1; 1425dc1fbaeSBastian Koppelmann env->PSW_USB_SV = (val & MASK_USB_SV) << 2; 1435dc1fbaeSBastian Koppelmann env->PSW_USB_AV = (val & MASK_USB_AV) << 3; 1445dc1fbaeSBastian Koppelmann env->PSW_USB_SAV = (val & MASK_USB_SAV) << 4; 14548e06fe0SBastian Koppelmann env->PSW = val; 146996a729fSBastian Koppelmann 147996a729fSBastian Koppelmann fpu_set_state(env); 14848e06fe0SBastian Koppelmann } 149