fpu-ucf64.c 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. /*
  2. * linux/arch/unicore32/kernel/fpu-ucf64.c
  3. *
  4. * Code specific to PKUnity SoC and UniCore ISA
  5. *
  6. * Copyright (C) 2001-2010 GUAN Xue-tao
  7. *
  8. * This program is free software; you can redistribute it and/or modify
  9. * it under the terms of the GNU General Public License version 2 as
  10. * published by the Free Software Foundation.
  11. */
  12. #include <linux/module.h>
  13. #include <linux/types.h>
  14. #include <linux/kernel.h>
  15. #include <linux/signal.h>
  16. #include <linux/sched.h>
  17. #include <linux/init.h>
  18. #include <asm/fpu-ucf64.h>
  19. /*
  20. * A special flag to tell the normalisation code not to normalise.
  21. */
  22. #define F64_NAN_FLAG 0x100
  23. /*
  24. * A bit pattern used to indicate the initial (unset) value of the
  25. * exception mask, in case nothing handles an instruction. This
  26. * doesn't include the NAN flag, which get masked out before
  27. * we check for an error.
  28. */
  29. #define F64_EXCEPTION_ERROR ((u32)-1 & ~F64_NAN_FLAG)
  30. /*
  31. * Since we aren't building with -mfpu=f64, we need to code
  32. * these instructions using their MRC/MCR equivalents.
  33. */
  34. #define f64reg(_f64_) #_f64_
  35. #define cff(_f64_) ({ \
  36. u32 __v; \
  37. asm("cff %0, " f64reg(_f64_) "@ fmrx %0, " #_f64_ \
  38. : "=r" (__v) : : "cc"); \
  39. __v; \
  40. })
  41. #define ctf(_f64_, _var_) \
  42. asm("ctf %0, " f64reg(_f64_) "@ fmxr " #_f64_ ", %0" \
  43. : : "r" (_var_) : "cc")
  44. /*
  45. * Raise a SIGFPE for the current process.
  46. * sicode describes the signal being raised.
  47. */
  48. void ucf64_raise_sigfpe(unsigned int sicode, struct pt_regs *regs)
  49. {
  50. siginfo_t info;
  51. memset(&info, 0, sizeof(info));
  52. info.si_signo = SIGFPE;
  53. info.si_code = sicode;
  54. info.si_addr = (void __user *)(instruction_pointer(regs) - 4);
  55. /*
  56. * This is the same as NWFPE, because it's not clear what
  57. * this is used for
  58. */
  59. current->thread.error_code = 0;
  60. current->thread.trap_no = 6;
  61. send_sig_info(SIGFPE, &info, current);
  62. }
  63. /*
  64. * Handle exceptions of UniCore-F64.
  65. */
  66. void ucf64_exchandler(u32 inst, u32 fpexc, struct pt_regs *regs)
  67. {
  68. u32 tmp = fpexc;
  69. u32 exc = F64_EXCEPTION_ERROR & fpexc;
  70. pr_debug("UniCore-F64: instruction %08x fpscr %08x\n",
  71. inst, fpexc);
  72. if (exc & FPSCR_CMPINSTR_BIT) {
  73. if (exc & FPSCR_CON)
  74. tmp |= FPSCR_CON;
  75. else
  76. tmp &= ~(FPSCR_CON);
  77. exc &= ~(FPSCR_CMPINSTR_BIT | FPSCR_CON);
  78. } else {
  79. pr_debug("UniCore-F64 Error: unhandled exceptions\n");
  80. pr_debug("UniCore-F64 FPSCR 0x%08x INST 0x%08x\n",
  81. cff(FPSCR), inst);
  82. ucf64_raise_sigfpe(0, regs);
  83. return;
  84. }
  85. /*
  86. * Update the FPSCR with the additional exception flags.
  87. * Comparison instructions always return at least one of
  88. * these flags set.
  89. */
  90. tmp &= ~(FPSCR_TRAP | FPSCR_IOS | FPSCR_OFS | FPSCR_UFS |
  91. FPSCR_IXS | FPSCR_HIS | FPSCR_IOC | FPSCR_OFC |
  92. FPSCR_UFC | FPSCR_IXC | FPSCR_HIC);
  93. tmp |= exc;
  94. ctf(FPSCR, tmp);
  95. }
  96. /*
  97. * F64 support code initialisation.
  98. */
  99. static int __init ucf64_init(void)
  100. {
  101. ctf(FPSCR, 0x0); /* FPSCR_UFE | FPSCR_NDE perhaps better */
  102. printk(KERN_INFO "Enable UniCore-F64 support.\n");
  103. return 0;
  104. }
  105. late_initcall(ucf64_init);