Commit | Line | Data |
---|---|---|
920dae64 AT |
1 | # ========== Copyright Header Begin ========================================== |
2 | # | |
3 | # OpenSPARC T2 Processor File: SS_Instr.py | |
4 | # Copyright (c) 2006 Sun Microsystems, Inc. All Rights Reserved. | |
5 | # DO NOT ALTER OR REMOVE COPYRIGHT NOTICES. | |
6 | # | |
7 | # The above named program is free software; you can redistribute it and/or | |
8 | # modify it under the terms of the GNU General Public | |
9 | # License version 2 as published by the Free Software Foundation. | |
10 | # | |
11 | # The above named program is distributed in the hope that it will be | |
12 | # useful, but WITHOUT ANY WARRANTY; without even the implied warranty of | |
13 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
14 | # General Public License for more details. | |
15 | # | |
16 | # You should have received a copy of the GNU General Public | |
17 | # License along with this work; if not, write to the Free Software | |
18 | # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. | |
19 | # | |
20 | # ========== Copyright Header End ============================================ | |
21 | ||
22 | import sys | |
23 | from SS_Setup import * | |
24 | ||
25 | setup = setups[sys.argv[1]] | |
26 | ||
27 | ||
28 | #============================================================================ | |
29 | # _if_(cond,then,else) is a workaround for the lack of a conditional | |
30 | # expression syntax ala 'c ? t : e' in Python ... | |
31 | #============================================================================ | |
32 | ||
33 | def _if_(c,t,e): | |
34 | if c: | |
35 | return t | |
36 | else: | |
37 | return e | |
38 | ||
39 | #============================================================================ | |
40 | # class SS_Instr | |
41 | #============================================================================ | |
42 | ||
43 | # We astart at two as the first two are for fetching code from | |
44 | # memory or from io. Code fetches are always big endian | |
45 | ||
46 | exe_idx_s_count = 4 # exe table index | |
47 | idx_mem_s_count = 1 # mem table index | |
48 | ||
49 | class SS_Instr: | |
50 | def __init__(self,name): | |
51 | self.name = name | |
52 | ||
53 | # run_exe_s() is for instructions that have an assembly code execute body | |
54 | def run_exe_s(self,file): | |
55 | pass | |
56 | ||
57 | # run_exe_c() is for instructions that have a c-code execute body | |
58 | def run_exe_c(self,file): | |
59 | pass | |
60 | ||
61 | # run_dec_s() is the assembly code for decoding instructions | |
62 | def run_dec_s(self,file): | |
63 | pass | |
64 | ||
65 | # run_dec_c() is the c code for decoding this instruction | |
66 | def run_dec_c(self,file): | |
67 | pass | |
68 | ||
69 | # run_dec_p() is the decode function name or decode table name | |
70 | def run_dec_p(self): | |
71 | return 'run_dec_%s' % self.name | |
72 | ||
73 | # run_dec_p_count() is the number or time the name should appear in a table | |
74 | # From example the branch opcodes use op2 .. so lower 3 bits of op3 are ... | |
75 | def run_dec_p_count(self): | |
76 | return 1 | |
77 | ||
78 | def exe_idx_s_name(self,file,n): | |
79 | global exe_idx_s_count | |
80 | file.write('#define IDX_'+n.upper()+'\t'+str(exe_idx_s_count)+'\n') | |
81 | exe_idx_s_count += 8 | |
82 | ||
83 | def exe_idx_s(self,file): | |
84 | self.exe_idx_s_name(file,self.name) | |
85 | ||
86 | def gen_exe_tbl(self,file,mode): | |
87 | ''' | |
88 | gen_exe_tbl(), for SS_Instr and all its children, produces entries | |
89 | for various execution tables, e.g. the idx, run, and trc | |
90 | exe_tables. Each entry corresponds to a decoded instruction | |
91 | action -- a function that simulates the instruction's behavior. | |
92 | ||
93 | gen_exe_tbl() writes its output to 'file'. | |
94 | ||
95 | Which kind of entry is controlled by 'mode', which can be either | |
96 | 'idx', 'run', or 'trc', for index, fast (or run) mode, or | |
97 | tracing/ras mode. 'idx' populates the ExeIdx enum, 'run' fills | |
98 | run_exe_table[], and 'trc' fills trc_exe_table[]. gen_exe_tbl() | |
99 | guarantees that the order and size of these tables will all match | |
100 | so that a ExeIdx enum can be used to index either exe table and | |
101 | the corresponding table entries will refer to the same instruction | |
102 | behavior. | |
103 | ||
104 | Note that at each level in the class hierarchy, gen_exe_tbl() | |
105 | produces *all* the table entries for the class' instance. This | |
106 | may involve some list traversal, multiple entry generation, or | |
107 | emitting nothing -- the behavior is ad hoc. | |
108 | ''' | |
109 | file.write(' %s_exe_%s,\n' % (mode,self.name)) | |
110 | ||
111 | def gen_exe_passthrough(self,file,mode): | |
112 | if mode == 'trc': | |
113 | file.write(' trc_exe_passthrough, /* '+self.name+' */\n') | |
114 | elif mode == 'v8_run': | |
115 | file.write(' run_exe_%s,\n' % self.name) | |
116 | else: | |
117 | file.write(' %s_exe_%s,\n' % (mode,self.name)) | |
118 | ||
119 | ||
120 | # The following family of gen_exe_ZZZ() routines generate tracing exe | |
121 | # functions that invoke the correct IRF/FRF RAS routines for the | |
122 | # various source and destination register sets. | |
123 | # | |
124 | # The naming convention for ZZZ is each 'Z' corresponds to: | |
125 | # rd rs1 rs2 | |
126 | # or | |
127 | # desintation, source1, source2 | |
128 | # | |
129 | # This order matches the appearance of the register fields in the | |
130 | # opcodes themselves. | |
131 | # | |
132 | # The legend for 'Z' is as follows: | |
133 | # | |
134 | # r integer register | |
135 | # p (N,N+1) integer register pair | |
136 | # f single precision FP reg | |
137 | # d double precision FP reg | |
138 | # b block FP reg (group of 8) | |
139 | # I either rs2 or an immediate | |
140 | # determined by imm | |
141 | # 0 no register | |
142 | # | |
143 | # The first letter may be captialized. This indicates that rd is used | |
144 | # as a source instead of a destination. | |
145 | ||
146 | def gen_exe_rrI(self,file,mode,imm='',out=''): | |
147 | self.gen_exe_XrI(file,mode,'r',imm,out) | |
148 | ||
149 | def gen_exe_RrI(self,file,mode,imm='',out=''): | |
150 | self.gen_exe_XrI(file,mode,'R',imm,out) | |
151 | ||
152 | def gen_exe_prI(self,file,mode,imm='',out=''): | |
153 | self.gen_exe_XrI(file,mode,'p',imm,out) | |
154 | ||
155 | def gen_exe_PrI(self,file,mode,imm='',out=''): | |
156 | self.gen_exe_XrI(file,mode,'P',imm,out) | |
157 | ||
158 | def gen_exe_frI(self,file,mode,imm='',out=''): | |
159 | self.gen_exe_XrI(file,mode,'f',imm,out) | |
160 | ||
161 | def gen_exe_FrI(self,file,mode,imm='',out=''): | |
162 | self.gen_exe_XrI(file,mode,'F',imm,out) | |
163 | ||
164 | def gen_exe_drI(self,file,mode,imm='',out=''): | |
165 | self.gen_exe_XrI(file,mode,'d',imm,out) | |
166 | ||
167 | def gen_exe_DrI(self,file,mode,imm='',out=''): | |
168 | self.gen_exe_XrI(file,mode,'D',imm,out) | |
169 | ||
170 | def gen_exe_brI(self,file,mode,imm='',out=''): | |
171 | self.gen_exe_XrI(file,mode,'b',imm,out) | |
172 | ||
173 | def gen_exe_BrI(self,file,mode,imm='',out=''): | |
174 | self.gen_exe_XrI(file,mode,'B',imm,out) | |
175 | ||
176 | def gen_exe_0rI(self,file,mode,imm='',out=''): | |
177 | self.gen_exe_XrI(file,mode,'0',imm,out) | |
178 | ||
179 | def gen_exe_XrI(self,file,mode,dest,imm,out): | |
180 | ''' | |
181 | Generate a call to either trc_exe_Xrr() or trc_exe_Xr0() depending on | |
182 | whether self.imm == 'i0'. 'X' is one of '0', 'r', 'p', 'f', or 'd' | |
183 | (or the upper case variants). | |
184 | ''' | |
185 | try: | |
186 | ccr = '_'+self.ccr | |
187 | except AttributeError: | |
188 | ccr = '' | |
189 | ||
190 | if out != '': | |
191 | out = '_'+out | |
192 | ||
193 | if imm == '': | |
194 | imm = self.imm | |
195 | ||
196 | if mode == 'trc': | |
197 | if imm == 'i0': | |
198 | file.write(' trc_exe_'+dest+'rr, /* '+self.opc+ccr+'_'+imm+out+' */\n') | |
199 | else: | |
200 | file.write(' trc_exe_'+dest+'r0, /* '+self.opc+ccr+'_'+imm+out+' */\n') | |
201 | else: | |
202 | file.write(' '+mode+'_exe_'+self.opc+ccr+'_'+imm+out+',\n') | |
203 | ||
204 | ||
205 | def gen_mem_tbl(self,file,mode): | |
206 | if mode == 'idx': | |
207 | if file == None: | |
208 | return 'idx_mem_' + self.name | |
209 | file.write(' %s,\n' % self.gen_mem_tbl(None,'idx')) | |
210 | else: | |
211 | file.write(' mem_%s_b_%s,\n' % (mode,self.name)) | |
212 | file.write(' mem_%s_l_%s,\n' % (mode,self.name)) | |
213 | file.write(' io_%s_b_%s,\n' % (mode,self.name)) | |
214 | file.write(' io_%s_l_%s,\n' % (mode,self.name)) | |
215 | ||
216 | def idx_mem_s(self,file): | |
217 | global idx_mem_s_count | |
218 | file.write('#define %s\t%d\n' % (self.gen_mem_tbl(None,'idx').upper(),idx_mem_s_count)) | |
219 | idx_mem_s_count += 1 | |
220 | ||
221 | def c_code_beg_name(self,file,name): | |
222 | file.write('\n') | |
223 | file.write('extern "C" SS_Vaddr %s( SS_Vaddr pc, SS_Vaddr npc, SS_Strand* s, SS_Instr* i )\n' % name) | |
224 | file.write('{\n') | |
225 | def c_code_beg(self,file,prefix): | |
226 | self.c_code_beg_name(file,prefix + self.name) | |
227 | def c_code_end(self,file): | |
228 | file.write('}\n') | |
229 | ||
230 | def c_code_dec_extern(self,file,name): | |
231 | file.write('\n') | |
232 | file.write('extern "C" SS_Vaddr %s( SS_Vaddr pc, SS_Vaddr npc, SS_Strand* s, SS_Instr* i, uint32_t opc );\n' % name) | |
233 | ||
234 | def c_code_dec_header(self,file,name): | |
235 | file.write('\n') | |
236 | file.write('extern "C" SS_Vaddr %s( SS_Vaddr pc, SS_Vaddr npc, SS_Strand* s, SS_Instr* i, uint32_t opc )\n' % name) | |
237 | file.write('{\n') | |
238 | file.write(' uint32_t idx;\n') | |
239 | file.write(' SS_Opcode o;\n') | |
240 | file.write(' o = opc;\n') | |
241 | def c_code_dec_beg_name(self,file,name): | |
242 | self.c_code_dec_header(file,name) | |
243 | def c_code_dec_beg(self,file,prefix): | |
244 | self.c_code_dec_header(file,prefix + self.name) | |
245 | def c_code_dec_end(self,file): | |
246 | file.write(' return (i->exe)(pc,npc,s,i);\n') | |
247 | self.c_code_end(file) | |
248 | ||
249 | def ill_ibe(self,file,indent=' '): | |
250 | if setup.ill_ibe: | |
251 | file.write(indent+'if (s->inst_breakpoint_hit(opc))\n') | |
252 | file.write(indent+' return (s->trap)(pc,npc,s,i,SS_Trap::INSTRUCTION_BREAKPOINT);\n') | |
253 | ||
254 | def dec_000(self,file,indent,index): | |
255 | self.dec_exe(file,indent,index) | |
256 | self.dec_rd_g0(file,indent) | |
257 | self.dec_tailcall(file,indent) | |
258 | ||
259 | def dec_r00(self,file,indent,index): | |
260 | self.dec_exe(file,indent,index) | |
261 | self.dec_rd_irf(file,indent) | |
262 | self.dec_tailcall(file,indent) | |
263 | ||
264 | def dec_f00(self,file,indent,index): | |
265 | self.dec_exe(file,indent,index) | |
266 | self.dec_rd_frf(file,indent) | |
267 | self.dec_tailcall(file,indent) | |
268 | ||
269 | def dec_d00(self,file,indent,index): | |
270 | self.dec_exe(file,indent,index) | |
271 | self.dec_rd_drf(file,indent) | |
272 | self.dec_tailcall(file,indent) | |
273 | ||
274 | def dec_r022(self,file,indent,index): | |
275 | self.dec_exe(file,indent,index) | |
276 | self.dec_rd_irf(file,indent) | |
277 | self.dec_ea_22(file,indent) | |
278 | self.dec_tailcall(file,indent) | |
279 | ||
280 | def dec_rrr(self,file,indent,index): | |
281 | self.dec_exe(file,indent,index) | |
282 | self.dec_rd_irf(file,indent) | |
283 | self.dec_rs1_irf(file,indent) | |
284 | self.dec_rs2_irf(file,indent) | |
285 | self.dec_tailcall(file,indent) | |
286 | ||
287 | def dec_nrr(self,file,indent,index): | |
288 | self.dec_exe(file,indent,index) | |
289 | self.dec_rd_fun(file,indent) | |
290 | self.dec_rs1_irf(file,indent) | |
291 | self.dec_rs2_irf(file,indent) | |
292 | self.dec_tailcall(file,indent) | |
293 | ||
294 | def dec_nff(self,file,indent,index): | |
295 | self.dec_exe(file,indent,index) | |
296 | self.dec_rd_fun(file,indent) | |
297 | self.dec_rs1_frf(file,indent) | |
298 | self.dec_rs2_frf(file,indent) | |
299 | self.dec_tailcall(file,indent) | |
300 | ||
301 | def dec_dff(self,file,indent,index): | |
302 | self.dec_exe(file,indent,index) | |
303 | self.dec_rd_drf(file,indent) | |
304 | self.dec_rs1_frf(file,indent) | |
305 | self.dec_rs2_frf(file,indent) | |
306 | self.dec_tailcall(file,indent) | |
307 | ||
308 | def dec_0ff(self,file,indent,index): | |
309 | self.dec_exe(file,indent,index) | |
310 | self.dec_rd_g0(file,indent) | |
311 | self.dec_rs1_frf(file,indent) | |
312 | self.dec_rs2_frf(file,indent) | |
313 | self.dec_tailcall(file,indent) | |
314 | ||
315 | def dec_0dd(self,file,indent,index): | |
316 | self.dec_exe(file,indent,index) | |
317 | self.dec_rd_g0(file,indent) | |
318 | self.dec_rs1_drf(file,indent) | |
319 | self.dec_rs2_drf(file,indent) | |
320 | self.dec_tailcall(file,indent) | |
321 | ||
322 | def dec_fff(self,file,indent,index): | |
323 | self.dec_exe(file,indent,index) | |
324 | self.dec_rd_frf(file,indent) | |
325 | self.dec_rs1_frf(file,indent) | |
326 | self.dec_rs2_frf(file,indent) | |
327 | self.dec_tailcall(file,indent) | |
328 | ||
329 | def dec_ndd(self,file,indent,index): | |
330 | self.dec_exe(file,indent,index) | |
331 | self.dec_rd_fun(file,indent) | |
332 | self.dec_rs1_drf(file,indent) | |
333 | self.dec_rs2_drf(file,indent) | |
334 | self.dec_tailcall(file,indent) | |
335 | ||
336 | def dec_rdd(self,file,indent,index): | |
337 | self.dec_exe(file,indent,index) | |
338 | self.dec_rd_irf(file,indent) | |
339 | self.dec_rs1_drf(file,indent) | |
340 | self.dec_rs2_drf(file,indent) | |
341 | self.dec_tailcall(file,indent) | |
342 | ||
343 | def dec_ddd(self,file,indent,index): | |
344 | self.dec_exe(file,indent,index) | |
345 | self.dec_rd_drf(file,indent) | |
346 | self.dec_rs1_drf(file,indent) | |
347 | self.dec_rs2_drf(file,indent) | |
348 | self.dec_tailcall(file,indent) | |
349 | ||
350 | def dec_dfd(self,file,indent,index): | |
351 | self.dec_exe(file,indent,index) | |
352 | self.dec_rd_drf(file,indent) | |
353 | self.dec_rs1_frf(file,indent) | |
354 | self.dec_rs2_drf(file,indent) | |
355 | self.dec_tailcall(file,indent) | |
356 | ||
357 | def dec_r0r(self,file,indent,index): | |
358 | self.dec_exe(file,indent,index) | |
359 | self.dec_rd_irf(file,indent) | |
360 | self.dec_rs2_irf(file,indent) | |
361 | self.dec_tailcall(file,indent) | |
362 | ||
363 | def dec_r0f(self,file,indent,index): | |
364 | self.dec_exe(file,indent,index) | |
365 | self.dec_rd_irf(file,indent) | |
366 | self.dec_rs2_frf(file,indent) | |
367 | self.dec_tailcall(file,indent) | |
368 | ||
369 | def dec_r0d(self,file,indent,index): | |
370 | self.dec_exe(file,indent,index) | |
371 | self.dec_rd_irf(file,indent) | |
372 | self.dec_rs2_drf(file,indent) | |
373 | self.dec_tailcall(file,indent) | |
374 | ||
375 | def dec_f0r(self,file,indent,index): | |
376 | self.dec_exe(file,indent,index) | |
377 | self.dec_rd_frf(file,indent) | |
378 | self.dec_rs2_irf(file,indent) | |
379 | self.dec_tailcall(file,indent) | |
380 | ||
381 | def dec_f0f(self,file,indent,index): | |
382 | self.dec_exe(file,indent,index) | |
383 | self.dec_rd_frf(file,indent) | |
384 | self.dec_rs2_frf(file,indent) | |
385 | self.dec_tailcall(file,indent) | |
386 | ||
387 | def dec_frf(self,file,indent,index): | |
388 | self.dec_exe(file,indent,index) | |
389 | self.dec_rd_frf(file,indent) | |
390 | self.dec_rs1_irf(file,indent) | |
391 | self.dec_rs2_frf(file,indent) | |
392 | self.dec_tailcall(file,indent) | |
393 | ||
394 | def dec_f0d(self,file,indent,index): | |
395 | self.dec_exe(file,indent,index) | |
396 | self.dec_rd_frf(file,indent) | |
397 | self.dec_rs2_drf(file,indent) | |
398 | self.dec_tailcall(file,indent) | |
399 | ||
400 | def dec_d0r(self,file,indent,index): | |
401 | self.dec_exe(file,indent,index) | |
402 | self.dec_rd_drf(file,indent) | |
403 | self.dec_rs2_irf(file,indent) | |
404 | self.dec_tailcall(file,indent) | |
405 | ||
406 | def dec_d0d(self,file,indent,index): | |
407 | self.dec_exe(file,indent,index) | |
408 | self.dec_rd_drf(file,indent) | |
409 | self.dec_rs2_drf(file,indent) | |
410 | self.dec_tailcall(file,indent) | |
411 | ||
412 | def dec_drd(self,file,indent,index): | |
413 | self.dec_exe(file,indent,index) | |
414 | self.dec_rd_drf(file,indent) | |
415 | self.dec_rs1_irf(file,indent) | |
416 | self.dec_rs2_drf(file,indent) | |
417 | self.dec_tailcall(file,indent) | |
418 | ||
419 | def dec_d0f(self,file,indent,index): | |
420 | self.dec_exe(file,indent,index) | |
421 | self.dec_rd_drf(file,indent) | |
422 | self.dec_rs2_frf(file,indent) | |
423 | self.dec_tailcall(file,indent) | |
424 | ||
425 | def dec_ff0(self,file,indent,index): | |
426 | self.dec_exe(file,indent,index) | |
427 | self.dec_rd_frf(file,indent) | |
428 | self.dec_rs1_frf(file,indent) | |
429 | self.dec_tailcall(file,indent) | |
430 | ||
431 | def dec_dd0(self,file,indent,index): | |
432 | self.dec_exe(file,indent,index) | |
433 | self.dec_rd_drf(file,indent) | |
434 | self.dec_rs1_drf(file,indent) | |
435 | self.dec_tailcall(file,indent) | |
436 | ||
437 | def dec_frr(self,file,indent,index): | |
438 | self.dec_exe(file,indent,index) | |
439 | self.dec_rd_frf(file,indent) | |
440 | self.dec_rs1_irf(file,indent) | |
441 | self.dec_rs2_irf(file,indent) | |
442 | self.dec_tailcall(file,indent) | |
443 | ||
444 | def dec_drr(self,file,indent,index): | |
445 | self.dec_exe(file,indent,index) | |
446 | self.dec_rd_drf(file,indent) | |
447 | self.dec_rs1_irf(file,indent) | |
448 | self.dec_rs2_irf(file,indent) | |
449 | self.dec_tailcall(file,indent) | |
450 | ||
451 | def dec_rr5(self,file,indent,index): | |
452 | self.dec_exe(file,indent,index) | |
453 | self.dec_rd_irf(file,indent) | |
454 | self.dec_rs1_irf(file,indent) | |
455 | self.dec_rs2_u5(file,indent) | |
456 | self.dec_tailcall(file,indent) | |
457 | ||
458 | def dec_rr6(self,file,indent,index): | |
459 | self.dec_exe(file,indent,index) | |
460 | self.dec_rd_irf(file,indent) | |
461 | self.dec_rs1_irf(file,indent) | |
462 | self.dec_rs2_u6(file,indent) | |
463 | self.dec_tailcall(file,indent) | |
464 | ||
465 | def dec_rr10(self,file,indent,index): | |
466 | self.dec_exe(file,indent,index) | |
467 | self.dec_rd_irf(file,indent) | |
468 | self.dec_rs1_irf(file,indent) | |
469 | self.dec_rs2_s10(file,indent) | |
470 | self.dec_tailcall(file,indent) | |
471 | ||
472 | def dec_rr11(self,file,indent,index): | |
473 | self.dec_exe(file,indent,index) | |
474 | self.dec_rd_irf(file,indent) | |
475 | self.dec_rs1_irf(file,indent) | |
476 | self.dec_rs2_s11(file,indent) | |
477 | self.dec_tailcall(file,indent) | |
478 | ||
479 | def dec_rr13(self,file,indent,index): | |
480 | self.dec_exe(file,indent,index) | |
481 | self.dec_rd_irf(file,indent) | |
482 | self.dec_rs1_irf(file,indent) | |
483 | self.dec_rs2_s13(file,indent) | |
484 | self.dec_tailcall(file,indent) | |
485 | ||
486 | def dec_nr13(self,file,indent,index): | |
487 | self.dec_exe(file,indent,index) | |
488 | self.dec_rd_fun(file,indent) | |
489 | self.dec_rs1_irf(file,indent) | |
490 | self.dec_rs2_s13(file,indent) | |
491 | self.dec_tailcall(file,indent) | |
492 | ||
493 | def dec_r013(self,file,indent,index): | |
494 | self.dec_exe(file,indent,index) | |
495 | self.dec_rd_irf(file,indent) | |
496 | self.dec_rs2_s13(file,indent) | |
497 | self.dec_tailcall(file,indent) | |
498 | ||
499 | def dec_fr13(self,file,indent,index): | |
500 | self.dec_exe(file,indent,index) | |
501 | self.dec_rd_frf(file,indent) | |
502 | self.dec_rs1_irf(file,indent) | |
503 | self.dec_rs2_s13(file,indent) | |
504 | self.dec_tailcall(file,indent) | |
505 | ||
506 | def dec_dr13(self,file,indent,index): | |
507 | self.dec_exe(file,indent,index) | |
508 | self.dec_rd_drf(file,indent) | |
509 | self.dec_rs1_irf(file,indent) | |
510 | self.dec_rs2_s13(file,indent) | |
511 | self.dec_tailcall(file,indent) | |
512 | ||
513 | def dec_0rr(self,file,indent,index): | |
514 | self.dec_exe(file,indent,index) | |
515 | self.dec_rd_g0(file,indent) | |
516 | self.dec_rs1_irf(file,indent) | |
517 | self.dec_rs2_irf(file,indent) | |
518 | self.dec_tailcall(file,indent) | |
519 | ||
520 | def dec_0r8(self,file,indent,index): | |
521 | self.dec_exe(file,indent,index) | |
522 | self.dec_rd_g0(file,indent) | |
523 | self.dec_rs1_irf(file,indent) | |
524 | self.dec_rs2_u8(file,indent) | |
525 | self.dec_tailcall(file,indent) | |
526 | ||
527 | def dec_0r13(self,file,indent,index): | |
528 | self.dec_exe(file,indent,index) | |
529 | self.dec_rd_g0(file,indent) | |
530 | self.dec_rs1_irf(file,indent) | |
531 | self.dec_rs2_s13(file,indent) | |
532 | self.dec_tailcall(file,indent) | |
533 | ||
534 | def dec_0r16(self,file,indent,index): | |
535 | self.dec_exe(file,indent,index) | |
536 | self.dec_rd_g0(file,indent) | |
537 | self.dec_rs1_irf(file,indent) | |
538 | self.dec_ea_16(file,indent) | |
539 | self.dec_tailcall(file,indent) | |
540 | ||
541 | def dec_00r(self,file,indent,index): | |
542 | self.dec_exe(file,indent,index) | |
543 | self.dec_rd_g0(file,indent) | |
544 | self.dec_rs2_irf(file,indent) | |
545 | self.dec_tailcall(file,indent) | |
546 | ||
547 | def dec_003(self,file,indent,index): | |
548 | self.dec_exe(file,indent,index) | |
549 | self.dec_rd_g0(file,indent) | |
550 | self.dec_rs2_u3(file,indent) | |
551 | self.dec_tailcall(file,indent) | |
552 | ||
553 | def dec_007(self,file,indent,index): | |
554 | self.dec_exe(file,indent,index) | |
555 | self.dec_rd_g0(file,indent) | |
556 | self.dec_rs2_u7(file,indent) | |
557 | self.dec_tailcall(file,indent) | |
558 | ||
559 | def dec_008(self,file,indent,index): | |
560 | self.dec_exe(file,indent,index) | |
561 | self.dec_rd_g0(file,indent) | |
562 | self.dec_rs2_u8(file,indent) | |
563 | self.dec_tailcall(file,indent) | |
564 | ||
565 | def dec_0013(self,file,indent,index): | |
566 | self.dec_exe(file,indent,index) | |
567 | self.dec_rd_g0(file,indent) | |
568 | self.dec_rs2_s13(file,indent) | |
569 | self.dec_tailcall(file,indent) | |
570 | ||
571 | def dec_ffff(self,file,indent,index): | |
572 | self.dec_exe(file,indent,index) | |
573 | self.dec_rd_frf(file,indent) | |
574 | self.dec_rs1_frf(file,indent) | |
575 | self.dec_rs2_frf(file,indent) | |
576 | self.dec_rs3_frf(file,indent) | |
577 | self.dec_tailcall(file,indent) | |
578 | ||
579 | def dec_dddd(self,file,indent,index): | |
580 | self.dec_exe(file,indent,index) | |
581 | self.dec_rd_drf(file,indent) | |
582 | self.dec_rs1_drf(file,indent) | |
583 | self.dec_rs2_drf(file,indent) | |
584 | self.dec_rs3_drf(file,indent) | |
585 | self.dec_tailcall(file,indent) | |
586 | ||
587 | def dec_exe(self,file,indent,index): | |
588 | file.write('%s{\n' % indent) | |
589 | file.write('%s i->exe_tbl_idx = %s;\n' % (indent,index)) | |
590 | file.write('%s i->exe = s->exe_table[i->exe_tbl_idx];\n' % (indent)) | |
591 | def dec_ea_16(self,file,indent): | |
592 | file.write('%s i->rs2 = o.get_imm16();\n' % indent) | |
593 | def dec_ea_22(self,file,indent): | |
594 | file.write('%s (uint32_t&)(i->rs2) = o.get_imm22();\n' % indent) | |
595 | def dec_rs3_frf(self,file,indent): | |
596 | file.write('%s i->rs3 = ptr_ofs(SS_Strand,drf[0]) + o.get_rs3_frf();\n' % indent) | |
597 | def dec_rs3_drf(self,file,indent): | |
598 | file.write('%s i->rs3 = ptr_ofs(SS_Strand,drf[0]) + o.get_rs3_drf();\n' % indent) | |
599 | def dec_rs2_u3(self,file,indent): | |
600 | file.write('%s i->rs2 = o.get_imm3();\n' % indent) | |
601 | def dec_rs2_u5(self,file,indent): | |
602 | file.write('%s i->rs2 = o.get_imm5();\n' % indent) | |
603 | def dec_rs2_u6(self,file,indent): | |
604 | file.write('%s i->rs2 = o.get_imm6();\n' % indent) | |
605 | def dec_rs2_u7(self,file,indent): | |
606 | file.write('%s i->rs2 = o.get_imm7();\n' % indent) | |
607 | def dec_rs2_u8(self,file,indent): | |
608 | file.write('%s i->rs2 = o.get_imm8();\n' % indent) | |
609 | def dec_rs2_s10(self,file,indent): | |
610 | file.write('%s i->rs2 = o.get_simm10();\n' % indent) | |
611 | def dec_rs2_s11(self,file,indent): | |
612 | file.write('%s i->rs2 = o.get_simm11();\n' % indent) | |
613 | def dec_rs2_s13(self,file,indent): | |
614 | file.write('%s i->rs2 = o.get_simm13();\n' % indent) | |
615 | def dec_rs2_irf(self,file,indent): | |
616 | file.write('%s i->rs2 = ptr_ofs(SS_Strand,irf[0]) + o.get_rs2_irf();\n' % indent) | |
617 | def dec_rs2_frf(self,file,indent): | |
618 | file.write('%s i->rs2 = ptr_ofs(SS_Strand,drf[0]) + o.get_rs2_frf();\n' % indent) | |
619 | def dec_rs2_drf(self,file,indent): | |
620 | file.write('%s i->rs2 = ptr_ofs(SS_Strand,drf[0]) + o.get_rs2_drf();\n' % indent) | |
621 | def dec_rs1_irf(self,file,indent): | |
622 | file.write('%s i->rs1 = ptr_ofs(SS_Strand,irf[0]) + o.get_rs1_irf();\n' % indent) | |
623 | def dec_rs1_frf(self,file,indent): | |
624 | file.write('%s i->rs1 = ptr_ofs(SS_Strand,drf[0]) + o.get_rs1_frf();\n' % indent) | |
625 | def dec_rs1_drf(self,file,indent): | |
626 | file.write('%s i->rs1 = ptr_ofs(SS_Strand,drf[0]) + o.get_rs1_drf();\n' % indent) | |
627 | def dec_rd_fun(self,file,indent): | |
628 | file.write('%s i->rd = o.get_rd();\n' % indent) | |
629 | def dec_rd_irf(self,file,indent): | |
630 | file.write('%s i->rd = ptr_ofs(SS_Strand,irf[0]) + o.get_rd_irf();\n' % indent) | |
631 | def dec_rd_g0(self,file,indent): | |
632 | file.write('%s i->rd = 0;\n' % indent) | |
633 | def dec_rd_frf(self,file,indent): | |
634 | file.write('%s i->rd = ptr_ofs(SS_Strand,drf[0]) + o.get_rd_frf();\n' % indent) | |
635 | def dec_rd_drf(self,file,indent): | |
636 | file.write('%s i->rd = ptr_ofs(SS_Strand,drf[0]) + o.get_rd_drf();\n' % indent) | |
637 | def dec_tailcall(self,file,indent): | |
638 | file.write('%s return (i->exe)(pc,npc,s,i);\n' % indent) | |
639 | file.write('%s}\n' % indent) | |
640 | ||
641 | def fail_chkpt(self,file): | |
642 | pass | |
643 | ||
644 | def test_icc(self,file,indent): | |
645 | if (self.cc == 'a'): | |
646 | file.write('%sif (1)\n' % indent) | |
647 | elif (self.cc == 'n'): | |
648 | file.write('%sif (0)\n' % indent) | |
649 | else: | |
650 | if (self.ccr == 'icc'): | |
651 | file.write('%suint8_t cc = s->ccr.icc();\n' % indent) | |
652 | else: | |
653 | file.write('%suint8_t cc = s->ccr.xcc();\n' % indent) | |
654 | if (self.cc == 'e'): | |
655 | file.write('%sif (cc&0x4)\n' % indent) | |
656 | elif (self.cc == 'le'): | |
657 | file.write('%sif ((cc&0x4) || (((cc&0x8)>>3)^((cc&0x2)>>1)))\n' % indent) | |
658 | elif (self.cc == 'l'): | |
659 | file.write('%sif (((cc&0x8)>>3)^((cc&0x2)>>1))\n' % indent) | |
660 | elif (self.cc == 'leu'): | |
661 | file.write('%sif (cc&0x5)\n' % indent) | |
662 | elif (self.cc == 'cs'): | |
663 | file.write('%sif (cc&0x1)\n' % indent) | |
664 | elif (self.cc == 'neg'): | |
665 | file.write('%sif (cc&0x8)\n' % indent) | |
666 | elif (self.cc == 'vs'): | |
667 | file.write('%sif (cc&0x2)\n' % indent) | |
668 | elif (self.cc == 'ne'): | |
669 | file.write('%sif ((cc&0x4)==0)\n' % indent) | |
670 | elif (self.cc == 'g'): | |
671 | file.write('%sif (((cc&0x4) || (((cc&0x8)>>3)^((cc&0x2)>>1)))==0)\n' % indent) | |
672 | elif (self.cc == 'ge'): | |
673 | file.write('%sif ((((cc&0x8)>>3)^((cc&0x2)>>1))==0)\n' % indent) | |
674 | elif (self.cc == 'gu'): | |
675 | file.write('%sif ((cc&0x5)==0)\n' % indent) | |
676 | elif (self.cc == 'cc'): | |
677 | file.write('%sif ((cc&0x1)==0)\n' % indent) | |
678 | elif (self.cc == 'pos'): | |
679 | file.write('%sif ((cc&0x8)==0)\n' % indent) | |
680 | elif (self.cc == 'vc'): | |
681 | file.write('%sif ((cc&0x2)==0)\n' % indent) | |
682 | ||
683 | def test_r(self,file,indent): | |
684 | file.write('%sint64_t rs1 = s->get_irf(i->rs1);\n' % indent) | |
685 | if (self.cc == 'z'): | |
686 | file.write('%sif (rs1 == 0)\n' % indent) | |
687 | elif (self.cc == 'lez'): | |
688 | file.write('%sif (rs1 <= 0)\n' % indent) | |
689 | elif (self.cc == 'lz'): | |
690 | file.write('%sif (rs1 < 0)\n' % indent) | |
691 | elif (self.cc == 'nz'): | |
692 | file.write('%sif (rs1 != 0)\n' % indent) | |
693 | elif (self.cc == 'gz'): | |
694 | file.write('%sif (rs1 > 0)\n' % indent) | |
695 | elif (self.cc == 'gez'): | |
696 | file.write('%sif (rs1 >= 0)\n' % indent) | |
697 | ||
698 | def test_fcc(self,file,indent): | |
699 | if (self.cc == 'a'): | |
700 | file.write('%sif (1)\n' % indent) | |
701 | elif (self.cc == 'n'): | |
702 | file.write('%sif (0)\n' % indent) | |
703 | else: | |
704 | file.write(('%suint64_t cc = s->fsr_run.' % indent)+self.ccr+'();\n') | |
705 | if (self.cc == 'ne'): | |
706 | file.write('%sif (cc!=0)\n' % indent) | |
707 | elif (self.cc == 'lg'): | |
708 | file.write('%sif ((cc==1) || (cc==2))\n' % indent) | |
709 | elif (self.cc == 'ul'): | |
710 | file.write('%sif ((cc==1) || (cc==3))\n' % indent) | |
711 | elif (self.cc == 'l'): | |
712 | file.write('%sif (cc==1)\n' % indent) | |
713 | elif (self.cc == 'ug'): | |
714 | file.write('%sif ((cc==2) || (cc==3))\n' % indent) | |
715 | elif (self.cc == 'g'): | |
716 | file.write('%sif (cc==2)\n' % indent) | |
717 | elif (self.cc == 'u'): | |
718 | file.write('%sif (cc==3)\n' % indent) | |
719 | elif (self.cc == 'e'): | |
720 | file.write('%sif (cc==0)\n' % indent) | |
721 | elif (self.cc == 'ue'): | |
722 | file.write('%sif ((cc==0) || (cc==3))\n' % indent) | |
723 | elif (self.cc == 'ge'): | |
724 | file.write('%sif ((cc==0) || (cc==2))\n' % indent) | |
725 | elif (self.cc == 'uge'): | |
726 | file.write('%sif (cc!=1)\n' % indent) | |
727 | elif (self.cc == 'le'): | |
728 | file.write('%sif ((cc==0) || (cc==1))\n' % indent) | |
729 | elif (self.cc == 'ule'): | |
730 | file.write('%sif (cc!=2)\n' % indent) | |
731 | elif (self.cc == 'o'): | |
732 | file.write('%sif (cc!=3)\n' % indent) | |
733 | ||
734 | ||
735 | #============================================================================ | |
736 | # class SS_InstrCpp | |
737 | #============================================================================ | |
738 | ||
739 | class SS_InstrCpp(SS_Instr): | |
740 | def __init__(self,name): | |
741 | SS_Instr.__init__(self,name) | |
742 | ||
743 | ||
744 | #============================================================================ | |
745 | # class SS_InstrAsm | |
746 | #============================================================================ | |
747 | ||
748 | class SS_InstrAsm(SS_Instr): | |
749 | def __init__(self,name): | |
750 | SS_Instr.__init__(self,name) | |
751 | ||
752 | def run_exe_c(self,file,product="run"): | |
753 | file.write('extern "C" SS_Vaddr %s_exe_%s( SS_Vaddr, SS_Vaddr, SS_Strand*, SS_Instr* );\n' % (product,self.name)) | |
754 | ||
755 | def s_code(self,file,prefix): | |
756 | name = prefix + self.name | |
757 | file.write('\n') | |
758 | file.write('.align 8\n') | |
759 | file.write('.global %s\n' % name) | |
760 | file.write('.type %s, #function\n' % name) | |
761 | file.write('%s:\n' % name) | |
762 | ||
763 | def asm_function(self,file,name): | |
764 | file.write('\n') | |
765 | file.write('.align 8\n') | |
766 | file.write('.global %s\n' % name) | |
767 | file.write('.type %s, #function\n' % name) | |
768 | file.write('%s:\n' % name) | |
769 | ||
770 | def asm_codesize(self,file,name): | |
771 | file.write('.size '+name+',(.-'+name+')\n') | |
772 | ||
773 | PC = '%o0' | |
774 | NPC = '%o1' | |
775 | S_PTR = '%o2' | |
776 | I_PTR = '%o3' | |
777 | TT = '%o4' # for call to (s->trap)(pc,npc,s,i,tt) | |
778 | ||
779 | def ld_rs1(self,file,rd): | |
780 | file.write('\tlduh\t[%s + I_RS1],%s\n' % (self.I_PTR,rd)) | |
781 | def ld_rs2(self,file,rd): | |
782 | file.write('\tlduh\t[%s + I_RS2],%s\n' % (self.I_PTR,rd)) | |
783 | def ld_rs2_32(self,file,rd): | |
784 | file.write('\tlduw\t[%s + I_RS2],%s\n' % (self.I_PTR,rd)) | |
785 | def ld_imm(self,file,rd): | |
786 | file.write('\tldsh\t[%s + I_RS2],%s\n' % (self.I_PTR,rd)) | |
787 | def ld_rs3(self,file,rd): | |
788 | file.write('\tlduh\t[%s + I_RS3],%s\n' % (self.I_PTR,rd)) | |
789 | def ld_rd(self,file,rd): | |
790 | file.write('\tlduh\t[%s + I_RD],%s\n' % (self.I_PTR,rd)) | |
791 | def ld_ea_rd(self,file,rd): | |
792 | file.write('\tldx\t[%s + I_RD],%s\n' % (self.I_PTR,rd)) | |
793 | def ld_tte(self,file,rd): | |
794 | file.write('\tldx\t[%s + I_TTE],%s\n' % (self.I_PTR,rd)) | |
795 | ||
796 | def ld_irf(self,file,rs2,rd): | |
797 | file.write('\tldx\t[%s + %s],%s\n' % (self.S_PTR,rs2,rd)) | |
798 | def st_irf(self,file,rs2,rd): | |
799 | file.write('\tstx\t%s,[%s + %s]\n' % (rd,self.S_PTR,rs2)) | |
800 | def st_o7(self,file,rd): | |
801 | file.write('\tstx\t%s,[%s + S_O7]\n' % (rd,self.S_PTR)) | |
802 | ||
803 | def lduw_frf(self,file,rs2,rd): | |
804 | file.write('\tldsw\t[%s + %s],%s\n' % (self.S_PTR,rs2,rd)) | |
805 | def lduw_frf(self,file,rs2,rd): | |
806 | file.write('\tlduw\t[%s + %s],%s\n' % (self.S_PTR,rs2,rd)) | |
807 | def stw_frf(self,file,rs2,rd): | |
808 | file.write('\tstw\t%s,[%s + %s]\n' % (rd,self.S_PTR,rs2)) | |
809 | ||
810 | def ld_frf(self,file,rs2,rd): | |
811 | file.write('\tld\t[%s + %s],%s\n' % (self.S_PTR,rs2,rd)) | |
812 | def st_frf(self,file,rs2,rd): | |
813 | file.write('\tst\t%s,[%s + %s]\n' % (rd,self.S_PTR,rs2)) | |
814 | ||
815 | def ldx_drf(self,file,rs2,rd): | |
816 | file.write('\tldx\t[%s + %s],%s\n' % (self.S_PTR,rs2,rd)) | |
817 | def stx_drf(self,file,rs2,rd): | |
818 | file.write('\tstx\t%s,[%s + %s]\n' % (rd,self.S_PTR,rs2)) | |
819 | ||
820 | def ld_drf(self,file,rs2,rd): | |
821 | file.write('\tldd\t[%s + %s],%s\n' % (self.S_PTR,rs2,rd)) | |
822 | def st_drf(self,file,rs2,rd): | |
823 | file.write('\tstd\t%s,[%s + %s]\n' % (rd,self.S_PTR,rs2)) | |
824 | ||
825 | def ld_npc(self,file,rd): | |
826 | file.write('\tldx\t[%s + S_NPC],%s\n' % (self.S_PTR,rd)) | |
827 | def st_npc(self,file,rd): | |
828 | file.write('\tstx\t%s,[%s + S_NPC]\n' % (rd,self.S_PTR)) | |
829 | ||
830 | def ld_sim(self,file,rd): | |
831 | file.write('\tldx\t[%s + S_SIM_STATE],%s\n' % (self.S_PTR,rd)) | |
832 | def ld_pstate(self,file,rd): | |
833 | file.write('\tldub\t[%s + S_PSTATE],%s\n' % (self.S_PTR,rd)) | |
834 | def ld_mask_pstate_am(self,file,rd): | |
835 | file.write('\tldx\t[%s + S_MASK_PSTATE_AM],%s\n' % (self.S_PTR,rd)) | |
836 | ||
837 | def ld_fsr_cpu(self,file,rd): | |
838 | file.write('\tldx\t[%s + S_FSR_CPU],%s\n' % (self.S_PTR,rd)) | |
839 | def st_fsr_cpu(self,file,rd): | |
840 | file.write('\tstx\t%s,[%s + S_FSR_CPU]\n' % (rd,self.S_PTR)) | |
841 | def ld_fsr_run(self,file,rd): | |
842 | file.write('\tldx\t[%s + S_FSR_RUN],%s\n' % (self.S_PTR,rd)) | |
843 | def st_fsr_run(self,file,rd): | |
844 | file.write('\tstx\t%s,[%s + S_FSR_RUN]\n' % (rd,self.S_PTR)) | |
845 | def ld_fsr(self,file,rd): | |
846 | file.write('\tldx\t[%s + S_FSR],%s\n' % (self.S_PTR,rd)) | |
847 | def st_fsr(self,file,rd): | |
848 | file.write('\tstx\t%s,[%s + S_FSR]\n' % (rd,self.S_PTR)) | |
849 | ||
850 | def ld_gsr(self,file,rd): | |
851 | file.write('\tldx\t[%s + S_GSR],%s\n' % (self.S_PTR,rd)) | |
852 | def st_gsr(self,file,rd): | |
853 | file.write('\tstx\t%s,[%s + S_GSR]\n' % (rd,self.S_PTR)) | |
854 | def rd_gsr(self,file,rd): | |
855 | file.write('\trd\t%%gsr,%s\n' % rd) | |
856 | def wr_gsr(self,file,rd): | |
857 | file.write('\twr\t%s,%%gsr\n' % rd) | |
858 | ||
859 | def ld_ccr(self,file,rd): | |
860 | file.write('\tldub\t[%s + S_CCR],%s\n' % (self.S_PTR,rd)) | |
861 | def st_ccr(self,file,rd): | |
862 | file.write('\tstb\t%s,[%s + S_CCR]\n' % (rd,self.S_PTR)) | |
863 | def rd_ccr(self,file,rd): | |
864 | file.write('\trd\t%%ccr,%s\n' % rd) | |
865 | def wr_ccr(self,file,rd): | |
866 | file.write('\twr\t%s,%%ccr\n' % rd) | |
867 | ||
868 | def ld_y(self,file,rd): | |
869 | file.write('\tlduw\t[%s + S_Y],%s\n' % (self.S_PTR,rd)) | |
870 | def st_y(self,file,rd): | |
871 | file.write('\tstw\t%s,[%s + S_Y]\n' % (rd,self.S_PTR)) | |
872 | def rd_y(self,file,rd): | |
873 | file.write('\trd\t%%y,%s\n' % rd) | |
874 | def wr_y(self,file,rd): | |
875 | file.write('\twr\t%s,%%y\n' % rd) | |
876 | ||
877 | def ld_trap(self,file,rd): | |
878 | file.write('\tldptr\t[%s + TRAP],%s\n' % (self.S_PTR,rd)) | |
879 | ||
880 | def ld_inst_trap(self,file,rd): | |
881 | file.write('\tldptr\t[%s + INST_TRAP],%s\n' % (self.S_PTR,rd)) | |
882 | ||
883 | def ldx(self,file,rs1,rs2,rd): | |
884 | file.write('\tldx\t[%s + %s],%s\n' % (rs1,rs2,rd)) | |
885 | def stx(self,file,rs1,rs2,rd): | |
886 | file.write('\tstx\t%s,[%s + %s]\n' % (rd,rs1,rs2)) | |
887 | ||
888 | def mov(self,file,rs2,rd): | |
889 | self.opr(file,'or','%g0',rs2,rd) | |
890 | ||
891 | def opr(self,file,opc,rs1,rs2,rd): | |
892 | file.write('\t%s\t%s,%s,%s\n' % (opc,rs1,rs2,rd)) | |
893 | def op2(self,file,opc,rs2,rd): | |
894 | file.write('\t%s\t%s,%s\n' % (opc,rs2,rd)) | |
895 | def op1(self,file,opc,rd): | |
896 | file.write('\t%s\t%s\n' % (opc,rd)) | |
897 | ||
898 | def sra(self,file,rs1,rs2,rd): | |
899 | self.opr(file,'sra',rs1,rs2,rd) | |
900 | def add(self,file,rs1,rs2,rd): | |
901 | self.opr(file,'add',rs1,rs2,rd) | |
902 | def andcc(self,file,rs1,rs2,rd): | |
903 | self.opr(file,'andcc',rs1,rs2,rd) | |
904 | ||
905 | def movcc(self,file,cc,ccr,rs2,rd): | |
906 | file.write('\tmov%s\t%s,%s,%s\n' % (cc,ccr,rs2,rd)) | |
907 | def movr(self,file,cc,rs1,rs2,rd): | |
908 | file.write('\tmovr%s\t%s,%s,%s\n' % (cc,rs1,rs2,rd)) | |
909 | ||
910 | def nop(self,file): | |
911 | file.write('\tnop\n') | |
912 | ||
913 | def branch(self,file,cc,ccr,label): | |
914 | if ccr[1:4] == 'fcc': | |
915 | file.write('\tfb%s\t%s,%s\n' % (cc,ccr,label)) | |
916 | else: | |
917 | file.write('\tb%s\t%s,%s\n' % (cc,ccr,label)) | |
918 | ||
919 | def jmpl(self,file,rs1,rs2,rd): | |
920 | file.write('\tjmpl\t'+rs1+'+'+rs2+','+rd+'\n') | |
921 | ||
922 | def retl(self,file): | |
923 | file.write('#ifdef ARCH_V8\n') | |
924 | file.write('\tsrl\t%o0,0,%o1\n') | |
925 | file.write('\tsrlx\t%o0,32,%o0\n') | |
926 | file.write('#endif\n') | |
927 | file.write('\tretl\n') | |
928 | ||
929 | # retl_st_npc is a store of rd to s->npc and a return. | |
930 | # The reason for a merge sequence is the difference | |
931 | # between v8 and v9 mode. | |
932 | ||
933 | def retl_st_npc(self,file,rd): | |
934 | file.write('#ifdef ARCH_V8\n') | |
935 | file.write('\tstx\t%s,[%s + S_NPC]\n' % (rd,self.S_PTR)) | |
936 | file.write('\tsrl\t%o0,0,%o1\n') | |
937 | file.write('\tretl\n') | |
938 | file.write('\tsrlx\t%o0,32,%o0\n') | |
939 | file.write('#else\n') | |
940 | file.write('\tretl\n') | |
941 | file.write('\tstx\t%s,[%s + S_NPC]\n' % (rd,self.S_PTR)) | |
942 | file.write('#endif\n') | |
943 | ||
944 | #============================================================================ | |
945 | # class SS_InstrGroup | |
946 | #============================================================================ | |
947 | ||
948 | class SS_InstrGroup(SS_Instr): | |
949 | def __init__(self,name,opc_sft,opc_msk,repeat=1): | |
950 | SS_Instr.__init__(self,name) | |
951 | self.name = name | |
952 | self.opc_sft = opc_sft | |
953 | self.opc_msk = opc_msk | |
954 | self.list = [] | |
955 | self.repeat = repeat | |
956 | ||
957 | def append(self,i): | |
958 | self.list.append(i) | |
959 | ||
960 | def extend(self,l): | |
961 | self.list.extend(l) | |
962 | ||
963 | def run_exe_s(self,file): | |
964 | for i in self.list: | |
965 | i.run_exe_s(file) | |
966 | ||
967 | def run_exe_c(self,file): | |
968 | for i in self.list: | |
969 | i.run_exe_c(file) | |
970 | ||
971 | def run_dec_s(self,file): | |
972 | for i in self.list: | |
973 | i.run_dec_s(file) | |
974 | ||
975 | def run_dec_c(self,file): | |
976 | for i in self.list: | |
977 | i.run_dec_c(file) | |
978 | ||
979 | file.write('\nSS_DecodeGroup<%d> run_dec_%s = \n' % (len(self.list),self.name)) | |
980 | file.write('{\n') | |
981 | file.write(' ptr_sft(%d), ptr_msk(%d),\n' % (self.opc_sft,self.opc_msk)) | |
982 | o = 0 | |
983 | for i in self.list: | |
984 | s = i.run_dec_p() | |
985 | if s != '': | |
986 | for x in range(0,i.run_dec_p_count()): | |
987 | if o == 0: | |
988 | file.write(' { /* %2x */ %s\n' % (o,s)) | |
989 | else: | |
990 | file.write(' , /* %2x */ %s\n' % (o,s)) | |
991 | o = o + 1 | |
992 | file.write(' }\n') | |
993 | file.write('};\n') | |
994 | ||
995 | def run_dec_p(self): | |
996 | return 'ss_dec_tbl(run_dec_%s)' % self.name | |
997 | ||
998 | def run_dec_p_count(self): | |
999 | return self.repeat | |
1000 | ||
1001 | def gen_exe_tbl(self,file,mode): | |
1002 | for i in self.list: | |
1003 | i.gen_exe_tbl(file,mode) | |
1004 | ||
1005 | def exe_idx_s(self,file): | |
1006 | for i in self.list: | |
1007 | i.exe_idx_s(file) | |
1008 | ||
1009 | ||
1010 | ||
1011 | #============================================================================ | |
1012 | # class SS_InstrTable | |
1013 | #============================================================================ | |
1014 | ||
1015 | class SS_InstrTable(SS_InstrGroup): | |
1016 | def __init__(self,setup,name): | |
1017 | SS_InstrGroup.__init__(self,name,0,0,1) | |
1018 | ||
1019 | def run_dec_c(self,file): | |
1020 | for i in self.list: | |
1021 | i.run_dec_c(file) | |
1022 | ||
1023 | file.write('\nSS_DecodeTable '+setup.product+'_Strand::run_dec_%s = \n' % self.name) | |
1024 | file.write('{\n') | |
1025 | o = 0 | |
1026 | for i in self.list: | |
1027 | s = i.run_dec_p() | |
1028 | if s != '': | |
1029 | for x in range(0,i.run_dec_p_count()): | |
1030 | if o == 0: | |
1031 | file.write(' { /* %2x */ %s\n' % (o,s)) | |
1032 | else: | |
1033 | file.write(' , /* %2x */ %s\n' % (o,s)) | |
1034 | o = o + 1 | |
1035 | file.write(' }\n') | |
1036 | file.write('};\n') | |
1037 | ||
1038 | #============================================================================ | |
1039 | # SS_ill() - a place holder for decoded as illegal instruction trap | |
1040 | #============================================================================ | |
1041 | ||
1042 | class SS_ill(SS_InstrCpp): | |
1043 | def __init__(self): | |
1044 | SS_InstrCpp.__init__(self,'ill') | |
1045 | ||
1046 | def exe_idx_s(self,file): | |
1047 | pass | |
1048 | ||
1049 | def gen_exe_tbl(self,file,mode): | |
1050 | pass | |
1051 | ||
1052 | def run_dec_p(self): | |
1053 | return 'run_dec_illtrap' | |
1054 | ||
1055 | #============================================================================ | |
1056 | # condition codes | |
1057 | #============================================================================ | |
1058 | ||
1059 | cond=[ | |
1060 | ('n' , 0), | |
1061 | ('e' , 1), | |
1062 | ('le' , 2), | |
1063 | ('l' , 3), | |
1064 | ('leu', 4), | |
1065 | ('cs' , 5), | |
1066 | ('neg', 6), | |
1067 | ('vs' , 7), | |
1068 | ('a' , 8), | |
1069 | ('ne' , 9), | |
1070 | ('g' , 10), | |
1071 | ('ge' , 11), | |
1072 | ('gu' , 12), | |
1073 | ('cc' , 13), | |
1074 | ('pos', 14), | |
1075 | ('vc' , 15) | |
1076 | ] | |
1077 | ||
1078 | inv_rcond = { | |
1079 | 'z' :'nz', | |
1080 | 'lez':'gz', | |
1081 | 'lz' :'gez', | |
1082 | 'nz' :'z', | |
1083 | 'gz' :'lez', | |
1084 | 'gez':'lz' | |
1085 | } | |
1086 | ||
1087 | rcond = [ | |
1088 | ('' , 0), | |
1089 | ('z' , 1), | |
1090 | ('lez', 2), | |
1091 | ('lz' , 3), | |
1092 | ('' , 4), | |
1093 | ('nz' , 5), | |
1094 | ('gz' , 6), | |
1095 | ('gez', 7), | |
1096 | ('' , 8), | |
1097 | ('' , 9), | |
1098 | ('' , 10), | |
1099 | ('' , 11), | |
1100 | ('' , 12), | |
1101 | ('' , 13), | |
1102 | ('' , 14), | |
1103 | ('' , 15) | |
1104 | ] | |
1105 | ||
1106 | rcond8 = [ | |
1107 | ('' , 0), | |
1108 | ('z' , 1), | |
1109 | ('lez', 2), | |
1110 | ('lz' , 3), | |
1111 | ('' , 4), | |
1112 | ('nz' , 5), | |
1113 | ('gz' , 6), | |
1114 | ('gez', 7) | |
1115 | ] | |
1116 | ||
1117 | fcond = [ | |
1118 | ('n' , 0), | |
1119 | ('ne' , 1), | |
1120 | ('lg' , 2), | |
1121 | ('ul' , 3), | |
1122 | ('l' , 4), | |
1123 | ('ug' , 5), | |
1124 | ('g' , 6), | |
1125 | ('u' , 7), | |
1126 | ('a' , 8), | |
1127 | ('e' , 9), | |
1128 | ('ue' , 10), | |
1129 | ('ge' , 11), | |
1130 | ('uge', 12), | |
1131 | ('le' , 13), | |
1132 | ('ule', 14), | |
1133 | ('o' , 15) | |
1134 | ] |