diff --git a/README.md b/README.md index 63f3673..3207d25 100644 --- a/README.md +++ b/README.md @@ -400,7 +400,16 @@ Regions can also be used to place assets such as character sets at fixed locatio The #pragma data(), #pragma code() and #pragma bss() control the placement of the generated objects into sections other than the default sections. +#### Heap and Stack sections +The heap and stack sections have an initial size of 1K and 4K. The heap will grow to use all space between the end of the data/bss section and +the start of the stack section. The size of the stack and the minimum size of the heap can be specified using pragmas: + + #pragma stacksize( 4096 ) + + #pragma heapsize( 4096 ) + +The linker will throw an error if the heap or stack cannot be placed without collision. ### Inline Assembler diff --git a/oscar64/Compiler.cpp b/oscar64/Compiler.cpp index c2f4360..4640789 100644 --- a/oscar64/Compiler.cpp +++ b/oscar64/Compiler.cpp @@ -23,6 +23,7 @@ Compiler::Compiler(void) mCompilationUnits->mSectionStack = mLinker->AddSection(Ident::Unique("stack"), LST_STACK); mCompilationUnits->mSectionZeroPage = mLinker->AddSection(Ident::Unique("zeropage"), LST_ZEROPAGE); mCompilationUnits->mSectionStack->mSize = 4096; + mCompilationUnits->mSectionHeap->mSize = 1024; mPreprocessor = new Preprocessor(mErrors); mByteCodeGenerator = new ByteCodeGenerator(mErrors, mLinker); diff --git a/oscar64/Linker.cpp b/oscar64/Linker.cpp index acaa8f5..185ed88 100644 --- a/oscar64/Linker.cpp +++ b/oscar64/Linker.cpp @@ -392,6 +392,12 @@ void Linker::Link(void) lsec->mEnd = lsec->mStart; lsec->mStart = lrgn->mEnd; + + if (lsec->mStart < lrgn->mStart + lrgn->mUsed) + { + Location loc; + mErrors->Error(loc, ERRR_INSUFFICIENT_MEMORY, "Cannot place stack section"); + } } } } @@ -409,6 +415,12 @@ void Linker::Link(void) { lsec->mStart = lrgn->mStart + lrgn->mUsed; lsec->mEnd = lrgn->mEnd; + + if (lsec->mStart + lsec->mSize > lsec->mEnd) + { + Location loc; + mErrors->Error(loc, ERRR_INSUFFICIENT_MEMORY, "Cannot place heap section"); + } } } } diff --git a/oscar64/Parser.cpp b/oscar64/Parser.cpp index b64bfea..7f1c86a 100644 --- a/oscar64/Parser.cpp +++ b/oscar64/Parser.cpp @@ -3367,6 +3367,20 @@ void Parser::ParsePragma(void) ConsumeToken(TK_CLOSE_PARENTHESIS); } + else if (!strcmp(mScanner->mTokenIdent->mString, "heapsize")) + { + mScanner->NextToken(); + ConsumeToken(TK_OPEN_PARENTHESIS); + if (mScanner->mToken == TK_INTEGER) + { + mCompilationUnits->mSectionHeap->mSize = mScanner->mTokenInteger; + mScanner->NextToken(); + } + else + mErrors->Error(mScanner->mLocation, EERR_PRAGMA_PARAMETER, "Heap size expected"); + + ConsumeToken(TK_CLOSE_PARENTHESIS); + } else if (!strcmp(mScanner->mTokenIdent->mString, "charmap")) { mScanner->NextToken();