From 55b77c84a725b55bdbdb876140354fbeb5cf02bf Mon Sep 17 00:00:00 2001 From: "Rich O." Date: Sun, 1 Nov 2026 21:49:29 -0500 Subject: [PATCH] palm-client: third code section (vmcode3); checker resolves COFF symbol sections visormesh.def adds vmcode3 and sections.h VM_SECT3, ahead of new screens (segment 2 is at 27 KB). check_sections.py checks every extra section, and now maps COFF symbols' (sec N) to section names: before, it only resolved section symbols such as .text, not named ones. sect2.py takes --sect3. --- palm-client/src/sections.h | 7 +- .../check_sections.cpython-311.pyc | Bin 0 -> 5127 bytes palm-client/tools/check_sections.py | 61 +++++++++++------- palm-client/tools/sect2.py | 17 +++-- palm-client/visormesh.def | 2 +- 5 files changed, 56 insertions(+), 31 deletions(-) create mode 100644 palm-client/tools/__pycache__/check_sections.cpython-311.pyc diff --git a/palm-client/src/sections.h b/palm-client/src/sections.h index 84ef48c..debc07a 100644 --- a/palm-client/src/sections.h +++ b/palm-client/src/sections.h @@ -1,7 +1,8 @@ /* * Code segments. The app's code is more than the ~32 KB one 68k code resource - * can reach, so some modules live in a second one (section vmcode2, see - * visormesh.def; multigen makes the stub and linker script). + * can reach, so modules also live in vmcode2 and vmcode3 (VM_SECT2/VM_SECT3; see + * visormesh.def; multigen makes the stub and linker script). Everything below + * applies to any extra section. * * How prc-tools/GCC 2.95 handles it (checked in the compiled objects): * - A function declared VM_SECT2 is placed in vmcode2; callers that see the @@ -28,8 +29,10 @@ #if defined(__palmos__) && !defined(__clang__) /* clang: the editor's checker, which rejects the section name */ #define VM_SECT2 __attribute__ ((section ("vmcode2"))) +#define VM_SECT3 __attribute__ ((section ("vmcode3"))) #else #define VM_SECT2 +#define VM_SECT3 #endif #endif diff --git a/palm-client/tools/__pycache__/check_sections.cpython-311.pyc b/palm-client/tools/__pycache__/check_sections.cpython-311.pyc new file mode 100644 index 0000000000000000000000000000000000000000..7185fb67012d9f4c084384aa8f9cf5615473ad0a GIT binary patch literal 5127 zcma)AT}&L;6~41G%gzqVvcTH>*f9epHEY8X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)6<4`o3GK`S2Fz7EPqw!ufprH{AuuJFz>?a2jMr<=+6Rm z`?GF;hVRMpJv!gB%~!ARsk%?9SE`q*w>hUS9J_yTO}^{9=L0r>XSm~8?zmpO%}6l# z$w}%flaoHda7<3h(ZJ*+eg&K+@9W1XXS%*wB+_$LJ{+iTQDJ)C0*PMQK}!_V|91I- za8!nWWSzz%(8j<+ZUWh18HU;6Tnq<(2BZZsLefe9a;Q!(-Z>;B&A;!e+md`vXiYkH zs(7Yu2bIWPH+?OU_C3sr9aJK(AHCe{rGIs{M%s>*8= 2 and parts[0].isdigit(): + names.append(parts[1]) + return names + + def symbols_by_section(objs): """{symbol: section} for symbols defined in the objects.""" where = {} for obj in objs: + names = section_names(obj) out = subprocess.run([OBJDUMP, '-t', obj], capture_output=True, text=True).stdout for line in out.splitlines(): - parts = line.split() - # "00000000 g F vmcode2 00000012 VmSha256" / "00000000 l d .text ..." - if len(parts) >= 4 and parts[-2] != '*UND*' and not line.startswith(obj): - sect = next((p for p in parts if p in ('.text', '.data', '.bss', SECTION)), None) - if sect: - where[parts[-1]] = sect + # COFF: "[ 5](sec 1)(fl 0x00)(ty 0)(scl 6) (nx 0) 0x00000000 MaxTop" + m = re.search(r'\(sec\s+(-?\d+)\).*\s(\S+)$', line) + if not m: + continue + sec = int(m.group(1)) + if 1 <= sec <= len(names) and names[sec - 1] in ('.text', '.data', '.bss') + SECTIONS: + where.setdefault(m.group(2), names[sec - 1]) return where @@ -37,19 +53,20 @@ def main(): where = symbols_by_section(objs) bad = [] for obj in objs: - out = subprocess.run([OBJDUMP, '-r', '-j', SECTION, obj], capture_output=True, text=True) - if out.returncode != 0: # no vmcode2 section in this object - continue - for line in out.stdout.splitlines(): - parts = line.split() - if len(parts) != 3 or not parts[1].startswith('DISP'): + for section in SECTIONS: + out = subprocess.run([OBJDUMP, '-r', '-j', section, obj], capture_output=True, text=True) + if out.returncode != 0: # no such section in this object continue - target = parts[2].split('+')[0].split('-')[0] - sect = target if target.startswith('.') else where.get(target, SECTION) - if sect != SECTION: - bad.append(f'{obj}: PC-relative {parts[1]} at {parts[0]} to {parts[2]} (in {sect})') + for line in out.stdout.splitlines(): + parts = line.split() + if len(parts) != 3 or not parts[1].startswith('DISP'): + continue + target = parts[2].split('+')[0].split('-')[0] + sect = target if target.startswith('.') or target in SECTIONS else where.get(target, section) + if sect != section: + bad.append(f'{obj}: {section}: PC-relative {parts[1]} at {parts[0]} to {parts[2]} (in {sect})') if bad: - print('Second code segment refers PC-relative outside itself (see src/sections.h):') + print('An extra code segment refers PC-relative outside itself (see src/sections.h):') print('\n'.join(' ' + b for b in bad)) sys.exit(1) print(f'sections OK: {len(objs)} objects checked') diff --git a/palm-client/tools/sect2.py b/palm-client/tools/sect2.py index ae06f73..08e5129 100644 --- a/palm-client/tools/sect2.py +++ b/palm-client/tools/sect2.py @@ -1,18 +1,23 @@ #!/usr/bin/env python3 -"""Puts a C file's static functions in the second code segment: inserts a -'static VM_SECT2;' forward declaration for each one after the -last #include (see src/sections.h). Run once per file moved; idempotent.""" +"""Puts a C file's static functions in an extra code segment: inserts a +'static VM_SECT2;' (or --sect3: VM_SECT3) forward declaration for +each one after the last #include (see src/sections.h). Run once per file +moved; idempotent.""" import re import sys -for path in sys.argv[1:]: +macro = 'VM_SECT3' if '--sect3' in sys.argv else 'VM_SECT2' +for path in [a for a in sys.argv[1:] if not a.startswith('--')]: src = open(path).read() - marker = '/* In the second code segment: see sections.h for the rules. */' + marker = '/* In an extra code segment (' + macro + '): see sections.h for the rules. */' + if 'code segment: see sections.h' in src or 'code segment (VM_SECT' in src: + print(f'{path}: already done') + continue if marker in src: print(f'{path}: already done') continue sigs = re.findall(r'^(static\s+(?!const\s+UInt|UInt8\s+g|Char\s+\*g)[^=;{]*?\w+\s*\([^;{]*?\))\s*\n\{', src, re.M) - decls = '\n'.join(re.sub(r'\s+', ' ', s) + ' VM_SECT2;' for s in sigs) + decls = '\n'.join(re.sub(r'\s+', ' ', s) + ' ' + macro + ';' for s in sigs) last_inc = list(re.finditer(r'^#include .*\n', src, re.M))[-1] src = src[:last_inc.end()] + f'\n{marker}\n{decls}\n' + src[last_inc.end():] open(path, 'w').write(src) diff --git a/palm-client/visormesh.def b/palm-client/visormesh.def index 21ce7dd..1d83d24 100644 --- a/palm-client/visormesh.def +++ b/palm-client/visormesh.def @@ -1,2 +1,2 @@ application { "VisorMesh" VMsh backup } -multiple code { "vmcode2" } +multiple code { "vmcode2" "vmcode3" }