agentleFS
gerphgerph/riscos-agent-skills/skills/using-cmhg/SKILL.md

using-cmhg

Skill4 starsChanged 7 months agoMITView on GitHub

Describes the CMHG file format and CMunge usage. Use when CMHG files are required for RISC OS modules.

We split this skill into the rules it gives an agent

4 rules. About 0 are common, 2 are distinctive, and 2 are very specific to this project.

  • ≈0

    Common · estimate

    Many files like this have a rule of this kind.

  • ≈2

    Distinctive · estimate

    This author's own choices. Worth a look.

  • 2

    Very specific

    Tied to their project's names, files or tools. Probably skip.

  • Common
  • Distinctive
  • Very specific
  1. Distinctive:

    All of these use the same CMHG mechanism:

    line 69
  2. Distinctive:

    Don't remove the comment sections that describe the file.

    line 107
  3. Very specific:

    If services are required for the module, use the symbolic names where possible from the include file riscos/Services.h.

    line 131
  4. Very specific:

    If you need to post-process the vector results after it is passed on, see the vector-traps docuemnt for a worked example in …

    line 149

≈ “Common” is an estimate: at least 1 in 5 of the 308,232 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
SKILL.md

CMunge Skill Summary

Purpose

CMunge is an enhanced, free alternative to the Acorn C Module Header Generator (CMHG). It generates ARM assembly "veneers" that allow RISC OS relocatable modules to be written in C or C++. It supports 26-bit, 32-bit, and 64-bit ARM architectures.

Command Line Usage

CMunge [options] <infile>

Key options:

  • -o <file>: Output object (AOF) file.
  • -s <file>: Output assembly file.
  • -d <file>: Output C header file.
  • -26bit: Target legacy 26-bit ARM (default).
  • -32bit: Target 32-bit compatible ARM.
  • -64bit: Target 64-bit (AArch64) ARM for GCC.
  • -p / -px: Pre-process input file (standard / extended).
  • -throwback: Enable error reporting to editors.
  • -zoslib / -zoslibpath: Use OSLib header styles.

CMHG/CMunge Directives Summary

  • title-string: Internal module name.
  • help-string: Descriptive name and version.
  • initialisation-code: C function called on load.
  • finalisation-code: C function called on unload.
  • module-is-initialised-early: (CMunge) Requests early initialization for ROM.
  • service-call-handler: C function for service calls.
  • swi-chunk-base-number: Base SWI number.
  • swi-handler-code: Central SWI handler C function.
  • swi-decoding-table: Lists SWI names and optional specific handlers.
  • command-keyword-table: Defines *Commands and their handlers — see references/command-tables.md.
  • generic-veneers: General purpose C wrappers.
  • vector-handlers: Wrappers for claiming RISC OS vectors - see references/vectors.md
  • event-handler: Wrappers for RISC OS events.
  • error-base (CMunge): Base error number for the module.
  • error-identifiers (CMunge): Automatically generates error definitions.
  • vector-traps (CMunge): Advanced vector chaining handlers — see references/vector-traps.md.
  • library-initialisation-code / library-enter-code: Override C library entry symbols.

Generic veneers reference index

These files describe common generic veneer usage patterns:

  • Timers: OS_CallEvery, OS_CallAfter, and OS_RemoveTickerEvent.
  • OS_AddCallBack/OS_RemoveCallBack deferred work.
  • OS_SetVarVal type 16 read/write code variables.
  • FilterManager and Internet filter callbacks.
  • ImageFileConvert converter and miscellaneous-operation entries.
  • ImageFileRender render, bbox, info, declare, start, and stop entries.
  • colour-map workspace, function descriptors.
  • DBResultManager provider callbacks.
  • OS_DynamicArea handlers.
  • Vectors claimed with OS_Claim.
  • OS_ClaimOSSWI handlers.
  • PPP, WebFTP, AUN, and network driver callback entries.
  • SCSI provider operation callbacks.
  • abort traps and ErrorV handling.
  • hand-built callback trampolines and carry-capable:.

All of these use the same CMHG mechanism:

generic-veneers: EntryName/HandlerName

CMHG generates EntryName, which is the address passed to the OS or another module. The C function HandlerName is called by the veneer with:

_kernel_oserror *HandlerName(_kernel_swi_regs *r, void *pw);

The handler reads and writes the register block according to the owning API's ABI, not according to CMHG itself.

Service call reference index

General information on CMHG syntax, C handler ABI, claiming, and filtering is in the Service Calls overview.

These files describe common CMHG service-call-handler usage patterns:

  • startup, shutdown, reset, and manager started/dying notifications
  • ResourceFS related registration services
  • Toolbox object/task lifecycle, Wimp start/shutdown, submenu mediation
  • filing-system redeclaration, filer lifecycle, disc dismount, and MultiFS format negotiation
  • mode changes, display changes/status, screen mode enumeration, and blanking
  • SCSI, USB, buffers, sound, and other device/provider registrations
  • DCI driver/protocol, Internet state, PPP, Freeway, and statistics services
  • ImageFileConvert and ImageFileRender registry lifecycle services
  • services used as synchronous extension interfaces by claiming and returning register values
  • Service_UKCompression and Service_ModulePreInit patching hooks
  • desktop banners, Wimp shutdown, TaskManager acknowledgements, and shutdown services
  • Service_APCSBacktrace diagnostic extension and minidump hooks
  • Service_ErrorStarting and related Wimp error-report monitoring hooks

Service information may often also be found through the riscos-prm --url Service_... command.

CMHG style guidelines

  • Don't remove the comment sections that describe the file. They are useful for humans to know how to add new sections.
  • Any definition which may be split across lines if the definition is incomplete. For example, a list of SWIs like:
swi-decoding-table: JUnitXML Create/SWI_Create TestSuite/SWI_TestSuite TestCase/SWI_TestCase Close/SWI_Close

Can be comma separated, thus:

swi-decoding-table: JUnitXML Create/SWI_Create, TestSuite/SWI_TestSuite, TestCase/SWI_TestCase Close/SWI_Close

And the comma separated parts can be split if the comma is the last entry on the line:

swi-decoding-table: JUnitXML Create/SWI_Create,
                             TestSuite/SWI_TestSuite,
                             TestCase/SWI_TestCase,
                             Close/SWI_Close

Which makes for nice aligned text.

  • If services are required for the module, use the symbolic names where possible from the include file riscos/Services.h. This can be included using C preprocessor includes, like this:
#include "riscos/Services.h"

service-call-handler: Mod_Service Service_ModeChange

References

For more information on the CMHG file format, see references/cmhg-syntax.md.

For examples and detailed syntax of the *Command tables, see references/command-tables.md.

Vectors

  • Vectors can be claimed or passed on. For detailed information on vectors including a worked example, see references/vector-traps.md.
  • If you need to post-process the vector results after it is passed on, see the vector-traps docuemnt for a worked example in references/vector-traps.md.

Download now (ZIP)

Does it work?

Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.

No reviews yet

People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.

  • It worked
  • Partly
  • It didn't
What did you use it for? e.g. Reviewing pull requests in a Rails app

Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.

Your trail

Files you open will collect here, so you can find them again.

Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.

Now do this for your own.

Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.