Add relocated sections

This commit is contained in:
drmortalwombat 2022-01-22 18:21:52 +01:00
parent 5bda8a4d01
commit ca93f107c3
18 changed files with 476 additions and 259 deletions

1
.gitignore vendored
View File

@ -343,3 +343,4 @@ make/oscar64
*.int *.int
*.bcs *.bcs
*.crt *.crt
*.crt

View File

@ -23,17 +23,6 @@ char spentry = 0;
int main(void); int main(void);
__asm inp_exit
{
lda #$4c
sta $54
lda #0
sta $13
lda #$19
sta $16
rts
}
__asm startup __asm startup
{ {
@ -139,7 +128,6 @@ tyexec:
yexec: yexec:
zexec: zexec:
exec: exec:
jmp inp_exit
#else #else
@ -178,6 +166,15 @@ bcode:
byt >main byt >main
byt BC_EXIT * 2 byt BC_EXIT * 2
#endif #endif
spexit:
lda #$4c
sta $54
lda #0
sta $13
lda #$19
sta $16
rts
} }
#pragma startup(startup) #pragma startup(startup)
@ -689,7 +686,7 @@ __asm inp_nop
#pragma bytecode(BC_NOP, inp_nop) #pragma bytecode(BC_NOP, inp_nop)
#pragma bytecode(BC_EXIT, inp_exit) #pragma bytecode(BC_EXIT, startup.spexit)
__asm inp_jsr __asm inp_jsr
{ {

View File

@ -8,7 +8,7 @@
#include <string.h> #include <string.h>
CompilationUnits::CompilationUnits(Errors * errors) CompilationUnits::CompilationUnits(Errors * errors)
: mErrors(errors) : mErrors(errors), mReferenced(nullptr)
{ {
mCompilationUnits = nullptr; mCompilationUnits = nullptr;
mPendingUnits = nullptr; mPendingUnits = nullptr;
@ -25,6 +25,11 @@ CompilationUnits::~CompilationUnits(void)
} }
void CompilationUnits::AddReferenced(Declaration* ref)
{
mReferenced.Push(ref);
}
bool CompilationUnits::AddUnit(Location& location, const char* name, const char* from) bool CompilationUnits::AddUnit(Location& location, const char* name, const char* from)
{ {
char filename[200]; char filename[200];

View File

@ -24,6 +24,7 @@ public:
Declaration* mStartup; Declaration* mStartup;
Declaration* mByteCodes[256]; Declaration* mByteCodes[256];
GrowingArray<Declaration*> mReferenced;
DeclarationScope* mRuntimeScope; DeclarationScope* mRuntimeScope;
@ -32,6 +33,9 @@ public:
bool AddUnit(Location & location, const char* name, const char * from); bool AddUnit(Location & location, const char* name, const char * from);
CompilationUnit* PendingUnit(void); CompilationUnit* PendingUnit(void);
void AddReferenced(Declaration* ref);
protected: protected:
Errors* mErrors; Errors* mErrors;
}; };

View File

@ -177,15 +177,30 @@ bool Compiler::GenerateCode(void)
mGlobalAnalyzer->mCompilerOptions = mCompilerOptions; mGlobalAnalyzer->mCompilerOptions = mCompilerOptions;
mGlobalAnalyzer->AnalyzeAssembler(dcrtstart->mValue, nullptr); mGlobalAnalyzer->AnalyzeAssembler(dcrtstart->mValue, nullptr);
// mGlobalAnalyzer->DumpCallGraph();
for (int i = 0; i < mCompilationUnits->mReferenced.Size(); i++)
{
Declaration* dec = mCompilationUnits->mReferenced[i];
if (dec->mType == DT_CONST_FUNCTION)
mGlobalAnalyzer->AnalyzeProcedure(dec->mValue, dec);
else
mGlobalAnalyzer->AnalyzeGlobalVariable(dec);
}
mGlobalAnalyzer->AutoInline(); mGlobalAnalyzer->AutoInline();
// mGlobalAnalyzer->DumpCallGraph();
mInterCodeGenerator->mCompilerOptions = mCompilerOptions; mInterCodeGenerator->mCompilerOptions = mCompilerOptions;
mNativeCodeGenerator->mCompilerOptions = mCompilerOptions; mNativeCodeGenerator->mCompilerOptions = mCompilerOptions;
mInterCodeModule->mCompilerOptions = mCompilerOptions; mInterCodeModule->mCompilerOptions = mCompilerOptions;
mInterCodeGenerator->TranslateAssembler(mInterCodeModule, dcrtstart->mValue, nullptr); mInterCodeGenerator->TranslateAssembler(mInterCodeModule, dcrtstart->mValue, nullptr);
for (int i = 0; i < mCompilationUnits->mReferenced.Size(); i++)
{
Declaration* dec = mCompilationUnits->mReferenced[i];
if (dec->mType == DT_CONST_FUNCTION)
mInterCodeGenerator->TranslateProcedure(mInterCodeModule, dec->mValue, dec);
else
mInterCodeGenerator->InitGlobalVariable(mInterCodeModule, dec);
}
if (mErrors->mErrorCount != 0) if (mErrors->mErrorCount != 0)
return false; return false;
@ -335,6 +350,9 @@ bool Compiler::GenerateCode(void)
if (!(mCompilerOptions & COPT_NATIVE)) if (!(mCompilerOptions & COPT_NATIVE))
mLinker->ReferenceObject(byteCodeObject); mLinker->ReferenceObject(byteCodeObject);
for (int i = 0; i < mCompilationUnits->mReferenced.Size(); i++)
mLinker->ReferenceObject(mCompilationUnits->mReferenced[i]->mLinkerObject);
mLinker->Link(); mLinker->Link();
return mErrors->mErrorCount == 0; return mErrors->mErrorCount == 0;

View File

@ -201,7 +201,14 @@ Expression* Expression::ConstantFold(Errors * errors)
} }
} }
}
else if (mLeft->mDecValue->mType == DT_CONST_FUNCTION)
{
switch (mToken)
{
case TK_BINARY_AND:
return mLeft;
}
} }
} }
else if (mType == EX_TYPECAST && mRight->mType == EX_CONSTANT) else if (mType == EX_TYPECAST && mRight->mType == EX_CONSTANT)

View File

@ -53,6 +53,7 @@ enum ErrorID
EERR_PRAGMA_PARAMETER, EERR_PRAGMA_PARAMETER,
ERRR_PREPROCESSOR, ERRR_PREPROCESSOR,
ERRR_INVALID_CASE, ERRR_INVALID_CASE,
ERRR_INSUFFICIENT_MEMORY,
EERR_INVALID_PREPROCESSOR, EERR_INVALID_PREPROCESSOR,
}; };

View File

@ -64,6 +64,7 @@ LinkerRegion* Linker::AddRegion(const Ident* region, int start, int end)
LinkerRegion* lrgn = new LinkerRegion(); LinkerRegion* lrgn = new LinkerRegion();
lrgn->mIdent = region; lrgn->mIdent = region;
lrgn->mStart = start; lrgn->mStart = start;
lrgn->mReloc = 0;
lrgn->mEnd = end; lrgn->mEnd = end;
lrgn->mUsed = 0; lrgn->mUsed = 0;
lrgn->mNonzero = 0; lrgn->mNonzero = 0;
@ -188,6 +189,7 @@ bool LinkerRegion::Allocate(LinkerObject* lobj)
{ {
lobj->mFlags |= LOBJF_PLACED; lobj->mFlags |= LOBJF_PLACED;
lobj->mAddress = start; lobj->mAddress = start;
lobj->mRefAddress = start + mReloc;
lobj->mRegion = this; lobj->mRegion = this;
if (start == mFreeChunks[i].mStart) if (start == mFreeChunks[i].mStart)
@ -219,6 +221,7 @@ bool LinkerRegion::Allocate(LinkerObject* lobj)
{ {
lobj->mFlags |= LOBJF_PLACED; lobj->mFlags |= LOBJF_PLACED;
lobj->mAddress = start; lobj->mAddress = start;
lobj->mRefAddress = start + mReloc;
lobj->mRegion = this; lobj->mRegion = this;
#if 1 #if 1
if (start != mStart + mUsed) if (start != mStart + mUsed)
@ -330,12 +333,20 @@ void Linker::Link(void)
{ {
LinkerObject* obj = mObjects[i]; LinkerObject* obj = mObjects[i];
if (obj->mType == LOT_SECTION_START) if (obj->mType == LOT_SECTION_START)
{
obj->mAddress = obj->mSection->mStart; obj->mAddress = obj->mSection->mStart;
obj->mRefAddress = obj->mAddress + obj->mRegion->mReloc;
}
else if (obj->mType == LOT_SECTION_END) else if (obj->mType == LOT_SECTION_END)
{
obj->mAddress = obj->mSection->mEnd; obj->mAddress = obj->mSection->mEnd;
obj->mRefAddress = obj->mAddress + obj->mRegion->mReloc;
}
else if (obj->mFlags & LOBJF_REFERENCED) else if (obj->mFlags & LOBJF_REFERENCED)
{ {
if (obj->mRegion->mCartridge >= 0) if (!obj->mRegion)
mErrors->Error(obj->mLocation, ERRR_INSUFFICIENT_MEMORY, "Could not place object", obj->mIdent->mString);
else if (obj->mRegion->mCartridge >= 0)
{ {
mCartridgeBankUsed[obj->mRegion->mCartridge] = true; mCartridgeBankUsed[obj->mRegion->mCartridge] = true;
memcpy(mCartridge[obj->mRegion->mCartridge] + obj->mAddress - obj->mRegion->mStart, obj->mData, obj->mSize); memcpy(mCartridge[obj->mRegion->mCartridge] + obj->mAddress - obj->mRegion->mStart, obj->mData, obj->mSize);
@ -352,10 +363,12 @@ void Linker::Link(void)
LinkerReference* ref = mReferences[i]; LinkerReference* ref = mReferences[i];
LinkerObject* obj = ref->mObject; LinkerObject* obj = ref->mObject;
if (obj->mFlags & LOBJF_REFERENCED) if (obj->mFlags & LOBJF_REFERENCED)
{
if (obj->mRegion)
{ {
LinkerObject* robj = ref->mRefObject; LinkerObject* robj = ref->mRefObject;
int raddr = robj->mAddress + ref->mRefOffset; int raddr = robj->mRefAddress + ref->mRefOffset;
uint8* dp; uint8* dp;
if (obj->mRegion->mCartridge < 0) if (obj->mRegion->mCartridge < 0)
@ -372,6 +385,7 @@ void Linker::Link(void)
} }
} }
} }
}
} }
static const char * LinkerObjectTypeNames[] = static const char * LinkerObjectTypeNames[] =

View File

@ -42,7 +42,7 @@ public:
const Ident* mIdent; const Ident* mIdent;
uint32 mFlags; uint32 mFlags;
int mStart, mEnd, mUsed, mNonzero; int mStart, mEnd, mUsed, mNonzero, mReloc;
int mCartridge; int mCartridge;
GrowingArray<LinkerSection*> mSections; GrowingArray<LinkerSection*> mSections;
@ -101,7 +101,7 @@ public:
const Ident * mIdent; const Ident * mIdent;
LinkerObjectType mType; LinkerObjectType mType;
int mID; int mID;
int mAddress; int mAddress, mRefAddress;
int mSize, mAlignment; int mSize, mAlignment;
LinkerSection * mSection; LinkerSection * mSection;
LinkerRegion * mRegion; LinkerRegion * mRegion;

View File

@ -852,7 +852,7 @@ Expression* Parser::ParseInitExpression(Declaration* dtype)
} }
else if (dtype->mType == DT_TYPE_POINTER) else if (dtype->mType == DT_TYPE_POINTER)
{ {
if (exp->mDecValue->mType == DT_CONST_ADDRESS) if (exp->mDecValue->mType == DT_CONST_ADDRESS || exp->mDecValue->mType == DT_CONST_FUNCTION)
; ;
else else
mErrors->Error(mScanner->mLocation, EERR_CONSTANT_INITIALIZER, "Illegal pointer constant initializer"); mErrors->Error(mScanner->mLocation, EERR_CONSTANT_INITIALIZER, "Illegal pointer constant initializer");
@ -3014,6 +3014,20 @@ void Parser::ParsePragma(void)
} }
ConsumeToken(TK_CLOSE_PARENTHESIS); ConsumeToken(TK_CLOSE_PARENTHESIS);
} }
else if (!strcmp(mScanner->mTokenIdent->mString, "stacksize"))
{
mScanner->NextToken();
ConsumeToken(TK_OPEN_PARENTHESIS);
if (mScanner->mToken == TK_INTEGER)
{
mCompilationUnits->mSectionStack->mSize = mScanner->mTokenInteger;
mScanner->NextToken();
}
else
mErrors->Error(mScanner->mLocation, EERR_PRAGMA_PARAMETER, "Stack size expected");
ConsumeToken(TK_CLOSE_PARENTHESIS);
}
else if (!strcmp(mScanner->mTokenIdent->mString, "charmap")) else if (!strcmp(mScanner->mTokenIdent->mString, "charmap"))
{ {
mScanner->NextToken(); mScanner->NextToken();
@ -3136,6 +3150,15 @@ void Parser::ParsePragma(void)
} while (ConsumeTokenIf(TK_COMMA)); } while (ConsumeTokenIf(TK_COMMA));
ConsumeToken(TK_CLOSE_BRACE); ConsumeToken(TK_CLOSE_BRACE);
} }
if (ConsumeTokenIf(TK_COMMA))
{
exp = ParseRExpression();
if (exp->mType == EX_CONSTANT && exp->mDecValue->mType == DT_CONST_INTEGER)
rgn->mReloc = exp->mDecValue->mInteger - rgn->mStart;
else
mErrors->Error(mScanner->mLocation, EERR_PRAGMA_PARAMETER, "Integer number for bank expected");
}
} }
else else
mErrors->Error(mScanner->mLocation, EERR_PRAGMA_PARAMETER, "Region name expected"); mErrors->Error(mScanner->mLocation, EERR_PRAGMA_PARAMETER, "Region name expected");
@ -3272,6 +3295,30 @@ void Parser::ParsePragma(void)
ConsumeToken(TK_CLOSE_PARENTHESIS); ConsumeToken(TK_CLOSE_PARENTHESIS);
} }
else if (!strcmp(mScanner->mTokenIdent->mString, "reference"))
{
mScanner->NextToken();
ConsumeToken(TK_OPEN_PARENTHESIS);
if (mScanner->mToken == TK_IDENT)
{
Declaration* dec = mGlobals->Lookup(mScanner->mTokenIdent);
if (dec && (dec->mType == DT_CONST_FUNCTION || (dec->mType == DT_VARIABLE && (dec->mFlags & DTF_GLOBAL))))
{
mCompilationUnits->AddReferenced(dec);
mScanner->NextToken();
}
else
{
mErrors->Error(mScanner->mLocation, EERR_OBJECT_NOT_FOUND, "Variable not found");
mScanner->NextToken();
}
}
else
mErrors->Error(mScanner->mLocation, EERR_PRAGMA_PARAMETER, "Variable name expected");
ConsumeToken(TK_CLOSE_PARENTHESIS);
}
else else
{ {
mScanner->NextToken(); mScanner->NextToken();

View File

@ -73,7 +73,7 @@ int main(int argc, const char** argv)
#else #else
strcpy(strProductName, "oscar64"); strcpy(strProductName, "oscar64");
strcpy(strProductVersion, "1.2.63"); strcpy(strProductVersion, "1.2.64");
#ifdef __APPLE__ #ifdef __APPLE__
uint32_t length = sizeof(basePath); uint32_t length = sizeof(basePath);

View File

@ -25,8 +25,8 @@ LANGUAGE LANG_ENGLISH, SUBLANG_NEUTRAL
// //
VS_VERSION_INFO VERSIONINFO VS_VERSION_INFO VERSIONINFO
FILEVERSION 1,2,63,0 FILEVERSION 1,2,64,0
PRODUCTVERSION 1,2,63,0 PRODUCTVERSION 1,2,64,0
FILEFLAGSMASK 0x3fL FILEFLAGSMASK 0x3fL
#ifdef _DEBUG #ifdef _DEBUG
FILEFLAGS 0x1L FILEFLAGS 0x1L
@ -43,12 +43,12 @@ BEGIN
BEGIN BEGIN
VALUE "CompanyName", "oscar64" VALUE "CompanyName", "oscar64"
VALUE "FileDescription", "oscar64 compiler" VALUE "FileDescription", "oscar64 compiler"
VALUE "FileVersion", "1.2.63.0" VALUE "FileVersion", "1.2.64.0"
VALUE "InternalName", "oscar64.exe" VALUE "InternalName", "oscar64.exe"
VALUE "LegalCopyright", "Copyright (C) 2021" VALUE "LegalCopyright", "Copyright (C) 2021"
VALUE "OriginalFilename", "oscar64.exe" VALUE "OriginalFilename", "oscar64.exe"
VALUE "ProductName", "oscar64" VALUE "ProductName", "oscar64"
VALUE "ProductVersion", "1.2.63.0" VALUE "ProductVersion", "1.2.64.0"
END END
END END
BLOCK "VarFileInfo" BLOCK "VarFileInfo"

View File

@ -34,12 +34,6 @@
} }
"Entry" "Entry"
{ {
"MsmKey" = "8:_03D7013B0D39A89CEA9D267005ADCE39"
"OwnerKey" = "8:_FB2E467BC172457785F4279BB0BFE8B6"
"MsmSig" = "8:_UNDEFINED"
}
"Entry"
{
"MsmKey" = "8:_05BBBE09BC7047B6AB2F10A2E9032E37" "MsmKey" = "8:_05BBBE09BC7047B6AB2F10A2E9032E37"
"OwnerKey" = "8:_UNDEFINED" "OwnerKey" = "8:_UNDEFINED"
"MsmSig" = "8:_UNDEFINED" "MsmSig" = "8:_UNDEFINED"
@ -130,24 +124,12 @@
} }
"Entry" "Entry"
{ {
"MsmKey" = "8:_326B44043E3720E0A341FB5627DA8873"
"OwnerKey" = "8:_FB2E467BC172457785F4279BB0BFE8B6"
"MsmSig" = "8:_UNDEFINED"
}
"Entry"
{
"MsmKey" = "8:_343F58F80DF84D40AE23457288C5D7D5" "MsmKey" = "8:_343F58F80DF84D40AE23457288C5D7D5"
"OwnerKey" = "8:_UNDEFINED" "OwnerKey" = "8:_UNDEFINED"
"MsmSig" = "8:_UNDEFINED" "MsmSig" = "8:_UNDEFINED"
} }
"Entry" "Entry"
{ {
"MsmKey" = "8:_36B4A1247BFCE001E1BAE7560E9CFEEA"
"OwnerKey" = "8:_FB2E467BC172457785F4279BB0BFE8B6"
"MsmSig" = "8:_UNDEFINED"
}
"Entry"
{
"MsmKey" = "8:_379EE3C17FEC4C5EA79D07668CD05FC4" "MsmKey" = "8:_379EE3C17FEC4C5EA79D07668CD05FC4"
"OwnerKey" = "8:_UNDEFINED" "OwnerKey" = "8:_UNDEFINED"
"MsmSig" = "8:_UNDEFINED" "MsmSig" = "8:_UNDEFINED"
@ -220,12 +202,6 @@
} }
"Entry" "Entry"
{ {
"MsmKey" = "8:_458189403F0009BC49371204B74F3BD3"
"OwnerKey" = "8:_FB2E467BC172457785F4279BB0BFE8B6"
"MsmSig" = "8:_UNDEFINED"
}
"Entry"
{
"MsmKey" = "8:_47A877D439EE429BAB64C52FEF69EDA4" "MsmKey" = "8:_47A877D439EE429BAB64C52FEF69EDA4"
"OwnerKey" = "8:_UNDEFINED" "OwnerKey" = "8:_UNDEFINED"
"MsmSig" = "8:_UNDEFINED" "MsmSig" = "8:_UNDEFINED"
@ -292,12 +268,6 @@
} }
"Entry" "Entry"
{ {
"MsmKey" = "8:_749A2BA18335F50EB53CCE7029861FBC"
"OwnerKey" = "8:_FB2E467BC172457785F4279BB0BFE8B6"
"MsmSig" = "8:_UNDEFINED"
}
"Entry"
{
"MsmKey" = "8:_79985361F09A43299E258E1A8E5ED934" "MsmKey" = "8:_79985361F09A43299E258E1A8E5ED934"
"OwnerKey" = "8:_UNDEFINED" "OwnerKey" = "8:_UNDEFINED"
"MsmSig" = "8:_UNDEFINED" "MsmSig" = "8:_UNDEFINED"
@ -340,8 +310,8 @@
} }
"Entry" "Entry"
{ {
"MsmKey" = "8:_8667075410229C38BF63AC1CC776055E" "MsmKey" = "8:_8827B6B07A1C4B32B08DF784E090381D"
"OwnerKey" = "8:_FB2E467BC172457785F4279BB0BFE8B6" "OwnerKey" = "8:_UNDEFINED"
"MsmSig" = "8:_UNDEFINED" "MsmSig" = "8:_UNDEFINED"
} }
"Entry" "Entry"
@ -412,6 +382,12 @@
} }
"Entry" "Entry"
{ {
"MsmKey" = "8:_A18504BA88CE40128ED44BD1854F0A33"
"OwnerKey" = "8:_UNDEFINED"
"MsmSig" = "8:_UNDEFINED"
}
"Entry"
{
"MsmKey" = "8:_A27837E885F24200AC5CD5D9F8A0C2A4" "MsmKey" = "8:_A27837E885F24200AC5CD5D9F8A0C2A4"
"OwnerKey" = "8:_UNDEFINED" "OwnerKey" = "8:_UNDEFINED"
"MsmSig" = "8:_UNDEFINED" "MsmSig" = "8:_UNDEFINED"
@ -586,12 +562,6 @@
} }
"Entry" "Entry"
{ {
"MsmKey" = "8:_DD5A4DD822437085CD584319732F2D4D"
"OwnerKey" = "8:_FB2E467BC172457785F4279BB0BFE8B6"
"MsmSig" = "8:_UNDEFINED"
}
"Entry"
{
"MsmKey" = "8:_E218D776D9014F99BE2B046AEF2D6E8B" "MsmKey" = "8:_E218D776D9014F99BE2B046AEF2D6E8B"
"OwnerKey" = "8:_UNDEFINED" "OwnerKey" = "8:_UNDEFINED"
"MsmSig" = "8:_UNDEFINED" "MsmSig" = "8:_UNDEFINED"
@ -646,12 +616,6 @@
} }
"Entry" "Entry"
{ {
"MsmKey" = "8:_EA3C0BCB01F2639DFA2E37EC8436E5F6"
"OwnerKey" = "8:_FB2E467BC172457785F4279BB0BFE8B6"
"MsmSig" = "8:_UNDEFINED"
}
"Entry"
{
"MsmKey" = "8:_ED872D39D58443D590B7C80604BC0FF4" "MsmKey" = "8:_ED872D39D58443D590B7C80604BC0FF4"
"OwnerKey" = "8:_UNDEFINED" "OwnerKey" = "8:_UNDEFINED"
"MsmSig" = "8:_UNDEFINED" "MsmSig" = "8:_UNDEFINED"
@ -676,12 +640,6 @@
} }
"Entry" "Entry"
{ {
"MsmKey" = "8:_F20F5618C7576D758C01D89C87469AF8"
"OwnerKey" = "8:_FB2E467BC172457785F4279BB0BFE8B6"
"MsmSig" = "8:_UNDEFINED"
}
"Entry"
{
"MsmKey" = "8:_F35970F9D8FA46B09F36D7E9DE5532CA" "MsmKey" = "8:_F35970F9D8FA46B09F36D7E9DE5532CA"
"OwnerKey" = "8:_UNDEFINED" "OwnerKey" = "8:_UNDEFINED"
"MsmSig" = "8:_UNDEFINED" "MsmSig" = "8:_UNDEFINED"
@ -857,26 +815,6 @@
"IsDependency" = "11:FALSE" "IsDependency" = "11:FALSE"
"IsolateTo" = "8:" "IsolateTo" = "8:"
} }
"{1FB2D0AE-D3B9-43D4-B9DD-F88EC61E35DE}:_03D7013B0D39A89CEA9D267005ADCE39"
{
"SourcePath" = "8:VCRUNTIME140.dll"
"TargetName" = "8:VCRUNTIME140.dll"
"Tag" = "8:"
"Folder" = "8:_607E75AF0E2A4CB9908C4C39DF8FE6E4"
"Condition" = "8:"
"Transitive" = "11:FALSE"
"Vital" = "11:TRUE"
"ReadOnly" = "11:FALSE"
"Hidden" = "11:FALSE"
"System" = "11:FALSE"
"Permanent" = "11:FALSE"
"SharedLegacy" = "11:FALSE"
"PackageAs" = "3:1"
"Register" = "3:1"
"Exclude" = "11:FALSE"
"IsDependency" = "11:TRUE"
"IsolateTo" = "8:"
}
"{1FB2D0AE-D3B9-43D4-B9DD-F88EC61E35DE}:_05BBBE09BC7047B6AB2F10A2E9032E37" "{1FB2D0AE-D3B9-43D4-B9DD-F88EC61E35DE}:_05BBBE09BC7047B6AB2F10A2E9032E37"
{ {
"SourcePath" = "8:..\\samples\\kernalio\\hiresread.c" "SourcePath" = "8:..\\samples\\kernalio\\hiresread.c"
@ -1177,26 +1115,6 @@
"IsDependency" = "11:FALSE" "IsDependency" = "11:FALSE"
"IsolateTo" = "8:" "IsolateTo" = "8:"
} }
"{1FB2D0AE-D3B9-43D4-B9DD-F88EC61E35DE}:_326B44043E3720E0A341FB5627DA8873"
{
"SourcePath" = "8:api-ms-win-crt-stdio-l1-1-0.dll"
"TargetName" = "8:api-ms-win-crt-stdio-l1-1-0.dll"
"Tag" = "8:"
"Folder" = "8:_607E75AF0E2A4CB9908C4C39DF8FE6E4"
"Condition" = "8:"
"Transitive" = "11:FALSE"
"Vital" = "11:TRUE"
"ReadOnly" = "11:FALSE"
"Hidden" = "11:FALSE"
"System" = "11:FALSE"
"Permanent" = "11:FALSE"
"SharedLegacy" = "11:FALSE"
"PackageAs" = "3:1"
"Register" = "3:1"
"Exclude" = "11:FALSE"
"IsDependency" = "11:TRUE"
"IsolateTo" = "8:"
}
"{1FB2D0AE-D3B9-43D4-B9DD-F88EC61E35DE}:_343F58F80DF84D40AE23457288C5D7D5" "{1FB2D0AE-D3B9-43D4-B9DD-F88EC61E35DE}:_343F58F80DF84D40AE23457288C5D7D5"
{ {
"SourcePath" = "8:..\\include\\c64\\keyboard.c" "SourcePath" = "8:..\\include\\c64\\keyboard.c"
@ -1217,26 +1135,6 @@
"IsDependency" = "11:FALSE" "IsDependency" = "11:FALSE"
"IsolateTo" = "8:" "IsolateTo" = "8:"
} }
"{1FB2D0AE-D3B9-43D4-B9DD-F88EC61E35DE}:_36B4A1247BFCE001E1BAE7560E9CFEEA"
{
"SourcePath" = "8:api-ms-win-crt-math-l1-1-0.dll"
"TargetName" = "8:api-ms-win-crt-math-l1-1-0.dll"
"Tag" = "8:"
"Folder" = "8:_607E75AF0E2A4CB9908C4C39DF8FE6E4"
"Condition" = "8:"
"Transitive" = "11:FALSE"
"Vital" = "11:TRUE"
"ReadOnly" = "11:FALSE"
"Hidden" = "11:FALSE"
"System" = "11:FALSE"
"Permanent" = "11:FALSE"
"SharedLegacy" = "11:FALSE"
"PackageAs" = "3:1"
"Register" = "3:1"
"Exclude" = "11:FALSE"
"IsDependency" = "11:TRUE"
"IsolateTo" = "8:"
}
"{1FB2D0AE-D3B9-43D4-B9DD-F88EC61E35DE}:_379EE3C17FEC4C5EA79D07668CD05FC4" "{1FB2D0AE-D3B9-43D4-B9DD-F88EC61E35DE}:_379EE3C17FEC4C5EA79D07668CD05FC4"
{ {
"SourcePath" = "8:..\\samples\\memmap\\easyflash.c" "SourcePath" = "8:..\\samples\\memmap\\easyflash.c"
@ -1477,26 +1375,6 @@
"IsDependency" = "11:FALSE" "IsDependency" = "11:FALSE"
"IsolateTo" = "8:" "IsolateTo" = "8:"
} }
"{1FB2D0AE-D3B9-43D4-B9DD-F88EC61E35DE}:_458189403F0009BC49371204B74F3BD3"
{
"SourcePath" = "8:api-ms-win-crt-string-l1-1-0.dll"
"TargetName" = "8:api-ms-win-crt-string-l1-1-0.dll"
"Tag" = "8:"
"Folder" = "8:_607E75AF0E2A4CB9908C4C39DF8FE6E4"
"Condition" = "8:"
"Transitive" = "11:FALSE"
"Vital" = "11:TRUE"
"ReadOnly" = "11:FALSE"
"Hidden" = "11:FALSE"
"System" = "11:FALSE"
"Permanent" = "11:FALSE"
"SharedLegacy" = "11:FALSE"
"PackageAs" = "3:1"
"Register" = "3:1"
"Exclude" = "11:FALSE"
"IsDependency" = "11:TRUE"
"IsolateTo" = "8:"
}
"{1FB2D0AE-D3B9-43D4-B9DD-F88EC61E35DE}:_47A877D439EE429BAB64C52FEF69EDA4" "{1FB2D0AE-D3B9-43D4-B9DD-F88EC61E35DE}:_47A877D439EE429BAB64C52FEF69EDA4"
{ {
"SourcePath" = "8:..\\samples\\memmap\\largemem.c" "SourcePath" = "8:..\\samples\\memmap\\largemem.c"
@ -1717,26 +1595,6 @@
"IsDependency" = "11:FALSE" "IsDependency" = "11:FALSE"
"IsolateTo" = "8:" "IsolateTo" = "8:"
} }
"{1FB2D0AE-D3B9-43D4-B9DD-F88EC61E35DE}:_749A2BA18335F50EB53CCE7029861FBC"
{
"SourcePath" = "8:api-ms-win-crt-runtime-l1-1-0.dll"
"TargetName" = "8:api-ms-win-crt-runtime-l1-1-0.dll"
"Tag" = "8:"
"Folder" = "8:_607E75AF0E2A4CB9908C4C39DF8FE6E4"
"Condition" = "8:"
"Transitive" = "11:FALSE"
"Vital" = "11:TRUE"
"ReadOnly" = "11:FALSE"
"Hidden" = "11:FALSE"
"System" = "11:FALSE"
"Permanent" = "11:FALSE"
"SharedLegacy" = "11:FALSE"
"PackageAs" = "3:1"
"Register" = "3:1"
"Exclude" = "11:FALSE"
"IsDependency" = "11:TRUE"
"IsolateTo" = "8:"
}
"{1FB2D0AE-D3B9-43D4-B9DD-F88EC61E35DE}:_79985361F09A43299E258E1A8E5ED934" "{1FB2D0AE-D3B9-43D4-B9DD-F88EC61E35DE}:_79985361F09A43299E258E1A8E5ED934"
{ {
"SourcePath" = "8:..\\include\\gfx\\mcbitmap.c" "SourcePath" = "8:..\\include\\gfx\\mcbitmap.c"
@ -1877,12 +1735,12 @@
"IsDependency" = "11:FALSE" "IsDependency" = "11:FALSE"
"IsolateTo" = "8:" "IsolateTo" = "8:"
} }
"{1FB2D0AE-D3B9-43D4-B9DD-F88EC61E35DE}:_8667075410229C38BF63AC1CC776055E" "{1FB2D0AE-D3B9-43D4-B9DD-F88EC61E35DE}:_8827B6B07A1C4B32B08DF784E090381D"
{ {
"SourcePath" = "8:api-ms-win-crt-filesystem-l1-1-0.dll" "SourcePath" = "8:..\\samples\\memmap\\tsr.c"
"TargetName" = "8:api-ms-win-crt-filesystem-l1-1-0.dll" "TargetName" = "8:tsr.c"
"Tag" = "8:" "Tag" = "8:"
"Folder" = "8:_607E75AF0E2A4CB9908C4C39DF8FE6E4" "Folder" = "8:_A62A71A6A08941C5964B90112D87731F"
"Condition" = "8:" "Condition" = "8:"
"Transitive" = "11:FALSE" "Transitive" = "11:FALSE"
"Vital" = "11:TRUE" "Vital" = "11:TRUE"
@ -1894,7 +1752,7 @@
"PackageAs" = "3:1" "PackageAs" = "3:1"
"Register" = "3:1" "Register" = "3:1"
"Exclude" = "11:FALSE" "Exclude" = "11:FALSE"
"IsDependency" = "11:TRUE" "IsDependency" = "11:FALSE"
"IsolateTo" = "8:" "IsolateTo" = "8:"
} }
"{1FB2D0AE-D3B9-43D4-B9DD-F88EC61E35DE}:_89C3C9640CD142CCB3192AF3B15FC771" "{1FB2D0AE-D3B9-43D4-B9DD-F88EC61E35DE}:_89C3C9640CD142CCB3192AF3B15FC771"
@ -2117,6 +1975,26 @@
"IsDependency" = "11:FALSE" "IsDependency" = "11:FALSE"
"IsolateTo" = "8:" "IsolateTo" = "8:"
} }
"{1FB2D0AE-D3B9-43D4-B9DD-F88EC61E35DE}:_A18504BA88CE40128ED44BD1854F0A33"
{
"SourcePath" = "8:..\\samples\\memmap\\easyflashreloc.c"
"TargetName" = "8:easyflashreloc.c"
"Tag" = "8:"
"Folder" = "8:_A62A71A6A08941C5964B90112D87731F"
"Condition" = "8:"
"Transitive" = "11:FALSE"
"Vital" = "11:TRUE"
"ReadOnly" = "11:FALSE"
"Hidden" = "11:FALSE"
"System" = "11:FALSE"
"Permanent" = "11:FALSE"
"SharedLegacy" = "11:FALSE"
"PackageAs" = "3:1"
"Register" = "3:1"
"Exclude" = "11:FALSE"
"IsDependency" = "11:FALSE"
"IsolateTo" = "8:"
}
"{1FB2D0AE-D3B9-43D4-B9DD-F88EC61E35DE}:_A27837E885F24200AC5CD5D9F8A0C2A4" "{1FB2D0AE-D3B9-43D4-B9DD-F88EC61E35DE}:_A27837E885F24200AC5CD5D9F8A0C2A4"
{ {
"SourcePath" = "8:..\\include\\conio.c" "SourcePath" = "8:..\\include\\conio.c"
@ -2697,26 +2575,6 @@
"IsDependency" = "11:FALSE" "IsDependency" = "11:FALSE"
"IsolateTo" = "8:" "IsolateTo" = "8:"
} }
"{1FB2D0AE-D3B9-43D4-B9DD-F88EC61E35DE}:_DD5A4DD822437085CD584319732F2D4D"
{
"SourcePath" = "8:api-ms-win-crt-heap-l1-1-0.dll"
"TargetName" = "8:api-ms-win-crt-heap-l1-1-0.dll"
"Tag" = "8:"
"Folder" = "8:_607E75AF0E2A4CB9908C4C39DF8FE6E4"
"Condition" = "8:"
"Transitive" = "11:FALSE"
"Vital" = "11:TRUE"
"ReadOnly" = "11:FALSE"
"Hidden" = "11:FALSE"
"System" = "11:FALSE"
"Permanent" = "11:FALSE"
"SharedLegacy" = "11:FALSE"
"PackageAs" = "3:1"
"Register" = "3:1"
"Exclude" = "11:FALSE"
"IsDependency" = "11:TRUE"
"IsolateTo" = "8:"
}
"{1FB2D0AE-D3B9-43D4-B9DD-F88EC61E35DE}:_E218D776D9014F99BE2B046AEF2D6E8B" "{1FB2D0AE-D3B9-43D4-B9DD-F88EC61E35DE}:_E218D776D9014F99BE2B046AEF2D6E8B"
{ {
"SourcePath" = "8:..\\include\\stdlib.c" "SourcePath" = "8:..\\include\\stdlib.c"
@ -2897,26 +2755,6 @@
"IsDependency" = "11:FALSE" "IsDependency" = "11:FALSE"
"IsolateTo" = "8:" "IsolateTo" = "8:"
} }
"{1FB2D0AE-D3B9-43D4-B9DD-F88EC61E35DE}:_EA3C0BCB01F2639DFA2E37EC8436E5F6"
{
"SourcePath" = "8:VERSION.dll"
"TargetName" = "8:VERSION.dll"
"Tag" = "8:"
"Folder" = "8:_607E75AF0E2A4CB9908C4C39DF8FE6E4"
"Condition" = "8:"
"Transitive" = "11:FALSE"
"Vital" = "11:TRUE"
"ReadOnly" = "11:FALSE"
"Hidden" = "11:FALSE"
"System" = "11:FALSE"
"Permanent" = "11:FALSE"
"SharedLegacy" = "11:FALSE"
"PackageAs" = "3:1"
"Register" = "3:1"
"Exclude" = "11:FALSE"
"IsDependency" = "11:TRUE"
"IsolateTo" = "8:"
}
"{1FB2D0AE-D3B9-43D4-B9DD-F88EC61E35DE}:_ED872D39D58443D590B7C80604BC0FF4" "{1FB2D0AE-D3B9-43D4-B9DD-F88EC61E35DE}:_ED872D39D58443D590B7C80604BC0FF4"
{ {
"SourcePath" = "8:..\\samples\\kernalio\\fileread.c" "SourcePath" = "8:..\\samples\\kernalio\\fileread.c"
@ -2997,26 +2835,6 @@
"IsDependency" = "11:FALSE" "IsDependency" = "11:FALSE"
"IsolateTo" = "8:" "IsolateTo" = "8:"
} }
"{1FB2D0AE-D3B9-43D4-B9DD-F88EC61E35DE}:_F20F5618C7576D758C01D89C87469AF8"
{
"SourcePath" = "8:api-ms-win-crt-locale-l1-1-0.dll"
"TargetName" = "8:api-ms-win-crt-locale-l1-1-0.dll"
"Tag" = "8:"
"Folder" = "8:_607E75AF0E2A4CB9908C4C39DF8FE6E4"
"Condition" = "8:"
"Transitive" = "11:FALSE"
"Vital" = "11:TRUE"
"ReadOnly" = "11:FALSE"
"Hidden" = "11:FALSE"
"System" = "11:FALSE"
"Permanent" = "11:FALSE"
"SharedLegacy" = "11:FALSE"
"PackageAs" = "3:1"
"Register" = "3:1"
"Exclude" = "11:FALSE"
"IsDependency" = "11:TRUE"
"IsolateTo" = "8:"
}
"{1FB2D0AE-D3B9-43D4-B9DD-F88EC61E35DE}:_F35970F9D8FA46B09F36D7E9DE5532CA" "{1FB2D0AE-D3B9-43D4-B9DD-F88EC61E35DE}:_F35970F9D8FA46B09F36D7E9DE5532CA"
{ {
"SourcePath" = "8:..\\include\\c64\\charwin.h" "SourcePath" = "8:..\\include\\c64\\charwin.h"
@ -3351,15 +3169,15 @@
{ {
"Name" = "8:Microsoft Visual Studio" "Name" = "8:Microsoft Visual Studio"
"ProductName" = "8:oscar64" "ProductName" = "8:oscar64"
"ProductCode" = "8:{EB9870E9-BC61-4218-8C98-A107F7A56458}" "ProductCode" = "8:{1260D4CA-BF60-4790-8BCD-CBF821D925A6}"
"PackageCode" = "8:{D6A2DECC-DBEF-487B-8DC2-3FD3E7A8771F}" "PackageCode" = "8:{D10B71B9-5CF7-4BB4-818F-66EE5EC3965C}"
"UpgradeCode" = "8:{9AB61EFF-ACAC-4079-9950-8D96615CD4EF}" "UpgradeCode" = "8:{9AB61EFF-ACAC-4079-9950-8D96615CD4EF}"
"AspNetVersion" = "8:2.0.50727.0" "AspNetVersion" = "8:2.0.50727.0"
"RestartWWWService" = "11:FALSE" "RestartWWWService" = "11:FALSE"
"RemovePreviousVersions" = "11:TRUE" "RemovePreviousVersions" = "11:TRUE"
"DetectNewerInstalledVersion" = "11:TRUE" "DetectNewerInstalledVersion" = "11:TRUE"
"InstallAllUsers" = "11:FALSE" "InstallAllUsers" = "11:FALSE"
"ProductVersion" = "8:1.2.63" "ProductVersion" = "8:1.2.64"
"Manufacturer" = "8:oscar64" "Manufacturer" = "8:oscar64"
"ARPHELPTELEPHONE" = "8:" "ARPHELPTELEPHONE" = "8:"
"ARPHELPLINK" = "8:" "ARPHELPLINK" = "8:"

View File

@ -5,3 +5,5 @@
../../bin/oscar64 charsethi.c ../../bin/oscar64 charsethi.c
../../bin/oscar64 charsetcopy.c ../../bin/oscar64 charsetcopy.c
../../bin/oscar64 easyflash.c -n -tf=crt ../../bin/oscar64 easyflash.c -n -tf=crt
../../bin/oscar64 easyflashreloc.c -n -tf=crt
../../bin/oscar64 tsr.c -n -dNOFLOAT -dNOLONG

Binary file not shown.

View File

@ -0,0 +1,231 @@
#include <c64/memmap.h>
#include <c64/charwin.h>
#include <c64/cia.h>
#include <c64/vic.h>
#include <c64/easyflash.h>
#include <string.h>
// Shared code/data region, copied from easyflash bank 0 to ram during startup
#pragma region( main, 0x0900, 0x8000, , , { code, data, bss, heap, stack } )
// Section and region for first easyflash bank, code is compiled for a
// target address of 0x7000 but placed into the bank at 0x8000
// The data section is first to ensure the jump table is at the start
// address
#pragma section( bcode1, 0 )
#pragma section( bdata1, 0 )
#pragma region(bank1, 0x8000, 0x9000, , 1, { bdata1, bcode1 }, 0x7000 )
// Section and region for second easyflash bank
#pragma section( bcode2, 0 )
#pragma section( bdata2, 0 )
#pragma region(bank2, 0x8000, 0x9000, , 2, { bdata2, bcode2 }, 0x7000 )
#pragma section( bcode3, 0 )
#pragma section( bdata3, 0 )
#pragma region(bank3, 0x8000, 0x9000, , 3, { bdata3, bcode3 }, 0x7000 )
#pragma section( bcode4, 0 )
#pragma section( bdata4, 0 )
#pragma region(bank4, 0x8000, 0x9000, , 4, { bdata4, bcode4 }, 0x7000 )
#pragma section( bcode5, 0 )
#pragma section( bdata5, 0 )
#pragma region(bank5, 0x8000, 0x9000, , 5, { bdata5, bcode5 }, 0x7000 )
#pragma section( bcode6, 0 )
#pragma section( bdata6, 0 )
#pragma region(bank6, 0x8000, 0x9000, , 6, { bdata6, bcode6 } , 0x7000 )
// Charwin in shared memory section
CharWin cw;
struct EntryTable
{
void (*fhello)(void);
void (*fdone)(void);
};
// Now switch code generation to bank 1
#pragma code ( bcode1 )
#pragma data ( bdata1 )
// Print into shared charwin
void print1(void)
{
cwin_put_string(&cw, p"This is first bank", 7);
}
void done1(void)
{
cwin_cursor_newline(&cw);
}
const EntryTable entry1 = {
.fhello = &print1,
.fdone = &done1
}
// make sure the function is referenced
#pragma reference(entry1)
// Now switch code generation to bank 2
#pragma code ( bcode2 )
#pragma data ( bdata2 )
void print2(void)
{
cwin_put_string(&cw, p"This is second bank", 7);
}
void done2(void)
{
cwin_cursor_newline(&cw);
}
const EntryTable entry2 = {
.fhello = &print2,
.fdone = &done2
}
// make sure the function is referenced
#pragma reference(entry2)
#pragma code ( bcode3 )
#pragma data ( bdata3 )
void print3(void)
{
cwin_put_string(&cw, p"This is third bank", 7);
}
void done3(void)
{
cwin_cursor_newline(&cw);
}
const EntryTable entry3 = {
.fhello = &print3,
.fdone = &done3
}
#pragma reference(entry3)
#pragma code ( bcode4 )
#pragma data ( bdata4 )
void print4(void)
{
cwin_put_string(&cw, p"This is fourth bank", 7);
}
void done4(void)
{
cwin_cursor_newline(&cw);
}
const EntryTable entry4 = {
.fhello = &print4,
.fdone = &done4
}
#pragma reference(entry4)
#pragma code ( bcode5 )
#pragma data ( bdata5 )
void print5(void)
{
cwin_put_string(&cw, p"This is fifth bank", 7);
}
void done5(void)
{
cwin_cursor_newline(&cw);
}
const EntryTable entry5 = {
.fhello = &print5,
.fdone = &done5
}
#pragma reference(entry5)
#pragma code ( bcode6 )
#pragma data ( bdata6 )
void print6(void)
{
cwin_put_string(&cw, p"This is sixth bank", 7);
}
void done6(void)
{
cwin_cursor_newline(&cw);
}
const EntryTable entry6 = {
.fhello = &print6,
.fdone = &done6
}
#pragma reference(entry6)
// Switching code generation back to shared section
#pragma code ( code )
#pragma data ( data )
// Copy the data of the rom bank, and call the function
// with the jump table
void callbank(char bank)
{
eflash.bank = bank;
memcpy((char *)0x7000, (char *)0x8000, 0x1000);
// call function at start of copied section
((EntryTable *)0x7000)->fhello();
((EntryTable *)0x7000)->fdone();
}
int main(void)
{
// Enable ROM
mmap_set(MMAP_ROM);
// Init CIAs (no kernal rom was executed so far)
cia_init();
// Init VIC
vic_setmode(VICM_TEXT, (char *)0x0400, (char *)0x1800);
// Prepare output window
cwin_init(&cw, (char *)0x0400, 0, 0, 40, 25);
cwin_clear(&cw);
// Call function in bank 1
callbank(1);
// Switch easyflash ROM region to bank 2
callbank(2);
callbank(3);
callbank(4);
callbank(5);
callbank(6);
// Loop forever
while (true)
;
return 0;
}

View File

@ -4,3 +4,5 @@ call ..\..\bin\oscar64 charsetlo.c
call ..\..\bin\oscar64 charsethi.c call ..\..\bin\oscar64 charsethi.c
call ..\..\bin\oscar64 charsetcopy.c call ..\..\bin\oscar64 charsetcopy.c
call ..\..\bin\oscar64 easyflash.c -n -tf=crt call ..\..\bin\oscar64 easyflash.c -n -tf=crt
call ..\..\bin\oscar64 easyflashreloc.c -n -tf=crt
call ..\..\bin\oscar64 tsr.c -n -dNOFLOAT -dNOLONG

70
samples/memmap/tsr.c Normal file
View File

@ -0,0 +1,70 @@
#include <string.h>
#include <stdio.h>
#include <c64/asm6502.h>
// Invoke resident section with "SYS 49152" from basic
// not much space, so we go with a smaller stack size
#pragma stacksize(256)
// shrink size of startup section
#pragma section(startup, 0);
#pragma region(startup, 0x0801, 0x0860, , , { startup } )
// section for code copy
#pragma section(rcode, 0)
#pragma region(rcode, 0x0860, 0x0900, , , { rcode } )
// main section to stay resident, save three bytes at the
// beginning to have space for an entry jump
#pragma region(main, 0x0903, 0x1900, , , {code, data, bss, heap, stack}, 0xc003 )
// resident entry routine
void tsr(void)
{
// Initialize stack pointer
__asm {
lda #$ff
sta __sp
lda #$cf
sta __sp +1
}
// do something useless
printf(p"Hello World\n");
// and done
}
// Now the copy code section
#pragma code(rcode)
int main(void)
{
// source and target address to copy, no memcpy as it is itself
// not yet copied
char * dp = (char *)0xc000;
char * sp = (char *)0x0903;
// A jmp to the code at the absolute address 0xc000 / 49152
dp += asm_ab(dp, ASM_JMP, (unsigned)tsr);
// then the code
for(unsigned i=0; i<0xffd; i++)
*dp++ = *sp++;
// now we are done
return 0;
}