aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--include/kern/log.h2
-rw-r--r--linker/linker_script.ld1
-rw-r--r--src/kern/init.c49
-rw-r--r--src/kern/log.c4
-rw-r--r--src/kern/panic.c38
5 files changed, 64 insertions, 30 deletions
diff --git a/include/kern/log.h b/include/kern/log.h
index e1e4088..32d3890 100644
--- a/include/kern/log.h
+++ b/include/kern/log.h
@@ -20,4 +20,6 @@ void kerr_logf(const char* fmt, ...);
/** Like klogf, but with a va_list argument. */
void kerr_vlogf(const char* fmt, va_list args);
+void initialize_logging();
+
#endif
diff --git a/linker/linker_script.ld b/linker/linker_script.ld
index f2a99ae..1817fbd 100644
--- a/linker/linker_script.ld
+++ b/linker/linker_script.ld
@@ -55,6 +55,7 @@ SECTIONS
} >sram1 AT>flash
+ . = ALIGN(0x04);
BSS_START = .;
.bss : {
*(.bss);
diff --git a/src/kern/init.c b/src/kern/init.c
index 9869749..4c2bfcd 100644
--- a/src/kern/init.c
+++ b/src/kern/init.c
@@ -36,32 +36,55 @@ extern uint32_t INIT_5_END;
extern uint32_t INIT_6_END;
extern uint32_t INIT_7_END;
-init0()
+init2()
{
- /* 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);
-}
+ volatile uint32_t bss_start_ptr = (uint32_t) &BSS_START;
+ volatile uint32_t bss_end_ptr = (uint32_t) &BSS_END;
+ volatile uint32_t init_data_values_ptr = (uint32_t) &INIT_DATA_VALUES;
+ volatile uint32_t data_segment_start_ptr = (uint32_t) &DATA_SEGMENT_START;
+ volatile uint32_t data_segment_stop_ptr = (uint32_t) &DATA_SEGMENT_STOP;
+
+ if ((data_segment_start_ptr | data_segment_start_ptr) & 3) {
+ panic(".data segment not aligned with sizeof(uint32_t)!\n");
+ }
+
+ if (init_data_values_ptr & 3) {
+ panic("init data values pointer not aligned with sizeof(uint32_t)!\n");
+ }
+
+ if ((bss_start_ptr | bss_end_ptr) & 3) {
+ panic(".bss data segment not aligned with sizeof(uint32_t)!\n");
+ }
+
+ klogf("Copy data segments from flash ... \n");
-init1()
-{
/* Next, we'll copy the data sections from flash to ram. */
uint32_t* src;
uint32_t* dest;
+ klogf(" .data ...\n");
+ klogf(" set (%p - %p)\n", &DATA_SEGMENT_START, &DATA_SEGMENT_STOP);
+ klogf(" from (%p)\n", &INIT_DATA_VALUES);
+
src = &INIT_DATA_VALUES;
dest = &DATA_SEGMENT_START;
/* Copy the values from flash into the data segment. */
- while (dest != &DATA_SEGMENT_STOP) {
+ while (dest < &DATA_SEGMENT_STOP) {
*(dest++) = *(src++);
}
+ klogf(" .bss ...\n");
+ klogf(" clear (%p - %p)\n", &BSS_START, &BSS_END);
+
/* Everything in the BSS segment is set to zero. */
dest = &BSS_START;
+
while (dest != &BSS_END) {
*(dest++) = 0;
}
+
+ klogf("Done!\n");
}
init3()
@@ -84,11 +107,20 @@ void run_init_routines()
&INIT_7_END,
};
+ initialize_logging();
+
void (**initfn)();
+
+ /* 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);
+
+ klogf("Init Level 0 ...\n");
for (initfn = &INIT_ROUTINES_FLASH_START; initfn < &INIT_ROUTINES_FLASH_STOP;
++initfn) {
while (initfn == init_boundaries[initlevel] && initlevel < INIT_LEVEL_7) {
++initlevel;
+ klogf("Init Level %d ...\n", initlevel);
}
(*initfn)();
@@ -105,6 +137,7 @@ void run_init_routines()
*/
_Noreturn void on_reset()
{
+
initlevel = INIT_LEVEL_0;
run_init_routines();
diff --git a/src/kern/log.c b/src/kern/log.c
index e9bd424..e6bbec6 100644
--- a/src/kern/log.c
+++ b/src/kern/log.c
@@ -12,12 +12,14 @@ void setup_usart2(uint32_t baud_rate);
/** This module requires an initialization routine. This is a level2 routine,
* so anything running at level3 or lower is guaranteed to have access
* to the klong. */
-init2()
+void initialize_logging()
{
setup_usart2(115200);
regset(USART2.c_r1, usart_txeie, 1);
regset(USART2.c_r1, usart_rxneie, 1);
usart_set_enabled(&USART2, USART_ENABLE_TX | USART_ENABLE_RX);
+
+ klogf("Logging has been initalized!\n");
}
void klogf(const char* fmt, ...)
diff --git a/src/kern/panic.c b/src/kern/panic.c
index de1d143..e005bcc 100644
--- a/src/kern/panic.c
+++ b/src/kern/panic.c
@@ -15,30 +15,26 @@ _Noreturn void panic(const char* fmt, ...)
uint32_t base[0];
disable_all_interrupts();
- if (get_system_init_level() > INIT_LEVEL_2) {
- va_list l;
- va_start(l, fmt);
+ va_list l;
+ va_start(l, fmt);
- kerr_logf("** Kernel Panic! **\n");
- kerr_vlogf(fmt, l);
- kerr_logf("** Stack:\n");
+ kerr_logf("** Kernel Panic! **\n");
+ kerr_vlogf(fmt, l);
+ kerr_logf("** Stack:\n");
- int i = 0;
- for (; i < 20 && &base[i] != (void*)STACK_TOP; ++ i) {
- kerr_logf(" (%p) %p\n", &base[i], base[i]);
- }
+ int i = 0;
+ for (; i < 20 && &base[i] != (void*)STACK_TOP; ++ i) {
+ kerr_logf(" (%p) %p\n", &base[i], base[i]);
+ }
+
+ set_system_clock_MHz(4); /* reduce power usage while we do nothing. */
+ gpio_reserved_pin_t pin3 = get_sysled();
- set_system_clock_MHz(4); /* reduce power usage while we do nothing. */
- for(;;);
- } else {
- set_system_clock_MHz(4); /* reduce power usage while we do nothing. */
- gpio_reserved_pin_t pin3 = get_sysled();
- for (;;) {
- set_gpio_pin_high(pin3);
- delay(100000);
- set_gpio_pin_low(pin3);
- delay(100000);
- }
+ for (;;) {
+ set_gpio_pin_high(pin3);
+ delay(100000);
+ set_gpio_pin_low(pin3);
+ delay(100000);
}
}
#endif