summaryrefslogtreecommitdiff
path: root/tb/sim/irq.S
diff options
context:
space:
mode:
authorAlejandro Soto <alejandro@34project.org>2022-12-13 23:21:32 -0600
committerAlejandro Soto <alejandro@34project.org>2022-12-16 16:29:10 -0600
commit8c06c97c81339f68e06ff465aac2d8b1f2da4e27 (patch)
tree05e71f5508f4f00cb0abd6b0ec0d35d441313de8 /tb/sim/irq.S
parentf3c153f342ed969b1abfbe79d1017b651f21a649 (diff)
Implement interrupt emulation
Diffstat (limited to 'tb/sim/irq.S')
-rw-r--r--tb/sim/irq.S44
1 files changed, 44 insertions, 0 deletions
diff --git a/tb/sim/irq.S b/tb/sim/irq.S
new file mode 100644
index 0000000..35ce2c9
--- /dev/null
+++ b/tb/sim/irq.S
@@ -0,0 +1,44 @@
+.global reset
+reset:
+ # Stop and reset timer
+ ldr r2, =0x30020000
+ mov r1, #(1 << 3)
+ str r1, [r2, #4]
+ mov r1, #0
+ str r1, [r2, #0]
+
+ # Enable timer interrupts
+ ldr r3, =0x30070000
+ ldr r1, =(1 << 0)
+ str r1, [r3, #4]
+
+ # Enable IRQs
+ mov r0, #0
+ mrs r1, cpsr
+ and r1, #~(1 << 7)
+ msr cpsr_c, r1
+
+ # Program timer with timeout value of 128 cycles
+ mov r1, #4
+ str r1, [r2, #8]
+ mov r1, #0
+ str r1, [r2, #12]
+
+ # Start timer
+ mov r1, #(1 << 0 | 1 << 2)
+ str r1, [r2, #4]
+
+ .wfi:
+ tst r0, r0
+ beq .wfi
+
+ mov r2, #2
+ mov pc, lr
+
+.global irq
+irq:
+ mov r0, #1
+ ldr r1, [r2, #0]
+ mov r4, #0
+ str r4, [r2, #0]
+ subs pc, lr, #4