fpmodule.inl 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  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. extern __inline__
  18. unsigned int readRegister(const unsigned int nReg)
  19. {
  20. /* Note: The CPU thinks it has dealt with the current instruction. As
  21. a result the program counter has been advanced to the next
  22. instruction, and points 4 bytes beyond the actual instruction
  23. that caused the invalid instruction trap to occur. We adjust
  24. for this in this routine. LDF/STF instructions with Rn = PC
  25. depend on the PC being correct, as they use PC+8 in their
  26. address calculations. */
  27. unsigned int *userRegisters = GET_USERREG();
  28. unsigned int val = userRegisters[nReg];
  29. if (REG_PC == nReg) val -= 4;
  30. return val;
  31. }
  32. extern __inline__
  33. void writeRegister(const unsigned int nReg, const unsigned int val)
  34. {
  35. unsigned int *userRegisters = GET_USERREG();
  36. userRegisters[nReg] = val;
  37. }
  38. extern __inline__
  39. unsigned int readCPSR(void)
  40. {
  41. return(readRegister(REG_CPSR));
  42. }
  43. extern __inline__
  44. void writeCPSR(const unsigned int val)
  45. {
  46. writeRegister(REG_CPSR,val);
  47. }
  48. extern __inline__
  49. unsigned int readConditionCodes(void)
  50. {
  51. #ifdef __FPEM_TEST__
  52. return(0);
  53. #else
  54. return(readCPSR() & CC_MASK);
  55. #endif
  56. }
  57. extern __inline__
  58. void writeConditionCodes(const unsigned int val)
  59. {
  60. unsigned int *userRegisters = GET_USERREG();
  61. unsigned int rval;
  62. /*
  63. * Operate directly on userRegisters since
  64. * the CPSR may be the PC register itself.
  65. */
  66. rval = userRegisters[REG_CPSR] & ~CC_MASK;
  67. userRegisters[REG_CPSR] = rval | (val & CC_MASK);
  68. }
  69. extern __inline__
  70. unsigned int readMemoryInt(unsigned int *pMem)
  71. {
  72. return *pMem;
  73. }