Build binaries that will run bare metal. Add enough syscall library to init the uart...
authorDavid Given <dg@cowlark.com>
Fri, 24 May 2013 23:35:29 +0000 (00:35 +0100)
committerDavid Given <dg@cowlark.com>
Fri, 24 May 2013 23:35:29 +0000 (00:35 +0100)
--HG--
branch : dtrg-videocore
rename : plat/rpi/libsys/libsys.h => plat/rpi/libsys/libsysasm.h
rename : plat/rpi/libsys/_sys_rawread.s => plat/rpi/libsys/phys_to_user.s
rename : plat/rpi/libsys/_sys_rawread.s => plat/rpi/libsys/uart.s
rename : plat/rpi/libsys/_sys_rawread.s => plat/rpi/libsys/user_to_phys.s

plat/rpi/boot.s
plat/rpi/build.mk
plat/rpi/include/pi.h [new file with mode: 0644]
plat/rpi/libsys/libsysasm.h [new file with mode: 0644]
plat/rpi/libsys/phys_to_user.s [new file with mode: 0644]
plat/rpi/libsys/uart.s [new file with mode: 0644]
plat/rpi/libsys/user_to_phys.s [new file with mode: 0644]

index 43811a6..523cf40 100644 (file)
 #define STACKSIZE 16*1024
 
 ! MAIN ENTRY POINT
-!
-! When running as a kernel, our parameters are passed in in r0-r5, so
-! the startup sequence mustn't disturb these.
 
 begtext:
+       ! This empty space is required by the boot loader.
+
+       b start
+       .space 508 ! 512 minus space needed for branch instruction
+
        ! Wipe the bss. This must happen absolutely first, because we need
        ! to store the old system registers into it.
-       
+
+start:
        lea r6, begbss
        lea r7, endbss
        mov r8, #0
@@ -79,6 +82,7 @@ _1:
 
 .define __exit
 __exit:
+       mov r0, sr
        ld fp, .returnfp
        ld sp, .returnsp
        ld lr, .returnlr
index 9716eb0..dffe59d 100644 (file)
@@ -13,10 +13,15 @@ D := plat/rpi/
 
 platform-headers := \
        unistd.h \
+       pi.h \
        ack/config.h
 
 platform-libsys := \
        _hol0.s \
+       phys_to_user.s \
+       user_to_phys.s \
+       uart.s \
+       write.c \
 
 ifeq (x,y)
        errno.s \
@@ -26,7 +31,6 @@ ifeq (x,y)
        creat.c \
        close.c \
        read.c \
-       write.c \
        brk.c \
        getpid.c \
        kill.c \
diff --git a/plat/rpi/include/pi.h b/plat/rpi/include/pi.h
new file mode 100644 (file)
index 0000000..a69cdd8
--- /dev/null
@@ -0,0 +1,21 @@
+/*
+ * Raspberry Pi support library for the ACK
+ * © 2013 David Given
+ * This file is redistributable under the terms of the 3-clause BSD license.
+ * See the file 'Copying' in the root of the distribution for the full text.
+ */
+
+#ifndef PI_H
+#define PI_H
+
+/* Initialise the mini UART (only do this if running on bare metal! */
+extern void init_uart(void);
+
+/* Converts a pointer from a physical address to a user address. */
+extern void* phys_to_user(void* ptr);
+
+/* Converts a pointer from a user address to a physical address. */
+extern void* user_to_phys(void* ptr);
+
+#endif
+
diff --git a/plat/rpi/libsys/libsysasm.h b/plat/rpi/libsys/libsysasm.h
new file mode 100644 (file)
index 0000000..16dbbcf
--- /dev/null
@@ -0,0 +1,20 @@
+/*
+ * Raspberry Pi support library for the ACK
+ * © 2013 David Given
+ * This file is redistributable under the terms of the 3-clause BSD license.
+ * See the file 'Copying' in the root of the distribution for the full text.
+ */
+
+#ifndef LIBSYSASM_H
+#define LIBSYSASM_H
+
+! Declare segments (the order is important).
+
+.sect .text
+.sect .rom
+.sect .data
+.sect .bss
+
+#define gp r15
+
+#endif
diff --git a/plat/rpi/libsys/phys_to_user.s b/plat/rpi/libsys/phys_to_user.s
new file mode 100644 (file)
index 0000000..649b19b
--- /dev/null
@@ -0,0 +1,20 @@
+#
+/*
+ * Raspberry Pi support library for the ACK
+ * © 2013 David Given
+ * This file is redistributable under the terms of the 3-clause BSD license.
+ * See the file 'Copying' in the root of the distribution for the full text.
+ */
+
+#include "libsysasm.h"
+
+.sect .text
+
+! Transforms a physical address into a user address.
+
+.define _phys_to_user
+_phys_to_user:
+       ld r0, 0 (sp)
+       sub r0, gp
+       b lr
+
diff --git a/plat/rpi/libsys/uart.s b/plat/rpi/libsys/uart.s
new file mode 100644 (file)
index 0000000..b12f2ef
--- /dev/null
@@ -0,0 +1,135 @@
+#
+/*
+ * Raspberry Pi support library for the ACK
+ * © 2013 David Given
+ * This file is redistributable under the terms of the 3-clause BSD license.
+ * See the file 'Copying' in the root of the distribution for the full text.
+ */
+
+#include "libsysasm.h"
+
+.sect .text
+
+! Because of the low system clock rate, this baud rate might be inaccurate
+! So be careful with your serial/terminal, some adjustment may be necessary.
+TARGET_BAUD_RATE = 115200
+
+! System clock is running directly off the 19.2MHz crystal at initial reset
+SYSTEM_CLOCK = 19200000
+
+GPFSEL1 = 0x7e200004
+GPSET0 = 0x7e20001C
+GPCLR0 = 0x7e200028
+GPPUD = 0x7e200094
+GPPUDCLK0 = 0x7e200098
+
+AUX_ENABLES = 0x7e215004
+AUX_MU_IO_REG = 0x7e215040
+AUX_MU_IER_REG = 0x7e215044
+AUX_MU_IIR_REG = 0x7e215048
+AUX_MU_LCR_REG = 0x7e21504C
+AUX_MU_MCR_REG = 0x7e215050
+AUX_MU_LSR_REG = 0x7e215054
+AUX_MU_MSR_REG = 0x7e215058
+AUX_MU_SCRATCH = 0x7e21505C
+AUX_MU_CNTL_REG = 0x7e215060
+AUX_MU_STAT_REG = 0x7e215064
+AUX_MU_BAUD_REG = 0x7e215068
+
+! Sets up the mini UART for use as a console.
+
+.define _init_uart
+_init_uart:
+       ! Configure TX and RX GPIO pins for Mini Uart function.
+       mov     r1, #GPFSEL1
+       ld      r0, (r1)
+       and     r0, #~[7<<12]
+       or      r0, #2<<12
+       and     r0, #~[7<<15]
+       or      r0, #2<<15
+       st      r0, (r1)
+
+       mov     r1, #GPPUD
+       mov     r0, #0
+       st      r0, (r1)
+
+delay1:
+       add     r0, #1
+       cmp     r0, #150
+       b.ne delay1
+
+       mov     r1, #GPPUDCLK0
+       mov     r0, #[1<<14]|[1<<15]
+       st      r0, (r1)
+
+       mov     r0, #0
+delay2:
+       add     r0, #1
+       cmp     r0, #150
+       b.ne delay2
+
+       mov     r1, #GPPUDCLK0
+       mov     r0, #0
+       st      r0, (r1)
+
+       ! Set up serial port
+       mov     r1, #AUX_ENABLES
+       mov     r0, #1
+       st      r0, (r1)
+
+       mov     r1, #AUX_MU_IER_REG
+       mov     r0, #0
+       st      r0, (r1)
+
+       mov     r1, #AUX_MU_CNTL_REG
+       mov     r0, #0
+       st      r0, (r1)
+
+       mov     r1, #AUX_MU_LCR_REG
+       mov     r0, #3
+       st      r0, (r1)
+
+       mov     r1, #AUX_MU_MCR_REG
+       mov     r0, #0
+       st      r0, (r1)
+
+       mov     r1, #AUX_MU_IER_REG
+       mov     r0, #0
+       st      r0, (r1)
+
+       mov     r1, #AUX_MU_IIR_REG
+       mov     r0, #0xC6
+       st      r0, (r1)
+
+       mov     r1, #AUX_MU_BAUD_REG
+       mov     r0, #[[SYSTEM_CLOCK/[TARGET_BAUD_RATE*8]]-1]
+       st      r0, (r1)
+
+       mov     r1, #AUX_MU_LCR_REG
+       mov     r0, #3
+       st      r0, (r1)
+
+       mov     r1, #AUX_MU_CNTL_REG
+       mov     r0, #3
+       st      r0, (r1)
+
+       b lr
+
+! Send a single byte.
+
+.define __sys_rawwrite
+__sys_rawwrite:
+       ld r0, (sp)
+       mov r1, #AUX_MU_LSR_REG
+       ! loop until space available in Tx buffer
+sendwait:
+       ld      r2, (r1)
+       and     r2, #0x20
+       cmp     r2, #0x20
+       b.ne sendwait
+
+       mov     r1, #AUX_MU_IO_REG
+       stb     r0, (r1)
+
+       b lr
+
diff --git a/plat/rpi/libsys/user_to_phys.s b/plat/rpi/libsys/user_to_phys.s
new file mode 100644 (file)
index 0000000..7b988fd
--- /dev/null
@@ -0,0 +1,20 @@
+#
+/*
+ * Raspberry Pi support library for the ACK
+ * © 2013 David Given
+ * This file is redistributable under the terms of the 3-clause BSD license.
+ * See the file 'Copying' in the root of the distribution for the full text.
+ */
+
+#include "libsysasm.h"
+
+.sect .text
+
+! Transforms a user address into a physical address.
+
+.define _user_to_phys
+_user_to_phys:
+       ld r0, 0 (sp)
+       add r0, gp
+       b lr
+