Alternative library and kernel for add-in development on fx-9860G and fx-CG50 under Linux.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

64 lines
1.4KB

  1. //---
  2. // gint:core:gint - Library functions
  3. //---
  4. #include <gint/gint.h>
  5. #include <core/std.h>
  6. #include <gint/mpu.h>
  7. #include <gint/mpu/intc.h>
  8. /* Interrupt controllers */
  9. GDATA3 sh7705_intc_t SH7705_INTC = {
  10. .IPRS = {
  11. (void *)0xfffffee2, (void *)0xfffffee4,
  12. (void *)0xa4000016, (void *)0xa4000018, (void *)0xa400001a,
  13. (void *)0xa4080000, (void *)0xa4080002, (void *)0xa4080004,
  14. },
  15. .ICR1 = (void *)0xa4000010,
  16. };
  17. GDATA sh7305_intc_t SH7305_INTC = {
  18. .IPRS = (void *)0xa4080000,
  19. .MSK = (void *)0xa4080080,
  20. .MSKCLR = (void *)0xa40800c0,
  21. .USERIMASK = (void *)0xa4700000,
  22. };
  23. //---
  24. // Library functions
  25. //---
  26. /* gint_intlevel() - configure the level of interrupts */
  27. int gint_intlevel(int intid, int level)
  28. {
  29. int shift = (~intid & 0x3) << 2;
  30. volatile uint16_t *ipr;
  31. level &= 0xf;
  32. ipr = isSH3()
  33. ? SH7705_INTC.IPRS[intid >> 2] /* SH3-based */
  34. : &SH7305_INTC.IPRS[2 * (intid >> 2)]; /* SH4-based */
  35. int oldlevel = (*ipr >> shift) & 0xf;
  36. *ipr = (*ipr & ~(0xf << shift)) | (level << shift);
  37. return oldlevel;
  38. }
  39. /* gint_inthandler() - configure interrupt handlers */
  40. void *gint_inthandler(int event_code, const void *handler, size_t size)
  41. {
  42. extern char gint_vbr;
  43. /* Normalize the event code */
  44. event_code -= 0x400;
  45. event_code &= ~0x1f;
  46. /* Prevent overriding the entry gate */
  47. if(event_code < 0) return NULL;
  48. void *dest = (void *)&gint_vbr + event_code + 0x620;
  49. return memcpy(dest, handler, size);
  50. }