Boot code now works properly in both kernel and bare-metal mode.

--HG--
branch : dtrg-videocore
This commit is contained in:
David Given 2013-05-26 19:41:37 +01:00
parent ef25c53c9c
commit 38e4726f5c
2 changed files with 40 additions and 31 deletions

View file

@ -23,13 +23,15 @@
begtext: begtext:
! This empty space is required by the boot loader. ! This empty space is required by the boot loader.
b start kernel_start:
.space 508 ! 512 minus space needed for branch instruction ! When running as a kernel, we need to preserve all registers. We save
! them onto the default stack.
push r0-r24
b baremetal_start
.space 506 ! first 512 bytes are ignored by the boot loader
baremetal_start:
! Wipe the bss (including the new stack).
! Wipe the bss. This must happen absolutely first, because we need
! to store the old system registers into it.
start:
lea r6, begbss lea r6, begbss
lea r7, endbss lea r7, endbss
mov r8, #0 mov r8, #0
@ -37,35 +39,23 @@ _1:
stb r8, (r6) stb r8, (r6)
addcmpb.lt r6, #1, r7, _1 addcmpb.lt r6, #1, r7, _1
! Set up system registers. ! Save system registers.
lea gp, begtext
st fp, .returnfp st fp, .returnfp
st sp, .returnsp st sp, .returnsp
st lr, .returnlr st lr, .returnlr
! Set up the new stack and save the kernel parameters to it. lea gp, begtext
lea sp, .stack + STACKSIZE - 6*4 ! Save the kernel parameters.
sub r0, gp ! pointer
st r0, 0 (sp)
sub r1, gp ! pointer
st r1, 4 (sp)
sub r2, gp ! pointer
st r2, 8 (sp)
sub r3, gp ! pointer
st r3, 12 (sp)
! r4-r5 are not pointers and don't need adjusting
st r4, 16 (sp)
st r5, 20 (sp)
sub r0, gp ! fix up pointer
sub r1, gp ! fix up pointer
sub r2, gp ! fix up pointer
sub r3, gp ! fix up pointer
push r0-r5
sub r0, sp, gp sub r0, sp, gp
st r0, _gpu_parameters st r0, _pi_kernel_parameters
! Push standard parameters onto the stack and go. ! Push standard parameters onto the stack and go.
@ -82,10 +72,16 @@ _1:
.define __exit .define __exit
__exit: __exit:
! It only makes sense to get here if we're in kernel mode. If we're in
! bare-metal mode, we'll just crash, but that's fine.
st r0, _pi_kernel_parameters ! save return value
mov r0, sr mov r0, sr
ld fp, .returnfp ld fp, .returnfp
ld sp, .returnsp ld sp, .returnsp
ld lr, .returnlr ld lr, .returnlr
pop r0-r24
ld r0, _pi_kernel_parameters ! restore return value
b lr b lr
! Define symbols at the beginning of our various segments, so that we can find ! Define symbols at the beginning of our various segments, so that we can find
@ -110,10 +106,8 @@ __exit:
.comm .returnsp, 4 .comm .returnsp, 4
.comm .returnlr, 4 .comm .returnlr, 4
! User pointer to the GPU kernel parameter block. .define _pi_kernel_parameters
.comm _pi_kernel_parameters, 4
.define _gpu_parameters
.comm _gpu_parameters, 4
! User stack. ! User stack.

View file

@ -8,6 +8,21 @@
#ifndef PI_H #ifndef PI_H
#define PI_H #define PI_H
/* When running in kernel mode, this structure gets the incoming parameters.
* In bare metal mode, it's gibberish. */
struct pi_kernel_parameters
{
int r5;
int r4;
void* r3;
void* r2;
void* r1;
void* r0;
};
extern struct pi_kernel_parameters* pi_kernel_parameters;
/* Initialise the mini UART (only do this if running on bare metal! */ /* Initialise the mini UART (only do this if running on bare metal! */
extern void pi_init_uart(void); extern void pi_init_uart(void);