1 /* inline functions for Z8KSIM
2 Copyright (C) 1992, 1993 Free Software Foundation, Inc.
4 This file is part of Z8KSIM
6 GNU CC is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2, or (at your option)
11 GNU CC is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with Z8KZIM; if not, write to the Free Software
18 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
37 static int is_cond_true
PARAMS((sim_state_type
*context
, int c
));
38 static void makeflags
PARAMS((sim_state_type
*context
, int mask
));
45 return ((si
& 0xff000000) >> 8) | (si
& 0xffff);
51 return ((ptr
& 0xff0000) << 8) | (ptr
& 0xffff);
56 put_long_reg (context
, reg
, val
)
57 sim_state_type
*context
;
61 context
->regs
[reg
].word
= val
>> 16;
62 context
->regs
[reg
+ 1].word
= val
;
67 put_quad_reg (context
, reg
, val1
, val2
)
68 sim_state_type
*context
;
73 context
->regs
[reg
].word
= val2
>> 16;
74 context
->regs
[reg
+ 1].word
= val2
;
75 context
->regs
[reg
+ 2].word
= val1
>> 16;
76 context
->regs
[reg
+ 3].word
= val1
;
81 put_word_reg (context
, reg
, val
)
82 sim_state_type
*context
;
86 context
->regs
[reg
].word
= val
;
90 SItype
get_long_reg (context
, reg
)
91 sim_state_type
*context
;
94 USItype lsw
= context
->regs
[reg
+ 1].word
;
95 USItype msw
= context
->regs
[reg
].word
;
97 return (msw
<< 16) | lsw
;
103 get_quad_reg (context
, reg
)
104 sim_state_type
*context
;
108 USItype lsw
= get_long_reg (context
, reg
+ 2);
109 USItype msw
= get_long_reg (context
, reg
);
119 put_byte_mem_da (context
, addr
, value
)
120 sim_state_type
*context
;
124 ((unsigned char *) (context
->memory
))[addr
] = value
;
129 put_byte_reg (context
, reg
, val
)
130 sim_state_type
*context
;
134 int old
= context
->regs
[reg
& 0x7].word
;
137 old
= old
& 0xff00 | (val
& 0xff);
141 old
= old
& 0x00ff | (val
<< 8);
143 context
->regs
[reg
& 0x7].word
= old
;
148 get_byte_reg (context
, reg
)
149 sim_state_type
*context
;
153 return context
->regs
[reg
& 0x7].word
& 0xff;
155 return (context
->regs
[reg
& 0x7].word
>> 8) & 0xff;
160 put_word_mem_da (context
, addr
, value
)
161 sim_state_type
*context
;
167 context
->exception
= SIM_BAD_ALIGN
;
170 put_byte_mem_da(context
, addr
, value
>>8);
171 put_byte_mem_da(context
, addr
+1, value
);
174 static INLINE
unsigned char
175 get_byte_mem_da (context
, addr
)
176 sim_state_type
*context
;
179 return ((unsigned char *) (context
->memory
))[addr
];
184 #define get_word_mem_da(context,addr)\
185 *((unsigned short*)((char*)((context)->memory)+(addr)))
188 #define get_word_mem_da(context,addr) (get_byte_mem_da(context, addr) << 8) | (get_byte_mem_da(context,addr+1))
191 #define get_word_reg(context,reg) (context)->regs[reg].word
195 get_long_mem_da (context
, addr
)
196 sim_state_type
*context
;
199 USItype lsw
= get_word_mem_da(context
,addr
+2);
200 USItype msw
= get_word_mem_da(context
, addr
);
202 return (msw
<< 16) + lsw
;
207 put_long_mem_da (context
, addr
, value
)
208 sim_state_type
*context
;
212 put_word_mem_da(context
,addr
, value
>>16);
213 put_word_mem_da(context
,addr
+2, value
);
218 get_word_mem_ir (context
, reg
)
219 sim_state_type
*context
;
222 return get_word_mem_da (context
, get_word_reg (context
, reg
));
227 put_word_mem_ir (context
, reg
, value
)
228 sim_state_type
*context
;
233 put_word_mem_da (context
, get_word_reg (context
, reg
), value
);
238 get_byte_mem_ir (context
, reg
)
239 sim_state_type
*context
;
242 return get_byte_mem_da (context
, get_word_reg (context
, reg
));
247 put_byte_mem_ir (context
, reg
, value
)
248 sim_state_type
*context
;
252 put_byte_mem_da (context
, get_word_reg (context
, reg
), value
);
257 get_long_mem_ir (context
, reg
)
258 sim_state_type
*context
;
261 return get_long_mem_da (context
, get_word_reg (context
, reg
));
266 put_long_mem_ir (context
, reg
, value
)
267 sim_state_type
*context
;
272 put_long_mem_da (context
, get_word_reg (context
, reg
), value
);
277 put_long_mem_x (context
, base
, reg
, value
)
278 sim_state_type
*context
;
283 put_long_mem_da (context
, get_word_reg (context
, reg
) + base
, value
);
288 put_word_mem_x (context
, base
, reg
, value
)
289 sim_state_type
*context
;
294 put_word_mem_da (context
, get_word_reg (context
, reg
) + base
, value
);
299 put_byte_mem_x (context
, base
, reg
, value
)
300 sim_state_type
*context
;
305 put_byte_mem_da (context
, get_word_reg (context
, reg
) + base
, value
);
310 get_word_mem_x (context
, base
, reg
)
311 sim_state_type
*context
;
315 return get_word_mem_da (context
, base
+ get_word_reg (context
, reg
));
320 get_byte_mem_x (context
, base
, reg
)
321 sim_state_type
*context
;
325 return get_byte_mem_da (context
, base
+ get_word_reg (context
, reg
));
330 get_long_mem_x (context
, base
, reg
)
331 sim_state_type
*context
;
335 return get_long_mem_da (context
, base
+ get_word_reg (context
, reg
));
341 makeflags (context
, mask
)
342 sim_state_type
*context
;
346 PSW_ZERO
= (context
->dst
& mask
) == 0;
347 PSW_SIGN
= (context
->dst
>> (context
->size
- 1));
349 if (context
->broken_flags
== TST_FLAGS
)
351 extern char the_parity
[];
353 if (context
->size
== 8)
355 PSW_OVERFLOW
= the_parity
[context
->dst
& 0xff];
360 /* Overflow is set if both operands have the same sign and the
361 result is of different sign.
363 V = A==B && R!=B jumping logic
365 V = (A^B)^(R^B) boolean
370 (~(context
->srca
^ context
->srcb
)
371 & (context
->srca
^ context
->dst
))
372 ) >> (context
->size
- 1)
375 if (context
->size
< 32)
377 PSW_CARRY
= ((context
->dst
>> context
->size
)) & 1;
381 /* carry is set when the result is smaller than a source */
384 PSW_CARRY
= (unsigned) context
->dst
> (unsigned) context
->srca
;
388 context
->broken_flags
= 0;
392 /* There are two ways to calculate the flags. We can
393 either always calculate them and so the cc will always
394 be correct, or we can only keep the arguments around and
395 calc the flags when they're actually going to be used. */
397 /* Right now we always calc the flags - I think it may be faster*/
400 #define NORMAL_FLAGS(c,s,d,sa,sb,sub) \
402 normal_flags_8(c,d,sa,sb,sub); \
404 normal_flags_16(c,d,sa,sb,sub); \
406 normal_flags_32(c,d,sa,sb,sub);
410 normal_flags (context
, size
, dst
, srca
, srcb
)
411 sim_state_type
*context
;
417 context
->srca
= srca
;
418 context
->srcb
= srcb
;
420 context
->size
= size
;
421 context
->broken_flags
= CMP_FLAGS
;
426 TEST_NORMAL_FLAGS (context
, size
, dst
)
427 sim_state_type
*context
;
432 context
->size
= size
;
433 context
->broken_flags
= TST_FLAGS
;
438 put_ptr_long_reg (context
, reg
, val
)
439 sim_state_type
*context
;
443 context
->regs
[reg
].word
= (val
>> 8) & 0x7f00;
444 context
->regs
[reg
+ 1].word
= val
;
449 get_ptr_long_reg (context
, reg
)
450 sim_state_type
*context
;
455 val
= (context
->regs
[reg
].word
<< 8) | context
->regs
[reg
+ 1].word
;
461 get_ptr_long_mem_ir (context
, reg
)
462 sim_state_type
*context
;
465 return sitoptr (get_long_mem_da (context
, get_ptr_long_reg (context
, reg
)));
470 get_ptr_long_mem_da (context
, addr
)
471 sim_state_type
*context
;
474 return sitoptr (get_long_mem_da (context
, addr
));
479 put_ptr_long_mem_da (context
, addr
, ptr
)
480 sim_state_type
*context
;
484 put_long_mem_da (context
, addr
, ptrtosi (ptr
));
This page took 0.03965 seconds and 4 git commands to generate.