softemu8xx.c 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  1. /*
  2. * Software emulation of some PPC instructions for the 8xx core.
  3. *
  4. * Copyright (C) 1998 Dan Malek (dmalek@jlc.net)
  5. *
  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.
  12. *
  13. * For this emulation, our working registers are found on the register
  14. * save area.
  15. */
  16. #include <linux/errno.h>
  17. #include <linux/sched.h>
  18. #include <linux/kernel.h>
  19. #include <linux/mm.h>
  20. #include <linux/stddef.h>
  21. #include <linux/unistd.h>
  22. #include <linux/ptrace.h>
  23. #include <linux/slab.h>
  24. #include <linux/user.h>
  25. #include <linux/a.out.h>
  26. #include <linux/interrupt.h>
  27. #include <asm/pgtable.h>
  28. #include <asm/uaccess.h>
  29. #include <asm/system.h>
  30. #include <asm/io.h>
  31. extern void
  32. print_8xx_pte(struct mm_struct *mm, unsigned long addr);
  33. extern int
  34. get_8xx_pte(struct mm_struct *mm, unsigned long addr);
  35. /* Eventually we may need a look-up table, but this works for now.
  36. */
  37. #define LFS 48
  38. #define LFD 50
  39. #define LFDU 51
  40. #define STFD 54
  41. #define STFDU 55
  42. #define FMR 63
  43. /*
  44. * We return 0 on success, 1 on unimplemented instruction, and EFAULT
  45. * if a load/store faulted.
  46. */
  47. int
  48. Soft_emulate_8xx(struct pt_regs *regs)
  49. {
  50. uint inst, instword;
  51. uint flreg, idxreg, disp;
  52. uint retval;
  53. signed short sdisp;
  54. uint *ea, *ip;
  55. retval = 0;
  56. instword = *((uint *)regs->nip);
  57. inst = instword >> 26;
  58. flreg = (instword >> 21) & 0x1f;
  59. idxreg = (instword >> 16) & 0x1f;
  60. disp = instword & 0xffff;
  61. ea = (uint *)(regs->gpr[idxreg] + disp);
  62. ip = (uint *)&current->thread.fpr[flreg];
  63. switch ( inst )
  64. {
  65. case LFD:
  66. /* this is a 16 bit quantity that is sign extended
  67. * so use a signed short here -- Cort
  68. */
  69. sdisp = (instword & 0xffff);
  70. ea = (uint *)(regs->gpr[idxreg] + sdisp);
  71. if (copy_from_user(ip, ea, sizeof(double)))
  72. retval = -EFAULT;
  73. break;
  74. case LFDU:
  75. if (copy_from_user(ip, ea, sizeof(double)))
  76. retval = -EFAULT;
  77. else
  78. regs->gpr[idxreg] = (uint)ea;
  79. break;
  80. case LFS:
  81. sdisp = (instword & 0xffff);
  82. ea = (uint *)(regs->gpr[idxreg] + sdisp);
  83. if (copy_from_user(ip, ea, sizeof(float)))
  84. retval = -EFAULT;
  85. break;
  86. case STFD:
  87. /* this is a 16 bit quantity that is sign extended
  88. * so use a signed short here -- Cort
  89. */
  90. sdisp = (instword & 0xffff);
  91. ea = (uint *)(regs->gpr[idxreg] + sdisp);
  92. if (copy_to_user(ea, ip, sizeof(double)))
  93. retval = -EFAULT;
  94. break;
  95. case STFDU:
  96. if (copy_to_user(ea, ip, sizeof(double)))
  97. retval = -EFAULT;
  98. else
  99. regs->gpr[idxreg] = (uint)ea;
  100. break;
  101. case FMR:
  102. /* assume this is a fp move -- Cort */
  103. memcpy( ip, &current->thread.fpr[(instword>>11)&0x1f],
  104. sizeof(double) );
  105. break;
  106. default:
  107. retval = 1;
  108. printk("Bad emulation %s/%d\n"
  109. " NIP: %08lx instruction: %08x opcode: %x "
  110. "A: %x B: %x C: %x code: %x rc: %x\n",
  111. current->comm,current->pid,
  112. regs->nip,
  113. instword,inst,
  114. (instword>>16)&0x1f,
  115. (instword>>11)&0x1f,
  116. (instword>>6)&0x1f,
  117. (instword>>1)&0x3ff,
  118. instword&1);
  119. {
  120. int pa;
  121. print_8xx_pte(current->mm,regs->nip);
  122. pa = get_8xx_pte(current->mm,regs->nip) & PAGE_MASK;
  123. pa |= (regs->nip & ~PAGE_MASK);
  124. pa = (unsigned long)__va(pa);
  125. printk("Kernel VA for NIP %x ", pa);
  126. print_8xx_pte(current->mm,pa);
  127. }
  128. }
  129. if (retval == 0)
  130. regs->nip += 4;
  131. return(retval);
  132. }