home *** CD-ROM | disk | FTP | other *** search
/ Programmer 7500 / MAX_PROGRAMMERS.iso / INFO / CROSSASM / 68ASMSIM.ZIP / simsrc / code9.c < prev    next >
Encoding:
C/C++ Source or Header  |  1989-04-09  |  1.8 KB  |  134 lines

  1.  
  2. /***************************** 68000 SIMULATOR ****************************
  3.  
  4. File Name: CODE9.C
  5. Version: 1.0
  6.  
  7. The instructions implemented in this file are the exception processing
  8. related operations:
  9.  
  10.         CHK, ILLEGAL, RESET, STOP, TRAP, TRAPV    
  11.  
  12.  
  13. ***************************************************************************/
  14.  
  15.  
  16. #include <stdio.h>
  17. #include "extern.h"         /* contains global "extern" declarations */
  18.  
  19.  
  20.  
  21.  
  22. int    CHK()
  23. {
  24. int    reg;
  25. long    temp;
  26.  
  27. reg = (inst >> 9) & 0x07;
  28.  
  29. if (eff_addr ((long) WORD, DATA_ADDR, TRUE))
  30.     return (BAD_INST);        /* bad instruction format */
  31.  
  32. from_2s_comp (EV1, (long) WORD, &source);
  33. dest = D[reg] & WORD;
  34.  
  35. cc_update (N_A, GEN, UND, UND, UND, source, D[reg], D[reg], WORD, 0);
  36.  
  37. /* perform the CHK operation */
  38. if ((dest < 0) || (dest > source))
  39.     return(CHK_EXCEPTION);
  40.  
  41. inc_cyc (10);
  42.  
  43. return SUCCESS;
  44.  
  45. }
  46.  
  47.  
  48.  
  49. int    ILLEGAL()
  50. {
  51.  
  52. return (ILLEGAL_TRAP);
  53.  
  54. }
  55.  
  56.  
  57.  
  58. int    RESET()
  59. {
  60.  
  61. if (!(SR & sbit))
  62.     return (NO_PRIVILEGE);
  63.  
  64. /* assert the reset line to reset external devices */
  65.  
  66. inc_cyc (132);
  67.  
  68. return SUCCESS;
  69.  
  70. }
  71.  
  72.  
  73.  
  74. int    STOP()
  75. {
  76. long    temp;
  77. int    tr_on;
  78.  
  79. inc_cyc (4);
  80.  
  81. mem_request (&PC, (long) WORD, &temp);
  82.  
  83. if (SR & tbit)
  84.     tr_on = TRUE;
  85. else
  86.     tr_on = FALSE;
  87.  
  88. if (!(SR & sbit))
  89.     return (NO_PRIVILEGE);
  90.  
  91. SR = temp & WORD;
  92. if (tr_on)
  93.     SR = SR | tbit;
  94.  
  95. if (!(SR & sbit))
  96.     return (NO_PRIVILEGE);
  97.  
  98. if (!(SR & tbit))
  99.     printf ("Processor has entered stop mode.  Processing halted.");
  100. else
  101.     {
  102.     printf ("Processor has entered stop mode.\n");
  103.     printf ("Processing halted, but resumed due to a trace exception.");
  104.     }
  105.  
  106. return (STOP_TRAP);
  107.  
  108. }
  109.  
  110.  
  111.  
  112. int    TRAP()
  113. {
  114.  
  115. return (TRAP_TRAP);
  116.  
  117. }
  118.  
  119.  
  120.  
  121.  
  122. int    TRAPV()
  123. {
  124.  
  125. if (SR & vbit)
  126.     return (TRAPV_TRAP);
  127.  
  128. inc_cyc (4);
  129.  
  130. return SUCCESS;
  131.  
  132. }
  133.  
  134.