summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThomas White <taw@physics.org>2018-07-28 20:42:25 +0200
committerThomas White <taw@physics.org>2018-07-28 20:42:25 +0200
commit354c532e19d9ab338720f3031ba8a0787886f4ee (patch)
tree16955e3e18c48b5a7d05b1e82493d2e3d52fc340
parentc4cdeef09cb36f0e7e9d84571a023f59b33b7d1c (diff)
Initial framebuffer stuffHEADmaster
-rw-r--r--Makefile4
-rw-r--r--src/framebuffer.s92
-rw-r--r--src/main.s5
-rw-r--r--src/ports.h24
4 files changed, 122 insertions, 3 deletions
diff --git a/Makefile b/Makefile
index b10fe7a..2dc1ae5 100644
--- a/Makefile
+++ b/Makefile
@@ -1,5 +1,5 @@
-SRCS=main.s slow_status_flash.s flash_button.s swi_handler.s
-OBJS=main.o slow_status_flash.o flash_button.o swi_handler.o
+SRCS=main.s slow_status_flash.s flash_button.s swi_handler.s framebuffer.s
+OBJS=main.o slow_status_flash.o flash_button.o swi_handler.o framebuffer.o
all: kernel.img
diff --git a/src/framebuffer.s b/src/framebuffer.s
new file mode 100644
index 0000000..ef3d9a1
--- /dev/null
+++ b/src/framebuffer.s
@@ -0,0 +1,92 @@
+/*
+ * framebuffer.s
+ *
+ * Copyright © 2018 Thomas White <taw@bitwiz.org.uk>
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ *
+ */
+
+.include "ports.h"
+
+.global framebuffer_init
+
+framebuffer_init:
+ STMDB R13!, {R14}
+
+ ADR R1, framebuffer_info
+ ADD R1, R1, #0x40000000
+ MOV R0, #1
+ BL send_mailbox
+@ BL read_mailbox
+
+ CMP R1, #0
+ LDMNEIA R13!, {PC} @ Fail
+
+ LDMIA R13!, {PC}
+
+
+/* -> R0 = mailbox number
+ * R1 = value to write */
+send_mailbox:
+ STMDB R13!, {R2, R8, R14}
+ LDR R8, =(PERIPHERAL_BASE+OFFS_MAILBOX)
+
+ /* Wait for empty mailbox */
+1:
+ LDR R2, [R8, #18]
+ TST R2, #1<<31
+ BNE 1b
+
+ AND R2, R0, #0xf
+ ORR R2, R2, R1
+ STR R2, [R8, #20]
+
+ LDMIA R13!, {R2, R8, PC}
+
+
+/* -> R0 = mailbox number
+ * <- R1 = value read */
+read_mailbox:
+ STMDB R13!, {R2, R8, R14}
+ LDR R8, =(PERIPHERAL_BASE+OFFS_MAILBOX)
+
+ /* Wait for non-empty mailbox */
+1:
+ LDR R2, [R8, #18]
+ TST R2, #1<<30
+ BNE 1b
+
+ LDR R2, [R8, #0]
+ AND R1, R2, #0xf
+ CMP R1, R0
+ BNE 1b @ Wrong mailbox
+
+ BIC R1, R2, #0xf
+
+ LDMIA R13!, {R2, R8, PC}
+
+
+.align 4
+framebuffer_info:
+ .int 1024
+ .int 768
+ .int 1024
+ .int 768
+ .int 0
+ .int 16
+ .int 0
+ .int 0
+ .int 0
+ .int 0
diff --git a/src/main.s b/src/main.s
index 40f3ff0..ca63640 100644
--- a/src/main.s
+++ b/src/main.s
@@ -19,6 +19,7 @@
*/
.include "swi_numbers.h"
+.include "ports.h"
.section .init
@@ -64,8 +65,10 @@ reset:
LDMIA R10!, {R0-R7}
STMIA R11!, {R0-R7}
+ BL framebuffer_init
+
/* Configure GPIOs */
- LDR R8, =0x3f200000
+ LDR R8, =(PERIPHERAL_BASE+OFFS_GPIO)
LDR R1, [R8, #0x04] @ GPFSEL1
ORR R1, R1, #1<<18 @ GPIO pin 16 is output
BIC R1, R1, #3<<21 @ GPIO pin 17 is input
diff --git a/src/ports.h b/src/ports.h
new file mode 100644
index 0000000..4f7e584
--- /dev/null
+++ b/src/ports.h
@@ -0,0 +1,24 @@
+/*
+ * ports.h
+ *
+ * Copyright © 2018 Thomas White <taw@bitwiz.org.uk>
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ *
+ */
+
+PERIPHERAL_BASE = 0x3f000000
+
+OFFS_GPIO = 0x00200000
+OFFS_MAILBOX = 0x0000b880