mips32.h 6.44 KB
Newer Older
ntfreak's avatar
ntfreak committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
/***************************************************************************
 *   Copyright (C) 2008 by Spencer Oliver                                  *
 *   spen@spen-soft.co.uk                                                  *
 *                                                                         *
 *   Copyright (C) 2008 by David T.L. Wong                                 *
 *                                                                         *
 *   This program is free software; you can redistribute it and/or modify  *
 *   it under the terms of the GNU General Public License as published by  *
 *   the Free Software Foundation; either version 2 of the License, or     *
 *   (at your option) any later version.                                   *
 *                                                                         *
 *   This program is distributed in the hope that it will be useful,       *
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
 *   GNU General Public License for more details.                          *
 *                                                                         *
 *   You should have received a copy of the GNU General Public License     *
 *   along with this program; if not, write to the                         *
 *   Free Software Foundation, Inc.,                                       *
 *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
 ***************************************************************************/

#ifndef MIPS32_H
#define MIPS32_H

26
27
#include "target.h"
#include "mips32_pracc.h"
ntfreak's avatar
ntfreak committed
28
29
30
31

#define MIPS32_COMMON_MAGIC		0xB320B320

/* offsets into mips32 core register cache */
32
enum
ntfreak's avatar
ntfreak committed
33
34
35
36
37
{
	MIPS32_PC = 37,
	MIPS32NUMCOREREGS
};

38
39
40
41
42
43
44
45
enum mips32_isa_mode
{
	MIPS32_ISA_MIPS32 = 0,
	MIPS32_ISA_MIPS16E = 1,
};

extern const char *mips_isa_strings[];

46
struct mips32_comparator
47
48
{
	int used;
49
50
	uint32_t bp_value;
	uint32_t reg_address;
51
};
52

53
struct mips32_common
ntfreak's avatar
ntfreak committed
54
{
55
	uint32_t common_magic;
ntfreak's avatar
ntfreak committed
56
	void *arch_info;
57
	struct reg_cache *core_cache;
58
	struct mips_ejtag ejtag_info;
59
	uint32_t core_regs[MIPS32NUMCOREREGS];
60
	enum mips32_isa_mode isa_mode;
61

62
63
64
65
66
	int bp_scanned;
	int num_inst_bpoints;
	int num_data_bpoints;
	int num_inst_bpoints_avail;
	int num_data_bpoints_avail;
67
68
	struct mips32_comparator *inst_break_list;
	struct mips32_comparator *data_break_list;
69

ntfreak's avatar
ntfreak committed
70
	/* register cache to processor synchronization */
Zachary T Welch's avatar
Zachary T Welch committed
71
72
	int (*read_core_reg)(struct target *target, int num);
	int (*write_core_reg)(struct target *target, int num);
73
};
ntfreak's avatar
ntfreak committed
74

75
76
77
78
79
80
static inline struct mips32_common *
target_to_mips32(struct target *target)
{
	return target->arch_info;
}

81
struct mips32_core_reg
ntfreak's avatar
ntfreak committed
82
{
83
	uint32_t num;
Zachary T Welch's avatar
Zachary T Welch committed
84
	struct target *target;
85
	struct mips32_common *mips32_common;
86
};
ntfreak's avatar
ntfreak committed
87

88
89
90
91
92
93
struct mips32_algorithm
{
	int common_magic;
	enum mips32_isa_mode isa_mode;
};

ntfreak's avatar
ntfreak committed
94
#define MIPS32_OP_BEQ	0x04
95
#define MIPS32_OP_BNE	0x05
ntfreak's avatar
ntfreak committed
96
97
98
#define MIPS32_OP_ADDI	0x08
#define MIPS32_OP_AND	0x24
#define MIPS32_OP_COP0	0x10
99
#define MIPS32_OP_JR	0x08
ntfreak's avatar
ntfreak committed
100
101
102
103
104
#define MIPS32_OP_LUI	0x0F
#define MIPS32_OP_LW	0x23
#define MIPS32_OP_LBU	0x24
#define MIPS32_OP_LHU	0x25
#define MIPS32_OP_MFHI	0x10
105
#define MIPS32_OP_MTHI	0x11
ntfreak's avatar
ntfreak committed
106
#define MIPS32_OP_MFLO	0x12
107
#define MIPS32_OP_MTLO	0x13
ntfreak's avatar
ntfreak committed
108
109
110
111
112
113
114
115
#define MIPS32_OP_SB	0x28
#define MIPS32_OP_SH	0x29
#define MIPS32_OP_SW	0x2B
#define MIPS32_OP_ORI	0x0D

#define MIPS32_COP0_MF	0x00
#define MIPS32_COP0_MT	0x04

zwelch's avatar
zwelch committed
116
117
#define MIPS32_R_INST(opcode, rs, rt, rd, shamt, funct)	(((opcode) << 26) |((rs) << 21) | ((rt) << 16) | ((rd) << 11)| ((shamt) << 6) | (funct))
#define MIPS32_I_INST(opcode, rs, rt, immd)	(((opcode) << 26) |((rs) << 21) | ((rt) << 16) | (immd))
zwelch's avatar
zwelch committed
118
#define MIPS32_J_INST(opcode, addr)	(((opcode) << 26) |(addr))
ntfreak's avatar
ntfreak committed
119
120
121
122
123
124

#define MIPS32_NOP					0
#define MIPS32_ADDI(tar, src, val)	MIPS32_I_INST(MIPS32_OP_ADDI, src, tar, val)
#define MIPS32_AND(reg, off, val)	MIPS32_R_INST(0, off, val, reg, 0, MIPS32_OP_AND)
#define MIPS32_B(off)				MIPS32_BEQ(0, 0, off)
#define MIPS32_BEQ(src,tar,off)		MIPS32_I_INST(MIPS32_OP_BEQ, src, tar, off)
125
#define MIPS32_BNE(src,tar,off)		MIPS32_I_INST(MIPS32_OP_BNE, src, tar, off)
126
#define MIPS32_JR(reg)				MIPS32_R_INST(0, reg, 0, 0, 0, MIPS32_OP_JR)
ntfreak's avatar
ntfreak committed
127
128
129
130
131
132
#define MIPS32_MFC0(gpr, cpr, sel)	MIPS32_R_INST(MIPS32_OP_COP0, MIPS32_COP0_MF, gpr, cpr, 0, sel)
#define MIPS32_MTC0(gpr,cpr, sel)	MIPS32_R_INST(MIPS32_OP_COP0, MIPS32_COP0_MT, gpr, cpr, 0, sel)
#define MIPS32_LBU(reg, off, base)	MIPS32_I_INST(MIPS32_OP_LBU, base, reg, off)
#define MIPS32_LHU(reg, off, base)	MIPS32_I_INST(MIPS32_OP_LHU, base, reg, off)
#define MIPS32_LUI(reg, val)		MIPS32_I_INST(MIPS32_OP_LUI, 0, reg, val)
#define MIPS32_LW(reg, off, base)	MIPS32_I_INST(MIPS32_OP_LW, base, reg, off)
133
134
#define MIPS32_MFLO(reg)			MIPS32_R_INST(0, 0, 0, reg, 0, MIPS32_OP_MFLO)
#define MIPS32_MFHI(reg)			MIPS32_R_INST(0, 0, 0, reg, 0, MIPS32_OP_MFHI)
135
136
#define MIPS32_MTLO(reg)			MIPS32_R_INST(0, reg, 0, 0, 0, MIPS32_OP_MTLO)
#define MIPS32_MTHI(reg)			MIPS32_R_INST(0, reg, 0, 0, 0, MIPS32_OP_MTHI)
ntfreak's avatar
ntfreak committed
137
138
139
140
#define MIPS32_ORI(src, tar, val)	MIPS32_I_INST(MIPS32_OP_ORI, src, tar, val)
#define MIPS32_SB(reg, off, base)	MIPS32_I_INST(MIPS32_OP_SB, base, reg, off)
#define MIPS32_SH(reg, off, base)	MIPS32_I_INST(MIPS32_OP_SH, base, reg, off)
#define MIPS32_SW(reg, off, base)	MIPS32_I_INST(MIPS32_OP_SW, base, reg, off)
141
142

/* ejtag specific instructions */
ntfreak's avatar
ntfreak committed
143
#define MIPS32_DRET					0x4200001F
144
#define MIPS32_SDBBP				0x7000003F
Spencer Oliver's avatar
Spencer Oliver committed
145
#define MIPS16_SDBBP				0xE801
ntfreak's avatar
ntfreak committed
146

Zachary T Welch's avatar
Zachary T Welch committed
147
int mips32_arch_state(struct target *target);
148

Zachary T Welch's avatar
Zachary T Welch committed
149
int mips32_init_arch_info(struct target *target,
150
		struct mips32_common *mips32, struct jtag_tap *tap);
151

Zachary T Welch's avatar
Zachary T Welch committed
152
153
int mips32_restore_context(struct target *target);
int mips32_save_context(struct target *target);
154

Zachary T Welch's avatar
Zachary T Welch committed
155
struct reg_cache *mips32_build_reg_cache(struct target *target);
156

Zachary T Welch's avatar
Zachary T Welch committed
157
int mips32_run_algorithm(struct target *target,
158
		int num_mem_params, struct mem_param *mem_params,
159
		int num_reg_params, struct reg_param *reg_params,
160
161
162
		uint32_t entry_point, uint32_t exit_point,
		int timeout_ms, void *arch_info);

Zachary T Welch's avatar
Zachary T Welch committed
163
int mips32_configure_break_unit(struct target *target);
164

Zachary T Welch's avatar
Zachary T Welch committed
165
int mips32_enable_interrupts(struct target *target, int enable);
166

Zachary T Welch's avatar
Zachary T Welch committed
167
int mips32_examine(struct target *target);
168

169
int mips32_register_commands(struct command_context *cmd_ctx);
170

Zachary T Welch's avatar
Zachary T Welch committed
171
int mips32_get_gdb_reg_list(struct target *target,
Zachary T Welch's avatar
Zachary T Welch committed
172
		struct reg **reg_list[], int *reg_list_size);
173
174
175
176
int mips32_checksum_memory(struct target *target, uint32_t address,
		uint32_t count, uint32_t* checksum);
int mips32_blank_check_memory(struct target *target,
		uint32_t address, uint32_t count, uint32_t* blank);
ntfreak's avatar
ntfreak committed
177
178

#endif	/*MIPS32_H*/