In OS-9 for the 6809, command line parameters are passed to a program through a specific convention using the process's data area and registers at startup.
At Program Entry, the CPU Registers Contain:
- X — points to the start of the parameter string in memory
- Y — points to the top of the data area (the program's allocated memory)
- U — points to the bottom of the data area (start of the stack/data)
- D (A:B) — contains the size of the parameter string
The Parameter String
The parameter string is a raw text buffer containing everything typed after the command name on the shell line. For example, typing:
myprogram foo bar -x
...results in X pointing to foo bar -x, with D holding its byte length.
Key characteristics of the parameter string:
- It is not null-terminated — you must use the length in D to know where it ends
- It ends with a carriage return (0x0D), which counts as part of the string
- It may be empty (D = 1, pointing to just the CR) if no arguments were given
- The string lives in the system's I/O buffer area, not in your program's data area, so you should copy it if you need to keep it
Memory Layout at Entry
Low address ┌─────────────────────┐ ← U (data area base / stack bottom) │ Program Stack │ │ ↓ │ │ (grows down) │ │ │ │ Static Data │ └─────────────────────┘ ← Y (top of data area) High address Separately, in system buffer: ┌─────────────────────┐ ← X │ "foo bar -x\r" │ (D bytes long) └─────────────────────┘
Parsing Responsibility
OS-9 does no parsing for you. Unlike Unix which gives you argc/argv, OS-9 hands you the raw string and leaves tokenization entirely to the program (or to a library like the one in the C runtime). You walk the string byte by byte, using the length in D as your bounds, splitting on spaces or other delimiters as needed.
Standard I/O
At entry, the program's standard I/O paths are already open:
- Path 0 — standard input
- Path 1 — standard output
- Path 2 — standard error
These are inherited from the shell and ready to use via OS-9 I$Read / I$Write system calls.
This convention is quite minimal and low-level compared to later systems, which is typical of OS-9's design philosophy of keeping the kernel small and fast on 8/16-bit hardware.
roelof4
Discussions
Become a Hackaday.io Member
Create an account to leave a comment. Already have an account? Log In.