Extern all the globals, not just the tables

This commit is contained in:
Michael Martin 2016-01-24 00:00:20 -08:00
parent 693c15a2a8
commit d53658da5e
6 changed files with 342 additions and 136 deletions

View File

@ -7,14 +7,14 @@ PROC =6502
OBJECTS = y.tab.o actions.o buildStuff1.o buildStuff2.o\ OBJECTS = y.tab.o actions.o buildStuff1.o buildStuff2.o\
buildStuff3.o builtInFunctions.o builtInFunsSD.o debugPrint.o debugPrintSD.o\ buildStuff3.o builtInFunctions.o builtInFunsSD.o debugPrint.o debugPrintSD.o\
emitBranch.o emitStuff.o encode.o errorStuff.o expressionSemantics.o fixups.o\ emitBranch.o emitStuff.o encode.o errorStuff.o expressionSemantics.o fixups.o\
garbage.o initialize.o lexer.o listing.o lookups.o macrossTables.o main.o\ garbage.o globals.o initialize.o lexer.o listing.o lookups.o macrossTables.o main.o\
object.o operandStuffSD.o parserMisc.o semanticMisc.o\ object.o operandStuffSD.o parserMisc.o semanticMisc.o\
statementSemantics.o structSemantics.o tokenStrings.o statementSemantics.o structSemantics.o tokenStrings.o
SOURCES = macross_$(PROC).y actions_$(PROC).c buildStuff1.c buildStuff2.c\ SOURCES = macross_$(PROC).y actions_$(PROC).c buildStuff1.c buildStuff2.c\
buildStuff3.c builtInFunctions.c builtInFunsSD_$(PROC).c debugPrint.c\ buildStuff3.c builtInFunctions.c builtInFunsSD_$(PROC).c debugPrint.c\
debugPrintSD_$(PROC).c emitBranch_$(PROC).c emitStuff.c encode.c errorStuff.c\ debugPrintSD_$(PROC).c emitBranch_$(PROC).c emitStuff.c encode.c errorStuff.c\
expressionSemantics.c fixups.c garbage.c initialize.c lexer.c listing.c\ expressionSemantics.c fixups.c garbage.c globals.c initialize.c lexer.c listing.c\
lookups.c macrossTables_$(PROC).c main.c object.c\ lookups.c macrossTables_$(PROC).c main.c object.c\
operandStuffSD_$(PROC).c parserMisc.c semanticMisc.c statementSemantics.c\ operandStuffSD_$(PROC).c parserMisc.c semanticMisc.c statementSemantics.c\
structSemantics.c tokenStrings_$(PROC).c lexerTables.h macrossGlobals.h\ structSemantics.c tokenStrings_$(PROC).c lexerTables.h macrossGlobals.h\

143
globals.c Normal file
View File

@ -0,0 +1,143 @@
/*
* Copyright (c) 1987 Fujitsu
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
/*
macrossGlobals.h -- Global variable definitions for the Macross
assembler.
Chip Morningstar -- Lucasfilm Ltd.
1-November-1984
*/
#include "macrossTypes.h"
#include "macrossGlobals.h"
bool backwardsCompatibleIfFlag;
bool beneathFunction;
commandLineDefineType *commandLineDefines;
int cumulativeLineNumber;
environmentType *currentEnvironment;
int currentFieldOffset;
char *currentFileName;
char *lastErrorFile;
stringType *currentFunctionName;
int currentLabelTagNumber;
int currentLineNumber;
int lastErrorLine;
identifierListType *currentLocalVariableList;
valueType currentLocationCounter;
int currentOperandNumber;
int currentReferenceDepth;
bool debug;
bool emitPrint;
bool expandMacros;
bool errorFlag;
bool expressionFailed;
bool finishOperand;
operandKindType fixupAddressMode[MAX_NUMBER_OF_OPERANDS];
operandKindType newFixupAddressMode;
fixupListType *fixupList;
bool freeFlag;
bool freturnExit;
bool generatingFixup;
environmentType globalEnvironment;
int hackFlag;
bool haveUserStartAddress;
bool fixupStartAddress;
int includeNestingDepth;
FILE *indexFileForPass2;
FILE *input;
fileNameListType *inputFileStack;
FILE *listFileOutput;
int listingControlCounter;
bool listingOn;
int macroCallDepth;
FILE *macroFileForPass2;
int macroOrFunctionNestingDepth;
structInstanceType *newStruct;
int nextEnvironmentNumber;
int nextLabelTagNumber;
FILE *objectFileOutput;
char operandBuffer[MAX_NUMBER_OF_OPERANDS][LINE_BUFFER_SIZE];
expressionType *pendingFixup[MAX_NUMBER_OF_OPERANDS];
bool performingFixups;
bool positionIndependentCodeMode;
bool produceLinkableObject;
addressType relocatableHighWaterMark;
reservationListType *reservationList;
valueType *resultOfLastFunctionCall;
valueType savedRelocatableCurrentLocationCounter;
FILE *saveFileForPass2;
bool showAllSymbolsFlag;
bool sideEffectFlag;
bool standaloneExpansionFlag;
valueType *startAddress;
int statementEvaluationDepth;
int statementListNestingDepth;
int structNestingDepth;
FILE *symbolDumpFileOutput;
bool symbolTableDumpOn;
int tabCount;
addressType targetOffset;
bool terseErrorMessages;
valueType *UndefinedValue;
symbolUsageKindType unknownSymbolTag;
int (*lexDispatchTable[128])();
macroTableEntryType *macroTable[HASH_TABLE_SIZE];
opcodeTableEntryType *opcodeTable[HASH_TABLE_SIZE];
keywordTableEntryType *keywordTable[HASH_TABLE_SIZE];
conditionTableEntryType *conditionTable[HASH_TABLE_SIZE];
symbolTableEntryType *symbolTable[HASH_TABLE_SIZE];
int validSymbolValues[NUM_OF_SYM_USAGES];
byte structScratchBuffer[MAXIMUM_ALLOWED_STRUCT_SIZE];
codeRegionType absoluteCodeRegion;
codeRegionType relocatableCodeRegion;
codeRegionType *codeRegions[2];
codeBufferKindType currentCodeMode;
codeBufferType *emptyBuffer; /* ??? */
codeBreakType *codeBreakList;
codeBreakType *lastCodeBreak;
expressionReferenceListType *expressionReferenceList[3];
expressionReferenceListType *referencesToNote[MAX_NUMBER_OF_OPERANDS];
int numberOfReferencesInList[3];
functionDefinitionType *externalFunctionList;
functionDefinitionType *endOfExternalFunctionList;
int externalFunctionCount;
char alphabeticCharacterTable[128];
char alphaNumericCharacterTable[128];
char lowerCaseCharacterTable[128];
char numericCharacterTable[128];
int expressionBufferSize;
byte expressionBuffer[EXPRESSION_BUFFER_LIMIT];

View File

@ -29,84 +29,84 @@
*/ */
bool backwardsCompatibleIfFlag; extern bool backwardsCompatibleIfFlag;
bool beneathFunction; extern bool beneathFunction;
commandLineDefineType *commandLineDefines; extern commandLineDefineType *commandLineDefines;
int cumulativeLineNumber; extern int cumulativeLineNumber;
environmentType *currentEnvironment; extern environmentType *currentEnvironment;
int currentFieldOffset; extern int currentFieldOffset;
char *currentFileName; extern char *currentFileName;
char *lastErrorFile; extern char *lastErrorFile;
stringType *currentFunctionName; extern stringType *currentFunctionName;
int currentLabelTagNumber; extern int currentLabelTagNumber;
int currentLineNumber; extern int currentLineNumber;
int lastErrorLine; extern int lastErrorLine;
identifierListType *currentLocalVariableList; extern identifierListType *currentLocalVariableList;
valueType currentLocationCounter; extern valueType currentLocationCounter;
int currentOperandNumber; extern int currentOperandNumber;
int currentReferenceDepth; extern int currentReferenceDepth;
bool debug; extern bool debug;
bool emitPrint; extern bool emitPrint;
bool expandMacros; extern bool expandMacros;
bool errorFlag; extern bool errorFlag;
bool expressionFailed; extern bool expressionFailed;
bool finishOperand; extern bool finishOperand;
operandKindType fixupAddressMode[MAX_NUMBER_OF_OPERANDS]; extern operandKindType fixupAddressMode[MAX_NUMBER_OF_OPERANDS];
operandKindType newFixupAddressMode; extern operandKindType newFixupAddressMode;
fixupListType *fixupList; extern fixupListType *fixupList;
bool freeFlag; extern bool freeFlag;
bool freturnExit; extern bool freturnExit;
bool generatingFixup; extern bool generatingFixup;
environmentType globalEnvironment; extern environmentType globalEnvironment;
int hackFlag; extern int hackFlag;
bool haveUserStartAddress; extern bool haveUserStartAddress;
bool fixupStartAddress; extern bool fixupStartAddress;
int includeNestingDepth; extern int includeNestingDepth;
FILE *indexFileForPass2; extern FILE *indexFileForPass2;
FILE *input; extern FILE *input;
fileNameListType *inputFileStack; extern fileNameListType *inputFileStack;
FILE *listFileOutput; extern FILE *listFileOutput;
int listingControlCounter; extern int listingControlCounter;
bool listingOn; extern bool listingOn;
int macroCallDepth; extern int macroCallDepth;
FILE *macroFileForPass2; extern FILE *macroFileForPass2;
int macroOrFunctionNestingDepth; extern int macroOrFunctionNestingDepth;
structInstanceType *newStruct; extern structInstanceType *newStruct;
int nextEnvironmentNumber; extern int nextEnvironmentNumber;
int nextLabelTagNumber; extern int nextLabelTagNumber;
FILE *objectFileOutput; extern FILE *objectFileOutput;
char operandBuffer[MAX_NUMBER_OF_OPERANDS][LINE_BUFFER_SIZE]; extern char operandBuffer[MAX_NUMBER_OF_OPERANDS][LINE_BUFFER_SIZE];
extern char pass2IndexFileName[]; extern char pass2IndexFileName[];
extern char pass2SourceFileName[]; extern char pass2SourceFileName[];
extern char pass2MacroExpansionFileName[]; extern char pass2MacroExpansionFileName[];
expressionType *pendingFixup[MAX_NUMBER_OF_OPERANDS]; extern expressionType *pendingFixup[MAX_NUMBER_OF_OPERANDS];
bool performingFixups; extern bool performingFixups;
bool positionIndependentCodeMode; extern bool positionIndependentCodeMode;
bool produceLinkableObject; extern bool produceLinkableObject;
addressType relocatableHighWaterMark; extern addressType relocatableHighWaterMark;
reservationListType *reservationList; extern reservationListType *reservationList;
valueType *resultOfLastFunctionCall; extern valueType *resultOfLastFunctionCall;
valueType savedRelocatableCurrentLocationCounter; extern valueType savedRelocatableCurrentLocationCounter;
FILE *saveFileForPass2; extern FILE *saveFileForPass2;
bool showAllSymbolsFlag; extern bool showAllSymbolsFlag;
bool sideEffectFlag; extern bool sideEffectFlag;
bool standaloneExpansionFlag; extern bool standaloneExpansionFlag;
valueType *startAddress; extern valueType *startAddress;
int statementEvaluationDepth; extern int statementEvaluationDepth;
int statementListNestingDepth; extern int statementListNestingDepth;
int structNestingDepth; extern int structNestingDepth;
FILE *symbolDumpFileOutput; extern FILE *symbolDumpFileOutput;
bool symbolTableDumpOn; extern bool symbolTableDumpOn;
int tabCount; extern int tabCount;
addressType targetOffset; extern addressType targetOffset;
bool terseErrorMessages; extern bool terseErrorMessages;
valueType *UndefinedValue; extern valueType *UndefinedValue;
symbolUsageKindType unknownSymbolTag; extern symbolUsageKindType unknownSymbolTag;
#define DEFAULT_OBJECT_FILE_NAME "m.out" #define DEFAULT_OBJECT_FILE_NAME "m.out"
#define LEX_DISPATCH_TABLE_SIZE 128 #define LEX_DISPATCH_TABLE_SIZE 128
int (*lexDispatchTable[128])(); extern int (*lexDispatchTable[128])();
#define HASH_TABLE_SIZE 512 #define HASH_TABLE_SIZE 512
#define HASH_TABLE_MASK 0x1FF #define HASH_TABLE_MASK 0x1FF
@ -123,50 +123,50 @@ extern struct {
int symbolValue; int symbolValue;
} predefinedSymbolTable[]; } predefinedSymbolTable[];
macroTableEntryType *macroTable[HASH_TABLE_SIZE]; extern macroTableEntryType *macroTable[HASH_TABLE_SIZE];
opcodeTableEntryType *opcodeTable[HASH_TABLE_SIZE]; extern opcodeTableEntryType *opcodeTable[HASH_TABLE_SIZE];
extern opcodeTableEntryType theOpcodes[]; extern opcodeTableEntryType theOpcodes[];
keywordTableEntryType *keywordTable[HASH_TABLE_SIZE]; extern keywordTableEntryType *keywordTable[HASH_TABLE_SIZE];
extern keywordTableEntryType theKeywords[]; extern keywordTableEntryType theKeywords[];
conditionTableEntryType *conditionTable[HASH_TABLE_SIZE]; extern conditionTableEntryType *conditionTable[HASH_TABLE_SIZE];
extern conditionTableEntryType theConditions[]; extern conditionTableEntryType theConditions[];
symbolTableEntryType *symbolTable[HASH_TABLE_SIZE]; extern symbolTableEntryType *symbolTable[HASH_TABLE_SIZE];
extern int operandClassTable[]; extern int operandClassTable[];
extern void (*instructionActionTable[])(); extern void (*instructionActionTable[])();
int validSymbolValues[NUM_OF_SYM_USAGES]; extern int validSymbolValues[NUM_OF_SYM_USAGES];
byte structScratchBuffer[MAXIMUM_ALLOWED_STRUCT_SIZE]; extern byte structScratchBuffer[MAXIMUM_ALLOWED_STRUCT_SIZE];
codeRegionType absoluteCodeRegion; extern codeRegionType absoluteCodeRegion;
codeRegionType relocatableCodeRegion; extern codeRegionType relocatableCodeRegion;
codeRegionType *codeRegions[2]; extern codeRegionType *codeRegions[2];
codeBufferKindType currentCodeMode; extern codeBufferKindType currentCodeMode;
codeBufferType *emptyBuffer; /* ??? */ extern codeBufferType *emptyBuffer; /* ??? */
codeBreakType *codeBreakList; extern codeBreakType *codeBreakList;
codeBreakType *lastCodeBreak; extern codeBreakType *lastCodeBreak;
expressionReferenceListType *expressionReferenceList[3]; extern expressionReferenceListType *expressionReferenceList[3];
expressionReferenceListType *referencesToNote[MAX_NUMBER_OF_OPERANDS]; extern expressionReferenceListType *referencesToNote[MAX_NUMBER_OF_OPERANDS];
int numberOfReferencesInList[3]; extern int numberOfReferencesInList[3];
functionDefinitionType *externalFunctionList; extern functionDefinitionType *externalFunctionList;
functionDefinitionType *endOfExternalFunctionList; extern functionDefinitionType *endOfExternalFunctionList;
int externalFunctionCount; extern int externalFunctionCount;
char alphabeticCharacterTable[128]; extern char alphabeticCharacterTable[128];
char alphaNumericCharacterTable[128]; extern char alphaNumericCharacterTable[128];
char lowerCaseCharacterTable[128]; extern char lowerCaseCharacterTable[128];
char numericCharacterTable[128]; extern char numericCharacterTable[128];
int expressionBufferSize; extern int expressionBufferSize;
#define EXPRESSION_BUFFER_LIMIT 500 #define EXPRESSION_BUFFER_LIMIT 500
byte expressionBuffer[EXPRESSION_BUFFER_LIMIT]; extern byte expressionBuffer[EXPRESSION_BUFFER_LIMIT];

View File

@ -1,17 +1,17 @@
.SUFFIXES: .o .c .h .run .SUFFIXES: .o .c .h .run
OBJECTS = builtins.o debugPrint.o errorStuff.o expr.o initialize.o\ OBJECTS = builtins.o debugPrint.o errorStuff.o expr.o globals.o initialize.o\
instantiate.o link.o main.o map.o poke.o read.o relocate.o slinkyTables.o\ instantiate.o link.o main.o map.o poke.o read.o relocate.o slinkyTables.o\
write.o write.o
SOURCES = builtins.c debugPrint.c errorStuff.c expr.c initialize.c\ SOURCES = builtins.c debugPrint.c errorStuff.c expr.c globals.c initialize.c\
instantiate.c link.c main.c map.c poke.c read.c relocate.c slinkyTables.c\ instantiate.c link.c main.c map.c poke.c read.c relocate.c slinkyTables.c\
write.c slinkyExpressions.h slinkyGlobals.h slinkyTypes.h y.tab.h write.c slinkyExpressions.h slinkyGlobals.h slinkyTypes.h y.tab.h
CFLAGS=-m32 -Wno-int-conversion -Wno-incompatible-pointer-types # slinky is not 64 bit clean CFLAGS=-O2 -m32 -Wno-int-conversion -Wno-incompatible-pointer-types # slinky is not 64 bit clean
.c.o: .c.o:
cc $(CFLAGS) -c -g $*.c cc $(CFLAGS) -c $*.c
.c.run: .c.run:
cc $(CFLAGS) -o $* $*.c cc $(CFLAGS) -o $* $*.c

63
slinky/globals.c Normal file
View File

@ -0,0 +1,63 @@
/*
* Copyright (c) 1987 Fujitsu
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
/*
slinkyGlobals.h -- Global variables for the Slinky linker.
Chip Morningstar -- Lucasfilm Ltd.
9-March-1985
*/
#include "slinkyTypes.h"
#include "slinkyGlobals.h"
bool debug; /* TRUE iff we should print debug diagnostics */
bool errorFlag; /* TRUE iff an error occured during linking */
bool verbose;
bool packFlag;
FILE *loadFileOutput; /* where to put the results */
FILE *mapFileOutput;
objectFileListType *objectFileList;
objectFileListType *endOfObjectFileList;
char *currentFileName;
freeSegmentEntryType *freeSegmentList;
freeSegmentEntryType *effectiveFreeSegmentList;
addressType relocationOffset;
addressType entryPointAddress;
int entryPointMode;
expressionPCType entryPointExpression;
bool produceLoadMap;
bool leaveOffLoadFiles;
bool haveEntryPoint;
bool haveExpressionEntryPoint;
bool readExpressionEntryPoint;
symbolType **globalSymbolTable;
int globalSymbolCount;
symbolType **currentSymbolTable;
functionType *currentFunctionTable;
reservationListType *reservationList;
int totalSymbolCount;
expressionPCType pc;
addressType here;
bindingListType *localBindings;
segmentListType *generatedLoadImage[CODE_REGIONS_IN_ADDRESS_SPACE];

View File

@ -27,40 +27,40 @@
9-March-1985 9-March-1985
*/ */
bool debug; /* TRUE iff we should print debug diagnostics */ extern bool debug; /* TRUE iff we should print debug diagnostics */
bool errorFlag; /* TRUE iff an error occured during linking */ extern bool errorFlag; /* TRUE iff an error occured during linking */
bool verbose; extern bool verbose;
bool packFlag; extern bool packFlag;
#define DEFAULT_LOAD_FILE_NAME "s.out" #define DEFAULT_LOAD_FILE_NAME "s.out"
FILE *loadFileOutput; /* where to put the results */ extern FILE *loadFileOutput; /* where to put the results */
FILE *mapFileOutput; extern FILE *mapFileOutput;
objectFileListType *objectFileList; extern objectFileListType *objectFileList;
objectFileListType *endOfObjectFileList; extern objectFileListType *endOfObjectFileList;
char *currentFileName; extern char *currentFileName;
freeSegmentEntryType *freeSegmentList; extern freeSegmentEntryType *freeSegmentList;
freeSegmentEntryType *effectiveFreeSegmentList; extern freeSegmentEntryType *effectiveFreeSegmentList;
addressType relocationOffset; extern addressType relocationOffset;
addressType entryPointAddress; extern addressType entryPointAddress;
int entryPointMode; extern int entryPointMode;
expressionPCType entryPointExpression; extern expressionPCType entryPointExpression;
bool produceLoadMap; extern bool produceLoadMap;
bool leaveOffLoadFiles; extern bool leaveOffLoadFiles;
bool haveEntryPoint; extern bool haveEntryPoint;
bool haveExpressionEntryPoint; extern bool haveExpressionEntryPoint;
bool readExpressionEntryPoint; extern bool readExpressionEntryPoint;
symbolType **globalSymbolTable; extern symbolType **globalSymbolTable;
int globalSymbolCount; extern int globalSymbolCount;
symbolType **currentSymbolTable; extern symbolType **currentSymbolTable;
functionType *currentFunctionTable; extern functionType *currentFunctionTable;
reservationListType *reservationList; extern reservationListType *reservationList;
int totalSymbolCount; extern int totalSymbolCount;
expressionPCType pc; extern expressionPCType pc;
addressType here; extern addressType here;
bindingListType *localBindings; extern bindingListType *localBindings;
#define CODE_REGIONS_IN_ADDRESS_SPACE 256 #define CODE_REGIONS_IN_ADDRESS_SPACE 256
#define CODE_REGION_SIZE 0x100 #define CODE_REGION_SIZE 0x100
segmentListType *generatedLoadImage[CODE_REGIONS_IN_ADDRESS_SPACE]; extern segmentListType *generatedLoadImage[CODE_REGIONS_IN_ADDRESS_SPACE];
#define regionOf(addr) (addr / CODE_REGION_SIZE) #define regionOf(addr) (addr / CODE_REGION_SIZE)
extern struct { extern struct {