home *** CD-ROM | disk | FTP | other *** search
/ Fresh Fish 9 / FreshFishVol9-CD2.bin / bbs / gnu / gdb-4.14-src.lha / gdb-4.14 / sim / z8k / inlines.h < prev    next >
Encoding:
C/C++ Source or Header  |  1994-12-29  |  9.4 KB  |  486 lines

  1. /* inline functions for Z8KSIM
  2.    Copyright (C) 1992, 1993 Free Software Foundation, Inc.
  3.  
  4. This file is part of Z8KSIM
  5.  
  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)
  9. any later version.
  10.  
  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.
  15.  
  16. You should have received a copy of the GNU General Public License
  17. along with GNU CC; see the file COPYING.  If not, write to
  18. the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.  */
  19.  
  20. #ifndef INLINE
  21. #define INLINE
  22. #endif
  23. #define UGT 0x0b
  24. #define ULE 0x03
  25. #define ULT 0x07
  26. #define UGE 0x0f
  27. #define SLOW 0
  28. #define T 0x8
  29. #define F 0x0
  30. #define LT 0x1
  31. #define GT 0xa
  32. #define LE 0x2
  33. #define EQ 0x6
  34. #define NE 0xe
  35. #define GE 0x9
  36.  
  37.  static int is_cond_true PARAMS((sim_state_type *context, int c)); 
  38.  static void makeflags PARAMS((sim_state_type *context, int mask)); 
  39.  
  40. static INLINE
  41. long
  42. sitoptr (si)
  43. long si;
  44. {
  45.   return ((si & 0xff000000) >> 8) | (si & 0xffff);
  46. }
  47. static INLINE long
  48. ptrtosi (ptr)
  49. long ptr;
  50. {
  51.   return ((ptr & 0xff0000) << 8) | (ptr & 0xffff);
  52. }
  53.  
  54. static INLINE
  55. void 
  56. put_long_reg (context, reg, val)
  57.      sim_state_type *context;
  58.      int reg;
  59.      int val;
  60. {
  61.   context->regs[reg].word = val >> 16;
  62.   context->regs[reg + 1].word = val;
  63. }
  64.  
  65. static INLINE
  66. void 
  67. put_quad_reg (context, reg, val1, val2)
  68.      sim_state_type *context;
  69.      int reg;
  70.      int val1;
  71.      int val2;
  72. {
  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;
  77. }
  78.  
  79. static INLINE
  80. void 
  81. put_word_reg (context, reg, val)
  82.      sim_state_type *context;
  83.      int reg;
  84.      int val;
  85. {
  86.   context->regs[reg].word = val;
  87. }
  88.  
  89. static INLINE
  90. SItype get_long_reg (context, reg)
  91.      sim_state_type *context;
  92.      int reg;
  93. {
  94.   USItype lsw = context->regs[reg + 1].word;
  95.   USItype msw = context->regs[reg].word;
  96.  
  97.   return (msw << 16) | lsw;
  98. }
  99.  
  100. #ifdef __GNUC__
  101. static INLINE
  102. struct UDIstruct
  103. get_quad_reg (context, reg)
  104.      sim_state_type *context;
  105.      int reg;
  106. {
  107.   UDItype res;
  108.   USItype lsw = get_long_reg (context, reg + 2);
  109.   USItype msw = get_long_reg (context, reg);
  110.  
  111.   res.low = lsw;
  112.   res.high = msw;
  113.   return res;
  114. }
  115.  
  116. #endif
  117.  
  118. static INLINE
  119. void 
  120. put_byte_reg (context, reg, val)
  121.      sim_state_type *context;
  122.      int reg;
  123.      int val;
  124. {
  125.   int old = context->regs[reg & 0x7].word;
  126.   if (reg & 0x8)
  127.     {
  128.       old = old & 0xff00 | (val & 0xff);
  129.     }
  130.   else
  131.     {
  132.       old = old & 0x00ff | (val << 8);
  133.     }
  134.   context->regs[reg & 0x7].word = old;      
  135. }
  136.  
  137. static INLINE
  138. int 
  139. get_byte_reg (context, reg)
  140.      sim_state_type *context;
  141.      int reg;
  142. {
  143.   if (reg & 0x8)
  144.     return  context->regs[reg & 0x7].word & 0xff;
  145.   else
  146.     return  (context->regs[reg & 0x7].word >> 8) & 0xff;
  147. }
  148.  
  149. static INLINE
  150. void 
  151. put_word_mem_da (context, addr, value)
  152.      sim_state_type *context;
  153.      int addr;
  154.      int value;
  155. {
  156.   if (addr & 1)
  157.     {
  158.       context->exception = SIM_BAD_ALIGN;
  159.       addr &= ~1;
  160.     }
  161.   put_byte_mem_da(context, addr, value>>8);
  162.   put_byte_mem_da(context, addr+1, value);
  163. }
  164.  
  165. static INLINE unsigned char
  166. get_byte_mem_da (context, addr)
  167.      sim_state_type *context;
  168.      int addr;
  169. {
  170.   return ((unsigned char *) (context->memory))[addr];
  171. }
  172.  
  173. static INLINE void
  174. put_byte_mem_da (context, addr, value)
  175.      sim_state_type *context;
  176.      int addr;
  177.      int value;
  178. {
  179.   ((unsigned char *) (context->memory))[addr] = value;
  180. }
  181.  
  182. #if 0
  183. #define get_word_mem_da(context,addr)\
  184.  *((unsigned short*)((char*)((context)->memory)+(addr)))
  185.  
  186. #else
  187. #define get_word_mem_da(context,addr) (get_byte_mem_da(context, addr) << 8) | (get_byte_mem_da(context,addr+1))
  188. #endif
  189.  
  190. #define get_word_reg(context,reg) (context)->regs[reg].word
  191.  
  192. static INLINE
  193. SItype
  194. get_long_mem_da (context, addr)
  195.      sim_state_type *context;
  196.      int addr;
  197. {
  198.   USItype lsw = get_word_mem_da(context,addr+2);
  199.   USItype msw =  get_word_mem_da(context, addr);
  200.  
  201.   return (msw << 16) + lsw;
  202. }
  203.  
  204. static INLINE
  205. void 
  206. put_long_mem_da (context, addr, value)
  207.      sim_state_type *context;
  208.      int addr;
  209.      int value;
  210. {
  211.   put_word_mem_da(context,addr, value>>16);
  212.   put_word_mem_da(context,addr+2, value);
  213. }
  214.  
  215. static INLINE
  216. int 
  217. get_word_mem_ir (context, reg)
  218.      sim_state_type *context;
  219.      int reg;
  220. {
  221.   return get_word_mem_da (context, get_word_reg (context, reg));
  222. }
  223.  
  224. static INLINE
  225. void 
  226. put_word_mem_ir (context, reg, value)
  227.      sim_state_type *context;
  228.      int reg;
  229.      int value;
  230. {
  231.  
  232.   put_word_mem_da (context, get_word_reg (context, reg), value);
  233. }
  234.  
  235. static INLINE
  236. int 
  237. get_byte_mem_ir (context, reg)
  238.      sim_state_type *context;
  239.      int reg;
  240. {
  241.   return get_byte_mem_da (context, get_word_reg (context, reg));
  242. }
  243.  
  244. static INLINE
  245. void 
  246. put_byte_mem_ir (context, reg, value)
  247.      sim_state_type *context;
  248.      int reg;
  249.      int value;
  250. {
  251.   put_byte_mem_da (context, get_word_reg (context, reg), value);
  252. }
  253.  
  254. static INLINE
  255. int 
  256. get_long_mem_ir (context, reg)
  257.      sim_state_type *context;
  258.      int reg;
  259. {
  260.   return get_long_mem_da (context, get_word_reg (context, reg));
  261. }
  262.  
  263. static INLINE
  264. void 
  265. put_long_mem_ir (context, reg, value)
  266.      sim_state_type *context;
  267.      int reg;
  268.      int value;
  269. {
  270.  
  271.   put_long_mem_da (context, get_word_reg (context, reg), value);
  272. }
  273.  
  274. static INLINE
  275. void 
  276. put_long_mem_x (context, base, reg, value)
  277.      sim_state_type *context;
  278.      int base;
  279.      int reg;
  280.      int value;
  281. {
  282.   put_long_mem_da (context, get_word_reg (context, reg) + base, value);
  283. }
  284.  
  285. static INLINE
  286. void 
  287. put_word_mem_x (context, base, reg, value)
  288.      sim_state_type *context;
  289.      int base;
  290.      int reg;
  291.      int value;
  292. {
  293.   put_word_mem_da (context, get_word_reg (context, reg) + base, value);
  294. }
  295.  
  296. static INLINE
  297. void 
  298. put_byte_mem_x (context, base, reg, value)
  299.      sim_state_type *context;
  300.      int base;
  301.      int reg;
  302.      int value;
  303. {
  304.   put_byte_mem_da (context, get_word_reg (context, reg) + base, value);
  305. }
  306.  
  307. static INLINE
  308. int 
  309. get_word_mem_x (context, base, reg)
  310.      sim_state_type *context;
  311.      int base;
  312.      int reg;
  313. {
  314.   return get_word_mem_da (context, base + get_word_reg (context, reg));
  315. }
  316.  
  317. static INLINE
  318. int 
  319. get_byte_mem_x (context, base, reg)
  320.      sim_state_type *context;
  321.      int base;
  322.      int reg;
  323. {
  324.   return get_byte_mem_da (context, base + get_word_reg (context, reg));
  325. }
  326.  
  327. static INLINE
  328. int 
  329. get_long_mem_x (context, base, reg)
  330.      sim_state_type *context;
  331.      int base;
  332.      int reg;
  333. {
  334.   return get_long_mem_da (context, base + get_word_reg (context, reg));
  335. }
  336.  
  337.  
  338. static
  339. void
  340. makeflags (context, mask)
  341.      sim_state_type *context;
  342.      int mask;
  343. {
  344.  
  345.   PSW_ZERO = (context->dst & mask) == 0;
  346.   PSW_SIGN = (context->dst >> (context->size - 1));
  347.  
  348.   if (context->broken_flags == TST_FLAGS)
  349.     {
  350.       extern char the_parity[];
  351.  
  352.       if (context->size == 8)
  353.     {
  354.       PSW_OVERFLOW = the_parity[context->dst & 0xff];
  355.     }
  356.     }
  357.   else
  358.     {
  359.       /* Overflow is set if both operands have the same sign and the
  360.          result is of different sign.
  361.  
  362.          V =  A==B && R!=B  jumping logic
  363.          (~(A^B))&(R^B)
  364.          V =  (A^B)^(R^B)   boolean
  365.          */
  366.  
  367.       PSW_OVERFLOW =
  368.     ((
  369.        (~(context->srca ^ context->srcb)
  370.         & (context->srca ^ context->dst))
  371.      ) >> (context->size - 1)
  372.     );
  373.  
  374.       if (context->size < 32)
  375.     {
  376.       PSW_CARRY = ((context->dst >> context->size)) & 1;
  377.     }
  378.       else
  379.     {
  380.       /* carry is set when the result is smaller than a source */
  381.  
  382.  
  383.       PSW_CARRY =  (unsigned) context->dst > (unsigned) context->srca ;
  384.  
  385.     }
  386.     }
  387.   context->broken_flags = 0;
  388. }
  389.  
  390.  
  391. /* There are two ways to calculate the flags.  We can
  392.    either always calculate them and so the cc will always
  393.    be correct, or we can only keep the arguments around and
  394.    calc the flags when they're actually going to be used. */
  395.  
  396. /* Right now we always calc the flags - I think it may be faster*/
  397.  
  398.  
  399. #define NORMAL_FLAGS(c,s,d,sa,sb,sub)     \
  400.     if (s == 8)                \
  401.       normal_flags_8(c,d,sa,sb,sub); \
  402.     else if (s == 16)                \
  403.       normal_flags_16(c,d,sa,sb,sub); \
  404.     else if (s == 32)                \
  405.       normal_flags_32(c,d,sa,sb,sub); 
  406.  
  407. static INLINE
  408. void 
  409. normal_flags (context, size, dst, srca, srcb)
  410.      sim_state_type *context;
  411.      int size;
  412.      int dst;
  413.      int srca;
  414.      int srcb;
  415. {
  416.   context->srca = srca;
  417.   context->srcb = srcb;
  418.   context->dst = dst;
  419.   context->size = size;
  420.   context->broken_flags = CMP_FLAGS;
  421. }
  422.  
  423. static INLINE
  424. void 
  425. TEST_NORMAL_FLAGS (context, size, dst)
  426.      sim_state_type *context;
  427.      int size;
  428.      int dst;
  429. {
  430.   context->dst = dst;
  431.   context->size = size;
  432.   context->broken_flags = TST_FLAGS;
  433. }
  434.  
  435. static INLINE
  436. void 
  437. put_ptr_long_reg (context, reg, val)
  438.      sim_state_type *context;
  439.      int reg;
  440.      int val;
  441. {
  442.   context->regs[reg].word = (val >> 8) & 0x7f00;
  443.   context->regs[reg + 1].word = val;
  444. }
  445.  
  446. static INLINE
  447. long 
  448. get_ptr_long_reg (context, reg)
  449.      sim_state_type *context;
  450.      int reg;
  451. {
  452.   int val;
  453.  
  454.   val = (context->regs[reg].word << 8) | context->regs[reg + 1].word;
  455.   return val;
  456. }
  457.  
  458. static INLINE
  459. long 
  460. get_ptr_long_mem_ir (context, reg)
  461. sim_state_type *context;
  462. int reg;
  463. {
  464.   return sitoptr (get_long_mem_da (context, get_ptr_long_reg (context, reg)));
  465. }
  466.  
  467. static INLINE
  468. long 
  469. get_ptr_long_mem_da (context, addr)
  470. sim_state_type *context;
  471. long addr; 
  472. {
  473.   return sitoptr (get_long_mem_da (context, addr));
  474. }
  475.  
  476. static INLINE
  477. void 
  478. put_ptr_long_mem_da (context, addr, ptr)
  479. sim_state_type *context;
  480. long addr; 
  481. long ptr;
  482. {
  483.   put_long_mem_da (context, addr, ptrtosi (ptr));
  484.  
  485. }
  486.