From 435acccd52b7ca86f62b4514bb4934ef914f7ab6 Mon Sep 17 00:00:00 2001 From: "Tom Ball (MSR)" Date: Tue, 25 Feb 2025 18:37:08 -0800 Subject: [PATCH 1/7] update check --- pxtcompiler/emitter/hexfile.ts | 2 +- pxtlib/emitter/assembler.ts | 14 +++++++------- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/pxtcompiler/emitter/hexfile.ts b/pxtcompiler/emitter/hexfile.ts index 333441581c39..ec2571b98b36 100644 --- a/pxtcompiler/emitter/hexfile.ts +++ b/pxtcompiler/emitter/hexfile.ts @@ -1021,7 +1021,7 @@ ${hexfile.hexPrelude()} src = `; Interface tables: ${bin.itFullEntries}/${bin.itEntries} (${Math.round(100 * bin.itFullEntries / bin.itEntries)}%)\n` + `; Virtual methods: ${bin.numVirtMethods} / ${bin.numMethods}\n` + - b.getSource(!peepDbg, bin.numStmts, target.flashEnd); + b.getSource(!peepDbg, bin.numStmts, target.flashUsableEnd); throwAssemblerErrors(b) diff --git a/pxtlib/emitter/assembler.ts b/pxtlib/emitter/assembler.ts index 6d131354c851..2815c25f4a98 100644 --- a/pxtlib/emitter/assembler.ts +++ b/pxtlib/emitter/assembler.ts @@ -1067,7 +1067,7 @@ namespace ts.pxtc.assembler { return r } - public getSource(clean: boolean, numStmts = 1, flashSize = 0) { + public getSource(clean: boolean, numStmts = 1, flashUsableEnd = 0) { let lenPrev = 0 let size = (lbl: string) => { let curr = this.labels[lbl] || lenPrev @@ -1081,18 +1081,18 @@ namespace ts.pxtc.assembler { let lenVtables = size("_vtables_end") let lenLiterals = size("_literals_end") let lenAllCode = lenPrev - let totalSize = (lenTotal + this.baseOffset) & 0xffffff + let totalEnd = (lenTotal + this.baseOffset - 1) & 0xffffff - if (flashSize && totalSize > flashSize) { - const e = new Error(lf("program too big by {0} bytes!", totalSize - flashSize)); + if (flashUsableEnd && totalEnd >= flashUsableEnd) { + const e = new Error(lf("program too big by {0} bytes!", totalEnd - flashUsableEnd)); (e as any).ksErrorCode = 9283; throw e; } - flashSize = flashSize || 128 * 1024 + flashUsableEnd = flashUsableEnd || 128 * 1024 let totalInfo = lf("; total bytes: {0} ({1}% of {2}k flash with {3} free)", - totalSize, (100 * totalSize / flashSize).toFixed(1), (flashSize / 1024).toFixed(1), - flashSize - totalSize) + totalEnd, (100 * totalEnd / flashUsableEnd).toFixed(1), (flashUsableEnd / 1024).toFixed(1), + flashUsableEnd - totalEnd) let res = // ARM-specific lf("; generated code sizes (bytes): {0} (incl. {1} user, {2} helpers, {3} vtables, {4} lits); src size {5}\n", From 4e71bbccf65799247f31cc30efacc9f9012a768e Mon Sep 17 00:00:00 2001 From: "Tom Ball (MSR)" Date: Thu, 27 Feb 2025 13:24:22 -0800 Subject: [PATCH 2/7] make sure to backstop flashusableend --- pxtcompiler/emitter/hexfile.ts | 4 +++- pxtlib/emitter/assembler.ts | 2 +- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/pxtcompiler/emitter/hexfile.ts b/pxtcompiler/emitter/hexfile.ts index ec2571b98b36..3d9c7fde8627 100644 --- a/pxtcompiler/emitter/hexfile.ts +++ b/pxtcompiler/emitter/hexfile.ts @@ -1019,9 +1019,11 @@ ${hexfile.hexPrelude()} let b = mkProcessorFile(target) b.emit(src); + let flashUsableEnd = target.flashUsableEnd ? target.flashUsableEnd : target.flashEnd + src = `; Interface tables: ${bin.itFullEntries}/${bin.itEntries} (${Math.round(100 * bin.itFullEntries / bin.itEntries)}%)\n` + `; Virtual methods: ${bin.numVirtMethods} / ${bin.numMethods}\n` + - b.getSource(!peepDbg, bin.numStmts, target.flashUsableEnd); + b.getSource(!peepDbg, bin.numStmts, flashUsableEnd); throwAssemblerErrors(b) diff --git a/pxtlib/emitter/assembler.ts b/pxtlib/emitter/assembler.ts index 2815c25f4a98..0b0ad3f4e694 100644 --- a/pxtlib/emitter/assembler.ts +++ b/pxtlib/emitter/assembler.ts @@ -1084,7 +1084,7 @@ namespace ts.pxtc.assembler { let totalEnd = (lenTotal + this.baseOffset - 1) & 0xffffff if (flashUsableEnd && totalEnd >= flashUsableEnd) { - const e = new Error(lf("program too big by {0} bytes!", totalEnd - flashUsableEnd)); + const e = new Error(lf("program too big by {0} bytes!", totalEnd - flashUsableEnd + 1)); (e as any).ksErrorCode = 9283; throw e; } From c97fb560765db0efd054f9dcc6345d6374840626 Mon Sep 17 00:00:00 2001 From: Tom Ball Date: Tue, 4 Mar 2025 09:59:42 -0800 Subject: [PATCH 3/7] off by one --- pxtlib/emitter/assembler.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/pxtlib/emitter/assembler.ts b/pxtlib/emitter/assembler.ts index 0b0ad3f4e694..6de59bc30670 100644 --- a/pxtlib/emitter/assembler.ts +++ b/pxtlib/emitter/assembler.ts @@ -1081,10 +1081,10 @@ namespace ts.pxtc.assembler { let lenVtables = size("_vtables_end") let lenLiterals = size("_literals_end") let lenAllCode = lenPrev - let totalEnd = (lenTotal + this.baseOffset - 1) & 0xffffff + let totalEnd = (lenTotal + this.baseOffset) & 0xffffff - if (flashUsableEnd && totalEnd >= flashUsableEnd) { - const e = new Error(lf("program too big by {0} bytes!", totalEnd - flashUsableEnd + 1)); + if (flashUsableEnd && totalEnd > flashUsableEnd) { + const e = new Error(lf("program too big by {0} bytes!", totalEnd - flashUsableEnd)); (e as any).ksErrorCode = 9283; throw e; } From d6e1cb81f66c88d0f3db879a723f53f4568aff11 Mon Sep 17 00:00:00 2001 From: Tom Ball Date: Wed, 5 Mar 2025 15:24:10 -0800 Subject: [PATCH 4/7] plumb cres through --- pxtcompiler/emitter/hexfile.ts | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/pxtcompiler/emitter/hexfile.ts b/pxtcompiler/emitter/hexfile.ts index 333441581c39..d231e08667e3 100644 --- a/pxtcompiler/emitter/hexfile.ts +++ b/pxtcompiler/emitter/hexfile.ts @@ -1015,10 +1015,15 @@ ${hexfile.hexPrelude()} } let peepDbg = false - export function assemble(target: CompileTarget, bin: Binary, src: string) { + export function assemble(target: CompileTarget, bin: Binary, src: string, cres: CompileResult) { let b = mkProcessorFile(target) b.emit(src); + // TODO: given cres.configData, we can look up to see if either of the following is set + // - CFG_SETTINGS_SIZE_DEFL + // - CFG_SETTINGS_SIZE + // with the second taking priority over the first + src = `; Interface tables: ${bin.itFullEntries}/${bin.itEntries} (${Math.round(100 * bin.itFullEntries / bin.itEntries)}%)\n` + `; Virtual methods: ${bin.numVirtMethods} / ${bin.numMethods}\n` + b.getSource(!peepDbg, bin.numStmts, target.flashEnd); @@ -1127,7 +1132,7 @@ __flash_checksums: } const prefix = opts.extinfo.outputPrefix || "" bin.writeFile(prefix + pxtc.BINARY_ASM, src) - const res = assemble(opts.target, bin, src) + const res = assemble(opts.target, bin, src, cres) if (res.thumbFile.commPtr) bin.commSize = res.thumbFile.commPtr - hexfile.getCommBase() if (res.src) From c65de8b77fe9e527a1ed75754195080edb9d8fd3 Mon Sep 17 00:00:00 2001 From: Tom Ball Date: Fri, 7 Mar 2025 09:30:24 -0800 Subject: [PATCH 5/7] take settings size into account --- pxtcompiler/emitter/hexfile.ts | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/pxtcompiler/emitter/hexfile.ts b/pxtcompiler/emitter/hexfile.ts index ef9141483ce7..61af49971b32 100644 --- a/pxtcompiler/emitter/hexfile.ts +++ b/pxtcompiler/emitter/hexfile.ts @@ -1019,11 +1019,11 @@ ${hexfile.hexPrelude()} let b = mkProcessorFile(target) b.emit(src); - // TODO: given cres.configData, we can look up to see if either of the following is set - // - CFG_SETTINGS_SIZE_DEFL - // - CFG_SETTINGS_SIZE - // with the second taking priority over the first - let flashUsableEnd = target.flashUsableEnd ? target.flashUsableEnd : target.flashEnd + let settingsSizeDefault = cres.configData.find(ce => ce.name === "CFG_SETTINGS_SIZE_DEFL") + let settingsSize = cres.configData.find(ce => ce.name === "CFG_SETTINGS_SIZE") + let actualSettingsSize = settingsSize ? settingsSize.value : settingsSizeDefault ? settingsSizeDefault.value : 0 + + let flashUsableEnd = (target.flashUsableEnd ? target.flashUsableEnd : target.flashEnd) - actualSettingsSize src = `; Interface tables: ${bin.itFullEntries}/${bin.itEntries} (${Math.round(100 * bin.itFullEntries / bin.itEntries)}%)\n` + `; Virtual methods: ${bin.numVirtMethods} / ${bin.numMethods}\n` + From 0b3974e17bdd45f7e376e3967bc6cf6a9c9b8b2b Mon Sep 17 00:00:00 2001 From: Tom Ball Date: Fri, 7 Mar 2025 09:37:21 -0800 Subject: [PATCH 6/7] missed a call --- pxtcompiler/emitter/backvm.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pxtcompiler/emitter/backvm.ts b/pxtcompiler/emitter/backvm.ts index 2b06e2ac4741..1df9c3a83fb7 100644 --- a/pxtcompiler/emitter/backvm.ts +++ b/pxtcompiler/emitter/backvm.ts @@ -340,7 +340,7 @@ _start_${name}: vmsource += "\n; The end.\n" bin.writeFile(BINARY_ASM, vmsource) - let res = assemble(opts.target, bin, vmsource) + let res = assemble(opts.target, bin, vmsource, cres) const srcmap = res.thumbFile.getSourceMap() const encodedSrcMap = encodeSourceMap(srcmap) From 89468f0fb3d28d51f03bc8c01f81725c484cbb6f Mon Sep 17 00:00:00 2001 From: Tom Ball Date: Fri, 7 Mar 2025 11:14:28 -0800 Subject: [PATCH 7/7] remove CFG_ --- pxtcompiler/emitter/hexfile.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pxtcompiler/emitter/hexfile.ts b/pxtcompiler/emitter/hexfile.ts index 61af49971b32..d61990c349e9 100644 --- a/pxtcompiler/emitter/hexfile.ts +++ b/pxtcompiler/emitter/hexfile.ts @@ -1019,8 +1019,8 @@ ${hexfile.hexPrelude()} let b = mkProcessorFile(target) b.emit(src); - let settingsSizeDefault = cres.configData.find(ce => ce.name === "CFG_SETTINGS_SIZE_DEFL") - let settingsSize = cres.configData.find(ce => ce.name === "CFG_SETTINGS_SIZE") + let settingsSizeDefault = cres.configData.find(ce => ce.name === "SETTINGS_SIZE_DEFL") + let settingsSize = cres.configData.find(ce => ce.name === "SETTINGS_SIZE") let actualSettingsSize = settingsSize ? settingsSize.value : settingsSizeDefault ? settingsSizeDefault.value : 0 let flashUsableEnd = (target.flashUsableEnd ? target.flashUsableEnd : target.flashEnd) - actualSettingsSize