Add linking step

This commit is contained in:
Alexander Heldt
2024-06-22 19:20:43 +02:00
parent 4c77450e47
commit 8c8a72df71
8 changed files with 5643 additions and 1 deletions

34
src/startup.c Normal file
View File

@@ -0,0 +1,34 @@
#include <stdint.h>
extern void stack_start(void); // Defined in link.ld
extern int main(void);
void init_memory(void) {
// Copy .data SECTION to ram
extern uint32_t _data_start, _data_end, _data_addr;
for (uint32_t *dst = &_data_start, *src = &_data_addr; dst < &_data_end;) {
*dst++ = *src++;
}
// Initialize .bss SECTION with zeros
extern uint32_t _bss_start, _bss_end;
for (uint32_t *dst = &_bss_start; dst < &_bss_end; dst++) {
*dst = 0;
}
}
void reset(void) {
(void)init_memory();
main();
// Infinite loop in case main returns
for (;;) (void) 0;
}
// Create minimal interrupt vector table
// 16 standard and 86 STM32F411xC/E-specific handlers
void (*const interrupt_vector_table[16 + 86])(void) __attribute__((section(".isr_vector"))) = {
stack_start, // Defined in link.ld
reset
};