Memory models - ylab-nsu/cdm16-llvm-neo GitHub Wiki
1 Introduction
The CDM-16 processor can work with two memory models: von Neumann and Harvard.
- In von Neumann mode, program code and data are located in one address space.
- In Harvard mode, there are separate memory address spaces for program code and data. Program memory is read-only, and is only accessed by the processor during the fetch phase, to read the next instruction, or with special instructions (
lcw,lcb,lcsb), to read constants at arbitrary addresses.
The cdm LLVM target supports both memory models. You can choose the model with the -mmem-model= option.
It accepts one of the following arguments:
| Long form | Short form | Description |
|---|---|---|
vonNeumann |
vn |
von Neumann memory model |
harvard |
hv |
Harvard memory model |
This option does not affect code generation in any way. It only changes the version of crt0.o and the linker script used during the final linking step (see Standard Library and Default linker scripts).
The default memory model is von Neumann (used when -mmem-model= is not specified).
It is possible to detect the memory model used at compile time by checking the presence of the __VON_NEUMANN__
and __HARVARD__ preprocessor definitions.
[!NOTE] Due to limitations of Cocas,
-mmem-model=harvardis not supported with--target=cdm-cocas(see LLVM targets).
2 von Neumann memory model
Usage:
clang-cdm --target=cdm -mmem-model=vonNeumann # ...
This memory model allows the use of self-modifying code and has a faster startup sequence, since there is no data that is copied from ROM to RAM.
[!WARNING] It is impossible to perform a complete soft reset when using this memory model, because there are no backups of the
.datasection in memory. When it is modified, the previous contents are lost forever.
3 Harvard memory model
Usage:
clang-cdm --target=cdm -mmem-model=harvard # ...
This memory model allows for much larger programs that use the entire 64K address space for code and constants. The program startup sequence involves copying the .data section from ROM to RAM and zeroing out the .bss section. This can take some time, but it allows for complete soft resets.
Constants are NOT placed in program memory by default. They are placed in .rodata, which is merged into .data.
For a constant to be placed in program memory, its declaration has to be marked with the __progmem macro:
__progmem const long foo = 0xDEADBEEF;
__progmem can also be used with pointers:
void bar(__progmem const int *ptr);
See the docs for __progmem for more information.