nios.h 2.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. /*
  2. * (C) Copyright 2003, Psyent Corporation <www.psyent.com>
  3. * Scott McNutt <smcnutt@psyent.com>
  4. *
  5. * See file CREDITS for list of people who contributed to this
  6. * project.
  7. *
  8. * This program is free software; you can redistribute it and/or
  9. * modify it under the terms of the GNU General Public License as
  10. * published by the Free Software Foundation; either version 2 of
  11. * the License, or (at your option) any later version.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License
  19. * along with this program; if not, write to the Free Software
  20. * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
  21. * MA 02111-1307 USA
  22. */
  23. #ifndef __NIOS_H__
  24. #define __NIOS_H__
  25. /*------------------------------------------------------------------------
  26. * Control registers -- use with wrctl() & rdctl()
  27. *----------------------------------------------------------------------*/
  28. #define CTL_STATUS 0x00 /* Processor status */
  29. #define CTL_ISTATUS 0x01 /* Saved status (exception) */
  30. #define CTL_WVALID 0x02 /* Valid window limit */
  31. #define CTL_ICACHE 0x05 /* I-cache line-invalidate */
  32. #define CTL_CPU_ID 0x06 /* CPU version id */
  33. #define CTL_DCACHE 0x07 /* D-cache line-invalidate */
  34. #define CTL_CLR_IE 0x08 /* Interrupt clear (disable) */
  35. #define CTL_SET_IE 0x09 /* Interrupt set (enable) */
  36. /*------------------------------------------------------------------------
  37. * Access to control regs
  38. *----------------------------------------------------------------------*/
  39. #define _str_(s) #s
  40. #define rdctl(reg)\
  41. ({unsigned int val;\
  42. asm volatile( "pfx " _str_(reg) "\n\t rdctl %0"\
  43. : "=r" (val) ); val;})
  44. #define wrctl(reg,val)\
  45. asm volatile( "pfx " _str_(reg) "\n\t wrctl %0 \n\t nop"\
  46. : : "r" (val))
  47. /*------------------------------------------------------------------------
  48. * Control reg bit masks
  49. *----------------------------------------------------------------------*/
  50. #define STATUS_DC (1<<17) /* Data cache enable */
  51. #define STATUS_IC (1<<16) /* Instruction cache enable */
  52. #define STATUS_IE (1<<15) /* Interrupt enable */
  53. #define STATUS_IPRI (0x3f<<9) /* Interrupt priority */
  54. #define STATUS_CWP (0x1f<<4) /* Current window pointer */
  55. #define STATUS_N (1<<3) /* Condition code: negative */
  56. #define STATUS_V (1<<2) /* Condition code: overflow */
  57. #define STATUS_Z (1<<1) /* Condition code: zero */
  58. #define STATUS_C (1<<0) /* Condition code: carry/borrow */
  59. static inline unsigned ipri( unsigned prio )
  60. {
  61. unsigned tmp;
  62. unsigned status = rdctl(CTL_STATUS);
  63. prio = (prio << 9) & STATUS_IPRI;
  64. tmp = (status & ~STATUS_IPRI) | prio;
  65. wrctl(CTL_STATUS,tmp);
  66. return( (status & STATUS_IPRI) >> 9);
  67. }
  68. #endif /* __NIOS_H__ */