From ca93f107c3825be49a11c3eeeda5afd5f34bd870 Mon Sep 17 00:00:00 2001 From: drmortalwombat <90205530+drmortalwombat@users.noreply.github.com> Date: Sat, 22 Jan 2022 18:21:52 +0100 Subject: [PATCH] Add relocated sections --- .gitignore | 1 + include/crt.c | 23 ++- oscar64/CompilationUnits.cpp | 7 +- oscar64/CompilationUnits.h | 4 + oscar64/Compiler.cpp | 22 ++- oscar64/Declaration.cpp | 9 +- oscar64/Errors.h | 1 + oscar64/Linker.cpp | 44 ++++-- oscar64/Linker.h | 4 +- oscar64/Parser.cpp | 51 ++++++- oscar64/oscar64.cpp | 2 +- oscar64/oscar64.rc | 8 +- oscar64setup/oscar64setup.vdproj | 254 +++++-------------------------- samples/memmap/build.sh | 2 + samples/memmap/easyflash.crt | Bin 114976 -> 114976 bytes samples/memmap/easyflashreloc.c | 231 ++++++++++++++++++++++++++++ samples/memmap/make.bat | 2 + samples/memmap/tsr.c | 70 +++++++++ 18 files changed, 476 insertions(+), 259 deletions(-) create mode 100644 samples/memmap/easyflashreloc.c create mode 100644 samples/memmap/tsr.c diff --git a/.gitignore b/.gitignore index 896dfbf..193df86 100644 --- a/.gitignore +++ b/.gitignore @@ -343,3 +343,4 @@ make/oscar64 *.int *.bcs *.crt +*.crt diff --git a/include/crt.c b/include/crt.c index f75e4e2..d5d2c41 100644 --- a/include/crt.c +++ b/include/crt.c @@ -23,17 +23,6 @@ char spentry = 0; int main(void); -__asm inp_exit -{ - lda #$4c - sta $54 - lda #0 - sta $13 - lda #$19 - sta $16 - rts -} - __asm startup { @@ -139,7 +128,6 @@ tyexec: yexec: zexec: exec: - jmp inp_exit #else @@ -178,6 +166,15 @@ bcode: byt >main byt BC_EXIT * 2 #endif + +spexit: + lda #$4c + sta $54 + lda #0 + sta $13 + lda #$19 + sta $16 + rts } #pragma startup(startup) @@ -689,7 +686,7 @@ __asm inp_nop #pragma bytecode(BC_NOP, inp_nop) -#pragma bytecode(BC_EXIT, inp_exit) +#pragma bytecode(BC_EXIT, startup.spexit) __asm inp_jsr { diff --git a/oscar64/CompilationUnits.cpp b/oscar64/CompilationUnits.cpp index e78ab47..60f8e8a 100644 --- a/oscar64/CompilationUnits.cpp +++ b/oscar64/CompilationUnits.cpp @@ -8,7 +8,7 @@ #include CompilationUnits::CompilationUnits(Errors * errors) - : mErrors(errors) + : mErrors(errors), mReferenced(nullptr) { mCompilationUnits = 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) { char filename[200]; diff --git a/oscar64/CompilationUnits.h b/oscar64/CompilationUnits.h index 027ea0f..c5a15e5 100644 --- a/oscar64/CompilationUnits.h +++ b/oscar64/CompilationUnits.h @@ -24,6 +24,7 @@ public: Declaration* mStartup; Declaration* mByteCodes[256]; + GrowingArray mReferenced; DeclarationScope* mRuntimeScope; @@ -32,6 +33,9 @@ public: bool AddUnit(Location & location, const char* name, const char * from); CompilationUnit* PendingUnit(void); + + void AddReferenced(Declaration* ref); + protected: Errors* mErrors; }; diff --git a/oscar64/Compiler.cpp b/oscar64/Compiler.cpp index 038f84d..8a7e75a 100644 --- a/oscar64/Compiler.cpp +++ b/oscar64/Compiler.cpp @@ -177,15 +177,30 @@ bool Compiler::GenerateCode(void) mGlobalAnalyzer->mCompilerOptions = mCompilerOptions; 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->DumpCallGraph(); mInterCodeGenerator->mCompilerOptions = mCompilerOptions; mNativeCodeGenerator->mCompilerOptions = mCompilerOptions; mInterCodeModule->mCompilerOptions = mCompilerOptions; 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) return false; @@ -335,6 +350,9 @@ bool Compiler::GenerateCode(void) if (!(mCompilerOptions & COPT_NATIVE)) mLinker->ReferenceObject(byteCodeObject); + for (int i = 0; i < mCompilationUnits->mReferenced.Size(); i++) + mLinker->ReferenceObject(mCompilationUnits->mReferenced[i]->mLinkerObject); + mLinker->Link(); return mErrors->mErrorCount == 0; diff --git a/oscar64/Declaration.cpp b/oscar64/Declaration.cpp index 10a2670..5708e91 100644 --- a/oscar64/Declaration.cpp +++ b/oscar64/Declaration.cpp @@ -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) diff --git a/oscar64/Errors.h b/oscar64/Errors.h index 4b46761..108600c 100644 --- a/oscar64/Errors.h +++ b/oscar64/Errors.h @@ -53,6 +53,7 @@ enum ErrorID EERR_PRAGMA_PARAMETER, ERRR_PREPROCESSOR, ERRR_INVALID_CASE, + ERRR_INSUFFICIENT_MEMORY, EERR_INVALID_PREPROCESSOR, }; diff --git a/oscar64/Linker.cpp b/oscar64/Linker.cpp index 1752e37..3b9e733 100644 --- a/oscar64/Linker.cpp +++ b/oscar64/Linker.cpp @@ -64,6 +64,7 @@ LinkerRegion* Linker::AddRegion(const Ident* region, int start, int end) LinkerRegion* lrgn = new LinkerRegion(); lrgn->mIdent = region; lrgn->mStart = start; + lrgn->mReloc = 0; lrgn->mEnd = end; lrgn->mUsed = 0; lrgn->mNonzero = 0; @@ -188,6 +189,7 @@ bool LinkerRegion::Allocate(LinkerObject* lobj) { lobj->mFlags |= LOBJF_PLACED; lobj->mAddress = start; + lobj->mRefAddress = start + mReloc; lobj->mRegion = this; if (start == mFreeChunks[i].mStart) @@ -219,6 +221,7 @@ bool LinkerRegion::Allocate(LinkerObject* lobj) { lobj->mFlags |= LOBJF_PLACED; lobj->mAddress = start; + lobj->mRefAddress = start + mReloc; lobj->mRegion = this; #if 1 if (start != mStart + mUsed) @@ -330,12 +333,20 @@ void Linker::Link(void) { LinkerObject* obj = mObjects[i]; if (obj->mType == LOT_SECTION_START) + { obj->mAddress = obj->mSection->mStart; + obj->mRefAddress = obj->mAddress + obj->mRegion->mReloc; + } else if (obj->mType == LOT_SECTION_END) + { obj->mAddress = obj->mSection->mEnd; + obj->mRefAddress = obj->mAddress + obj->mRegion->mReloc; + } 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; memcpy(mCartridge[obj->mRegion->mCartridge] + obj->mAddress - obj->mRegion->mStart, obj->mData, obj->mSize); @@ -353,22 +364,25 @@ void Linker::Link(void) LinkerObject* obj = ref->mObject; if (obj->mFlags & LOBJF_REFERENCED) { - LinkerObject* robj = ref->mRefObject; + if (obj->mRegion) + { + LinkerObject* robj = ref->mRefObject; - int raddr = robj->mAddress + ref->mRefOffset; - uint8* dp; - - if (obj->mRegion->mCartridge < 0) - dp = mMemory + obj->mAddress + ref->mOffset; - else - dp = mCartridge[obj->mRegion->mCartridge] + obj->mAddress - obj->mRegion->mStart + ref->mOffset; + int raddr = robj->mRefAddress + ref->mRefOffset; + uint8* dp; - if (ref->mFlags & LREF_LOWBYTE) - *dp++ = raddr & 0xff; - if (ref->mFlags & LREF_HIGHBYTE) - *dp++ = (raddr >> 8) & 0xff; - if (ref->mFlags & LREF_TEMPORARY) - *dp += obj->mTemporaries[ref->mRefOffset]; + if (obj->mRegion->mCartridge < 0) + dp = mMemory + obj->mAddress + ref->mOffset; + else + dp = mCartridge[obj->mRegion->mCartridge] + obj->mAddress - obj->mRegion->mStart + ref->mOffset; + + if (ref->mFlags & LREF_LOWBYTE) + *dp++ = raddr & 0xff; + if (ref->mFlags & LREF_HIGHBYTE) + *dp++ = (raddr >> 8) & 0xff; + if (ref->mFlags & LREF_TEMPORARY) + *dp += obj->mTemporaries[ref->mRefOffset]; + } } } } diff --git a/oscar64/Linker.h b/oscar64/Linker.h index 93d396f..96577c9 100644 --- a/oscar64/Linker.h +++ b/oscar64/Linker.h @@ -42,7 +42,7 @@ public: const Ident* mIdent; uint32 mFlags; - int mStart, mEnd, mUsed, mNonzero; + int mStart, mEnd, mUsed, mNonzero, mReloc; int mCartridge; GrowingArray mSections; @@ -101,7 +101,7 @@ public: const Ident * mIdent; LinkerObjectType mType; int mID; - int mAddress; + int mAddress, mRefAddress; int mSize, mAlignment; LinkerSection * mSection; LinkerRegion * mRegion; diff --git a/oscar64/Parser.cpp b/oscar64/Parser.cpp index 8f03e31..05dfdb2 100644 --- a/oscar64/Parser.cpp +++ b/oscar64/Parser.cpp @@ -852,7 +852,7 @@ Expression* Parser::ParseInitExpression(Declaration* dtype) } 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 mErrors->Error(mScanner->mLocation, EERR_CONSTANT_INITIALIZER, "Illegal pointer constant initializer"); @@ -3014,7 +3014,21 @@ void Parser::ParsePragma(void) } ConsumeToken(TK_CLOSE_PARENTHESIS); } - else if (!strcmp(mScanner->mTokenIdent->mString, "charmap")) + 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")) { mScanner->NextToken(); ConsumeToken(TK_OPEN_PARENTHESIS); @@ -3136,6 +3150,15 @@ void Parser::ParsePragma(void) } while (ConsumeTokenIf(TK_COMMA)); 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 mErrors->Error(mScanner->mLocation, EERR_PRAGMA_PARAMETER, "Region name expected"); @@ -3272,6 +3295,30 @@ void Parser::ParsePragma(void) 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 { mScanner->NextToken(); diff --git a/oscar64/oscar64.cpp b/oscar64/oscar64.cpp index b60bc74..d4a58fc 100644 --- a/oscar64/oscar64.cpp +++ b/oscar64/oscar64.cpp @@ -73,7 +73,7 @@ int main(int argc, const char** argv) #else strcpy(strProductName, "oscar64"); - strcpy(strProductVersion, "1.2.63"); + strcpy(strProductVersion, "1.2.64"); #ifdef __APPLE__ uint32_t length = sizeof(basePath); diff --git a/oscar64/oscar64.rc b/oscar64/oscar64.rc index 553a43f..dc90564 100644 --- a/oscar64/oscar64.rc +++ b/oscar64/oscar64.rc @@ -25,8 +25,8 @@ LANGUAGE LANG_ENGLISH, SUBLANG_NEUTRAL // VS_VERSION_INFO VERSIONINFO - FILEVERSION 1,2,63,0 - PRODUCTVERSION 1,2,63,0 + FILEVERSION 1,2,64,0 + PRODUCTVERSION 1,2,64,0 FILEFLAGSMASK 0x3fL #ifdef _DEBUG FILEFLAGS 0x1L @@ -43,12 +43,12 @@ BEGIN BEGIN VALUE "CompanyName", "oscar64" VALUE "FileDescription", "oscar64 compiler" - VALUE "FileVersion", "1.2.63.0" + VALUE "FileVersion", "1.2.64.0" VALUE "InternalName", "oscar64.exe" VALUE "LegalCopyright", "Copyright (C) 2021" VALUE "OriginalFilename", "oscar64.exe" VALUE "ProductName", "oscar64" - VALUE "ProductVersion", "1.2.63.0" + VALUE "ProductVersion", "1.2.64.0" END END BLOCK "VarFileInfo" diff --git a/oscar64setup/oscar64setup.vdproj b/oscar64setup/oscar64setup.vdproj index 179140d..55a5ae8 100644 --- a/oscar64setup/oscar64setup.vdproj +++ b/oscar64setup/oscar64setup.vdproj @@ -34,12 +34,6 @@ } "Entry" { - "MsmKey" = "8:_03D7013B0D39A89CEA9D267005ADCE39" - "OwnerKey" = "8:_FB2E467BC172457785F4279BB0BFE8B6" - "MsmSig" = "8:_UNDEFINED" - } - "Entry" - { "MsmKey" = "8:_05BBBE09BC7047B6AB2F10A2E9032E37" "OwnerKey" = "8:_UNDEFINED" "MsmSig" = "8:_UNDEFINED" @@ -130,24 +124,12 @@ } "Entry" { - "MsmKey" = "8:_326B44043E3720E0A341FB5627DA8873" - "OwnerKey" = "8:_FB2E467BC172457785F4279BB0BFE8B6" - "MsmSig" = "8:_UNDEFINED" - } - "Entry" - { "MsmKey" = "8:_343F58F80DF84D40AE23457288C5D7D5" "OwnerKey" = "8:_UNDEFINED" "MsmSig" = "8:_UNDEFINED" } "Entry" { - "MsmKey" = "8:_36B4A1247BFCE001E1BAE7560E9CFEEA" - "OwnerKey" = "8:_FB2E467BC172457785F4279BB0BFE8B6" - "MsmSig" = "8:_UNDEFINED" - } - "Entry" - { "MsmKey" = "8:_379EE3C17FEC4C5EA79D07668CD05FC4" "OwnerKey" = "8:_UNDEFINED" "MsmSig" = "8:_UNDEFINED" @@ -220,12 +202,6 @@ } "Entry" { - "MsmKey" = "8:_458189403F0009BC49371204B74F3BD3" - "OwnerKey" = "8:_FB2E467BC172457785F4279BB0BFE8B6" - "MsmSig" = "8:_UNDEFINED" - } - "Entry" - { "MsmKey" = "8:_47A877D439EE429BAB64C52FEF69EDA4" "OwnerKey" = "8:_UNDEFINED" "MsmSig" = "8:_UNDEFINED" @@ -292,12 +268,6 @@ } "Entry" { - "MsmKey" = "8:_749A2BA18335F50EB53CCE7029861FBC" - "OwnerKey" = "8:_FB2E467BC172457785F4279BB0BFE8B6" - "MsmSig" = "8:_UNDEFINED" - } - "Entry" - { "MsmKey" = "8:_79985361F09A43299E258E1A8E5ED934" "OwnerKey" = "8:_UNDEFINED" "MsmSig" = "8:_UNDEFINED" @@ -340,8 +310,8 @@ } "Entry" { - "MsmKey" = "8:_8667075410229C38BF63AC1CC776055E" - "OwnerKey" = "8:_FB2E467BC172457785F4279BB0BFE8B6" + "MsmKey" = "8:_8827B6B07A1C4B32B08DF784E090381D" + "OwnerKey" = "8:_UNDEFINED" "MsmSig" = "8:_UNDEFINED" } "Entry" @@ -412,6 +382,12 @@ } "Entry" { + "MsmKey" = "8:_A18504BA88CE40128ED44BD1854F0A33" + "OwnerKey" = "8:_UNDEFINED" + "MsmSig" = "8:_UNDEFINED" + } + "Entry" + { "MsmKey" = "8:_A27837E885F24200AC5CD5D9F8A0C2A4" "OwnerKey" = "8:_UNDEFINED" "MsmSig" = "8:_UNDEFINED" @@ -586,12 +562,6 @@ } "Entry" { - "MsmKey" = "8:_DD5A4DD822437085CD584319732F2D4D" - "OwnerKey" = "8:_FB2E467BC172457785F4279BB0BFE8B6" - "MsmSig" = "8:_UNDEFINED" - } - "Entry" - { "MsmKey" = "8:_E218D776D9014F99BE2B046AEF2D6E8B" "OwnerKey" = "8:_UNDEFINED" "MsmSig" = "8:_UNDEFINED" @@ -646,12 +616,6 @@ } "Entry" { - "MsmKey" = "8:_EA3C0BCB01F2639DFA2E37EC8436E5F6" - "OwnerKey" = "8:_FB2E467BC172457785F4279BB0BFE8B6" - "MsmSig" = "8:_UNDEFINED" - } - "Entry" - { "MsmKey" = "8:_ED872D39D58443D590B7C80604BC0FF4" "OwnerKey" = "8:_UNDEFINED" "MsmSig" = "8:_UNDEFINED" @@ -676,12 +640,6 @@ } "Entry" { - "MsmKey" = "8:_F20F5618C7576D758C01D89C87469AF8" - "OwnerKey" = "8:_FB2E467BC172457785F4279BB0BFE8B6" - "MsmSig" = "8:_UNDEFINED" - } - "Entry" - { "MsmKey" = "8:_F35970F9D8FA46B09F36D7E9DE5532CA" "OwnerKey" = "8:_UNDEFINED" "MsmSig" = "8:_UNDEFINED" @@ -857,26 +815,6 @@ "IsDependency" = "11:FALSE" "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" { "SourcePath" = "8:..\\samples\\kernalio\\hiresread.c" @@ -1177,26 +1115,6 @@ "IsDependency" = "11:FALSE" "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" { "SourcePath" = "8:..\\include\\c64\\keyboard.c" @@ -1217,26 +1135,6 @@ "IsDependency" = "11:FALSE" "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" { "SourcePath" = "8:..\\samples\\memmap\\easyflash.c" @@ -1477,26 +1375,6 @@ "IsDependency" = "11:FALSE" "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" { "SourcePath" = "8:..\\samples\\memmap\\largemem.c" @@ -1717,26 +1595,6 @@ "IsDependency" = "11:FALSE" "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" { "SourcePath" = "8:..\\include\\gfx\\mcbitmap.c" @@ -1877,12 +1735,12 @@ "IsDependency" = "11:FALSE" "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" - "TargetName" = "8:api-ms-win-crt-filesystem-l1-1-0.dll" + "SourcePath" = "8:..\\samples\\memmap\\tsr.c" + "TargetName" = "8:tsr.c" "Tag" = "8:" - "Folder" = "8:_607E75AF0E2A4CB9908C4C39DF8FE6E4" + "Folder" = "8:_A62A71A6A08941C5964B90112D87731F" "Condition" = "8:" "Transitive" = "11:FALSE" "Vital" = "11:TRUE" @@ -1894,7 +1752,7 @@ "PackageAs" = "3:1" "Register" = "3:1" "Exclude" = "11:FALSE" - "IsDependency" = "11:TRUE" + "IsDependency" = "11:FALSE" "IsolateTo" = "8:" } "{1FB2D0AE-D3B9-43D4-B9DD-F88EC61E35DE}:_89C3C9640CD142CCB3192AF3B15FC771" @@ -2117,6 +1975,26 @@ "IsDependency" = "11:FALSE" "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" { "SourcePath" = "8:..\\include\\conio.c" @@ -2697,26 +2575,6 @@ "IsDependency" = "11:FALSE" "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" { "SourcePath" = "8:..\\include\\stdlib.c" @@ -2897,26 +2755,6 @@ "IsDependency" = "11:FALSE" "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" { "SourcePath" = "8:..\\samples\\kernalio\\fileread.c" @@ -2997,26 +2835,6 @@ "IsDependency" = "11:FALSE" "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" { "SourcePath" = "8:..\\include\\c64\\charwin.h" @@ -3351,15 +3169,15 @@ { "Name" = "8:Microsoft Visual Studio" "ProductName" = "8:oscar64" - "ProductCode" = "8:{EB9870E9-BC61-4218-8C98-A107F7A56458}" - "PackageCode" = "8:{D6A2DECC-DBEF-487B-8DC2-3FD3E7A8771F}" + "ProductCode" = "8:{1260D4CA-BF60-4790-8BCD-CBF821D925A6}" + "PackageCode" = "8:{D10B71B9-5CF7-4BB4-818F-66EE5EC3965C}" "UpgradeCode" = "8:{9AB61EFF-ACAC-4079-9950-8D96615CD4EF}" "AspNetVersion" = "8:2.0.50727.0" "RestartWWWService" = "11:FALSE" "RemovePreviousVersions" = "11:TRUE" "DetectNewerInstalledVersion" = "11:TRUE" "InstallAllUsers" = "11:FALSE" - "ProductVersion" = "8:1.2.63" + "ProductVersion" = "8:1.2.64" "Manufacturer" = "8:oscar64" "ARPHELPTELEPHONE" = "8:" "ARPHELPLINK" = "8:" diff --git a/samples/memmap/build.sh b/samples/memmap/build.sh index 53813b1..0a15861 100644 --- a/samples/memmap/build.sh +++ b/samples/memmap/build.sh @@ -5,3 +5,5 @@ ../../bin/oscar64 charsethi.c ../../bin/oscar64 charsetcopy.c ../../bin/oscar64 easyflash.c -n -tf=crt +../../bin/oscar64 easyflashreloc.c -n -tf=crt +../../bin/oscar64 tsr.c -n -dNOFLOAT -dNOLONG diff --git a/samples/memmap/easyflash.crt b/samples/memmap/easyflash.crt index 133dcc5ffaf5a2fd2f11f99aac6564a72ba39a9d..74374c17d84e97ca0ce236d44f8375cbdf089754 100644 GIT binary patch delta 651 zcmb8nu}cC`9KiA4d)}SBdL|N-r$YzNsnN+u@PZ1828aFt9fF`XQ3#?;c#vBU8-kWw zqJAwG91#*hHpJ0%v<8iVn^TJrkuC+d+;{knAEy;}TJh6#iom$lYHfdQuUgwty*Xtw zLe<9NiYrazGE+d_=Y!-8f&O8%jl(gIE6txn$>Kth6-kWxq zRY5}8%%A`cSYApmWj#xOj(L?5BY6s>2^JJCMW0D=OJ8yrcMK)ab*K`^eI?NTUDH>> zI-5e*yRbjz4GQG1rYW1{DbT3aLvv)&5GxkddVd;Ou@Fm(Xx$CT$kIYAJ)(7=T^?h4 P2xdgZmX61m@elg}i~Zs_ delta 648 zcmb8pF-yZh7{>AUu1RY2Y6U@>b}(?A96MDlG{s3Nw5T7z#mU)CXiYhA^oWDtl11=! z5>F8^f`gRcRA)h)glwH$0wQf46td(Q{^O6wceB2mJuc+ncdf0p#-@BNNyj80H4FW_a~_$3U(tRUv%VoY20oP>StvO=qjW>b?UNY{)S2_X zXaErZkETh-tN_ro)WvVo`4x?vDL!~ IX8gl`07Qr0<^TWy diff --git a/samples/memmap/easyflashreloc.c b/samples/memmap/easyflashreloc.c new file mode 100644 index 0000000..4f78144 --- /dev/null +++ b/samples/memmap/easyflashreloc.c @@ -0,0 +1,231 @@ +#include +#include +#include +#include +#include +#include + +// 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; +} diff --git a/samples/memmap/make.bat b/samples/memmap/make.bat index 0fc7b41..db12e64 100644 --- a/samples/memmap/make.bat +++ b/samples/memmap/make.bat @@ -4,3 +4,5 @@ call ..\..\bin\oscar64 charsetlo.c call ..\..\bin\oscar64 charsethi.c call ..\..\bin\oscar64 charsetcopy.c call ..\..\bin\oscar64 easyflash.c -n -tf=crt +call ..\..\bin\oscar64 easyflashreloc.c -n -tf=crt +call ..\..\bin\oscar64 tsr.c -n -dNOFLOAT -dNOLONG diff --git a/samples/memmap/tsr.c b/samples/memmap/tsr.c new file mode 100644 index 0000000..2c3a9bf --- /dev/null +++ b/samples/memmap/tsr.c @@ -0,0 +1,70 @@ +#include +#include +#include + +// 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; +}