usb: tag standalone uhci as hotpluggable
[qemu.git] / target-tricore / helper.c
blobe4af6f1ac22e02c73bb1cef6d20a6de2a6fb7089
1 /*
2 * Copyright (c) 2012-2014 Bastian Koppelmann C-Lab/University Paderborn
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, see <http://www.gnu.org/licenses/>.
18 #include <stdarg.h>
19 #include <stdlib.h>
20 #include <stdio.h>
21 #include <string.h>
22 #include <inttypes.h>
23 #include <signal.h>
25 #include "cpu.h"
27 enum {
28 TLBRET_DIRTY = -4,
29 TLBRET_INVALID = -3,
30 TLBRET_NOMATCH = -2,
31 TLBRET_BADADDR = -1,
32 TLBRET_MATCH = 0
35 #if defined(CONFIG_SOFTMMU)
36 static int get_physical_address(CPUTriCoreState *env, hwaddr *physical,
37 int *prot, target_ulong address,
38 int rw, int access_type)
40 int ret = TLBRET_MATCH;
42 *physical = address & 0xFFFFFFFF;
43 *prot = PAGE_READ | PAGE_WRITE | PAGE_EXEC;
45 return ret;
47 #endif
49 /* TODO: Add exeption support*/
50 static void raise_mmu_exception(CPUTriCoreState *env, target_ulong address,
51 int rw, int tlb_error)
55 int cpu_tricore_handle_mmu_fault(CPUState *cs, target_ulong address,
56 int rw, int mmu_idx)
58 TriCoreCPU *cpu = TRICORE_CPU(cs);
59 CPUTriCoreState *env = &cpu->env;
60 hwaddr physical;
61 int prot;
62 int access_type;
63 int ret = 0;
65 rw &= 1;
66 access_type = ACCESS_INT;
67 ret = get_physical_address(env, &physical, &prot,
68 address, rw, access_type);
69 qemu_log("%s address=" TARGET_FMT_lx " ret %d physical " TARGET_FMT_plx
70 " prot %d\n", __func__, address, ret, physical, prot);
72 if (ret == TLBRET_MATCH) {
73 tlb_set_page(cs, address & TARGET_PAGE_MASK,
74 physical & TARGET_PAGE_MASK, prot | PAGE_EXEC,
75 mmu_idx, TARGET_PAGE_SIZE);
76 ret = 0;
77 } else if (ret < 0) {
78 raise_mmu_exception(env, address, rw, ret);
79 ret = 1;
82 return ret;
85 void tricore_cpu_do_interrupt(CPUState *cs)
89 TriCoreCPU *cpu_tricore_init(const char *cpu_model)
91 return TRICORE_CPU(cpu_generic_init(TYPE_TRICORE_CPU, cpu_model));
94 static void tricore_cpu_list_entry(gpointer data, gpointer user_data)
96 ObjectClass *oc = data;
97 CPUListState *s = user_data;
98 const char *typename;
99 char *name;
101 typename = object_class_get_name(oc);
102 name = g_strndup(typename, strlen(typename) - strlen("-" TYPE_TRICORE_CPU));
103 (*s->cpu_fprintf)(s->file, " %s\n",
104 name);
105 g_free(name);
108 void tricore_cpu_list(FILE *f, fprintf_function cpu_fprintf)
110 CPUListState s = {
111 .file = f,
112 .cpu_fprintf = cpu_fprintf,
114 GSList *list;
116 list = object_class_get_list(TYPE_TRICORE_CPU, false);
117 (*cpu_fprintf)(f, "Available CPUs:\n");
118 g_slist_foreach(list, tricore_cpu_list_entry, &s);
119 g_slist_free(list);
122 uint32_t psw_read(CPUTriCoreState *env)
124 /* clear all USB bits */
125 env->PSW &= 0xffffff;
126 /* now set them from the cache */
127 env->PSW |= ((env->PSW_USB_C != 0) << 31);
128 env->PSW |= ((env->PSW_USB_V & (1 << 31)) >> 1);
129 env->PSW |= ((env->PSW_USB_SV & (1 << 31)) >> 2);
130 env->PSW |= ((env->PSW_USB_AV & (1 << 31)) >> 3);
131 env->PSW |= ((env->PSW_USB_SAV & (1 << 31)) >> 4);
133 return env->PSW;
136 void psw_write(CPUTriCoreState *env, uint32_t val)
138 env->PSW_USB_C = (val & MASK_USB_C);
139 env->PSW_USB_V = (val & MASK_USB_V << 1);
140 env->PSW_USB_SV = (val & MASK_USB_SV << 2);
141 env->PSW_USB_AV = ((val & MASK_USB_AV) << 3);
142 env->PSW_USB_SAV = ((val & MASK_USB_SAV) << 4);
143 env->PSW = val;