From 9b113c0cbbb350db9b0125af78bf49fd100f2f30 Mon Sep 17 00:00:00 2001 From: Irmen de Jong Date: Sat, 23 Dec 2023 20:11:50 +0100 Subject: [PATCH] added -varsgolden to put BSS into Golden Ram at $0400 --- .../src/prog8/code/core/CompilationOptions.kt | 1 + .../src/prog8/code/core/IMachineDefinition.kt | 2 ++ .../target/atari/AtariMachineDefinition.kt | 2 ++ .../code/target/c128/C128MachineDefinition.kt | 2 ++ .../code/target/c64/C64MachineDefinition.kt | 2 ++ .../code/target/cx16/CX16MachineDefinition.kt | 2 ++ .../code/target/pet/PETMachineDefinition.kt | 2 ++ .../virtual/VirtualMachineDefinition.kt | 2 ++ .../codegen/cpu6502/ProgramAndVarsGen.kt | 34 +++++++++++++++---- compiler/src/prog8/CompilerMain.kt | 14 ++++++++ compiler/src/prog8/compiler/Compiler.kt | 2 ++ compiler/test/TestCompilerOnExamples.kt | 1 + compiler/test/TestCompilerOptionLibdirs.kt | 1 + compiler/test/helpers/compileXyz.kt | 1 + docs/source/compiling.rst | 5 +++ docs/source/todo.rst | 1 - .../src/prog8/http/TestHttp.kt | 1 + 17 files changed, 67 insertions(+), 8 deletions(-) diff --git a/codeCore/src/prog8/code/core/CompilationOptions.kt b/codeCore/src/prog8/code/core/CompilationOptions.kt index 342fcd384..b81f642ed 100644 --- a/codeCore/src/prog8/code/core/CompilationOptions.kt +++ b/codeCore/src/prog8/code/core/CompilationOptions.kt @@ -21,6 +21,7 @@ class CompilationOptions(val output: OutputType, var includeSourcelines: Boolean = false, var experimentalCodegen: Boolean = false, var varsHighBank: Int? = null, + var varsGolden: Boolean = false, var splitWordArrays: Boolean = false, var breakpointCpuInstruction: Boolean = false, var outputDir: Path = Path(""), diff --git a/codeCore/src/prog8/code/core/IMachineDefinition.kt b/codeCore/src/prog8/code/core/IMachineDefinition.kt index a835f1907..c35ff597f 100644 --- a/codeCore/src/prog8/code/core/IMachineDefinition.kt +++ b/codeCore/src/prog8/code/core/IMachineDefinition.kt @@ -16,6 +16,8 @@ interface IMachineDefinition { val PROGRAM_LOAD_ADDRESS : UInt val BSSHIGHRAM_START: UInt val BSSHIGHRAM_END: UInt + val BSSGOLDENRAM_START: UInt + val BSSGOLDENRAM_END: UInt val cpu: CpuType var zeropage: Zeropage diff --git a/codeCore/src/prog8/code/target/atari/AtariMachineDefinition.kt b/codeCore/src/prog8/code/target/atari/AtariMachineDefinition.kt index 9332b2643..e152dca65 100644 --- a/codeCore/src/prog8/code/target/atari/AtariMachineDefinition.kt +++ b/codeCore/src/prog8/code/target/atari/AtariMachineDefinition.kt @@ -15,6 +15,8 @@ class AtariMachineDefinition: IMachineDefinition { override val BSSHIGHRAM_START = 0u // TODO override val BSSHIGHRAM_END = 0u // TODO + override val BSSGOLDENRAM_START = 0u // TODO + override val BSSGOLDENRAM_END = 0u // TODO override lateinit var zeropage: Zeropage override lateinit var golden: GoldenRam diff --git a/codeCore/src/prog8/code/target/c128/C128MachineDefinition.kt b/codeCore/src/prog8/code/target/c128/C128MachineDefinition.kt index 29d2e4066..1c418e143 100644 --- a/codeCore/src/prog8/code/target/c128/C128MachineDefinition.kt +++ b/codeCore/src/prog8/code/target/c128/C128MachineDefinition.kt @@ -17,6 +17,8 @@ class C128MachineDefinition: IMachineDefinition { override val BSSHIGHRAM_START = 0u // TODO override val BSSHIGHRAM_END = 0u // TODO + override val BSSGOLDENRAM_START = 0u // TODO + override val BSSGOLDENRAM_END = 0u // TODO override lateinit var zeropage: Zeropage override lateinit var golden: GoldenRam diff --git a/codeCore/src/prog8/code/target/c64/C64MachineDefinition.kt b/codeCore/src/prog8/code/target/c64/C64MachineDefinition.kt index 4a8e31e35..b5825e635 100644 --- a/codeCore/src/prog8/code/target/c64/C64MachineDefinition.kt +++ b/codeCore/src/prog8/code/target/c64/C64MachineDefinition.kt @@ -18,6 +18,8 @@ class C64MachineDefinition: IMachineDefinition { override val BSSHIGHRAM_START = 0xc000u override val BSSHIGHRAM_END = 0xcfffu + override val BSSGOLDENRAM_START = 0u + override val BSSGOLDENRAM_END = 0u override lateinit var zeropage: Zeropage override lateinit var golden: GoldenRam diff --git a/codeCore/src/prog8/code/target/cx16/CX16MachineDefinition.kt b/codeCore/src/prog8/code/target/cx16/CX16MachineDefinition.kt index fec9e8498..d208b49cb 100644 --- a/codeCore/src/prog8/code/target/cx16/CX16MachineDefinition.kt +++ b/codeCore/src/prog8/code/target/cx16/CX16MachineDefinition.kt @@ -17,6 +17,8 @@ class CX16MachineDefinition: IMachineDefinition { override val BSSHIGHRAM_START = 0xa000u // hiram bank 1, 8Kb, assumed to be active override val BSSHIGHRAM_END = 0xbfffu // Rom starts at $c000 + override val BSSGOLDENRAM_START = 0x0400u + override val BSSGOLDENRAM_END = 0x07ffu override lateinit var zeropage: Zeropage override lateinit var golden: GoldenRam diff --git a/codeCore/src/prog8/code/target/pet/PETMachineDefinition.kt b/codeCore/src/prog8/code/target/pet/PETMachineDefinition.kt index 469613847..abc0d9ffe 100644 --- a/codeCore/src/prog8/code/target/pet/PETMachineDefinition.kt +++ b/codeCore/src/prog8/code/target/pet/PETMachineDefinition.kt @@ -17,6 +17,8 @@ class PETMachineDefinition: IMachineDefinition { override val BSSHIGHRAM_START = 0u override val BSSHIGHRAM_END = 0u + override val BSSGOLDENRAM_START = 0u + override val BSSGOLDENRAM_END = 0u override lateinit var zeropage: Zeropage override lateinit var golden: GoldenRam diff --git a/codeCore/src/prog8/code/target/virtual/VirtualMachineDefinition.kt b/codeCore/src/prog8/code/target/virtual/VirtualMachineDefinition.kt index 012c1cec2..96a3d2a02 100644 --- a/codeCore/src/prog8/code/target/virtual/VirtualMachineDefinition.kt +++ b/codeCore/src/prog8/code/target/virtual/VirtualMachineDefinition.kt @@ -17,6 +17,8 @@ class VirtualMachineDefinition: IMachineDefinition { override val BSSHIGHRAM_START = 0u // not actually used override val BSSHIGHRAM_END = 0u // not actually used + override val BSSGOLDENRAM_START = 0u // not actually used + override val BSSGOLDENRAM_END = 0u // not actually used override lateinit var zeropage: Zeropage // not actually used override lateinit var golden: GoldenRam // not actually used diff --git a/codeGenCpu6502/src/prog8/codegen/cpu6502/ProgramAndVarsGen.kt b/codeGenCpu6502/src/prog8/codegen/cpu6502/ProgramAndVarsGen.kt index ae8c50925..88779dfad 100644 --- a/codeGenCpu6502/src/prog8/codegen/cpu6502/ProgramAndVarsGen.kt +++ b/codeGenCpu6502/src/prog8/codegen/cpu6502/ProgramAndVarsGen.kt @@ -173,26 +173,46 @@ internal class ProgramAndVarsGen( } private fun footer() { - asmgen.out("; bss sections") - asmgen.out("PROG8_VARSHIGH_RAMBANK = ${options.varsHighBank ?: 1}") - if(options.varsHighBank!=null) { + var relocateBssVars = false + var relocatedBssStart = 0u + var relocatedBssEnd = 0u + + if(options.varsGolden) { + if(options.compTarget.machine.BSSGOLDENRAM_START == 0u || + options.compTarget.machine.BSSGOLDENRAM_END == 0u || + options.compTarget.machine.BSSGOLDENRAM_END <= options.compTarget.machine.BSSGOLDENRAM_START) { + throw AssemblyError("current compilation target hasn't got the golden ram area properly defined or it is simply not available") + } + relocateBssVars = true + relocatedBssStart = options.compTarget.machine.BSSGOLDENRAM_START + relocatedBssEnd = options.compTarget.machine.BSSGOLDENRAM_END + } + else if(options.varsHighBank!=null) { if(options.compTarget.machine.BSSHIGHRAM_START == 0u || options.compTarget.machine.BSSHIGHRAM_END == 0u || options.compTarget.machine.BSSHIGHRAM_END <= options.compTarget.machine.BSSHIGHRAM_START) { throw AssemblyError("current compilation target hasn't got the high ram area properly defined or it is simply not available") } - // BSS vars in high ram area, memory() slabs just concatenated at the end of the program. + relocateBssVars = true + relocatedBssStart = options.compTarget.machine.BSSHIGHRAM_START + relocatedBssEnd = options.compTarget.machine.BSSHIGHRAM_END + } + + asmgen.out("; bss sections") + asmgen.out("PROG8_VARSHIGH_RAMBANK = ${options.varsHighBank ?: 1}") + if(relocateBssVars) { + // BSS vars in another ram area, memory() slabs just concatenated at the end of the program. if(symboltable.allMemorySlabs.isNotEmpty()) { asmgen.out(" .dsection slabs_BSS") } asmgen.out("prog8_program_end\t; end of program label for progend()") - asmgen.out(" * = ${options.compTarget.machine.BSSHIGHRAM_START.toHex()}") + asmgen.out(" * = ${relocatedBssStart.toHex()}") asmgen.out("prog8_bss_section_start") asmgen.out(" .dsection BSS") - asmgen.out(" .cerror * > ${options.compTarget.machine.BSSHIGHRAM_END.toHex()}, \"too many variables for BSS section\"") + asmgen.out(" .cerror * > ${relocatedBssEnd.toHex()}, \"too many variables for BSS section\"") asmgen.out("prog8_bss_section_size = * - prog8_bss_section_start") } else { - // BSS vars followed by memory() slabs, concatenated at the end of the program. + // just append BSS vars followed by memory() slabs, concatenated at the end of the program. asmgen.out("prog8_bss_section_start") asmgen.out(" .dsection BSS") asmgen.out("prog8_bss_section_size = * - prog8_bss_section_start") diff --git a/compiler/src/prog8/CompilerMain.kt b/compiler/src/prog8/CompilerMain.kt index b44cf8f7f..04fe2a5b7 100644 --- a/compiler/src/prog8/CompilerMain.kt +++ b/compiler/src/prog8/CompilerMain.kt @@ -53,6 +53,7 @@ private fun compileMain(args: Array): Boolean { val compilationTarget by cli.option(ArgType.String, fullName = "target", description = "target output of the compiler (one of '${C64Target.NAME}', '${C128Target.NAME}', '${Cx16Target.NAME}', '${AtariTarget.NAME}', '${PETTarget.NAME}', '${VMTarget.NAME}') (required)") val startVm by cli.option(ArgType.Boolean, fullName = "vm", description = "load and run a .p8ir IR source file in the VM") val watchMode by cli.option(ArgType.Boolean, fullName = "watch", description = "continuous compilation mode (watch for file changes)") + val varsGolden by cli.option(ArgType.Boolean, fullName = "varsgolden", description = "put uninitialized variables in 'golden ram' memory area instead of at the end of the program. On the cx16 target this is $0400-07ff. This is unavailable on other systems.") val varsHighBank by cli.option(ArgType.Int, fullName = "varshigh", description = "put uninitialized variables in high memory area instead of at the end of the program. On the cx16 target the value specifies the HiRAM bank to use, on other systems this value is ignored.") val moduleFiles by cli.argument(ArgType.String, fullName = "modules", description = "main module file(s) to compile").multiple(999) @@ -96,6 +97,17 @@ private fun compileMain(args: Array): Boolean { return false } + if (varsGolden==true) { + if (compilationTarget != Cx16Target.NAME) { + System.err.println("Golden Ram is only available on the Commander X16 target.") + return false + } + if (varsHighBank!=null) { + System.err.println("Either use varsgolden or varshigh, not both.") + return false + } + } + if(startVm==true) { return runVm(moduleFiles.first()) } @@ -121,6 +133,7 @@ private fun compileMain(args: Array): Boolean { includeSourcelines == true, experimentalCodegen == true, varsHighBank, + varsGolden == true, compilationTarget!!, splitWordArrays == true, breakpointCpuInstruction = false, @@ -190,6 +203,7 @@ private fun compileMain(args: Array): Boolean { includeSourcelines == true, experimentalCodegen == true, varsHighBank, + varsGolden == true, compilationTarget!!, splitWordArrays == true, breakpointCpuInstruction == true, diff --git a/compiler/src/prog8/compiler/Compiler.kt b/compiler/src/prog8/compiler/Compiler.kt index 4e8041dfa..fa5ea70c6 100644 --- a/compiler/src/prog8/compiler/Compiler.kt +++ b/compiler/src/prog8/compiler/Compiler.kt @@ -36,6 +36,7 @@ class CompilerArguments(val filepath: Path, val includeSourcelines: Boolean, val experimentalCodegen: Boolean, val varsHighBank: Int?, + val varsGolden: Boolean, val compilationTarget: String, val splitWordArrays: Boolean, val breakpointCpuInstruction: Boolean, @@ -77,6 +78,7 @@ fun compileProgram(args: CompilerArguments): CompilationResult? { experimentalCodegen = args.experimentalCodegen breakpointCpuInstruction = args.breakpointCpuInstruction varsHighBank = args.varsHighBank + varsGolden = args.varsGolden splitWordArrays = args.splitWordArrays outputDir = args.outputDir.normalize() symbolDefs = args.symbolDefs diff --git a/compiler/test/TestCompilerOnExamples.kt b/compiler/test/TestCompilerOnExamples.kt index a4c52cb7b..f03c6536b 100644 --- a/compiler/test/TestCompilerOnExamples.kt +++ b/compiler/test/TestCompilerOnExamples.kt @@ -33,6 +33,7 @@ private fun compileTheThing(filepath: Path, optimize: Boolean, target: ICompilat includeSourcelines = false, experimentalCodegen = false, varsHighBank = null, + varsGolden = false, compilationTarget = target.name, splitWordArrays = false, breakpointCpuInstruction = false, diff --git a/compiler/test/TestCompilerOptionLibdirs.kt b/compiler/test/TestCompilerOptionLibdirs.kt index 7337a500b..ec613da6e 100644 --- a/compiler/test/TestCompilerOptionLibdirs.kt +++ b/compiler/test/TestCompilerOptionLibdirs.kt @@ -31,6 +31,7 @@ class TestCompilerOptionSourcedirs: FunSpec({ includeSourcelines = false, experimentalCodegen = false, varsHighBank = null, + varsGolden = false, compilationTarget = Cx16Target.NAME, splitWordArrays = false, breakpointCpuInstruction = false, diff --git a/compiler/test/helpers/compileXyz.kt b/compiler/test/helpers/compileXyz.kt index f55f39e02..b46861de9 100644 --- a/compiler/test/helpers/compileXyz.kt +++ b/compiler/test/helpers/compileXyz.kt @@ -30,6 +30,7 @@ internal fun compileFile( includeSourcelines = false, experimentalCodegen = false, varsHighBank = null, + varsGolden = false, platform.name, symbolDefs = emptyMap(), outputDir = outputDir, diff --git a/docs/source/compiling.rst b/docs/source/compiling.rst index 7b2c77cde..dde1a4ed9 100644 --- a/docs/source/compiling.rst +++ b/docs/source/compiling.rst @@ -215,6 +215,11 @@ One or more .p8 module files (it's called 'BSS' section or Gap at the address mentioned above). Assembling the program will fail if there are too many variables to fit in a single high ram bank. +``-varsgolden`` + Like ``-varshigh``, but places the variables in the $0400-$07FF "golden ram" area instead. + Because this is in normal system memory, there are no bank switching issues. + This mode is only available on the Commander X16. + Module source code files ------------------------ diff --git a/docs/source/todo.rst b/docs/source/todo.rst index ac15710be..28a5a60b5 100644 --- a/docs/source/todo.rst +++ b/docs/source/todo.rst @@ -2,7 +2,6 @@ TODO ==== -- add -varsgold to put BSS vars into golden ram at $0400 (cx16 only) rather than in high memory. Make sure the 64tass .cerror check still works to guard against overflow - add -slabshigh and -slabsgold to also put the memory() slabs into these memory areas (they're now still always part of the prg itself) - add -nowarnunused, or %option ignore_unused (module scope), to suppress all warnings about unused symbols. Useful in libraries. put this in all library code, like %option no_symbol_prefixing, and get rid of the "trick" it uses currently to suppress unused symbol warnings for library modules. diff --git a/httpCompilerService/src/prog8/http/TestHttp.kt b/httpCompilerService/src/prog8/http/TestHttp.kt index a70908c3f..b8e745edb 100644 --- a/httpCompilerService/src/prog8/http/TestHttp.kt +++ b/httpCompilerService/src/prog8/http/TestHttp.kt @@ -44,6 +44,7 @@ class RequestParser : Take { splitWordArrays = false, breakpointCpuInstruction = false, varsHighBank = null, + varsGolden = false ) compileProgram(args) return RsJson(Jsonding())