Bug 476331 - clean up generated/distributed filter scripts
[valgrind.git] / VEX / priv / guest_nanomips_helpers.c
blob00944494b4b04751df6ce8dea4d3ebf539865541
2 /*---------------------------------------------------------------*/
3 /*--- begin guest_nanomips_helpers.c ---*/
4 /*---------------------------------------------------------------*/
6 /*
7 This file is part of Valgrind, a dynamic binary instrumentation
8 framework.
10 Copyright (C) 2017-2018 RT-RK
12 This program is free software; you can redistribute it and/or
13 modify it under the terms of the GNU General Public License as
14 published by the Free Software Foundation; either version 2 of the
15 License, or (at your option) any later version.
17 This program is distributed in the hope that it will be useful, but
18 WITHOUT ANY WARRANTY; without even the implied warranty of
19 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
20 General Public License for more details.
22 You should have received a copy of the GNU General Public License
23 along with this program; if not, write to the Free Software
24 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
25 02111-1307, USA.
27 The GNU General Public License is contained in the file COPYING.
30 #include "libvex_basictypes.h"
31 #include "libvex_emnote.h"
32 #include "libvex_guest_mips32.h"
33 #include "libvex_ir.h"
34 #include "libvex.h"
36 #include "main_util.h"
37 #include "main_globals.h"
38 #include "guest_generic_bb_to_IR.h"
39 #include "guest_nanomips_defs.h"
41 #if defined (__GNUC__)
42 #define GCC_VERSION (__GNUC__ * 100 + __GNUC_MINOR__)
43 #else
44 #define GCC_VERSION 0
45 #endif
47 /* This file contains helper functions for mips guest code. Calls to
48 these functions are generated by the back end.
51 #define ALWAYSDEFD32(field) \
52 { offsetof(VexGuestMIPS32State, field), \
53 (sizeof ((VexGuestMIPS32State*)0)->field) }
55 VexGuestLayout nanomipsGuest_layout = {
56 /* Total size of the guest state, in bytes. */
57 .total_sizeB = sizeof(VexGuestMIPS32State),
58 /* Describe the stack pointer. */
59 .offset_SP = offsetof(VexGuestMIPS32State, guest_r29),
60 .sizeof_SP = 4,
61 /* Describe the frame pointer. */
62 .offset_FP = offsetof(VexGuestMIPS32State, guest_r30),
63 .sizeof_FP = 4,
64 /* Describe the instruction pointer. */
65 .offset_IP = offsetof(VexGuestMIPS32State, guest_PC),
66 .sizeof_IP = 4,
67 /* Describe any sections to be regarded by Memcheck as
68 'always-defined'. */
69 .n_alwaysDefd = 8,
70 /* ? :( */
71 .alwaysDefd = {
72 /* 0 */ ALWAYSDEFD32(guest_r0),
73 /* 1 */ ALWAYSDEFD32(guest_r1),
74 /* 2 */ ALWAYSDEFD32(guest_EMNOTE),
75 /* 3 */ ALWAYSDEFD32(guest_CMSTART),
76 /* 4 */ ALWAYSDEFD32(guest_CMLEN),
77 /* 5 */ ALWAYSDEFD32(guest_r29),
78 /* 6 */ ALWAYSDEFD32(guest_r31),
79 /* 7 */ ALWAYSDEFD32(guest_ULR)
84 #define ASM_VOLATILE_RDHWR(opcode) \
85 __asm__ __volatile__(".word 0x204001C0 | "#opcode" << 16 \n\t" \
86 : "+r" (x) : : \
89 HWord nanomips_dirtyhelper_rdhwr ( UInt rd )
91 #if defined(__nanomips__)
92 register HWord x __asm__("t4") = 0;
94 switch (rd) {
95 case 0: /* x = CPUNum() */
96 ASM_VOLATILE_RDHWR(0); /* rdhwr t4, $0 */
97 break;
99 case 1: /* x = SYNCI_Step() */
100 ASM_VOLATILE_RDHWR(1); /* rdhwr t4, $1 */
101 break;
103 case 2: /* x = CC() */
104 ASM_VOLATILE_RDHWR(2); /* rdhwr t4, $2 */
105 break;
107 case 3: /* x = CCRes() */
108 ASM_VOLATILE_RDHWR(3); /* rdhwr t4, $3 */
109 break;
112 default:
113 vassert(0);
114 break;
117 return x;
118 #else
119 return 0;
120 #endif
124 /*---------------------------------------------------------------*/
125 /*--- end guest_nanomips_helpers.c ---*/
126 /*---------------------------------------------------------------*/