xref: /qemu/target/ppc/user_only_helper.c (revision 794511bc51bc89f384063103653e5f40c75cd49e)
1cc8eae8aSDavid Gibson /*
2cc8eae8aSDavid Gibson  *  PowerPC MMU stub handling for user mode emulation
3cc8eae8aSDavid Gibson  *
4cc8eae8aSDavid Gibson  *  Copyright (c) 2003-2007 Jocelyn Mayer
5cc8eae8aSDavid Gibson  *  Copyright (c) 2013 David Gibson, IBM Corporation.
6cc8eae8aSDavid Gibson  *
7cc8eae8aSDavid Gibson  * This library is free software; you can redistribute it and/or
8cc8eae8aSDavid Gibson  * modify it under the terms of the GNU Lesser General Public
9cc8eae8aSDavid Gibson  * License as published by the Free Software Foundation; either
106bd039cdSChetan Pant  * version 2.1 of the License, or (at your option) any later version.
11cc8eae8aSDavid Gibson  *
12cc8eae8aSDavid Gibson  * This library is distributed in the hope that it will be useful,
13cc8eae8aSDavid Gibson  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14cc8eae8aSDavid Gibson  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15cc8eae8aSDavid Gibson  * Lesser General Public License for more details.
16cc8eae8aSDavid Gibson  *
17cc8eae8aSDavid Gibson  * You should have received a copy of the GNU Lesser General Public
18cc8eae8aSDavid Gibson  * License along with this library; if not, see <http://www.gnu.org/licenses/>.
19cc8eae8aSDavid Gibson  */
20cc8eae8aSDavid Gibson 
210d75590dSPeter Maydell #include "qemu/osdep.h"
22cc8eae8aSDavid Gibson #include "cpu.h"
23351bc97eSRichard Henderson #include "exec/exec-all.h"
241db8af5cSRichard Henderson #include "internal.h"
25cc8eae8aSDavid Gibson 
261db8af5cSRichard Henderson void ppc_cpu_record_sigsegv(CPUState *cs, vaddr address,
271db8af5cSRichard Henderson                             MMUAccessType access_type,
281db8af5cSRichard Henderson                             bool maperr, uintptr_t retaddr)
29cc8eae8aSDavid Gibson {
30*794511bcSPhilippe Mathieu-Daudé     CPUPPCState *env = cpu_env(cs);
31cc8eae8aSDavid Gibson     int exception, error_code;
32cc8eae8aSDavid Gibson 
331db8af5cSRichard Henderson     /*
341db8af5cSRichard Henderson      * Both DSISR and the "trap number" (exception vector offset,
351db8af5cSRichard Henderson      * looked up from exception_index) are present in the linux-user
361db8af5cSRichard Henderson      * signal frame.
371db8af5cSRichard Henderson      * FIXME: we don't actually populate the trap number properly.
381db8af5cSRichard Henderson      * It would be easiest to fill in an env->trap value now.
391db8af5cSRichard Henderson      */
40351bc97eSRichard Henderson     if (access_type == MMU_INST_FETCH) {
41cc8eae8aSDavid Gibson         exception = POWERPC_EXCP_ISI;
42cc8eae8aSDavid Gibson         error_code = 0x40000000;
43cc8eae8aSDavid Gibson     } else {
44cc8eae8aSDavid Gibson         exception = POWERPC_EXCP_DSI;
45cc8eae8aSDavid Gibson         error_code = 0x40000000;
46351bc97eSRichard Henderson         if (access_type == MMU_DATA_STORE) {
47cc8eae8aSDavid Gibson             error_code |= 0x02000000;
48cc8eae8aSDavid Gibson         }
49cc8eae8aSDavid Gibson         env->spr[SPR_DAR] = address;
50cc8eae8aSDavid Gibson         env->spr[SPR_DSISR] = error_code;
51cc8eae8aSDavid Gibson     }
5227103424SAndreas Färber     cs->exception_index = exception;
53cc8eae8aSDavid Gibson     env->error_code = error_code;
54351bc97eSRichard Henderson     cpu_loop_exit_restore(cs, retaddr);
55cc8eae8aSDavid Gibson }
56