aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--linker/linker_script.ld14
-rw-r--r--src/kern/init.c44
-rw-r--r--src/kern/main.c91
3 files changed, 100 insertions, 49 deletions
diff --git a/linker/linker_script.ld b/linker/linker_script.ld
index d6ce40b..bec8fb7 100644
--- a/linker/linker_script.ld
+++ b/linker/linker_script.ld
@@ -8,11 +8,15 @@ MEMORY
SECTIONS
{
/* This is where the code goes. */
+ WAT = ORIGIN(flash);
. = ORIGIN(flash);
- .text ALIGN(0x100) : {
+ TEXT_START = .;
+ .text ALIGN(0x04) : {
*(.vectors); /* All .vector sections go here. */
*(.text); /* All .text sections go here. */
} >flash
+ TEXT_STOP = .;
+ . = ALIGN(0x04);
.data : ALIGN(0x04) {
/* Data segment as defined in the flash. */
@@ -24,9 +28,11 @@ SECTIONS
*(.data);
DATA_SEGMENT_STOP = .;
- INIT_ROUTINES_FLASH_START =
- LOADADDR(.data) + (DATA_SEGMENT_STOP - DATA_SEGMENT_START);
-
+ /* INIT_ROUTINES_FLASH_START =
+ LOADADDR(.data) + (DATA_SEGMENT_STOP - DATA_SEGMENT_START);
+ */
+ . = ALIGN(0x1c);
+ INIT_ROUTINES_FLASH_START = .;
INITS_START = .;
*(.init0);
INIT_0_END = ABSOLUTE(INIT_ROUTINES_FLASH_START) + (. - INITS_START);
diff --git a/src/kern/init.c b/src/kern/init.c
index 5120745..2af3877 100644
--- a/src/kern/init.c
+++ b/src/kern/init.c
@@ -21,6 +21,8 @@ int main();
extern uint32_t INIT_DATA_VALUES;
extern uint32_t DATA_SEGMENT_START;
extern uint32_t DATA_SEGMENT_STOP;
+extern uint32_t TEXT_START;
+extern uint32_t TEXT_STOP;
extern uint32_t BSS_START;
extern uint32_t BSS_END;
@@ -36,6 +38,12 @@ extern uint32_t INIT_5_END;
extern uint32_t INIT_6_END;
extern uint32_t INIT_7_END;
+extern uint32_t WAT;
+
+#define MAGIC_COOKIE 0xDEADBEEF
+/* Test that data segment is properly set. */
+static uint32_t magic_cookie = MAGIC_COOKIE;
+
init2()
{
volatile uint32_t bss_start_ptr = (uint32_t)&BSS_START;
@@ -84,6 +92,10 @@ init2()
*(dest++) = 0;
}
+ if (magic_cookie != MAGIC_COOKIE) {
+ panic("Data Segment Initialization Failed!");
+ }
+
klogf("Done!\n");
}
@@ -109,11 +121,42 @@ void run_init_routines()
void (**initfn)();
+ klogf("WAT: %p\n", &WAT);
+
klogf(
"Init routines at (%p - %p)\n",
&INIT_ROUTINES_FLASH_START,
&INIT_ROUTINES_FLASH_STOP);
+ klogf(
+ "Data segment at (%p - %p) from (%p)\n",
+ &DATA_SEGMENT_START,
+ &DATA_SEGMENT_STOP,
+ &INIT_DATA_VALUES);
+
+ klogf(
+ "Bss segment at (%p - %p)\n",
+ &BSS_START,
+ &BSS_END);
+
+ klogf(
+ "Heap at (%p - %p)\n",
+ &HEAP_START,
+ &HEAP_STOP);
+
+ klogf(
+ "Text at (%p - %p)\n",
+ &TEXT_START,
+ &TEXT_STOP);
+
+ klogf( "Init Boundary 0: %p\n", &INIT_0_END);
+ klogf( "Init Boundary 1: %p\n", &INIT_1_END);
+ klogf( "Init Boundary 2: %p\n", &INIT_2_END);
+
+ // for (size_t i = 0; i < sizeof(init_boundaries) / sizeof(void*); ++ i) {
+ // klogf("Init Boundary %d at %p\n", i, init_boundaries[i]);
+ // }
+
/* Enable a higher clock speed. This is the first thing we do
* beacuse it will boost the boot up time. */
set_system_clock_MHz(80);
@@ -126,6 +169,7 @@ void run_init_routines()
klogf("[Init Level %d]\n", initlevel);
}
+ klogf("Calling (%p)\n", initfn);
(*initfn)();
}
}
diff --git a/src/kern/main.c b/src/kern/main.c
index 957e43f..61e60c9 100644
--- a/src/kern/main.c
+++ b/src/kern/main.c
@@ -211,51 +211,52 @@ static void reset_state()
/* Main function. This gets executed from the interrupt vector defined above. */
int main()
{
- klogf("Entering Main\n");
-
- systick_add_callback(on_systick, NULL);
- enable_systick(10000);
- configure_gpio();
-
- ir_begin_listen();
- enable_ir_control();
-
- add_ir_code_callback(RC_HIGH, printit, "RC_HIGH");
- add_ir_code_callback(RC_TEMP_UP, timetick_up, NULL);
- add_ir_code_callback(RC_DRY, set_red, NULL);
- add_ir_code_callback(RC_LOW, printit, "RC_LOW");
- add_ir_code_callback(RC_TEMP_DOWN, timetick_down, NULL);
- add_ir_code_callback(RC_COOL, toggle_cool, NULL);
- add_ir_code_callback(RC_CONTINUOUS, set_snow, "RC_CONTINUOUS");
- add_ir_code_callback(RC_FAN, toggle_brightness, NULL);
- add_ir_code_callback(RC_SLEEP, toggle_sleep, NULL);
- add_ir_code_callback(RC_UNITS, printit, "RC_UNITS");
- add_ir_code_callback(RC_TIMER, reset_state, NULL);
- add_ir_code_callback(RC_POWER, toggle_power, NULL);
-
- int ec;
- state.drv = ws2812b_new(SPI_SELECT_SPI1, &ec);
-
- if (ec || !state.drv) {
- panic("Unable to create WS2812b driver :( (%d)\n", ec);
- }
-
- reset_state();
-
- for (int i = 0; i < state.n_leds; ++i) {
- /* Clear the LED strip. */
- disable_all_interrupts();
- ws2812b_write_rgb_sync(state.drv, 0, 0, 0);
- enable_all_interrupts();
- }
- ws2812b_latch(state.drv);
-
- for (;;) {
- // while (!do_redraw)
- // ;
- // do_redraw = 0;
- if (!state.sleep) redraw();
- }
+ klogf("Entering Main (%p).\n", main);
+
+ // systick_add_callback(on_systick, NULL);
+ // enable_systick(10000);
+ // configure_gpio();
+
+ // ir_begin_listen();
+ // enable_ir_control();
+
+ // add_ir_code_callback(RC_HIGH, printit, "RC_HIGH");
+ // add_ir_code_callback(RC_TEMP_UP, timetick_up, NULL);
+ // add_ir_code_callback(RC_DRY, set_red, NULL);
+ // add_ir_code_callback(RC_LOW, printit, "RC_LOW");
+ // add_ir_code_callback(RC_TEMP_DOWN, timetick_down, NULL);
+ // add_ir_code_callback(RC_COOL, toggle_cool, NULL);
+ // add_ir_code_callback(RC_CONTINUOUS, set_snow, "RC_CONTINUOUS");
+ // add_ir_code_callback(RC_FAN, toggle_brightness, NULL);
+ // add_ir_code_callback(RC_SLEEP, toggle_sleep, NULL);
+ // add_ir_code_callback(RC_UNITS, printit, "RC_UNITS");
+ // add_ir_code_callback(RC_TIMER, reset_state, NULL);
+ // add_ir_code_callback(RC_POWER, toggle_power, NULL);
+
+ // int ec;
+ // state.drv = ws2812b_new(SPI_SELECT_SPI1, &ec);
+
+ // if (ec || !state.drv) {
+ // panic("Unable to create WS2812b driver :( (%d)\n", ec);
+ // }
+
+ // reset_state();
+
+ // for (int i = 0; i < state.n_leds; ++i) {
+ // /* Clear the LED strip. */
+ // disable_all_interrupts();
+ // ws2812b_write_rgb_sync(state.drv, 0, 0, 0);
+ // enable_all_interrupts();
+ // }
+ // ws2812b_latch(state.drv);
+
+ // for (;;) {
+ // // while (!do_redraw)
+ // // ;
+ // // do_redraw = 0;
+ // if (!state.sleep) redraw();
+ // }
+ for (;;);
}
#endif