kdb
[Top] [All Lists]

KDB 1.1 changes for non Intel x86 CPUs and 2.3.99pre1

To: kdb@xxxxxxxxxxx
Subject: KDB 1.1 changes for non Intel x86 CPUs and 2.3.99pre1
From: "Andi Kleen" <ak@xxxxxxx>
Date: Fri, 17 Mar 2000 22:21:21 +0100
Sender: owner-kdb@xxxxxxxxxxx
Hallo,

I ported kdb-1.1-2.3.48 to 2.3.99pre1. Turns out it was full of Intel
specific MSR accesses, which made it crash at boot on the AMD K6. 

Here are several patches that were needed to make it work (incremental
to the kdb patch): 

Remove the clearing of branch counting on page faults. It does not 
look very useful. If someone really needs it it needs to be guarded
with a CPU check (but I didn't want that in such a critical code path)

--- arch/i386/kernel/entry.S-o  Thu Mar 16 23:51:14 2000
+++ arch/i386/kernel/entry.S    Fri Mar 17 21:47:47 2000
@@ -432,6 +432,7 @@
        jmp error_code
 
 ENTRY(page_fault)
+#if 0
        pushl %ecx
        pushl %edx
        pushl %eax
@@ -442,6 +443,7 @@
        popl  %eax
        popl  %edx
        popl  %ecx
+#endif
        pushl $ SYMBOL_NAME(do_page_fault)
        jmp error_code


Make MSR setting conditional on the CPU: 

 
--- arch/i386/kdb/kdbasupport.c-o       Thu Mar 16 23:51:14 2000
+++ arch/i386/kdb/kdbasupport.c Fri Mar 17 20:59:27 2000
@@ -37,6 +37,40 @@
 unsigned long smp_kdb_wait;
 #endif
 
+enum cpu { IntelP5, IntelP6, AmdK6, Unknown } kdba_msrtype; 
+
+/* The normal kernel does the same, but be independent. */ 
+static void 
+checkcpu(void) 
+{ 
+       union { 
+               char str[12]; 
+               __u32 reg[3];  
+       } v; 
+       int eax,ebx,ecx,edx; 
+       __asm__("cpuid" 
+               : "=a" (eax), "=b" (v.reg[0]) , "=c" (v.reg[1]), "=d" (v.reg[2])
+               : "a" (0)); 
+       __asm__("cpuid"
+               : "=a" (eax), "=b" (ebx), "=c" (ecx), "=d" (edx)
+               : "a" (1)); 
+
+       kdba_msrtype = Unknown; 
+       if (!strcmp(v.str, "GenuineIntel")) {
+               switch ((ebx >> 4) & 0xF) { 
+               case 5:
+                       kdba_msrtype = IntelP5;
+                       break;
+               case 6:
+                       kdba_msrtype = IntelP6;
+                       break;
+               }                       
+       } else if (!strcmp(v.str, "AuthenticAMD") && (((ebx >> 4) & 0xF) == 6)) 
{
+               kdba_msrtype = AmdK6; 
+       }
+} 
+
+
 void
 kdba_installdbreg(kdb_bp_t *bp)
 {
@@ -708,6 +742,11 @@
 {
        u32  lv, hv;
 
+       /* Does the P5 have this? */ 
+       if (kdba_msrtype != IntelP6) { 
+               return;
+       }
+
        rdmsr(DEBUGCTLMSR, lv, hv);
        lv |= 0x1;      /* Set LBR enable */
        wrmsr(DEBUGCTLMSR, lv, hv);
@@ -734,6 +773,11 @@
        u32  bflv, bfhv;
        u32  btlv, bthv;
 
+       if (kdba_msrtype != IntelP6) { 
+               kdb_printf("Last branch information not supported on this 
CPU.\n");
+               return;
+       }
+
        rdmsr(LASTBRANCHFROMIP, bflv, bfhv);
        rdmsr(LASTBRANCHTOIP, btlv, bthv);
        kdb_printf("Last Branch IP, from: 0x%x  to 0x%x\n",
@@ -1087,6 +1131,7 @@
 void
 kdba_init(void)
 {
+       checkcpu(); 
        kdba_enablelbr();
 
        return;

Minor surgery needed for 2.3.99pre1 (patch refuses to apply 
the 2.3.48 version here because the Makefile has changed)

--- Makefile-o  Thu Mar 16 23:51:14 2000
+++ Makefile    Thu Mar 16 23:54:18 2000
@@ -121,6 +121,11 @@
 LIBS           =$(TOPDIR)/lib/lib.a
 SUBDIRS                =kernel drivers mm fs net ipc lib
 
+ifdef CONFIG_KDB
+CORE_FILES := $(CORE_FILES) kdb/kdb.o
+SUBDIRS           := $(SUBDIRS) kdb
+endif
+
 DRIVERS-n :=
 DRIVERS-y :=
 DRIVERS-m :=
@@ -168,6 +173,8 @@
 DRIVERS-$(CONFIG_PHONE) += drivers/telephony/telephony.a
 
 DRIVERS += $(DRIVERS-y)
+
+
 
 include arch/$(ARCH)/Makefile
 


-Andi



<Prev in Thread] Current Thread [Next in Thread>
  • KDB 1.1 changes for non Intel x86 CPUs and 2.3.99pre1, Andi Kleen <=