]> wirehaze git hosting - stm32f411ceu6.git/commitdiff

wirehaze git hosting

panic () main
authorphfr24 <phfr24@inf.ufpr.br>
Tue, 14 Jul 2026 04:04:18 +0000 (01:04 -0300)
committerphfr24 <phfr24@inf.ufpr.br>
Tue, 14 Jul 2026 04:04:18 +0000 (01:04 -0300)
sys/core/exceptions.c
sys/core/kentry.c
sys/core/panic.c [new file with mode: 0644]
sys/dev/led.c
sys/include/panic.h [new file with mode: 0644]

index 77e67d7fd2748e5984ad90ca2a3aba6f46d9ce7d..ad76fc9a3a16505c824ca7b3ade1de8092cacbc0 100644 (file)
@@ -2,6 +2,7 @@
 #include <link.h>
 #include <led.h>
 #include <uart.h>
 #include <link.h>
 #include <led.h>
 #include <uart.h>
+#include <panic.h>
 
 /* Initialize just enough to be able to handle a fault.  */
 __attribute__ ((noinline, used)) static void
 
 /* Initialize just enough to be able to handle a fault.  */
 __attribute__ ((noinline, used)) static void
@@ -46,8 +47,17 @@ reset_handler (void)
   asm ("b kentry");
 }
 
   asm ("b kentry");
 }
 
+/* TODO write proper exception handlers, this is just a test  */
+__attribute__ ((noreturn)) static void
+fault_handler (void)
+{
+  panic ("Fault");
+}
+
 __attribute__ ((section (".vector_table"), used))
 static unsigned long const vector_table[] = {
 __attribute__ ((section (".vector_table"), used))
 static unsigned long const vector_table[] = {
-  (unsigned long) &_sram_end,
-  (unsigned long) reset_handler,
+  [0] = (unsigned long) &_sram_end,
+  [1] = (unsigned long) reset_handler,
+  [3] = (unsigned long) fault_handler, /* ???  */
+  [6] = (unsigned long) fault_handler,
 };
 };
index 7fcc4b8a1abb06ffc330ad7859a8eadf845ec73a..c78af6b3468d25420ca8c793b37a5f9f2308c67a 100644 (file)
@@ -20,14 +20,14 @@ kentry (void)
 {
   unsigned int line;
 
 {
   unsigned int line;
 
-  /*  Test UART and LED  ----------------------------------------------------  */
+  for (line = 0; line < sizeof text / sizeof *text; ++line)
+    kputs_busytc (text[line]);
+
+  /* Trigger a fault to test kernel panic  */
+  asm ("udf #0");
+
+  kputs_busytc ("Unreachable");
 
   while (1)
 
   while (1)
-    {
-      for (line = 0; line < sizeof text / sizeof *text; ++line)
-        {
-          kputs_busytc (text[line]);
-          led_toggle ();
-        }
-    }
+    asm ("wfi");
 }
 }
diff --git a/sys/core/panic.c b/sys/core/panic.c
new file mode 100644 (file)
index 0000000..3594a4f
--- /dev/null
@@ -0,0 +1,17 @@
+#include <panic.h>
+#include <led.h>
+#include <uart.h>
+
+void
+panic (const char *msg)
+{
+  asm ("cpsid f");
+
+  led_on ();
+  kputs_busytc ("\r\n\nKernel panic: ");
+  kputs_busytc (msg);
+  kputs_busytc ("\r\n\nStop.");
+
+  while (1)
+    asm ("wfi");
+}
index 222bcb51a1810f3739584d0e67e31f8235e63ff5..529414da6154a4253edfef808288720e045ea1fd 100644 (file)
@@ -6,6 +6,10 @@ led_init (void)
 {
   /* GPIOCEN: IO port C clock enable  */
   *RCC_AHB1ENR |= (1u << 2); /* 1: IO port C clock enabled  */
 {
   /* GPIOCEN: IO port C clock enable  */
   *RCC_AHB1ENR |= (1u << 2); /* 1: IO port C clock enabled  */
+
+  /* Default to LED being turned off  */
+  *GPIOC_ODR |= (1u << 13);
+
   /* MODERy[1:0]: Port x configuration bits (y = 0..15)  */
   *GPIOC_MODER &= ~(0b11u << 26); /* Clear PC13 bits  */
   *GPIOC_MODER |= (1u << 26); /* 01: General purpose output mode  */
   /* MODERy[1:0]: Port x configuration bits (y = 0..15)  */
   *GPIOC_MODER &= ~(0b11u << 26); /* Clear PC13 bits  */
   *GPIOC_MODER |= (1u << 26); /* 01: General purpose output mode  */
diff --git a/sys/include/panic.h b/sys/include/panic.h
new file mode 100644 (file)
index 0000000..b050fb0
--- /dev/null
@@ -0,0 +1,6 @@
+#ifndef _PANIC_H_
+#define _PANIC_H_
+
+__attribute__ ((noreturn)) void panic (const char *msg);
+
+#endif /* _PANIC_H_  */