]> git.proxmox.com Git - qemu.git/blob - target-xtensa/helper.c
44ebb9f29dc9f268365fb7bb800b6705ce7652ba
[qemu.git] / target-xtensa / helper.c
1 /*
2 * Copyright (c) 2011, Max Filippov, Open Source and Linux Lab.
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are met:
7 * * Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * * Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
12 * * Neither the name of the Open Source and Linux Lab nor the
13 * names of its contributors may be used to endorse or promote products
14 * derived from this software without specific prior written permission.
15 *
16 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
17 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
20 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
23 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
25 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 */
27
28 #include "cpu.h"
29 #include "exec-all.h"
30 #include "gdbstub.h"
31 #include "qemu-common.h"
32 #include "host-utils.h"
33 #if !defined(CONFIG_USER_ONLY)
34 #include "hw/loader.h"
35 #endif
36
37 void cpu_reset(CPUXtensaState *env)
38 {
39 env->exception_taken = 0;
40 env->pc = env->config->exception_vector[EXC_RESET];
41 env->sregs[PS] = 0x1f;
42 }
43
44 static const XtensaConfig core_config[] = {
45 {
46 .name = "sample-xtensa-core",
47 .options = -1,
48 .ndepc = 1,
49 .excm_level = 16,
50 .exception_vector = {
51 [EXC_RESET] = 0x5fff8000,
52 [EXC_WINDOW_OVERFLOW4] = 0x5fff8400,
53 [EXC_WINDOW_UNDERFLOW4] = 0x5fff8440,
54 [EXC_WINDOW_OVERFLOW8] = 0x5fff8480,
55 [EXC_WINDOW_UNDERFLOW8] = 0x5fff84c0,
56 [EXC_WINDOW_OVERFLOW12] = 0x5fff8500,
57 [EXC_WINDOW_UNDERFLOW12] = 0x5fff8540,
58 [EXC_KERNEL] = 0x5fff861c,
59 [EXC_USER] = 0x5fff863c,
60 [EXC_DOUBLE] = 0x5fff865c,
61 },
62 },
63 };
64
65 CPUXtensaState *cpu_xtensa_init(const char *cpu_model)
66 {
67 static int tcg_inited;
68 CPUXtensaState *env;
69 const XtensaConfig *config = NULL;
70 int i;
71
72 for (i = 0; i < ARRAY_SIZE(core_config); ++i)
73 if (strcmp(core_config[i].name, cpu_model) == 0) {
74 config = core_config + i;
75 break;
76 }
77
78 if (config == NULL) {
79 return NULL;
80 }
81
82 env = g_malloc0(sizeof(*env));
83 env->config = config;
84 cpu_exec_init(env);
85
86 if (!tcg_inited) {
87 tcg_inited = 1;
88 xtensa_translate_init();
89 }
90
91 qemu_init_vcpu(env);
92 return env;
93 }
94
95
96 void xtensa_cpu_list(FILE *f, fprintf_function cpu_fprintf)
97 {
98 int i;
99 cpu_fprintf(f, "Available CPUs:\n");
100 for (i = 0; i < ARRAY_SIZE(core_config); ++i) {
101 cpu_fprintf(f, " %s\n", core_config[i].name);
102 }
103 }
104
105 target_phys_addr_t cpu_get_phys_page_debug(CPUState *env, target_ulong addr)
106 {
107 return addr;
108 }
109
110 void do_interrupt(CPUState *env)
111 {
112 switch (env->exception_index) {
113 case EXC_WINDOW_OVERFLOW4:
114 case EXC_WINDOW_UNDERFLOW4:
115 case EXC_WINDOW_OVERFLOW8:
116 case EXC_WINDOW_UNDERFLOW8:
117 case EXC_WINDOW_OVERFLOW12:
118 case EXC_WINDOW_UNDERFLOW12:
119 case EXC_KERNEL:
120 case EXC_USER:
121 case EXC_DOUBLE:
122 if (env->config->exception_vector[env->exception_index]) {
123 env->pc = env->config->exception_vector[env->exception_index];
124 env->exception_taken = 1;
125 } else {
126 qemu_log("%s(pc = %08x) bad exception_index: %d\n",
127 __func__, env->pc, env->exception_index);
128 }
129 break;
130
131 }
132 }