main.c 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194
  1. /*
  2. Main loop
  3. */
  4. /* $Id$ */
  5. #include <stdio.h>
  6. #include <setjmp.h>
  7. #include <em_abs.h>
  8. #include "e.out.h"
  9. #include "logging.h"
  10. #include "nofloat.h"
  11. #include "global.h"
  12. #include "log.h"
  13. #include "trap.h"
  14. #include "warn.h"
  15. #include "text.h"
  16. #include "read.h"
  17. #include "opcode.h"
  18. #include "rsb.h"
  19. extern int atoi();
  20. extern long atol();
  21. extern char *strcpy();
  22. char mess_file[64] = "int.mess"; /* name of message file */
  23. jmp_buf trapbuf;
  24. char *prog_name;
  25. int running; /* set if EM machine is running */
  26. size maxstack; /* if set, max stack size */
  27. size maxheap; /* if set, max heap size */
  28. #ifdef LOGGING
  29. extern long inr; /* from log.c */
  30. #endif /* LOGGING */
  31. PRIVATE char *dflt_av[] = {"e.out", 0}; /* default arguments */
  32. main(argc, argv)
  33. int argc;
  34. char *argv[];
  35. {
  36. register int i;
  37. register int nosetjmp = 1;
  38. int must_disassemble = 0;
  39. int must_tally = 0;
  40. prog_name = argv[0];
  41. /* Initialize the EM machine */
  42. PreIgnMask = 0;
  43. FRALimit = FRALIMIT;
  44. for (i = 1; i < argc; i++) {
  45. if (*(argv[i]) == '-') {
  46. switch (*(argv[i] + 1)) {
  47. case 'd': /* disassembly */
  48. must_disassemble = 1;
  49. break;
  50. case 'h': /* limit heap size */
  51. maxheap = atol(argv[i] + 2);
  52. break;
  53. case 'I': /* IgnMask pre-setting */
  54. if (atoi(argv[i] + 2) < 16)
  55. PreIgnMask = BIT(atoi(argv[i] + 2));
  56. break;
  57. case 'm': /* messagefile name override */
  58. strcpy(mess_file, argv[i] + 2);
  59. break;
  60. case 'r': /* FRALimit override */
  61. FRALimit = atoi(argv[i] + 2);
  62. break;
  63. case 's': /* limit stack size */
  64. maxstack = atol(argv[i] + 2);
  65. break;
  66. case 't': /* switch on tallying */
  67. must_tally= 1;
  68. break;
  69. case 'W': /* disable warning */
  70. set_wmask(atoi(argv[i] + 2));
  71. break;
  72. default:
  73. fprintf(stderr,
  74. "%s: bad option: %s\n",
  75. prog_name,
  76. argv[i]
  77. );
  78. exit(1);
  79. }
  80. }
  81. #ifdef LOGGING
  82. else if (logarg(argv[i])) {
  83. /* interesting for the logging machine */
  84. }
  85. #endif /* LOGGING */
  86. else break;
  87. }
  88. #ifdef LOGGING
  89. /* Initialize the logging machine */
  90. init_log();
  91. #endif /* LOGGING */
  92. if (argc > i)
  93. init(argc - i, argv + i);
  94. else
  95. init(1, dflt_av);
  96. /* Text dump only? */
  97. if (must_disassemble) {
  98. message(
  99. "text segment disassembly produced; program was not run");
  100. disassemble();
  101. close_down(0);
  102. }
  103. /* Analyse FLAGS word */
  104. if (FLAGS&FB_TEST)
  105. must_test = 1;
  106. if ((FLAGS&FB_PROFILE) || (FLAGS&FB_FLOW) || (FLAGS&FB_COUNT))
  107. must_tally = 1;
  108. #ifdef NOFLOAT
  109. if (FLAGS&FB_REALS)
  110. warning(WFLUSED);
  111. #endif /* NOFLOAT */
  112. if (FLAGS&FB_EXTRA)
  113. warning(WEXTRIGN);
  114. /* Call first procedure */
  115. running = 1; /* start the machine */
  116. OnTrap = TR_HALT; /* default trap handling */
  117. call(ENTRY, RSB_STP);
  118. /* Run the machine */
  119. while (running) {
  120. #ifdef LOGGING
  121. inr++;
  122. if (must_log && inr >= log_start) {
  123. /* log this instruction */
  124. logging = 1;
  125. }
  126. #endif /* LOGGING */
  127. LOG(("@x9 PC = %lu OPCODE = %lu", PC,
  128. btol(text_loc(PC)) < SECONDARY ?
  129. btol(text_loc(PC)) :
  130. btol(text_loc(PC)) + btol(text_loc(PC+1))
  131. ));
  132. newPC(PC); /* just check for validity */
  133. do_instr(nextPCbyte()); /* here it happens */
  134. if (must_tally) {
  135. tally();
  136. }
  137. if (signalled) {
  138. /* a signal has come in during this instruction */
  139. LOG(("@t1 signal %d caught by EM machine", signalled));
  140. trap_signal();
  141. }
  142. if (nosetjmp) {
  143. /* entry point after a trap occurred */
  144. setjmp(trapbuf);
  145. nosetjmp = 0;
  146. }
  147. #ifdef LOGGING
  148. log_eoi();
  149. #endif /* LOGGING */
  150. }
  151. if (must_tally) {
  152. out_tally();
  153. }
  154. if (ES_def == DEFINED) {
  155. message("program exits with status %ld", ES);
  156. close_down((int) ES);
  157. }
  158. else {
  159. message("program exits with undefined status");
  160. close_down(0);
  161. }
  162. /*NOTREACHED*/
  163. }