[llvm-commits] CVS: llvm-test/MultiSource/Benchmarks/Prolangs-C/simulator/Makefile boolean.h constants.h convert.c convert.h debugger.c debugger.h define-instr-tab.h format.c format.h instruct.c instruct.h instruct2.c instruct2.h interupt.c interupt.h load.h loadexe.c loadexe.h machine.c machine.h memory.c memory.h print.c print.h sim_debug.c sim_debug.h stringI.c stringI.h sym_tab.c sym_tab.h
Chris Lattner
lattner at cs.uiuc.edu
Tue Oct 5 14:08:51 PDT 2004
Changes in directory llvm-test/MultiSource/Benchmarks/Prolangs-C/simulator:
Makefile added (r1.1)
boolean.h added (r1.1)
constants.h added (r1.1)
convert.c added (r1.1)
convert.h added (r1.1)
debugger.c added (r1.1)
debugger.h added (r1.1)
define-instr-tab.h added (r1.1)
format.c added (r1.1)
format.h added (r1.1)
instruct.c added (r1.1)
instruct.h added (r1.1)
instruct2.c added (r1.1)
instruct2.h added (r1.1)
interupt.c added (r1.1)
interupt.h added (r1.1)
load.h added (r1.1)
loadexe.c added (r1.1)
loadexe.h added (r1.1)
machine.c added (r1.1)
machine.h added (r1.1)
memory.c added (r1.1)
memory.h added (r1.1)
print.c added (r1.1)
print.h added (r1.1)
sim_debug.c added (r1.1)
sim_debug.h added (r1.1)
stringI.c added (r1.1)
stringI.h added (r1.1)
sym_tab.c added (r1.1)
sym_tab.h added (r1.1)
---
Log message:
Another benchmark without an input
---
Diffs of the changes: (+4482 -0)
Index: llvm-test/MultiSource/Benchmarks/Prolangs-C/simulator/Makefile
diff -c /dev/null llvm-test/MultiSource/Benchmarks/Prolangs-C/simulator/Makefile:1.1
*** /dev/null Tue Oct 5 16:08:50 2004
--- llvm-test/MultiSource/Benchmarks/Prolangs-C/simulator/Makefile Tue Oct 5 16:08:39 2004
***************
*** 0 ****
--- 1,6 ----
+ LEVEL = ../../../..
+
+ PROG = simulator
+ LDFLAGS = -lm
+ include $(LEVEL)/MultiSource/Makefile.multisrc
+
Index: llvm-test/MultiSource/Benchmarks/Prolangs-C/simulator/boolean.h
diff -c /dev/null llvm-test/MultiSource/Benchmarks/Prolangs-C/simulator/boolean.h:1.1
*** /dev/null Tue Oct 5 16:08:51 2004
--- llvm-test/MultiSource/Benchmarks/Prolangs-C/simulator/boolean.h Tue Oct 5 16:08:39 2004
***************
*** 0 ****
--- 1,6 ----
+ /* %%%%%%%%%%%%%%%%%%%% (c) William Landi 1991 %%%%%%%%%%%%%%%%%%%%%%%%%%%% */
+ /* Permission to use this code is granted as long as the copyright */
+ /* notice remains in place. */
+ /* ============================= boolean.h ================================= */
+ /* Just makes BOOLEAN another name for int. */
+ typedef int BOOLEAN;
Index: llvm-test/MultiSource/Benchmarks/Prolangs-C/simulator/constants.h
diff -c /dev/null llvm-test/MultiSource/Benchmarks/Prolangs-C/simulator/constants.h:1.1
*** /dev/null Tue Oct 5 16:08:51 2004
--- llvm-test/MultiSource/Benchmarks/Prolangs-C/simulator/constants.h Tue Oct 5 16:08:39 2004
***************
*** 0 ****
--- 1,61 ----
+ /* %%%%%%%%%%%%%%%%%%%% (c) William Landi 1991 %%%%%%%%%%%%%%%%%%%%%%%%%%%% */
+ /* Permission to use this code is granted as long as the copyright */
+ /* notice remains in place. */
+ /* ============================= constants.h =============================== */
+ /* A collection of commonly used constants for the assembler. */
+
+
+ /* DEBUG_FLAG_1 Controls whether certain lines of the program. */
+ /* Execution or non-execution of these lines aids in */
+ /* Debugging the program. */
+ #define DEBUG_FLAG_1 0
+
+ /* LABEL_SIZE_1 Size of the largest valid LABEL in characters */
+ #define LABEL_SIZE_1 8
+
+ /* MEM_SIZE_1 Size of SIC/XE main memory in bytes */
+ /* NOTE: 2^20 = 1048576 */
+ #define MEM_SIZE_1 1048576
+
+ /* MEM_ADDR_SIZE_1 Number of BITS in an address {log2(MEM_SIZE_1)} */
+ #define MEM_ADDR_SIZE_1 20
+
+ /* BITS_PER_WORD_1 Number of BITS in a WORD */
+ #define BITS_PER_WORD_1 24
+
+ /* MAX_INT_1 Biggest integer+1: 2^BITS_PER_WORD_1 */
+ #define MAX_INT_1 16777216
+
+ /* BITS_PER_HALFBYTE_1 Number of BITS in a Half BYTE */
+ #define BITS_PER_HALFBYTE_1 4
+
+ /* BITS_PER_BYTE_2 Number of BITS in a BYTE */
+ #define BITS_PER_BYTE_2 8
+
+ /* HEX_CHAR_PER_BYTE_1 Number of hexidecimal characters (ASCII) must be */
+ /* used to produce a 1 BYTE value. */
+ #define HEX_CHAR_PER_BYTE_1 2
+
+ /* LARGEST_INSTRUCT_SIZE_1 Size in BITS of the the largest instruction in */
+ /* SIC/XE. Format 4 is 32 bits */
+ #define LARGEST_INSTRUCT_SIZE_1 32
+
+ /* MAX_PC_RELATIVE_1 Smallest number that will NOT fit in a PC relative*/
+ /* address. {4096 = 2^12} */
+ #define MAX_PC_RELATIVE_1 4096
+
+ /* GLOBAL_1 Module name for Global labels -- used by LOADER. */
+ #define GLOBAL_1 "_GLOBAL "
+
+ /* -------------------------- Boolean Constants ---------------------------- */
+ #define FALSE_1 0
+ #define TRUE_1 1
+
+
+ /* ------------------- Expression types (LABELS,CONSTANTS,etc) ------------- */
+ #define ABSOLUTE_OR_RELATIVE_1 0 /* Don't know type */
+ #define ABSOLUTE_VALUE_1 1 /* Absolute expressions */
+ #define RELATIVE_VALUE_1 2 /* Relative expressions */
+ #define EXTERN_VALUE_1 3 /* An external reference */
+
+
Index: llvm-test/MultiSource/Benchmarks/Prolangs-C/simulator/convert.c
diff -c /dev/null llvm-test/MultiSource/Benchmarks/Prolangs-C/simulator/convert.c:1.1
*** /dev/null Tue Oct 5 16:08:51 2004
--- llvm-test/MultiSource/Benchmarks/Prolangs-C/simulator/convert.c Tue Oct 5 16:08:39 2004
***************
*** 0 ****
--- 1,104 ----
+ /* %%%%%%%%%%%%%%%%%%%% (c) William Landi 1991 %%%%%%%%%%%%%%%%%%%%%%%%%%%% */
+ /* Permission to use this code is granted as long as the copyright */
+ /* notice remains in place. */
+ /* ============================= convert.c ================================= */
+ /* Contains routines that convert one thing to another. Most of the routines */
+ /* deal with converting a number to a string of that number in some base, or */
+ /* converting a string (assuming some base) into an integer. Basically */
+ /* just a file of miscellaneous 'useful' routines. */
+ #include <stdio.h>
+ #include <string.h>
+ #include <math.h>
+ #include "boolean.h"
+ #include "constants.h"
+
+ /* ----------------------------- eoln -------------------------------------- */
+ /* true if CH is the End Of LiNe character, otherwise false. */
+ BOOLEAN eoln(char CH)
+ {
+ return (CH == '\0');
+ }
+
+ /* ------------------------ CHAR_TO_DIGIT ---------------------------------- */
+ /* Convert a character (CH) into its integer value give base NUM_BASE. Return*/
+ /* -1 if it is not a valid digit in that base. */
+ int CHAR_TO_DIGIT(char CH,int NUM_BASE)
+ {
+ int DIGIT = -1;
+ if ( (CH >= '0') && (CH <= '9') ) DIGIT = (int) (CH - '0');
+ if ( (CH >= 'A') && (CH <= 'Z') ) DIGIT = ((int) (CH - 'A'))+10;
+ if (DIGIT >= NUM_BASE) DIGIT = -1;
+ return DIGIT;
+ }
+
+
+ /* ------------------------- NUM_TO_STR ------------------------------------ */
+ /* Put into STR the string with LEN digits that represents the number NUM */
+ /* in base BASE (eg. NUM_TO_STR(10,16,3,STR) puts "00A" in STR). */
+ void NUM_TO_STR(int NUM,int BASE,int LEN,char *STR)
+ {
+ int I; /* loop counter */
+ int DIGIT; /* one digit in base specified of NUM */
+
+ STR[LEN] = '\0';
+ for (I=(LEN-1); I>=0; I--) {
+ DIGIT = NUM - (NUM/BASE) * BASE;
+ NUM /= BASE;
+ if ((DIGIT >= 0) && (DIGIT <= 9))
+ STR[I] = (char) DIGIT + '0';
+ else STR[I] = (char) (DIGIT-10) + 'A';
+ }
+ if (NUM != 0)
+ (void) printf("NUM_TO_STR called illegally.\n");
+ }
+
+ /* ------------------------------ GET_NUM ---------------------------------- */
+ /* CURRENT_CHAR points to a string. Starting with the character */
+ /* **CURRENT_CHAR and get the biggest possible integer in BASE NUM_BASE. If */
+ /* that number is too large/small to fit in BITS bits (2's complement), */
+ /* Put an error message into ERROR_REC_BUF. Returns 0 if this or any error is*/
+ /* detected, otherwise it returns the integer representation of the number. */
+ /* NOTE: If number is to large/small this routine stops as soon as it */
+ /* realizes this w/o (with out) looking at the rest of the input. */
+ int GET_NUM(char **CURRENT_CHAR,int BITS,int NUM_BASE,BOOLEAN *ERROR)
+ {
+ int CONVERT = 0; /* CONVERT is the converted integer of the */
+ /* string */
+ int MAX_UNSIGNED_INT; /* MAX_UNSIGNED_INT = 2^BITS */
+ /* - Biggest biggest number + 1 */
+ /* (w/o sign) that fits */
+ int DIGIT; /* One digit of the number. */
+
+ MAX_UNSIGNED_INT = (int) pow(2.0,BITS*1.0);
+
+ /* ----------------------------- Get the biggest [legal] number you can */
+ while ( ( (DIGIT = CHAR_TO_DIGIT(**CURRENT_CHAR,NUM_BASE)) != -1) &&
+ !eoln(**CURRENT_CHAR) ) {
+ if (CONVERT <= MAX_UNSIGNED_INT)
+ CONVERT = CONVERT*NUM_BASE + DIGIT;
+ (*CURRENT_CHAR) ++;
+ }
+
+ if ( (CONVERT > (MAX_UNSIGNED_INT - 1)) ||
+ (!eoln(**CURRENT_CHAR)) ) (*ERROR) = TRUE_1;
+
+ return CONVERT;
+ }
+
+ /* -------------------------------- STR_TO_NUM ----------------------------- */
+ /* Convert the first DIGITS characters of STR to an integer of base BASE. */
+ void STR_TO_NUM(char *STR,int DIGITS,int BASE,int *NUM,BOOLEAN *ERROR)
+ {
+ int I;
+ int ONE_DIGIT;
+ BOOLEAN LOCAL_ERROR = FALSE_1;
+
+ (*NUM) = 0;
+ for (I = 0; ((I < DIGITS) && !LOCAL_ERROR); I ++)
+ if ( (ONE_DIGIT = CHAR_TO_DIGIT(STR[I],BASE)) == -1)
+ LOCAL_ERROR = TRUE_1; /* Not a valid number. */
+ else
+ (*NUM) = (*NUM)*BASE + ONE_DIGIT;
+
+ if (LOCAL_ERROR) (*ERROR) = TRUE_1;
+ }
Index: llvm-test/MultiSource/Benchmarks/Prolangs-C/simulator/convert.h
diff -c /dev/null llvm-test/MultiSource/Benchmarks/Prolangs-C/simulator/convert.h:1.1
*** /dev/null Tue Oct 5 16:08:51 2004
--- llvm-test/MultiSource/Benchmarks/Prolangs-C/simulator/convert.h Tue Oct 5 16:08:39 2004
***************
*** 0 ****
--- 1,60 ----
+ /* %%%%%%%%%%%%%%%%%%%% (c) William Landi 1991 %%%%%%%%%%%%%%%%%%%%%%%%%%%% */
+ /* Permission to use this code is granted as long as the copyright */
+ /* notice remains in place. */
+ /* =============================== convert.h =============================== */
+ /* Contains routines that convert one thing to another. Most of the routines */
+ /* deal with converting a number to a string of that number in some base, or */
+ /* converting a string (assuming some base) into an integer. Basically */
+ /* just a file of miscellaneous 'useful' routines. */
+
+ /* ----------------------------- eoln -------------------------------------- */
+ /* true if CH is the End Of LiNe character, otherwise false. */
+ /* 1 parameter: */
+ /* 1) char CH; Character in question. */
+ extern int eoln();
+
+ /* ------------------------ CHAR_TO_DIGIT ---------------------------------- */
+ /* 2 parameters: */
+ /* 1) char CH; character to convert */
+ /* 2) int NUM_BASE; base of number */
+ /* Convert a character (CH) into its integer value give base NUM_BASE. Return*/
+ /* -1 if it is not a valid digit in that base. */
+ extern int CHAR_TO_DIGIT();
+
+ /* ------------------------- NUM_TO_STR ------------------------------------ */
+ /* 4 parameters: */
+ /* 1) int NUM; Number to convert */
+ /* 2) int BASE; Base to convert into */
+ /* 3) int LEN; Number of digits in final string */
+ /* 4) char *STR; where to put it. */
+ /* Put into STR the string with LEN digits that represents the number NUM */
+ /* in base BASE (eg. NUM_TO_STR(10,16,3,STR) puts "00A" in STR). */
+ extern void NUM_TO_STR();
+
+ /* ------------------------------ GET_NUM ---------------------------------- */
+ /* 4 parameters: */
+ /* 1) char **CURRENT_CHAR; pointer to start of string to interpret */
+ /* as an integer (in NUM_BASE) */
+ /* 2) int BITS; Number must fit in this may bits 2's */
+ /* complement. */
+ /* 3) int NUM_BASE; Base the number is in. */
+ /* 4) BOOLEAN *ERROR; Was an error detected. */
+ /* CURRENT_CHAR points to a string. Starting with the character */
+ /* **CURRENT_CHAR and get the biggest possible integer in BASE NUM_BASE. If */
+ /* that number is too large/small to fit in BITS bits (2's complement), */
+ /* Put an error message into ERROR_REC_BUF. Returns 0 if this or any error is*/
+ /* detected, otherwise it returns the integer representation of the number. */
+ /* NOTE: If number is to large/small this routine stops as soon as it */
+ /* realizes this w/o (with out) looking at the rest of the input. */
+ extern int GET_NUM();
+
+ /* -------------------------------- STR_TO_NUM ----------------------------- */
+ /* Convert the first DIGITS characters of STR to an integer of base BASE. */
+ /* 5 paramaters: */
+ /* 1) char *STR; STRing to convert. */
+ /* 2) int DIGITS; number of DIGITS of string to convert. */
+ /* 3) int BASE; BASE of the number. */
+ /* 4) int *NUM; Place to return the result */
+ /* 5) BOOLEAN *ERROR; Has an error been detected. */
+ extern void STR_TO_NUM();
+
Index: llvm-test/MultiSource/Benchmarks/Prolangs-C/simulator/debugger.c
diff -c /dev/null llvm-test/MultiSource/Benchmarks/Prolangs-C/simulator/debugger.c:1.1
*** /dev/null Tue Oct 5 16:08:51 2004
--- llvm-test/MultiSource/Benchmarks/Prolangs-C/simulator/debugger.c Tue Oct 5 16:08:39 2004
***************
*** 0 ****
--- 1,806 ----
+ /* %%%%%%%%%%%%%%%%%%%% (c) William Landi 1991 %%%%%%%%%%%%%%%%%%%%%%%%%%%% */
+ /* Permission to use this code is granted as long as the copyright */
+ /* notice remains in place. */
+
+ /* =============================== debugger.c =============================== */
+ /* Drives the whole simulatation/debugging process. Contains the debugging */
+ /* Routines and calls the simulation routines (else where defined). */
+ #include <string.h>
+ #include "memory.h"
+ #include "boolean.h"
+ #include "constants.h"
+ #include "sym_tab.h"
+ #include "sim_debug.h"
+ #include "machine.h"
+ #include "stringI.h"
+ /* ---------------------------------- Globals ------------------------------ */
+ /* MAIN_ROUTINE Name of (program) module declared with */
+ /* a START (main routine). */
+ char MAIN_ROUTINE[LABEL_SIZE_1+1];
+
+ /* START_ADDRESS Location where execution begins */
+ int START_ADDRESS = 0;
+
+ /* SYM_TAB The symbol table */
+ SYMBOL_TABLE SYM_TAB;
+
+ /* RETURN_STATUS Status of machine when control returned*/
+ int RETURN_STATUS = HALT_1; /* to debugger. */
+
+ /* TYPE_OUT_MODE Remembers the type out mode */
+ char TYPE_OUT_MODE[6] = "Hex";
+
+ /* ----------------------------- Non-Globals ------------------------------- */
+ #define MAX_NUM_BREAK_POINTS 16
+ int BREAK_POINTS[MAX_NUM_BREAK_POINTS+1];
+ int SORTED_BREAK_POINTS[MAX_NUM_BREAK_POINTS+1];
+ int NUM_BREAK_POINTS = 0;
+ BOOLEAN TRACE = FALSE_1;
+
+ /* ---------------------------- Procedures --------------------------------- */
+
+ extern int CHAR_TO_DIGIT(char CH,int NUM_BASE);
+
+ /* -------------------------- IS_PREFIX_TO (local) ------------------------- */
+ /* Returns TRUE iff PREFIX is a prefix of WORD */
+ BOOLEAN IS_PREFIX_TO(char *PREFIX,char *WORD)
+ {
+ int COUNT;
+ int LEN;
+
+ if ((LEN = strlen(PREFIX)) > strlen(WORD)) return FALSE_1;
+ for (COUNT=0; COUNT < LEN; COUNT ++)
+ if (PREFIX[COUNT] != WORD[COUNT]) return FALSE_1;
+ return TRUE_1;
+ }
+
+ /* ---------------------------- REMOVE_WS (local) ------------------------- */
+ /* Line is a pointer to a string. Changes LINE to point to the string that */
+ /* starts at the first non-blank/tab character in *LINE. */
+ void REMOVE_WS(char **LINE)
+ {
+ /* Skip SPACEs and TABs */
+ while (((**LINE) == ' ') || ((**LINE) == ' '))
+ (*LINE) ++;
+ }
+
+ /* ------ Different types of things need to type into the debugger. */
+ #define ADDRESS_0 0
+ #define ADDR_REG_0 1
+ #define NUMBER_0 2
+ #define VALUE_0 3
+ /* ----------------------------- TYPE_IN (local) --------------------------- */
+ /* Return a value specified by a type in mode. Assumes: */
+ /* No $ prefix Hexidecimal input */
+ /* $D prefix Decimal input */
+ /* $C prefix Character input. */
+ /* $S prefix Address of a LABEL returned. */
+ int TYPE_IN(char **COMMAND,BOOLEAN *LEGAL,int RESULT_TYPE)
+ {
+ int VALUE = 0;
+ int LOOP;
+
+ (*LEGAL) = TRUE_1;
+ REMOVE_WS(COMMAND);
+ if ( (**COMMAND) == '$')
+ {
+ (*COMMAND) ++;
+ switch (**COMMAND) {
+ /* -------------------------------- $D prefix ------------------------------ */
+ case 'D':
+ (*COMMAND) ++;
+ if (CHAR_TO_DIGIT((**COMMAND),10) == -1) {
+ (void) printf("Expected an decimal, found '%s'. Ignoring command.\n",
+ *COMMAND);
+ (*LEGAL) = FALSE_1;
+ } else {
+ while (CHAR_TO_DIGIT((**COMMAND),10) != -1) {
+ VALUE = VALUE * 10 + CHAR_TO_DIGIT((**COMMAND),10);
+ (*COMMAND) ++;
+ }
+ }
+ break;
+
+ /* -------------------------------- $C prefix ------------------------------ */
+ case 'C':
+ if (RESULT_TYPE != VALUE_0) (*LEGAL) = FALSE_1;
+ else {
+ (*COMMAND) ++;
+ VALUE = (int) **COMMAND;
+ if ( (**COMMAND != '\0')) (*COMMAND) ++;
+ }
+ break;
+
+ /* -------------------------------- $S prefix ------------------------------ */
+ case 'S':
+ if (RESULT_TYPE == NUMBER_0) (*LEGAL) = FALSE_1;
+ else {
+ (*COMMAND) ++;
+ REMOVE_WS(COMMAND);
+ if (!( ((**COMMAND) >= 'A') && ((**COMMAND) <= 'Z'))) {
+ (void) printf(
+ "Expected an identifier, found '%s'. Ignoring command.\n",
+ *COMMAND);
+ (*LEGAL) = FALSE_1;
+ return 0;
+ } else {
+ char SYMBOL[LABEL_SIZE_1+1];
+ struct SYMBOL_TABLE_ENTRY *SYMB;
+
+ for (LOOP=0; ( (LOOP < LABEL_SIZE_1) &&
+ ( ((**COMMAND) >= 'A') && ((**COMMAND) <= 'Z')));
+ LOOP ++) {
+ SYMBOL[LOOP] = **COMMAND;
+ (*COMMAND) ++;
+ }
+ for (;LOOP<LABEL_SIZE_1;LOOP++)
+ SYMBOL[LOOP] = ' ';
+ SYMBOL[LABEL_SIZE_1] = '\0';
+ SYMB = LOOK_UP_SYMBOL(GLOBAL_1,SYMBOL,&SYM_TAB);
+ if (SYMB == NULL) {
+ (void) printf(
+ "Unknown identifier, found '%s'. Ignoring command.\n",
+ SYMBOL);
+ (*LEGAL) = FALSE_1;
+ return 0;
+ }
+ VALUE = (*SYMB).LOCATION;
+ }
+ }
+ break;
+ default:
+ (*LEGAL) = FALSE_1;
+ }
+
+ if (!(*LEGAL)) {
+ switch (RESULT_TYPE) {
+ case ADDRESS_0:
+ (void) printf("Expected an type-in mode specifier ($D or $S).\n");
+ break;
+ case NUMBER_0:
+ (void) printf("Expected an type-in mode specifier ($D).\n");
+ break;
+ case ADDR_REG_0:
+ (void) printf(
+ "Expected an type-in mode specifier ($D, $S or $R).\n");
+ break;
+ case VALUE_0:
+ (void) printf(
+ "Expected an type-in mode specifier ($C, $D, or $S).\n");
+ break;
+ default: ;
+ }
+ (void) printf (" Found $%c. Ignoring command.\n",(**COMMAND));
+ }
+ }
+ else
+ /* --------------------------NO $ prefix (hex) ----------------------------- */
+ if (CHAR_TO_DIGIT((**COMMAND),16) == -1) {
+
+ (void) printf("Expected an hexidecimal, found '%s'. Ignoring command.\n",
+ *COMMAND);
+ (*LEGAL) = FALSE_1;
+ } else {
+ while (CHAR_TO_DIGIT((**COMMAND),16) != -1) {
+ VALUE = VALUE * 16 + CHAR_TO_DIGIT((**COMMAND),16);
+ (*COMMAND) ++;
+ }
+ }
+
+ return VALUE;
+ }
+
+ /* ---------------------------- EXAMINE (local) ---------------------------- */
+ /* DEBUGGER COMMAND. */
+ /* Print of the contents of a register of memory location or store into a */
+ /* Register or memory location. */
+ void EXAMINE(char *COMMAND,BOOLEAN *LEGAL)
+ {
+ int ADDRESS; /* Register number of memory address dealing */
+ /* with. */
+ int VALUE; /* Value to store (if necessary) */
+ char *START; /* START of address/register in command. */
+ char *END; /* END of address/register in command. */
+ BOOLEAN NO_ERROR; /* TRUE iff NO_ERROR has been found. */
+ BOOLEAN STORE = FALSE_1; /* TRUE if a store command, else FALSE */
+
+ (*LEGAL) = TRUE_1;
+ REMOVE_WS(&COMMAND);
+ START = (COMMAND);
+ if (strlen(COMMAND) <2) ADDRESS = TYPE_IN(&COMMAND,&NO_ERROR,ADDR_REG_0);
+ else if ((COMMAND[0] != '$') || (COMMAND[1] != 'R'))
+ ADDRESS = TYPE_IN(&COMMAND,&NO_ERROR,ADDR_REG_0);
+ else {
+ /* ~~~~~~~~~~~~~~~~~~~~~ Get register number if $R type in mode. */
+ COMMAND += 2;
+ switch (*COMMAND) {
+ case 'A':
+ ADDRESS = 0; break;
+ case 'X':
+ ADDRESS = 1; break;
+ case 'L':
+ ADDRESS = 2; break;
+ case 'B':
+ ADDRESS = 3; break;
+ case 'S':
+ if (*(COMMAND+1) == 'W') {
+ (COMMAND) ++;
+ ADDRESS = 9;
+ } else ADDRESS = 4;
+ break;
+ case 'T':
+ ADDRESS = 5; break;
+ case 'P':
+ if (*(COMMAND+1) == 'C') {
+ COMMAND ++;
+ ADDRESS = 8;
+ } else ADDRESS = -1;
+ break;
+ default:
+ ADDRESS = -1; break;
+ }
+ if (ADDRESS == -1) {
+ (void) printf(
+ "Expected a valid register name (A,X,L,B,S,T,SW, or PC).\n");
+ (void) printf(" Found %s. Ignoring command.\n",COMMAND);
+ return;
+ }
+ /* ~~~~~~~~~~~~~~~~~~~~~ Handle registers. */
+ COMMAND++;
+ END = COMMAND;
+ REMOVE_WS(&COMMAND);
+ /* --------------------- if '=' then a store command */
+ if ((*COMMAND) == '=') {
+ COMMAND++;
+ VALUE = TYPE_IN(&COMMAND,&NO_ERROR,VALUE_0);
+ if (!NO_ERROR) return;
+ REMOVE_WS(&COMMAND);
+ STORE = TRUE_1;
+ }
+ if ((*COMMAND) != '\0') {
+ (void) printf(
+ "Expected end of statement, found '%s'. Ignoring command.\n"
+ ,COMMAND);
+ return;
+ }
+ else {
+ /* ------------------------ Do what is supposed to be done. */
+ (*END) = '\0';
+ if (STORE) {
+ REGISTER[ADDRESS] = VALUE;
+ (void) printf("Set ");
+ }
+ (void) printf("Register %s = ",START);
+ (void) PRINT_CONSTANT("",REGISTER[ADDRESS],".\n");
+ return;
+ }
+ }
+ {
+ /* ~~~~~~~~~~~~~~~~~~~~~~~~~~~ Handle memory address */
+ END = COMMAND;
+ REMOVE_WS(&COMMAND);
+ if (NO_ERROR)
+ if ( (0 > ADDRESS) || (MEM_SIZE_1 <= ADDRESS+2))
+ PRINT_CONSTANT("",ADDRESS," is a legal memory [word] address.\n");
+ else {
+ /* --------------------- if '=' then a store command */
+ if ((*COMMAND) == '=') {
+ COMMAND++;
+ VALUE = TYPE_IN(&COMMAND,&NO_ERROR,VALUE_0);
+ if (!NO_ERROR) return;
+ REMOVE_WS(&COMMAND);
+ STORE = TRUE_1;
+ }
+
+ if ((*COMMAND) != '\0')
+ (void) printf(
+ "Expected end of statement, found '%s'. Ignoring command.\n"
+ ,COMMAND);
+ else {
+
+ (*END) = '\0';
+ /* ------------ Take the appropriate action (STORE/EXAMINE) */
+ if (STORE) {
+ REGISTER[ADDRESS] = VALUE;
+ MEMORY[ADDRESS] = VALUE/(256*256);
+ MEMORY[ADDRESS+1] = (VALUE - INT(MEMORY[ADDRESS])*256*256)/256;
+ MEMORY[ADDRESS+2] = (VALUE - INT(MEMORY[ADDRESS+1])*256);
+ (void) printf("Set ");
+ }
+ VALUE = ((INT(MEMORY[ADDRESS])*256 + INT(MEMORY[ADDRESS+1]))*256+
+ INT(MEMORY[ADDRESS+2]));
+ (void) printf("Location %s = ",START);
+ if (TYPE_OUT_MODE[0] != 'I')
+ PRINT_ADDRESS("",VALUE,".\n");
+ else {
+ (void) printf("\n");
+ PRINT_INSTRUCTION(ADDRESS,TRUE_1,&VALUE);
+ }
+ }
+ }
+ }
+ }
+
+ /* ---------------------------- LIST_BP (local) ---------------------------- */
+ /* DEBUGGER COMMAND. */
+ /* Print out all the currently set break points. */
+ void LIST_BP(char *COMMAND,BOOLEAN *LEGAL)
+ {
+ int COUNT; /* A loop counter. */
+
+ REMOVE_WS(&COMMAND);
+ (*LEGAL) = TRUE_1;
+
+ if ((*COMMAND) != '\0')
+ (void) printf("Expected end of statement, found '%s'. Ignoring command.\n"
+ ,COMMAND);
+ else
+ if (NUM_BREAK_POINTS == 0)
+ (void) printf("No break points set.\n");
+ else for (COUNT=0;COUNT<MAX_NUM_BREAK_POINTS;COUNT++)
+ if (BREAK_POINTS[COUNT] != -1) {
+ PRINT_CONSTANT("Set B",COUNT,"= ");
+ PRINT_ADDRESS("",BREAK_POINTS[COUNT],"\n");
+ }
+ }
+
+ /* ---------------------------- SET_BP (local) ----------------------------- */
+ /* DEBUGGER COMMAND. */
+ /* Check if list breakpoint command. If so call LIST_BP, other wise set a */
+ /* break point. A sorted version of the breakpoints is kept so that binary */
+ /* search can be used on them. */
+ void SET_BP(char *COMMAND,BOOLEAN *LEGAL)
+ {
+ BOOLEAN NO_ERROR; /* TRUE iff NO_ERROR has been found. */
+ int ADDR;
+ int OPEN_SPOT;
+ int COUNT;
+
+ if ((*COMMAND) == '?') {
+ LIST_BP(&(COMMAND[1]),LEGAL);
+ return;
+ }
+ (*LEGAL) = TRUE_1;
+ ADDR = TYPE_IN(&COMMAND,&NO_ERROR,ADDRESS_0);
+ REMOVE_WS(&COMMAND);
+ if (NO_ERROR)
+ if ( (0 > ADDR) || (MEM_SIZE_1 <= ADDR))
+ PRINT_CONSTANT(
+ "Address specified ",ADDR," out of range. No break point set.\n");
+ else if (NUM_BREAK_POINTS == MAX_NUM_BREAK_POINTS)
+ PRINT_CONSTANT("All ",MAX_NUM_BREAK_POINTS," breakpoints are in use.\n");
+ else if ((*COMMAND) != '\0')
+ (void) printf("Expected end of statement, found '%s'. Ignoring command.\n"
+ ,COMMAND);
+ else {
+ for (OPEN_SPOT=0;BREAK_POINTS[OPEN_SPOT] != -1; OPEN_SPOT++);
+ BREAK_POINTS[OPEN_SPOT] = ADDR;
+
+ for (COUNT=NUM_BREAK_POINTS;
+ ((BREAK_POINTS[SORTED_BREAK_POINTS[COUNT]] > ADDR) &&
+ (COUNT > 0));
+ COUNT --)
+ SORTED_BREAK_POINTS[COUNT+1] = SORTED_BREAK_POINTS[COUNT];
+ SORTED_BREAK_POINTS[COUNT+1] = OPEN_SPOT;
+ NUM_BREAK_POINTS ++;
+ PRINT_CONSTANT("Set B",OPEN_SPOT,"= ");
+ PRINT_ADDRESS("",BREAK_POINTS[OPEN_SPOT],"\n");
+ }
+ }
+
+ /* ----------------------------- RESET (local) ----------------------------- */
+ /* DEBUGGER COMMAND. */
+ /* Remove the specified break point. */
+ void RESET_BP(char *COMMAND,BOOLEAN *LEGAL)
+ {
+ BOOLEAN NO_ERROR; /* TRUE iff NO_ERROR has been found. */
+ int NUM; /* NUM of the break point to remove. */
+ int BP; /* Loop counter, steps through the break points*/
+
+ (*LEGAL) = TRUE_1;
+ NUM = TYPE_IN(&COMMAND,&NO_ERROR,NUMBER_0);
+ REMOVE_WS(&COMMAND);
+ if (NO_ERROR)
+ if ( (0 > NUM) || (NUM_BREAK_POINTS <= NUM)) {
+ PRINT_CONSTANT("",NUM," is not a legal break point.\n");
+ PRINT_CONSTANT("Expected a number 0 - ",MAX_NUM_BREAK_POINTS,
+ ". Command ignored.\n");
+ }
+ else if ((*COMMAND) != '\0')
+ (void) printf("Expected end of statement, found '%s'. Ignoring command.\n"
+ ,COMMAND);
+ else
+ if (BREAK_POINTS[NUM] == -1)
+ PRINT_CONSTANT("Break point ",NUM," is not set. Command ignored.\n");
+ else {
+ for (BP=1;
+ ((SORTED_BREAK_POINTS[BP] != NUM) && (BP <= NUM_BREAK_POINTS));
+ BP++);
+ BREAK_POINTS[NUM] = -1;
+ for (;BP <= NUM_BREAK_POINTS; BP ++)
+ SORTED_BREAK_POINTS[BP] = SORTED_BREAK_POINTS[BP+1];
+ NUM_BREAK_POINTS --;
+ PRINT_CONSTANT("Removed break point ",NUM,".\n");
+ }
+ }
+
+ /* ------------------------------ AT_BREAK_POINT (local) ------------------- */
+ /* returns TRUE iff PC points to an instruction that has a byte in it that */
+ /* has been set as a break point. */
+ BOOLEAN AT_BREAK_POINT(void)
+ {
+ /* Binary Searches the sorted array of break_points for the breakpoint */
+ int MID;
+ int HIGH;
+ int LOW = 1;
+ int RANGE; /* How many bytes the instruction is */
+
+ if (NUM_BREAK_POINTS == 0) return FALSE_1;
+ HIGH = NUM_BREAK_POINTS;
+ PRINT_INSTRUCTION(PC_0,FALSE_1,&RANGE);
+ do {
+ MID = (LOW + HIGH)/2;
+ if ((BREAK_POINTS[SORTED_BREAK_POINTS[MID]] >= PC_0) &&
+ (BREAK_POINTS[SORTED_BREAK_POINTS[MID]] <= PC_0 + RANGE - 1))
+ return TRUE_1;
+ if (BREAK_POINTS[SORTED_BREAK_POINTS[MID]] <= PC_0)
+ LOW = MID + 1;
+ else HIGH = MID - 1;
+ } while (LOW <= HIGH);
+ return FALSE_1;
+ }
+
+ /* ---------------------------- RUN_IT (local) ----------------------------- */
+ /* DEBUGGER COMMAND. */
+ /* Set up the machine for execution of the proceedure and keep executing */
+ /* instructions until it stops or hits a break point. */
+ void RUN_IT(char *COMMAND,BOOLEAN *LEGAL)
+ {
+ REMOVE_WS(&COMMAND);
+ (*LEGAL) = TRUE_1;
+
+ if ((*COMMAND) != '\0')
+ (void) printf("Expected end of statement, found '%s'. Ignoring command.\n"
+ ,COMMAND);
+ else {
+ int DONT_CARE;
+
+ RETURN_STATUS = EXECUTING_1;
+ L_0 = RETURN_TO_OS_1;
+ PC_0 = START_ADDRESS;
+ RESET_DEVICES();
+
+ SW_0 = 61440; /* 00000001111000000000000 binary = 61440 decimal */
+ /* User mode, Running, PID = 0, CC = 0, MASK = 1111, ICODE = 0 */
+ if (TRACE) PRINT_INSTRUCTION(PC_0,TRUE_1,&DONT_CARE);
+ while ((RETURN_STATUS == EXECUTING_1) && !AT_BREAK_POINT()) {
+ EXEC(TRUE_1,TRACE);
+ if ((TRACE) && (RETURN_STATUS == EXECUTING_1)) {
+ (void) printf("\n");
+ PRINT_INSTRUCTION(PC_0,TRUE_1,&DONT_CARE);
+ }
+ }
+ if (RETURN_STATUS == EXECUTING_1)
+ PRINT_ADDRESS("Break point encountered at ",PC_0,".\n");
+ }
+ }
+
+ /* ---------------------------- PROCEED (local) ---------------------------- */
+ /* DEBUGGER COMMAND. */
+ /* Continue execution a program from a break point until the program */
+ /* terminates or another break point is found. */
+ void PROCEED(char *COMMAND,BOOLEAN *LEGAL)
+ {
+ int DONT_CARE;
+
+ REMOVE_WS(&COMMAND);
+ (*LEGAL) = TRUE_1;
+
+ if ((*COMMAND) != '\0')
+ (void) printf("Expected end of statement, found '%s'. Ignoring command.\n"
+ ,COMMAND);
+ else {
+
+ if (RETURN_STATUS != EXECUTING_1)
+ (void) printf("Can not continue. Instruction ignored.\n");
+ else
+ do {
+ EXEC(TRUE_1,TRACE);
+ if ((TRACE) && (RETURN_STATUS == EXECUTING_1)) {
+ (void) printf("\n");
+ PRINT_INSTRUCTION(PC_0,TRUE_1,&DONT_CARE);
+ }
+ } while ((RETURN_STATUS == EXECUTING_1) && !AT_BREAK_POINT());
+
+ if (RETURN_STATUS == EXECUTING_1)
+ PRINT_ADDRESS("Break point encountered at ",PC_0,".\n");
+ }
+ }
+
+ /* ---------------------------- EXAMINE (local) ---------------------------- */
+ /* DEBUGGER COMMAND. */
+ /* Execute on instruction, printing the result and the next instruction to */
+ /* execute. */
+ void STEP(char *COMMAND,BOOLEAN *LEGAL)
+ {
+ int DONT_CARE;
+
+ REMOVE_WS(&COMMAND);
+ (*LEGAL) = TRUE_1;
+
+ if ((*COMMAND) != '\0')
+ (void) printf("Expected end of statement, found '%s'. Ignoring command.\n"
+ ,COMMAND);
+ else {
+
+ if (RETURN_STATUS != EXECUTING_1)
+ (void) printf("Can not continue. Instruction ignored.\n");
+ else {
+ EXEC(TRUE_1,TRUE_1);
+ (void) printf("\n");
+ if (RETURN_STATUS == EXECUTING_1)
+ PRINT_INSTRUCTION(PC_0,TRUE_1,&DONT_CARE);
+ }
+
+ }
+ }
+
+ /* ------------------------------- HELP (local) ---------------------------- */
+ /* DEBUGGER COMMAND. */
+ /* Prints out the debuggers help message. */
+ void HELP(char *COMMAND,BOOLEAN *LEGAL)
+ {
+ REMOVE_WS(&COMMAND);
+ (*LEGAL) = TRUE_1;
+ if ((*COMMAND) != '\0')
+ (void) printf("Expected end of statement, found '%s'. Ignoring command.\n"
+ ,COMMAND);
+ else {
+ (void) printf("List of commands:\n");
+ (void) printf(" Short Long Function\n\n");
+ (void) printf(" B<addr> BREAK<addr> Set break point at <addr>.\n");
+ (void) printf(" B? BREAK? List out the break points.\n");
+ (void) printf(" H HELP Displays this table.\n");
+ (void) printf(
+ " L<loc> LOC<loc> Examines contents of memory and registers.\n");
+ (void) printf(
+ " L<loc>=<v> LOC<loc>=<v> Examines contents of memory and registers.\n");
+ (void) printf(" M<mode> MODE<mode> Set type out mode.\n");
+ (void) printf(" P PROCEED Proceed from break point.\n");
+ (void) printf(" Q QUIT Exit Debugger.\n");
+ (void) printf(
+ " R RUN Start execution at entry point.\n");
+ (void) printf(" RB<num> RESET<num> Remve break point <num>.\n");
+ (void) printf(" S STEP Execute one instruction.\n");
+ (void) printf(" T TRACE Trace the execution.\n");
+ (void) printf(
+ " U UNTRACE Stop tracing the execution.\n");
+ (void) printf("\n");
+ (void) printf("<addr> = memory address or label.\n");
+ (void) printf("<loc> = memory address, label or register.\n");
+ (void) printf(
+ "<mode> = H (hexidecimal), D (decimal), or I (instruction).\n");
+ (void) printf(
+ "<v> = hexidecimal number, decimal number, or 1 character.\n\n");
+ }
+ }
+
+ /* ---------------------------- EXAMINE (local) ---------------------------- */
+ /* DEBUGGER COMMAND. */
+ /* Tells the debugger that the user wish to terminate the debugging session. */
+ void QUIT(char *COMMAND,BOOLEAN *LEGAL)
+ {
+ (*LEGAL) = TRUE_1;
+ REMOVE_WS(&COMMAND);
+ if ((*COMMAND) != '\0')
+ (void) printf("Expected end of statement, found '%s'. Ignoring command.\n"
+ ,COMMAND);
+ else {
+ RETURN_STATUS = QUIT_1;
+ }
+ }
+
+ /* ---------------------------- TRACE_P (local) ---------------------------- */
+ /* DEBUGGER COMMAND. */
+ /* Turns on the tracing mode. */
+ void TRACE_P(char *COMMAND,BOOLEAN *LEGAL)
+ {
+ (*LEGAL) = TRUE_1;
+ REMOVE_WS(&COMMAND);
+ if ((*COMMAND) != '\0')
+ (void) printf("Expected end of statement, found '%s'. Ignoring command.\n"
+ ,COMMAND);
+ else
+ if (TRACE) (void) printf("Trace is already on.\n");
+ else {
+ TRACE = TRUE_1;
+ (void) printf("Trace is now on.\n");
+ }
+ }
+
+ /* --------------------------- UNTRACE_P (local) --------------------------- */
+ /* DEBUGGER COMMAND. */
+ /* Turns off tracing mode. */
+ void UNTRACE(char *COMMAND,BOOLEAN *LEGAL)
+ {
+ (*LEGAL) = TRUE_1;
+ REMOVE_WS(&COMMAND);
+ if ((*COMMAND) != '\0')
+ (void) printf("Expected end of statement, found '%s'. Ignoring command.\n"
+ ,COMMAND);
+ else
+ if (!TRACE) (void) printf("Trace is already off.\n");
+ else {
+ TRACE = FALSE_1;
+ (void) printf("Trace is now off.\n");
+ }
+ }
+
+ /* ------------------------------ MODE (local) ----------------------------- */
+ /* DEBUGGER COMMAND. */
+ /* Set the type out mode [(H)exidecimal, (D)ecimal, (I)nstruction] */
+ void MODE(char *COMMAND,BOOLEAN *LEGAL)
+ {
+ (*LEGAL) = TRUE_1;
+ REMOVE_WS(&COMMAND);
+ if (*COMMAND == '\0')
+ (void) printf("Unexpected end of command. Ignoring command.\n");
+ else {
+ if (*(COMMAND+1) == '\0')
+ switch (*COMMAND) {
+ case 'H':
+ (void) strcpy(TYPE_OUT_MODE,"Hex");
+ return;
+ break;
+ case 'D':
+ (void) strcpy(TYPE_OUT_MODE,"Dec");
+ return;
+ break;
+ case 'I':
+ (void) strcpy(TYPE_OUT_MODE,"Instr");
+ return;
+ break;
+ default: ;
+ }
+
+ (void) printf(
+ "Expected valid mode (H,D, or I). Found %s. Ignoring command.\n",
+ COMMAND);
+ }
+ }
+
+ /* ---------------------- CAPITALIZE_STRING -------------------------------- */
+ /* Make all lower case letters in the string STR upper case letters */
+ void CAPITALIZE_STRING(char STR[])
+ {
+ int I;
+ for (I=0; I<= (strlen(STR)); I++)
+ if ((STR[I] >= 'a') && (STR[I] <= 'z'))
+ STR[I] = STR[I] - 'a' + 'A';
+ }
+
+
+ #define STEP0 1
+ #define SET_BP0 2
+ #define EXAMINE0 3
+ #define RESET_BP0 4
+ #define RUN_IT0 5
+ #define HELP0 6
+ #define MODE0 7
+ #define PROCEED0 8
+ #define TRACE_P0 9
+ #define UNTRACE0 10
+ #define QUIT0 11
+
+ /* ~~~~~~~~~~~~~~~~~~~~~~ Table with the debugger commands */
+ #define COM_TAB_SIZE_1 11
+ struct COMMAND_TYPE {
+ char *SHORT; /* Short version of command. */
+ char *LONG; /* Long version of the command. */
+ int FUNCTION;
+ } COMMANDS[COM_TAB_SIZE_1] =
+ {{"S","STEP",STEP0},
+ {"B","BREAK",SET_BP0},
+ {"L","LOC",EXAMINE0},
+ {"RB","RESET",RESET_BP0},
+ {"R","RUN",RUN_IT0},
+ {"H","HELP",HELP0},
+ {"M","MODE",MODE0},
+ {"P","PROCEED",PROCEED0},
+ {"T","TRACE",TRACE_P0},
+ {"U","UNTRACE",UNTRACE0},
+ {"Q","QUIT",QUIT0}};
+
+ void CALL_FUNCTION(int FUNC,char *COMMAND,BOOLEAN *LEGAL)
+ {
+ switch(FUNC) {
+ case STEP0: STEP(COMMAND,LEGAL);
+ break;
+ case SET_BP0: SET_BP(COMMAND,LEGAL);
+ break;
+ case EXAMINE0: EXAMINE(COMMAND,LEGAL);
+ break;
+ case RESET_BP0: RESET_BP(COMMAND,LEGAL);
+ break;
+ case RUN_IT0: RUN_IT(COMMAND,LEGAL);
+ break;
+ case HELP0: HELP(COMMAND,LEGAL);
+ break;
+ case MODE0: MODE(COMMAND,LEGAL);
+ break;
+ case PROCEED0: PROCEED(COMMAND,LEGAL);
+ break;
+ case TRACE_P0: TRACE_P(COMMAND,LEGAL);
+ break;
+ case UNTRACE0: UNTRACE(COMMAND,LEGAL);
+ break;
+ case QUIT0: QUIT(COMMAND,LEGAL);
+ break;
+ }
+ }
+ /* -------------------------------- DEBUGGER ------------------------------- */
+ /* Drives the entire simulatation/debugging process. */
+ void DEBUGGER(BOOLEAN DEBUG_MODE)
+ {
+ char *COMMAND; /* The debugging command. */
+ BOOLEAN LEGAL_COMMAND; /* Is this a recognized command? */
+ int COUNT; /* Loop counter. */
+
+ for (COUNT=0; COUNT <= MAX_NUM_BREAK_POINTS; COUNT ++)
+ BREAK_POINTS[COUNT] = -1;
+
+ if (!DEBUG_MODE) {
+ /* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~ No Debugging, just execute it */
+ RETURN_STATUS = EXECUTING_1;
+ L_0 = RETURN_TO_OS_1;
+ PC_0 = START_ADDRESS;
+
+ SW_0 = 61440; /* 00000001111000000000000 binary = 61440 decimal */
+ /* User mode, Running, PID = 0, CC = 0, MASK = 1111, ICODE = 0 */
+ EXEC(FALSE_1,FALSE_1);
+ } else
+ /* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Debug the program. */
+ while (RETURN_STATUS != QUIT_1) {
+ LEGAL_COMMAND = FALSE_1;
+ (void) printf("%s> ",TYPE_OUT_MODE);
+ GET_LINE(&COMMAND,stdin);
+ REMOVE_WS(&COMMAND);
+ if ((*COMMAND) != '\0') {
+ CAPITALIZE_STRING(COMMAND);
+
+ for (COUNT=0; (COUNT < COM_TAB_SIZE_1) && !LEGAL_COMMAND; COUNT++)
+ if (IS_PREFIX_TO(COMMANDS[COUNT].LONG,COMMAND))
+ CALL_FUNCTION(COMMANDS[COUNT].FUNCTION,
+ &(COMMAND[strlen(COMMANDS[COUNT].LONG)]),
+ &LEGAL_COMMAND);
+ else if (IS_PREFIX_TO(COMMANDS[COUNT].SHORT,COMMAND))
+ CALL_FUNCTION(COMMANDS[COUNT].FUNCTION,
+ &(COMMAND[strlen(COMMANDS[COUNT].SHORT)]),
+ &LEGAL_COMMAND);
+
+ if (!LEGAL_COMMAND) {
+ (void) printf("'%s' is not a legal command. Ignoring it.\n",COMMAND);
+ (void) printf("Type HELP for the list of legal commands.\n");
+ }
+ }
+ if (RETURN_STATUS == ABNORMAL_1) {
+ int CODE;
+
+ RETURN_STATUS = HALT_1;
+ CODE = SW_0 - (SW_0/256)*256;
+ PRINT_CONSTANT("error code =",CODE," ");
+ switch (CODE) {
+ case 0: (void) printf("Illegal instruction.\n"); break;
+ case 1: (void) printf("Privileged instruction in user mode.\n"); break;
+ case 2: (void) printf("Address out of range.\n"); break;
+ case 3: (void) printf("Memory-protection violation.\n"); break;
+ case 4: (void) printf("Aritmetic overflow.\n"); break;
+ case 10: (void) printf("Page fault.\n"); break;
+ case 11: (void) printf("Segment fault.\n"); break;
+ case 12: (void) printf("Segment-protection violation.\n"); break;
+ case 13: (void) printf("Segment length exceeded.\n"); break;
+ default: (void) printf("\n"); break;
+ }
+ }
+ }
+ }
Index: llvm-test/MultiSource/Benchmarks/Prolangs-C/simulator/debugger.h
diff -c /dev/null llvm-test/MultiSource/Benchmarks/Prolangs-C/simulator/debugger.h:1.1
*** /dev/null Tue Oct 5 16:08:51 2004
--- llvm-test/MultiSource/Benchmarks/Prolangs-C/simulator/debugger.h Tue Oct 5 16:08:39 2004
***************
*** 0 ****
--- 1,31 ----
+ /* %%%%%%%%%%%%%%%%%%%% (c) William Landi 1991 %%%%%%%%%%%%%%%%%%%%%%%%%%%% */
+ /* Permission to use this code is granted as long as the copyright */
+ /* notice remains in place. */
+ /* =============================== debugger.h ============================== */
+ /* Drives the whole simulatation/debugging process. Contains the debugging */
+ /* Routines and calls the simulation routines (else where defined). */
+ #include "sym_tab.h"
+ /* ---------------------------------- Globals ------------------------------ */
+ /* MAIN_ROUTINE Name of (program) module declared with */
+ /* a START (main routine). */
+ extern char MAIN_ROUTINE[LABEL_SIZE_1+1];
+
+ /* START_ADDRESS Location where execution begins */
+ extern int START_ADDRESS;
+
+ /* SYM_TAB The symbol table */
+ extern SYMBOL_TABLE SYM_TAB;
+
+ /* RETURN_STATUS Status of machine when control returned*/
+ extern int RETURN_STATUS; /* to debugger. */
+
+ /* TYPE_OUT_MODE Remembers the type out mode */
+ char TYPE_OUT_MODE[6];
+
+ /* ------------------------------- Procedures ------------------------------ */
+ /* -------------------------------- DEBUGGER ------------------------------- */
+ /* 1 parameter: */
+ /* 1) BOOLEAN DEBUG_MODE; TRUE => Debugging. FALSE => just simulating */
+ /* Drives the entire simulatation/debugging process. */
+ extern void DEBUGGER ();
+
Index: llvm-test/MultiSource/Benchmarks/Prolangs-C/simulator/define-instr-tab.h
diff -c /dev/null llvm-test/MultiSource/Benchmarks/Prolangs-C/simulator/define-instr-tab.h:1.1
*** /dev/null Tue Oct 5 16:08:51 2004
--- llvm-test/MultiSource/Benchmarks/Prolangs-C/simulator/define-instr-tab.h Tue Oct 5 16:08:39 2004
***************
*** 0 ****
--- 1,127 ----
+ /* %%%%%%%%%%%%%%%%%%%% (c) William Landi 1991 %%%%%%%%%%%%%%%%%%%%%%%%%%%% */
+ /* Permission to use this code is granted as long as the copyright */
+ /* notice remains in place. */
+ /*============================ define-instr-tab.h ======================= */
+ /* A table for quick (constant time) look up of MNEMONIC, FORMAT, and */
+ /* the function that knows what to do with an instruction give its code. */
+
+ struct INSTR_INFO {
+ char *MNEMONIC;
+ int FORMAT;
+ int FUNCTION;
+ };
+
+
+ #define LDA_P0 22
+ #define LDX_P0 1
+ #define LDL_P0 2
+ #define STA_P0 3
+ #define STX_P0 4
+ #define STL_P0 5
+ #define ADD_P0 6
+ #define SUB_P0 7
+ #define MUL_P0 8
+ #define DIV_P0 9
+ #define COMP_P0 10
+ #define TIX_P0 11
+ #define JEQ_P0 12
+ #define JGT_P0 13
+ #define JLT_P0 14
+ #define J_P0 15
+ #define AND_P0 16
+ #define OR_P0 17
+ #define JSUB_P0 18
+ #define RSUB_P0 19
+ #define LDCH_P0 20
+ #define STCH_P0 21
+ #define NULL0 0
+ #define LDB_P0 23
+ #define LDS_P0 24
+ #define LDT_P0 25
+ #define STB_P0 26
+ #define STS_P0 27
+ #define STT_P0 28
+ #define ADDR_P0 29
+ #define SUBR_P0 30
+ #define MULR_P0 31
+ #define DIVR_P0 32
+ #define COMPR_P0 33
+ #define SHIFTL_P0 34
+ #define SHIFTR_P0 35
+ #define RMO_P0 36
+ #define SVC_P0 37
+ #define CLEAR_P0 38
+ #define TIXR_P0 39
+ #define STI_P0 40
+ #define RD_P0 41
+ #define WD_P0 42
+ #define TD_P0 43
+ #define STSW_P0 44
+
+
+ #define INSTR_TAB_SIZE_1 64
+ struct INSTR_INFO INSTR[INSTR_TAB_SIZE_1] =
+ {{"LDA",3,LDA_P0}, /* Opcode = 00 */
+ {"LDX",3,LDX_P0}, /* Opcode = 04 */
+ {"LDL",3,LDL_P0}, /* Opcode = 08 */
+ {"STA",3,STA_P0}, /* Opcode = 0C */
+ {"STX",3,STX_P0}, /* Opcode = 10 */
+ {"STL",3,STL_P0}, /* Opcode = 14 */
+ {"ADD",3,ADD_P0}, /* Opcode = 18 */
+ {"SUB",3,SUB_P0}, /* Opcode = 1C */
+ {"MUL",3,MUL_P0}, /* Opcode = 20 */
+ {"DIV",3,DIV_P0}, /* Opcode = 24 */
+ {"COMP",3,COMP_P0}, /* Opcode = 28 */
+ {"TIX",3,TIX_P0}, /* Opcode = 2C */
+ {"JEQ",3,JEQ_P0}, /* Opcode = 30 */
+ {"JGT",3,JGT_P0}, /* Opcode = 34 */
+ {"JLT",3,JLT_P0}, /* Opcode = 38 */
+ {"J",3,J_P0}, /* Opcode = 3C */
+ {"AND",3,AND_P0}, /* Opcode = 40 */
+ {"OR",3,OR_P0}, /* Opcode = 44 */
+ {"JSUB",3,JSUB_P0}, /* Opcode = 48 */
+ {"RSUB",3,RSUB_P0}, /* Opcode = 4C */
+ {"LDCH",3,LDCH_P0}, /* Opcode = 50 */
+ {"STCH",3,STCH_P0}, /* Opcode = 54 */
+ {"ADDF",3,NULL0}, /* Opcode = 58 */
+ {"SUBF",3,NULL0}, /* Opcode = 5C */
+ {"MULF",3,NULL0}, /* Opcode = 60 */
+ {"DIVF",3,NULL0}, /* Opcode = 64 */
+ {"LDB",3,LDB_P0}, /* Opcode = 68 */
+ {"LDS",3,LDS_P0}, /* Opcode = 6C */
+ {"LDF",3,NULL0}, /* Opcode = 70 */
+ {"LDT",3,LDT_P0}, /* Opcode = 74 */
+ {"STB",3,STB_P0}, /* Opcode = 78 */
+ {"STS",3,STS_P0}, /* Opcode = 7C */
+ {"STF",3,NULL0}, /* Opcode = 80 */
+ {"STT",3,STT_P0}, /* Opcode = 84 */
+ {"COMPF",3,NULL0}, /* Opcode = 88 */
+ {"UNDEF",1,NULL0}, /* Opcode = 8C */
+ {"ADDR",2,ADDR_P0}, /* Opcode = 90 */
+ {"SUBR",2,SUBR_P0}, /* Opcode = 94 */
+ {"MULR",2,MULR_P0}, /* Opcode = 98 */
+ {"DIVR",2,DIVR_P0}, /* Opcode = 9C */
+ {"COMPR",2,COMPR_P0}, /* Opcode = A0 */
+ {"SHIFTL",2,SHIFTL_P0}, /* Opcode = A4 */
+ {"SHIFTR",2,SHIFTR_P0}, /* Opcode = A8 */
+ {"RMO",2,RMO_P0}, /* Opcode = AC */
+ {"SVC",2,SVC_P0}, /* Opcode = B0 */
+ {"CLEAR",2,CLEAR_P0}, /* Opcode = B4 */
+ {"TIXR",2,TIXR_P0}, /* Opcode = B8 */
+ {"UNDEF",1,NULL0}, /* Opcode = BC */
+ {"FLOAT",1,NULL0}, /* Opcode = C0 */
+ {"FIX",1,NULL0}, /* Opcode = C4 */
+ {"NORM",1,NULL0}, /* Opcode = C8 */
+ {"UNDEF",1,NULL0}, /* Opcode = CC */
+ {"LPS",3,NULL0}, /* Opcode = D0 */
+ {"STI",3,STI_P0}, /* Opcode = D4 */
+ {"RD",3,RD_P0}, /* Opcode = D8 */
+ {"WD",3,WD_P0}, /* Opcode = DC */
+ {"TD",3,TD_P0}, /* Opcode = E0 */
+ {"UNDEF",1,NULL0}, /* Opcode = E4 */
+ {"STSW",3,STSW_P0}, /* Opcode = E8 */
+ {"SSK",3,NULL0}, /* Opcode = EC */
+ {"SIO",1,NULL0}, /* Opcode = F0 */
+ {"HIO",1,NULL0}, /* Opcode = F4 */
+ {"TIO",1,NULL0}, /* Opcode = F8 */
+ {"UNDEF",1,NULL0}}; /* Opcode = FC */
Index: llvm-test/MultiSource/Benchmarks/Prolangs-C/simulator/format.c
diff -c /dev/null llvm-test/MultiSource/Benchmarks/Prolangs-C/simulator/format.c:1.1
*** /dev/null Tue Oct 5 16:08:51 2004
--- llvm-test/MultiSource/Benchmarks/Prolangs-C/simulator/format.c Tue Oct 5 16:08:39 2004
***************
*** 0 ****
--- 1,155 ----
+ /* %%%%%%%%%%%%%%%%%%%% (c) William Landi 1991 %%%%%%%%%%%%%%%%%%%%%%%%%%%% */
+ /* Permission to use this code is granted as long as the copyright */
+ /* notice remains in place. */
+
+ /* =============================== format.c ================================ */
+ /* Returns the registers associtiated with a FORMAT2 instruction (handles */
+ /* BITS 8-15) and the Address or value associated with a FORMAT3/FORMAT4 */
+ /* instruction (handles BITS 6-23 or BITS 6-31). */
+
+ #include <math.h>
+ #include "boolean.h"
+ #include "memory.h"
+ #include "machine.h"
+ #include "convert.h"
+ #include "constants.h"
+ #include "instruct.h"
+ #include "interupt.h"
+
+
+ /* ------------------------------ FORMAT2 ---------------------------------- */
+ /* Handles bits 8-15 of format 2 instruction. Puts bits 8-11 in REG1, bits */
+ /* 12-15 in REG2 and updates PC. */
+ void FORMAT2(int *REG1,int *REG2)
+ {
+ (*REG1) = INT(MEMORY[PC_0+1]) / 16;
+ (*REG2) = INT(MEMORY[PC_0+1]) - (*REG1) * 16;
+ PC_0 += 2;
+ }
+
+
+ /* ----------------------------- FORMAT3_4 --------------------------------- */
+ /* Handles bits 6-23 for format 3 instructions, and bits 5-31 for format 4 */
+ /* instructions. Updates PC and returns ADDRESS or VALUE of the operand */
+ /* Depending on demand. */
+ int FORMAT3_4(int DEMAND,int BYTES)
+ {
+ int INSTR[4*BITS_PER_BYTE_2]; /* BIT for of the instruction. */
+
+ BOOLEAN RANGE_ERROR = FALSE_1; /* TRUE iff an illegal address is found. */
+ int FORMAT = 3; /* Format 3 or format 4 instruction. */
+ int ADDRESS; /* Address specified by instruction. */
+ int VALUE; /* Value specified by instruction */
+
+ if (PC_0+2 >= MEM_SIZE_1) RANGE_ERROR = TRUE_1;
+ else {
+ BYTES_TO_BITS(INT(MEMORY[PC_0]),1,INSTR);
+ BYTES_TO_BITS(INT(MEMORY[PC_0+1]),1,&(INSTR[8]));
+ BYTES_TO_BITS(INT(MEMORY[PC_0+2]),1,&(INSTR[16]));
+
+ /* ------------------ if expended format bit on and not plane SIC -----------*/
+ if ((INSTR[11] == 1) && !((INSTR[6] == 0) && (INSTR[7] == 0)))
+ if (PC_0+3 >= MEM_SIZE_1) RANGE_ERROR = TRUE_1;
+ else {
+ BYTES_TO_BITS(INT(MEMORY[PC_0+3]),1,&(INSTR[24]));
+ FORMAT = 4;
+ }
+ }
+
+ /* ------------ Check for Address out of range error */
+ if (RANGE_ERROR) {
+ SIGNAL_INTERUPT(2,02);
+ return (0);
+ }
+
+ PC_0 += FORMAT;
+ /* ------- if plane SIC ---------------------------------------------------- */
+ if ((INSTR[6] == 0) && (INSTR[7] == 0))
+ ADDRESS = BITS_TO_BYTE(&(INSTR[12]),12);
+ else if (FORMAT == 3) {
+ ADDRESS = BITS_TO_BYTE(&(INSTR[12]),12);
+ /* ------------ Check for Illegal instruction */
+ if ((INSTR[9] == 1) && (INSTR[10] == 1)) {
+ SIGNAL_INTERUPT(2,00);
+ return (0);
+ }
+ if (INSTR[8] == 1) ADDRESS += X_0;
+ if (INSTR[9] == 1) ADDRESS += B_0;
+ if (INSTR[10] == 1) {
+ if (ADDRESS >= MAX_PC_RELATIVE_1 / 2)
+ ADDRESS = (ADDRESS - MAX_PC_RELATIVE_1) + PC_0;
+ else ADDRESS += PC_0;
+ }
+ } else {
+ /* ~~~~~~~~~~~~~~~~~~~~~~ FORMAT 4 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
+ /* ------------ Check for Illegal instruction */
+ if ((INSTR[9] == 1) || (INSTR[10] == 1)) {
+ SIGNAL_INTERUPT(2,00);
+ return (0);
+ }
+ ADDRESS = BITS_TO_BYTE(&(INSTR[12]),20);
+ if (INSTR[8] == 1) ADDRESS += X_0;
+ }
+
+ /* ~~~~~~~~~~~~~~~~~~~~~~~ DIRECT ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
+ if ((INSTR[6] == 1) && (INSTR[7] == 1)) {
+
+ if (DEMAND == VALUE_1) {
+ int I;
+
+ /* ------------ Check for Illegal instruction */
+ if ((ADDRESS < 0) || (ADDRESS+2 >= MEM_SIZE_1)) {
+ SIGNAL_INTERUPT(2,00);
+ return (0);
+ }
+
+ VALUE = 0;
+ for (I = 0; I < BYTES; I ++)
+ VALUE = VALUE * 256 + INT(MEMORY[ADDRESS + I]);
+
+ /* -------------- If unitialized value that will not fit in SIC/XE make it 0 */
+ if (VALUE >= (int) pow(2.0,BITS_PER_WORD_1*1.0)) VALUE = 0;
+ return VALUE;
+ } else return ADDRESS;
+ }
+
+ /* ~~~~~~~~~~~~~~~~~~~~~~~ INDIRECT ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
+ if ((INSTR[6] == 1) && (INSTR[7] == 0)) {
+ /* ------------ Check for Illegal instruction */
+ if ((ADDRESS < 0) || (ADDRESS+2 >= MEM_SIZE_1)) {
+ SIGNAL_INTERUPT(2,00);
+ return (0);
+ }
+ ADDRESS = (((INT(MEMORY[ADDRESS]) * 256) + INT(MEMORY[ADDRESS+1]))*256 +
+ INT(MEMORY[ADDRESS+2]));
+
+ if (DEMAND == VALUE_1) {
+ int I;
+
+ /* ------------ Check for Address out of range error */
+ if (ADDRESS > MEM_SIZE_1) {
+ SIGNAL_INTERUPT(2,02);
+ return (0);
+ }
+
+ VALUE = 0;
+ for (I = 0; I < BYTES; I ++)
+ VALUE = VALUE * 256 + INT(MEMORY[ADDRESS + I]);
+
+ /* -------------- If unitialized value that will not fit in SIC/XE make it 0 */
+ if (VALUE >= (int) pow(2.0,BITS_PER_WORD_1*1.0)) VALUE = 0;
+ return VALUE;
+ } else return ADDRESS;
+ }
+
+ /* ~~~~~~~~~~~~~~~~~~~~~~~ Immediate ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
+ if ((INSTR[6] == 0) && (INSTR[7] == 1)) {
+ /* ------------ Check for Illegal instruction */
+ if (ADDRESS >= (int) pow(2.0,BITS_PER_WORD_1*1.0)) {
+ SIGNAL_INTERUPT(2,00);
+ return (0);
+ }
+ return (ADDRESS);
+ }
+ return(0); /* This will never be executed, but to keep lint happy */
+ }
Index: llvm-test/MultiSource/Benchmarks/Prolangs-C/simulator/format.h
diff -c /dev/null llvm-test/MultiSource/Benchmarks/Prolangs-C/simulator/format.h:1.1
*** /dev/null Tue Oct 5 16:08:51 2004
--- llvm-test/MultiSource/Benchmarks/Prolangs-C/simulator/format.h Tue Oct 5 16:08:39 2004
***************
*** 0 ****
--- 1,26 ----
+ /* %%%%%%%%%%%%%%%%%%%% (c) William Landi 1991 %%%%%%%%%%%%%%%%%%%%%%%%%%%% */
+ /* Permission to use this code is granted as long as the copyright */
+ /* notice remains in place. */
+ /* =============================== format.h ================================ */
+ /* Returns the registers associtiated with a FORMAT2 instruction (handles */
+ /* BITS 8-15) and the Address or value associated with a FORMAT3/FORMAT4 */
+ /* instruction (handles BITS 6-23 or BITS 6-31). */
+
+
+ /* ------------------------------ FORMAT2 ---------------------------------- */
+ /* 2 parameters: */
+ /* 1) int *REG1; See bellow */
+ /* 2) int *REG2; See bellow */
+ /* Handles bits 8-15 of format 2 instruction. Puts bits 8-11 in REG1, bits */
+ /* 12-15 in REG2 and updates PC. */
+ extern int FORMAT2();
+
+ /* ----------------------------- FORMAT3_4 --------------------------------- */
+ /* 2 parameters: */
+ /* 1) int DEMAND; Do you want the VALUE_1 or ADDRESS_1? */
+ /* 2) int BYTES; If want a value, how many bytes do you */
+ /* need? */
+ /* Handles bits 6-23 for format 3 instructions, and bits 5-31 for format 4 */
+ /* instructions. Updates PC and returns ADDRESS or VALUE of the operand */
+ /* Depending on demand. */
+ extern int FORMAT3_4();
Index: llvm-test/MultiSource/Benchmarks/Prolangs-C/simulator/instruct.c
diff -c /dev/null llvm-test/MultiSource/Benchmarks/Prolangs-C/simulator/instruct.c:1.1
*** /dev/null Tue Oct 5 16:08:51 2004
--- llvm-test/MultiSource/Benchmarks/Prolangs-C/simulator/instruct.c Tue Oct 5 16:08:39 2004
***************
*** 0 ****
--- 1,784 ----
+ /* %%%%%%%%%%%%%%%%%%%% (c) William Landi 1991 %%%%%%%%%%%%%%%%%%%%%%%%%%%% */
+ /* Permission to use this code is granted as long as the copyright */
+ /* notice remains in place. */
+
+ /* =============================== intruction.c ============================ */
+ /* Contains all the procedures that know how to handle FORMAT3/4 instructions*/
+ /* Name of the procedure is the same as the SIC/XE instruction name but with */
+ /* a '_P' added to the end. See p. 410-411 of "System Software: An */
+ /* Introduction to Systems Programming" by Leland L. Beck for detailed */
+ /* Description to the function of each command. */
+
+ #include <math.h>
+ #include "boolean.h"
+ #include "debugger.h"
+ #include "memory.h"
+ #include "machine.h"
+ #include "convert.h"
+ #include "format.h"
+ #include "interupt.h"
+
+ #define MAX_BYTE_VAL_0 256
+
+ /* ---------------------------------- ADD_P -------------------------------- */
+ /* This proceedure is messy because work had to be done with the signs of */
+ /* the arguments so that overflow could be detected. */
+ void ADD_P(BOOLEAN PRINT_EFFECT)
+ {
+ int VALUE; /* Value specified by the parameter. */
+ BOOLEAN OVERFLOW1 = FALSE_1; /* Has an overflow been detected. */
+ int ASIGN = 1; /* Sign of Accumulator */
+ int VALSIGN = 1; /* Sign of VALUE */
+
+ VALUE = FORMAT3_4(VALUE_1,3);
+
+ /* Check if VALUE if an impossible (in SIC/XE) unitialized value */
+ if ((VALUE < 0) || (VALUE >= MAX_INT_1)) VALUE = 0;
+
+ /* --------------- This is needed to correctly dectect overflow ------------ */
+ if (VALUE >= MAX_INT_1 / 2) VALSIGN = -1;
+ if (A_0 >= MAX_INT_1 / 2) ASIGN = -1;
+
+ if ((ASIGN == 1) && (VALSIGN == 1)) {
+ A_0 = A_0 + VALUE;
+ if (A_0 >= MAX_INT_1 / 2) OVERFLOW1 = TRUE_1;
+ }
+ if ((ASIGN == -1) && (VALSIGN == 1)) {
+ A_0 = A_0 + VALUE;
+ A_0 = A_0 - ((int) A_0 / MAX_INT_1) * MAX_INT_1;
+ }
+ if ((ASIGN == 1) && (VALSIGN == -1)) {
+ A_0 = A_0 + VALUE;
+ A_0 = A_0 - ((int) A_0 / MAX_INT_1) * MAX_INT_1;
+ }
+ if ((ASIGN == -1) && (VALSIGN == -1)) {
+ A_0 = A_0 + VALUE;
+ A_0 = A_0 - ((int) A_0 / MAX_INT_1) * MAX_INT_1;
+ if (A_0 < MAX_INT_1 / 2) OVERFLOW1 = TRUE_1;
+ }
+
+ if (PRINT_EFFECT) PRINT_CONSTANT("Set A to ",A_0,".\n");
+ if (OVERFLOW1) SIGNAL_INTERUPT(2,04);
+ }
+
+ /* --------------------------------- AND_P --------------------------------- */
+ /* Bitwise AND of 2 words. */
+ void AND_P(BOOLEAN PRINT_EFFECT)
+ {
+ int VALUE; /* Value specified by the parameter. */
+ int COUNT; /* Loop counter */
+
+ int A_BITS[BITS_PER_WORD_1]; /* BIT form of A */
+ int VAL_BITS[BITS_PER_WORD_1]; /* BIT form of VALUE */
+
+ VALUE = FORMAT3_4(VALUE_1,3);
+
+ /* Check if VALUE if an impossible (in SIC/XE) unitialized value */
+ if ((VALUE < 0) || (VALUE >= MAX_INT_1)) VALUE = 0;
+
+ BYTES_TO_BITS(A_0,3,A_BITS);
+ BYTES_TO_BITS(VALUE,3,VAL_BITS);
+
+ for (COUNT = 0; COUNT < BITS_PER_WORD_1; COUNT ++)
+ A_BITS[COUNT] = A_BITS[COUNT] && VAL_BITS[COUNT];
+
+ A_0 = BITS_TO_BYTE(A_BITS,BITS_PER_WORD_1);
+
+ if (PRINT_EFFECT) PRINT_CONSTANT("Set A to ",A_0,".\n");
+ }
+
+ /* --------------------------------- COMP_P -------------------------------- */
+ void COMP_P(BOOLEAN PRINT_EFFECT)
+ {
+ int VALUE;
+ int A_VAL;
+
+ VALUE = FORMAT3_4(VALUE_1,3);
+
+ if (A_0 >= MAX_INT_1 / 2) A_VAL = A_0 - MAX_INT_1;
+ else A_VAL = A_0;
+
+ if (VALUE >= MAX_INT_1 / 2) VALUE = VALUE - MAX_INT_1;
+
+ if (A_VAL == VALUE) {
+ SET_CC(EQUAL_1);
+ if (PRINT_EFFECT) (void) printf("Set CC to =.\n");
+ }
+ if (A_VAL < VALUE) {
+ SET_CC(LESS_THAN_1);
+ if (PRINT_EFFECT) (void) printf("Set CC to <.\n");
+ }
+ if (A_VAL > VALUE) {
+ SET_CC(GREATER_THAN_1);
+ if (PRINT_EFFECT) (void) printf("Set CC to >.\n");
+ }
+ }
+
+ /* ---------------------------------- DIV_P -------------------------------- */
+ /* This proceedure is messy because work had to be done with the signs of */
+ /* the arguments. */
+ void DIV_P(BOOLEAN PRINT_EFFECT)
+ {
+ int VALUE; /* Value specified by the parameter. */
+ int ASIGN = 1; /* Sign of Accumulator */
+ int VALSIGN = 1; /* Sign of VALUE */
+
+ VALUE = FORMAT3_4(VALUE_1,3);
+
+ /* Check if VALUE if an impossible (in SIC/XE) unitialized value */
+ if ((VALUE < 0) || (VALUE >= MAX_INT_1)) VALUE = 1;
+
+ if (VALUE == 0) {
+ SIGNAL_INTERUPT(2,04);
+ if (PRINT_EFFECT) (void) printf("Attempted division by zero.\n");
+ } else {
+ /* --------------- This is needed to correctly dectect overflow ------------ */
+ if (VALUE >= MAX_INT_1 / 2) VALSIGN = -1;
+ if (A_0 >= MAX_INT_1 / 2) ASIGN = -1;
+
+ if ((ASIGN == 1) && (VALSIGN == 1)) A_0 = A_0 / VALUE;
+ if ((ASIGN == -1) && (VALSIGN == 1))
+ A_0 = MAX_INT_1 - ((MAX_INT_1 - A_0) / VALUE);
+ if ((ASIGN == 1) && (VALSIGN == -1))
+ A_0 = MAX_INT_1 - (A_0 / (MAX_INT_1 - VALUE));
+ if ((ASIGN == -1) && (VALSIGN == -1))
+ A_0 = (MAX_INT_1 - A_0) / (MAX_INT_1 - VALUE);
+
+ if (PRINT_EFFECT) PRINT_CONSTANT("Set A to ",A_0,".\n");
+ }
+ }
+
+ /* ----------------------------------- J_P --------------------------------- */
+ void J_P(BOOLEAN PRINT_EFFECT)
+ {
+ int VALUE;
+
+ VALUE = FORMAT3_4(LOCATION_1,3);
+
+ if ((VALUE < 0) || ((VALUE >= MEM_SIZE_1) && VALUE != RETURN_TO_OS_1)) {
+ SIGNAL_INTERUPT(2,02);
+ if (PRINT_EFFECT) (void) printf("J m, m is an illegal address.\n");
+ } else {
+ PC_0 = VALUE;
+ if (PRINT_EFFECT)
+ if (PC_0 == RETURN_TO_OS_1)
+ (void) printf("Returning to Operating System.\n");
+ else
+ PRINT_ADDRESS("Jump to ",PC_0,"\n");
+ }
+ }
+
+ /* ---------------------------------- JEQ_P -------------------------------- */
+ void JEQ_P(BOOLEAN PRINT_EFFECT)
+ {
+ int VALUE;
+
+ VALUE = FORMAT3_4(LOCATION_1,3);
+
+ if (CC() != EQUAL_1) {
+ if (PRINT_EFFECT) (void) printf("No action taken.\n");
+ } else
+ if ((VALUE < 0) || ((VALUE >= MEM_SIZE_1) && VALUE != RETURN_TO_OS_1)) {
+ SIGNAL_INTERUPT(2,02);
+ if (PRINT_EFFECT) (void) printf("JEQ m, m is an illegal address.\n");
+ } else {
+ PC_0 = VALUE;
+ if (PRINT_EFFECT)
+ if (PC_0 == RETURN_TO_OS_1)
+ (void) printf("Returning to Operating System.\n");
+ else
+ PRINT_ADDRESS("Jump to ",PC_0,"\n");
+ }
+ }
+
+ /* -------------------------------- JGT_P ---------------------------------- */
+ void JGT_P(BOOLEAN PRINT_EFFECT)
+ {
+ int VALUE;
+
+ VALUE = FORMAT3_4(LOCATION_1,3);
+
+ if (CC() != GREATER_THAN_1) {
+ if (PRINT_EFFECT) (void) printf("No action taken.\n");
+ } else
+ if ((VALUE < 0) || ((VALUE >= MEM_SIZE_1) && VALUE != RETURN_TO_OS_1)) {
+ SIGNAL_INTERUPT(2,02);
+ if (PRINT_EFFECT) (void) printf("JGT m, m is an illegal address.\n");
+ } else {
+ PC_0 = VALUE;
+ if (PRINT_EFFECT)
+ if (PC_0 == RETURN_TO_OS_1)
+ (void) printf("Returning to Operating System.\n");
+ else
+ PRINT_ADDRESS("Jump to ",PC_0,"\n");
+ }
+ }
+
+ /* ------------------------------- JLT_P ----------------------------------- */
+ void JLT_P(BOOLEAN PRINT_EFFECT)
+ {
+ int VALUE;
+
+ VALUE = FORMAT3_4(LOCATION_1,3);
+
+ if (CC() != LESS_THAN_1) {
+ if (PRINT_EFFECT) (void) printf("No action taken.\n");
+ } else
+ if ((VALUE < 0) || ((VALUE >= MEM_SIZE_1) && VALUE != RETURN_TO_OS_1)) {
+ SIGNAL_INTERUPT(2,02);
+ if (PRINT_EFFECT) (void) printf("JLT m, m is an illegal address.\n");
+ } else {
+ PC_0 = VALUE;
+ if (PRINT_EFFECT)
+ if (PC_0 == RETURN_TO_OS_1)
+ (void) printf("Returning to Operating System.\n");
+ else
+ PRINT_ADDRESS("Jump to ",PC_0,"\n");
+ }
+ }
+
+ /* --------------------------------- JSUB_P -------------------------------- */
+ void JSUB_P(BOOLEAN PRINT_EFFECT)
+ {
+ int VALUE;
+
+ VALUE = FORMAT3_4(LOCATION_1,3);
+
+ if ((VALUE < 0) || (VALUE >= MEM_SIZE_1)) {
+ SIGNAL_INTERUPT(2,02);
+ if (PRINT_EFFECT) (void) printf("JSUB m, m is an illegal address.\n");
+ } else {
+ L_0 = PC_0;
+ PC_0 = VALUE;
+ if (PRINT_EFFECT) {
+ PRINT_ADDRESS("Put ",L_0," into L and jump to ");
+ PRINT_ADDRESS("",PC_0,".\n");
+ }
+ }
+ }
+
+ /* ------------------------------- LDA_P ----------------------------------- */
+ void LDA_P(BOOLEAN PRINT_EFFECT)
+ {
+ int VALUE;
+
+ VALUE = FORMAT3_4(VALUE_1,3);
+ A_0 = VALUE;
+ if (PRINT_EFFECT) PRINT_CONSTANT("Set A to ",A_0,".\n");
+
+ }
+
+ /* ------------------------------- LDB_P ----------------------------------- */
+ void LDB_P(BOOLEAN PRINT_EFFECT)
+ {
+ int VALUE;
+
+ VALUE = FORMAT3_4(VALUE_1,3);
+ B_0 = VALUE;
+ if (PRINT_EFFECT) PRINT_CONSTANT("Set B to ",B_0,".\n");
+
+ }
+
+ /* ------------------------------- LDCH_P ---------------------------------- */
+ void LDCH_P(BOOLEAN PRINT_EFFECT)
+ {
+ int VALUE;
+
+ VALUE = FORMAT3_4(VALUE_1,1);
+ A_0 = ((int) A_0 / MAX_BYTE_VAL_0) * MAX_BYTE_VAL_0 + VALUE;
+ if (PRINT_EFFECT) PRINT_CONSTANT("Set A to ",A_0,".\n");
+
+ }
+
+ /* ------------------------------- LDL_P ----------------------------------- */
+ void LDL_P(BOOLEAN PRINT_EFFECT)
+ {
+ int VALUE;
+
+ VALUE = FORMAT3_4(VALUE_1,3);
+ L_0 = VALUE;
+ if (PRINT_EFFECT) PRINT_CONSTANT("Set L to ",L_0,".\n");
+
+ }
+
+ /* ------------------------------- LDS_P ----------------------------------- */
+ void LDS_P(BOOLEAN PRINT_EFFECT)
+ {
+ int VALUE;
+
+ VALUE = FORMAT3_4(VALUE_1,3);
+ S_0 = VALUE;
+ if (PRINT_EFFECT) PRINT_CONSTANT("Set S to ",S_0,".\n");
+
+ }
+
+ /* ------------------------------- LDT_P ----------------------------------- */
+ void LDT_P(BOOLEAN PRINT_EFFECT)
+ {
+ int VALUE;
+
+ VALUE = FORMAT3_4(VALUE_1,3);
+ T_0 = VALUE;
+ if (PRINT_EFFECT) PRINT_CONSTANT("Set T to ",T_0,".\n");
+
+ }
+
+ /* ------------------------------- LDX_P ----------------------------------- */
+ void LDX_P(BOOLEAN PRINT_EFFECT)
+ {
+ int VALUE;
+
+ VALUE = FORMAT3_4(VALUE_1,3);
+ X_0 = VALUE;
+ if (PRINT_EFFECT) PRINT_CONSTANT("Set X to ",X_0,".\n");
+
+ }
+
+ /* ---------------------------------- MUL_P -------------------------------- */
+ /* This proceedure is messy because work had to be done with the signs of */
+ /* the arguments so that overflow could be detected. */
+ void MUL_P(BOOLEAN PRINT_EFFECT)
+ {
+ int VALUE; /* Value specified by the parameter. */
+ BOOLEAN OVERFLOW1 = FALSE_1; /* Has an overflow been detected. */
+ int ASIGN = 1; /* Sign of Accumulator */
+ int VALSIGN = 1; /* Sign of VALUE */
+ double STORE_A; /* So the simulator does not overflow */
+
+ VALUE = FORMAT3_4(VALUE_1,3);
+
+ /* Check if VALUE if an impossible (in SIC/XE) unitialized value */
+ if ((VALUE < 0) || (VALUE >= MAX_INT_1)) VALUE = 0;
+
+ /* --------------- This is needed to correctly dectect overflow ------------ */
+ if (VALUE >= MAX_INT_1 / 2) VALSIGN = -1;
+ if (A_0 >= MAX_INT_1 / 2) ASIGN = -1;
+
+ if ((ASIGN == 1) && (VALSIGN == 1)) {
+ STORE_A = (A_0*1.0) * VALUE;
+ if (STORE_A >= MAX_INT_1 / 2) OVERFLOW1 = TRUE_1;
+ else A_0 = (int) STORE_A;
+ }
+ if ((ASIGN == -1) && (VALSIGN == 1)) {
+ STORE_A = 1.0 * (MAX_INT_1 - A_0) * VALUE;
+ STORE_A = STORE_A - ((int) (STORE_A / MAX_INT_1)) * MAX_INT_1;
+ if (STORE_A > MAX_INT_1 / 2) OVERFLOW1 = TRUE_1;
+ else A_0 = MAX_INT_1 - (int) STORE_A;
+ }
+ if ((ASIGN == 1) && (VALSIGN == -1)) {
+ STORE_A = 1.0 * A_0 * (MAX_INT_1 - VALUE);
+ STORE_A = STORE_A - ((int) (STORE_A / MAX_INT_1)) * MAX_INT_1;
+ if (STORE_A > MAX_INT_1 / 2) OVERFLOW1 = TRUE_1;
+ else A_0 = MAX_INT_1 - (int) STORE_A;
+ }
+ if ((ASIGN == -1) && (VALSIGN == -1)) {
+ STORE_A = 1.0 *(MAX_INT_1 - A_0) * (MAX_INT_1 - VALUE);
+ if (STORE_A >= MAX_INT_1 / 2) OVERFLOW1 = TRUE_1;
+ else A_0 = (int) STORE_A;
+ }
+
+ if (PRINT_EFFECT) PRINT_CONSTANT("Set A to ",A_0,".\n");
+ if (OVERFLOW1) SIGNAL_INTERUPT(2,04);
+ }
+
+ /* --------------------------------- OR_P ---------------------------------- */
+ /* BITwise OR of 2 words. */
+ void OR_P(BOOLEAN PRINT_EFFECT)
+ {
+ int VALUE; /* Value specified by the parameter. */
+ int COUNT; /* Loop counter */
+
+ int A_BITS[BITS_PER_WORD_1]; /* BIT form of A */
+ int VAL_BITS[BITS_PER_WORD_1]; /* BIT form of VALUE */
+
+ VALUE = FORMAT3_4(VALUE_1,3);
+
+ /* Check if VALUE if an impossible (in SIC/XE) unitialized value */
+ if ((VALUE < 0) || (VALUE >= MAX_INT_1)) VALUE = 0;
+
+ BYTES_TO_BITS(A_0,3,A_BITS);
+ BYTES_TO_BITS(VALUE,3,VAL_BITS);
+
+ for (COUNT = 0; COUNT < BITS_PER_WORD_1; COUNT ++)
+ A_BITS[COUNT] = A_BITS[COUNT] || VAL_BITS[COUNT];
+
+ A_0 = BITS_TO_BYTE(A_BITS,BITS_PER_WORD_1);
+
+ if (PRINT_EFFECT) PRINT_CONSTANT("Set A to ",A_0,".\n");;
+ }
+
+ /* ----------------------------------- RD_P -------------------------------- */
+ void RD_P(BOOLEAN PRINT_EFFECT)
+ {
+ int DEV;
+
+ DEV = FORMAT3_4(VALUE_1,1);
+ if ((0 > DEV) || (DEV > 255)) {
+ SIGNAL_INTERUPT(2,00);
+ if (PRINT_EFFECT) (void) printf("RD illegal device.\n");
+ } else {
+ if ((DEVICE[DEV].STREAM == NULL) || (DEVICE[DEV].STATUS == NOT_IN_USE_1)
+ || (DEV >= 128)) {
+ SIGNAL_INTERUPT(2,00);
+ if (PRINT_EFFECT) (void) printf("RD illegal device.\n");
+ } else {
+ int INPUT;
+
+ INPUT = fgetc(DEVICE[DEV].STREAM);
+ if (INPUT == -1) INPUT = 0;
+ A_0 = ((int) A_0 / MAX_BYTE_VAL_0) * MAX_BYTE_VAL_0 + INPUT;
+ DEVICE[DEV].STATUS = NOT_IN_USE_1;
+ if (PRINT_EFFECT) PRINT_CONSTANT("Set A to ",A_0,".\n");
+ }
+ }
+ }
+
+ /* ---------------------------------- SUB_P -------------------------------- */
+ /* This proceedure is messy because work had to be done with the signs of */
+ /* the arguments so that overflow could be detected. */
+ void SUB_P(BOOLEAN PRINT_EFFECT)
+ {
+ int VALUE; /* Value specified by the parameter. */
+ BOOLEAN OVERFLOW1 = FALSE_1; /* Has an overflow been detected. */
+ int ASIGN = 1; /* Sign of Accumulator */
+ int VALSIGN = 1; /* Sign of VALUE */
+
+ VALUE = FORMAT3_4(VALUE_1,3);
+
+ /* Check if VALUE if an impossible (in SIC/XE) unitialized value */
+ if ((VALUE < 0) || (VALUE >= MAX_INT_1)) VALUE = 0;
+
+ /* --------------- This is needed to correctly dectect overflow ------------ */
+ if (VALUE >= MAX_INT_1 / 2) VALSIGN = -1;
+ if (A_0 >= MAX_INT_1 / 2) ASIGN = -1;
+
+ if ((ASIGN == 1) && (VALSIGN == 1)) {
+ A_0 = A_0 - VALUE;
+ if (A_0 < 0) A_0 = MAX_INT_1 + A_0;
+ }
+ if ((ASIGN == -1) && (VALSIGN == 1)) {
+ A_0 = A_0 + (MAX_INT_1 - VALUE);
+ A_0 = A_0 - ((int) A_0 / MAX_INT_1) * MAX_INT_1;
+ if (A_0 < MAX_INT_1 / 2) OVERFLOW1 = TRUE_1;
+ }
+ if ((ASIGN == 1) && (VALSIGN == -1)) {
+ A_0 = A_0 + (MAX_INT_1 - VALUE);
+ if (A_0 >= MAX_INT_1 / 2) OVERFLOW1 = TRUE_1;
+ }
+ if ((ASIGN == -1) && (VALSIGN == -1)) {
+ A_0 = A_0 + (MAX_INT_1 - VALUE);
+ A_0 = A_0 - ((int) A_0 / MAX_INT_1) * MAX_INT_1;
+ }
+
+ if (PRINT_EFFECT) PRINT_CONSTANT("Set A to ",A_0,".\n");
+ if (OVERFLOW1) SIGNAL_INTERUPT(2,04);
+ }
+
+ /* ---------------------------------- RSUB_P ------------------------------- */
+ void RSUB_P(BOOLEAN PRINT_EFFECT)
+ {
+ if ((L_0 < 0) || ((L_0 >= MEM_SIZE_1) && L_0 != RETURN_TO_OS_1)) {
+ SIGNAL_INTERUPT(2,02);
+ if (PRINT_EFFECT) (void) printf("JLT m, m is an illegal address.\n");
+ } else {
+ PC_0 = L_0;
+ if (PRINT_EFFECT)
+ if (PC_0 == RETURN_TO_OS_1)
+ (void) printf("RSUB to Operating System.\n");
+ else
+ PRINT_ADDRESS("RSUB to ",PC_0,"\n");
+ }
+ }
+
+ /* ---------------------------------- STA_P -------------------------------- */
+ void STA_P(BOOLEAN PRINT_EFFECT)
+ {
+ int ADDRESS;
+
+ ADDRESS = FORMAT3_4(LOCATION_1,3);
+ if (ADDRESS+2 >= MEM_SIZE_1) {
+ SIGNAL_INTERUPT(2,02);
+ if (PRINT_EFFECT) (void) printf("STA m, m is an illegal address.\n");
+ } else {
+ MEMORY[ADDRESS] = A_0 / (MAX_BYTE_VAL_0 * MAX_BYTE_VAL_0);
+ MEMORY[ADDRESS+1] = (A_0 -
+ INT(MEMORY[ADDRESS]) * (MAX_BYTE_VAL_0 * MAX_BYTE_VAL_0))
+ / MAX_BYTE_VAL_0;
+ MEMORY[ADDRESS+2] = (A_0 - INT(MEMORY[ADDRESS+1]) * MAX_BYTE_VAL_0);
+
+ if (PRINT_EFFECT) {
+ PRINT_CONSTANT("Put ",A_0," into ");
+ PRINT_ADDRESS("",ADDRESS,".\n");
+ }
+ }
+ }
+
+ /* ---------------------------------- STB_P -------------------------------- */
+ void STB_P(BOOLEAN PRINT_EFFECT)
+ {
+ int ADDRESS;
+
+ ADDRESS = FORMAT3_4(LOCATION_1,3);
+ if (ADDRESS+2 >= MEM_SIZE_1) {
+ SIGNAL_INTERUPT(2,02);
+ if (PRINT_EFFECT) (void) printf("STB m, m is an illegal address.\n");
+ } else {
+ MEMORY[ADDRESS] = B_0 / (MAX_BYTE_VAL_0 * MAX_BYTE_VAL_0);
+ MEMORY[ADDRESS+1] = (B_0 -
+ INT(MEMORY[ADDRESS]) * (MAX_BYTE_VAL_0 * MAX_BYTE_VAL_0))
+ / MAX_BYTE_VAL_0;
+ MEMORY[ADDRESS+2] = (B_0 - INT(MEMORY[ADDRESS+1]) * MAX_BYTE_VAL_0);
+
+ if (PRINT_EFFECT) {
+ PRINT_CONSTANT("Put ",B_0," into ");
+ PRINT_ADDRESS("",ADDRESS,".\n");
+ }
+ }
+ }
+
+ /* ---------------------------------- STCH_P ------------------------------- */
+ void STCH_P(BOOLEAN PRINT_EFFECT)
+ {
+ int ADDRESS;
+
+ ADDRESS = FORMAT3_4(LOCATION_1,1);
+ MEMORY[ADDRESS] = A_0 - (A_0 / MAX_BYTE_VAL_0) * MAX_BYTE_VAL_0;
+
+ if (PRINT_EFFECT) {
+ PRINT_CONSTANT("Put ",A_0," into ");
+ PRINT_ADDRESS("",ADDRESS,".\n");
+ }
+ }
+
+ /* ---------------------------------- STI_P -------------------------------- */
+ void STI_P(BOOLEAN PRINT_EFFECT)
+ {
+ int ADDRESS;
+
+ if (!SUPERVISOR_MODE()) {
+ SIGNAL_INTERUPT(2,01);
+ if (PRINT_EFFECT) (void) printf("STI is a privileged instruction.\n");
+ } else {
+ ADDRESS = FORMAT3_4(LOCATION_1,3);
+ if (ADDRESS+2 >= MEM_SIZE_1) {
+ SIGNAL_INTERUPT(2,02);
+ if (PRINT_EFFECT) (void) printf("STI m, m is an illegal address.\n");
+ } else {
+ MEMORY[ADDRESS] = INTERVAL_TIMER / (MAX_BYTE_VAL_0 * MAX_BYTE_VAL_0);
+ MEMORY[ADDRESS+1] = (INTERVAL_TIMER -
+ INT(MEMORY[ADDRESS]) *
+ (MAX_BYTE_VAL_0 * MAX_BYTE_VAL_0)) / MAX_BYTE_VAL_0;
+ MEMORY[ADDRESS+2] =
+ (INTERVAL_TIMER - INT(MEMORY[ADDRESS+1]) * MAX_BYTE_VAL_0);
+
+ if (PRINT_EFFECT) {
+ PRINT_CONSTANT("Put ",INTERVAL_TIMER," into ");
+ PRINT_ADDRESS("",ADDRESS,".\n");
+ }
+ }
+ }
+ }
+
+ /* ---------------------------------- STL_P -------------------------------- */
+ void STL_P(BOOLEAN PRINT_EFFECT)
+ {
+ int ADDRESS;
+
+ ADDRESS = FORMAT3_4(LOCATION_1,3);
+ if (ADDRESS+2 >= MEM_SIZE_1) {
+ SIGNAL_INTERUPT(2,02);
+ if (PRINT_EFFECT) (void) printf("STL m, m is an illegal address.\n");
+ } else {
+ MEMORY[ADDRESS] = L_0 / (MAX_BYTE_VAL_0 * MAX_BYTE_VAL_0);
+ MEMORY[ADDRESS+1] = (L_0 -
+ INT(MEMORY[ADDRESS]) * (MAX_BYTE_VAL_0 * MAX_BYTE_VAL_0))
+ / MAX_BYTE_VAL_0;
+ MEMORY[ADDRESS+2] = (L_0 - INT(MEMORY[ADDRESS+1]) * MAX_BYTE_VAL_0);
+
+ if (PRINT_EFFECT) {
+ PRINT_CONSTANT("Put ",L_0," into ");
+ PRINT_ADDRESS("",ADDRESS,".\n");
+ }
+ }
+ }
+
+ /* ---------------------------------- STS_P -------------------------------- */
+ void STS_P(BOOLEAN PRINT_EFFECT)
+ {
+ int ADDRESS;
+
+ ADDRESS = FORMAT3_4(LOCATION_1,3);
+ if (ADDRESS+2 >= MEM_SIZE_1) {
+ SIGNAL_INTERUPT(2,02);
+ if (PRINT_EFFECT) (void) printf("STS m, m is an illegal address.\n");
+ } else {
+ MEMORY[ADDRESS] = S_0 / (MAX_BYTE_VAL_0 * MAX_BYTE_VAL_0);
+ MEMORY[ADDRESS+1] = (S_0 -
+ INT(MEMORY[ADDRESS]) * (MAX_BYTE_VAL_0 * MAX_BYTE_VAL_0))
+ / MAX_BYTE_VAL_0;
+ MEMORY[ADDRESS+2] = (S_0 - INT(MEMORY[ADDRESS+1]) * MAX_BYTE_VAL_0);
+
+ if (PRINT_EFFECT) {
+ PRINT_CONSTANT("Put ",S_0," into ");
+ PRINT_ADDRESS("",ADDRESS,".\n");
+ }
+ }
+ }
+
+ /* --------------------------------- STSW_P -------------------------------- */
+ void STSW_P(BOOLEAN PRINT_EFFECT)
+ {
+ int ADDRESS;
+
+ if (!SUPERVISOR_MODE()) {
+ SIGNAL_INTERUPT(2,01);
+ if (PRINT_EFFECT) (void) printf("STSW is a privileged instruction.\n");
+ } else {
+ ADDRESS = FORMAT3_4(LOCATION_1,3);
+ if (ADDRESS+2 >= MEM_SIZE_1) {
+ SIGNAL_INTERUPT(2,02);
+ if (PRINT_EFFECT) (void) printf("STSW m, m is an illegal address.\n");
+ } else {
+ MEMORY[ADDRESS] = SW_0 / (MAX_BYTE_VAL_0 * MAX_BYTE_VAL_0);
+ MEMORY[ADDRESS+1] = (SW_0 -
+ INT(MEMORY[ADDRESS]) *
+ (MAX_BYTE_VAL_0 * MAX_BYTE_VAL_0)) / MAX_BYTE_VAL_0;
+ MEMORY[ADDRESS+2] = (SW_0 - INT(MEMORY[ADDRESS+1]) * MAX_BYTE_VAL_0);
+
+ if (PRINT_EFFECT) {
+ PRINT_CONSTANT("Put ",SW_0," into ");
+ PRINT_ADDRESS("",ADDRESS,".\n");
+ }
+ }
+ }
+ }
+
+ /* ---------------------------------- STT_P -------------------------------- */
+ void STT_P(BOOLEAN PRINT_EFFECT)
+ {
+ int ADDRESS;
+
+ ADDRESS = FORMAT3_4(LOCATION_1,3);
+ if (ADDRESS+2 >= MEM_SIZE_1) {
+ SIGNAL_INTERUPT(2,02);
+ if (PRINT_EFFECT) (void) printf("STT m, m is an illegal address.\n");
+ } else {
+ MEMORY[ADDRESS] = T_0 / (MAX_BYTE_VAL_0 * MAX_BYTE_VAL_0);
+ MEMORY[ADDRESS+1] = (T_0 -
+ INT(MEMORY[ADDRESS]) * (MAX_BYTE_VAL_0 * MAX_BYTE_VAL_0))
+ / MAX_BYTE_VAL_0;
+ MEMORY[ADDRESS+2] = (T_0 - INT(MEMORY[ADDRESS+1]) * MAX_BYTE_VAL_0);
+
+ if (PRINT_EFFECT) {
+ PRINT_CONSTANT("Put ",T_0," into ");
+ PRINT_ADDRESS("",ADDRESS,".\n");
+ }
+ }
+ }
+
+ /* ---------------------------------- STX_P -------------------------------- */
+ void STX_P(BOOLEAN PRINT_EFFECT)
+ {
+ int ADDRESS;
+
+ ADDRESS = FORMAT3_4(LOCATION_1,3);
+ if (ADDRESS+2 >= MEM_SIZE_1) {
+ SIGNAL_INTERUPT(2,02);
+ if (PRINT_EFFECT) (void) printf("STX m, m is an illegal address.\n");
+ } else {
+ MEMORY[ADDRESS] = X_0 / (MAX_BYTE_VAL_0 * MAX_BYTE_VAL_0);
+ MEMORY[ADDRESS+1] = (X_0 -
+ INT(MEMORY[ADDRESS]) * (MAX_BYTE_VAL_0 * MAX_BYTE_VAL_0))
+ / MAX_BYTE_VAL_0;
+ MEMORY[ADDRESS+2] = (X_0 - INT(MEMORY[ADDRESS+1]) * MAX_BYTE_VAL_0);
+
+ if (PRINT_EFFECT) {
+ PRINT_CONSTANT("Put ",X_0," into ");
+ PRINT_ADDRESS("",ADDRESS,".\n");
+ }
+ }
+ }
+
+ /* ---------------------------------- TD_P --------------------------------- */
+ void TD_P(BOOLEAN PRINT_EFFECT)
+ {
+ int DEV_NUM;
+
+ DEV_NUM = FORMAT3_4(VALUE_1,1);
+ if ((0 > DEV_NUM) || (DEV_NUM > 255)) {
+ SIGNAL_INTERUPT(2,00);
+ if (PRINT_EFFECT) (void) printf("TD illegal device.\n");
+ }
+ else if (DEVICE[DEV_NUM].STATUS == NOT_IN_USE_1) {
+ OPEN_DEVICE(DEV_NUM);
+ SET_CC(LESS_THAN_1);
+ if (PRINT_EFFECT)
+ PRINT_CONSTANT("Set CC to <. Marked Device ",DEV_NUM," as in use.\n");
+ } else {
+ SET_CC(EQUAL_1);
+ if (PRINT_EFFECT) (void) printf("Set CC to =.\n");
+ }
+ }
+
+ /* ---------------------------------- TIX_P -------------------------------- */
+ void TIX_P(BOOLEAN PRINT_EFFECT)
+ {
+ int VALUE;
+ int X_VAL;
+
+ VALUE = FORMAT3_4(VALUE_1,3);
+
+ X_0 ++;
+ X_0 = X_0 - ((int) X_0 / MAX_INT_1) * MAX_INT_1;
+
+ if (X_0 == MAX_INT_1 / 2) {
+ SIGNAL_INTERUPT(2,04);
+ if (PRINT_EFFECT) (void) printf("X has overflowed.\n");
+ return;
+ }
+
+ if (X_0 >= MAX_INT_1 / 2) X_VAL = X_0 - MAX_INT_1;
+ else X_VAL = X_0;
+
+ if (VALUE >= MAX_INT_1 / 2) VALUE = VALUE - MAX_INT_1;
+
+ if (X_VAL == VALUE) {
+ SET_CC(EQUAL_1);
+ if (PRINT_EFFECT) PRINT_CONSTANT("Set X to ",X_0," and set CC to =.\n");
+ }
+ if (X_VAL < VALUE) {
+ SET_CC(LESS_THAN_1);
+ if (PRINT_EFFECT) PRINT_CONSTANT("Set X to ",X_0," and set CC to <.\n");
+ }
+ if (X_VAL > VALUE) {
+ SET_CC(GREATER_THAN_1);
+ if (PRINT_EFFECT) PRINT_CONSTANT("Set X to ",X_0," and set CC to >.\n");
+ }
+ }
+
+ /* ---------------------------------- WD_P --------------------------------- */
+ void WD_P(BOOLEAN PRINT_EFFECT)
+ {
+ int DEV;
+ int VALUE;
+
+ DEV = FORMAT3_4(VALUE_1,1);
+ if ((0 > DEV) || (DEV > 255)) {
+ SIGNAL_INTERUPT(2,00);
+ if (PRINT_EFFECT) (void) printf("WD illegal device.\n");
+ } else {
+ if ((DEVICE[DEV].STREAM == NULL) || (DEVICE[DEV].STATUS == NOT_IN_USE_1)
+ || (DEV < 128)) {
+ SIGNAL_INTERUPT(2,00);
+ if (PRINT_EFFECT) (void) printf("WD illegal device.\n");
+ } else {
+ VALUE = A_0 - ((int) A_0/MAX_BYTE_VAL_0)*MAX_BYTE_VAL_0;
+ (void) fprintf(DEVICE[DEV].STREAM,"%c",VALUE);
+ if (PRINT_EFFECT) {
+ PRINT_CONSTANT("Wrote ASCII char ",VALUE," to device ");
+ PRINT_CONSTANT("",DEV,"\n");
+ }
+ DEVICE[DEV].STATUS = NOT_IN_USE_1;
+ }
+ }
+ }
Index: llvm-test/MultiSource/Benchmarks/Prolangs-C/simulator/instruct.h
diff -c /dev/null llvm-test/MultiSource/Benchmarks/Prolangs-C/simulator/instruct.h:1.1
*** /dev/null Tue Oct 5 16:08:51 2004
--- llvm-test/MultiSource/Benchmarks/Prolangs-C/simulator/instruct.h Tue Oct 5 16:08:39 2004
***************
*** 0 ****
--- 1,189 ----
+ /* %%%%%%%%%%%%%%%%%%%% (c) William Landi 1991 %%%%%%%%%%%%%%%%%%%%%%%%%%%% */
+ /* Permission to use this code is granted as long as the copyright */
+ /* notice remains in place. */
+ /* =============================== intruction.h ============================ */
+ /* Contains all the procedures that know how to handle FORMAT3/4 instructions*/
+ /* Name of the procedure is the same as the SIC/XE instruction name but with */
+ /* a '_P' added to the end. See p. 410-411 of "System Software: An */
+ /* Introduction to Systems Programming" by Leland L. Beck for detailed */
+ /* Description to the function of each command. */
+
+ /* ---------------------------------- ADD_P -------------------------------- */
+ /* 1 paramater: */
+ /* 1) BOOLEAN PRINT_EFFECT; Output effect of this command for debugging */
+ /* This proceedure is messy because work had to be done with the signs of */
+ /* the arguments so that overflow could be detected. */
+ extern void ADD_P();
+
+ /* --------------------------------- AND_P --------------------------------- */
+ /* 1 paramater: */
+ /* 1) BOOLEAN PRINT_EFFECT; Output effect of this command for debugging */
+ /* Bitwise AND of 2 words. */
+ extern void AND_P();
+
+ /* --------------------------------- COMP_P -------------------------------- */
+ /* 1 paramater: */
+ /* 1) BOOLEAN PRINT_EFFECT; Output effect of this command for debugging */
+ extern void COMP_P();
+
+ /* ---------------------------------- DIV_P -------------------------------- */
+ /* 1 paramater: */
+ /* 1) BOOLEAN PRINT_EFFECT; Output effect of this command for debugging */
+ /* This proceedure is messy because work had to be done with the signs of */
+ /* the arguments. */
+ extern void DIV_P();
+
+ /* ----------------------------------- J_P --------------------------------- */
+ /* 1 paramater: */
+ /* 1) BOOLEAN PRINT_EFFECT; Output effect of this command for debugging */
+ extern void J_P();
+
+ /* ---------------------------------- JEQ_P -------------------------------- */
+ /* 1 paramater: */
+ /* 1) BOOLEAN PRINT_EFFECT; Output effect of this command for debugging */
+ extern void JEQ_P();
+
+ /* -------------------------------- JGT_P ---------------------------------- */
+ /* 1 paramater: */
+ /* 1) BOOLEAN PRINT_EFFECT; Output effect of this command for debugging */
+ extern void JGT_P();
+
+ /* ------------------------------- JLT_P ----------------------------------- */
+ /* 1 paramater: */
+ /* 1) BOOLEAN PRINT_EFFECT; Output effect of this command for debugging */
+ extern void JLT_P();
+
+ /* --------------------------------- JSUB_P -------------------------------- */
+ /* 1 paramater: */
+ /* 1) BOOLEAN PRINT_EFFECT; Output effect of this command for debugging */
+ extern void JSUB_P();
+
+ /* ------------------------------- LDA_P ----------------------------------- */
+ /* 1 paramater: */
+ /* 1) BOOLEAN PRINT_EFFECT; Output effect of this command for debugging */
+ extern void SUB_P();
+
+ /* ------------------------------- LDA_P ----------------------------------- */
+ /* 1 paramater: */
+ /* 1) BOOLEAN PRINT_EFFECT; Output effect of this command for debugging */
+ extern void LDA_P();
+
+ /* ------------------------------- LDB_P ----------------------------------- */
+ /* 1 paramater: */
+ /* 1) BOOLEAN PRINT_EFFECT; Output effect of this command for debugging */
+ extern void LDB_P();
+
+ /* ------------------------------- LDCH_P ---------------------------------- */
+ /* 1 paramater: */
+ /* 1) BOOLEAN PRINT_EFFECT; Output effect of this command for debugging */
+ extern void LDCH_P();
+
+ /* ------------------------------- LDL_P ----------------------------------- */
+ /* 1 paramater: */
+ /* 1) BOOLEAN PRINT_EFFECT; Output effect of this command for debugging */
+ extern void LDL_P();
+
+ /* ------------------------------- LDS_P ----------------------------------- */
+ /* 1 paramater: */
+ /* 1) BOOLEAN PRINT_EFFECT; Output effect of this command for debugging */
+ extern void LDS_P();
+
+ /* ------------------------------- LDT_P ----------------------------------- */
+ /* 1 paramater: */
+ /* 1) BOOLEAN PRINT_EFFECT; Output effect of this command for debugging */
+ extern void LDT_P();
+
+ /* ------------------------------- LDX_P ----------------------------------- */
+ /* 1 paramater: */
+ /* 1) BOOLEAN PRINT_EFFECT; Output effect of this command for debugging */
+ extern void LDX_P();
+
+ /* ---------------------------------- MUL_P -------------------------------- */
+ /* 1 paramater: */
+ /* 1) BOOLEAN PRINT_EFFECT; Output effect of this command for debugging */
+ /* This proceedure is messy because work had to be done with the signs of */
+ /* the arguments so that overflow could be detected. */
+ extern void MUL_P();
+
+ /* --------------------------------- OR_P ---------------------------------- */
+ /* 1 paramater: */
+ /* 1) BOOLEAN PRINT_EFFECT; Output effect of this command for debugging */
+ /* BITwise OR of 2 words. */
+ extern void OR_P();
+
+ /* ----------------------------------- RD_P -------------------------------- */
+ /* 1 paramater: */
+ /* 1) BOOLEAN PRINT_EFFECT; Output effect of this command for debugging */
+ extern void RD_P();
+
+ /* ---------------------------------- RSUB_P ------------------------------- */
+ /* 1 paramater: */
+ /* 1) BOOLEAN PRINT_EFFECT; Output effect of this command for debugging */
+ extern void RSUB_P();
+
+ /* ---------------------------------- STA_P -------------------------------- */
+ /* 1 paramater: */
+ /* 1) BOOLEAN PRINT_EFFECT; Output effect of this command for debugging */
+ extern void STA_P();
+
+ /* ---------------------------------- STB_P -------------------------------- */
+ /* 1 paramater: */
+ /* 1) BOOLEAN PRINT_EFFECT; Output effect of this command for debugging */
+ extern void STB_P();
+
+ /* ---------------------------------- STCH_P ------------------------------- */
+ /* 1 paramater: */
+ /* 1) BOOLEAN PRINT_EFFECT; Output effect of this command for debugging */
+ extern void STCH_P();
+
+ /* ---------------------------------- STI_P -------------------------------- */
+ /* 1 paramater: */
+ /* 1) BOOLEAN PRINT_EFFECT; Output effect of this command for debugging */
+ extern void STI_P();
+
+ /* ---------------------------------- STL_P -------------------------------- */
+ /* 1 paramater: */
+ /* 1) BOOLEAN PRINT_EFFECT; Output effect of this command for debugging */
+ extern void STL_P();
+
+ /* ---------------------------------- STS_P -------------------------------- */
+ /* 1 paramater: */
+ /* 1) BOOLEAN PRINT_EFFECT; Output effect of this command for debugging */
+ extern void STS_P();
+
+ /* --------------------------------- STSW_P -------------------------------- */
+ /* 1 paramater: */
+ /* 1) BOOLEAN PRINT_EFFECT; Output effect of this command for debugging */
+ extern void STSW_P();
+
+ /* ---------------------------------- STT_P -------------------------------- */
+ /* 1 paramater: */
+ /* 1) BOOLEAN PRINT_EFFECT; Output effect of this command for debugging */
+ extern void STT_P();
+
+ /* ---------------------------------- STX_P -------------------------------- */
+ /* 1 paramater: */
+ /* 1) BOOLEAN PRINT_EFFECT; Output effect of this command for debugging */
+ extern void STX_P();
+
+ /* ---------------------------------- SUB_P -------------------------------- */
+ /* 1 paramater: */
+ /* 1) BOOLEAN PRINT_EFFECT; Output effect of this command for debugging */
+ /* This proceedure is messy because work had to be done with the signs of */
+ /* the arguments so that overflow could be detected. */
+ extern void SUB_P();
+
+ /* ---------------------------------- TD_P --------------------------------- */
+ /* 1 paramater: */
+ /* 1) BOOLEAN PRINT_EFFECT; Output effect of this command for debugging */
+ extern void TD_P();
+
+ /* ---------------------------------- TIX_P -------------------------------- */
+ /* 1 paramater: */
+ /* 1) BOOLEAN PRINT_EFFECT; Output effect of this command for debugging */
+ extern void TIX_P();
+
+ /* ---------------------------------- WD_P --------------------------------- */
+ /* 1 paramater: */
+ /* 1) BOOLEAN PRINT_EFFECT; Output effect of this command for debugging */
+ extern void WD_P();
Index: llvm-test/MultiSource/Benchmarks/Prolangs-C/simulator/instruct2.c
diff -c /dev/null llvm-test/MultiSource/Benchmarks/Prolangs-C/simulator/instruct2.c:1.1
*** /dev/null Tue Oct 5 16:08:51 2004
--- llvm-test/MultiSource/Benchmarks/Prolangs-C/simulator/instruct2.c Tue Oct 5 16:08:39 2004
***************
*** 0 ****
--- 1,426 ----
+ /* %%%%%%%%%%%%%%%%%%%% (c) William Landi 1991 %%%%%%%%%%%%%%%%%%%%%%%%%%%% */
+ /* Permission to use this code is granted as long as the copyright */
+ /* notice remains in place. */
+
+ /* ============================== intruction2.c ============================ */
+ /* Contains all the procedures that know how to handle FORMAT2 instructions */
+ /* Name of the procedure is the same as the SIC/XE instruction name but with */
+ /* a '_P' added to the end. See p. 410-411 of "System Software: An */
+ /* Introduction to Systems Programming" by Leland L. Beck for detailed */
+ /* Description to the function of each command. */
+
+ #include <math.h>
+ #include "boolean.h"
+ #include "debugger.h"
+ #include "memory.h"
+ #include "machine.h"
+ #include "convert.h"
+ #include "format.h"
+ #include "interupt.h"
+
+ /* ----------------------------- MOD (local) ------------------------------- */
+ /* return (N mod M); */
+ int MOD(N,M)
+ int N;
+ int M;
+ {
+ return N - ((int) N / M) * M;
+ }
+
+ /* ----------------------------------- ADDR_P ------------------------------ */
+ /* This proceedure is messy because work had to be done with the signs of */
+ /* the arguments so that overflow could be detected. */
+ void ADDR_P(PRINT_EFFECT)
+ BOOLEAN PRINT_EFFECT; /* Output effect of this command for debugging */
+ {
+ BOOLEAN OVERFLOW1 = FALSE_1; /* Has an overflow been detected. */
+ int REG1; /* First Register in instruction */
+ int REG2; /* Second Register in instruction */
+ int REG1_SIGN = 1; /* Sign of value in the first register */
+ int REG2_SIGN = 1; /* Sign of value in the second register */
+
+ FORMAT2(®1,®2);
+
+ if (!( ( (REG1 >=0 ) && (REG1 < NUM_REGISTERS)) ||
+ ( (REG2 >=0 ) && (REG2 < NUM_REGISTERS)) )) {
+ SIGNAL_INTERUPT(2,00);
+ } else {
+
+ /* --------------- This is needed to correctly dectect overflow ------------ */
+ if (REGISTER[REG1] >= MAX_INT_1 / 2) REG1_SIGN = -1;
+ if (REGISTER[REG2] >= MAX_INT_1 / 2) REG2_SIGN = -1;
+
+ if ((REG2_SIGN == 1) && (REG1_SIGN == 1)) {
+ REGISTER[REG2] = REGISTER[REG2] + REGISTER[REG1];
+ if (REGISTER[REG2] >= MAX_INT_1 / 2) OVERFLOW1 = TRUE_1;
+ }
+ if ((REG2_SIGN == -1) && (REG1_SIGN == 1)) {
+ REGISTER[REG2] = REGISTER[REG2] + REGISTER[REG1];
+ REGISTER[REG2] = REGISTER[REG2] -
+ ((int) REGISTER[REG2] / MAX_INT_1) * MAX_INT_1;
+ }
+ if ((REG2_SIGN == 1) && (REG1_SIGN == -1)) {
+ REGISTER[REG2] = REGISTER[REG2] + REGISTER[REG1];
+ REGISTER[REG2] = REGISTER[REG2] -
+ ((int) REGISTER[REG2] / MAX_INT_1) * MAX_INT_1;
+ }
+ if ((REG2_SIGN == -1) && (REG1_SIGN == -1)) {
+ REGISTER[REG2] = REGISTER[REG2] + REGISTER[REG1];
+ REGISTER[REG2] = REGISTER[REG2] -
+ ((int) REGISTER[REG2] / MAX_INT_1) * MAX_INT_1;
+ if (REGISTER[REG2] < MAX_INT_1 / 2) OVERFLOW1 = TRUE_1;
+ }
+
+ if (PRINT_EFFECT) {
+ PRINT_REG_NAME("Set ",REG2,"");
+ PRINT_CONSTANT(" to ",REGISTER[REG2],".\n");
+ }
+ if (OVERFLOW1) SIGNAL_INTERUPT(2,04);
+ }
+ }
+
+ /* ----------------------------------- CLEAR_P ---------------------------- */
+ void CLEAR_P(PRINT_EFFECT)
+ BOOLEAN PRINT_EFFECT; /* Output effect of this command for debugging */
+ {
+ int REG1; /* First Register in instruction */
+ int REG2; /* Second Register in instruction */
+
+ FORMAT2(®1,®2);
+
+ if (!( (REG1 >=0 ) && (REG1 < NUM_REGISTERS)))
+ SIGNAL_INTERUPT(2,00);
+ else {
+ REGISTER[REG1] = 0;
+ if (PRINT_EFFECT) {
+ PRINT_REG_NAME("Set ",REG1,"");
+ PRINT_CONSTANT(" to ",REGISTER[REG1],".\n");
+ }
+ }
+ }
+
+ /* ---------------------------------- COMPR_P ------------------------------ */
+ void COMPR_P(PRINT_EFFECT)
+ BOOLEAN PRINT_EFFECT; /* Output effect of this command for debugging */
+
+ {
+ int REG1; /* First Register in instruction */
+ int REG2; /* Second Register in instruction */
+ int REG1_VAL; /* What is stored in first register. */
+ int REG2_VAL; /* What is stored in second register. */
+
+ FORMAT2(®1,®2);
+
+ if (REGISTER[REG1] >= MAX_INT_1 / 2) REG1_VAL = REGISTER[REG1] - MAX_INT_1;
+ else REG1_VAL = REGISTER[REG1];
+
+ if (REGISTER[REG1] >= MAX_INT_1 / 2) REG2_VAL = REGISTER[REG2] - MAX_INT_1;
+ else REG2_VAL = REGISTER[REG2];
+
+ if (REG1_VAL == REG2_VAL) {
+ SET_CC(EQUAL_1);
+ if (PRINT_EFFECT) (void) printf("Set CC to =.\n");
+ }
+ if (REG1_VAL < REG2_VAL) {
+ SET_CC(LESS_THAN_1);
+ if (PRINT_EFFECT) (void) printf("Set CC to <.\n");
+ }
+ if (REG1_VAL > REG2_VAL) {
+ SET_CC(GREATER_THAN_1);
+ if (PRINT_EFFECT) (void) printf("Set CC to >.\n");
+ }
+ }
+
+ /* ---------------------------------- DIVR_P ------------------------------ */
+ /* This proceedure is messy because work had to be done with the signs of */
+ /* the arguments. */
+ void DIVR_P(PRINT_EFFECT)
+ BOOLEAN PRINT_EFFECT; /* Output effect of this command for debugging */
+ {
+ int REG1; /* First Register in instruction */
+ int REG2; /* Second Register in instruction */
+ int REG1_SIGN = 1; /* Sign of value in the first register */
+ int REG2_SIGN = 1; /* Sign of value in the second register */
+
+ FORMAT2(®1,®2);
+
+ if (!( ( (REG1 >=0 ) && (REG1 < NUM_REGISTERS)) ||
+ ( (REG2 >=0 ) && (REG2 < NUM_REGISTERS)) )) {
+ SIGNAL_INTERUPT(2,00);
+ } else if (REGISTER[REG1] == 0) {
+ SIGNAL_INTERUPT(2,04);
+ if (PRINT_EFFECT) (void) printf("Attempted division by zero.\n");
+ } else {
+ /* --------------- This is needed to correctly dectect overflow ------------ */
+ if (REGISTER[REG1] >= MAX_INT_1 / 2) REG1_SIGN = -1;
+ if (REGISTER[REG2] >= MAX_INT_1 / 2) REG2_SIGN = -1;
+
+ if ((REG2_SIGN == 1) && (REG1_SIGN == 1))
+ REGISTER[REG2] = REGISTER[REG2] / REGISTER[REG1];
+ if ((REG2_SIGN == -1) && (REG1_SIGN == 1))
+ REGISTER[REG2] = MAX_INT_1 -
+ ((MAX_INT_1 - REGISTER[REG2]) / REGISTER[REG1]);
+ if ((REG2_SIGN == 1) && (REG1_SIGN == -1))
+ REGISTER[REG2] = MAX_INT_1 -
+ (REGISTER[REG2] / (MAX_INT_1 - REGISTER[REG1]));
+ if ((REG2_SIGN == -1) && (REG1_SIGN == -1))
+ REGISTER[REG2] = (MAX_INT_1 - REGISTER[REG2]) /
+ (MAX_INT_1 - REGISTER[REG1]);
+ }
+
+ if (PRINT_EFFECT) {
+ PRINT_REG_NAME("Set ",REG2,"");
+ PRINT_CONSTANT(" to ",REGISTER[REG2],".\n");
+ }
+ }
+
+ /* ---------------------------------- MULR_P ------------------------------ */
+ /* This proceedure is messy because work had to be done with the signs of */
+ /* the arguments so that overflow could be detected. */
+ void MULR_P(PRINT_EFFECT)
+ BOOLEAN PRINT_EFFECT; /* Output effect of this command for debugging */
+ {
+ BOOLEAN OVERFLOW1 = FALSE_1; /* Has an overflow been detected. */
+ int REG1; /* First Register in instruction */
+ int REG2; /* Second Register in instruction */
+ int REG1_SIGN = 1; /* Sign of value in the first register */
+ int REG2_SIGN = 1; /* Sign of value in the second register */
+ double STORE_VALUE; /* So the simulator does not overflow */
+
+ FORMAT2(®1,®2);
+
+ if (!( ( (REG1 >=0 ) && (REG1 < NUM_REGISTERS)) ||
+ ( (REG2 >=0 ) && (REG2 < NUM_REGISTERS)) )) {
+ SIGNAL_INTERUPT(2,00);
+ } else {
+
+ /* --------------- This is needed to correctly dectect overflow ------------ */
+ if (REGISTER[REG1] >= MAX_INT_1 / 2) REG1_SIGN = -1;
+ if (REGISTER[REG2] >= MAX_INT_1 / 2) REG2_SIGN = -1;
+
+ if ((REG2_SIGN == 1) && (REG1_SIGN == 1)) {
+ STORE_VALUE = 1.0 * REGISTER[REG2] * REGISTER[REG1];
+ if (STORE_VALUE >= MAX_INT_1 / 2) OVERFLOW1 = TRUE_1;
+ else REGISTER[REG2] = (int) STORE_VALUE;
+ }
+ if ((REG2_SIGN == -1) && (REG1_SIGN == 1)) {
+ STORE_VALUE = 1.0 * (MAX_INT_1 - REGISTER[REG2]) * REGISTER[REG1];
+ STORE_VALUE = STORE_VALUE - ((int)(STORE_VALUE / MAX_INT_1)) * MAX_INT_1;
+ if (STORE_VALUE >= MAX_INT_1 / 2) OVERFLOW1 = TRUE_1;
+ else REGISTER[REG2] = MAX_INT_1 - (int) STORE_VALUE;
+ }
+ if ((REG2_SIGN == 1) && (REG1_SIGN == -1)) {
+ STORE_VALUE = 1.0 * REGISTER[REG2] * (MAX_INT_1 - REGISTER[REG1]);
+ STORE_VALUE = STORE_VALUE - ((int)(STORE_VALUE / MAX_INT_1)) * MAX_INT_1;
+ if (STORE_VALUE >= MAX_INT_1 / 2) OVERFLOW1 = TRUE_1;
+ else REGISTER[REG2] = MAX_INT_1 - (int) STORE_VALUE;
+ }
+ if ((REG2_SIGN == -1) && (REG1_SIGN == -1)) {
+ STORE_VALUE = 1.0 * (MAX_INT_1 - REGISTER[REG2]) *
+ (MAX_INT_1 - REGISTER[REG1]);
+ if (STORE_VALUE >= MAX_INT_1 / 2) OVERFLOW1 = TRUE_1;
+ else REGISTER[REG2] = (int) STORE_VALUE;
+ }
+
+ if (PRINT_EFFECT) {
+ PRINT_REG_NAME("Set ",REG2,"");
+ PRINT_CONSTANT(" to ",REGISTER[REG2],".\n");
+ }
+ if (OVERFLOW1) SIGNAL_INTERUPT(2,04);
+ }
+ }
+
+ /* ----------------------------------- RMO_P ------------------------------- */
+ void RMO_P(PRINT_EFFECT)
+ BOOLEAN PRINT_EFFECT; /* Output effect of this command for debugging */
+ {
+ int REG1; /* First Register in instruction */
+ int REG2; /* Second Register in instruction */
+
+ FORMAT2(®1,®2);
+
+ if (!( ( (REG1 >=0 ) && (REG1 < NUM_REGISTERS)) ||
+ ( (REG2 >=0 ) && (REG2 < NUM_REGISTERS)) )) {
+ SIGNAL_INTERUPT(2,00);
+ } else {
+ REGISTER[REG2] = REGISTER[REG1];
+ if (PRINT_EFFECT) {
+ PRINT_REG_NAME("Set ",REG2,"");
+ PRINT_CONSTANT(" to ",REGISTER[REG2],".\n");
+ }
+ }
+ }
+
+
+ /* --------------------------------- SHIFTL_P ------------------------------ */
+ void SHIFTL_P(PRINT_EFFECT)
+ BOOLEAN PRINT_EFFECT; /* Output effect of this command for debugging */
+ {
+ int REG1; /* First Register in instruction */
+ int REG2; /* Second Register in instruction */
+
+ FORMAT2(®1,®2);
+ if (!( (REG1 >=0 ) && (REG1 < NUM_REGISTERS))) SIGNAL_INTERUPT(2,00);
+ else {
+ int LOOP; /* COUNTER VARIBLE */
+ int REG_BITS[BITS_PER_WORD_1];
+ int SHIFTED_BITS[BITS_PER_WORD_1];
+
+ BYTES_TO_BITS(REGISTER[REG1],3,REG_BITS);
+ for (LOOP = 0; LOOP < BITS_PER_WORD_1; LOOP ++)
+ SHIFTED_BITS[LOOP] = REG_BITS[MOD(LOOP+REG2+1,BITS_PER_WORD_1)];
+
+ REGISTER[REG1] = BITS_TO_BYTE(SHIFTED_BITS,BITS_PER_WORD_1);
+
+ if (PRINT_EFFECT) {
+ PRINT_REG_NAME("Set ",REG1,"");
+ PRINT_CONSTANT(" to ",REGISTER[REG1],".\n");
+ }
+ }
+ }
+
+ /* --------------------------------- SHIFTR_P ------------------------------ */
+ void SHIFTR_P(PRINT_EFFECT)
+ BOOLEAN PRINT_EFFECT; /* Output effect of this command for debugging */
+ {
+ int REG1; /* First Register in instruction */
+ int REG2; /* Second Register in instruction */
+
+ FORMAT2(®1,®2);
+ if (!( (REG1 >=0 ) && (REG1 < NUM_REGISTERS))) SIGNAL_INTERUPT(2,00);
+ else {
+ int LOOP; /* COUNTER VARIBLE */
+ int REG_BITS[BITS_PER_WORD_1];
+ int SHIFTED_BITS[BITS_PER_WORD_1];
+
+ BYTES_TO_BITS(REGISTER[REG1],3,REG_BITS);
+ for (LOOP = 0; LOOP < BITS_PER_WORD_1; LOOP ++)
+ if (LOOP <= REG2) SHIFTED_BITS[LOOP] = REG_BITS[0];
+ else SHIFTED_BITS[LOOP] = REG_BITS[LOOP-REG2-1];
+
+ REGISTER[REG1] = BITS_TO_BYTE(SHIFTED_BITS,BITS_PER_WORD_1);
+
+ if (PRINT_EFFECT) {
+ PRINT_REG_NAME("Set ",REG1,"");
+ PRINT_CONSTANT(" to ",REGISTER[REG1],".\n");
+ }
+ }
+ }
+
+ /* ---------------------------------- SUBR_P ------------------------------- */
+ /* This proceedure is messy because work had to be done with the signs of */
+ /* the arguments so that overflow could be detected. */
+ void SUBR_P(PRINT_EFFECT)
+ BOOLEAN PRINT_EFFECT; /* Output effect of this command for debugging */
+ {
+ BOOLEAN OVERFLOW1 = FALSE_1; /* Has an overflow been detected. */
+ int REG1; /* First Register in instruction */
+ int REG2; /* Second Register in instruction */
+ int REG1_SIGN = 1; /* Sign of value in the first register */
+ int REG2_SIGN = 1; /* Sign of value in the second register */
+
+ FORMAT2(®1,®2);
+
+ if (!( ( (REG1 >=0 ) && (REG1 < NUM_REGISTERS)) ||
+ ( (REG2 >=0 ) && (REG2 < NUM_REGISTERS)) )) {
+ SIGNAL_INTERUPT(2,00);
+ } else {
+
+ /* --------------- This is needed to correctly dectect overflow ------------ */
+ if (REGISTER[REG1] >= MAX_INT_1 / 2) REG1_SIGN = -1;
+ if (REGISTER[REG2] >= MAX_INT_1 / 2) REG2_SIGN = -1;
+
+ if ((REG2_SIGN == 1) && (REG1_SIGN == 1)) {
+ REGISTER[REG2] = REGISTER[REG2] + (MAX_INT_1 - REGISTER[REG1]);
+ REGISTER[REG2] = REGISTER[REG2] -
+ ((int) REGISTER[REG2] / MAX_INT_1) * MAX_INT_1;
+ }
+ if ((REG2_SIGN == -1) && (REG1_SIGN == 1)) {
+ REGISTER[REG2] = REGISTER[REG2] + (MAX_INT_1 - REGISTER[REG1]);
+ REGISTER[REG2] = REGISTER[REG2] -
+ ((int) REGISTER[REG2] / MAX_INT_1) * MAX_INT_1;
+ if (REGISTER[REG2] < MAX_INT_1 / 2) OVERFLOW1 = TRUE_1;
+ }
+ if ((REG2_SIGN == 1) && (REG1_SIGN == -1)) {
+ REGISTER[REG2] = REGISTER[REG2] + (MAX_INT_1 - REGISTER[REG1]);
+ if (REGISTER[REG2] >= MAX_INT_1 / 2) OVERFLOW1 = TRUE_1;
+ }
+ if ((REG2_SIGN == -1) && (REG1_SIGN == -1)) {
+ REGISTER[REG2] = REGISTER[REG2] + (MAX_INT_1 - REGISTER[REG1]);
+ REGISTER[REG2] = REGISTER[REG2] -
+ ((int) REGISTER[REG2] / MAX_INT_1) * MAX_INT_1;
+ }
+
+ if (PRINT_EFFECT) {
+ PRINT_REG_NAME("Set ",REG2,"");
+ PRINT_CONSTANT(" to ",REGISTER[REG2],".\n");
+ }
+ if (OVERFLOW1) SIGNAL_INTERUPT(2,04);
+ }
+ }
+
+ /* ----------------------------------- SVC_P ------------------------------- */
+ void SVC_P(PRINT_EFFECT)
+ BOOLEAN PRINT_EFFECT; /* Output effect of this command for debugging */
+ {
+ int REG1; /* First Register in instruction */
+ int REG2; /* Second Register in instruction */
+
+ FORMAT2(®1,®2);
+
+ if ( (REG1 < 0 ) || (REG1 > 4))
+ SIGNAL_INTERUPT(2,00);
+ else {
+ SIGNAL_INTERUPT(1,REG1);
+ if (PRINT_EFFECT) (void) printf("Generated SVC interupt %d.\n",REG1);
+ }
+ }
+
+ /* ---------------------------------- TIXR_P ------------------------------- */
+ void TIXR_P(PRINT_EFFECT)
+ BOOLEAN PRINT_EFFECT; /* Output effect of this command for debugging */
+ {
+ int REG1; /* First Register in instruction */
+ int REG2; /* Second Register in instruction */
+ int X_VAL; /* Value stored in X */
+ int REG_VAL; /* Value stored in REG1 */
+
+ FORMAT2(®1,®2);
+
+ if (!( (REG1 >=0 ) && (REG1 < NUM_REGISTERS)))
+ SIGNAL_INTERUPT(2,00);
+ else {
+
+ X_0 ++;
+ X_0 = X_0 - ((int) X_0 / MAX_INT_1) * MAX_INT_1;
+
+ if (X_0 == MAX_INT_1 / 2) {
+ SIGNAL_INTERUPT(2,04);
+ if (PRINT_EFFECT) (void) printf("X has overflowed.\n");
+ return;
+ }
+
+ if (X_0 >= MAX_INT_1 / 2) X_VAL = X_0 - MAX_INT_1;
+ else X_VAL = X_0;
+
+ REG_VAL = REGISTER[REG1];
+
+ if (REG_VAL >= MAX_INT_1 / 2) REG_VAL = REG_VAL - MAX_INT_1;
+
+ if (X_VAL == REG_VAL) {
+ SET_CC(EQUAL_1);
+ if (PRINT_EFFECT)
+ PRINT_CONSTANT("Set X to ",X_0," and set CC to =.\n");
+ }
+ if (X_VAL < REG_VAL) {
+ SET_CC(LESS_THAN_1);
+ if (PRINT_EFFECT)
+ PRINT_CONSTANT("Set X to ",X_0," and set CC to <.\n");
+ }
+ if (X_VAL > REG_VAL) {
+ SET_CC(GREATER_THAN_1);
+ if (PRINT_EFFECT)
+ PRINT_CONSTANT("Set X to ",X_0," and set CC to >.\n");
+ }
+ }
+ }
Index: llvm-test/MultiSource/Benchmarks/Prolangs-C/simulator/instruct2.h
diff -c /dev/null llvm-test/MultiSource/Benchmarks/Prolangs-C/simulator/instruct2.h:1.1
*** /dev/null Tue Oct 5 16:08:51 2004
--- llvm-test/MultiSource/Benchmarks/Prolangs-C/simulator/instruct2.h Tue Oct 5 16:08:39 2004
***************
*** 0 ****
--- 1,72 ----
+ /* %%%%%%%%%%%%%%%%%%%% (c) William Landi 1991 %%%%%%%%%%%%%%%%%%%%%%%%%%%% */
+ /* Permission to use this code is granted as long as the copyright */
+ /* notice remains in place. */
+ /* ============================== intruction2.h ============================ */
+ /* Contains all the procedures that know how to handle FORMAT2 instructions */
+ /* Name of the procedure is the same as the SIC/XE instruction name but with */
+ /* a '_P' added to the end. See p. 410-411 of "System Software: An */
+ /* Introduction to Systems Programming" by Leland L. Beck for detailed */
+ /* Description to the function of each command. */
+
+ /* ----------------------------------- ADDR_P ------------------------------ */
+ /* 1 parameter: */
+ /* 1) BOOLEAN PRINT_EFFECT; Output effect of this command for debugging */
+ /* This proceedure is messy because work had to be done with the signs of */
+ /* the arguments so that overflow could be detected. */
+ extern void ADDR_P();
+
+ /* ----------------------------------- CLEAR_P ---------------------------- */
+ /* 1 parameter: */
+ /* 1) BOOLEAN PRINT_EFFECT; Output effect of this command for debugging */
+ extern void CLEAR_P();
+
+ /* ---------------------------------- COMPR_P ------------------------------ */
+ /* 1 parameter: */
+ /* 1) BOOLEAN PRINT_EFFECT; Output effect of this command for debugging */
+ extern void COMPR_P();
+
+ /* ---------------------------------- DIVR_P ------------------------------ */
+ /* 1 parameter: */
+ /* 1) BOOLEAN PRINT_EFFECT; Output effect of this command for debugging */
+ /* This proceedure is messy because work had to be done with the signs of */
+ /* the arguments. */
+ extern void DIVR_P();
+
+ /* ---------------------------------- MULR_P ------------------------------ */
+ /* 1 parameter: */
+ /* 1) BOOLEAN PRINT_EFFECT; Output effect of this command for debugging */
+ /* This proceedure is messy because work had to be done with the signs of */
+ /* the arguments so that overflow could be detected. */
+ extern void MULR_P();
+
+ /* ----------------------------------- RMO_P ------------------------------- */
+ /* 1 parameter: */
+ /* 1) BOOLEAN PRINT_EFFECT; Output effect of this command for debugging */
+ extern void RMO_P();
+
+ /* --------------------------------- SHIFTL_P ------------------------------ */
+ /* 1 parameter: */
+ /* 1) BOOLEAN PRINT_EFFECT; Output effect of this command for debugging */
+ extern void SHIFTL_P();
+
+ /* --------------------------------- SHIFTR_P ------------------------------ */
+ /* 1 parameter: */
+ /* 1) BOOLEAN PRINT_EFFECT; Output effect of this command for debugging */
+ extern void SHIFTR_P();
+
+ /* ---------------------------------- SUBR_P ------------------------------- */
+ /* 1 parameter: */
+ /* 1) BOOLEAN PRINT_EFFECT; Output effect of this command for debugging */
+ /* This proceedure is messy because work had to be done with the signs of */
+ /* the arguments so that overflow could be detected. */
+ extern void SUBR_P();
+
+ /* ----------------------------------- SVC_P ------------------------------- */
+ /* 1 parameter: */
+ /* 1) BOOLEAN PRINT_EFFECT; Output effect of this command for debugging */
+ extern void SVC_P();
+
+ /* ---------------------------------- TIXR_P ------------------------------- */
+ /* 1 parameter: */
+ /* 1) BOOLEAN PRINT_EFFECT; Output effect of this command for debugging */
+ extern void TIXR_P();
Index: llvm-test/MultiSource/Benchmarks/Prolangs-C/simulator/interupt.c
diff -c /dev/null llvm-test/MultiSource/Benchmarks/Prolangs-C/simulator/interupt.c:1.1
*** /dev/null Tue Oct 5 16:08:51 2004
--- llvm-test/MultiSource/Benchmarks/Prolangs-C/simulator/interupt.c Tue Oct 5 16:08:39 2004
***************
*** 0 ****
--- 1,30 ----
+ /* %%%%%%%%%%%%%%%%%%%% (c) William Landi 1991 %%%%%%%%%%%%%%%%%%%%%%%%%%%% */
+ /* Permission to use this code is granted as long as the copyright */
+ /* notice remains in place. */
+
+ /* ============================== interupt.c =============================== */
+ /* Handles interupts, rather simply. */
+
+ #include "boolean.h"
+ #include "memory.h"
+ #include "machine.h"
+ #include "debugger.h"
+ #include "sim_debug.h"
+ #include "constants.h"
+
+ /* ------------------------------ SIGNAL_INTERUPT -------------------------- */
+ /* Handles a signal interupt. */
+ void SIGNAL_INTERUPT(TYPE,CODE)
+ int TYPE; /* TYPE/CLASS of interupt (1,2,3, or 4) */
+ int CODE; /* Interupt code. */
+ {
+ switch(TYPE) {
+ case 2:
+ SW_0 = ((int) SW_0 / 256) * 256 + CODE;
+ RETURN_STATUS = ABNORMAL_1;
+ break;
+ default:
+ ;
+ }
+ }
+
Index: llvm-test/MultiSource/Benchmarks/Prolangs-C/simulator/interupt.h
diff -c /dev/null llvm-test/MultiSource/Benchmarks/Prolangs-C/simulator/interupt.h:1.1
*** /dev/null Tue Oct 5 16:08:51 2004
--- llvm-test/MultiSource/Benchmarks/Prolangs-C/simulator/interupt.h Tue Oct 5 16:08:39 2004
***************
*** 0 ****
--- 1,12 ----
+ /* %%%%%%%%%%%%%%%%%%%% (c) William Landi 1991 %%%%%%%%%%%%%%%%%%%%%%%%%%%% */
+ /* Permission to use this code is granted as long as the copyright */
+ /* notice remains in place. */
+ /* ============================== interupt.h =============================== */
+ /* Handles interupts, rather simply. */
+
+ /* ------------------------------ SIGNAL_INTERUPT -------------------------- */
+ /* 2 parameters: */
+ /* 1) int TYPE; TYPE/CLASS of interupt (1,2,3, or 4) */
+ /* 2) int CODE; Interupt code. */
+ /* Handles a signal interupt. */
+ extern void SIGNAL_INTERUPT();
Index: llvm-test/MultiSource/Benchmarks/Prolangs-C/simulator/load.h
diff -c /dev/null llvm-test/MultiSource/Benchmarks/Prolangs-C/simulator/load.h:1.1
*** /dev/null Tue Oct 5 16:08:51 2004
--- llvm-test/MultiSource/Benchmarks/Prolangs-C/simulator/load.h Tue Oct 5 16:08:39 2004
***************
*** 0 ****
--- 1,12 ----
+ /* %%%%%%%%%%%%%%%%%%%% (c) William Landi 1991 %%%%%%%%%%%%%%%%%%%%%%%%%%%% */
+ /* Permission to use this code is granted as long as the copyright */
+ /* notice remains in place. */
+ /* ================================= load.h =============================== */
+
+ /* --------------------------------- Globals ------------------------------ */
+ /* START_ADDRESS Start Address for program execution. */
+ int START_ADDRESS;
+
+ /* MAIN_ROUTINE Name of (program) module declared with */
+ /* a START (main routine). */
+ char MAIN_ROUTINE[LABEL_SIZE_1+1];
Index: llvm-test/MultiSource/Benchmarks/Prolangs-C/simulator/loadexe.c
diff -c /dev/null llvm-test/MultiSource/Benchmarks/Prolangs-C/simulator/loadexe.c:1.1
*** /dev/null Tue Oct 5 16:08:51 2004
--- llvm-test/MultiSource/Benchmarks/Prolangs-C/simulator/loadexe.c Tue Oct 5 16:08:39 2004
***************
*** 0 ****
--- 1,100 ----
+ /* %%%%%%%%%%%%%%%%%%%% (c) William Landi 1991 %%%%%%%%%%%%%%%%%%%%%%%%%%%% */
+ /* Permission to use this code is granted as long as the copyright */
+ /* notice remains in place. */
+
+ /* ================================ loadexe.c ============================== */
+ /* Sets up the machine from the executable file ('loads' program) */
+
+ #include <stdio.h>
+ #include <string.h>
+ #include "boolean.h"
+ #include "stringI.h"
+ #include "memory.h"
+ #include "constants.h"
+ #include "convert.h"
+ #include "machine.h"
+ #include "debugger.h"
+
+ /* ------------------------------ LOAD ------------------------------------- */
+ /* Load the program from the executable file. */
+ void LOAD(BOOLEAN DEBUG_MODE,int *ERROR,FILE *INPUT)
+ {
+ char *RECORD; /* One record from the input stream */
+ int LENGTH; /* Used to store length of blocks of */
+ /* memory affected by text and modification*/
+ /* records */
+ int LOCATION = 0; /* Location to load next csect */
+ char MODULE_NAME[LABEL_SIZE_1+1]; /* Name of a module of program. */
+
+ MODULE_NAME[LABEL_SIZE_1] = '\0';
+
+ if (feof(INPUT)) (*ERROR) = TRUE_1;
+ else {
+ GET_LINE(&RECORD,INPUT);
+ if ((RECORD[0] != 'S') || (strlen(RECORD) != 14)) (*ERROR) = TRUE_1;
+ else {
+ /* ---------------------------- START RECORD ------------------------------- */
+ if (DEBUG_MODE) {
+ MAIN_ROUTINE[LABEL_SIZE_1] = '\0';
+ (void) strncpy(MAIN_ROUTINE,&(RECORD[1]),LABEL_SIZE_1);
+ }
+ STR_TO_NUM(&(RECORD[LABEL_SIZE_1+1]), 5, 16,
+ &START_ADDRESS,ERROR);
+ }
+ }
+
+ while (!feof(INPUT) && (LOCATION <= MEM_SIZE_1) && !(*ERROR)) {
+
+ GET_LINE(&RECORD,INPUT);
+ switch (RECORD[0]) {
+
+ case 'T':
+ /* ---------------------------- TEXT RECORD -------------------------------- */
+ if (strlen(RECORD) < 9)
+ (*ERROR) = TRUE_1;
+ else {
+
+ STR_TO_NUM(&(RECORD[1]),6,16,&LOCATION,ERROR);
+ STR_TO_NUM(&(RECORD[7]),2,16,&LENGTH,ERROR);
+ if (strlen(RECORD) != 9+LENGTH*2) (*ERROR) = TRUE_1;
+ else STORE_AT(&(RECORD[9]), LENGTH, LOCATION, MEMORY,ERROR);
+ }
+ break;
+
+
+ case 'M':
+ /* ---------------------- MODULE RECORD ------------------------------------ */
+ if (strlen(RECORD) != (13 + LABEL_SIZE_1)) (*ERROR) = TRUE_1;
+ else if (DEBUG_MODE) {
+
+ (void) strncpy(MODULE_NAME,&(RECORD[1]),LABEL_SIZE_1);
+ STR_TO_NUM(&(RECORD[9]),6,16,&LOCATION,ERROR);
+ (*ERROR) = !INSERT_IN_SYM_TAB(GLOBAL_1,MODULE_NAME,LOCATION,MODULE,
+ &SYM_TAB);
+ STR_TO_NUM(&(RECORD[15]),6,16,&LENGTH,ERROR);
+ (*LOOK_UP_SYMBOL(GLOBAL_1,MODULE_NAME,&SYM_TAB)).LENGTH = LENGTH;
+ }
+
+ break;
+
+ case 'G':
+ /* ----------------------- GLOBAL RECORD ----------------------------------- */
+ if (strlen(RECORD) != (7 + LABEL_SIZE_1)) (*ERROR) = TRUE_1;
+ else if (DEBUG_MODE) {
+
+ (void) strncpy(MODULE_NAME,&(RECORD[1]),LABEL_SIZE_1);
+ STR_TO_NUM(&(RECORD[9]),6,16,&LOCATION,ERROR);
+ (*ERROR) = !INSERT_IN_SYM_TAB(GLOBAL_1,MODULE_NAME,LOCATION,GLOBAL,
+ &SYM_TAB);
+ }
+
+ break;
+
+ case '\0':
+ default:
+ break;
+ }
+ }
+ if (*ERROR)
+ (void) printf("ERROR: Input is not an executable file. Aborting.\n");
+ }
Index: llvm-test/MultiSource/Benchmarks/Prolangs-C/simulator/loadexe.h
diff -c /dev/null llvm-test/MultiSource/Benchmarks/Prolangs-C/simulator/loadexe.h:1.1
*** /dev/null Tue Oct 5 16:08:51 2004
--- llvm-test/MultiSource/Benchmarks/Prolangs-C/simulator/loadexe.h Tue Oct 5 16:08:39 2004
***************
*** 0 ****
--- 1,13 ----
+ /* %%%%%%%%%%%%%%%%%%%% (c) William Landi 1991 %%%%%%%%%%%%%%%%%%%%%%%%%%%% */
+ /* Permission to use this code is granted as long as the copyright */
+ /* notice remains in place. */
+ /* ================================ loadexe.h ============================== */
+ /* Sets up the machine from the executable file ('loads' program) */
+
+ /* ------------------------------ LOAD ------------------------------------- */
+ /* 3 parameters: */
+ /* 1) BOOLEAN DEBUG_MODE; False - Simulator; True - Sim/Debugger */
+ /* 2) int *ERROR; any errors in the executable code? */
+ /* 3) FILE *INPUT; stream with the executable code */
+ /* Load the program from the executable file. */
+ extern void LOAD();
Index: llvm-test/MultiSource/Benchmarks/Prolangs-C/simulator/machine.c
diff -c /dev/null llvm-test/MultiSource/Benchmarks/Prolangs-C/simulator/machine.c:1.1
*** /dev/null Tue Oct 5 16:08:51 2004
--- llvm-test/MultiSource/Benchmarks/Prolangs-C/simulator/machine.c Tue Oct 5 16:08:39 2004
***************
*** 0 ****
--- 1,506 ----
+ /* %%%%%%%%%%%%%%%%%%%% (c) William Landi 1991 %%%%%%%%%%%%%%%%%%%%%%%%%%%% */
+ /* Permission to use this code is granted as long as the copyright */
+ /* notice remains in place. */
+
+ /* ============================= machine.c ================================= */
+ /* Maintains all the information associated with the machine. Can be used to */
+ /* drive complete simulation of a program or just execute one instruction. */
+ #include <math.h>
+ #include <stdio.h>
+ #include "boolean.h"
+ #include "constants.h"
+ #include "convert.h"
+ #include "memory.h"
+ #include "sim_debug.h"
+ #include "debugger.h"
+ #include "instruct.h"
+ #include "instruct2.h"
+ #include "interupt.h"
+
+ /* --------------------------------- GLOBALS ------------------------------ */
+ /* MEMORY THE MAIN MEMORY. */
+ MEM_SPACE MEMORY = NULL;
+
+ /* INTERVAL_TIMER USED FOR TIMING OUT A PROCESS AND */
+ int INTERVAL_TIMER = 0; /* RETURNING CONTROL TO THE OS */
+
+ /* ---------------------------- THE REGISTERS ----------------------------- */
+ int REGISTER[NUM_REGISTERS];
+ #define A_0 REGISTER[0] /* 0 A ACCUMULATOR */
+ #define X_0 REGISTER[1] /* 1 X INDEX REGISTER */
+ #define L_0 REGISTER[2] /* 2 L LINKAGE REGISTER */
+ #define B_0 REGISTER[3] /* 3 B BASE REGISTER */
+ #define S_0 REGISTER[4] /* 4 S GENERAL REGISTER */
+ #define T_0 REGISTER[5] /* 5 T GENERAL REGISTER */
+ #define F_0 REGISTER[6] /* 6 F FLOATING POINT - NOT*/
+ /* IMPLEMENTED */
+ /* 7 NO REGISTER */
+ #define PC_0 REGISTER[8] /* 8 PC PROGRAM COUNTER */
+ #define SW_0 REGISTER[9] /* 9 SW STATUS WORD */
+
+ /* ------------------------------ THE DEVICES ------------------------------ */
+ #define NOT_IN_USE_1 0
+ #define IN_USE_1 1
+ /* THE DEVICES: */
+ /* 0 KEYBOARD (INPUT) */
+ /* 80 TERMINAL (OUTPUT) */
+ /* I (00 <= I <= FF) FILE NAMED DEVI */
+ /* I (00 <= I < 80) Input Devices. I (80 <= I <= FF) Output Devices. */
+ struct DEVICE_ENTRY {
+ int STATUS;
+ FILE *STREAM;
+ } DEVICE[256];
+
+ /* --------------------- NON-GLOBAL MACHINE STRUCTURES -------------------- */
+ #include "define-instr-tab.h"
+ char REG_NAMES[NUM_REGISTERS][3] = /* Name of the registers. */
+ {"A","X","L","B","S","T","F","7","PC","SW"};
+
+ BOOLEAN PRINT_INSTR = FALSE_1; /* Not a nice fix, so that */
+ /* PRINT_ADDRESS can print */
+ /* in instruction format when needed */
+ /* Should be a parameter, but too */
+ /* much work for me to correct. */
+
+ extern void FORMAT2(int *REG1,int *REG2);
+ extern int FORMAT3_4(int DEMAND,int BYTES);
+
+ void CALL_FUNCTION1(int FUNC,BOOLEAN PRINT_EFFECT)
+ {
+ switch(FUNC) {
+ case LDA_P0: LDA_P(PRINT_EFFECT);
+ break;
+ case LDX_P0: LDX_P(PRINT_EFFECT);
+ break;
+ case LDL_P0: LDL_P(PRINT_EFFECT);
+ break;
+ case STA_P0: STA_P(PRINT_EFFECT);
+ break;
+ case STX_P0: STX_P(PRINT_EFFECT);
+ break;
+ case STL_P0: STL_P(PRINT_EFFECT);
+ break;
+ case ADD_P0: ADD_P(PRINT_EFFECT);
+ break;
+ case SUB_P0: SUB_P(PRINT_EFFECT);
+ break;
+ case MUL_P0: MUL_P(PRINT_EFFECT);
+ break;
+ case DIV_P0: DIV_P(PRINT_EFFECT);
+ break;
+ case COMP_P0: COMP_P(PRINT_EFFECT);
+ break;
+ case TIX_P0: TIX_P(PRINT_EFFECT);
+ break;
+ case JEQ_P0: JEQ_P(PRINT_EFFECT);
+ break;
+ case JGT_P0: JGT_P(PRINT_EFFECT);
+ break;
+ case JLT_P0: JLT_P(PRINT_EFFECT);
+ break;
+ case J_P0: J_P(PRINT_EFFECT);
+ break;
+ case AND_P0: AND_P(PRINT_EFFECT);
+ break;
+ case OR_P0: OR_P(PRINT_EFFECT);
+ break;
+ case JSUB_P0: JSUB_P(PRINT_EFFECT);
+ break;
+ case RSUB_P0: RSUB_P(PRINT_EFFECT);
+ break;
+ case LDCH_P0: LDCH_P(PRINT_EFFECT);
+ break;
+ case STCH_P0: STCH_P(PRINT_EFFECT);
+ break;
+ case NULL0: break;
+ case LDB_P0: LDB_P(PRINT_EFFECT);
+ break;
+ case LDS_P0: LDS_P(PRINT_EFFECT);
+ break;
+ case LDT_P0: LDT_P(PRINT_EFFECT);
+ break;
+ case STB_P0: STB_P(PRINT_EFFECT);
+ break;
+ case STS_P0: STS_P(PRINT_EFFECT);
+ break;
+ case STT_P0: STT_P(PRINT_EFFECT);
+ break;
+ case ADDR_P0: ADDR_P(PRINT_EFFECT);
+ break;
+ case SUBR_P0: SUBR_P(PRINT_EFFECT);
+ break;
+ case MULR_P0: MULR_P(PRINT_EFFECT);
+ break;
+ case DIVR_P0: DIVR_P(PRINT_EFFECT);
+ break;
+ case COMPR_P0: COMPR_P(PRINT_EFFECT);
+ break;
+ case SHIFTL_P0: SHIFTL_P(PRINT_EFFECT);
+ break;
+ case SHIFTR_P0: SHIFTR_P(PRINT_EFFECT);
+ break;
+ case RMO_P0: RMO_P(PRINT_EFFECT);
+ break;
+ case SVC_P0: SVC_P(PRINT_EFFECT);
+ break;
+ case CLEAR_P0: CLEAR_P(PRINT_EFFECT);
+ break;
+ case TIXR_P0: TIXR_P(PRINT_EFFECT);
+ break;
+ case STI_P0: STI_P(PRINT_EFFECT);
+ break;
+ case RD_P0: RD_P(PRINT_EFFECT);
+ break;
+ case WD_P0: WD_P(PRINT_EFFECT);
+ break;
+ case TD_P0: TD_P(PRINT_EFFECT);
+ break;
+ case STSW_P0: STSW_P(PRINT_EFFECT);
+ break;
+ }
+ }
+ /* --------------------------- RESET_DEVICES ------------------------------- */
+ /* Reset all the devices. This is needed so that if you run program twice */
+ /* in one debugging section, you can be sure the devices will be okay. */
+ void RESET_DEVICES(void)
+ {
+ int COUNT;
+
+ DEVICE[0].STATUS = NOT_IN_USE_1;
+ DEVICE[0].STREAM = NULL;
+ DEVICE[128].STATUS = NOT_IN_USE_1;
+ DEVICE[128].STREAM = NULL;
+ for (COUNT = 0; COUNT < 256; COUNT ++) {
+ if (DEVICE[COUNT].STATUS == IN_USE_1)
+ DEVICE[COUNT].STATUS = NOT_IN_USE_1;
+ if (DEVICE[COUNT].STREAM != NULL) {
+ (void) fclose(DEVICE[COUNT].STREAM);
+ DEVICE[COUNT].STREAM = NULL;
+ }
+ }
+ }
+
+ /* --------------------------- PRINT_REG_NAME ------------------------------ */
+ /* Prints out STR1, followed by the name of a register, followed by STR2. */
+ void PRINT_REG_NAME(char *STR1,int REG_NUM,char *STR2)
+ {
+ (void) printf("%S%S%S",STR1,REG_NAMES[REG_NUM],STR2);
+ }
+
+ /* ------------------------- INSTR_CODE (local) ---------------------------- */
+ /* Returns the first 6 bits of a BYTE. The relevant part to determining */
+ /* which instruction it is. */
+ int INSTR_CODE(int LOC)
+ {
+ return (INT(MEMORY[LOC]) / 4);
+ }
+
+ /* ----------------------------- BYTES_TO_BITS ----------------------------- */
+ /* Convert BYTES bytes store in VAL (the variable VAL) and set BINARY to be */
+ /* the corresponding binary array of BITS. */
+ void BYTES_TO_BITS(int VAL,int NUM_BYTES,int *BINARY)
+ {
+ int I;
+
+ for (I=1;I<=BITS_PER_BYTE_2*NUM_BYTES;I++) {
+ BINARY[BITS_PER_BYTE_2*NUM_BYTES - I] = VAL - ((int) VAL / 2) * 2;
+ VAL = VAL / 2;
+ }
+ }
+
+ /* -------------------------- BITS_TO_BYTE --------------------------------- */
+ /* Convert an array of BITS bits to an integer (BYTE) and return result. */
+ int BITS_TO_BYTE(int *BINARY,int BITS)
+ {
+ int I; /* Counter variable. */
+ int VAL; /* VALue to return. */
+
+ VAL = 0;
+ for ( I = 0; I < BITS; I ++)
+ VAL = VAL * 2 + BINARY[I];
+
+ return VAL;
+ }
+
+ /* --------------------------- SET_CC -------------------------------------- */
+ /* SET the CC (Condition Code) to CODE */
+ void SET_CC(int CODE)
+ {
+ int SW[BITS_PER_WORD_1];
+
+ if ((CODE >= 0) && (CODE <= 3)) {
+ BYTES_TO_BITS(SW_0,3,SW);
+ SW[6] = CODE / 2;
+ SW[7] = CODE - SW[6]*2;
+ SW_0 = BITS_TO_BYTE(SW,BITS_PER_WORD_1);
+ } else (void) printf("SET_CC called improperly.\n");
+ }
+
+ /* ---------------------------------- CC ----------------------------------- */
+ /* Return the value stored in the condition code. */
+ int CC(void)
+ {
+ int SW[BITS_PER_WORD_1];
+
+ BYTES_TO_BITS(SW_0,3,SW);
+ return SW[6] * 2 + SW[7];
+ }
+
+ /* ---------------------------- SUPERVISOR_MODE ---------------------------- */
+ /* Return TRUE iff in SUPERVISOR MODE. */
+ BOOLEAN SUPERVISOR_MODE(void)
+ {
+ int SW[BITS_PER_WORD_1]; /* BIT version of SW (status word) */
+
+ BYTES_TO_BITS(SW_0,3,SW);
+ return (SW[0] == 1);
+ }
+
+ /* ------------------------ DIGIT_TO_CHAR (local) -------------------------- */
+ /* Convert a DIGIT to its character representation BASE 16. */
+ char DIGIT_TO_CHAR(int DIGIT)
+ {
+ char CH;
+ if (9 >= DIGIT) CH = DIGIT + '0';
+ else CH = DIGIT - 10 + 'A';
+ return CH;
+ }
+
+ /* --------------------------- OPEN_DEVICE --------------------------------- */
+ /* Mark device DEV as IN USE and, if needed, open it. */
+ void OPEN_DEVICE(int DEV)
+ {
+
+ DEVICE[DEV].STATUS = IN_USE_1;
+ if (DEVICE[DEV].STREAM == NULL)
+ {
+ char NAME[6];
+
+ NAME[0] = 'd'; NAME[1] = 'e'; NAME[2] = 'v'; NAME[5] = '\0';
+
+ if (DEV == 0)
+ DEVICE[0].STREAM = stdin;
+ else if (DEV == 128)
+ DEVICE[128].STREAM = stdout;
+ else {
+ NAME[3] = DIGIT_TO_CHAR(DEV/16);
+ NAME[4] = DIGIT_TO_CHAR(DEV - ((int) DEV/16)*16);
+ if (DEV < 128)
+ DEVICE[DEV].STREAM = fopen(NAME,"r");
+ else DEVICE[DEV].STREAM = fopen(NAME,"w");
+ }
+ }
+ }
+
+ /* Declared later on in this file... see bellow. */
+ extern void PRINT_INSTRUCTION();
+
+ /* ---------------------------- PRINT_ADDRESS ------------------------------ */
+ /* Output PREFIX, followed by the ADDRESS, followed by SUFFIX. Print the */
+ /* Address in hexidecimal, decimal or by a LABEL name. */
+ void PRINT_ADDRESS(char *PREFIX,int ADDRESS,char *SUFFIX)
+ {
+ char ADDR[LABEL_SIZE_1+1]; /* String version of address. */
+ SYMBOL_TABLE NEXT; /* Used to walk through the symbol table */
+
+ NEXT = SYM_TAB;
+ while (NEXT != NULL)
+ if ((*NEXT).LOCATION == ADDRESS) {
+ int COUNT;
+ char SAV;
+
+ for (COUNT=LABEL_SIZE_1-1;
+ (COUNT > 0) && ((*NEXT).LABEL[COUNT] == ' ');
+ COUNT --);
+ SAV = (*NEXT).LABEL[COUNT+1];
+ (*NEXT).LABEL[COUNT+1] = '\0';
+ (void) printf("%s%s%s",PREFIX,(*NEXT).LABEL,SUFFIX);
+ (*NEXT).LABEL[COUNT+1] = SAV;
+ NEXT = NULL;
+ return;
+ } else NEXT = (*NEXT).NEXT;
+
+ if (TYPE_OUT_MODE[0] == 'D') {
+ NUM_TO_STR(ADDRESS,10,8,ADDR);
+ (void) printf("%s%s [base 10]%s",PREFIX,ADDR,SUFFIX);
+ }
+ else {
+ NUM_TO_STR(ADDRESS,16,6,ADDR);
+ if (!PRINT_INSTR)
+ (void) printf("%s%s [base 16]%s",PREFIX,ADDR,SUFFIX);
+ else (void) printf("%s%s%s",PREFIX,ADDR,SUFFIX);
+ }
+ }
+
+ /* ---------------------------- PRINT_CONSTANT ----------------------------- */
+ /* Output PREFIX, followed by the CONSTANT in a base depending on */
+ /* TYPE_OUT_MODE, followed by SUFFIX */
+ void PRINT_CONSTANT(char *PREFIX,int CONST,char *SUFFIX)
+ {
+ char STR_CONST[LABEL_SIZE_1+1];
+ int DIGITS;
+
+ if (TYPE_OUT_MODE[0] == 'D') {
+ if (CONST == 0) DIGITS = 1;
+ else DIGITS = ((int) (log(1.0*CONST)/log(10.0))) + 1;
+ NUM_TO_STR(CONST,10,DIGITS,STR_CONST);
+ (void) printf("%s%s [base 10]%s",PREFIX,STR_CONST,SUFFIX);
+ }
+ else {
+ if (CONST == 0) DIGITS = 1;
+ else DIGITS = ((int) (log(1.0*CONST)/log(16.0))) + 1;
+ NUM_TO_STR(CONST,16,DIGITS,STR_CONST);
+ if (!PRINT_INSTR)
+ (void) printf("%s%s [base 16]%s",PREFIX,STR_CONST,SUFFIX);
+ else (void) printf("%s%s%s",PREFIX,STR_CONST,SUFFIX);
+ }
+ }
+
+ /* ------------------------- PRINT_INSTRUCTION ----------------------------- */
+ /* Output a number as a SIC/XE instruction. */
+ void PRINT_INSTRUCTION(int LOCATION,BOOLEAN PRINT,int *BYTES)
+ {
+ int BIT_INSTR[4*BITS_PER_BYTE_2]; /* BIT array version of instruction. */
+ int CODE; /* Instruction code of instruction. */
+ int SAV_PC; /* SAVE PC because not executing anything */
+
+ /* ~~~~~~~~~~~~~~~~~~~~~~~ Figure out the number of BYTES */
+ PRINT_INSTR = TRUE_1;
+ CODE = INSTR_CODE(LOCATION);
+ if ((0 > LOCATION) || (MEM_SIZE_1 <= LOCATION)) {
+ (*BYTES) = 0;
+ if (PRINT) (void) printf("Address out of range.\n");
+ } else
+ if (INSTR[CODE].FORMAT < 3)
+ (*BYTES) = INSTR[CODE].FORMAT;
+ else {
+ BYTES_TO_BITS(INT(MEMORY[LOCATION]),1,BIT_INSTR);
+ BYTES_TO_BITS(INT(MEMORY[LOCATION+1]),1,&(BIT_INSTR[8]));
+ BYTES_TO_BITS(INT(MEMORY[LOCATION+2]),1,&(BIT_INSTR[16]));
+ /* ------------------ if expended format bit on and not plane sic -----------*/
+ if ((BIT_INSTR[11] == 1) && !((BIT_INSTR[6] == 0)
+ && (BIT_INSTR[7] == 0))) {
+ (*BYTES) = 4;
+ BYTES_TO_BITS(INT(MEMORY[LOCATION+3]),1,&(BIT_INSTR[24]));
+ }
+ else (*BYTES) = 3;
+ }
+ if (PRINT) {
+ /* ~~~~~~~~~~~~~~~~~~~~~~~~~ Print out the instruction */
+ /* ---------- print location */
+ PRINT_ADDRESS("======>",LOCATION," ");
+
+ /* ---------- if extended format print out '+' */
+ if ((*BYTES) == 4) (void) printf("+");
+ else (void) printf(" ");
+ (void) printf("%s ",INSTR[CODE].MNEMONIC);
+ if ((*BYTES) == 1) {
+ PRINT_INSTR = FALSE_1;
+ return;
+ }
+ SAV_PC = PC_0;
+ PC_0 = LOCATION;
+ if ((*BYTES) == 2) {
+ /* ~~~~~~~~~~~~~~~~~~~~~~~~ Print out format2 arguments. */
+ int REG1; /* register int bits 8-11 */
+ int REG2; /* register int bits 12-15 */
+
+ FORMAT2(®1,®2);
+ PC_0 = SAV_PC;
+
+ /* ------ ONE REGISTER INSTRUCTIONS --------------------------------------- */
+ if ((CODE == 45) || (CODE == 46)) {
+ if (REG1 >= NUM_REGISTERS)
+ (void) printf("illegal register\n");
+ else (void) printf("%s\n", REG_NAMES[REG1]);
+ PRINT_INSTR = FALSE_1;
+ return;
+ }
+ /* ----- ONE CONSTANT INSTRUCTIONS ---------------------------------------- */
+ if (CODE == 44) {
+ if (REG1 > 4)
+ (void) printf("illegal argument\n");
+ else (void) printf("%d\n", REG1);
+ PRINT_INSTR = FALSE_1;
+ return;
+ }
+ /* ------ ONE REGISTER, ONE CONSTANT INSTRUCTIONS ------------------------- */
+
+ if ((CODE == 41) || (CODE == 42)) {
+ if (REG1 >= NUM_REGISTERS)
+ (void) printf("illegal register,");
+ else (void) printf("%s,", REG_NAMES[REG1]);
+ PRINT_CONSTANT("",REG2,"\n");
+ PRINT_INSTR = FALSE_1;
+ return;
+ }
+ /* ------ TWO REGISTER INSTRUCTIONS --------------------------------------- */
+ if (REG1 >= NUM_REGISTERS)
+ (void) printf("illegal register,");
+ else (void) printf("%s,", REG_NAMES[REG1]);
+ if (REG2 >= NUM_REGISTERS)
+ (void) printf("illegal register\n");
+ else (void) printf("%s\n", REG_NAMES[REG2]);
+ PRINT_INSTR = FALSE_1;
+ return;
+ }
+ /* ~~~~~~~~~~~~~~~~~~~~~~~~~ print FORMAT3/4 arguments */
+ {
+ int LOCATION;
+
+ /* -------------- Direct, immediate, or indirect. */
+ if ((BIT_INSTR[6] == 1) && (BIT_INSTR[7] == 0)) (void) printf("@");
+ else if ((BIT_INSTR[6] == 0) && (BIT_INSTR[7] == 1)) (void) printf("#");
+ else (void) printf(" ");
+
+ if ((*BYTES) == 3) {
+ /* --------------- Format 3 address */
+ LOCATION = BITS_TO_BYTE(&(BIT_INSTR[12]),12);
+ if (BIT_INSTR[9] == 1) LOCATION += B_0;
+ if (BIT_INSTR[10] == 1) {
+ if (LOCATION >= MAX_PC_RELATIVE_1 / 2)
+ LOCATION = (LOCATION - MAX_PC_RELATIVE_1) + PC_0 + 3;
+ else LOCATION += PC_0 + 3;
+ }
+ } else {
+ /* --------------- Format 4 address */
+ LOCATION = BITS_TO_BYTE(&(BIT_INSTR[12]),20);
+ }
+ if (LOCATION < MEM_SIZE_1) PRINT_ADDRESS("",LOCATION,"");
+ else (void) printf("invalid address");
+ if (BIT_INSTR[8] == 1) (void) printf(",X");
+ PC_0 = SAV_PC;
+ (void) printf("\n");
+ PRINT_INSTR = FALSE_1;
+ }
+ PRINT_INSTR = FALSE_1;
+ }
+ }
+
+ /* ---------------------------------- EXEC --------------------------------- */
+ /* if DEBUG_MODE is FALSE, drives the whole simulation process, otherwise */
+ /* Just does one instruction and returns. */
+ void EXEC(BOOLEAN DEBUG_MODE,BOOLEAN PRINT_EFFECT)
+ {
+
+ do {
+ /* ---------------------- Treats codes without assigned functions as no-ops */
+ if (INSTR[INSTR_CODE(PC_0)].FUNCTION == NULL0) {
+ (void) printf("%d %s ",PC_0,INSTR[INSTR_CODE(PC_0)].MNEMONIC);
+ if (INSTR[INSTR_CODE(PC_0)].FORMAT == 3)
+ (void) printf(" %d",FORMAT3_4(VALUE_1,3));
+ else PC_0 += INSTR[INSTR_CODE(PC_0)].FORMAT;
+ (void) printf("\n");
+ } else
+ CALL_FUNCTION1(INSTR[INSTR_CODE(PC_0)].FUNCTION,PRINT_EFFECT);
+ if (PC_0 == RETURN_TO_OS_1) RETURN_STATUS = HALT_1;
+ else
+ if (INTERVAL_TIMER > 0) {
+ INTERVAL_TIMER --;
+ if (INTERVAL_TIMER == 0)
+ SIGNAL_INTERUPT(3,0);
+ }
+
+ } while ( !DEBUG_MODE && (RETURN_STATUS == EXECUTING_1 ));
+
+ }
Index: llvm-test/MultiSource/Benchmarks/Prolangs-C/simulator/machine.h
diff -c /dev/null llvm-test/MultiSource/Benchmarks/Prolangs-C/simulator/machine.h:1.1
*** /dev/null Tue Oct 5 16:08:51 2004
--- llvm-test/MultiSource/Benchmarks/Prolangs-C/simulator/machine.h Tue Oct 5 16:08:40 2004
***************
*** 0 ****
--- 1,134 ----
+ /* %%%%%%%%%%%%%%%%%%%% (c) William Landi 1991 %%%%%%%%%%%%%%%%%%%%%%%%%%%% */
+ /* Permission to use this code is granted as long as the copyright */
+ /* notice remains in place. */
+ /* ============================= machine.h ================================= */
+ /* Maintains all the information associated with the machine. Can be used to */
+ /* drive complete simulation of a program or just execute one instruction. */
+ #include <stdio.h>
+ #include "sim_debug.h"
+
+
+ /* ---------------------------------- Globals ------------------------------ */
+ /* MEMORY The Main Memory. */
+ extern MEM_SPACE MEMORY;
+
+ /* INTERVAL_TIMER Used for timing out a process and */
+ extern int INTERVAL_TIMER; /* Returning control to the OS */
+
+ /* ---------------------------- The Registers ----------------------------- */
+ extern int REGISTER[NUM_REGISTERS];
+ #define A_0 REGISTER[0] /* 0 A Accumulator */
+ #define X_0 REGISTER[1] /* 1 X Index Register */
+ #define L_0 REGISTER[2] /* 2 L Linkage Register */
+ #define B_0 REGISTER[3] /* 3 B Base Register */
+ #define S_0 REGISTER[4] /* 4 S General Register */
+ #define T_0 REGISTER[5] /* 5 T General Register */
+ #define F_0 REGISTER[6] /* 6 F Floating Point - NOT*/
+ /* IMPLEMENTED */
+ /* 7 NO REGISTER */
+ #define PC_0 REGISTER[8] /* 8 PC Program Counter */
+ #define SW_0 REGISTER[9] /* 9 SW Status Word */
+
+
+ /* ------------------------------ The Devices ------------------------------ */
+ #define NOT_IN_USE_1 0
+ #define IN_USE_1 1
+ /* The devices: */
+ /* 0 Keyboard (Input) */
+ /* 80 Terminal (Output) */
+ /* i (00 <= i <= FF) File named DEVi */
+ /* I (00 <= I < 80) Input Devices. I (80 <= I <= FF) Output Devices. */
+ extern struct DEVICE_ENTRY {
+ int STATUS;
+ FILE *STREAM;
+ } DEVICE[256];
+
+ /*---------------------------------- Procedures ---------------------------- */
+
+ /* --------------------------- RESET_DEVICES ------------------------------- */
+ /* 0 parameters: */
+ /* Reset all the devices. This is needed so that if you run program twice */
+ /* in one debugging section, you can be sure the devices will be okay. */
+ extern void RESET_DEVICES();
+
+ /* --------------------------- PRINT_REG_NAME ------------------------------ */
+ /* 3 parameters: */
+ /* 1) char *STR1; */
+ /* 2) int REG_NUM; The number of the register. */
+ /* 3) char *STR2; */
+ /* Prints out STR1, followed by the name of a register, followed by STR2. */
+ extern void PRINT_REG_NAME();
+
+ /* ----------------------------- BYTES_TO_BITS ----------------------------- */
+ /* 3 parameters: */
+ /* 1) int VAL; VALue to convert to bits. */
+ /* 2) int NUM_BYTES; How many BYTES to convert. */
+ /* 3) int *BINARY; Where to put the bits. */
+ /* Convert BYTES bytes store in VAL (the variable VAL) and set BINARY to be */
+ /* the corresponding binary array of BITS. */
+ extern void BYTES_TO_BITS();
+
+ /* -------------------------- BITS_TO_BYTE --------------------------------- */
+ /* 2 parameters: */
+ /* 1) int *BINARY; array of bits to convert. */
+ /* 2) int BITS; number of BITS in the array. */
+ /* Convert an array of BITS bits to an integer (BYTE) and return result. */
+ extern int BITS_TO_BYTE();
+
+ /* --------------------------- SET_CC -------------------------------------- */
+ /* 1 parameter: */
+ /* 1) int CODE; Set the CC to CODE. */
+ /* SET the CC (Condition Code) to CODE */
+ extern void SET_CC();
+
+ /* ---------------------------------- CC ----------------------------------- */
+ /* 0 parameters: */
+ /* Return the value stored in the condition code. */
+ extern int CC();
+
+ /* ---------------------------- SUPERVISOR_MODE ---------------------------- */
+ /* 0 parameters: */
+ /* Return TRUE iff in SUPERVISOR MODE. */
+ extern BOOLEAN SUPERVISOR_MODE();
+
+ /* --------------------------- OPEN_DEVICE --------------------------------- */
+ /* 1 parameter: */
+ /* 1) int DEV; */
+ /* Mark device DEV as IN USE and, if needed, open it. */
+ extern void OPEN_DEVICE();
+
+ /* ---------------------------- PRINT_ADDRESS ------------------------------ */
+ /* 3 parameters: */
+ /* 1) char *STR1; */
+ /* 2) int ADDRESS; ADDRESS to output. */
+ /* 3) char *STR2; */
+ /* Output PREFIX, followed by the ADDRESS, followed by SUFFIX. Print the */
+ /* Address in hexidecimal, decimal or by a LABEL name. */
+ extern void PRINT_ADDRESS();
+
+ /* ---------------------------- PRINT_CONSTANT ----------------------------- */
+ /* 3 parameters: */
+ /* 1) char *STR1; */
+ /* 2) int CONST; */
+ /* 3) char *STR2; */
+ /* Output PREFIX, followed by the CONSTANT in a base depending on */
+ /* TYPE_OUT_MODE, followed by SUFFIX */
+ extern void PRINT_CONSTANT();
+
+ /* ------------------------- PRINT_INSTRUCTION ----------------------------- */
+ /* 3 parameters: */
+ /* 1) int LOCATION; Where the word in located in memory. */
+ /* 2) BOOLEAN PRINT; Do you really want to print out */
+ /* instruction or just want BYTES? */
+ /* 3) int *BYTES; Number of bytes this instruction has */
+ /* Output a number as a SIC/XE instruction. */
+ extern void PRINT_INSTRUCTION();
+
+ /* ---------------------------------- EXEC --------------------------------- */
+ /* 2 parameters: */
+ /* 1) BOOLEAN DEBUG_MODE; TRUE, debugging/simulating; FALSE simulating */
+ /* 2) BOOLEAN PRINT_EFFECT; Print the effect of the commands (TRUE/FALSE)*/
+ /* if DEBUG_MODE is FALSE, drives the whole simulation process, otherwise */
+ /* Just does one instruction and returns. */
+ extern void EXEC();
+
Index: llvm-test/MultiSource/Benchmarks/Prolangs-C/simulator/memory.c
diff -c /dev/null llvm-test/MultiSource/Benchmarks/Prolangs-C/simulator/memory.c:1.1
*** /dev/null Tue Oct 5 16:08:51 2004
--- llvm-test/MultiSource/Benchmarks/Prolangs-C/simulator/memory.c Tue Oct 5 16:08:40 2004
***************
*** 0 ****
--- 1,351 ----
+ /* %%%%%%%%%%%%%%%%%%%% (c) William Landi 1991 %%%%%%%%%%%%%%%%%%%%%%%%%%%% */
+ /* Permission to use this code is granted as long as the copyright */
+ /* notice remains in place. */
+ /* =============================== memory.c ================================ */
+ /* Contains all the routines that manage the main memory of the SIC/XE */
+ /* machine. */
+
+ #include "boolean.h"
+ #include <malloc.h>
+ #include <stdio.h>
+ #include <string.h>
+ #include "constants.h"
+ #include "convert.h"
+ #include "load.h"
+
+ /* MEM_SPACE The type of a main memory in this program.*/
+ typedef char *MEM_SPACE;
+
+ /* ========================== Printing memory constants ==================== */
+ /* BYTES_PER_GROUP How many bytes to print out at a time. */
+ #define BYTES_PER_GROUP 4
+ /* GROUPS_PER_LINE How many groups of bytes to put on one */
+ /* line*/
+ #define GROUPS_PER_LINE 4
+ /* LINES_OF_GAP_TO_ELIPSE How many consequative lines of unchanged */
+ /* bytes must present to elipse out the */
+ /* lines from the output. */
+ #define LINES_OF_GAP_TO_ELIPSE 3
+
+ /* ========== Keeping Track of which locations have been modified ========== */
+ /* Keep a linked list of blocks of memory that have been modified. ONLY */
+ /* locations that where actually loaded into are included in any block and */
+ /* locations that where loaded are in some block. */
+
+ /* BUFFER_ELEMENT Type of one block. START of block and it's */
+ /* length. Plus a pointer because a linked */
+ /* list. */
+ struct BUFFER_ELEMENT {
+ int START; /* Start of the block. */
+ int LENGTH; /* Length of the block. */
+ struct BUFFER_ELEMENT *NEXT; /* Next block in the linked list. */
+ };
+
+ /* BUFFER A record with the first and last element of */
+ /* a lined list. */
+ /* LOCATIONS_USED A BUFFER that contains the modifed locations*/
+ struct BUFFER {
+ struct BUFFER_ELEMENT *HEAD;/* First block of the linked list. */
+ struct BUFFER_ELEMENT *END; /* Last block of the linked list. */
+ } LOCATIONS_USED = {NULL,NULL};
+
+ /* ---------------------------- ADD_TO_BUFFER (local) ---------------------- */
+ /* Adds a block to the END of the linked list of blocks. */
+ void ADD_TO_BUFFER(int LOCATION,int LEN)
+ {
+ if (LOCATIONS_USED.HEAD == NULL) {
+ /* ------------ Add to an empty list. */
+ LOCATIONS_USED.HEAD = (struct BUFFER_ELEMENT *) malloc(sizeof(struct BUFFER_ELEMENT));
+ LOCATIONS_USED.END = LOCATIONS_USED.HEAD;
+ } else {
+ /* ------------ Add to a non-empty list. */
+ (*LOCATIONS_USED.END).NEXT =
+ (struct BUFFER_ELEMENT *) malloc(sizeof(struct BUFFER_ELEMENT));
+ LOCATIONS_USED.END = (*LOCATIONS_USED.END).NEXT;
+ }
+ (*LOCATIONS_USED.END).START = LOCATION;
+ (*LOCATIONS_USED.END).LENGTH = LEN;
+ (*LOCATIONS_USED.END).NEXT = NULL;
+ }
+
+ /* ============================= Memory Routines =========================== */
+
+ /* --------------------------------- INT ---------------------------------- */
+ /* Return the integer representation for a character. Had to be written */
+ /* Because the character 255 (for example) who be treated as the integer -1, */
+ /* but I needed it to be 255. */
+ int INT(char CH)
+ {
+ int I;
+ I = CH;
+
+ if (I<0) return (256+I);
+ return (I);
+ }
+
+ /* ----------------------------- Create Memory ----------------------------- */
+ /* Create a megabyte of memory and point MEMORY to it. It does not initialize*/
+ /* the memory as this took about 5 minuites. Since the memory was */
+ /* uninitized I needed another way to know when locations where modified, */
+ /* thus the above lined list of blocks. */
+ void CREATE_MEMORY(MEM_SPACE *MEMORY)
+ {
+ if ((*MEMORY) != NULL)
+ (void) printf("CREATE_MEMORY called illegally.\n");
+ else (*MEMORY) = malloc((unsigned int) MEM_SIZE_1);
+ }
+
+ /* -------------------------- DO_STORE (local) ----------------------------- */
+ /* Place BYTES consequative bytes into MEMORY, starting at ADDRESS. */
+ void DO_STORE(char *VALUE,int BYTES,int ADDRESS,MEM_SPACE MEMORY,
+ BOOLEAN *ERROR,BOOLEAN BUFFER_Q)
+ {
+ BOOLEAN LOCAL_ERROR = FALSE_1; /* Was an error detected during the store. */
+ int TEMP; /* A loop counter variable. */
+ int INT_VAL; /* Integer representation of one byte of the */
+ /* block. */
+
+ /* ---------------------- Check if fits into memory */
+ if ( (ADDRESS + BYTES <= MEM_SIZE_1) && (ADDRESS + BYTES >= 0) ) {
+
+ /* ---------------------- Remember loaded into this block (if necessary) */
+ if (BUFFER_Q) ADD_TO_BUFFER(ADDRESS,BYTES);
+
+ /* ---------------------- Load each byte into memory */
+ for (TEMP = 0; ((TEMP < BYTES) && !eoln(VALUE[TEMP]) && !LOCAL_ERROR);
+ TEMP++) {
+ STR_TO_NUM(&(VALUE[TEMP*HEX_CHAR_PER_BYTE_1]),HEX_CHAR_PER_BYTE_1,
+ 16,&INT_VAL,&LOCAL_ERROR);
+ MEMORY[ADDRESS+TEMP] = (char) INT_VAL;
+ }
+
+ if (LOCAL_ERROR) {
+ (void) printf("ERROR: Illegal store VALUE = %s.\n", VALUE);
+ (*ERROR) = TRUE_1;
+ }
+ } else {
+ (void) printf("ERROR: Illegal store[1] ADDRESS = %d, BYTES = %d.\n",
+ ADDRESS,BYTES);
+ (*ERROR) = TRUE_1;
+ }
+ }
+
+ /* ------------------------------ STORE_AT --------------------------------- */
+ /* Place BYTES consequative bytes into MEMORY, starting at ADDRESS. */
+ void STORE_AT(char *VALUE,int BYTES,int ADDRESS,MEM_SPACE MEMORY,
+ BOOLEAN *ERROR)
+ {
+ /* vvvvvv Remember loaded this block*/
+ DO_STORE(VALUE,BYTES,ADDRESS,MEMORY,ERROR,TRUE_1);
+ }
+
+ /* ---------------------------- ADD_INT_TO_LOC ----------------------------- */
+ /* Add the integer NUM to what is store at LOCATION in MEMORY. */
+ void ADD_INT_TO_LOC(int NUM,int LOCATION,int HALF_BYTES,MEM_SPACE MEMORY,
+ BOOLEAN *ERROR)
+ {
+ int INT_MEM_VAL = 0; /* Integer stored at the relavant location. */
+ char CHAR_MEM_VAL[BITS_PER_WORD_1/BITS_PER_HALFBYTE_1+2];
+ /* CHAR_MEM_VAL is the string representation of */
+ /* the number stored at a location of size */
+ /* HALF_BYTES. */
+
+ if ( ((int) HALF_BYTES/2)*2 != HALF_BYTES)
+ HALF_BYTES ++; /* If odd number of half_bytes include an extra */
+ /* one so that have an even number always. */
+
+ /* ----------------- Check if store is legal (fits in memory) */
+ if ( (LOCATION + HALF_BYTES/HEX_CHAR_PER_BYTE_1 <= MEM_SIZE_1)
+ && (LOCATION + HALF_BYTES/HEX_CHAR_PER_BYTE_1 >= 0)) {
+ int I;
+
+ /* ------ Get what is stored there */
+ for (I = 0; I < HALF_BYTES/HEX_CHAR_PER_BYTE_1; I ++)
+ INT_MEM_VAL = INT_MEM_VAL*256 + INT(MEMORY[LOCATION+I]);
+
+ /* ------ Add the NUMber to what was there */
+ INT_MEM_VAL += NUM;
+
+ /* ------ Put the result back */
+ NUM_TO_STR(INT_MEM_VAL,16,HALF_BYTES,CHAR_MEM_VAL);
+ DO_STORE(CHAR_MEM_VAL,HALF_BYTES/HEX_CHAR_PER_BYTE_1, LOCATION,
+ MEMORY, ERROR,FALSE_1);
+ } else {
+ (void) printf("ERROR: Illegal store[2] ADDRESS = %d, BYTES = %d.\n",
+ LOCATION,HALF_BYTES/HEX_CHAR_PER_BYTE_1);
+ (*ERROR) = TRUE_1;
+ }
+ }
+
+ /* ============================ Outputting routines ======================== */
+
+ /* ------------------------ START_OF_LINE_ADDR (local) --------------------- */
+ /* Returns smallest address that is output on the same line as ADDRESS. */
+ int START_OF_LINE_ADDR(int ADDRESS)
+ {
+ return ( ((int) ADDRESS / (BYTES_PER_GROUP * GROUPS_PER_LINE)) *
+ BYTES_PER_GROUP * GROUPS_PER_LINE);
+ }
+
+ /* ------------------------- END_OF_LINE_ADDR (local) ---------------------- */
+ /* Returns largest address that is output on the same line as ADDRESS. */
+ int END_OF_LINE_ADDR(int ADDRESS)
+ {
+ return (START_OF_LINE_ADDR(ADDRESS) + BYTES_PER_GROUP * GROUPS_PER_LINE - 1);
+ }
+
+ /* --------------------------- LINES_OF_GAP (local) ------------------------ */
+ /* Number of lines (of output) of bytes that seperate the two blocks. */
+ int LINES_OF_GAP(struct BUFFER_ELEMENT *REC1,struct BUFFER_ELEMENT *REC2)
+ {
+ int REC1_END; /* Smallest address displayed on an output */
+ /* line that contains last byte of REC1. */
+ int REC2_START; /* Smallest address displayed on an output */
+ /* line that contains first byte of REC2. */
+
+ if (REC1 == NULL) REC1_END = 0;
+ else REC1_END = START_OF_LINE_ADDR( (*REC1).START + (*REC1).LENGTH - 1);
+
+ if (REC2 == NULL) REC2_START = START_OF_LINE_ADDR(MEM_SIZE_1 - 1);
+ else REC2_START = START_OF_LINE_ADDR( (*REC2).START);
+
+ return ( (REC2_START - REC1_END) / (BYTES_PER_GROUP * GROUPS_PER_LINE) );
+ }
+
+ /* -------------------------- PRINT_ELIPSE (local) ------------------------- */
+ /* Elipse out portion of the output, if the gap between this block of memory */
+ /* and previous block is large enough. */
+ void PRINT_ELIPSE(struct BUFFER_ELEMENT *PREV,struct BUFFER_ELEMENT *CURR,
+ int PREV_ADDR,FILE *OUTPUT)
+ {
+ int LOOP_COUNTER;
+ /* ---------- STR_ADDR String rep of addr. */
+ char STR_ADDR[MEM_ADDR_SIZE_1/BITS_PER_HALFBYTE_1 + 1];
+
+
+ /* -------------- Check if gap is large enough */
+ if ( LINES_OF_GAP(PREV,CURR) >= LINES_OF_GAP_TO_ELIPSE ) {
+
+ NUM_TO_STR(PREV_ADDR,16,MEM_ADDR_SIZE_1/BITS_PER_HALFBYTE_1, STR_ADDR);
+ (void) fprintf(OUTPUT,
+ " %s xxxxxxxx xxxxxxxx xxxxxxxx xxxxxxxx\n",
+ STR_ADDR);
+
+ for (LOOP_COUNTER = 1;LOOP_COUNTER <= 3; LOOP_COUNTER++)
+ (void) fprintf(OUTPUT,
+ " . . . . .\n");
+
+ if (CURR != NULL)
+ NUM_TO_STR(START_OF_LINE_ADDR( (*CURR).START)-
+ BYTES_PER_GROUP*GROUPS_PER_LINE,
+ 16,MEM_ADDR_SIZE_1/BITS_PER_HALFBYTE_1, STR_ADDR);
+ else
+ NUM_TO_STR(START_OF_LINE_ADDR( MEM_SIZE_1) -
+ BYTES_PER_GROUP*GROUPS_PER_LINE,
+ 16,MEM_ADDR_SIZE_1/BITS_PER_HALFBYTE_1, STR_ADDR);
+
+ (void) fprintf(OUTPUT,
+ " %s xxxxxxxx xxxxxxxx xxxxxxxx xxxxxxxx\n",
+ STR_ADDR);
+ }
+ }
+
+ /* ----------------------------- PRINT_MEM --------------------------------- */
+ /* Output the loaded areas of memory in a nice user readable way. */
+ void PRINT_MEM(MEM_SPACE MEMORY,FILE *OUTPUT)
+ {
+ struct BUFFER_ELEMENT *STEP; /* Current block of memory outputing. */
+ struct BUFFER_ELEMENT *PREVIOUS = NULL; /* Last block output */
+ int PREVIOUS_ADDR = 0; /* Start address of the last output block */
+ int ADDRESS; /* Next address of memory to output. */
+ char STR_ADDR[MEM_ADDR_SIZE_1/BITS_PER_HALFBYTE_1 + 1];/* String version of*/
+ /* address */
+
+ (void) fprintf(OUTPUT,"MEMORY\n");
+ (void) fprintf(OUTPUT,"ADDRESS Contents\n");
+ (void) fprintf(OUTPUT,"------- --------------------------------------\n");
+ /* 12345 12345678 12345678 12345678 12345678 */
+ /* 123456789012345678901234567890123456789012345678 */
+
+ if (LOCATIONS_USED.HEAD == NULL)
+ (void) fprintf(OUTPUT,
+ "=========> NOTHING LOADED INTO MEMORY <=========\n");
+ else {
+
+ /* --------------- STEP through the list of loaded blocks */
+ for (STEP = LOCATIONS_USED.HEAD; STEP != NULL; STEP = (*STEP).NEXT) {
+
+ PRINT_ELIPSE(PREVIOUS,STEP,PREVIOUS_ADDR,OUTPUT);
+ ADDRESS = START_OF_LINE_ADDR((*STEP).START);
+
+ /* ------ repeat until consequtive blocks are output on seperate lines. */
+ do {
+ BOOLEAN REST_EMPTY = FALSE_1;
+ int I,J;
+ char STR_BYTE[HEX_CHAR_PER_BYTE_1 + 1];
+
+ NUM_TO_STR(ADDRESS,16,MEM_ADDR_SIZE_1/BITS_PER_HALFBYTE_1,STR_ADDR);
+ (void) fprintf(OUTPUT," %s ",STR_ADDR);
+
+ /* --------- OUTPUT 1 line */
+ for (I=0;I<GROUPS_PER_LINE;I++) {
+ for (J=0;J<BYTES_PER_GROUP;J++) {
+ int LOC;
+
+ LOC = ADDRESS+I*BYTES_PER_GROUP+J;
+ if (!REST_EMPTY && (LOC >= ((*STEP).START + (*STEP).LENGTH)))
+ {
+ if ( ((*STEP).NEXT == NULL) ||
+ (LINES_OF_GAP(STEP,(*STEP).NEXT) > 0)) REST_EMPTY = TRUE_1;
+ else STEP = (*STEP).NEXT;
+ }
+
+ if ( REST_EMPTY || (LOC < (*STEP).START))
+ (void) fprintf(OUTPUT,"xx");
+ else {
+ NUM_TO_STR(INT(MEMORY[LOC]),16,HEX_CHAR_PER_BYTE_1,STR_BYTE);
+ (void) fprintf(OUTPUT,"%s",STR_BYTE);
+ }
+ }
+ (void) fprintf(OUTPUT," ");
+ }
+ (void) fprintf(OUTPUT,"\n");
+
+ ADDRESS = END_OF_LINE_ADDR(ADDRESS) + 1;
+ } while (ADDRESS <=
+ END_OF_LINE_ADDR( (*STEP).START + (*STEP).LENGTH - 1) );
+ PREVIOUS_ADDR = ADDRESS;
+ PREVIOUS = STEP;
+ }
+ PRINT_ELIPSE(PREVIOUS,STEP,PREVIOUS_ADDR,OUTPUT);
+ }
+ }
+
+ /* ---------------------------- OUTPUT_MEM --------------------------------- */
+ /* Prints out the loaded areas of memory in a machine friendly format. Very */
+ /* to the text records of the object stream except relocated and modified. */
+ void OUTPUT_MEM(MEM_SPACE MEMORY,FILE *OUTPUT)
+ {
+ struct BUFFER_ELEMENT *CURRENT; /* Current block outputing */
+ int COUNT; /* Simple loop counter */
+ char ADDRESS[MEM_ADDR_SIZE_1/BITS_PER_HALFBYTE_1 + 2];/* String version of */
+ /* address */
+ char STR_BYTE[HEX_CHAR_PER_BYTE_1 + 1]; /* String version of byte */
+
+ CURRENT = LOCATIONS_USED.HEAD;
+ while (CURRENT != NULL) {
+ NUM_TO_STR((*CURRENT).START,16,MEM_ADDR_SIZE_1/BITS_PER_HALFBYTE_1+1,
+ ADDRESS);
+ NUM_TO_STR((*CURRENT).LENGTH,16,HEX_CHAR_PER_BYTE_1,STR_BYTE);
+ (void) fprintf(OUTPUT,"T%s%s",ADDRESS,STR_BYTE);
+
+ for (COUNT = (*CURRENT).START;
+ COUNT < ((*CURRENT).START + (*CURRENT).LENGTH);
+ COUNT ++) {
+ NUM_TO_STR(INT(MEMORY[COUNT]),16,HEX_CHAR_PER_BYTE_1,STR_BYTE);
+ (void) fprintf(OUTPUT,"%s",STR_BYTE);
+ }
+ (void) fprintf(OUTPUT,"\n");
+ CURRENT = (*CURRENT).NEXT;
+ }
+ }
Index: llvm-test/MultiSource/Benchmarks/Prolangs-C/simulator/memory.h
diff -c /dev/null llvm-test/MultiSource/Benchmarks/Prolangs-C/simulator/memory.h:1.1
*** /dev/null Tue Oct 5 16:08:51 2004
--- llvm-test/MultiSource/Benchmarks/Prolangs-C/simulator/memory.h Tue Oct 5 16:08:40 2004
***************
*** 0 ****
--- 1,62 ----
+ /* %%%%%%%%%%%%%%%%%%%% (c) William Landi 1991 %%%%%%%%%%%%%%%%%%%%%%%%%%%% */
+ /* Permission to use this code is granted as long as the copyright */
+ /* notice remains in place. */
+ /* ============================== memory.h ================================= */
+ /* Contains all the routines that manage the main memory of the SIC/XE */
+ /* machine. */
+
+ /* MEM_SPACE The type of a main memory in this program. */
+ typedef char *MEM_SPACE;
+
+ /* --------------------------------- INT ---------------------------------- */
+ /* 1 parameter: */
+ /* 1) char CH; Character to convert. */
+ /* Return the integer representation for a character. Had to be written */
+ /* Because the character 255 (for example) who be treated as the integer -1, */
+ /* but I needed it to be 255. */
+ extern int INT();
+
+ /* ----------------------------- Create Memory ----------------------------- */
+ /* 1 parameter: */
+ /* 1) MEM_SPACE *MEMORY; name of the main memory to create. */
+ /* Create a megabyte of memory and point MEMORY to it. It does not initialize*/
+ /* the memory as this took about 5 minuites. Since the memory was */
+ /* uninitized I needed another way to know when locations where modified, */
+ /* thus the above lined list of blocks. */
+ extern void CREATE_MEMORY();
+
+ /* ------------------------------ STORE_AT --------------------------------- */
+ /* 5 parameters: */
+ /* 1) char *VALUE; Character representation (2 chars/byte) of */
+ /* what the block of memory should contain. */
+ /* 2) int BYTES; bytes in the block to load into memory. */
+ /* 3) int ADDRESS; Where the block begins in memory. */
+ /* 4) MEM_SPACE MEMORY; The main memory. */
+ /* 5) BOOLEAN *ERROR; Was an error detected during the store. */
+ /* Place BYTES consequative bytes into MEMORY, starting at ADDRESS. */
+ extern void STORE_AT();
+
+ /* ---------------------------- ADD_INT_TO_LOC ----------------------------- */
+ /* 5 parameters: */
+ /* 1) int NUM; NUMber to add to the value already in memory*/
+ /* 2) int LOCATION; Address of the integer in memory */
+ /* 3) int HALF_BYTES; How many HALF_BYTES does the number occupy */
+ /* 4) MEM_SPACE MEMORY; The memory. */
+ /* 5) BOOLEAN *ERROR; Has an error been detected. */
+ /* Add the integer NUM to what is store at LOCATION in MEMORY. */
+ extern void ADD_INT_TO_LOC();
+
+ /* ----------------------------- PRINT_MEM --------------------------------- */
+ /* 2 parameters: */
+ /* 1) MEM_SPACE MEMORY; Memory to output. */
+ /* 2) FILE *OUTPUT; Output stream. */
+ /* Output the loaded areas of memory in a nice user readable way. */
+ extern void PRINT_MEM();
+
+ /* ---------------------------- OUTPUT_MEM --------------------------------- */
+ /* 2 parameters: */
+ /* 1) MEM_SPACE MEMORY; Memory to output. */
+ /* 2) FILE *OUTPUT; Output stream. */
+ /* Prints out the loaded areas of memory in a machine friendly format. Very */
+ /* to the text records of the object stream except relocated and modified. */
+ extern void OUTPUT_MEM();
Index: llvm-test/MultiSource/Benchmarks/Prolangs-C/simulator/print.c
diff -c /dev/null llvm-test/MultiSource/Benchmarks/Prolangs-C/simulator/print.c:1.1
*** /dev/null Tue Oct 5 16:08:51 2004
--- llvm-test/MultiSource/Benchmarks/Prolangs-C/simulator/print.c Tue Oct 5 16:08:40 2004
***************
*** 0 ****
--- 1,96 ----
+ /* %%%%%%%%%%%%%%%%%%%% (c) William Landi 1991 %%%%%%%%%%%%%%%%%%%%%%%%%%%% */
+ /* Permission to use this code is granted as long as the copyright */
+ /* notice remains in place. */
+ /* ============================== print.c ================================== */
+ /* Contains routines for output the symbol table and executable files. */
+ #include <string.h>
+ #include <stdio.h>
+ #include "boolean.h"
+ #include "constants.h"
+ #include "sym_tab.h"
+ #include "convert.h"
+ #include "memory.h"
+ #include "load.h"
+
+ /* ============================== Symbol Table ============================= */
+ /* -------------------------- PRINT_TABLE (local) -------------------------- */
+ /* Outputs the Symbol Table. Recursive */
+ void PRINT_TABLE(SYMBOL_TABLE SYM_TAB,FILE *OUTPUT)
+ {
+ char TEMP[(int) MEM_ADDR_SIZE_1/BITS_PER_HALFBYTE_1 + 1];
+
+ /* ------------------- Print out the linked list backwards */
+ if (SYM_TAB != NULL) {
+
+ PRINT_TABLE((*SYM_TAB).NEXT,OUTPUT);
+
+ if ((*SYM_TAB).TYPE == MODULE)
+ (void) fprintf(OUTPUT, "%s ",(*SYM_TAB).LABEL);
+ else (void) fprintf(OUTPUT," %s ",(*SYM_TAB).LABEL);
+
+ NUM_TO_STR((*SYM_TAB).LOCATION, 16,
+ (int) MEM_ADDR_SIZE_1/BITS_PER_HALFBYTE_1,TEMP);
+
+ if ((*SYM_TAB).TYPE == UNDEFINED)
+ (void) fprintf(OUTPUT,"Undefined ");
+ else (void) fprintf(OUTPUT,"%s ",TEMP);
+
+ if ((*SYM_TAB).TYPE == MODULE) {
+ NUM_TO_STR((*SYM_TAB).LENGTH, 16,
+ (int)MEM_ADDR_SIZE_1/BITS_PER_HALFBYTE_1+1,TEMP);
+ (void) fprintf(OUTPUT,"%s\n",TEMP);
+ } else (void) fprintf(OUTPUT,"\n");
+ }
+ }
+
+ /* --------------------------------- PRT_SYM_TAB --------------------------- */
+ /* Prints header for the symbol table file and lets PRINT_TABLE print it. */
+ void PRT_SYM_TAB(SYMBOL_TABLE SYM_TAB,FILE *OUTPUT)
+ {
+ (void) fprintf(OUTPUT,"CONTROL SYMBOL\n");
+ (void) fprintf(OUTPUT,"SECTION NAME ADDRESS LENGTH\n");
+ (void) fprintf(OUTPUT,"-----------------------------------\n");
+ PRINT_TABLE(SYM_TAB,OUTPUT);
+ }
+ /* ============================= Executable ================================ */
+ /* ----------------------------- OUTPUT_TABLE ------------------------------ */
+ /* Prints out the symbol table into the executable file. Again is recursive */
+ void OUTPUT_TABLE(SYMBOL_TABLE SYM_TAB,FILE *OUTPUT)
+ {
+ char TEMP[(int) MEM_ADDR_SIZE_1/BITS_PER_HALFBYTE_1 + 2];
+
+ /* ---------------- Prints linked list out backwards */
+ if (SYM_TAB != NULL) {
+ OUTPUT_TABLE((*SYM_TAB).NEXT,OUTPUT);
+
+ if ((*SYM_TAB).TYPE == MODULE)
+ (void) fprintf(OUTPUT,"M%s",(*SYM_TAB).LABEL);
+ else if (!strcmp((*SYM_TAB).MODULE,GLOBAL_1))
+ (void) fprintf(OUTPUT,"G%s",(*SYM_TAB).LABEL);
+ else (void) fprintf(OUTPUT,"L%s%s",(*SYM_TAB).MODULE,(*SYM_TAB).LABEL);
+
+ NUM_TO_STR((*SYM_TAB).LOCATION, 16,
+ (int) MEM_ADDR_SIZE_1/BITS_PER_HALFBYTE_1+1,TEMP);
+ (void) fprintf(OUTPUT,"%s",TEMP);
+
+ if ((*SYM_TAB).TYPE == MODULE) {
+ NUM_TO_STR((*SYM_TAB).LENGTH, 16,
+ (int) MEM_ADDR_SIZE_1/BITS_PER_HALFBYTE_1+1, TEMP);
+ (void) fprintf(OUTPUT,"%s",TEMP);
+ }
+ (void) fprintf(OUTPUT,"\n");
+ }
+ }
+
+ /* ------------------------------ PRINT_EXEC ------------------------------- */
+ /* Drives the outputing of the executable file */
+ void PRINT_EXEC(MEM_SPACE MEMORY,SYMBOL_TABLE SYM_TAB,FILE *OUTPUT)
+ {
+ char ADDRESS[MEM_ADDR_SIZE_1/BITS_PER_HALFBYTE_1 + 1];
+
+ NUM_TO_STR(START_ADDRESS,16,MEM_ADDR_SIZE_1/BITS_PER_HALFBYTE_1,ADDRESS);
+ (void) fprintf(OUTPUT,"S%s%s\n",MAIN_ROUTINE,ADDRESS);
+
+ OUTPUT_TABLE(SYM_TAB,OUTPUT);
+ OUTPUT_MEM(MEMORY,OUTPUT);
+ }
Index: llvm-test/MultiSource/Benchmarks/Prolangs-C/simulator/print.h
diff -c /dev/null llvm-test/MultiSource/Benchmarks/Prolangs-C/simulator/print.h:1.1
*** /dev/null Tue Oct 5 16:08:51 2004
--- llvm-test/MultiSource/Benchmarks/Prolangs-C/simulator/print.h Tue Oct 5 16:08:40 2004
***************
*** 0 ****
--- 1,20 ----
+ /* %%%%%%%%%%%%%%%%%%%% (c) William Landi 1991 %%%%%%%%%%%%%%%%%%%%%%%%%%%% */
+ /* Permission to use this code is granted as long as the copyright */
+ /* notice remains in place. */
+ /* ============================== print.h ================================== */
+ /* Contains routines for output the symbol table and executable files. */
+
+ /* --------------------------------- PRT_SYM_TAB --------------------------- */
+ /* 2 parameters: */
+ /* 1) SYMBOL_TABLE SYM_TAB; The symbol table. */
+ /* 2) FILE *OUTPUT; The output steam */
+ /* Prints header for the symbol table file and lets PRINT_TABLE print it. */
+ extern void PRT_SYM_TAB();
+
+ /* ------------------------------ PRINT_EXEC ------------------------------- */
+ /* 3 parameters: */
+ /* 1) MEM_SPACE MEMORY; The memory */
+ /* 2) SYMBOL_TABLE SYM_TAB; The symbol table */
+ /* 3) FILE *OUTPUT; The output stream */
+ /* Drives the outputing of the executable file */
+ extern void PRINT_EXEC();
Index: llvm-test/MultiSource/Benchmarks/Prolangs-C/simulator/sim_debug.c
diff -c /dev/null llvm-test/MultiSource/Benchmarks/Prolangs-C/simulator/sim_debug.c:1.1
*** /dev/null Tue Oct 5 16:08:51 2004
--- llvm-test/MultiSource/Benchmarks/Prolangs-C/simulator/sim_debug.c Tue Oct 5 16:08:40 2004
***************
*** 0 ****
--- 1,71 ----
+ /* %%%%%%%%%%%%%%%%%%%% (c) William Landi 1991 %%%%%%%%%%%%%%%%%%%%%%%%%%%% */
+ /* Permission to use this code is granted as long as the copyright */
+ /* notice remains in place. */
+
+ /* =========================== sim_debug.c ================================= */
+ /* Main (driving) routine of the Simulator/Debugger. */
+
+ /* to compile (the simulator/debugger) use: */
+ /* cc -o run sim_debug.c sym_tab.c stringI.c convert.c memory.c */
+ /* machine.c debugger.c loadexe.c print.c instruct.c format.c */
+ /* interupt.c instruct2.c -g -lm */
+
+ #include <stdio.h>
+ #include "constants.h"
+ #include "boolean.h"
+ #include "memory.h"
+ #include "machine.h"
+ #include "debugger.h"
+ #include "loadexe.h"
+ #include "print.h"
+
+ /* --------------------------------- Globals ------------------------------ */
+ /* MAIN_ROUTINE Name of (program) module declared with */
+ /* a START (main routine). */
+ char MAIN_ROUTINE[LABEL_SIZE_1+1];
+
+ /* -------------------------------- main ---------------------------------- */
+ int main(int argc,char **argv)
+ {
+ FILE *INPUT_STREAM; /* Input file stream */
+ BOOLEAN DEBUG_MODE = TRUE_1; /* Flag that can turn off the debugging */
+ /* feature. */
+ BOOLEAN ERROR = FALSE_1; /* Was there an error loading the */
+ /* executable? */
+
+ if (argc == 1) (void) printf("usage: run [-n] file\n");
+ else {
+ int ARGUMENT = 1; /* Which argument of the command line */
+ /* currently processing. */
+ BOOLEAN FLAG; /* Just a temporary boolean. */
+
+ /* --------------------------------- Process command directives */
+ if (ARGUMENT < argc) FLAG = (argv[ARGUMENT][0] == '-');
+ while ( (ARGUMENT < argc) && FLAG) {
+ if (!strcmp(argv[ARGUMENT],"-n")) DEBUG_MODE = FALSE_1;
+ else
+ (void) printf("Illegal command directive, '%s'. Ignoring.\n",
+ argv[ARGUMENT]);
+
+ if (ARGUMENT < argc) ARGUMENT ++;
+ if (ARGUMENT < argc) FLAG = (argv[ARGUMENT][0] == '-');
+ }
+
+ if (ARGUMENT >= argc)
+ (void) printf("run: requires a file name.\n");
+
+
+ INIT_SYM_TAB(&SYM_TAB); /* Initialize the symbol table */
+ CREATE_MEMORY(&MEMORY); /* Create/initialize the main memory. */
+ if ( (INPUT_STREAM = fopen(argv[ARGUMENT],"r")) == NULL) {
+ (void) printf("%s: No such file or directory\n",argv[ARGUMENT]);
+ } else {
+ /* --------------------------------- Have a valid file: run it */
+ LOAD(DEBUG_MODE,&ERROR,INPUT_STREAM);
+ if (!ERROR) DEBUGGER(DEBUG_MODE);
+ (void) fclose(INPUT_STREAM);
+ }
+
+ }
+ return 0;
+ }
Index: llvm-test/MultiSource/Benchmarks/Prolangs-C/simulator/sim_debug.h
diff -c /dev/null llvm-test/MultiSource/Benchmarks/Prolangs-C/simulator/sim_debug.h:1.1
*** /dev/null Tue Oct 5 16:08:51 2004
--- llvm-test/MultiSource/Benchmarks/Prolangs-C/simulator/sim_debug.h Tue Oct 5 16:08:40 2004
***************
*** 0 ****
--- 1,24 ----
+ /* %%%%%%%%%%%%%%%%%%%% (c) William Landi 1991 %%%%%%%%%%%%%%%%%%%%%%%%%%%% */
+ /* Permission to use this code is granted as long as the copyright */
+ /* notice remains in place. */
+ /* --------------------- Execution Return Status Codes --------------------- */
+ #define EXECUTING_1 0 /* Process still executing */
+ #define HALT_1 1 /* Normal Termination */
+ #define ABNORMAL_1 2 /* Adnormal Termination */
+ #define QUIT_1 3 /* Terminate SIC/XE emulation */
+
+ #define NUM_REGISTERS 10 /* Number of registers in machine + 1 */
+
+ /* Used for FORMAT3_4 (file format.c) to determine if returns a location or */
+ /* value. */
+ #define LOCATION_1 0
+ #define VALUE_1 1
+
+ /* ----------------------- Values stored in CC (condition code) for =,<, & > */
+ #define EQUAL_1 0
+ #define LESS_THAN_1 1
+ #define GREATER_THAN_1 2
+
+ #define RETURN_TO_OS_1 16777215 /* 24 bit 2's complement value of -1 */
+
+
Index: llvm-test/MultiSource/Benchmarks/Prolangs-C/simulator/stringI.c
diff -c /dev/null llvm-test/MultiSource/Benchmarks/Prolangs-C/simulator/stringI.c:1.1
*** /dev/null Tue Oct 5 16:08:51 2004
--- llvm-test/MultiSource/Benchmarks/Prolangs-C/simulator/stringI.c Tue Oct 5 16:08:40 2004
***************
*** 0 ****
--- 1,57 ----
+ /* %%%%%%%%%%%%%%%%%%%% (c) William Landi 1991 %%%%%%%%%%%%%%%%%%%%%%%%%%%% */
+ /* Permission to use this code is granted as long as the copyright */
+ /* notice remains in place. */
+ /* ================================ stringI.c ============================== */
+ /* Reads in one line of input gauranteeing that it will return a pointer to */
+ /* the whole line, no matter how long it is (it uses CALLOC a version of */
+ /* MALLOC). */
+ #include <stdio.h>
+
+ /* CARRAGIAGE_RETURN <cr> is ascii 10 */
+ #define CARRIAGE_RETURN 10
+
+ /* LEX_LEN_INCREMENT For long strings, number of characters to */
+ /* increase the string buffer by on overflow. */
+ #define LEX_LEN_INCR 128
+
+ char CH = ' '; /* Current input Character */
+ char LEXEME[LEX_LEN_INCR+1]; /* Input String */
+
+ char *FRONT,*BACK; /* FRONT and BACK characters of Input String */
+ unsigned LEX_LEN = LEX_LEN_INCR;/* Size of the Input String Buffer */
+
+
+ /* ------------------------------- GETCHR ---------------------------------- */
+ /* gets the next character form input file and expands buffer if needed */
+ void GETCHR(FILE *STREAM)
+ {
+ /* int TEMP; */
+
+ /* --------- get next character */
+ CH = getc(STREAM);
+
+ /* TEMP = (int) (FRONT-BACK); */
+ if ((FRONT-BACK) < ((int)LEX_LEN-3)) {
+ /* --------- update input string appropriately */
+ FRONT ++;
+ *FRONT = CH;
+ *(FRONT+1) = '\0';
+ }
+ }
+
+ /* --------------------------------- GET_LINE ------------------------------ */
+ /* Read in a line from the input stream. */
+ void GET_LINE(char **LINE,FILE *STREAM)
+ {
+ /* -------- Clear input string */
+ LEXEME[0] = '\0';
+ /* -------- reset pointers */
+ BACK = LEXEME;
+ FRONT = BACK - 1;
+
+ GETCHR(STREAM);
+ while ((CH != CARRIAGE_RETURN) && !feof(STREAM))
+ GETCHR(STREAM);
+ *FRONT = '\0';
+ *LINE = LEXEME;
+ }
Index: llvm-test/MultiSource/Benchmarks/Prolangs-C/simulator/stringI.h
diff -c /dev/null llvm-test/MultiSource/Benchmarks/Prolangs-C/simulator/stringI.h:1.1
*** /dev/null Tue Oct 5 16:08:51 2004
--- llvm-test/MultiSource/Benchmarks/Prolangs-C/simulator/stringI.h Tue Oct 5 16:08:40 2004
***************
*** 0 ****
--- 1,15 ----
+ /* %%%%%%%%%%%%%%%%%%%% (c) William Landi 1991 %%%%%%%%%%%%%%%%%%%%%%%%%%%% */
+ /* Permission to use this code is granted as long as the copyright */
+ /* notice remains in place. */
+ /* =============================== stringI.h =============================== */
+ /* Reads in one line of input gauranteeing that it will return a pointer to */
+ /* the whole line, no matter how long it is (it uses CALLOC a version of */
+ /* MALLOC). */
+
+ /* --------------------------------- GET_LINE ------------------------------ */
+ /* 2 parameters: */
+ /* 1) char **LINE; Points to the input line (string) when done*/
+ /* 2) FILE *STREAM; Where to get the line from. */
+ /* Read in a line from the input stream. */
+ extern void GET_LINE();
+
Index: llvm-test/MultiSource/Benchmarks/Prolangs-C/simulator/sym_tab.c
diff -c /dev/null llvm-test/MultiSource/Benchmarks/Prolangs-C/simulator/sym_tab.c:1.1
*** /dev/null Tue Oct 5 16:08:51 2004
--- llvm-test/MultiSource/Benchmarks/Prolangs-C/simulator/sym_tab.c Tue Oct 5 16:08:40 2004
***************
*** 0 ****
--- 1,72 ----
+ /* %%%%%%%%%%%%%%%%%%%% (c) William Landi 1991 %%%%%%%%%%%%%%%%%%%%%%%%%%%% */
+ /* Permission to use this code is granted as long as the copyright */
+ /* notice remains in place. */
+ /* ================================ sym_tab.c ============================== */
+ /* intialize, retrieve from, and store to the symbol table. Currently */
+ /* implemented with a linked list and linear search. */
+ #include "sym_tab.h"
+ #include <string.h>
+ #include <stdio.h>
+ #include <malloc.h>
+
+ /* -------------------------------- INIT_SYM_TAB --------------------------- */
+ /* Initialize the symbol table TABLE. */
+ void INIT_SYM_TAB(TABLE)
+
+ SYMBOL_TABLE *TABLE;
+
+ {
+ *TABLE = NULL;
+ }
+
+ /* ------------------------- LOOK_UP_SYMBOL -------------------------------- */
+ /* find a symbol in the table. Return a pointer to its entry in the table, if*/
+ /* found, otherwise return NULL. */
+ struct SYMBOL_TABLE_ENTRY *LOOK_UP_SYMBOL(MODULE,LABEL,TABLE)
+
+ char MODULE[]; /* Name of module label found it. */
+ char LABEL[]; /* Label to look for. */
+ SYMBOL_TABLE *TABLE; /* Table to look in. */
+
+ {
+ struct SYMBOL_TABLE_ENTRY *TABLE_ENTRY;
+ TABLE_ENTRY = *TABLE;
+ while (TABLE_ENTRY != NULL)
+ {
+ if ( !strcmp((*TABLE_ENTRY).MODULE,MODULE) &&
+ !strcmp((*TABLE_ENTRY).LABEL,LABEL)) return TABLE_ENTRY;
+ TABLE_ENTRY = (*TABLE_ENTRY).NEXT;
+ }
+ return NULL;
+ }
+
+ /* -------------------------- INSERT_IN_SYM_TAB ---------------------------- */
+ /* If <MODULE,LABEL> pair is not in the symbol table, put it there and */
+ /* TRUE (integer 1). Otherwise return FALSE (integer 0). */
+ /* Puts onto front of the linked list. */
+ int INSERT_IN_SYM_TAB(MODULE,LABEL,LOCATION,TYPE,TABLE)
+ SYMBOL_TABLE *TABLE; /* Table to add <MODULE,LABEL> to. */
+ char *LABEL; /* Label to add. */
+ char *MODULE; /* Module that this label was found in. */
+ int LOCATION; /* What the entries LOCATION field */
+ /* should be set to. */
+ enum kind TYPE; /* What the entries TYPE field should be */
+ /* set to. */
+ {
+ struct SYMBOL_TABLE_ENTRY *TABLE_ENTRY;
+
+ TABLE_ENTRY = LOOK_UP_SYMBOL(MODULE,LABEL,TABLE);
+ if (TABLE_ENTRY == NULL)
+ {
+ TABLE_ENTRY = (struct SYMBOL_TABLE_ENTRY *) malloc(sizeof(struct SYMBOL_TABLE_ENTRY));
+ (*TABLE_ENTRY).NEXT = *TABLE;
+ (void) strcpy((*TABLE_ENTRY).MODULE, MODULE);
+ (void) strcpy((*TABLE_ENTRY).LABEL, LABEL);
+ (*TABLE_ENTRY).LOCATION = LOCATION;
+ (*TABLE_ENTRY).LENGTH = 0;
+ (*TABLE_ENTRY).TYPE = TYPE;
+ *TABLE = TABLE_ENTRY;
+ return 1;
+ }
+ else return 0;
+ }
Index: llvm-test/MultiSource/Benchmarks/Prolangs-C/simulator/sym_tab.h
diff -c /dev/null llvm-test/MultiSource/Benchmarks/Prolangs-C/simulator/sym_tab.h:1.1
*** /dev/null Tue Oct 5 16:08:51 2004
--- llvm-test/MultiSource/Benchmarks/Prolangs-C/simulator/sym_tab.h Tue Oct 5 16:08:40 2004
***************
*** 0 ****
--- 1,54 ----
+ /* %%%%%%%%%%%%%%%%%%%% (c) William Landi 1991 %%%%%%%%%%%%%%%%%%%%%%%%%%%% */
+ /* Permission to use this code is granted as long as the copyright */
+ /* notice remains in place. */
+ /* ========================= sym_tab.h ===================================== */
+ #include "constants.h"
+
+ /* kind What kind/type of symbol is it. */
+ enum kind {RELATIVE,ABSOLUTE,EXTERN_REF,MODULE,GLOBAL,UNDEFINED};
+
+ /* SYMBOL_TABLE_ENTRY type of a symbol table entry. Part of a linked list*/
+ typedef struct SYMBOL_TABLE_ENTRY {
+ char LABEL[LABEL_SIZE_1+1]; /* Name of the symbol. */
+ char MODULE[LABEL_SIZE_1+1]; /* [Program] Module the symbol was found */
+ /* int. */
+ int LOCATION; /* Location in SICs memory this label */
+ /* represents. For module names it */
+ /* is the starting address. For */
+ /* constants it is the value. */
+ int LENGTH; /* Only for module names, the length of */
+ /* the module. */
+ enum kind TYPE; /* kind/type of label (relative, ...) */
+ struct SYMBOL_TABLE_ENTRY *NEXT; /* Pointer to next entry in the list */
+ } *SYMBOL_TABLE;
+
+ /* -------------------------------- INIT_SYM_TAB --------------------------- */
+ /* 1 parameter: */
+ /* 1) SYMBOL_TABLE *TABLE; */
+ /* Initialize the symbol table TABLE. */
+ extern void INIT_SYM_TAB();
+
+ /* ------------------------- LOOK_UP_SYMBOL -------------------------------- */
+ /* 3 parameters: */
+ /* 1) char MODULE[]; /* Name of module label found it. */
+ /* 2) char LABEL[]; /* Label to look for. */
+ /* 3) SYMBOL_TABLE *TABLE; /* Table to look in. */
+ /* find a symbol in the table. Return a pointer to its entry in the table, if*/
+ /* found, otherwise return NULL. */
+ extern struct SYMBOL_TABLE_ENTRY *LOOK_UP_SYMBOL();
+
+ /* -------------------------- INSERT_IN_SYM_TAB ---------------------------- */
+ /* 5 parameters: */
+ /* 1) char *LABEL; Label to add. */
+ /* 2) char *MODULE; Module that this label was found in. */
+ /* 3) int LOCATION; What the entries LOCATION field */
+ /* should be set to. */
+ /* 4) enum kind TYPE; What the entries TYPE field should be */
+ /* set to. */
+ /* 5) SYMBOL_TABLE *TABLE; Table to add <MODULE,LABEL> to. */
+ /* If <MODULE,LABEL> pair is not in the symbol table, put it there and */
+ /* TRUE (integer 1). Otherwise return FALSE (integer 0). */
+ /* Puts onto front of the linked list. */
+ extern int INSERT_IN_SYM_TAB();
+
+
More information about the llvm-commits
mailing list