PageRenderTime 41ms CodeModel.GetById 11ms RepoModel.GetById 0ms app.codeStats 0ms

/kern/arm32/shark/base_irq_inittab.S

https://bitbucket.org/mischief/oskit
Assembly | 304 lines | 266 code | 38 blank | 0 comment | 15 complexity | 41299b4761fa5c4962de0b9374a303c6 MD5 | raw file
Possible License(s): GPL-2.0
  1. /*
  2. * Copyright (c) 1999, 2000 University of Utah and the Flux Group.
  3. * All rights reserved.
  4. *
  5. * This file is part of the Flux OSKit. The OSKit is free software, also known
  6. * as "open source;" you can redistribute it and/or modify it under the terms
  7. * of the GNU General Public License (GPL), version 2, as published by the Free
  8. * Software Foundation (FSF). To explore alternate licensing terms, contact
  9. * the University of Utah at csl-dist@cs.utah.edu or +1-801-585-3271.
  10. *
  11. * The OSKit is distributed in the hope that it will be useful, but WITHOUT ANY
  12. * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
  13. * FOR A PARTICULAR PURPOSE. See the GPL for more details. You should have
  14. * received a copy of the GPL along with the OSKit; see the file COPYING. If
  15. * not, write to the FSF, 59 Temple Place #330, Boston, MA 02111-1307, USA.
  16. */
  17. /*
  18. * Copyright 1997
  19. * Digital Equipment Corporation. All rights reserved.
  20. *
  21. * This software is furnished under license and may be used and
  22. * copied only in accordance with the following terms and conditions.
  23. * Subject to these conditions, you may download, copy, install,
  24. * use, modify and distribute this software in source and/or binary
  25. * form. No title or ownership is transferred hereby.
  26. *
  27. * 1) Any source code used, modified or distributed must reproduce
  28. * and retain this copyright notice and list of conditions as
  29. * they appear in the source file.
  30. *
  31. * 2) No right is granted to use any trade name, trademark, or logo of
  32. * Digital Equipment Corporation. Neither the "Digital Equipment
  33. * Corporation" name nor any trademark or logo of Digital Equipment
  34. * Corporation may be used to endorse or promote products derived
  35. * from this software without the prior written permission of
  36. * Digital Equipment Corporation.
  37. *
  38. * 3) This software is provided "AS-IS" and any express or implied
  39. * warranties, including but not limited to, any implied warranties
  40. * of merchantability, fitness for a particular purpose, or
  41. * non-infringement are disclaimed. In no event shall DIGITAL be
  42. * liable for any damages whatsoever, and in particular, DIGITAL
  43. * shall not be liable for special, indirect, consequential, or
  44. * incidental damages or damages for lost profits, loss of
  45. * revenue or loss of use, whether such damages arise in contract,
  46. * negligence, tort, under statute, in equity, at law or otherwise,
  47. * even if advised of the possibility of such damage.
  48. */
  49. /*
  50. * Copyright (c) 1994-1998 Mark Brinicombe.
  51. * Copyright (c) 1994 Brini.
  52. * All rights reserved.
  53. *
  54. * This code is derived from software written for Brini by Mark Brinicombe
  55. *
  56. * Redistribution and use in source and binary forms, with or without
  57. * modification, are permitted provided that the following conditions
  58. * are met:
  59. * 1. Redistributions of source code must retain the above copyright
  60. * notice, this list of conditions and the following disclaimer.
  61. * 2. Redistributions in binary form must reproduce the above copyright
  62. * notice, this list of conditions and the following disclaimer in the
  63. * documentation and/or other materials provided with the distribution.
  64. * 3. All advertising materials mentioning features or use of this software
  65. * must display the following acknowledgement:
  66. * This product includes software developed by Mark Brinicombe
  67. * for the NetBSD Project.
  68. * 4. The name of the company nor the name of the author may be used to
  69. * endorse or promote products derived from this software without specific
  70. * prior written permission.
  71. *
  72. * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
  73. * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
  74. * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
  75. * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
  76. * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
  77. * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  78. * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  79. * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  80. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
  81. * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  82. */
  83. /*
  84. * Interrupt handler. This operates by looping through the request register
  85. * for each of the master and slaves (two loops). According to the NetBSD
  86. * documentation, ISA bus access is terribly slow, and NetBSD goes to great
  87. * pains to avoid it. I use a much simpler and slower approach, but this is
  88. * intended to be a prototype ...
  89. */
  90. #include <oskit/arm32/asm.h>
  91. #include <oskit/arm32/base_trap.h>
  92. #define IO_ICU1 0x20
  93. #define IO_ICU2 0xa0
  94. #define IO_ICU1_OCW 0x21
  95. #define IO_ICU2_OCW 0xa1
  96. #define ICU_EOI 0x20
  97. #define SLAVE_ON_IR2 0x04
  98. /*
  99. * r4 - irq counter for master and slave loop
  100. * r5 - slave imask
  101. * r6 - master imask
  102. * r7 - isa_iobus_address pointer
  103. * r8 - master iir
  104. * r9 - slave iir
  105. * r10 - trap state pointer
  106. */
  107. .text
  108. ENTRY(base_irq_trap_handler)
  109. stmfd sp!, {lr}
  110. mov r10, r0
  111. /*
  112. * Adjust the PC in the trap frame for an IRQ.
  113. */
  114. ldr r1, [r0, #(TRAP_STATE_PC)]
  115. sub r1, r1, #0x00000004
  116. str r1, [r0, #(TRAP_STATE_PC)]
  117. /*
  118. * Load the address of the ISA I/O bus, then indirect to read 8259
  119. * interrupt request registers.
  120. */
  121. ldr r7, Lisa_iobus_address
  122. ldr r7, [r7]
  123. ldrb r8, [r7, #IO_ICU1] /* ocw3 = irr */
  124. ldrb r9, [r7, #IO_ICU2] /* ocw3 = irr */
  125. bic r8, r8, #SLAVE_ON_IR2 /* always clear IRQ 2 (slave 8259) */
  126. /*
  127. * Increment the hardware interrupt nesting counter
  128. */
  129. ldr r2, Lbase_irq_nest
  130. ldr r3, [r2]
  131. add r3, r3, #0x1
  132. str r3, [r2]
  133. cmp r8, #0
  134. beq skipmpic
  135. /* Save the current master PIC mask */
  136. ldrb r6, [r7, #IO_ICU1_OCW]
  137. /* Remove masked bits from the master iir. */
  138. bic r8, r8, r6
  139. cmp r8, #0
  140. beq skipmpic
  141. /* Mask out the interrupting IRQs on the master */
  142. orr r3, r6, r8
  143. strb r3, [r7, #IO_ICU1_OCW]
  144. skipmpic:
  145. cmp r9, #0
  146. beq skipspic
  147. /* Save the current slave PIC mask */
  148. ldrb r5, [r7, #IO_ICU2_OCW]
  149. /* Remove masked bits from the slave iir */
  150. bic r9, r9, r5
  151. cmp r9, #0
  152. beq skipspic
  153. /* Mask out the interrupting IRQs on the slave */
  154. orr r3, r5, r9
  155. strb r3, [r7, #IO_ICU2_OCW]
  156. skipspic:
  157. /*
  158. * Now loop through and call the handler for each pending interrupt.
  159. */
  160. cmp r8, #0
  161. beq mskip
  162. mov r4, #0
  163. mloop:
  164. mov r3, #1
  165. mov r3, r3, lsl r4 /* Build the 1 bit mask */
  166. tst r8, r3 /* Is a bit set? */
  167. beq mnext /* No, then loop */
  168. /*
  169. * Call the interrupt handler. Be sure to stash the irq number
  170. * in the trap frame, and pass the stack pointer as arg0.
  171. */
  172. str r4, [r10, #(TRAP_STATE_INTNO)]
  173. ldr r3, Lbase_irq_handlers
  174. ldr r3, [r3, r4, asl #2] /* r3 = base_irq_handlers[irq] */
  175. mov r0, r10
  176. mov lr, pc
  177. mov pc, r3
  178. mnext:
  179. add r4, r4, #1 /* move on to next bit */
  180. cmp r4, #8 /* done the last bit ? */
  181. bmi mloop /* no - loop back. */
  182. /* Restore the interrupt mask */
  183. strb r6, [r7, #IO_ICU1_OCW]
  184. mskip:
  185. /*
  186. * Move to controller #2, and see what bits are set.
  187. */
  188. cmp r9, #0
  189. beq sskip
  190. mov r4, #0
  191. sloop:
  192. mov r3, #1
  193. mov r3, r3, lsl r4 /* Build the 1 bit mask */
  194. tst r9, r3 /* Is a bit set? */
  195. beq snext /* No, then loop */
  196. /*
  197. * Call the interrupt handler. Be sure to stash the irq number
  198. * in the trap frame, and pass the frame pointer as arg0. Note
  199. * that the irq numbering needs to be pushed up into 8-15.
  200. */
  201. add r2, r4, #8
  202. str r2, [r10, #(TRAP_STATE_INTNO)]
  203. ldr r3, Lbase_irq_handlers
  204. ldr r3, [r3, r2, asl #2] /* r3 = base_irq_handlers[irq] */
  205. mov r0, r10
  206. mov lr, pc
  207. mov pc, r3
  208. snext:
  209. add r4, r4, #1 /* move on to next bit */
  210. cmp r4, #8 /* done the last bit ? */
  211. bmi sloop /* no - loop back. */
  212. /* Restore the interrupt mask */
  213. strb r5, [r7, #IO_ICU2_OCW]
  214. sskip:
  215. /*
  216. * Decrement the hardware interrupt nesting counter
  217. */
  218. ldr r2, Lbase_irq_nest
  219. ldr r3, [r2]
  220. subs r3, r3, #0x1
  221. str r3, [r2]
  222. /*
  223. * Look for softints, base_irq_nest will be zero if one is pending.
  224. */
  225. bne nosoft /* Result of sub above */
  226. /*
  227. * XXX There should be a test to see if BASE_IRQ_SKIP_SOFTINT is set,
  228. * but since we run multiple handlers at once, kinda of a problem
  229. * until I get more ambitious and fix up the code above.
  230. */
  231. /*
  232. * Clear the pending indicator, disable softints, reenable HW ints
  233. * and call the softint handler.
  234. */
  235. mov r3, #0xC0 /* SOFTINT_DISABLED|SOFTINT_CLEARED */
  236. str r3, [r2]
  237. mrs r3, cpsr_all
  238. bic r3, r3, #0x80
  239. msr cpsr_all, r3
  240. mov r0, r10
  241. ldr r3, Lbase_irq_softint_handler
  242. ldr r3, [r3] /* r3 = *base_irq_softint_handler */
  243. mov lr, pc
  244. mov pc, r3
  245. /*
  246. * Reenable softints and disable HW interrupts
  247. */
  248. ldr r2, Lbase_irq_nest
  249. ldr r3, [r2]
  250. bic r3, r3, #0x40 /* SOFTINT_CLEARED */
  251. str r3, [r2]
  252. mrs r3, cpsr_all
  253. orr r3, r3, #0x80
  254. msr cpsr_all, r3
  255. nosoft:
  256. mov r0, #0
  257. ldmfd sp!, {pc}
  258. mov r0, r0
  259. Lisa_iobus_address:
  260. .word EXT(isa_iobus_address)
  261. Lbase_irq_nest:
  262. .word EXT(base_irq_nest)
  263. Lbase_irq_handlers:
  264. .word EXT(base_irq_handlers)
  265. Lbase_irq_softint_handler:
  266. .word EXT(base_irq_softint_handler)