aboutsummaryrefslogtreecommitdiff
path: root/prog
diff options
context:
space:
mode:
Diffstat (limited to 'prog')
-rw-r--r--prog/link.ld40
-rw-r--r--prog/src/startup.c54
2 files changed, 45 insertions, 49 deletions
diff --git a/prog/link.ld b/prog/link.ld
index ae0988f..5c9926c 100644
--- a/prog/link.ld
+++ b/prog/link.ld
@@ -1,7 +1,7 @@
MEMORY
{
- ROM (rx) : ORIGIN = 0x00010000, LENGTH = 4K
- RAM (rwx) : ORIGIN = 0x00100000, LENGTH = 4K
+ ROM (rx) : ORIGIN = 0x00010000, LENGTH = 4K /* (1024 words, 0x0001_0000 to 0x0001_FFFF) */
+ RAM (rwx) : ORIGIN = 0x00100000, LENGTH = 4K /* (1024 words, 0x0010_0000 to 0x0010_FFFF) */
}
ENTRY(_start)
@@ -12,61 +12,61 @@ SECTIONS
{
_stext = .;
. = ORIGIN(ROM);
- _start = .; /* Entry point address */
- KEEP(*(.text.startup)) /* Ensure startup code is kept */
- *(.text) /* .text sections (code) */
+ _start = .; /* entry point address */
+ *(.text.startup)
+ *(.text) /* .text sections (code) */
*(.text.*)
. = ALIGN(4);
- _etext = .; /* End of code section, needed for copying .data */
+ _etext = .; /* end of code section */
} > ROM
.rodata :
{
- *(.rodata) /* Read-only data */
+ *(.rodata) /* Read-only data */
*(.rodata.*)
} > ROM
.data :
{
- _sidata = LOADADDR(.data); /* Start address of .data section in ROM */
+ _sidata = LOADADDR(.data); /* start address of .data section in ROM */
. = ALIGN(4);
- _sdata = .; /* Start of .data section in RAM */
- *(.data) /* .data sections (initialized data) */
+ _sdata = .; /* start of .data section in RAM */
+ *(.data) /* .data sections (initialized data) */
*(.data.*)
*(.sdata) /* .sdata sections (small initialized data) */
*(.sdata.*)
. = ALIGN(4);
- _edata = .; /* End of .data section in RAM */
+ _edata = .; /* end of .data section in RAM */
} > RAM AT > ROM
.bss :
{
. = ALIGN(4);
- _sbss = .; /* Start of .bss section */
- *(.bss) /* .bss sections (zero-initialized data) */
+ _sbss = .; /* start of .bss section */
+ *(.bss) /* .bss sections (zero-initialized data) */
*(.bss.*)
*(.sbss) /* .sbss sections (small zero-initialized data) */
*(.sbss.*)
*(COMMON)
. = ALIGN(4);
- _ebss = .; /* End of .bss section */
+ _ebss = .; /* end of .bss section */
} > RAM
.heap (NOLOAD) :
{
. = ALIGN(4);
- _sheap = .; /* Start of heap */
- . = . + 1K; /* Size of heap (adjust as needed) */
- _eheap = .; /* End of heap */
+ _sheap = .; /* start of heap */
+ . = . + 1K; /* size of heap */
+ _eheap = .; /* end of heap */
. = ALIGN(4);
} > RAM
.stack (NOLOAD) :
{
. = ALIGN(4);
- _sstack = .; /* Start of stack */
- . = . + 1K; /* Size of stack (adjust as needed) */
- _estack = .; /* End of stack */
+ _sstack = .; /* start of stack */
+ . = . + 1K; /* size of stack */
+ _estack = .; /* end of stack */
. = ALIGN(4);
} > RAM
diff --git a/prog/src/startup.c b/prog/src/startup.c
index 32aa131..c09f221 100644
--- a/prog/src/startup.c
+++ b/prog/src/startup.c
@@ -1,39 +1,35 @@
-extern unsigned int _sidata; /* Start address for the .data section in ROM */
-extern unsigned int _sdata; /* Start address for the .data section in RAM */
-extern unsigned int _edata; /* End address for the .data section in RAM */
-extern unsigned int _sbss; /* Start address for the .bss section */
-extern unsigned int _ebss; /* End address for the .bss section */
-extern unsigned int _estack; /* End address for the stack section */
+extern unsigned int _sidata; // start of .data section in ROM
+extern unsigned int _sdata; // start of .data section in RAM
+extern unsigned int _edata; // end of .data section in RAM
+extern unsigned int _sbss; // start of .bss section
+extern unsigned int _ebss; // end of .bss section
+extern unsigned int _estack; // end of .stack section (stack top)
-void main(void); /* The main function declaration */
-void _start(void) __attribute__((section(".text.startup"), naked)); /* The entry point */
+void main(void); // main function declaration
+
+void _start(void) __attribute__((section(".text.startup"), naked)); // entry point, cpu starts executing from here
void _start(void)
{
- unsigned int *src, *dest;
-
- /* Copy .data section from ROM to RAM */
- src = &_sidata; /* ROM address of the .data section */
- for (dest = &_sdata; dest < &_edata;)
- {
- *dest++ = *src++;
- }
-
- //while(1);
+ unsigned int *src, *dst;
- /* Zero initialize .bss section */
- for (dest = &_sbss; dest < &_ebss;)
- {
- *dest++ = 0;
- }
+ // copy .data section from ROM to RAM
+ src = &_sidata;
+ for (dst = &_sdata; dst < &_edata;) {
+ *dst++ = *src++;
+ }
+ // zero initialize .bss section
+ for (dst = &_sbss; dst < &_ebss;) {
+ *dst++ = 0;
+ }
- /* Initialize stack pointer */
- asm volatile ("la sp, _estack");
+ // initialize stack pointer
+ asm volatile ("la sp, _estack");
- /* Call the main function */
- main();
+ // call main function
+ main();
- /* If main returns, loop forever */
- while (1);
+ // halt
+ while (1);
}