Ravenscar for Raspberry Pi 2/3 boards
=====================================

Boot the board with an Ada program:
-----------------------------------

By default the board boots on the FAT-formatted SD-CARD.

On this sd-card, you need to have the following firmware files:
- bootcode.bin (required)
- start.elf (required)
- fixup.dat (required to use 1GB)

Those startup files can be found with the raspbian distribution.

Use gprbuild to build the application, then for the Raspberry Pi2:
- arm-eabi-objcopy -O binary PROG PROG.bin
or for the Raspberry Pi3:
- aarch64-elf-objcopy -O binary PROG PROG.bin
and finally:
- cp PROG.bin /sdcard/kernel7.img

Install the sdcard on the Pi, and power it up.

Resources used by the runtime:
------------------------------

- mini-uart (MU) for textio.
  Uses pins of the GPIO port:
    5V +-+ GND
       | | | +--- TX
       | | | | +- RX
       1 2 3 4 5
   +----------------- ... ----+
   |/\ * * * * * *    ...     |
   |\/ * * * * * *    ...    USB
   |                         USB
   | #                        |

- Per core CNTP and CNTPCT (generic timer) for time

- The 64 timer in the local registers uses the crystal (19.2 Mhz)

- Mailbox 3 of each core is used to start the cores and for inter
  processor interrupts (IPI).

Memory mapping:
---------------
  <!--  Main memory for ARM -->
  <region access="rwx---" cache="wb"
	  virt="0x00000000" size="0x3ae00000" name="ram"/>

  <!--  Uncachable area to communicate with devices -->
  <region access="rw-rw-" cache="nc"
	  virt="0x3ae00000" size="0x00200000" name="uc"/>

  <!--  Frame buffer (64MB) -->
  <region access="rw-rw-" cache="nc"
	  virt="0x3b000000" size="0x04000000" name="vc"/>

  <!-- IO -->
  <region access="rw-rw-" cache="nc"
	  virt="0x3f000000" size="0x02000000" name="io"/>


Boot:
-----

- Use the normal boot (starts at 0x8000).
- Switch from HYP to SYS mode
- For ref, the reset code is:

   0:	ea000008 	b	0x28
   4:	0124f800
   8:	e3001131 	movw	r1, #305	; 0x131 # HCE, AW, FW, NS
   c:	ee011f11 	mcr	15, 0, r1, cr1, cr1, {0}
  10:	e30001da 	movw	r0, #474	; 0x1da
  14:	e16ff000 	msr	SPSR_fsxc, r0
  18:	e1b0f00e 	movs	pc, lr
  1c:	00063fff
  20:	00000c42
  24:	4000008c	# Mailbox 3 core 0
  28:	ee110f10 	mrc	15, 0, r0, cr1, cr0, {0}
  2c:	e3800004 	orr	r0, r0, #4
  30:	e3800a01 	orr	r0, r0, #4096	; 0x1000
  34:	ee010f10 	mcr	15, 0, r0, cr1, cr0, {0}
  38:	ee110f30 	mrc	15, 0, r0, cr1, cr0, {1}
  3c:	e3800040 	orr	r0, r0, #64	; 0x40
  40:	ee010f30 	mcr	15, 0, r0, cr1, cr0, {1}
  44:	e3a00001 	mov	r0, #1
  48:	ee0e0f33 	mcr	15, 0, r0, cr14, cr3, {1}
  4c:	e51f1038 	ldr	r1, [pc, #-56]	; 0x1c
  50:	ee011f51 	mcr	15, 0, r1, cr1, cr1, {2}
  54:	e51f1058 	ldr	r1, [pc, #-88]	; 0x4
  58:	ee0e1f10 	mcr	15, 0, r1, cr14, cr0, {0}
  5c:	e24f1064 	sub	r1, pc, #100	; 0x64
  60:	ee0c1f30 	mcr	15, 0, r1, cr12, cr0, {1}
  64:	ee1ccf10 	mrc	15, 0, ip, cr12, cr0, {0}
  68:	f57ff06f 	isb	sy
  6c:	e1600070 	smc	0
  70:	ee0ccf10 	mcr	15, 0, ip, cr12, cr0, {0}
  74:	e59f4080 	ldr	r4, [pc, #128]	; 0xfc
  78:	ee100fb0 	mrc	15, 0, r0, cr0, cr0, {5}
  7c:	e7e10050 	ubfx	r0, r0, #0, #2
  80:	e3500000 	cmp	r0, #0
  84:	0a00000a 	beq	0xb4
  88:	e3a05001 	mov	r5, #1
  8c:	e1a05015 	lsl	r5, r5, r0
  90:	e31500ff 	tst	r5, #255	; 0xff
  94:	0a00000a 	beq	0xc4
  98:	e51f507c 	ldr	r5, [pc, #-124]	; 0x24
  9c:	e3a03000 	mov	r3, #0
  a0:	e2855040 	add	r5, r5, #64	; 0x40
  a4:	e7954200 	ldr	r4, [r5, r0, lsl #4]
  a8:	e1540003 	cmp	r4, r3
  ac:	0afffffc 	beq	0xa4
  b0:	e7854200 	str	r4, [r5, r0, lsl #4]
  b4:	e3a00000 	mov	r0, #0
  b8:	e51f10a0 	ldr	r1, [pc, #-160]	; 0x20
  bc:	e59f2034 	ldr	r2, [pc, #52]	; 0xf8
  c0:	e12fff14 	bx	r4
  c4:	e320f003 	wfi
  c8:	eafffffd 	b	0xc4
	...
  fc:	00008000 	
