ms_iprint.c
1.87 KB
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
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
/*
* Copyright (C) 1996-1998 by the Board of Trustees
* of Leland Stanford Junior University.
*
* This file is part of the SimOS distribution.
* See LICENSE file for terms of the license.
*
*/
/*
* ms_iprint - Print out a mips instruction
*
* Jim Bennett
* 1993, 1994
*/
#include <stdio.h>
#include "ms.h"
void print_inst (FILE *stream, INST *ip)
{
int need_comma = 0;
fprintf (stream, "%s ", opcode_mnemonics[ip->op]);
if (ip->r1 != -1)
{
print_reg (stream, ip->r1);
fprintf (stream, " = ");
}
if (ip->r2 != -1)
{
print_reg (stream, ip->r2);
need_comma = 1;
}
if (ip->r3 != -1)
{
if (need_comma) fprintf (stream, ", ");
print_reg (stream, ip->r3);
need_comma = 1;
}
if (need_comma) fprintf (stream, ", ");
fprintf (stream, "0x%x", ip->imm);
}
/*
* print_reg - Print out the name of the register to the
* given output stream.
*/
void print_reg (FILE *stream, int r)
{
if (r < 0)
fprintf (stream, "XXX");
else if (r < FPREG)
{
if (r == SP)
fprintf (stream, "SP");
else if (r == LP)
fprintf (stream, "LP");
else
fprintf (stream, "R%d", r);
}
else if (r < HILOREG)
fprintf (stream, "F%d", r - FPREG);
else if (r < FPCTL)
fprintf (stream, (r == HIREG ? "HI" : "LO"));
else if (r < TOT_REG)
fprintf (stream, "C%d", r - FPCTL);
else if (r < MAX_FP)
fprintf (stream, "F%d", r);
else
fprintf (stream, "R%d", r);
}
/*
* print_reg_contents - Print out register contents
*/
void print_reg_contents (FILE *stream, int r, void *ptr)
{
if (r < 0)
fprintf (stream, "XXX");
else if (r < FPREG)
fprintf (stream, "0x%8.8x", *(int *)ptr);
else if (r < HILOREG)
fprintf (stream, "%f", *(double *)ptr);
else if (r < TOT_REG)
fprintf (stream, "0x%8.8x", *(int *)ptr);
else if (r < MAX_FP)
fprintf (stream, "%f", *(double *)ptr);
else
fprintf (stream, "0x%8.8x", *(int *)ptr);
}