Rev 843 | Rev 934 | Go to most recent revision | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 843 | Rev 845 | ||
---|---|---|---|
1 | # |
1 | # |
2 | # Copyright (C) 2005 Jakub Jermar |
2 | # Copyright (C) 2005 Jakub Jermar |
3 | # All rights reserved. |
3 | # All rights reserved. |
4 | # |
4 | # |
5 | # Redistribution and use in source and binary forms, with or without |
5 | # Redistribution and use in source and binary forms, with or without |
6 | # modification, are permitted provided that the following conditions |
6 | # modification, are permitted provided that the following conditions |
7 | # are met: |
7 | # are met: |
8 | # |
8 | # |
9 | # - Redistributions of source code must retain the above copyright |
9 | # - Redistributions of source code must retain the above copyright |
10 | # notice, this list of conditions and the following disclaimer. |
10 | # notice, this list of conditions and the following disclaimer. |
11 | # - Redistributions in binary form must reproduce the above copyright |
11 | # - Redistributions in binary form must reproduce the above copyright |
12 | # notice, this list of conditions and the following disclaimer in the |
12 | # notice, this list of conditions and the following disclaimer in the |
13 | # documentation and/or other materials provided with the distribution. |
13 | # documentation and/or other materials provided with the distribution. |
14 | # - The name of the author may not be used to endorse or promote products |
14 | # - The name of the author may not be used to endorse or promote products |
15 | # derived from this software without specific prior written permission. |
15 | # derived from this software without specific prior written permission. |
16 | # |
16 | # |
17 | # THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR |
17 | # THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR |
18 | # IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES |
18 | # IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES |
19 | # OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. |
19 | # OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. |
20 | # IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, |
20 | # IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, |
21 | # INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT |
21 | # INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT |
22 | # NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
22 | # NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
23 | # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
23 | # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
24 | # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
24 | # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
25 | # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF |
25 | # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF |
26 | # THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
26 | # THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
27 | # |
27 | # |
28 | 28 | ||
29 | #include <arch/asm/macro.h> |
29 | #include <arch/asm/regname.h> |
30 | #include <arch/asm/spr.h> |
30 | #include <arch/asm/spr.h> |
31 | 31 | ||
32 | .section K_TEXT_START |
32 | .section K_TEXT_START |
33 | 33 | ||
34 | .global kernel_image_start |
34 | .global kernel_image_start |
35 | 35 | ||
36 | .org 0x0 |
36 | .org 0x0 |
37 | /* 256 bytes of some data */ |
37 | /* 256 bytes of some data */ |
38 | /* exception table - must use 'ba' instructions for branches, |
38 | /* exception table - must use 'ba' instructions for branches, |
39 | * because it is elsewhere than the linker thinks |
39 | * because it is elsewhere than the linker thinks |
40 | */ |
40 | */ |
41 | .space 4096 |
41 | .space 4096 |
42 | 42 | ||
43 | kernel_image_start: |
43 | kernel_image_start: |
44 | /* Initialize OFW, might be needed before relocate_kernel? */ |
44 | /* Initialize OFW, might be needed before relocate_kernel? */ |
45 | lis r4, ofw@ha |
45 | lis r4, ofw@ha |
46 | addi r4, r4, ofw@l |
46 | addi r4, r4, ofw@l |
47 | stw r5, 0(r4) |
47 | stw r5, 0(r4) |
48 | 48 | ||
49 | bl ofw_init |
49 | bl ofw_init |
50 | bl preboot_read_config |
50 | bl preboot_read_config |
51 | 51 | ||
52 | bl relocate_kernel |
52 | bl relocate_kernel |
53 | __after_reloc: |
53 | __after_reloc: |
54 | /* Set stack to some more meaningful value */ |
54 | /* Set stack to some more meaningful value */ |
55 | /* TODO: This is hardcoded for PearPC, must be changed later */ |
55 | /* TODO: This is hardcoded for PearPC, must be changed later */ |
56 | lis r1, 0x70 |
56 | lis r1, 0x70 |
57 | b main_bsp |
57 | b main_bsp |
58 | 58 | ||
59 | relocate_kernel: |
59 | relocate_kernel: |
60 | /* TODO: We _know_ that pearpc loads it to 8MB, and |
60 | /* TODO: We _know_ that pearpc loads it to 8MB, and |
61 | * but it should be really generic |
61 | * but it should be really generic |
62 | */ |
62 | */ |
63 | lis r4, 0x80 /* r4 is where data was loaded - 8MB */ |
63 | lis r4, 0x80 /* r4 is where data was loaded - 8MB */ |
64 | 64 | ||
65 | bl to_real_mode |
65 | bl to_real_mode |
66 | /* Now we are in real mode, copy first block and jump to it, |
66 | /* Now we are in real mode, copy first block and jump to it, |
67 | * we are running in the loaded kernel now |
67 | * we are running in the loaded kernel now |
68 | * We still have in r3 physical load kernel address |
68 | * We still have in r3 physical load kernel address |
69 | */ |
69 | */ |
70 | 70 | ||
71 | b __after_reloc /* We know in pearpc we are ok, so return, |
71 | b __after_reloc /* We know in pearpc we are ok, so return, |
72 | * otherwise we should relocate kernel |
72 | * otherwise we should relocate kernel |
73 | * here |
73 | * here |
74 | */ |
74 | */ |
75 | 75 | ||
76 | 76 | ||
77 | 77 | ||
78 | 78 | ||
79 | /* Turn off page translation |
79 | /* Turn off page translation |
80 | * - assume that physical-loaded address is in r4 |
80 | * - assume that physical-loaded address is in r4 |
81 | */ |
81 | */ |
82 | to_real_mode: |
82 | to_real_mode: |
83 | mflr r0 |
83 | mflr r0 |
84 | 84 | ||
85 | lis r5, ktext_start@ha // Expected start of kernel |
85 | lis r5, ktext_start@ha // Expected start of kernel |
86 | addi r5, r5, ktext_start@l |
86 | addi r5, r5, ktext_start@l |
87 | 87 | ||
88 | add r0, r4, r0 |
88 | add r0, r4, r0 |
89 | sub r0, r0, r5 // r0 now contains physical return address |
89 | sub r0, r0, r5 // r0 now contains physical return address |
90 | 90 | ||
91 | mfmsr r3 |
91 | mfmsr r3 |
92 | andis. r3, r3, (~MSR_DR | MSR_IR) >> 16 |
92 | andis. r3, r3, (~MSR_DR | MSR_IR) >> 16 |
93 | mtspr SPRN_SRR0, r0 |
93 | mtspr SPRN_SRR0, r0 |
94 | mtspr SPRN_SRR1, r3 |
94 | mtspr SPRN_SRR1, r3 |
95 | sync // Really needed? RFI should do it as well? |
95 | sync // Really needed? RFI should do it as well? |
96 | RFI |
96 | RFI |
97 | 97 | ||
98 | 98 |