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
17 #include <linux/errno.h>
18 #include <linux/sched.h>
19 #include <linux/kernel.h>
21 #include <linux/stddef.h>
22 #include <linux/unistd.h>
23 #include <linux/ptrace.h>
24 #include <linux/slab.h>
25 #include <linux/user.h>
26 #include <linux/a.out.h>
27 #include <linux/interrupt.h>
29 #include <asm/pgtable.h>
30 #include <asm/uaccess.h>
31 #include <asm/system.h>
34 /* Eventually we may need a look-up table, but this works for now.
43 void print_8xx_pte(struct mm_struct *mm, unsigned long addr)
49 printk(" pte @ 0x%8lx: ", addr);
50 pgd = pgd_offset(mm, addr & PAGE_MASK);
52 pmd = pmd_offset(pud_offset(pgd, addr & PAGE_MASK),
54 if (pmd && pmd_present(*pmd)) {
55 pte = pte_offset_kernel(pmd, addr & PAGE_MASK);
57 printk(" (0x%08lx)->(0x%08lx)->0x%08lx\n",
58 (long)pgd, (long)pte, (long)pte_val(*pte));
59 #define pp ((long)pte_val(*pte))
60 printk(" RPN: %05lx PP: %lx SPS: %lx SH: %lx "
64 (pp>>3)&1, /* small */
65 (pp>>2)&1, /* shared */
66 (pp>>1)&1, /* cache inhibit */
84 int get_8xx_pte(struct mm_struct *mm, unsigned long addr)
91 pgd = pgd_offset(mm, addr & PAGE_MASK);
93 pmd = pmd_offset(pud_offset(pgd, addr & PAGE_MASK),
95 if (pmd && pmd_present(*pmd)) {
96 pte = pte_offset_kernel(pmd, addr & PAGE_MASK);
98 retval = (int)pte_val(*pte);
106 * We return 0 on success, 1 on unimplemented instruction, and EFAULT
107 * if a load/store faulted.
109 int Soft_emulate_8xx(struct pt_regs *regs)
112 u32 flreg, idxreg, disp;
119 instword = *((u32 *)regs->nip);
120 inst = instword >> 26;
122 flreg = (instword >> 21) & 0x1f;
123 idxreg = (instword >> 16) & 0x1f;
124 disp = instword & 0xffff;
126 ea = (u32 *)(regs->gpr[idxreg] + disp);
127 ip = (u32 *)¤t->thread.fpr[flreg];
132 /* this is a 16 bit quantity that is sign extended
133 * so use a signed short here -- Cort
135 sdisp = (instword & 0xffff);
136 ea = (u32 *)(regs->gpr[idxreg] + sdisp);
137 if (copy_from_user(ip, ea, sizeof(double)))
142 if (copy_from_user(ip, ea, sizeof(double)))
145 regs->gpr[idxreg] = (u32)ea;
148 sdisp = (instword & 0xffff);
149 ea = (u32 *)(regs->gpr[idxreg] + sdisp);
150 if (copy_from_user(ip, ea, sizeof(float)))
154 /* this is a 16 bit quantity that is sign extended
155 * so use a signed short here -- Cort
157 sdisp = (instword & 0xffff);
158 ea = (u32 *)(regs->gpr[idxreg] + sdisp);
159 if (copy_to_user(ea, ip, sizeof(double)))
164 if (copy_to_user(ea, ip, sizeof(double)))
167 regs->gpr[idxreg] = (u32)ea;
170 /* assume this is a fp move -- Cort */
171 memcpy(ip, ¤t->thread.fpr[(instword>>11)&0x1f],
176 printk("Bad emulation %s/%d\n"
177 " NIP: %08lx instruction: %08x opcode: %x "
178 "A: %x B: %x C: %x code: %x rc: %x\n",
179 current->comm,current->pid,
189 print_8xx_pte(current->mm,regs->nip);
190 pa = get_8xx_pte(current->mm,regs->nip) & PAGE_MASK;
191 pa |= (regs->nip & ~PAGE_MASK);
192 pa = (unsigned long)__va(pa);
193 printk("Kernel VA for NIP %x ", pa);
194 print_8xx_pte(current->mm,pa);