diff --git a/slinky/builtins.c b/slinky/builtins.c index 38b22a5..2fd9e6e 100644 --- a/slinky/builtins.c +++ b/slinky/builtins.c @@ -30,6 +30,11 @@ #include "slinkyTypes.h" #include "slinkyGlobals.h" #include "slinkyExpressions.h" +#include "builtins.h" +#include "errorStuff.h" +#include "expr.h" +#include "link.h" +#include "relocate.h" #include #define getSymbol() ((symbolType *)getNumber()) @@ -409,7 +414,6 @@ symbolLookupBIF(argCount) { symbolType *symbol; stringType *symbolName; - symbolType *lookupGlobalSymbol(); if (argCount < 1) { tooFewArgs(argCount, "symbolLookup"); diff --git a/slinky/builtins.h b/slinky/builtins.h new file mode 100644 index 0000000..703914e --- /dev/null +++ b/slinky/builtins.h @@ -0,0 +1,24 @@ +#ifndef BUILTINS_H_ +#define BUILTINS_H_ + +#include "slinkyTypes.h" + +void tooFewArgs(int argCount, stringType *name); +void tooManyArgs(int argCount, stringType *name); +stringType *atasciiBIF(int argCount); +stringType *atasciiColorBIF(int argCount); +bool isAbsoluteValueBIF(int argCount); +bool isConditionCodeBIF(int argCount); +bool isDefinedBIF(int argCount); +bool isExternalBIF(int argCount); +int nthCharBIF(int argCount); +int printfBIF(int argCount); +stringType *strcatBIF(int argCount); +int strcmpBIF(int argCount); +int strcmplcBIF(int argCount); +int strlenBIF(int argCount); +char *substrBIF(int argCount); +addressType symbolLookupBIF(int argCount); +stringType *symbolNameBIF(int argCount); + +#endif diff --git a/slinky/debugPrint.c b/slinky/debugPrint.c index 87048e9..add444b 100644 --- a/slinky/debugPrint.c +++ b/slinky/debugPrint.c @@ -31,7 +31,7 @@ #include "slinkyTypes.h" #include "slinkyGlobals.h" - +#include "debugPrint.h" static char *modeStrings[2] = { "abs", diff --git a/slinky/debugPrint.h b/slinky/debugPrint.h new file mode 100644 index 0000000..8112886 --- /dev/null +++ b/slinky/debugPrint.h @@ -0,0 +1,14 @@ +#ifndef DEBUG_PRINT_H_ +#define DEBUG_PRINT_H_ + +#include "slinkyTypes.h" + +void printCode(int startAddress, int endAddress, int mode); +void printReference(expressionReferenceType *reference); +void printReferenceFixup(expressionReferenceType *reference); +void printSymbol(int symbolTag, symbolType *symbol); +void printLoadMapSymbol(symbolType *symbol); +void printGlobalSymbols(void); +void printExpression(expressionPCType expression, int length); + +#endif diff --git a/slinky/errorStuff.c b/slinky/errorStuff.c index 4166f81..ede5892 100644 --- a/slinky/errorStuff.c +++ b/slinky/errorStuff.c @@ -29,6 +29,7 @@ #include "slinkyTypes.h" #include "slinkyGlobals.h" +#include "errorStuff.h" #include diff --git a/slinky/errorStuff.h b/slinky/errorStuff.h new file mode 100644 index 0000000..f1ec7c5 --- /dev/null +++ b/slinky/errorStuff.h @@ -0,0 +1,8 @@ +#ifndef ERROR_STUFF_H_ +#define ERROR_STUFF_H_ + +#include "slinkyTypes.h" + +void error(errorType theError, ...); + +#endif diff --git a/slinky/expr.c b/slinky/expr.c index 3eb59c7..6673f4b 100644 --- a/slinky/expr.c +++ b/slinky/expr.c @@ -30,6 +30,9 @@ #include "slinkyTypes.h" #include "slinkyGlobals.h" #include "slinkyExpressions.h" +#include "expr.h" +#include "errorStuff.h" +#include "initialize.h" #include "y.tab.h" #define overSymbol() (pc+=sizeof(symbolType *)) @@ -41,12 +44,6 @@ #define nextByte(byt) (byt = *pc++) #define intOp(byt) (byt+256) -addressType evaluateExpression(); -void skipArray(); -void skipClause(); -void skipString(); -void skipExpression(); - static bool hitFreturn = FALSE; static addressType functionResult; diff --git a/slinky/expr.h b/slinky/expr.h new file mode 100644 index 0000000..4321f9a --- /dev/null +++ b/slinky/expr.h @@ -0,0 +1,57 @@ +#ifndef EXPR_H_ +#define EXPR_H_ + +#include "slinkyTypes.h" + +int getNumber(void); +addressType evaluateArray(void); +addressType evaluateAssert(void); +addressType evaluateBinop(void); +addressType evaluateBlock(void); +addressType evaluateConditionCode(void); +void pushSymbol(symbolType *symbol, addressType value); +void bindFunctionArguments(functionType *theFunction, int argCount); +void undoBindings(void); +addressType evaluateFreturn(void); +addressType evaluateBuiltinFunctionCall(void); +addressType evaluateFunctionCall(void); +addressType evaluateHere(void); +addressType evaluateMdefine(void); +addressType evaluateMdoUntil(void); +addressType evaluateMdoWhile(void); +addressType evaluateMfor(void); +addressType evaluateMif(void); +bool evaluateClause(addressType pattern); +addressType evaluateMswitch(void); +addressType evaluateMwhile(void); +addressType evaluateMvariable(void); +addressType evaluateNumber(void); +addressType evaluateRelocatableNumber(void); +addressType evaluatePerform(void); +addressType evaluatePostop(void); +addressType evaluatePreop(void); +addressType evaluateString(void); +addressType evaluateSymbol(void); +addressType evaluateUnop(void); +addressType evaluateExpression(void); +void skipArray(void); +void skipAssert(void); +void skipBinop(void); +void skipBlock(void); +void skipFunctionCall(void); +void skipMdefine(void); +void skipMdoUntil(void); +void skipMdoWhile(void); +void skipMfor(void); +void skipMif(void); +void skipClause(void); +void skipMswitch(void); +void skipMvariable(void); +void skipMwhile(void); +void skipPostop(void); +void skipPreop(void); +void skipString(void); +void skipUnop(void); +void skipExpression(void); + +#endif diff --git a/slinky/initialize.c b/slinky/initialize.c index 3905f35..c0bfcf5 100644 --- a/slinky/initialize.c +++ b/slinky/initialize.c @@ -29,6 +29,12 @@ #include "slinkyTypes.h" #include "slinkyGlobals.h" +#include "initialize.h" +#include "errorStuff.h" +#include "main.h" + +#include +#include static char *outputFileName; @@ -52,9 +58,6 @@ initializeStuff(argc, argv) int mapFilesFound; char *mapFileName; - void queueInputFile(); - void queueLoadAddress(); - currentFileName = ""; errorFlag = FALSE; packFlag = FALSE; diff --git a/slinky/initialize.h b/slinky/initialize.h new file mode 100644 index 0000000..2d3de4a --- /dev/null +++ b/slinky/initialize.h @@ -0,0 +1,11 @@ +#ifndef INITIALIZE_H_ +#define INITIALIZE_H_ + +#include "slinkyTypes.h" + +void chokePukeAndDie(void); +void initializeStuff(int argc, char **argv); +void queueInputFile(char *name); +void queueLoadAddress(char *addressString); + +#endif diff --git a/slinky/instantiate.c b/slinky/instantiate.c index 65fc4b1..05bc646 100644 --- a/slinky/instantiate.c +++ b/slinky/instantiate.c @@ -31,6 +31,9 @@ #include "slinkyTypes.h" #include "slinkyGlobals.h" #include "slinkyExpressions.h" +#include "errorStuff.h" +#include "expr.h" +#include "instantiate.h" #include "y.tab.h" #define overFunction() (pc+=sizeof(functionType *)) @@ -38,10 +41,6 @@ #define overByte() pc++ #define nextByte(byt) (byt = *pc++) -void putSymbolPointersIntoArray(); -void putSymbolPointersIntoClause(); -void putSymbolPointersIntoExpression(); - void putNumber(number) int number; diff --git a/slinky/instantiate.h b/slinky/instantiate.h new file mode 100644 index 0000000..78571ca --- /dev/null +++ b/slinky/instantiate.h @@ -0,0 +1,29 @@ +#ifndef INSTANTIATE_H_ +#define INSTANTIATE_H_ + +#include "slinkyTypes.h" + +void putNumber(int number); +void instantiateSymbol(void); +void instantiateFunction(void); +void putSymbolPointersIntoArray(void); +void putSymbolPointersIntoAssert(void); +void putSymbolPointersIntoBinop(void); +void putSymbolPointersIntoBlock(void); +void putSymbolPointersIntoBuiltinFunctionCall(void); +void putSymbolPointersIntoFunctionCall(void); +void putSymbolPointersIntoMdefine(void); +void putSymbolPointersIntoMdoUntil(void); +void putSymbolPointersIntoMdoWhile(void); +void putSymbolPointersIntoMfor(void); +void putSymbolPointersIntoMif(void); +void putSymbolPointersIntoClause(void); +void putSymbolPointersIntoMswitch(void); +void putSymbolPointersIntoMvariable(void); +void putSymbolPointersIntoMwhile(void); +void putSymbolPointersIntoPostop(void); +void putSymbolPointersIntoPreop(void); +void putSymbolPointersIntoUnop(void); +void putSymbolPointersIntoExpression(void); + +#endif diff --git a/slinky/link.c b/slinky/link.c index 2900ef6..5059186 100644 --- a/slinky/link.c +++ b/slinky/link.c @@ -29,6 +29,15 @@ #include "slinkyTypes.h" #include "slinkyGlobals.h" +#include "link.h" +#include "debugPrint.h" +#include "errorStuff.h" +#include "instantiate.h" +#include "poke.h" +#include "read.h" +#include "relocate.h" +#include "write.h" + /*#define readWord(f,fn) ((getc(f) & 0xFF) | ((getc(f) & 0xFF)<<8))*/ /* @@ -102,7 +111,6 @@ internalizeOneObjectFile(objectFile) int mode; addressType startAddress; addressType endAddress; - bool compareSymbolValues(); currentFileName = objectFile->name; if ((objectFildes = fopen(objectFile->name, "r")) == NULL) { diff --git a/slinky/link.h b/slinky/link.h new file mode 100644 index 0000000..2eceb1e --- /dev/null +++ b/slinky/link.h @@ -0,0 +1,19 @@ +#ifndef LINK_H_ +#define LINK_H_ + +#include "slinkyTypes.h" + +bool internalizeOneObjectFile(objectFileListType *objectFile); +bool strcmplc(char *s1, char *s2); +bool compareSymbols(symbolType **symbol1, symbolType **symbol2); +void buildGlobalSymbolTable(objectFileListType *inputFileList); +bool readem(void); +codeSegmentHeaderType *locateConflictingSegment(codeSegmentHeaderType *codeSegment); +void reserveSegment(addressType start, addressType end); +codeSegmentHeaderType *allocateAbsolute(codeSegmentHeaderType *codeSegment); +void reserveReservations(void); +void installSegment(codeSegmentHeaderType *codeSegment); +void installAbsoluteCodeSegment(codeSegmentHeaderType *codeSegment); +void linkem(void); + +#endif diff --git a/slinky/main.c b/slinky/main.c index abcc6a9..89455e7 100644 --- a/slinky/main.c +++ b/slinky/main.c @@ -29,7 +29,11 @@ #include "slinkyTypes.h" #include "slinkyGlobals.h" +#include "main.h" +#include "initialize.h" +#include "link.h" +int main(argc, argv) int argc; char *argv[]; @@ -38,8 +42,7 @@ main(argc, argv) linkem(); if (errorFlag) chokePukeAndDie(); - else - exit(0); + return 0; } void diff --git a/slinky/main.h b/slinky/main.h new file mode 100644 index 0000000..c102f42 --- /dev/null +++ b/slinky/main.h @@ -0,0 +1,8 @@ +#ifndef MAIN_H_ +#define MAIN_H_ + +#include "slinkyTypes.h" + +void printVersion(void); + +#endif diff --git a/slinky/map.c b/slinky/map.c index 41f0c5c..dab44a1 100644 --- a/slinky/map.c +++ b/slinky/map.c @@ -30,11 +30,9 @@ #include "slinkyTypes.h" #include "slinkyGlobals.h" - -typedef struct { - symbolType *symbol; - stringType *fileName; - } loadMapTableEntryType; +#include "map.h" +#include "debugPrint.h" +#include "link.h" int compareLoadMapEntries(entry1, entry2) diff --git a/slinky/map.h b/slinky/map.h new file mode 100644 index 0000000..294344f --- /dev/null +++ b/slinky/map.h @@ -0,0 +1,14 @@ +#ifndef MAP_H_ +#define MAP_H_ + +#include "slinkyTypes.h" + +typedef struct { + symbolType *symbol; + stringType *fileName; + } loadMapTableEntryType; + +int compareLoadMapEntries(loadMapTableEntryType *entry1, loadMapTableEntryType *entry2); +void outputLoadMap(void); + +#endif diff --git a/slinky/poke.c b/slinky/poke.c index 94b7b27..89fac42 100644 --- a/slinky/poke.c +++ b/slinky/poke.c @@ -31,6 +31,10 @@ #include "slinkyTypes.h" #include "slinkyGlobals.h" +#include "poke.h" +#include "debugPrint.h" +#include "errorStuff.h" +#include "expr.h" bool isWordSized(value) diff --git a/slinky/poke.h b/slinky/poke.h new file mode 100644 index 0000000..94c69bd --- /dev/null +++ b/slinky/poke.h @@ -0,0 +1,15 @@ +#ifndef POKE_H_ +#define POKE_H_ + +#include "slinkyTypes.h" + +bool isWordSized(int value); +bool isByteSized(int value); +bool isByteOffset(int value); +int computeRelativeValue(int valueToPoke, codeSegmentHeaderType *codeSegment, int offset); +int getBaseValue(byte *codeBuffer, int offset, int referenceKind); +void pokeValue(int value, byte *codeBuffer, int offset, int referenceKind, int trueAddress); +void fixupReference(expressionReferenceType *reference, codeSegmentHeaderType *codeSegment); +void pokem(void); + +#endif diff --git a/slinky/read.c b/slinky/read.c index 242cc4a..aab35b0 100644 --- a/slinky/read.c +++ b/slinky/read.c @@ -31,6 +31,12 @@ #include "slinkyTypes.h" #include "slinkyGlobals.h" +#include "read.h" +#include "debugPrint.h" +#include "errorStuff.h" +#include "initialize.h" +#include "instantiate.h" +#include "link.h" #define isAbsolute(symbol) (((symbol)->symbolClass & SYMBOL_ABSOLUTE) != 0) #define isRelocatable(symbol) (((symbol)->symbolClass &SYMBOL_RELOCATABLE)!=0) @@ -520,7 +526,6 @@ readReservations(objectFile, objectFildes) FILE *objectFildes; { addressType startAddress; - reservationListType *buildReservation(); if (debug) printf(" reservations\n"); diff --git a/slinky/read.h b/slinky/read.h new file mode 100644 index 0000000..a88557a --- /dev/null +++ b/slinky/read.h @@ -0,0 +1,28 @@ +#ifndef READ_H_ +#define READ_H_ + +#include "slinkyTypes.h" + +void fileCheck(FILE *fildes, char *fileName); +wordType readWord(FILE *file, char *fileName); +byte readByte(FILE *file, char *fileName); +bigWord readBigword(FILE *file, char *fileName); +bigWord read3ByteWord(FILE *file, char *fileName); +int readString(char *buffer, FILE *fildes, char *fileName); +void readChunk(byte *buffer, int numberOfBytes, FILE *fildes, char *fileName); +void readCode(addressType startAddress, addressType endAddress, int mode, objectFileListType *objectFile, FILE *objectFildes); +bool compareReferences(expressionReferenceType *reference1, expressionReferenceType *reference2); +void sortReferences(expressionReferenceType *theReferences, int numberOfReferences); +void readReference(expressionReferenceType *reference, FILE *fildes, char *fileName); +void readReferences(objectFileListType *objectFile, FILE *objectFildes); +bool compareSymbolValues(symbolType **symbol1, symbolType **symbol2); +void readSymbols(objectFileListType *objectFile, FILE *objectFildes); +expressionPCType readOneExpression(objectFileListType *objectFile, FILE *objectFildes); +void readExpressions(objectFileListType *objectFile, FILE *objectFildes); +argumentListType *readArgumentList(objectFileListType *objectFile, FILE *objectFildes); +void readFunctions(objectFileListType *objectFile, FILE *objectFildes); +void instantiateExpressionAndSymbolPointers(objectFileListType *objectFile); +void readReservations(objectFileListType *objectFile, FILE *objectFildes); +reservationListType *buildReservation(addressType startAddress, int blockSize, reservationListType *nextReservation); + +#endif diff --git a/slinky/relocate.c b/slinky/relocate.c index c04f95b..a108d8a 100644 --- a/slinky/relocate.c +++ b/slinky/relocate.c @@ -30,6 +30,11 @@ #include "slinkyTypes.h" #include "slinkyGlobals.h" +#include "relocate.h" +#include "debugPrint.h" +#include "errorStuff.h" +#include "link.h" +#include "map.h" #define isUndefined(symbol) (((symbol)->symbolClass & ~SYMBOL_EXTERNAL) == 0) diff --git a/slinky/relocate.h b/slinky/relocate.h new file mode 100644 index 0000000..ebdcf9f --- /dev/null +++ b/slinky/relocate.h @@ -0,0 +1,22 @@ +#ifndef RELOCATE_H_ +#define RELOCATE_H_ + +#include "slinkyTypes.h" + +void removeZeroPageFromFreeList(void); +addressType align(addressType address, int alignment); +addressType constrain(addressType address, int size, addressType constraint); +void moveRelocationBase(addressType newBase); +addressType allocateRelocatable(codeSegmentHeaderType *codeSegment); +void relocateOneCodeSegment(codeSegmentHeaderType *codeSegment, addressType targetLocation); +void relocatem(void); +codeSegmentHeaderType *matchModes(symbolType *symbol, codeSegmentHeaderType *codeSegment); +bool matchedModes(symbolType *symbol, codeSegmentHeaderType *codeSegment); +codeSegmentHeaderType *synchronizeCodeSegment(symbolType *symbol, codeSegmentHeaderType *codeSegment); +void handleGlobalSymbol(symbolType *symbol); +void valueSymbol(symbolType *symbol, codeSegmentHeaderType *codeSegment); +symbolType *lookupGlobalSymbol(char *symbolName); +void valueUndefinedSymbol(symbolType *symbol); +void valuem(void); + +#endif diff --git a/slinky/slinkyTables.c b/slinky/slinkyTables.c index d4ecc71..6146fb5 100644 --- a/slinky/slinkyTables.c +++ b/slinky/slinkyTables.c @@ -28,23 +28,7 @@ */ #include "slinkyTypes.h" - -addressType atasciiBIF(); -addressType atasciiColorBIF(); -addressType isAbsoluteValueBIF(); -addressType isConditionCodeBIF(); -addressType isDefinedBIF(); -addressType isExternalBIF(); -addressType nthCharBIF(); -addressType printfBIF(); -addressType strcatBIF(); -addressType strcmpBIF(); -addressType strcmplcBIF(); -addressType strlenBIF(); -addressType substrBIF(); -addressType symbolDefineBIF(); -addressType symbolLookupBIF(); -addressType symbolNameBIF(); +#include "builtins.h" /* Used to initialize symbols representing built-in functions */ struct { diff --git a/slinky/slinkyTables.h b/slinky/slinkyTables.h new file mode 100644 index 0000000..30ca7e3 --- /dev/null +++ b/slinky/slinkyTables.h @@ -0,0 +1,7 @@ +#ifndef SLINKY_TABLES_H_ +#define SLINKY_TABLES_H_ + +#include "slinkyTypes.h" + + +#endif diff --git a/slinky/slinkyTypes.h b/slinky/slinkyTypes.h index 2f41f51..161a143 100644 --- a/slinky/slinkyTypes.h +++ b/slinky/slinkyTypes.h @@ -26,6 +26,8 @@ 8-March-1985 */ +#ifndef SLINKY_TYPES_H_ +#define SLINKY_TYPES_H_ #include #include @@ -188,3 +190,5 @@ typedef enum { #define typeAlloc(type) (type *)malloc(sizeof(type)) #define typeAllocBlock(type, size) (type *)malloc(sizeof(type) * (size)) + +#endif diff --git a/slinky/write.c b/slinky/write.c index b73b8e9..740e923 100644 --- a/slinky/write.c +++ b/slinky/write.c @@ -30,6 +30,7 @@ #include "slinkyTypes.h" #include "slinkyGlobals.h" +#include "write.h" #define writeWord(aWord) putc(aWord & 0xFF, loadFileOutput);\ putc((aWord >> 8) & 0xFF, loadFileOutput) diff --git a/slinky/write.h b/slinky/write.h new file mode 100644 index 0000000..e4b616c --- /dev/null +++ b/slinky/write.h @@ -0,0 +1,10 @@ +#ifndef WRITE_H_ +#define WRITE_H_ + +#include "slinkyTypes.h" + +void writeEntryPoint(void); +void writeCodeSegment(codeSegmentHeaderType *codeSegment); +void writem(void); + +#endif