HACK
[asbestos.git] / stage1 / start.S
blobc5c0de25672fa587ccbab6ae418339ff7f515954
1 /*  start.S - AsbestOS stage1 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"
11         .text
12         .section .start,"ax",@progbits
13         .align 3
15         .global _start
17 _start:
18         mflr r0
19         bl 1f
21         mflr r4
22         /* calculate address of _start */
23         addi r4, r4, (_start - 1b)
25         /* relocate to our real address */
26         li r3, 1
27         sldi r3, r3, 63
28         oris r5, r3, __self_start@h
29         ori r5, r5, __self_start@l
30         oris r6, r3, __self_end@h
31         ori r6, r6, __self_end@l
33 _reloc_loop:
34         ld r8, 0(r4)
35         std r8, 0(r5)
36         ld r8, 8(r4)
37         std r8, 8(r5)
38         ld r8, 16(r4)
39         std r8, 16(r5)
40         ld r8, 24(r4)
41         std r8, 24(r5)
42         dcbst 0, r5
43         sync
44         icbi 0, r5
45         addi r4, r4, 0x20
46         addi r5, r5, 0x20
47         cmpld r5, r6
48         blt _reloc_loop
50         /* continue running at the relocated location */
51         oris r4, r3, reloced_start@h
52         ori r4, r4, reloced_start@l
53         mtctr r4
54         bctr
56 reloced_start:
57         std r0, 0x10(sp)
58         stdu sp, -0x80(sp)
60         /* register the USB device driver */
61         oris r3, r3, usb_driver@h
62         ori r3, r3, usb_driver@l
63         bl _usbRegisterDriver
65         /* return from exploit */
66 return:
67         addi sp, sp, 0x80
68         ld r0, 0x10(sp)
69         mtlr r0
70         li r3, 0
71         blr