pre-2.3.4..
[davej-history.git] / arch / ppc / kernel / softemu8xx.c
blob64f954b2e31cea612aab363e11b3e6e9b630b344
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/malloc.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>
32 #include <asm/io.h>
33 #include <asm/processor.h>
35 /* Eventually we may need a look-up table, but this works for now.
37 #define LFS 48
38 #define LFD 50
39 #define LFDU 51
40 #define STFD 54
41 #define STFDU 55
42 #define FMR 63
45 * We return 0 on success, 1 on unimplemented instruction, and EFAULT
46 * if a load/store faulted.
48 int
49 Soft_emulate_8xx(struct pt_regs *regs)
51 uint inst, instword;
52 uint flreg, idxreg, disp;
53 uint retval;
54 signed short sdisp;
55 uint *ea, *ip;
57 retval = 0;
59 instword = *((uint *)regs->nip);
60 inst = instword >> 26;
62 flreg = (instword >> 21) & 0x1f;
63 idxreg = (instword >> 16) & 0x1f;
64 disp = instword & 0xffff;
66 ea = (uint *)(regs->gpr[idxreg] + disp);
67 ip = (uint *)&current->tss.fpr[flreg];
69 switch ( inst )
71 case LFD:
72 /* this is a 16 bit quantity that is sign extended
73 * so use a signed short here -- Cort
75 sdisp = (instword & 0xffff);
76 ea = (uint *)(regs->gpr[idxreg] + sdisp);
77 if (copy_from_user(ip, ea, sizeof(double)))
78 retval = EFAULT;
79 break;
81 case LFDU:
82 if (copy_from_user(ip, ea, sizeof(double)))
83 retval = EFAULT;
84 else
85 regs->gpr[idxreg] = (uint)ea;
86 break;
87 case LFS:
88 sdisp = (instword & 0xffff);
89 ea = (uint *)(regs->gpr[idxreg] + sdisp);
90 if (copy_from_user(ip, ea, sizeof(float)))
91 retval = EFAULT;
92 break;
93 case STFD:
94 /* this is a 16 bit quantity that is sign extended
95 * so use a signed short here -- Cort
97 sdisp = (instword & 0xffff);
98 ea = (uint *)(regs->gpr[idxreg] + sdisp);
99 if (copy_to_user(ea, ip, sizeof(double)))
100 retval = EFAULT;
101 break;
103 case STFDU:
104 if (copy_to_user(ea, ip, sizeof(double)))
105 retval = EFAULT;
106 else
107 regs->gpr[idxreg] = (uint)ea;
108 break;
109 case FMR:
110 /* assume this is a fp move -- Cort */
111 memcpy( ip, &current->tss.fpr[(instword>>11)&0x1f],
112 sizeof(double) );
113 break;
114 default:
115 retval = 1;
116 printk("Bad emulation %s/%d\n"
117 " NIP: %08x instruction: %08x opcode: %x "
118 "A: %x B: %x C: %x code: %x rc: %x\n",
119 current->comm,current->pid,
120 regs->nip,
121 instword,inst,
122 (instword>>16)&0x1f,
123 (instword>>11)&0x1f,
124 (instword>>6)&0x1f,
125 (instword>>1)&0x3ff,
126 instword&1);
128 int pa;
129 print_8xx_pte(current->mm,regs->nip);
130 pa = get_8xx_pte(current->mm,regs->nip) & PAGE_MASK;
131 pa |= (regs->nip & ~PAGE_MASK);
132 pa = __va(pa);
133 printk("Kernel VA for NIP %x ", pa);
134 print_8xx_pte(current->mm,pa);
139 if (retval == 0)
140 regs->nip += 4;
141 return(retval);