-
Notifications
You must be signed in to change notification settings - Fork 0
/
ld.c
145 lines (135 loc) · 3.85 KB
/
ld.c
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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
static char RcsHeader[] = "$Header: /usr/home/nakashim/proj-arm64/src/csim/RCS/ld.c,v 1.26 2017/08/23 15:27:49 nakashim Exp nakashim $";
/* ARM Instruction Simulator */
/* Copyright (C) 2007 by NAIST. */
/* Primary writer: Y.Nakashima */
/* [email protected] */
/* ld.c 2005/3/22 */
#include "csim.h"
insn_exec_ld(tid, rob) Uint tid; struct rob *rob;
{
Ull s1, s2, s3, m0; /* source, through, middle(sft,shifter-carry), destination(alu) */
Ull D0[2];
Uint addr, wb, wbaddr, rot;
Ull mask[2];
if (rob->sr[0].t) ex_srr(tid, NULL, &s1, rob, 0);
if (rob->sr[1].t) ex_srr(tid, NULL, &s2, rob, 1);
if (rob->sr[2].t) ex_srr(tid, NULL, &s3, rob, 2);
if (rob->sr[3].t) ex_srr(tid, &rob->dr[0].val[1], &rob->dr[0].val[0], rob, 3);
if (rob->ptw) { /* save old_val for future partial_reg_write in dr[0] */
switch (rob->opcd) {
case 8: /* VLDRB(8) */
case 9: /* VlDRH(16) */
case 10: /* VLDRS(32) */
case 11: /* VLDRD(64) */
break;
}
}
/* Shifter */
switch (rob->sop) {
case 0: /* nop */
m0 = s2;
break;
case 8: /* 0:uxtb */
m0 = (Ull)(s2<<56)>>(56-s3);
break;
case 9: /* 1:uxth */
m0 = (Ull)(s2<<48)>>(48-s3);
break;
case 10: /* 2:uxtw */
m0 = (Ull)(s2<<32)>>(32-s3);
break;
case 11: /* 3:uxtx */
m0 = (Ull)(s2<<s3);
break;
case 12: /* 4:sxtb */
m0 = (Sll)(s2<<56)>>(56-s3);
break;
case 13: /* 5:sxth */
m0 = (Sll)(s2<<48)>>(48-s3);
break;
case 14: /* 6:sxtw */
m0 = (Sll)(s2<<32)>>(32-s3);
break;
case 15: /* 7:sxtx */
m0 = (Sll)(s2<<s3);
break;
}
if (!rob->plus) m0 = -(int)m0;
addr = s1 + ((rob->pre)?m0:0);
wbaddr = s1 + m0;
wb = rob->wb;
rot = 0;
/* LOAD */
switch (rob->opcd) {
case 0: /* LDRB */
case 4: /* LDRSB */
case 8: /* VLDRB */
mask[0] = 0x00000000000000ffLL;
mask[1] = 0x0000000000000000LL;
break;
case 1: /* LDRH */
case 5: /* LDRSH */
case 9: /* VLDRH */
mask[0] = 0x000000000000ffffLL;
mask[1] = 0x0000000000000000LL;
break;
case 2: /* LDRW */
case 6: /* LDRSW */
case 7: /* LDREX */
case 10: /* VLDRS */
mask[0] = 0x00000000ffffffffLL;
mask[1] = 0x0000000000000000LL;
break;
case 3: /* LDR */
case 11: /* VLDRD */
mask[0] = 0xffffffffffffffffLL;
mask[1] = 0x0000000000000000LL;
break;
case 12: /* VLDRQ */
mask[0] = 0xffffffffffffffffLL;
mask[1] = 0xffffffffffffffffLL;
break;
default:
return (ROB_EXECERR); /* error */
}
/* read cache */
switch (o_ldst(tid, rob->type, rob->opcd, addr, mask, rot, D0, rob)) {
case 0: /* i1hit normal end */
if (flag & TRACE_ARM) {
printf(":%08.8x->[%08.8x_%08.8x_%08.8x_%08.8x]", addr, (Uint)(D0[1]>>32), (Uint)D0[1], (Uint)(D0[0]>>32), (Uint)D0[0]);
}
t[tid].pa_d1hit++;
switch (rob->opcd) {
case 4: /* LDRSB */
D0[0] = (Sll)(D0[0]<<56)>>56;
break;
case 5: /* LDRSH */
D0[0] = (Sll)(D0[0]<<48)>>48;
break;
case 6: /* LDRSW */
D0[0] = (Sll)(D0[0]<<32)>>32;
break;
}
if ( rob->dr[1].t) ex_drw(tid, D0[1], D0[0], rob, 1);
if (wb && rob->dr[2].t) ex_drw(tid, 0LL, (Ull)wbaddr, rob, 2); /* update base */
return (ROB_COMPLETE); /* done */
case 1: /* d1mis l1rq busy */
if (flag & TRACE_ARM) {
printf(":%08.8x iorq/l1rq busy", addr);
}
t[tid].pa_d1waitcycle++;
return (ROB_MAPPED); /* no change */
case 2: /* d1mis l1rq enqueued */
if (flag & TRACE_ARM) {
printf(":%08.8x iorq/l1rq enqueued", addr);
}
if (wb && rob->dr[2].t) rob->dr[2].val[0] = wbaddr; /* should be rewritten ex_drw() by if not ROB_COMPLETE */
t[tid].pa_d1mis++;
return (ROB_ISSUED); /* error */
case 3: /* error (ouf of range) */
if (flag & TRACE_ARM) {
printf(":%08.8x address out of range", addr);
}
return (ROB_EXECERR); /* error */
}
}