entry26.S 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. /*
  2. NetWinder Floating Point Emulator
  3. (c) Rebel.COM, 1998
  4. (c) Philip Blundell 1998-1999
  5. Direct questions, comments to Scott Bambrough <scottb@netwinder.org>
  6. This program is free software; you can redistribute it and/or modify
  7. it under the terms of the GNU General Public License as published by
  8. the Free Software Foundation; either version 2 of the License, or
  9. (at your option) any later version.
  10. This program is distributed in the hope that it will be useful,
  11. but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. GNU General Public License for more details.
  14. You should have received a copy of the GNU General Public License
  15. along with this program; if not, write to the Free Software
  16. Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  17. */
  18. #include <asm/asm-offsets.h>
  19. /* This is the kernel's entry point into the floating point emulator.
  20. It is called from the kernel with code similar to this:
  21. mov fp, #0
  22. teqp pc, #PSR_I_BIT | SVC_MODE
  23. ldr r4, .LC2
  24. ldr pc, [r4] @ Call FP module USR entry point
  25. The kernel expects the emulator to return via one of two possible
  26. points of return it passes to the emulator. The emulator, if
  27. successful in its emulation, jumps to ret_from_exception and the
  28. kernel takes care of returning control from the trap to the user code.
  29. If the emulator is unable to emulate the instruction, it returns to
  30. fpundefinstr and the kernel halts the user program with a core dump.
  31. This routine does four things:
  32. 1) It saves SP into a variable called userRegisters. The kernel has
  33. created a struct pt_regs on the stack and saved the user registers
  34. into it. See /usr/include/asm/proc/ptrace.h for details. The
  35. emulator code uses userRegisters as the base of an array of words from
  36. which the contents of the registers can be extracted.
  37. 2) It locates the FP emulator work area within the TSS structure and
  38. points `fpa11' to it.
  39. 3) It calls EmulateAll to emulate a floating point instruction.
  40. EmulateAll returns 1 if the emulation was successful, or 0 if not.
  41. 4) If an instruction has been emulated successfully, it looks ahead at
  42. the next instruction. If it is a floating point instruction, it
  43. executes the instruction, without returning to user space. In this
  44. way it repeatedly looks ahead and executes floating point instructions
  45. until it encounters a non floating point instruction, at which time it
  46. returns via _fpreturn.
  47. This is done to reduce the effect of the trap overhead on each
  48. floating point instructions. GCC attempts to group floating point
  49. instructions to allow the emulator to spread the cost of the trap over
  50. several floating point instructions. */
  51. .globl nwfpe_enter
  52. nwfpe_enter:
  53. mov sl, sp
  54. ldr r5, [sp, #60] @ get contents of PC
  55. bic r5, r5, #0xfc000003
  56. ldr r0, [r5, #-4] @ get actual instruction into r0
  57. bl EmulateAll @ emulate the instruction
  58. 1: cmp r0, #0 @ was emulation successful
  59. beq fpundefinstr @ no, return failure
  60. next:
  61. .Lx1: ldrt r6, [r5], #4 @ get the next instruction and
  62. @ increment PC
  63. and r2, r6, #0x0F000000 @ test for FP insns
  64. teq r2, #0x0C000000
  65. teqne r2, #0x0D000000
  66. teqne r2, #0x0E000000
  67. bne ret_from_exception @ return ok if not a fp insn
  68. ldr r9, [sp, #60] @ get new condition codes
  69. and r9, r9, #0xfc000003
  70. orr r7, r5, r9
  71. str r7, [sp, #60] @ update PC copy in regs
  72. mov r0, r6 @ save a copy
  73. mov r1, r9 @ fetch the condition codes
  74. bl checkCondition @ check the condition
  75. cmp r0, #0 @ r0 = 0 ==> condition failed
  76. @ if condition code failed to match, next insn
  77. beq next @ get the next instruction;
  78. mov r0, r6 @ prepare for EmulateAll()
  79. adr lr, 1b
  80. orr lr, lr, #3
  81. b EmulateAll @ if r0 != 0, goto EmulateAll
  82. .Lret: b ret_from_exception @ let the user eat segfaults
  83. @ We need to be prepared for the instruction at .Lx1 to fault.
  84. @ Emit the appropriate exception gunk to fix things up.
  85. .section __ex_table,"a"
  86. .align 3
  87. .long .Lx1
  88. ldr lr, [lr, $(.Lret - .Lx1)/4]
  89. .previous