2 * arm cpu init and loop
4 * Copyright (c) 2013 Stacey D. Son
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * This program 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
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, see <http://www.gnu.org/licenses/>.
20 #ifndef TARGET_ARCH_CPU_H
21 #define TARGET_ARCH_CPU_H
23 #include "target_arch.h"
24 #include "signal-common.h"
26 #define TARGET_DEFAULT_CPU_MODEL "any"
28 static inline void target_cpu_init(CPUARMState
*env
,
29 struct target_pt_regs
*regs
)
33 cpsr_write(env
, regs
->uregs
[16], CPSR_USER
| CPSR_EXEC
,
35 for (i
= 0; i
< 16; i
++) {
36 env
->regs
[i
] = regs
->uregs
[i
];
40 static inline void target_cpu_loop(CPUARMState
*env
)
42 int trapnr
, si_signo
, si_code
;
43 CPUState
*cs
= env_cpu(env
);
47 trapnr
= cpu_exec(cs
);
49 process_queued_cpu_work(cs
);
55 * See arm/arm/undefined.c undefinedinstruction();
57 * A number of details aren't emulated (they likely don't matter):
58 * o Misaligned PC generates ILL_ILLADR (these can't come from qemu)
59 * o Thumb-2 instructions generate ILLADR
60 * o Both modes implement coprocessor instructions, which we don't
61 * do here. FreeBSD just implements them for the VFP coprocessor
62 * and special kernel breakpoints, trace points, dtrace, etc.
64 force_sig_fault(TARGET_SIGILL
, TARGET_ILL_ILLOPC
, env
->regs
[15]);
69 abi_ulong params
= get_sp_from_cpustate(env
);
70 int32_t syscall_nr
= env
->regs
[7];
71 int32_t arg1
, arg2
, arg3
, arg4
, arg5
, arg6
, arg7
, arg8
;
73 /* See arm/arm/syscall.c cpu_fetch_syscall_args() */
74 if (syscall_nr
== TARGET_FREEBSD_NR_syscall
) {
75 syscall_nr
= env
->regs
[0];
79 get_user_s32(arg4
, params
);
80 params
+= sizeof(int32_t);
81 get_user_s32(arg5
, params
);
82 params
+= sizeof(int32_t);
83 get_user_s32(arg6
, params
);
84 params
+= sizeof(int32_t);
85 get_user_s32(arg7
, params
);
87 } else if (syscall_nr
== TARGET_FREEBSD_NR___syscall
) {
88 syscall_nr
= env
->regs
[0];
91 get_user_s32(arg3
, params
);
92 params
+= sizeof(int32_t);
93 get_user_s32(arg4
, params
);
94 params
+= sizeof(int32_t);
95 get_user_s32(arg5
, params
);
96 params
+= sizeof(int32_t);
97 get_user_s32(arg6
, params
);
105 get_user_s32(arg5
, params
);
106 params
+= sizeof(int32_t);
107 get_user_s32(arg6
, params
);
108 params
+= sizeof(int32_t);
109 get_user_s32(arg7
, params
);
110 params
+= sizeof(int32_t);
111 get_user_s32(arg8
, params
);
113 ret
= do_freebsd_syscall(env
, syscall_nr
, arg1
, arg2
, arg3
,
114 arg4
, arg5
, arg6
, arg7
, arg8
);
116 * Compare to arm/arm/vm_machdep.c
117 * cpu_set_syscall_retval()
119 if (-TARGET_EJUSTRETURN
== ret
) {
121 * Returning from a successful sigreturn syscall.
122 * Avoid clobbering register state.
126 if (-TARGET_ERESTART
== ret
) {
127 env
->regs
[15] -= env
->thumb
? 2 : 4;
130 if ((unsigned int)ret
>= (unsigned int)(-515)) {
132 cpsr_write(env
, CPSR_C
, CPSR_C
, CPSRWriteByInstr
);
135 cpsr_write(env
, 0, CPSR_C
, CPSRWriteByInstr
);
136 env
->regs
[0] = ret
; /* XXX need to handle lseek()? */
137 /* env->regs[1] = 0; */
142 /* just indicate that signals should be handled asap */
144 case EXCP_PREFETCH_ABORT
:
145 case EXCP_DATA_ABORT
:
147 * See arm/arm/trap-v6.c prefetch_abort_handler() and
148 * data_abort_handler()
150 * However, FreeBSD maps these to a generic value and then uses that
151 * to maybe fault in pages in vm/vm_fault.c:vm_fault_trap(). I
152 * believe that the indirection maps the same as Linux, but haven't
153 * chased down every single possible indirection.
156 /* For user-only we don't set TTBCR_EAE, so look at the FSR. */
157 switch (env
->exception
.fsr
& 0x1f) {
158 case 0x1: /* Alignment */
159 si_signo
= TARGET_SIGBUS
;
160 si_code
= TARGET_BUS_ADRALN
;
162 case 0x3: /* Access flag fault, level 1 */
163 case 0x6: /* Access flag fault, level 2 */
164 case 0x9: /* Domain fault, level 1 */
165 case 0xb: /* Domain fault, level 2 */
166 case 0xd: /* Permission fault, level 1 */
167 case 0xf: /* Permission fault, level 2 */
168 si_signo
= TARGET_SIGSEGV
;
169 si_code
= TARGET_SEGV_ACCERR
;
171 case 0x5: /* Translation fault, level 1 */
172 case 0x7: /* Translation fault, level 2 */
173 si_signo
= TARGET_SIGSEGV
;
174 si_code
= TARGET_SEGV_MAPERR
;
177 g_assert_not_reached();
179 force_sig_fault(si_signo
, si_code
, env
->exception
.vaddress
);
183 force_sig_fault(TARGET_SIGTRAP
, TARGET_TRAP_BRKPT
, env
->regs
[15]);
186 /* nothing to do here for user-mode, just resume guest code */
189 cpu_exec_step_atomic(cs
);
192 fprintf(stderr
, "qemu: unhandled CPU exception 0x%x - aborting\n",
194 cpu_dump_state(cs
, stderr
, 0);
197 process_pending_signals(env
);
201 static inline void target_cpu_clone_regs(CPUARMState
*env
, target_ulong newsp
)
204 env
->regs
[13] = newsp
;
209 static inline void target_cpu_reset(CPUArchState
*env
)
213 #endif /* TARGET_ARCH_CPU_H */