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-19 22:33:29 +00:00
|
|
|
begtext:
|
2013-05-21 23:16:59 +00:00
|
|
|
! Set up system registers.
|
|
|
|
|
|
|
|
lea gp, begtext
|
2013-05-21 22:17:30 +00:00
|
|
|
st sp, .returnsp
|
|
|
|
st lr, .returnlr
|
|
|
|
|
2013-05-21 23:16:59 +00:00
|
|
|
! The GPU kernel code will load parameters into r0-r5. Save them
|
|
|
|
! so that the user code can access them.
|
|
|
|
|
|
|
|
sub r0, gp ! pointer
|
|
|
|
sub r1, gp ! pointer
|
|
|
|
sub r2, gp ! pointer
|
|
|
|
sub r3, gp ! pointer
|
|
|
|
! r4-r5 are not pointers and don't need adjusting
|
|
|
|
push r0-r5
|
|
|
|
sub r0, sp, gp
|
|
|
|
st r0, _gpu_parameters
|
|
|
|
|
2013-05-19 22:33:29 +00:00
|
|
|
! Wipe the bss. (I'm a little suprised that __m_a_i_n doesn't do this.)
|
|
|
|
|
2013-05-21 23:16:59 +00:00
|
|
|
lea r0, begbss
|
|
|
|
lea r1, endbss
|
|
|
|
mov r2, #0
|
|
|
|
_1:
|
|
|
|
stb r2, (r0)
|
2013-05-21 23:52:58 +00:00
|
|
|
addcmpb.lt r0, #1, r1, _1
|
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
|
|
|
|
! 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:
|
|
|
|
ld sp, .returnsp
|
|
|
|
ld lr, .returnlr
|
|
|
|
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.
|
|
|
|
|
|
|
|
.comm .returnsp, 4
|
|
|
|
.comm .returnlr, 4
|
2013-05-21 23:16:59 +00:00
|
|
|
|
|
|
|
! User pointer to the GPU kernel parameter block.
|
|
|
|
|
|
|
|
.define _gpu_parameters
|
|
|
|
.comm _gpu_parameters, 4
|
|
|
|
|