bitkeeper revision 1.481.1.1 (3f81afcd3Yfaq9KlIhuR96dSGAi-tA)
authorrneugeba@wyvis.research <rneugeba@wyvis.research>
Mon, 6 Oct 2003 18:09:17 +0000 (18:09 +0000)
committerrneugeba@wyvis.research <rneugeba@wyvis.research>
Mon, 6 Oct 2003 18:09:17 +0000 (18:09 +0000)
handle debug event

mini-os/h/os.h
mini-os/kernel.c
mini-os/traps.c

index 2645bea9549f0b8cacc3b4adb4959d8423311348..9578b8f5b4481eaae378a60d22ae35adef6c6f4b 100644 (file)
@@ -63,6 +63,10 @@ struct pt_regs {
        int  xss;
 };
 
+/* some function prototypes */
+void trap_init(void);
+void dump_regs(struct pt_regs *regs);
+
 
 /*
  * STI/CLI equivalents. These basically set and clear the virtual
index 6486fac119357354c8aab16b60b13a9f5a27c324..196d8612c3f3014bef32860c9ced354f850cd95b 100644 (file)
@@ -36,10 +36,10 @@ char stack[8192];
 void hypervisor_callback(void);
 void failsafe_callback(void);
 
-/* default exit event handler */
+/* default event handlers */
 static void exit_handler(int ev, struct pt_regs *regs);
+static void debug_handler(int ev, struct pt_regs *regs);
 
-extern void trap_init(void);
 
 /*
  * INITIAL C ENTRY POINT.
@@ -100,6 +100,10 @@ void start_kernel(start_info_t *si)
     enable_ev_action(EV_DIE);
     enable_hypervisor_event(EV_DIE);
 
+    add_ev_action(EV_DEBUG, &debug_handler);
+    enable_ev_action(EV_DEBUG);
+    enable_hypervisor_event(EV_DEBUG);
+
     /* init time and timers */
     init_time();
 
@@ -124,3 +128,9 @@ static void exit_handler(int ev, struct pt_regs *regs) {
     do_exit();
 }
 
+/*
+ * a debug handler to print out some state from the guest
+ */
+static void debug_handler(int ev, struct pt_regs *regs) {
+    dump_regs(regs);
+}
index 6352559c0f2447dabf19a6a619fa9b203eef8f5a..8dec10c5811c01ce4374b38f13e6139a8929a28e 100644 (file)
@@ -1,6 +1,7 @@
 
 #include <os.h>
 #include <hypervisor.h>
+#include <mm.h>
 #include <lib.h>
 
 /*
@@ -31,6 +32,7 @@ void machine_check(void);
 extern void do_exit(void);
 
 int kstack_depth_to_print = 24;
+#define THREAD_SIZE (2*PAGE_SIZE)
 
 static inline int kernel_text_address(unsigned long addr)
 {
@@ -57,24 +59,49 @@ void show_trace(unsigned long * stack)
     printk("\n");
 }
 
-void dump_regs(struct pt_regs *regs) {
-  printk("Register dump:");
-  printk("ebx: \t 0x%lx",      regs->ebx);
-  printk("ecx: \t 0x%lx",      regs->ecx);
-  printk("edx: \t 0x%lx",      regs->edx);
-  printk("esi: \t 0x%lx",      regs->esi);
-  printk("edi: \t 0x%lx",      regs->edi);
-  printk("ebp: \t 0x%lx",      regs->ebp);
-  printk("eax: \t 0x%lx",      regs->eax);
-  printk("xds: \t 0x%x",      regs->xds);
-  printk("xes: \t 0x%x",      regs->xes);
-  printk("orig_eax: \t 0x%lx", regs->orig_eax);
-  printk("eip: \t 0x%lx",      regs->eip);
-  printk("xcs: \t 0x%x",      regs->xcs);
-  printk("eflags: \t 0x%lx",   regs->eflags);
-  printk("esp: \t 0x%lx",      regs->esp);
-  printk("xss: \t 0x%x",      regs->xss);
-};
+void show_stack(unsigned long * esp)
+{
+       unsigned long *stack;
+       int i;
+
+       if(esp==NULL)
+               esp=(unsigned long*)&esp;
+
+       stack = esp;
+       for(i=0; i < kstack_depth_to_print; i++) {
+               if (((long) stack & (THREAD_SIZE-1)) == 0)
+                       break;
+               printk("%08lx ", *stack++);
+       }
+       printk("\n");
+       show_trace(esp);
+}
+
+void dump_regs(struct pt_regs *regs)
+{
+       int in_kernel = 1;
+       unsigned long esp;
+       unsigned short ss;
+
+       esp = (unsigned long) (&regs->esp);
+       ss = __KERNEL_DS;
+       if (regs->xcs & 2) {
+               in_kernel = 0;
+               esp = regs->esp;
+               ss = regs->xss & 0xffff;
+       }
+       printf("EIP:    %04x:[<%08lx>]\n",
+              0xffff & regs->xcs, regs->eip);
+       printf("EFLAGS: %08lx\n",regs->eflags);
+       printf("eax: %08lx   ebx: %08lx   ecx: %08lx   edx: %08lx\n",
+               regs->eax, regs->ebx, regs->ecx, regs->edx);
+       printf("esi: %08lx   edi: %08lx   ebp: %08lx   esp: %08lx\n",
+               regs->esi, regs->edi, regs->ebp, esp);
+       printf("ds: %04x   es: %04x   ss: %04x\n",
+               regs->xds & 0xffff, regs->xes & 0xffff, ss);
+       printf("\n");
+}      
+
 
 static inline void dump_code(unsigned eip)
 {