1 /* start.S - AsbestOS stage2 startup code
3 Copyright (C) 2010-2011 Hector Martin "marcan" <hector@marcansoft.com>
5 This code is licensed to you under the terms of the GNU GPL, version 2;
6 see file COPYING or http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt
9 #include "../common/assembly.h"
13 .section .vectors,"ax",@progbits
23 .space 0x100 - (.-_zero)
26 /* both threads end up running here */
28 /* calculate our base */
32 addi r30, r30, (_zero - 1b)
35 /* if this is thread 1, go to _thread1_start */
42 .space 0x1000 - (.-_zero)
45 .section .start,"ax",@progbits
50 /* relocate to our real address */
52 lis r5, __self_start@h
53 ori r5, r5, __self_start@l
55 ori r6, r6, __self_end@l
77 /* continue running at the relocated location */
78 lis r4, reloced_start@h
79 ori r4, r4, reloced_start@l
85 /* make sure _thread1_active is cleared on the new copy */
86 lis r3, _thread1_active@h
87 ori r3, r3, _thread1_active@l
91 /* now jump thread1 over to the new vector */
96 lis r3, _thread1_start@h
97 ori r3, r3, _thread1_start@l
103 /* set up the TOC register */
104 lis r2, (__toc_start+0x8000)@h
105 ori r2, r2, (__toc_start+0x8000)@l
106 /* set up the stack */
108 ori r1, r1, _stack_bot@l
109 /* make space for the first stack frame */
115 lis r3, __bss_start@h
116 ori r3, r3, __bss_start@l
118 ori r4, r4, __bss_end@l
126 /* jump to main (panic if it returns) */
130 /* thread 1 runs this code - spin until we have a vector */
132 lis r3, _thread1_active@h
133 ori r3, r3, _thread1_active@l
139 /* next time make sure we use the real base (if applicable) */
141 ori r30, r30, __base@l
151 li r3, 1 /* CPU number for Linux */
155 .global _thread1_active, _thread1_release, _thread1_vector
156 _thread1_active: .quad 0
157 _thread1_release: .quad 0
158 _thread1_vector: .quad 0