Blame

8c1491 Bob Green 2026-06-02 12:30:13
1
# Runtime (crt0)
19a02c Bob Green 2026-06-02 12:15:40
2
3
By default, when using my link scripts, the standard runtime is initialised by crt0 as follows:
4
7d18d3 Bob Green 2026-06-02 12:57:34
5
| Address | Size | Variable Name |Comment |
048596 Bob Green 2026-06-02 12:29:29
6
| ------- | ------- | ------- | ------- |
7
| `0x03fffe` | ~256k | `_STACK_SIZE` |Stack (SSP). Grows towards 0. At round about 0x0000400 it would start stomping all over the memory area used by the monitor |
8b70b5 Bob Green 2026-06-02 13:03:34
8
| `0x040000` | n/a | `_RUN_ADDRESS` | Start of user program (.text), followed by initialised data (.data) and then unititialised data (.bss). |
aa3982 Bob Green 2026-06-02 12:27:17
9
12cd8e Bob Green 2026-06-02 12:51:29
10
You can override the values at link time by using the linker option:
11
12
```
7d18d3 Bob Green 2026-06-02 12:57:34
13
--defsym=<Variable Name>=<value>
12cd8e Bob Green 2026-06-02 12:51:29
14
```
15
You can use this option as many times as needed.
16
8b70b5 Bob Green 2026-06-02 13:03:34
17
## Before calling main()
18
### Banner Message
19
If the code is running in ROM, a banner message will be printed, similar to the following:
20
```
21
Mega-680x0 Computer System
22
Code is running in ROM
23
68030 Processor running at ~40MHz
24
```
e7d651 Bob Green 2026-06-02 12:27:24
25
8b70b5 Bob Green 2026-06-02 13:03:34
26
### Heap
27
All free memory from the end of the .bss area to the end of ram to the heap (malloc/free).
018e16 Bob Green 2026-06-02 12:44:24
28
bb124e Bob Green 2026-06-02 12:56:47
29
### Global Variables
018e16 Bob Green 2026-06-02 12:44:24
30
crt0 sets the following global variables:
31
258e33 Bob Green 2026-06-02 13:05:22
32
| Variable | Comment |
33
| ------- | ------- |
34
| **uint8_t cpu_speed_mhz**. | This uses the counter in the PI/T to figure out roughly how fast the CPU is being clocked at. Within a MHz or so. |
35
| **uint8_t cpu_type**. | Figures out what CPU is installed: 0 - 68000/68008, 1 - 68010, 2 - 68020, 3 - 68030 |
36
| **uint8_t running_in_rom**. | When non-zero, indicates that the code is running in ROM. 0 indicates it's running in RAM. |
018e16 Bob Green 2026-06-02 12:44:24
37
dcb313 Bob Green 2026-06-02 12:49:16
38
To access any of these variables, simply ```#include <machine.h.>```
bb124e Bob Green 2026-06-02 12:56:47
39
40
### On Exit
b59bea Bob Green 2026-06-02 13:06:25
41
When `main()` returns or when `exit()` is called, a non-zero exit code will be displayed as follows:
bb124e Bob Green 2026-06-02 12:56:47
42
```
43
exited with status: <value>
44
```
45
No message is printed if the exit code was zero.
46
Control will then be passed back to the monitor