fpmodule.inl 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. /*
  2. NetWinder Floating Point Emulator
  3. (c) Rebel.COM, 1998,1999
  4. Direct questions, comments to Scott Bambrough <scottb@netwinder.org>
  5. This program is free software; you can redistribute it and/or modify
  6. it under the terms of the GNU General Public License as published by
  7. the Free Software Foundation; either version 2 of the License, or
  8. (at your option) any later version.
  9. This program is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. GNU General Public License for more details.
  13. You should have received a copy of the GNU General Public License
  14. along with this program; if not, write to the Free Software
  15. Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  16. */
  17. static inline unsigned long readRegister(const unsigned int nReg)
  18. {
  19. /* Note: The CPU thinks it has dealt with the current instruction.
  20. As a result the program counter has been advanced to the next
  21. instruction, and points 4 bytes beyond the actual instruction
  22. that caused the invalid instruction trap to occur. We adjust
  23. for this in this routine. LDF/STF instructions with Rn = PC
  24. depend on the PC being correct, as they use PC+8 in their
  25. address calculations. */
  26. struct pt_regs *regs = GET_USERREG();
  27. unsigned int val = regs->uregs[nReg];
  28. if (REG_PC == nReg)
  29. val -= 4;
  30. return val;
  31. }
  32. static inline void
  33. writeRegister(const unsigned int nReg, const unsigned long val)
  34. {
  35. struct pt_regs *regs = GET_USERREG();
  36. regs->uregs[nReg] = val;
  37. }
  38. static inline unsigned long readCPSR(void)
  39. {
  40. return (readRegister(REG_CPSR));
  41. }
  42. static inline void writeCPSR(const unsigned long val)
  43. {
  44. writeRegister(REG_CPSR, val);
  45. }
  46. static inline unsigned long readConditionCodes(void)
  47. {
  48. #ifdef __FPEM_TEST__
  49. return (0);
  50. #else
  51. return (readCPSR() & CC_MASK);
  52. #endif
  53. }
  54. static inline void writeConditionCodes(const unsigned long val)
  55. {
  56. struct pt_regs *regs = GET_USERREG();
  57. unsigned long rval;
  58. /*
  59. * Operate directly on userRegisters since
  60. * the CPSR may be the PC register itself.
  61. */
  62. rval = regs->ARM_cpsr & ~CC_MASK;
  63. regs->ARM_cpsr = rval | (val & CC_MASK);
  64. }