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"
25 #define TARGET_DEFAULT_CPU_MODEL "any"
27 static inline void target_cpu_init(CPUARMState
*env
,
28 struct target_pt_regs
*regs
)
32 cpsr_write(env
, regs
->uregs
[16], CPSR_USER
| CPSR_EXEC
,
34 for (i
= 0; i
< 16; i
++) {
35 env
->regs
[i
] = regs
->uregs
[i
];
39 static inline void target_cpu_loop(CPUARMState
*env
)
42 target_siginfo_t info
;
44 CPUState
*cs
= env_cpu(env
);
48 trapnr
= cpu_exec(cs
);
50 process_queued_cpu_work(cs
);
54 /* See arm/arm/undefined.c undefinedinstruction(); */
55 info
.si_addr
= env
->regs
[15];
57 /* illegal instruction */
58 info
.si_signo
= TARGET_SIGILL
;
60 info
.si_code
= TARGET_ILL_ILLOPC
;
61 queue_signal(env
, info
.si_signo
, &info
);
63 /* TODO: What about instruction emulation? */
71 * See arm/arm/trap.c cpu_fetch_syscall_args()
73 if (trapnr
== EXCP_BKPT
) {
81 if (bsd_type
== target_freebsd
) {
83 abi_ulong params
= get_sp_from_cpustate(env
);
84 int32_t syscall_nr
= n
;
85 int32_t arg1
, arg2
, arg3
, arg4
, arg5
, arg6
, arg7
, arg8
;
87 /* See arm/arm/trap.c cpu_fetch_syscall_args() */
88 if (syscall_nr
== TARGET_FREEBSD_NR_syscall
) {
89 syscall_nr
= env
->regs
[0];
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
);
98 params
+= sizeof(int32_t);
99 get_user_s32(arg7
, params
);
101 } else if (syscall_nr
== TARGET_FREEBSD_NR___syscall
) {
102 syscall_nr
= env
->regs
[0];
105 get_user_s32(arg3
, params
);
106 params
+= sizeof(int32_t);
107 get_user_s32(arg4
, params
);
108 params
+= sizeof(int32_t);
109 get_user_s32(arg5
, params
);
110 params
+= sizeof(int32_t);
111 get_user_s32(arg6
, params
);
119 get_user_s32(arg5
, params
);
120 params
+= sizeof(int32_t);
121 get_user_s32(arg6
, params
);
122 params
+= sizeof(int32_t);
123 get_user_s32(arg7
, params
);
124 params
+= sizeof(int32_t);
125 get_user_s32(arg8
, params
);
127 ret
= do_freebsd_syscall(env
, syscall_nr
, arg1
, arg2
, arg3
,
128 arg4
, arg5
, arg6
, arg7
, arg8
);
130 * Compare to arm/arm/vm_machdep.c
131 * cpu_set_syscall_retval()
133 if (-TARGET_EJUSTRETURN
== ret
) {
135 * Returning from a successful sigreturn syscall.
136 * Avoid clobbering register state.
140 if (-TARGET_ERESTART
== ret
) {
141 env
->regs
[15] -= env
->thumb
? 2 : 4;
144 if ((unsigned int)ret
>= (unsigned int)(-515)) {
146 cpsr_write(env
, CPSR_C
, CPSR_C
, CPSRWriteByInstr
);
149 cpsr_write(env
, 0, CPSR_C
, CPSRWriteByInstr
);
150 env
->regs
[0] = ret
; /* XXX need to handle lseek()? */
151 /* env->regs[1] = 0; */
154 fprintf(stderr
, "qemu: bsd_type (= %d) syscall "
155 "not supported\n", bsd_type
);
160 /* just indicate that signals should be handled asap */
162 case EXCP_PREFETCH_ABORT
:
163 /* See arm/arm/trap.c prefetch_abort_handler() */
164 case EXCP_DATA_ABORT
:
165 /* See arm/arm/trap.c data_abort_handler() */
166 info
.si_signo
= TARGET_SIGSEGV
;
168 /* XXX: check env->error_code */
170 info
.si_addr
= env
->exception
.vaddress
;
171 queue_signal(env
, info
.si_signo
, &info
);
176 info
.si_signo
= TARGET_SIGTRAP
;
178 info
.si_code
= TARGET_TRAP_BRKPT
;
179 info
.si_addr
= env
->exception
.vaddress
;
180 queue_signal(env
, info
.si_signo
, &info
);
184 cpu_exec_step_atomic(cs
);
187 /* nothing to do here for user-mode, just resume guest code */
190 fprintf(stderr
, "qemu: unhandled CPU exception 0x%x - aborting\n",
192 cpu_dump_state(cs
, stderr
, 0);
195 process_pending_signals(env
);
199 static inline void target_cpu_clone_regs(CPUARMState
*env
, target_ulong newsp
)
202 env
->regs
[13] = newsp
;
207 static inline void target_cpu_reset(CPUArchState
*cpu
)
211 #endif /* !_TARGET_ARCH_CPU_H */