Repository navigation
Common API definitions
Built-in macros and definitions.
#define __CDM__Defined automatically when compiling for the cdm-cocas or the cdm target.
#define __COCAS__Defined automatically when compiling for the cdm-cocas target.
#define __CDM_EXT_E__Defined automatically when the "E" (operating system) extension is enabled.
#define __CDM_EXT_M__Defined automatically when the "M" (integer multiplication and division) extension is enabled.
#define __VON_NEUMANN__Defined automatically when compiling for the von Neumann memory architecture (with -mmem-model=vonNeumann).
#define __HARVARD__Defined automatically when compiling for the Harvard memory architecture (with -mmem-model=harvard).
#define __progmem __attribute__((__address_space__(1)))
__progmem const char example_constant[] = "Hello, world!";
void foo(__progmem const char *progmem_ptr);Sets the address space of a global variable or a pointer to 1 (program memory).
- global variables marked with
__progmemwill be placed in program memory and accessed withlcw/lcb/lcsbcommands - pointers marked with
__progmemwill uselcw/lcb/lcsbcommands when dereferenced
Important
Must be used with const, because program memory is read-only.
#include <cdm/ivt.h>
ISR void _exception_handler(context_t *ctx);
ISR void _ex_unaligned_sp(context_t *ctx); // 0xDED1
ISR void _ex_unaligned_pc(context_t *ctx); // 0xDED2
ISR void _ex_invalid_inst(context_t *ctx); // 0xDED3
ISR void _ex_double_fault(context_t *ctx); // 0xDED4
ISR void _ex_priv_violation(context_t *ctx); // 0xDED5
ISR void _ex_reserved_6(context_t *ctx); // 0xDED6
ISR void _ex_syscall(context_t *ctx); // 0xDED7
ISR void _ex_reserved_8(context_t *ctx); // 0xDED8
ISR void _ex_reserved_9(context_t *ctx); // 0xDED9
ISR void _ex_reserved_a(context_t *ctx); // 0xDEDA
ISR void _ex_reserved_b(context_t *ctx); // 0xDEDB
ISR void _ex_reserved_c(context_t *ctx); // 0xDEDC
ISR void _ex_reserved_d(context_t *ctx); // 0xDEDD
ISR void _ex_reserved_e(context_t *ctx); // 0xDEDE
ISR void _ex_reserved_f(context_t *ctx); // 0xDEDFNote
Only supported on the cdm target.
These functions are called when a hardware exception is triggered.
Default behavior: 0xDEDY is loaded into r0 (where Y is the exception number) and the processor is halted.
The functions can be re-defined to override this behavior:
-
_exception_handler- exception handler used in absence of a specific exception handler (any of the below) -
_ex_unaligned_sp- unaligned stack pointer register (SP) -
_ex_unaligned_pc- unaligned program counter register (PC) -
_ex_invalid_inst- invalid instruction -
_ex_double_fault- double fault -
_ex_priv_violation- privilege violation (cdm16eonly) -
_ex_syscall- system call (cdm16eonly)
Note
Before returning from these functions, you should modify the saved program counter. If it is left unchanged, the processor will try to re-execute the instruction that triggered the exception, re-entering the exception handler.
#include <cdm/ivt.h>
ISR void _interrupt_handler(context_t *ctx);Note
Only supported on the cdm target.
This function is called when handling an interrupt without a specific handler attached to it.
Default behavior: 0xDED0 is loaded into r0, then the processor halts. The function can be re-defined to override this behavior.
int main(void);The main entry point to the application. The return value is left in r0 when the processor halts.
- Home
- LLVM targets
- Memory models
- ISA extensions
- Standard library
- Platform C headers
- Default linker scripts
- CDM ABI
- Getting started
- Setting up a project
- Using C and assembly together
- Memory-mapped IO
- Interrupt handlers