Added boot process information to help someone find out what really happens.
[bootos.git] / stage2 / start.S
blobd660d8a964238e0e3d9d48efd5d585cd82085e07
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
7 */
9 #include "../common/assembly.h"
10 #define LV1_PANIC 255
12         .text
13         .section .start,"ax",@progbits
14         .align 3
16         .global _start
18 _start:
19         /* at this point, one thread is (hopefully) spinning in the decrementer vector */
20         /* release it here (it will already be in realmode and with IRQs disabled) */
21         lis r3, _threads_start@h
22         ori r3, r3, _threads_start@l
23         std r3, 0x920(0)
25 _threads_start:
26         /* both threads end up running here */
28         /* if this is thread 1, go to _thread1_start */
29         mfspr r3, 0x88
30         cntlzw. r3, r3
31         bne _thread1_start
33         /* set up the TOC register */
34         lis r2, (__toc_start+0x8000)@h
35         ori r2, r2, (__toc_start+0x8000)@l
36         /* set up the stack */
37         lis r1, _stack_bot@h
38         ori r1, r1, _stack_bot@l
39         /* make space for the first stack frame */
40         addi r1, r1, 64
41         li r0, 0
42         std r0, 0(r1)
44         /* clear BSS */
45         lis r3, __bss_start@h
46         ori r3, r3, __bss_start@l
47         lis r4, __bss_end@h
48         ori r4, r4, __bss_end@l
49         li r5, 0
50 _bss_loop:
51         std r5, 0(r3)
52         addi r3, r3, 8
53         cmpld r3, r4
54         blt _bss_loop
56         /* jump to main (panic if it returns) */
57         bl main
58         b panic
60         /* thread 1 runs this code - spin until we have a vector */
61 _thread1_start:
62         lis r3, _thread1_active@h
63         ori r3, r3, _thread1_active@l
64         li r4, 1
65         std r4, 0(r3)
67         ld r4, 8(r3)
68         cmpldi r4, 0
69         beq 1b
70         ld r4, 16(r3)
71         mtctr r4
72         li r3, 1 /* CPU number for Linux */
73         bctr
75         .align 3
76         .global _thread1_active, _thread1_release, _thread1_vector
77 _thread1_active:        .quad 0
78 _thread1_release:       .quad 0
79 _thread1_vector:        .quad 0
81 /* shutdown */
82         .global panic
83 panic:
84         li r3, 0
85         li r11, LV1_PANIC
86         lv1call
88 /* reboot */
89         .global reboot
90 reboot:
91         li r3, 1
92         li r11, LV1_PANIC
93         lv1call