]> Git Repo - qemu.git/blob - target/hppa/helper.c
target/hppa: Implement the system mask instructions
[qemu.git] / target / hppa / helper.c
1 /*
2  *  HPPA emulation cpu helpers for qemu.
3  *
4  * Copyright (c) 2016 Richard Henderson <[email protected]>
5  *
6  * This library is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public
8  * License as published by the Free Software Foundation; either
9  * version 2 of the License, or (at your option) any later version.
10  *
11  * This library 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 GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with this library; if not, see <http://www.gnu.org/licenses/>.
18  */
19
20 #include "qemu/osdep.h"
21
22 #include "cpu.h"
23 #include "exec/exec-all.h"
24 #include "fpu/softfloat.h"
25 #include "exec/helper-proto.h"
26
27 target_ureg cpu_hppa_get_psw(CPUHPPAState *env)
28 {
29     target_ureg psw;
30
31     /* Fold carry bits down to 8 consecutive bits.  */
32     /* ??? Needs tweaking for hppa64.  */
33     /* .......b...c...d...e...f...g...h */
34     psw = (env->psw_cb >> 4) & 0x01111111;
35     /* .......b..bc..cd..de..ef..fg..gh */
36     psw |= psw >> 3;
37     /* .............bcd............efgh */
38     psw |= (psw >> 6) & 0x000f000f;
39     /* .........................bcdefgh */
40     psw |= (psw >> 12) & 0xf;
41     psw |= env->psw_cb_msb << 7;
42     psw = (psw & 0xff) << 8;
43
44     psw |= env->psw_n * PSW_N;
45     psw |= (env->psw_v < 0) * PSW_V;
46     psw |= env->psw;
47
48     return psw;
49 }
50
51 void cpu_hppa_put_psw(CPUHPPAState *env, target_ureg psw)
52 {
53     target_ureg cb = 0;
54
55     env->psw = psw & ~(PSW_N | PSW_V | PSW_CB);
56     env->psw_n = (psw / PSW_N) & 1;
57     env->psw_v = -((psw / PSW_V) & 1);
58     env->psw_cb_msb = (psw >> 15) & 1;
59
60     cb |= ((psw >> 14) & 1) << 28;
61     cb |= ((psw >> 13) & 1) << 24;
62     cb |= ((psw >> 12) & 1) << 20;
63     cb |= ((psw >> 11) & 1) << 16;
64     cb |= ((psw >> 10) & 1) << 12;
65     cb |= ((psw >>  9) & 1) <<  8;
66     cb |= ((psw >>  8) & 1) <<  4;
67     env->psw_cb = cb;
68 }
69
70 void hppa_cpu_do_interrupt(CPUState *cs)
71 {
72     HPPACPU *cpu = HPPA_CPU(cs);
73     CPUHPPAState *env = &cpu->env;
74     int i = cs->exception_index;
75
76     if (qemu_loglevel_mask(CPU_LOG_INT)) {
77         static const char * const names[] = {
78             [EXCP_HPMC]          = "high priority machine check",
79             [EXCP_POWER_FAIL]    = "power fail interrupt",
80             [EXCP_RC]            = "recovery counter trap",
81             [EXCP_EXT_INTERRUPT] = "external interrupt",
82             [EXCP_LPMC]          = "low priority machine check",
83             [EXCP_ITLB_MISS]     = "instruction tlb miss fault",
84             [EXCP_IMP]           = "instruction memory protection trap",
85             [EXCP_ILL]           = "illegal instruction trap",
86             [EXCP_BREAK]         = "break instruction trap",
87             [EXCP_PRIV_OPR]      = "privileged operation trap",
88             [EXCP_PRIV_REG]      = "privileged register trap",
89             [EXCP_OVERFLOW]      = "overflow trap",
90             [EXCP_COND]          = "conditional trap",
91             [EXCP_ASSIST]        = "assist exception trap",
92             [EXCP_DTLB_MISS]     = "data tlb miss fault",
93             [EXCP_NA_ITLB_MISS]  = "non-access instruction tlb miss",
94             [EXCP_NA_DTLB_MISS]  = "non-access data tlb miss",
95             [EXCP_DMP]           = "data memory protection trap",
96             [EXCP_DMB]           = "data memory break trap",
97             [EXCP_TLB_DIRTY]     = "tlb dirty bit trap",
98             [EXCP_PAGE_REF]      = "page reference trap",
99             [EXCP_ASSIST_EMU]    = "assist emulation trap",
100             [EXCP_HPT]           = "high-privilege transfer trap",
101             [EXCP_LPT]           = "low-privilege transfer trap",
102             [EXCP_TB]            = "taken branch trap",
103             [EXCP_DMAR]          = "data memory access rights trap",
104             [EXCP_DMPI]          = "data memory protection id trap",
105             [EXCP_UNALIGN]       = "unaligned data reference trap",
106             [EXCP_PER_INTERRUPT] = "performance monitor interrupt",
107             [EXCP_SYSCALL]       = "syscall",
108             [EXCP_SYSCALL_LWS]   = "syscall-lws",
109         };
110         static int count;
111         const char *name = NULL;
112
113         if (i >= 0 && i < ARRAY_SIZE(names)) {
114             name = names[i];
115         }
116         if (name) {
117             qemu_log("INT %6d: %s ia_f=" TARGET_FMT_lx "\n",
118                      ++count, name, env->iaoq_f);
119         } else {
120             qemu_log("INT %6d: unknown %d ia_f=" TARGET_FMT_lx "\n",
121                      ++count, i, env->iaoq_f);
122         }
123     }
124     cs->exception_index = -1;
125 }
126
127 bool hppa_cpu_exec_interrupt(CPUState *cs, int interrupt_request)
128 {
129     abort();
130     return false;
131 }
132
133 void hppa_cpu_dump_state(CPUState *cs, FILE *f,
134                          fprintf_function cpu_fprintf, int flags)
135 {
136     HPPACPU *cpu = HPPA_CPU(cs);
137     CPUHPPAState *env = &cpu->env;
138     target_ureg psw = cpu_hppa_get_psw(env);
139     target_ureg psw_cb;
140     char psw_c[20];
141     int i;
142
143     cpu_fprintf(f, "IA_F " TARGET_FMT_lx " IA_B " TARGET_FMT_lx "\n",
144                 (target_ulong)env->iaoq_f, (target_ulong)env->iaoq_b);
145
146     psw_c[0]  = (psw & PSW_W ? 'W' : '-');
147     psw_c[1]  = (psw & PSW_E ? 'E' : '-');
148     psw_c[2]  = (psw & PSW_S ? 'S' : '-');
149     psw_c[3]  = (psw & PSW_T ? 'T' : '-');
150     psw_c[4]  = (psw & PSW_H ? 'H' : '-');
151     psw_c[5]  = (psw & PSW_L ? 'L' : '-');
152     psw_c[6]  = (psw & PSW_N ? 'N' : '-');
153     psw_c[7]  = (psw & PSW_X ? 'X' : '-');
154     psw_c[8]  = (psw & PSW_B ? 'B' : '-');
155     psw_c[9]  = (psw & PSW_C ? 'C' : '-');
156     psw_c[10] = (psw & PSW_V ? 'V' : '-');
157     psw_c[11] = (psw & PSW_M ? 'M' : '-');
158     psw_c[12] = (psw & PSW_F ? 'F' : '-');
159     psw_c[13] = (psw & PSW_R ? 'R' : '-');
160     psw_c[14] = (psw & PSW_Q ? 'Q' : '-');
161     psw_c[15] = (psw & PSW_P ? 'P' : '-');
162     psw_c[16] = (psw & PSW_D ? 'D' : '-');
163     psw_c[17] = (psw & PSW_I ? 'I' : '-');
164     psw_c[18] = '\0';
165     psw_cb = ((env->psw_cb >> 4) & 0x01111111) | (env->psw_cb_msb << 28);
166
167     cpu_fprintf(f, "PSW  " TREG_FMT_lx " CB   " TREG_FMT_lx " %s\n",
168                 psw, psw_cb, psw_c);
169
170     for (i = 0; i < 32; i++) {
171         cpu_fprintf(f, "GR%02d " TREG_FMT_lx " ", i, env->gr[i]);
172         if ((i % 4) == 3) {
173             cpu_fprintf(f, "\n");
174         }
175     }
176     cpu_fprintf(f, "\n");
177
178     /* ??? FR */
179 }
This page took 0.036079 seconds and 4 git commands to generate.