983855587025f281779cfc97bc8417a6ae5fc0c4
[akaros.git] / kern / arch / sparc / cpuinfo.c
1 #include <arch/sparc.h>
2 #include <arch/arch.h>
3 #include <arch/mmu.h>
4 #include <stdio.h>
5 #include <assert.h>
6 #include <smp.h>
7 #include <pmap.h>
8
9 #ifdef __SHARC__
10 #pragma nosharc
11 #endif
12
13 #ifdef __DEPUTY__
14 #pragma nodeputy
15 #endif
16
17 void
18 static_asserts_can_go_here()
19 {
20         static_assert(SIZEOF_TRAPFRAME_T == sizeof(trapframe_t));
21         static_assert(SIZEOF_TRAPFRAME_T % 8 == 0);
22         static_assert(SIZEOF_KERNEL_MESSAGE_T == sizeof(kernel_message_t));
23         static_assert(SIZEOF_KERNEL_MESSAGE_T % 8 == 0);
24         static_assert(offsetof(env_t,env_tf) % 8 == 0);
25         static_assert(offsetof(env_t,env_ancillary_state) % 8 == 0);
26 }
27
28 void
29 print_cpuinfo(void)
30 {
31         uint32_t psr = read_psr();
32         uint32_t wim = read_wim();
33         uint32_t tbr = read_tbr();
34
35         uint32_t mmucr  = read_mmu_reg(MMU_REG_CTRL);
36         uint32_t mmuctp = read_mmu_reg(MMU_REG_CTXTBL);
37         uint32_t mmuctx = read_mmu_reg(MMU_REG_CTX);
38         uint32_t mmufsr = read_mmu_reg(MMU_REG_FSR);
39         uint32_t mmufar = read_mmu_reg(MMU_REG_FAR);
40
41         cprintf("CPU Info:\n");
42         cprintf("ISA:             SPARC V8\n");
43         cprintf("Number of cores: %d\n",num_cpus);
44         cprintf("Implementation:  0x%x\n",(psr >> 28) & 0xF);
45         cprintf("Version:         0x%x\n",(psr >> 24) & 0xF);
46         cprintf("Current PSR:     0x%08x\n",psr);
47         cprintf("Current WIM:     0x%08x\n",wim);
48         cprintf("Current TBR:     0x%08x\n",tbr);
49
50         cprintf("SRMMU Info:\n");
51         cprintf("Implementation:  0x%x\n",(mmucr >> 28) & 0xF);
52         cprintf("Version:         0x%x\n",(mmucr >> 24) & 0xF);
53         cprintf("Current CR:      0x%08x\n",mmucr);
54         cprintf("Current CTP:     0x%08x\n",mmuctp);
55         cprintf("Current CTX:     0x%08x\n",mmuctx);
56         cprintf("Current FSR:     0x%08x\n",mmufsr);
57         cprintf("Current FAR:     0x%08x\n",mmufar);
58 }
59
60 void show_mapping(uintptr_t start, size_t size)
61 {
62         extern pde_t l1_page_table[NL1ENTRIES];
63         pte_t* pte;
64         uintptr_t i;
65         page_t* page;
66
67         cprintf("   Virtual    Physical  C M R ACC P\n");
68         cprintf("------------------------------------------\n");
69         for(i = 0; i < size; i += PGSIZE, start += PGSIZE)
70         {
71                 page = page_lookup(l1_page_table,(void*)start,&pte);
72                 cprintf("%08p  ",start);
73                 if(page)
74                 {
75                         cprintf("%08p  %1d %1d %1d  %1x  %1d\n",page2pa(page),
76                                 !!(*pte & PTE_C),!!(*pte & PTE_M),
77                                 !!(*pte & PTE_R),(*pte & PTE_ACC) >> 2,
78                                 !!(*pte & PTE_PTE));
79                 }
80                 else
81                         cprintf("%08p\n",0);
82         }
83 }
84
85 void
86 backtrace(void)
87 {
88         int i = 0, j;
89
90         flush_windows();
91
92         cprintf("Backtrace:\n");
93
94         // hack: assumes (correctly) we aren't a leaf routine
95         void *sp, *pc, *newsp;
96         __asm__ __volatile__ ("mov %%sp,%0" : "=r"(sp));
97
98         assert(sp >= (void*)KERNBASE);
99
100         newsp = *((void**)sp+14);
101         pc = *((void**)sp+15);
102
103         cprintf("initial sp = %x, newsp = %x, pc = %x\n",sp,newsp,pc);
104         assert(newsp >= (void*)KERNBASE);
105
106         while(newsp)
107         {
108                 cprintf("#%02d [<%x>]:\n",++i,pc);
109                 cprintf("    %%sp: %x   Args:",newsp);
110                 for(j = 8; j < 14; j++)
111                         cprintf(" %x",*((void**)sp+j));
112                 cprintf("\n");
113
114                 sp = newsp;
115
116                 if(sp >= (void*)KERNBASE && (void**)sp+16 > ((void**)0+16))
117                 {
118                         newsp = *((void**)sp+14);
119                         pc = *((void**)sp+15);
120                 }
121                 else if(current)
122                 {
123                         error_t ret;
124                         ret  = memcpy_from_user(current,&newsp,(void**)sp+14,sizeof(void*));
125                         ret |= memcpy_from_user(current,&pc,(void**)sp+15,sizeof(void*));
126                         if(ret)
127                         {
128                                 warn("Backtrace would have caused access exception; corrupt user stack?");
129                                 break;
130                         }
131                 }
132                 else
133                         break;
134         }
135 }