1 /*--------------------------------------------------------------------------
3 -- Identity : Linux50 Debug Funcions
5 -- File : arch/sh/lib64/dbg.c
7 -- Copyright 2000, 2001 STMicroelectronics Limited.
8 -- Copyright 2004 Richard Curnow (evt_debug etc)
10 --------------------------------------------------------------------------*/
11 #include <linux/types.h>
12 #include <linux/kernel.h>
13 #include <linux/sched.h>
16 #include <asm/mmu_context.h>
18 typedef u64 regType_t;
20 static regType_t getConfigReg(u64 id)
22 register u64 reg __asm__("r2");
23 asm volatile ("getcfg %1, 0, %0":"=r" (reg):"r"(id));
27 /* ======================================================================= */
29 static char *szTab[] = { "4k", "64k", "1M", "512M" };
30 static char *protTab[] = { "----",
47 #define ITLB_BASE 0x00000000
48 #define DTLB_BASE 0x00800000
51 #define GET_VALID(pte) ((pte) & 0x1)
52 #define GET_SHARED(pte) ((pte) & 0x2)
53 #define GET_ASID(pte) ((pte >> 2) & 0x0ff)
54 #define GET_EPN(pte) ((pte) & 0xfffff000)
57 #define GET_CBEHAVIOR(pte) ((pte) & 0x3)
58 #define GET_PAGE_SIZE(pte) szTab[((pte >> 3) & 0x3)]
59 #define GET_PROTECTION(pte) protTab[((pte >> 6) & 0xf)]
60 #define GET_PPN(pte) ((pte) & 0xfffff000)
62 #define PAGE_1K_MASK 0x00000000
63 #define PAGE_4K_MASK 0x00000010
64 #define PAGE_64K_MASK 0x00000080
65 #define MMU_PAGESIZE_MASK (PAGE_64K_MASK | PAGE_4K_MASK)
66 #define PAGE_1MB_MASK MMU_PAGESIZE_MASK
67 #define PAGE_1K (1024)
68 #define PAGE_4K (1024 * 4)
69 #define PAGE_64K (1024 * 64)
70 #define PAGE_1MB (1024 * 1024)
72 #define HOW_TO_READ_TLB_CONTENT \
73 "[ ID] PPN EPN ASID Share CB P.Size PROT.\n"
75 void print_single_tlb(unsigned long tlb, int single_print)
79 unsigned int valid, shared, asid, epn, cb, ppn;
84 ** in case of single print <single_print> is true, this implies:
85 ** 1) print the TLB in any case also if NOT VALID
86 ** 2) print out the header
89 pteH = getConfigReg(tlb);
90 valid = GET_VALID(pteH);
92 printk(HOW_TO_READ_TLB_CONTENT);
96 pteL = getConfigReg(tlb + 1);
98 shared = GET_SHARED(pteH);
99 asid = GET_ASID(pteH);
101 cb = GET_CBEHAVIOR(pteL);
102 pSize = GET_PAGE_SIZE(pteL);
103 pProt = GET_PROTECTION(pteL);
105 printk("[%c%2ld] 0x%08x 0x%08x %03d %02x %02x %4s %s\n",
106 ((valid) ? ' ' : 'u'), ((tlb & 0x0ffff) / TLB_STEP),
107 ppn, epn, asid, shared, cb, pSize, pProt);
110 void print_dtlb(void)
115 printk(" ================= SH-5 D-TLBs Status ===================\n");
116 printk(HOW_TO_READ_TLB_CONTENT);
118 for (count = 0; count < MAX_TLBs; count++, tlb += TLB_STEP)
119 print_single_tlb(tlb, 0);
121 (" =============================================================\n");
124 void print_itlb(void)
129 printk(" ================= SH-5 I-TLBs Status ===================\n");
130 printk(HOW_TO_READ_TLB_CONTENT);
132 for (count = 0; count < MAX_TLBs; count++, tlb += TLB_STEP)
133 print_single_tlb(tlb, 0);
135 (" =============================================================\n");
138 /* ======================================================================= */
140 #ifdef CONFIG_POOR_MANS_STRACE
142 #include "syscalltab.h"
154 static struct ring_node event_ring[16];
155 static int event_ptr = 0;
157 struct stored_syscall_data {
162 #define N_STORED_SYSCALLS 16
164 static struct stored_syscall_data stored_syscalls[N_STORED_SYSCALLS];
165 static int syscall_next=0;
166 static int syscall_next_print=0;
168 void evt_debug(int evt, int ret_addr, int event, int tra, struct pt_regs *regs)
170 int syscallno = tra & 0xff;
172 unsigned long stack_bottom;
174 struct ring_node *rr;
177 stack_bottom = (unsigned long) task_stack_page(current);
178 asm volatile("ori r15, 0, %0" : "=r" (sp));
179 rr = event_ring + event_ptr;
181 rr->ret_addr = ret_addr;
188 if (sp < stack_bottom + 3092) {
190 printk("evt_debug : stack underflow report\n");
191 for (j=0, i = event_ptr; j<16; j++) {
193 printk("evt=%08x event=%08x tra=%08x pid=%5d sp=%08lx pc=%08lx\n",
194 rr->evt, rr->event, rr->tra, rr->pid, rr->sp, rr->pc);
198 panic("STACK UNDERFLOW\n");
201 event_ptr = (event_ptr + 1) & 15;
203 if ((event == 2) && (evt == 0x160)) {
204 if (syscallno < NUM_SYSCALL_INFO_ENTRIES) {
205 /* Store the syscall information to print later. We
206 * can't print this now - currently we're running with
207 * SR.BL=1, so we can't take a tlbmiss (which could occur
208 * in the console drivers under printk).
210 * Just overwrite old entries on ring overflow - this
211 * is only for last-hope debugging. */
212 stored_syscalls[syscall_next].pid = current->pid;
213 stored_syscalls[syscall_next].syscall_number = syscallno;
215 syscall_next &= (N_STORED_SYSCALLS - 1);
220 static void drain_syscalls(void) {
221 while (syscall_next_print != syscall_next) {
222 printk("Task %d: %s()\n",
223 stored_syscalls[syscall_next_print].pid,
224 syscall_info_table[stored_syscalls[syscall_next_print].syscall_number].name);
225 syscall_next_print++;
226 syscall_next_print &= (N_STORED_SYSCALLS - 1);
230 void evt_debug2(unsigned int ret)
233 printk("Task %d: syscall returns %08x\n", current->pid, ret);
236 void evt_debug_ret_from_irq(struct pt_regs *regs)
239 struct ring_node *rr;
242 rr = event_ring + event_ptr;
249 event_ptr = (event_ptr + 1) & 15;
252 void evt_debug_ret_from_exc(struct pt_regs *regs)
255 struct ring_node *rr;
258 rr = event_ring + event_ptr;
265 event_ptr = (event_ptr + 1) & 15;
268 #endif /* CONFIG_POOR_MANS_STRACE */
270 /* ======================================================================= */
272 void show_excp_regs(char *from, int trapnr, int signr, struct pt_regs *regs)
275 unsigned long long ah, al, bh, bl, ch, cl;
278 printk("EXCEPTION - %s: task %d; Linux trap # %d; signal = %d\n",
279 ((from) ? from : "???"), current->pid, trapnr, signr);
281 asm volatile ("getcon " __EXPEVT ", %0":"=r"(ah));
282 asm volatile ("getcon " __EXPEVT ", %0":"=r"(al));
284 al = (al) & 0xffffffff;
285 asm volatile ("getcon " __KCR1 ", %0":"=r"(bh));
286 asm volatile ("getcon " __KCR1 ", %0":"=r"(bl));
288 bl = (bl) & 0xffffffff;
289 asm volatile ("getcon " __INTEVT ", %0":"=r"(ch));
290 asm volatile ("getcon " __INTEVT ", %0":"=r"(cl));
292 cl = (cl) & 0xffffffff;
293 printk("EXPE: %08Lx%08Lx KCR1: %08Lx%08Lx INTE: %08Lx%08Lx\n",
294 ah, al, bh, bl, ch, cl);
296 asm volatile ("getcon " __PEXPEVT ", %0":"=r"(ah));
297 asm volatile ("getcon " __PEXPEVT ", %0":"=r"(al));
299 al = (al) & 0xffffffff;
300 asm volatile ("getcon " __PSPC ", %0":"=r"(bh));
301 asm volatile ("getcon " __PSPC ", %0":"=r"(bl));
303 bl = (bl) & 0xffffffff;
304 asm volatile ("getcon " __PSSR ", %0":"=r"(ch));
305 asm volatile ("getcon " __PSSR ", %0":"=r"(cl));
307 cl = (cl) & 0xffffffff;
308 printk("PEXP: %08Lx%08Lx PSPC: %08Lx%08Lx PSSR: %08Lx%08Lx\n",
309 ah, al, bh, bl, ch, cl);
311 ah = (regs->pc) >> 32;
312 al = (regs->pc) & 0xffffffff;
313 bh = (regs->regs[18]) >> 32;
314 bl = (regs->regs[18]) & 0xffffffff;
315 ch = (regs->regs[15]) >> 32;
316 cl = (regs->regs[15]) & 0xffffffff;
317 printk("PC : %08Lx%08Lx LINK: %08Lx%08Lx SP : %08Lx%08Lx\n",
318 ah, al, bh, bl, ch, cl);
320 ah = (regs->sr) >> 32;
321 al = (regs->sr) & 0xffffffff;
322 asm volatile ("getcon " __TEA ", %0":"=r"(bh));
323 asm volatile ("getcon " __TEA ", %0":"=r"(bl));
325 bl = (bl) & 0xffffffff;
326 asm volatile ("getcon " __KCR0 ", %0":"=r"(ch));
327 asm volatile ("getcon " __KCR0 ", %0":"=r"(cl));
329 cl = (cl) & 0xffffffff;
330 printk("SR : %08Lx%08Lx TEA : %08Lx%08Lx KCR0: %08Lx%08Lx\n",
331 ah, al, bh, bl, ch, cl);
333 ah = (regs->regs[0]) >> 32;
334 al = (regs->regs[0]) & 0xffffffff;
335 bh = (regs->regs[1]) >> 32;
336 bl = (regs->regs[1]) & 0xffffffff;
337 ch = (regs->regs[2]) >> 32;
338 cl = (regs->regs[2]) & 0xffffffff;
339 printk("R0 : %08Lx%08Lx R1 : %08Lx%08Lx R2 : %08Lx%08Lx\n",
340 ah, al, bh, bl, ch, cl);
342 ah = (regs->regs[3]) >> 32;
343 al = (regs->regs[3]) & 0xffffffff;
344 bh = (regs->regs[4]) >> 32;
345 bl = (regs->regs[4]) & 0xffffffff;
346 ch = (regs->regs[5]) >> 32;
347 cl = (regs->regs[5]) & 0xffffffff;
348 printk("R3 : %08Lx%08Lx R4 : %08Lx%08Lx R5 : %08Lx%08Lx\n",
349 ah, al, bh, bl, ch, cl);
351 ah = (regs->regs[6]) >> 32;
352 al = (regs->regs[6]) & 0xffffffff;
353 bh = (regs->regs[7]) >> 32;
354 bl = (regs->regs[7]) & 0xffffffff;
355 ch = (regs->regs[8]) >> 32;
356 cl = (regs->regs[8]) & 0xffffffff;
357 printk("R6 : %08Lx%08Lx R7 : %08Lx%08Lx R8 : %08Lx%08Lx\n",
358 ah, al, bh, bl, ch, cl);
360 ah = (regs->regs[9]) >> 32;
361 al = (regs->regs[9]) & 0xffffffff;
362 bh = (regs->regs[10]) >> 32;
363 bl = (regs->regs[10]) & 0xffffffff;
364 ch = (regs->regs[11]) >> 32;
365 cl = (regs->regs[11]) & 0xffffffff;
366 printk("R9 : %08Lx%08Lx R10 : %08Lx%08Lx R11 : %08Lx%08Lx\n",
367 ah, al, bh, bl, ch, cl);
370 ah = (regs->tregs[0]) >> 32;
371 al = (regs->tregs[0]) & 0xffffffff;
372 bh = (regs->tregs[1]) >> 32;
373 bl = (regs->tregs[1]) & 0xffffffff;
374 ch = (regs->tregs[2]) >> 32;
375 cl = (regs->tregs[2]) & 0xffffffff;
376 printk("T0 : %08Lx%08Lx T1 : %08Lx%08Lx T2 : %08Lx%08Lx\n",
377 ah, al, bh, bl, ch, cl);
384 /* ======================================================================= */
387 ** Depending on <base> scan the MMU, Data or Instruction side
388 ** looking for a valid mapping matching Eaddr & asid.
389 ** Return -1 if not found or the TLB id entry otherwise.
390 ** Note: it works only for 4k pages!
393 lookup_mmu_side(unsigned long base, unsigned long Eaddr, unsigned long asid)
399 epn = Eaddr & 0xfffff000;
401 for (count = 0; count < MAX_TLBs; count++, base += TLB_STEP) {
402 pteH = getConfigReg(base);
404 if ((unsigned long) GET_EPN(pteH) == epn)
405 if ((unsigned long) GET_ASID(pteH) == asid)
408 return ((unsigned long) ((count < MAX_TLBs) ? base : -1));
411 unsigned long lookup_dtlb(unsigned long Eaddr)
413 unsigned long asid = get_asid();
414 return (lookup_mmu_side((u64) DTLB_BASE, Eaddr, asid));
417 unsigned long lookup_itlb(unsigned long Eaddr)
419 unsigned long asid = get_asid();
420 return (lookup_mmu_side((u64) ITLB_BASE, Eaddr, asid));
423 void print_page(struct page *page)
425 printk(" page[%p] -> index 0x%lx, count 0x%x, flags 0x%lx\n",
426 page, page->index, page_count(page), page->flags);
427 printk(" address_space = %p, pages =%ld\n", page->mapping,
428 page->mapping->nrpages);