2013-05-19 22:33:29 +00:00
|
|
|
#
|
|
|
|
/*
|
|
|
|
* 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.
|
|
|
|
*/
|
|
|
|
|
|
|
|
! Declare segments (the order is important).
|
|
|
|
|
|
|
|
.sect .text
|
|
|
|
.sect .rom
|
|
|
|
.sect .data
|
|
|
|
.sect .bss
|
|
|
|
|
|
|
|
.sect .text
|
|
|
|
|
2013-05-21 23:16:59 +00:00
|
|
|
#define gp r15
|
2013-05-22 17:25:30 +00:00
|
|
|
#define STACKSIZE 16*1024
|
|
|
|
|
|
|
|
! MAIN ENTRY POINT
|
2013-05-21 23:16:59 +00:00
|
|
|
|
2013-05-19 22:33:29 +00:00
|
|
|
begtext:
|
2013-05-24 23:35:29 +00:00
|
|
|
! This empty space is required by the boot loader.
|
|
|
|
|
2013-05-26 18:41:37 +00:00
|
|
|
kernel_start:
|
|
|
|
! 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).
|
2013-05-24 23:35:29 +00:00
|
|
|
|
2013-05-22 17:25:30 +00:00
|
|
|
lea r6, begbss
|
|
|
|
lea r7, endbss
|
|
|
|
mov r8, #0
|
|
|
|
_1:
|
|
|
|
stb r8, (r6)
|
|
|
|
addcmpb.lt r6, #1, r7, _1
|
|
|
|
|
2013-05-26 18:41:37 +00:00
|
|
|
! Save system registers.
|
2013-05-22 21:46:10 +00:00
|
|
|
|
|
|
|
st fp, .returnfp
|
|
|
|
st sp, .returnsp
|
|
|
|
st lr, .returnlr
|
|
|
|
|
2013-05-26 18:41:37 +00:00
|
|
|
lea gp, begtext
|
2013-05-22 21:46:10 +00:00
|
|
|
|
2013-05-26 18:41:37 +00:00
|
|
|
! Save the kernel parameters.
|
2013-05-22 17:25:30 +00:00
|
|
|
|
2013-05-26 18:41:37 +00:00
|
|
|
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
|
2013-05-21 23:16:59 +00:00
|
|
|
sub r0, sp, gp
|
2013-05-26 18:41:37 +00:00
|
|
|
st r0, _pi_kernel_parameters
|
2013-05-21 23:16:59 +00:00
|
|
|
|
2013-05-19 22:33:29 +00:00
|
|
|
! Push standard parameters onto the stack and go.
|
|
|
|
|
2013-05-21 23:16:59 +00:00
|
|
|
mov r0, #0
|
|
|
|
push r0 ! envp
|
|
|
|
push r0 ! argv
|
|
|
|
push r0 ! argc
|
|
|
|
|
|
|
|
! Call the language startup code.
|
|
|
|
|
|
|
|
bl __m_a_i_n
|
2013-05-22 21:46:10 +00:00
|
|
|
|
2013-05-21 23:16:59 +00:00
|
|
|
! Fall through to __exit if this returns.
|
2013-05-19 22:33:29 +00:00
|
|
|
|
2013-05-21 22:17:30 +00:00
|
|
|
.define __exit
|
|
|
|
__exit:
|
2013-05-26 18:41:37 +00:00
|
|
|
! 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
|
2013-05-24 23:35:29 +00:00
|
|
|
mov r0, sr
|
2013-05-22 21:46:10 +00:00
|
|
|
ld fp, .returnfp
|
2013-05-21 22:17:30 +00:00
|
|
|
ld sp, .returnsp
|
|
|
|
ld lr, .returnlr
|
2013-05-26 18:41:37 +00:00
|
|
|
pop r0-r24
|
|
|
|
ld r0, _pi_kernel_parameters ! restore return value
|
2013-05-21 22:17:30 +00:00
|
|
|
b lr
|
|
|
|
|
2013-05-19 22:33:29 +00:00
|
|
|
! Define symbols at the beginning of our various segments, so that we can find
|
|
|
|
! them. (Except .text, which has already been done.)
|
|
|
|
|
|
|
|
.define begtext, begdata, begbss
|
|
|
|
.sect .data; begdata:
|
|
|
|
.sect .rom; begrom:
|
|
|
|
.sect .bss; begbss:
|
|
|
|
|
|
|
|
! Some magic data. All EM systems need these.
|
|
|
|
|
|
|
|
.define .trppc, .ignmask, _errno
|
|
|
|
.comm .trppc, 4
|
|
|
|
.comm .ignmask, 4
|
|
|
|
.comm _errno, 4
|
2013-05-21 22:17:30 +00:00
|
|
|
|
|
|
|
! We store the stack pointer and return address on entry so that we can
|
|
|
|
! cleanly exit.
|
|
|
|
|
2013-05-22 21:46:10 +00:00
|
|
|
.comm .returnfp, 4
|
2013-05-21 22:17:30 +00:00
|
|
|
.comm .returnsp, 4
|
|
|
|
.comm .returnlr, 4
|
2013-05-21 23:16:59 +00:00
|
|
|
|
2013-05-26 18:41:37 +00:00
|
|
|
.define _pi_kernel_parameters
|
|
|
|
.comm _pi_kernel_parameters, 4
|
2013-05-21 23:16:59 +00:00
|
|
|
|
2013-05-22 17:25:30 +00:00
|
|
|
! User stack.
|
|
|
|
|
|
|
|
.comm .stack, STACKSIZE
|
|
|
|
|