added -varsgolden to put BSS into Golden Ram at $0400

This commit is contained in:
Irmen de Jong 2023-12-23 20:11:50 +01:00
parent 0e0fac8c4b
commit 9b113c0cbb
17 changed files with 67 additions and 8 deletions

View File

@ -21,6 +21,7 @@ class CompilationOptions(val output: OutputType,
var includeSourcelines: Boolean = false, var includeSourcelines: Boolean = false,
var experimentalCodegen: Boolean = false, var experimentalCodegen: Boolean = false,
var varsHighBank: Int? = null, var varsHighBank: Int? = null,
var varsGolden: Boolean = false,
var splitWordArrays: Boolean = false, var splitWordArrays: Boolean = false,
var breakpointCpuInstruction: Boolean = false, var breakpointCpuInstruction: Boolean = false,
var outputDir: Path = Path(""), var outputDir: Path = Path(""),

View File

@ -16,6 +16,8 @@ interface IMachineDefinition {
val PROGRAM_LOAD_ADDRESS : UInt val PROGRAM_LOAD_ADDRESS : UInt
val BSSHIGHRAM_START: UInt val BSSHIGHRAM_START: UInt
val BSSHIGHRAM_END: UInt val BSSHIGHRAM_END: UInt
val BSSGOLDENRAM_START: UInt
val BSSGOLDENRAM_END: UInt
val cpu: CpuType val cpu: CpuType
var zeropage: Zeropage var zeropage: Zeropage

View File

@ -15,6 +15,8 @@ class AtariMachineDefinition: IMachineDefinition {
override val BSSHIGHRAM_START = 0u // TODO override val BSSHIGHRAM_START = 0u // TODO
override val BSSHIGHRAM_END = 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 zeropage: Zeropage
override lateinit var golden: GoldenRam override lateinit var golden: GoldenRam

View File

@ -17,6 +17,8 @@ class C128MachineDefinition: IMachineDefinition {
override val BSSHIGHRAM_START = 0u // TODO override val BSSHIGHRAM_START = 0u // TODO
override val BSSHIGHRAM_END = 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 zeropage: Zeropage
override lateinit var golden: GoldenRam override lateinit var golden: GoldenRam

View File

@ -18,6 +18,8 @@ class C64MachineDefinition: IMachineDefinition {
override val BSSHIGHRAM_START = 0xc000u override val BSSHIGHRAM_START = 0xc000u
override val BSSHIGHRAM_END = 0xcfffu override val BSSHIGHRAM_END = 0xcfffu
override val BSSGOLDENRAM_START = 0u
override val BSSGOLDENRAM_END = 0u
override lateinit var zeropage: Zeropage override lateinit var zeropage: Zeropage
override lateinit var golden: GoldenRam override lateinit var golden: GoldenRam

View File

@ -17,6 +17,8 @@ class CX16MachineDefinition: IMachineDefinition {
override val BSSHIGHRAM_START = 0xa000u // hiram bank 1, 8Kb, assumed to be active override val BSSHIGHRAM_START = 0xa000u // hiram bank 1, 8Kb, assumed to be active
override val BSSHIGHRAM_END = 0xbfffu // Rom starts at $c000 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 zeropage: Zeropage
override lateinit var golden: GoldenRam override lateinit var golden: GoldenRam

View File

@ -17,6 +17,8 @@ class PETMachineDefinition: IMachineDefinition {
override val BSSHIGHRAM_START = 0u override val BSSHIGHRAM_START = 0u
override val BSSHIGHRAM_END = 0u override val BSSHIGHRAM_END = 0u
override val BSSGOLDENRAM_START = 0u
override val BSSGOLDENRAM_END = 0u
override lateinit var zeropage: Zeropage override lateinit var zeropage: Zeropage
override lateinit var golden: GoldenRam override lateinit var golden: GoldenRam

View File

@ -17,6 +17,8 @@ class VirtualMachineDefinition: IMachineDefinition {
override val BSSHIGHRAM_START = 0u // not actually used override val BSSHIGHRAM_START = 0u // not actually used
override val BSSHIGHRAM_END = 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 zeropage: Zeropage // not actually used
override lateinit var golden: GoldenRam // not actually used override lateinit var golden: GoldenRam // not actually used

View File

@ -173,26 +173,46 @@ internal class ProgramAndVarsGen(
} }
private fun footer() { private fun footer() {
asmgen.out("; bss sections") var relocateBssVars = false
asmgen.out("PROG8_VARSHIGH_RAMBANK = ${options.varsHighBank ?: 1}") var relocatedBssStart = 0u
if(options.varsHighBank!=null) { 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 || if(options.compTarget.machine.BSSHIGHRAM_START == 0u ||
options.compTarget.machine.BSSHIGHRAM_END == 0u || options.compTarget.machine.BSSHIGHRAM_END == 0u ||
options.compTarget.machine.BSSHIGHRAM_END <= options.compTarget.machine.BSSHIGHRAM_START) { 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") 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()) { if(symboltable.allMemorySlabs.isNotEmpty()) {
asmgen.out(" .dsection slabs_BSS") asmgen.out(" .dsection slabs_BSS")
} }
asmgen.out("prog8_program_end\t; end of program label for progend()") 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("prog8_bss_section_start")
asmgen.out(" .dsection BSS") 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") asmgen.out("prog8_bss_section_size = * - prog8_bss_section_start")
} else { } 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("prog8_bss_section_start")
asmgen.out(" .dsection BSS") asmgen.out(" .dsection BSS")
asmgen.out("prog8_bss_section_size = * - prog8_bss_section_start") asmgen.out("prog8_bss_section_size = * - prog8_bss_section_start")

View File

@ -53,6 +53,7 @@ private fun compileMain(args: Array<String>): 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 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 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 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 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) 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<String>): Boolean {
return false 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) { if(startVm==true) {
return runVm(moduleFiles.first()) return runVm(moduleFiles.first())
} }
@ -121,6 +133,7 @@ private fun compileMain(args: Array<String>): Boolean {
includeSourcelines == true, includeSourcelines == true,
experimentalCodegen == true, experimentalCodegen == true,
varsHighBank, varsHighBank,
varsGolden == true,
compilationTarget!!, compilationTarget!!,
splitWordArrays == true, splitWordArrays == true,
breakpointCpuInstruction = false, breakpointCpuInstruction = false,
@ -190,6 +203,7 @@ private fun compileMain(args: Array<String>): Boolean {
includeSourcelines == true, includeSourcelines == true,
experimentalCodegen == true, experimentalCodegen == true,
varsHighBank, varsHighBank,
varsGolden == true,
compilationTarget!!, compilationTarget!!,
splitWordArrays == true, splitWordArrays == true,
breakpointCpuInstruction == true, breakpointCpuInstruction == true,

View File

@ -36,6 +36,7 @@ class CompilerArguments(val filepath: Path,
val includeSourcelines: Boolean, val includeSourcelines: Boolean,
val experimentalCodegen: Boolean, val experimentalCodegen: Boolean,
val varsHighBank: Int?, val varsHighBank: Int?,
val varsGolden: Boolean,
val compilationTarget: String, val compilationTarget: String,
val splitWordArrays: Boolean, val splitWordArrays: Boolean,
val breakpointCpuInstruction: Boolean, val breakpointCpuInstruction: Boolean,
@ -77,6 +78,7 @@ fun compileProgram(args: CompilerArguments): CompilationResult? {
experimentalCodegen = args.experimentalCodegen experimentalCodegen = args.experimentalCodegen
breakpointCpuInstruction = args.breakpointCpuInstruction breakpointCpuInstruction = args.breakpointCpuInstruction
varsHighBank = args.varsHighBank varsHighBank = args.varsHighBank
varsGolden = args.varsGolden
splitWordArrays = args.splitWordArrays splitWordArrays = args.splitWordArrays
outputDir = args.outputDir.normalize() outputDir = args.outputDir.normalize()
symbolDefs = args.symbolDefs symbolDefs = args.symbolDefs

View File

@ -33,6 +33,7 @@ private fun compileTheThing(filepath: Path, optimize: Boolean, target: ICompilat
includeSourcelines = false, includeSourcelines = false,
experimentalCodegen = false, experimentalCodegen = false,
varsHighBank = null, varsHighBank = null,
varsGolden = false,
compilationTarget = target.name, compilationTarget = target.name,
splitWordArrays = false, splitWordArrays = false,
breakpointCpuInstruction = false, breakpointCpuInstruction = false,

View File

@ -31,6 +31,7 @@ class TestCompilerOptionSourcedirs: FunSpec({
includeSourcelines = false, includeSourcelines = false,
experimentalCodegen = false, experimentalCodegen = false,
varsHighBank = null, varsHighBank = null,
varsGolden = false,
compilationTarget = Cx16Target.NAME, compilationTarget = Cx16Target.NAME,
splitWordArrays = false, splitWordArrays = false,
breakpointCpuInstruction = false, breakpointCpuInstruction = false,

View File

@ -30,6 +30,7 @@ internal fun compileFile(
includeSourcelines = false, includeSourcelines = false,
experimentalCodegen = false, experimentalCodegen = false,
varsHighBank = null, varsHighBank = null,
varsGolden = false,
platform.name, platform.name,
symbolDefs = emptyMap(), symbolDefs = emptyMap(),
outputDir = outputDir, outputDir = outputDir,

View File

@ -215,6 +215,11 @@ One or more .p8 module files
(it's called 'BSS' section or Gap at the address mentioned above). (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. 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 Module source code files
------------------------ ------------------------

View File

@ -2,7 +2,6 @@
TODO 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 -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. - 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. 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.

View File

@ -44,6 +44,7 @@ class RequestParser : Take {
splitWordArrays = false, splitWordArrays = false,
breakpointCpuInstruction = false, breakpointCpuInstruction = false,
varsHighBank = null, varsHighBank = null,
varsGolden = false
) )
compileProgram(args) compileProgram(args)
return RsJson(Jsonding()) return RsJson(Jsonding())