progress on all fronts
[com32] / src / panic.c
index 18e7dc6..788900e 100644 (file)
@@ -18,6 +18,7 @@ along with this program.  If not, see <https://www.gnu.org/licenses/>.
 #include <stdio.h>
 #include <string.h>
 #include <stdarg.h>
+#include "intr.h"
 #include "asmops.h"
 
 struct all_registers {
@@ -63,3 +64,18 @@ void panic(const char *fmt, ...)
 
        for(;;) halt_cpu();
 }
+
+void backtrace(void)
+{
+       int lvl = 0;
+       uint32_t *frmptr;
+       int ien = get_intr_flag();
+       disable_intr();
+       get_ebp(frmptr);
+       set_intr_flag(ien);
+
+       while(frmptr) {
+               printf("%d: %p\n", lvl++, (void*)frmptr[1]);
+               frmptr = (uint32_t*)*frmptr;
+       }
+}