Richard Henderson | 61766fe | 2016-12-15 11:26:14 -0800 | [diff] [blame] | 1 | /* |
| 2 | * HPPA emulation cpu helpers for qemu. |
| 3 | * |
| 4 | * Copyright (c) 2016 Richard Henderson <rth@twiddle.net> |
| 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 |
Chetan Pant | d6ea423 | 2020-10-23 12:33:53 +0000 | [diff] [blame] | 9 | * version 2.1 of the License, or (at your option) any later version. |
Richard Henderson | 61766fe | 2016-12-15 11:26:14 -0800 | [diff] [blame] | 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" |
Philippe Mathieu-Daudé | cd61748 | 2022-02-07 09:27:56 +0100 | [diff] [blame] | 21 | #include "qemu/log.h" |
Richard Henderson | 61766fe | 2016-12-15 11:26:14 -0800 | [diff] [blame] | 22 | #include "cpu.h" |
Richard Henderson | 61766fe | 2016-12-15 11:26:14 -0800 | [diff] [blame] | 23 | #include "fpu/softfloat.h" |
Sven Schnelle | d5de20b | 2019-03-11 20:16:00 +0100 | [diff] [blame] | 24 | #include "exec/exec-all.h" |
Richard Henderson | 61766fe | 2016-12-15 11:26:14 -0800 | [diff] [blame] | 25 | #include "exec/helper-proto.h" |
Markus Armbruster | 90c84c5 | 2019-04-17 21:18:02 +0200 | [diff] [blame] | 26 | #include "qemu/qemu-print.h" |
Richard Henderson | 61766fe | 2016-12-15 11:26:14 -0800 | [diff] [blame] | 27 | |
Richard Henderson | eaa3783 | 2017-10-09 12:35:48 -0700 | [diff] [blame] | 28 | target_ureg cpu_hppa_get_psw(CPUHPPAState *env) |
Richard Henderson | 61766fe | 2016-12-15 11:26:14 -0800 | [diff] [blame] | 29 | { |
Richard Henderson | eaa3783 | 2017-10-09 12:35:48 -0700 | [diff] [blame] | 30 | target_ureg psw; |
Richard Henderson | 61766fe | 2016-12-15 11:26:14 -0800 | [diff] [blame] | 31 | |
| 32 | /* Fold carry bits down to 8 consecutive bits. */ |
| 33 | /* ??? Needs tweaking for hppa64. */ |
| 34 | /* .......b...c...d...e...f...g...h */ |
| 35 | psw = (env->psw_cb >> 4) & 0x01111111; |
| 36 | /* .......b..bc..cd..de..ef..fg..gh */ |
| 37 | psw |= psw >> 3; |
| 38 | /* .............bcd............efgh */ |
| 39 | psw |= (psw >> 6) & 0x000f000f; |
| 40 | /* .........................bcdefgh */ |
| 41 | psw |= (psw >> 12) & 0xf; |
| 42 | psw |= env->psw_cb_msb << 7; |
Richard Henderson | fa57e32 | 2017-10-08 19:00:40 -0400 | [diff] [blame] | 43 | psw = (psw & 0xff) << 8; |
Richard Henderson | 61766fe | 2016-12-15 11:26:14 -0800 | [diff] [blame] | 44 | |
Richard Henderson | fa57e32 | 2017-10-08 19:00:40 -0400 | [diff] [blame] | 45 | psw |= env->psw_n * PSW_N; |
| 46 | psw |= (env->psw_v < 0) * PSW_V; |
| 47 | psw |= env->psw; |
Richard Henderson | 61766fe | 2016-12-15 11:26:14 -0800 | [diff] [blame] | 48 | |
| 49 | return psw; |
| 50 | } |
| 51 | |
Richard Henderson | eaa3783 | 2017-10-09 12:35:48 -0700 | [diff] [blame] | 52 | void cpu_hppa_put_psw(CPUHPPAState *env, target_ureg psw) |
Richard Henderson | 61766fe | 2016-12-15 11:26:14 -0800 | [diff] [blame] | 53 | { |
Sven Schnelle | d5de20b | 2019-03-11 20:16:00 +0100 | [diff] [blame] | 54 | target_ureg old_psw = env->psw; |
Richard Henderson | eaa3783 | 2017-10-09 12:35:48 -0700 | [diff] [blame] | 55 | target_ureg cb = 0; |
Richard Henderson | 61766fe | 2016-12-15 11:26:14 -0800 | [diff] [blame] | 56 | |
Richard Henderson | fa57e32 | 2017-10-08 19:00:40 -0400 | [diff] [blame] | 57 | env->psw = psw & ~(PSW_N | PSW_V | PSW_CB); |
| 58 | env->psw_n = (psw / PSW_N) & 1; |
| 59 | env->psw_v = -((psw / PSW_V) & 1); |
Richard Henderson | 61766fe | 2016-12-15 11:26:14 -0800 | [diff] [blame] | 60 | env->psw_cb_msb = (psw >> 15) & 1; |
| 61 | |
| 62 | cb |= ((psw >> 14) & 1) << 28; |
| 63 | cb |= ((psw >> 13) & 1) << 24; |
| 64 | cb |= ((psw >> 12) & 1) << 20; |
| 65 | cb |= ((psw >> 11) & 1) << 16; |
| 66 | cb |= ((psw >> 10) & 1) << 12; |
| 67 | cb |= ((psw >> 9) & 1) << 8; |
| 68 | cb |= ((psw >> 8) & 1) << 4; |
| 69 | env->psw_cb = cb; |
Sven Schnelle | d5de20b | 2019-03-11 20:16:00 +0100 | [diff] [blame] | 70 | |
| 71 | /* If PSW_P changes, it affects how we translate addresses. */ |
| 72 | if ((psw ^ old_psw) & PSW_P) { |
| 73 | #ifndef CONFIG_USER_ONLY |
Helge Deller | 88b7ad1 | 2023-08-07 11:42:11 +0200 | [diff] [blame] | 74 | tlb_flush_by_mmuidx(env_cpu(env), HPPA_MMU_FLUSH_MASK); |
Sven Schnelle | d5de20b | 2019-03-11 20:16:00 +0100 | [diff] [blame] | 75 | #endif |
| 76 | } |
Richard Henderson | 61766fe | 2016-12-15 11:26:14 -0800 | [diff] [blame] | 77 | } |
| 78 | |
Markus Armbruster | 90c84c5 | 2019-04-17 21:18:02 +0200 | [diff] [blame] | 79 | void hppa_cpu_dump_state(CPUState *cs, FILE *f, int flags) |
Richard Henderson | 61766fe | 2016-12-15 11:26:14 -0800 | [diff] [blame] | 80 | { |
| 81 | HPPACPU *cpu = HPPA_CPU(cs); |
| 82 | CPUHPPAState *env = &cpu->env; |
Richard Henderson | eaa3783 | 2017-10-09 12:35:48 -0700 | [diff] [blame] | 83 | target_ureg psw = cpu_hppa_get_psw(env); |
| 84 | target_ureg psw_cb; |
Richard Henderson | fa57e32 | 2017-10-08 19:00:40 -0400 | [diff] [blame] | 85 | char psw_c[20]; |
Richard Henderson | 61766fe | 2016-12-15 11:26:14 -0800 | [diff] [blame] | 86 | int i; |
| 87 | |
Helge Deller | 770525f | 2022-09-18 21:45:49 +0200 | [diff] [blame] | 88 | qemu_fprintf(f, "IA_F " TARGET_FMT_lx " IA_B " TARGET_FMT_lx |
| 89 | " IIR " TREG_FMT_lx "\n", |
Markus Armbruster | 90c84c5 | 2019-04-17 21:18:02 +0200 | [diff] [blame] | 90 | hppa_form_gva_psw(psw, env->iasq_f, env->iaoq_f), |
Helge Deller | 770525f | 2022-09-18 21:45:49 +0200 | [diff] [blame] | 91 | hppa_form_gva_psw(psw, env->iasq_b, env->iaoq_b), |
| 92 | env->cr[CR_IIR]); |
Richard Henderson | fa57e32 | 2017-10-08 19:00:40 -0400 | [diff] [blame] | 93 | |
| 94 | psw_c[0] = (psw & PSW_W ? 'W' : '-'); |
| 95 | psw_c[1] = (psw & PSW_E ? 'E' : '-'); |
| 96 | psw_c[2] = (psw & PSW_S ? 'S' : '-'); |
| 97 | psw_c[3] = (psw & PSW_T ? 'T' : '-'); |
| 98 | psw_c[4] = (psw & PSW_H ? 'H' : '-'); |
| 99 | psw_c[5] = (psw & PSW_L ? 'L' : '-'); |
| 100 | psw_c[6] = (psw & PSW_N ? 'N' : '-'); |
| 101 | psw_c[7] = (psw & PSW_X ? 'X' : '-'); |
| 102 | psw_c[8] = (psw & PSW_B ? 'B' : '-'); |
| 103 | psw_c[9] = (psw & PSW_C ? 'C' : '-'); |
| 104 | psw_c[10] = (psw & PSW_V ? 'V' : '-'); |
| 105 | psw_c[11] = (psw & PSW_M ? 'M' : '-'); |
| 106 | psw_c[12] = (psw & PSW_F ? 'F' : '-'); |
| 107 | psw_c[13] = (psw & PSW_R ? 'R' : '-'); |
| 108 | psw_c[14] = (psw & PSW_Q ? 'Q' : '-'); |
| 109 | psw_c[15] = (psw & PSW_P ? 'P' : '-'); |
| 110 | psw_c[16] = (psw & PSW_D ? 'D' : '-'); |
| 111 | psw_c[17] = (psw & PSW_I ? 'I' : '-'); |
| 112 | psw_c[18] = '\0'; |
| 113 | psw_cb = ((env->psw_cb >> 4) & 0x01111111) | (env->psw_cb_msb << 28); |
| 114 | |
Markus Armbruster | 90c84c5 | 2019-04-17 21:18:02 +0200 | [diff] [blame] | 115 | qemu_fprintf(f, "PSW " TREG_FMT_lx " CB " TREG_FMT_lx " %s\n", |
| 116 | psw, psw_cb, psw_c); |
Richard Henderson | fa57e32 | 2017-10-08 19:00:40 -0400 | [diff] [blame] | 117 | |
| 118 | for (i = 0; i < 32; i++) { |
Markus Armbruster | 90c84c5 | 2019-04-17 21:18:02 +0200 | [diff] [blame] | 119 | qemu_fprintf(f, "GR%02d " TREG_FMT_lx "%c", i, env->gr[i], |
| 120 | (i & 3) == 3 ? '\n' : ' '); |
Richard Henderson | 61766fe | 2016-12-15 11:26:14 -0800 | [diff] [blame] | 121 | } |
Richard Henderson | 3342347 | 2017-10-09 22:54:12 -0700 | [diff] [blame] | 122 | #ifndef CONFIG_USER_ONLY |
| 123 | for (i = 0; i < 8; i++) { |
Markus Armbruster | 90c84c5 | 2019-04-17 21:18:02 +0200 | [diff] [blame] | 124 | qemu_fprintf(f, "SR%02d %08x%c", i, (uint32_t)(env->sr[i] >> 32), |
| 125 | (i & 3) == 3 ? '\n' : ' '); |
Richard Henderson | 3342347 | 2017-10-09 22:54:12 -0700 | [diff] [blame] | 126 | } |
| 127 | #endif |
Markus Armbruster | 90c84c5 | 2019-04-17 21:18:02 +0200 | [diff] [blame] | 128 | qemu_fprintf(f, "\n"); |
Richard Henderson | 61766fe | 2016-12-15 11:26:14 -0800 | [diff] [blame] | 129 | |
| 130 | /* ??? FR */ |
| 131 | } |