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/user.h>
25 #include <linux/interrupt.h>
27 #include <asm/pgtable.h>
28 #include <asm/uaccess.h>
31 /* Eventually we may need a look-up table, but this works for now.
40 void print_8xx_pte(struct mm_struct
*mm
, unsigned long addr
)
46 printk(" pte @ 0x%8lx: ", addr
);
47 pgd
= pgd_offset(mm
, addr
& PAGE_MASK
);
49 pmd
= pmd_offset(pud_offset(pgd
, addr
& PAGE_MASK
),
51 if (pmd
&& pmd_present(*pmd
)) {
52 pte
= pte_offset_kernel(pmd
, addr
& PAGE_MASK
);
54 printk(" (0x%08lx)->(0x%08lx)->0x%08lx\n",
55 (long)pgd
, (long)pte
, (long)pte_val(*pte
));
56 #define pp ((long)pte_val(*pte))
57 printk(" RPN: %05lx PP: %lx SPS: %lx SH: %lx "
61 (pp
>>3)&1, /* small */
62 (pp
>>2)&1, /* shared */
63 (pp
>>1)&1, /* cache inhibit */
81 int get_8xx_pte(struct mm_struct
*mm
, unsigned long addr
)
88 pgd
= pgd_offset(mm
, addr
& PAGE_MASK
);
90 pmd
= pmd_offset(pud_offset(pgd
, addr
& PAGE_MASK
),
92 if (pmd
&& pmd_present(*pmd
)) {
93 pte
= pte_offset_kernel(pmd
, addr
& PAGE_MASK
);
95 retval
= (int)pte_val(*pte
);
103 * We return 0 on success, 1 on unimplemented instruction, and EFAULT
104 * if a load/store faulted.
106 int Soft_emulate_8xx(struct pt_regs
*regs
)
109 u32 flreg
, idxreg
, disp
;
116 instword
= *((u32
*)regs
->nip
);
117 inst
= instword
>> 26;
119 flreg
= (instword
>> 21) & 0x1f;
120 idxreg
= (instword
>> 16) & 0x1f;
121 disp
= instword
& 0xffff;
123 ea
= (u32
*)(regs
->gpr
[idxreg
] + disp
);
124 ip
= (u32
*)¤t
->thread
.TS_FPR(flreg
);
129 /* this is a 16 bit quantity that is sign extended
130 * so use a signed short here -- Cort
132 sdisp
= (instword
& 0xffff);
133 ea
= (u32
*)(regs
->gpr
[idxreg
] + sdisp
);
134 if (copy_from_user(ip
, ea
, sizeof(double)))
139 if (copy_from_user(ip
, ea
, sizeof(double)))
142 regs
->gpr
[idxreg
] = (u32
)ea
;
145 sdisp
= (instword
& 0xffff);
146 ea
= (u32
*)(regs
->gpr
[idxreg
] + sdisp
);
147 if (copy_from_user(ip
, ea
, sizeof(float)))
151 /* this is a 16 bit quantity that is sign extended
152 * so use a signed short here -- Cort
154 sdisp
= (instword
& 0xffff);
155 ea
= (u32
*)(regs
->gpr
[idxreg
] + sdisp
);
156 if (copy_to_user(ea
, ip
, sizeof(double)))
161 if (copy_to_user(ea
, ip
, sizeof(double)))
164 regs
->gpr
[idxreg
] = (u32
)ea
;
167 /* assume this is a fp move -- Cort */
168 memcpy(ip
, ¤t
->thread
.TS_FPR((instword
>>11)&0x1f),
173 printk("Bad emulation %s/%d\n"
174 " NIP: %08lx instruction: %08x opcode: %x "
175 "A: %x B: %x C: %x code: %x rc: %x\n",
176 current
->comm
,current
->pid
,
186 print_8xx_pte(current
->mm
,regs
->nip
);
187 pa
= get_8xx_pte(current
->mm
,regs
->nip
) & PAGE_MASK
;
188 pa
|= (regs
->nip
& ~PAGE_MASK
);
189 pa
= (unsigned long)__va(pa
);
190 printk("Kernel VA for NIP %x ", pa
);
191 print_8xx_pte(current
->mm
,pa
);