Skip site navigation (1)Skip section navigation (2)
Date:      Thu, 27 May 2010 20:54:30 +0200
From:      =?UTF-8?B?VmxhZGltaXIgJ8+GLWNvZGVyL3BoY29kZXInIFNlcmJpbmVua28=?= <phcoder@gmail.com>
To:        "M. Warner Losh" <imp@bsdimp.com>
Cc:        freebsd-mips@freebsd.org
Subject:   Re: Fix mips64 ddb backtracing
Message-ID:  <4BFEBFE6.5000107@gmail.com>
In-Reply-To: <20100527.100407.784267736074446108.imp@bsdimp.com>
References:  <4BFDA036.7080502@gmail.com>	<B295B582-A432-434E-B9DE-2DBBF4353013@FreeBSD.org>	<4BFE72B2.1030107@gmail.com> <20100527.100407.784267736074446108.imp@bsdimp.com>

next in thread | previous in thread | raw e-mail | index | archive | help
M. Warner Losh wrote:
> In message: <4BFE72B2.1030107@gmail.com>
>             Vladimir 'φ-coder/phcoder' Serbinenko <phcoder@gmail.com> writes:
> : Rui Paulo wrote:
> : > On 26 May 2010, at 23:27, Vladimir 'φ-coder/phcoder' Serbinenko wrote:
> : >
> : >   
> : >> This is a multi-part message in MIME format.
> : >> --------------080906000803010207060400
> : >> Content-Type: text/plain; charset=UTF-8
> : >> Content-Transfer-Encoding: quoted-printable
> : >>
> : >> I've come accross this issue when coding for yeeloong. It's easy to fix
> : >> (patch attached). After applying the patch I had the session with
> : >> debugger as in attached capture file.
> : >> Can this patch go directly to -current ?
> : >>
> : >> --=20
> : >> Regards
> : >> Vladimir '=CF=86-coder/phcoder' Serbinenko
> : >>     
> : >
> : > Can you please resend this ? I cannot read this patch nor the pcap file correctly.
> : >
> : >   
> : Some kind of problem with signatures. I'll bug-report it, using beta
> : sometimes backfires.
> : The original patch had a mistake (always using 64-bit kseg0 address) I
> : fixed in this one. New cap file attached. Can some test it on 32-bit mips?
>
> there's no cap file attached to this mail.
>
>   
Are MIME attachments allowed? In outgoing copy I have those file
attacghed. So posting inline this time.

=== modified file 'mips/mips/db_trace.c'
--- mips/mips/db_trace.c    2010-05-26 07:47:16 +0000
+++ mips/mips/db_trace.c    2010-05-27 12:14:36 +0000
@@ -49,9 +49,19 @@
 #define    MIPS_END_OF_FUNCTION(ins)    ((ins) == 0x03e00008)
 
 /*
- * kdbpeekD(addr) - skip one word starting at 'addr', then read the
second word
+ * kdbpeekD(addr) - read double word.
  */
-#define    kdbpeekD(addr)    kdbpeek(((int *)(addr)) + 1)
+
+static inline register_t
+kdbpeekD (uintptr_t addr) {
+#ifdef __MIPSEL__
+    return ((register_t) kdbpeek ((int *) addr))
+        | (((register_t) kdbpeek ((int *) addr + 1)) << 32);
+#else
+    return ((register_t) kdbpeek ((int *) addr + 1))
+        | (((register_t) kdbpeek ((int *) addr)) << 32);
+#endif
+}
 
 /*
  * Functions ``special'' enough to print by name
@@ -119,6 +129,8 @@
     unsigned instr, mask;
     unsigned int frames = 0;
     int more, stksize, j;
+    const uintptr_t kseg0_start = sizeof (uintptr_t)
+        ? 0xffffffff80000000ULL : 0x80000000;
 
 /* Jump here when done with a frame, to start a new one */
 loop:
@@ -140,7 +152,7 @@
     }
     /* check for bad SP: could foul up next frame */
     /*XXX MIPS64 bad: this hard-coded SP is lame */
-    if (sp & 3 || sp < 0x80000000) {
+    if (sp & 3 || (uintptr_t) sp < kseg0_start) {
         (*printfn) ("SP 0x%x: not in kernel\n", sp);
         ra = 0;
         subr = 0;
@@ -181,7 +193,7 @@
     }
     /* check for bad PC */
     /*XXX MIPS64 bad: These hard coded constants are lame */
-    if (pc & 3 || pc < (uintptr_t)0x80000000) {
+    if (pc & 3 || (uintptr_t)pc < kseg0_start) {
         (*printfn) ("PC 0x%x: not in kernel\n", pc);
         ra = 0;
         goto done;
@@ -303,32 +315,34 @@
             mask |= (1 << i.IType.rt);
             switch (i.IType.rt) {
             case 4:/* a0 */
-                args[0] = kdbpeekD((int *)(sp + (short)i.IType.imm));
+                args[0] = kdbpeekD(sp + (short)i.IType.imm);
                 valid_args[0] = 1;
                 break;
 
             case 5:/* a1 */
-                args[1] = kdbpeekD((int *)(sp + (short)i.IType.imm));
+                args[1] = kdbpeekD(sp + (short)i.IType.imm);
                 valid_args[1] = 1;
                 break;
 
             case 6:/* a2 */
-                args[2] = kdbpeekD((int *)(sp + (short)i.IType.imm));
+                args[2] = kdbpeekD(sp + (short)i.IType.imm);
                 valid_args[2] = 1;
                 break;
 
             case 7:/* a3 */
-                args[3] = kdbpeekD((int *)(sp + (short)i.IType.imm));
+                args[3] = kdbpeekD(sp + (short)i.IType.imm);
                 valid_args[3] = 1;
                 break;
 
             case 31:    /* ra */
-                ra = kdbpeekD((int *)(sp + (short)i.IType.imm));
+                ra = kdbpeekD(sp + (short)i.IType.imm);
             }
             break;
 
         case OP_ADDI:
         case OP_ADDIU:
+        case OP_DADDIU:
+        case OP_DADDI:
             /* look for stack pointer adjustment */
             if (i.IType.rs != 29 || i.IType.rt != 29)
                 break;
@@ -337,17 +351,18 @@
     }
 
 done:
-    (*printfn) ("%s+%x (", fn_name(subr), pc - subr);
+    (*printfn) ("%s+%lx (", fn_name(subr), (unsigned long) (pc - subr));
     for (j = 0; j < 4; j ++) {
         if (j > 0)
             (*printfn)(",");
         if (valid_args[j])
-            (*printfn)("%x", args[j]);
+            (*printfn)("%lx", (unsigned long) args[j]);
         else
             (*printfn)("?");
     }
 
-    (*printfn) (") ra %x sp %x sz %d\n", ra, sp, stksize);
+    (*printfn) (") ra %lx sp %lx sz %ld\n", (unsigned long) ra,
+            (unsigned long) sp, (long) stksize);
 
     if (ra) {
         if (pc == ra && stksize == 0)


GRUB CS5536 at 00000200SMBus controller enabled.
00000080Caches enabled
Welcome to GRUB!

error: no device connected.
error: no device connected.
GNU GRUB  version 1.98

   Minimal BASH-like line editing is supported. For the first word, TAB
   lists possible command completions. Anywhere else TAB lists possible
   device or file completions.





grub> multiboot2 (usb0,msdos1)/kernel
grub> boot
entry: mips_init()
Cache info:
  picache_stride    = 0
  picache_loopcount = 0
  pdcache_stride    = 0
  pdcache_loopcount = 0
cpu0: Unknown cid 0 processor v3.99
  MMU: Standard BAT, 64 entries
  L1 i-cache: 0 ways of 0 sets, 32 bytes per line
  L1 d-cache: 0 ways of 0 sets, 32 bytes per line
Physical memory chunk(s):
0x45f000 - 0xfba1fff, 259272704 bytes (63299 pages)
Maxmem is 0xfba2000
KDB: debugger backends: ddb
KDB: current backend: ddb
hz=100 cyl_per_tick:400000 cyl_per_usec:400 freq:400000000
cyl_per_hz:4000000 cyl_per_stathz:4000000 cyl_per_profhz:4000000
Copyright (c) 1992-2010 The FreeBSD Project.
Copyright (c) 1979, 1980, 1983, 1986, 1988, 1989, 1991, 1992, 1993, 1994
    The Regents of the University of California. All rights reserved.
FreeBSD is a registered trademark of The FreeBSD Foundation.
FreeBSD 9.0-CURRENT #37: Thu May 27 14:10:53 CEST 2010
   
phcoder@freebsd.bg45.phnet:/home/phcoder/compile/mips/home/phcoder/p4/yeeloong/src/sys/YEELOONG
mips
Trap cause = 2 (TLB miss (load or instr. fetch) - kernel mode)
[ thread pid 0 tid 0 ]
Stopped at      0xffffffff80385c64:     lbu     v0,205(a0)
db> t
Tracing pid 0 tid 0 td 0xffffffff8043f070
ffffffff803c8218+40 (?,?,?,?) ra ffffffff801373b8 sp ffffffff804700e0 sz 16
ffffffff80137230+188 (0,?,ffffffffffffffff,?) ra ffffffff80136af8 sp
ffffffff804700f0 sz 48
ffffffff80136660+498 (?,?,?,?) ra ffffffff80136dc8 sp ffffffff80470120
sz 192
ffffffff80136cd0+f8 (?,?,?,?) ra ffffffff8013a600 sp ffffffff804701e0 sz 16
ffffffff8013a440+1c0 (?,?,?,?) ra ffffffff802295ac sp ffffffff804701f0
sz 816
ffffffff80229420+18c (?,?,?,?) ra ffffffff803b944c sp ffffffff80470520 sz 32
trap+1c8c (?,?,?,?) ra ffffffff803ad240 sp ffffffff80470540 sz 256
MipsKernGenException+154 (0,0,0,ffffffff80470900) ra ffffffff80385c64 sp
ffffffff80470640 sz 368
ffffffff80385c58+c (?,?,?,?) ra ffffffff80388088 sp ffffffff804707b0 sz 16
ffffffff80388018+70 (ffffffff804708f8,?,0,?) ra ffffffff80379e5c sp
ffffffff804707c0 sz 128
ffffffff80379d70+ec (0,ffffffffc0000000,2,0) ra ffffffff803b8280 sp
ffffffff80470840 sz 480
trap+ac0 (?,?,?,?) ra ffffffff803ad240 sp ffffffff80470a20 sz 256
MipsKernGenException+154 (ffffffffc0000004,0,1,ffffffffc0030000) ra
ffffffff803ca5e4 sp ffffffff80470b20 sz 368
ffffffff803ca5b0+34 (?,?,?,?) ra 0 sp ffffffff80470c90 sz 0
pid 0
db> show registers
at          0xffffffff804417d8
v0                 0x1
v1                   0
a0                   0
a1                   0
a2                   0
a3          0xffffffff80470900
t0          0xffffffff803969fc
t1              0x1000
t2                   0
t3                   0
t4          0xffffffff804708e8
t5          0xffffffff804708f0
t6          0xffffffff80470840
t7          0xffffffff80470844
s0          0xffffffff80470b40
s1            0x4eb000
s2                   0
s3                 0x2
s4                   0
--More--        s5          0xffffffff8044fa58
--More--        s6          0xffffffff80470900
s7                   0
t8                   0
t9                   0
k0                   0
k1                   0
gp          0xffffffff80440840
sp          0xffffffff804707b0
s8          0xffffffffc0000000
ra          0xffffffff80388088
sr          0x20100002
lo                0x48
hi                   0
bad               0xcd
cs              0x8c08
pc          0xffffffff80385c64
0xffffffff80385c64:     lbu     v0,205(a0)
db>

-- 
Regards
Vladimir 'φ-coder/phcoder' Serbinenko




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?4BFEBFE6.5000107>