Upgraded GRUB2 to 2.00 release.
[AROS.git] / arch / all-pc / boot / grub2-aros / grub-core / kern / sparc64 / ieee1275 / crt0.S
blob9d91fba486c1f16c260eaf2db85e39680788869e
1 /* crt0.S - Startup code for the Sparc64.  */
2 /*
3  *  GRUB  --  GRand Unified Bootloader
4  *  Copyright (C) 2009  Free Software Foundation, Inc.
5  *
6  *  GRUB is free software: you can redistribute it and/or modify
7  *  it under the terms of the GNU General Public License as published by
8  *  the Free Software Foundation, either version 3 of the License, or
9  *  (at your option) any later version.
10  *
11  *  GRUB is distributed in the hope that it will be useful,
12  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
13  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  *  GNU General Public License for more details.
15  *
16  *  You should have received a copy of the GNU General Public License
17  *  along with GRUB.  If not, see <http://www.gnu.org/licenses/>.
18  */
19 #include <grub/symbol.h>
20 #include <grub/machine/kernel.h>
21 #include <grub/offsets.h>
23         .text
24         .align  4
25         .globl  _start
26 _start:
27         ba      codestart
28          mov  %o4, %o0
30         . = EXT_C(_start) + GRUB_KERNEL_MACHINE_TOTAL_MODULE_SIZE
32 VARIABLE(grub_total_module_size)
33         .word   0
35 codestart:
36         /* Copy the modules past the end of the kernel image.
37          * They are currently sitting in the BSS.
38          */
39         sethi   %hi(__bss_start), %o2
40         or      %o2, %lo(__bss_start), %o2
41         sethi   %hi(_end), %o3
42         or      %o3, %lo(_end), %o3
43         sethi   %hi(grub_total_module_size), %o4
44         lduw    [%o4 + %lo(grub_total_module_size)], %o4
46         add     %o2, %o4, %o2
47         add     %o3, %o4, %o3
49         /* Save ieee1275 stack for future use by booter.  */
50         mov     %o6, %o1
51         /* Our future stack.  */
52         sethi   %hi(GRUB_KERNEL_MACHINE_STACK_SIZE), %o5
53         or      %o5, %lo(GRUB_KERNEL_MACHINE_STACK_SIZE), %o5
54         add     %o3, %o5, %o6
55         and     %o6, ~0xff, %o6
56         sub     %o6, 2047, %o6
57         
58         sub     %o2, 4, %o2
59         sub     %o3, 4, %o3
60 1:      lduw    [%o2], %o5
61         stw     %o5, [%o3]
62         subcc   %o4, 4, %o4
63         sub     %o2, 4, %o2
64         bne,pt  %icc, 1b
65          sub    %o3, 4, %o3
67         /* Now it's safe to clear out the BSS.  */
68         sethi   %hi(__bss_start), %o2
69         or      %o2, %lo(__bss_start), %o2
70         sethi   %hi(_end), %o3
71         or      %o3, %lo(_end), %o3
72 1:      stx     %g0, [%o2]
73         add     %o2, 8, %o2
74         cmp     %o2, %o3
75         blt,pt  %xcc, 1b
76          nop
77         sethi   %hi(grub_ieee1275_original_stack), %o2
78         stx     %o1, [%o2 + %lo(grub_ieee1275_original_stack)]
79         sethi   %hi(grub_ieee1275_entry_fn), %o2
80         call    grub_main
81          stx    %o0, [%o2 + %lo(grub_ieee1275_entry_fn)]
82 1:      ba,a    1b