Staging: comedi: hwdrv_apci2032.c: static sparse fix
[linux/fpc-iii.git] / arch / powerpc / kernel / softemu8xx.c
blobaf0e8290b4fc4f90faf3f59136683c10f3c47971
1 /*
2 * Software emulation of some PPC instructions for the 8xx core.
4 * Copyright (C) 1998 Dan Malek (dmalek@jlc.net)
6 * Software floating emuation for the MPC8xx processor. I did this mostly
7 * because it was easier than trying to get the libraries compiled for
8 * software floating point. The goal is still to get the libraries done,
9 * but I lost patience and needed some hacks to at least get init and
10 * shells running. The first problem is the setjmp/longjmp that save
11 * and restore the floating point registers.
13 * For this emulation, our working registers are found on the register
14 * save area.
17 #include <linux/errno.h>
18 #include <linux/sched.h>
19 #include <linux/kernel.h>
20 #include <linux/mm.h>
21 #include <linux/stddef.h>
22 #include <linux/unistd.h>
23 #include <linux/ptrace.h>
24 #include <linux/user.h>
25 #include <linux/interrupt.h>
27 #include <asm/pgtable.h>
28 #include <asm/uaccess.h>
29 #include <asm/system.h>
30 #include <asm/io.h>
32 /* Eventually we may need a look-up table, but this works for now.
34 #define LFS 48
35 #define LFD 50
36 #define LFDU 51
37 #define STFD 54
38 #define STFDU 55
39 #define FMR 63
41 void print_8xx_pte(struct mm_struct *mm, unsigned long addr)
43 pgd_t *pgd;
44 pmd_t *pmd;
45 pte_t *pte;
47 printk(" pte @ 0x%8lx: ", addr);
48 pgd = pgd_offset(mm, addr & PAGE_MASK);
49 if (pgd) {
50 pmd = pmd_offset(pud_offset(pgd, addr & PAGE_MASK),
51 addr & PAGE_MASK);
52 if (pmd && pmd_present(*pmd)) {
53 pte = pte_offset_kernel(pmd, addr & PAGE_MASK);
54 if (pte) {
55 printk(" (0x%08lx)->(0x%08lx)->0x%08lx\n",
56 (long)pgd, (long)pte, (long)pte_val(*pte));
57 #define pp ((long)pte_val(*pte))
58 printk(" RPN: %05lx PP: %lx SPS: %lx SH: %lx "
59 "CI: %lx v: %lx\n",
60 pp>>12, /* rpn */
61 (pp>>10)&3, /* pp */
62 (pp>>3)&1, /* small */
63 (pp>>2)&1, /* shared */
64 (pp>>1)&1, /* cache inhibit */
65 pp&1 /* valid */
67 #undef pp
69 else {
70 printk("no pte\n");
73 else {
74 printk("no pmd\n");
77 else {
78 printk("no pgd\n");
82 int get_8xx_pte(struct mm_struct *mm, unsigned long addr)
84 pgd_t *pgd;
85 pmd_t *pmd;
86 pte_t *pte;
87 int retval = 0;
89 pgd = pgd_offset(mm, addr & PAGE_MASK);
90 if (pgd) {
91 pmd = pmd_offset(pud_offset(pgd, addr & PAGE_MASK),
92 addr & PAGE_MASK);
93 if (pmd && pmd_present(*pmd)) {
94 pte = pte_offset_kernel(pmd, addr & PAGE_MASK);
95 if (pte) {
96 retval = (int)pte_val(*pte);
100 return retval;
104 * We return 0 on success, 1 on unimplemented instruction, and EFAULT
105 * if a load/store faulted.
107 int Soft_emulate_8xx(struct pt_regs *regs)
109 u32 inst, instword;
110 u32 flreg, idxreg, disp;
111 int retval;
112 s16 sdisp;
113 u32 *ea, *ip;
115 retval = 0;
117 instword = *((u32 *)regs->nip);
118 inst = instword >> 26;
120 flreg = (instword >> 21) & 0x1f;
121 idxreg = (instword >> 16) & 0x1f;
122 disp = instword & 0xffff;
124 ea = (u32 *)(regs->gpr[idxreg] + disp);
125 ip = (u32 *)&current->thread.TS_FPR(flreg);
127 switch ( inst )
129 case LFD:
130 /* this is a 16 bit quantity that is sign extended
131 * so use a signed short here -- Cort
133 sdisp = (instword & 0xffff);
134 ea = (u32 *)(regs->gpr[idxreg] + sdisp);
135 if (copy_from_user(ip, ea, sizeof(double)))
136 retval = -EFAULT;
137 break;
139 case LFDU:
140 if (copy_from_user(ip, ea, sizeof(double)))
141 retval = -EFAULT;
142 else
143 regs->gpr[idxreg] = (u32)ea;
144 break;
145 case LFS:
146 sdisp = (instword & 0xffff);
147 ea = (u32 *)(regs->gpr[idxreg] + sdisp);
148 if (copy_from_user(ip, ea, sizeof(float)))
149 retval = -EFAULT;
150 break;
151 case STFD:
152 /* this is a 16 bit quantity that is sign extended
153 * so use a signed short here -- Cort
155 sdisp = (instword & 0xffff);
156 ea = (u32 *)(regs->gpr[idxreg] + sdisp);
157 if (copy_to_user(ea, ip, sizeof(double)))
158 retval = -EFAULT;
159 break;
161 case STFDU:
162 if (copy_to_user(ea, ip, sizeof(double)))
163 retval = -EFAULT;
164 else
165 regs->gpr[idxreg] = (u32)ea;
166 break;
167 case FMR:
168 /* assume this is a fp move -- Cort */
169 memcpy(ip, &current->thread.TS_FPR((instword>>11)&0x1f),
170 sizeof(double));
171 break;
172 default:
173 retval = 1;
174 printk("Bad emulation %s/%d\n"
175 " NIP: %08lx instruction: %08x opcode: %x "
176 "A: %x B: %x C: %x code: %x rc: %x\n",
177 current->comm,current->pid,
178 regs->nip,
179 instword,inst,
180 (instword>>16)&0x1f,
181 (instword>>11)&0x1f,
182 (instword>>6)&0x1f,
183 (instword>>1)&0x3ff,
184 instword&1);
186 int pa;
187 print_8xx_pte(current->mm,regs->nip);
188 pa = get_8xx_pte(current->mm,regs->nip) & PAGE_MASK;
189 pa |= (regs->nip & ~PAGE_MASK);
190 pa = (unsigned long)__va(pa);
191 printk("Kernel VA for NIP %x ", pa);
192 print_8xx_pte(current->mm,pa);
196 if (retval == 0)
197 regs->nip += 4;
199 return retval;