Support far/banked memory model for S12/S12X (PPAGE/GPAGE, __far, @address) #1

Open
opened 2026-09-24 09:51:50 +02:00 by sid · 0 comments
Owner

CodeWarrior handles S12/S12X parts larger than 64 KB with its memory model support. This repo's GCC backend cannot address data or code beyond the 64 KB flat space: it has no __far keyword, no @address placement syntax, and no automatic PPAGE (S12) / GPAGE (S12X) banking with linker-generated paged call stubs. This blocks use of large S12X parts, which is the primary reason anyone would reach for a CodeWarrior replacement.

Motivation

  • S12X devices such as the MC9S12XDP512 expose a linear window into paged memory (PPAGE on S12, GPAGE on S12X). CodeWarrior lets a project:
    • place code/data in named segments and automatically route calls/data through the window (__far, @address, #pragma CODE_SEG), and
    • emit trampolines/stubs when a call crosses a page boundary.
  • Without this, only the low 64 KB is usable from C, defeating the purpose of the S12X line and the -m9s12x support this repo already has.

Current state

  • -m68hc11/-m68hc12/-m9s12x ISA flags and multilibs exist (patches/gcc-4.3.6-s12x.patch).
  • -mlong-calls generates call/rtc (far code) and is verified working; patches/gcc-4.3.6-ldivmod-s12x.asm honors __USE_RTC__.
  • Pointers are 16-bit in both -mshort and -mlong; __far is rejected by the compiler (error: '__far' declared as function returning a function).
  • No linker-side banking: no PPAGE/GPAGE window management, no paged call stubs, no far data relocation. -mrelax only affects soft-register direct addressing.

Proposed scope

  • Compiler:
    • Add a __far qualifier and a 32-bit far pointer type.
    • Support @address placement for variables/functions.
    • Emit call/rtc (and the GPAGE prefix addressing on S12X) for far code, with far data access through the appropriate window.
  • Assembler/linker:
    • Extend ldscripts/emulation for banked sections and paged windows.
    • Generate page-crossing call stubs automatically.
  • Runtime: soft-register and __frame handling in paged memory.

Acceptance criteria

  • A program with code/data above 64 KB compiles and links with -m9s12x without manual page management.
  • A cross-page call/rtc is exercised in the gdb-sim test corpus (tests/), byte-diff verified.
  • __far variables and far function pointers compile to the expected paged instructions.

References

  • pkgs/gcc-4.3.6.nix (build, multilib wiring)
  • patches/gcc-4.3.6-s12x.patch
  • patches/gcc-4.3.6-ldivmod-s12x.asm
  • tests/run-tests.sh, tests/compiler-diff.sh (verification harness)
CodeWarrior handles S12/S12X parts larger than 64 KB with its memory model support. This repo's GCC backend cannot address data or code beyond the 64 KB flat space: it has no `__far` keyword, no `@address` placement syntax, and no automatic PPAGE (S12) / GPAGE (S12X) banking with linker-generated paged call stubs. This blocks use of large S12X parts, which is the primary reason anyone would reach for a CodeWarrior replacement. ## Motivation - S12X devices such as the MC9S12XDP512 expose a linear window into paged memory (PPAGE on S12, GPAGE on S12X). CodeWarrior lets a project: - place code/data in named segments and automatically route calls/data through the window (`__far`, `@address`, `#pragma CODE_SEG`), and - emit trampolines/stubs when a call crosses a page boundary. - Without this, only the low 64 KB is usable from C, defeating the purpose of the S12X line and the `-m9s12x` support this repo already has. ## Current state - `-m68hc11/-m68hc12/-m9s12x` ISA flags and multilibs exist (`patches/gcc-4.3.6-s12x.patch`). - `-mlong-calls` generates `call`/`rtc` (far code) and is verified working; `patches/gcc-4.3.6-ldivmod-s12x.asm` honors `__USE_RTC__`. - Pointers are 16-bit in both `-mshort` and `-mlong`; `__far` is rejected by the compiler (`error: '__far' declared as function returning a function`). - No linker-side banking: no PPAGE/GPAGE window management, no paged call stubs, no far data relocation. `-mrelax` only affects soft-register direct addressing. ## Proposed scope - Compiler: - Add a `__far` qualifier and a 32-bit far pointer type. - Support `@address` placement for variables/functions. - Emit `call`/`rtc` (and the GPAGE prefix addressing on S12X) for far code, with far data access through the appropriate window. - Assembler/linker: - Extend `ldscripts`/emulation for banked sections and paged windows. - Generate page-crossing call stubs automatically. - Runtime: soft-register and `__frame` handling in paged memory. ## Acceptance criteria - A program with code/data above 64 KB compiles and links with `-m9s12x` without manual page management. - A cross-page `call`/`rtc` is exercised in the `gdb-sim` test corpus (`tests/`), byte-diff verified. - `__far` variables and far function pointers compile to the expected paged instructions. ## References - `pkgs/gcc-4.3.6.nix` (build, multilib wiring) - `patches/gcc-4.3.6-s12x.patch` - `patches/gcc-4.3.6-ldivmod-s12x.asm` - `tests/run-tests.sh`, `tests/compiler-diff.sh` (verification harness)
Sign in to join this conversation.
No labels
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
sid/m68hc11-toolchain#1
No description provided.