-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathimacblok.lisp
219 lines (207 loc) · 9.34 KB
/
imacblok.lisp
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
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
;;; -*- Mode: LISP; Syntax: Common-Lisp; Package: POWERPC-INTERNALS; Base: 10; Lowercase: T -*-
(in-package "POWERPC-INTERNALS")
;;; Macros in support of block instructions. These are mostly in IFUNBLOK.PPCS
(assert (lisp:and (< (integer-length processorstate$q-bar0) 15)
(< (integer-length processorstate$q-bar1) 15)
(< (integer-length processorstate$q-bar2) 15)
(< (integer-length processorstate$q-bar3) 15))
()
"The BAR registers have an offset of more than 15 bits")
;;; Note well! We always store the updated VMA back into the BAR, even
;;; in the no-increment case. This is because the BAR must get the result
;;; of having followed forwarding pointers.
;;; Note well! We always store the updated VMA back into the BAR, even
;;; in the no-increment case. This is because the BAR must get the result
;;; of having followed forwarding pointers.
(defmacro i%block-n-read (bar op vma tag data cycle temp3 temp4 temp5 temp6 temp9 temp10 temp11 temp12)
(check-temporaries (bar op) (cycle vma temp3 temp4 temp5 temp6 data tag temp9 temp10 temp11 temp12))
(let ((fntest (gensym))
(sk (gensym))
(sk1 (gensym))
(nofntest (gensym))
(ielab (gensym)))
(push
`((label ,fntest)
(CheckDataType ,tag |TypeFixnum| ,ielab ,temp9)
(B ,nofntest))
*function-epilogue*)
`((LWA ,vma 4 (,bar) "Get the vma")
(srdi ,cycle ,op 6 "cycle type")
(ANDI-DOT ,temp4 ,op 4 "=no-incrementp")
;;; we don't care about last-word
(ANDI-DOT ,temp5 ,op 16 "=cdr-code-nextp")
(ANDI-DOT ,temp6 ,op 32 "=fixnum onlyp")
(clrldi ,vma ,vma 32)
(comment "Do the read cycle")
(memory-read ,vma ,tag ,data ,cycle ,temp9 ,temp10 ,temp11 ,temp12 nil t)
(branch-if-nonzero ,temp6 ,fntest "J. if we have to test for fixnump.")
(unlikely-label ,nofntest)
(ADDI ,temp6 ,vma 1 "Compute Incremented address")
(force-alignment)
(CMPI 0 1 ,temp4 0)
(BC 4 2 ,sk "B.NE")
(mov ,vma ,temp6 "Conditionally update address")
(unlikely-label ,sk)
(STW ,vma 4 (,bar) "Store updated vma in BAR")
(ANDI-DOT ,temp4 ,tag #x3F "Compute CDR-NEXT")
(GetNextPC)
(CMPI 0 1 ,temp5 0)
(BC 12 2 ,sk1 "B.EQ")
(mov ,tag ,temp4 "Conditionally Set CDR-NEXT")
(unlikely-label ,sk1)
(GetNextCP)
(stack-push2-with-cdr ,tag ,data)
(ContinueToNextInstruction-NoStall)
(label ,ielab)
(illegal-operand block-read-transport-and-fixnum-type-check ,vma "Not a fixnum"))))
(defmacro i%block-n-write (bar-register bar-vma data temp2 temp3 temp4 temp5 temp6 temp7 temp8 temp9)
(check-temporaries (bar-register bar-vma data) (temp2 temp3 temp4 temp5 temp6 temp7 temp8))
`((srdi ,temp3 ,data 32 "Get tag")
(clrldi ,temp4 ,data 32 "Get data")
(memory-write ,bar-vma ,temp3 ,temp4 PROCESSORSTATE_RAW ,temp9 ,temp5 ,temp6 ,temp7 ,temp8)
(GetNextPCandCP)
(ADDI ,bar-vma ,bar-vma 1 "Increment the address")
;; Can't side-effect the BAR until after the write in case it would trap.
(STW ,bar-vma 4 (,bar-register) "Store updated vma in BAR")
(ContinueToNextInstruction-NoStall)))
(defmacro i%block-n-read-shift (bar op temp temp2 temp3 temp4 temp5 temp6 temp7 temp8 temp9 temp10 temp11 temp12)
(check-temporaries (bar op) (temp temp2 temp3 temp4 temp5 temp6 temp7 temp8 temp9 temp10 temp11 temp12))
(let ((nofntest (gensym))
(noincp (gensym))
(noclrcdr (gensym))
(ielab (gensym)))
`((LWA ,temp2 4 (,bar) "Get the vma")
(srdi ,temp ,op 6 "cycle type")
(ANDI-DOT ,temp4 ,op 4 "=no-incrementp")
;;; we don't care about last-word
(ANDI-DOT ,temp5 ,op 16 "=cdr-code-nextp")
(ANDI-DOT ,temp6 ,op 32 "=fixnum onlyp")
(clrldi ,temp2 ,temp2 32)
(memory-read ,temp2 ,temp8 ,temp7 ,temp ,temp9 ,temp10 ,temp11 ,temp12)
(branch-if-zero ,temp6 ,nofntest "J. if we don't have to test for fixnump.")
(CheckDataType ,temp8 |TypeFixnum| ,ielab ,temp9)
(label ,nofntest)
(branch-if-nonzero ,temp4 ,noincp "J. if we don't have to increment the address.")
(ADDI ,temp2 ,temp2 1 "Increment the address")
(label ,noincp)
(STW ,temp2 4 (,bar) "Store updated vma in BAR")
(branch-if-zero ,temp5 ,noclrcdr "J. if we don't have to clear CDR codes.")
(ANDI-DOT ,temp8 ,temp8 #x3F)
(label ,noclrcdr)
(load-constant ,temp #.(sys:%logdpb
(sys:%alu-function-dpb sys:%alu-byte-background-rotate-latch
sys:%alu-byte-set-rotate-latch)
sys:%%alu-function 0)
"Create a fake ALU control register")
(alu-function-byte ,temp ,temp ,temp7 ,temp7 ,temp2 ,temp3 ,temp4 ,temp5 ,temp6)
(GetNextPCandCP)
(stack-push2-with-cdr ,temp8 ,temp7)
(ContinueToNextInstruction-NoStall)
(label ,ielab)
(illegal-operand block-read-transport-and-fixnum-type-check ,temp2 "Not a fixnum"))))
(defmacro i%block-n-read-alu (bar addr temp temp2 temp3 temp4 temp5 temp6 temp7 temp8 temp9 temp10 temp11 temp12)
(check-temporaries (bar addr) (temp temp2 temp3 temp4 temp5 temp6 temp7 temp8 temp9 temp10 temp11 temp12))
(let ((ielab2 (gensym))
(ielab1 (gensym))
(op1tag temp2)
(op1data temp3)
(op2tag temp4)
(op2data temp5)
(aluop temp6)
(control temp7)
(result temp8))
`((LWA ,temp 4 (,bar) "Get the vma")
(stack-read2 ,addr ,op2tag ,op2data)
(CheckDataType ,op2tag |TypeFixnum| ,ielab2 ,temp9)
(clrldi ,temp ,temp 32)
(memory-read ,temp ,op1tag ,op1data PROCESSORSTATE_DATAREAD ,temp9 ,temp10 ,temp11 ,temp12)
(CheckDataType ,op1tag |TypeFixnum| ,ielab1 ,temp9)
(ADDI ,temp ,temp 1 "Increment the address")
(STW ,temp 4 (,bar) "Store updated vma in BAR")
(LD ,aluop PROCESSORSTATE_ALUOP (ivory))
(stzd PROCESSORSTATE_ALUOVERFLOW (ivory))
(LD ,control PROCESSORSTATE_ALUANDROTATECONTROL (ivory))
(basic-dispatch ,aluop ,temp
(|ALUFunctionBoolean|
(alu-function-boolean ,control ,result ,op1data ,op2data ,temp)
(stack-write-data ,addr ,result)
(ContinueToNextInstruction))
(|ALUFunctionByte|
(alu-function-byte ,control ,op1data ,op2data ,result ,temp ,temp9 ,temp10 ,temp11 ,temp12)
(stack-write-data ,addr ,result)
(ContinueToNextInstruction))
(|ALUFunctionAdder|
(alu-function-adder ,control ,op1data ,op2data ,result ,temp ,temp9 ,temp10 ,temp11)
(stack-write-data ,addr ,result)
(ContinueToNextInstruction))
(|ALUFunctionMultiplyDivide|
(alu-function-multiply-divide ,control ,op1data ,op2data ,result ,temp ,temp9)
(stack-write-data ,addr ,result)
(ContinueToNextInstruction)))
(label ,ielab2)
(SCAtoVMA ,addr ,temp ,temp9)
(illegal-operand block-read-transport-and-fixnum-type-check ,temp "Not a fixnum")
(label ,ielab1)
(illegal-operand block-read-transport-and-fixnum-type-check ,temp "Not a fixnum"))))
(defmacro i%block-n-read-test (bar op vma temp temp2 temp3 temp4 temp5 temp6 temp7 temp8 temp9 temp10 temp11 temp12)
(check-temporaries (bar op) (temp temp2 temp3 temp4 temp5 temp6 temp7 temp8 temp9 temp10 temp11 temp12))
(let ((nofntest (gensym))
(noincp (gensym))
(noclrcdr (gensym))
(ielab1 (gensym))
(ielab2 (gensym))
(taken (gensym))
(op1tag temp2 )
(op1data temp3)
(op2tag temp4)
(op2data temp5)
(aluop temp6)
(control temp7)
(result temp8))
`((LWA ,vma 4 (,bar) "Get the vma")
(srdi ,temp ,op 6 "cycle type")
(stack-read2 iSP ,op2tag ,op2data)
(clrldi ,vma ,vma 32)
(memory-read ,vma ,op1tag ,op1data ,temp ,temp9 ,temp10 ,temp11 ,temp12)
(ANDI-DOT ,temp ,op 32 "=fixnum onlyp")
(branch-if-zero ,temp ,nofntest "J. if we don't have to test for fixnump.")
(CheckDataType ,op1tag |TypeFixnum| ,ielab1 ,temp9)
(CheckDataType ,op2tag |TypeFixnum| ,ielab2 ,temp9)
(label ,nofntest)
(ANDI-DOT ,temp ,op 16 "=cdr-code-nextp")
(branch-if-zero ,temp ,noclrcdr "J. if we don't have to clear CDR codes.")
(TagType ,op1tag ,op1tag)
(label ,noclrcdr)
(LD ,aluop PROCESSORSTATE_ALUOP (ivory))
(stzd PROCESSORSTATE_ALUOVERFLOW (ivory))
(LD ,control PROCESSORSTATE_ALUANDROTATECONTROL (ivory))
(basic-dispatch ,aluop ,temp
(|ALUFunctionBoolean|
(alu-function-boolean ,control ,result ,op1data ,op2data ,temp))
(|ALUFunctionByte|
(alu-function-byte ,control ,op1data ,op2data ,result ,temp ,temp9 ,temp10 ,temp11 ,temp12))
(|ALUFunctionAdder|
(alu-function-adder ,control ,op1data ,op2data ,result ,temp ,temp9 ,temp10 ,temp11))
(|ALUFunctionMultiplyDivide|
(alu-function-multiply-divide ,control ,op1data ,op2data ,result ,temp ,temp9)))
(alu-compute-condition ,control ,op1tag ,op2tag ,result ,temp ,temp9 ,temp10 ,temp11 ,temp12)
(branch-true ,temp ,taken)
(ANDI-DOT ,temp ,op 4 "=no-incrementp")
(branch-if-nonzero ,temp ,noincp "J. if we don't have to increment the address.")
(ADDI ,vma ,vma 1 "Increment the address")
(label ,noincp)
(STW ,vma 4 (,bar) "Store updated vma in BAR")
(ContinueToNextInstruction)
(label ,taken)
(stack-read2-disp iSP -8 ,temp9 ,temp10)
#+++ignore (CheckAdjacentDataTypes ,temp9 |TypeEvenPC| 2 ,except ,temp10)
(sldi ,temp10 ,temp10 1)
(ANDI-DOT iPC ,temp9 1)
(ADD iPC iPC ,temp10)
(B InterpretInstructionForJump)
(label ,ielab2)
(SCAtoVMA iSP ,vma ,temp9)
(illegal-operand block-read-transport-and-fixnum-type-check ,vma "Not a fixnum")
(label ,ielab1)
(illegal-operand block-read-transport-and-fixnum-type-check ,vma "Not a fixnum"))))
;;; Fin.