Add qemu 2.4.0
[kvmfornfv.git] / qemu / roms / openhackware / src / boot.S
1 /* 
2  *      <boot.S>
3  *      
4  *     First stage BIOS loader for Open Hack'Ware.
5  *   
6  *   Copyright (C) 2004-2005 Jocelyn Mayer (l_indien@magic.fr)
7  *   
8  *   This program is free software; you can redistribute it and/or
9  *   modify it under the terms of the GNU General Public License V2
10  *   as published by the Free Software Foundation
11  *   
12  * Permission is hereby granted, free of charge, to any person obtaining a copy
13  * of this software and associated documentation files (the "Software"), to deal
14  * in the Software without restriction, including without limitation the rights
15  * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
16  * copies of the Software, and to permit persons to whom the Software is
17  * furnished to do so, subject to the following conditions:
18  *
19  * The above copyright notice and this permission notice shall be included in
20  * all copies or substantial portions of the Software.
21  *
22  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
23  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
24  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
25  * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
26  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
27  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
28  * THE SOFTWARE.
29  */
30 /*
31  * setup one RAM bank then
32  * relocate the one page BIOS second stage into RAM.
33  *
34  * We consider that we know nothing about the CPU state
35  * at the time we enter this code.
36  *
37  */
38
39 #define ASSEMBLY_CODE
40 #include "bios.h"
41
42 .section .rom, "ax"
43 .align 2
44 _boot_start:
45         /* Minimal setup */
46         li    r0, 0                                          ;
47         /* r11 is _boot_start address */
48         mflr    r11                                          ;
49         addi    r11, r11, (_boot_start - _start - 4)         ;
50         /* Disable MMU and interruptions */
51         addi    r12, r11, (_boot_no_mmu - _boot_start)       ;
52         mtspr   SRR0, r12                                    ;
53         mfmsr   r12                                          ;
54         lis     r13, 0x0004                                  ;
55         ori     r13, r13, 0xEF71                             ;
56         andc    r15, r12, r13                                ;
57         mtspr   SRR1, r12                                    ;
58         rfi                                                  ;
59 _boot_no_mmu:
60         /* TODO: initialize physical RAM (we need at least one page)
61          * before doing anything else.
62          * This may be machine dependent code.
63          */
64 _boot_copy:
65         /* Copy the second stage bootloader into RAM
66          * We may need a tiny driver if we need to boot from special device
67          * (ie disc-on-chip, ...)
68          */
69         lis    r12, (VECTORS_SIZE / 4)@h                     ;
70         ori    r12, r12, (VECTORS_SIZE / 4)@l                ;
71         mtctr  r12                                           ;
72         clrrwi r12, r11, BIOS_IMAGE_BITS                     ;
73         addis  r3, r12, VECTORS_SIZE@h                       ;
74         addi   r3, r3, VECTORS_SIZE@l                        ;
75         subi   r12, r12, 4                                   ;
76         lis    r13, VECTORS_BASE@h                           ;
77         ori    r13, r13, VECTORS_BASE@l                      ;
78         mtlr   r13                                           ;
79         subi   r13, r13, 4                                   ;
80 _boot_copy_loop:
81         lwzu   r14, 4(r12)                                   ;
82         stwu   r14, 4(r13)                                   ;
83         bdnz   _boot_copy_loop                               ;
84         /* Synchronize the whole execution context */
85         addi    r12, r11, (_boot_sync - _boot_start)         ;
86         mtspr   SRR0, r12                                    ;
87         mfmsr   r12                                          ;
88         mtspr   SRR1, r12                                    ;
89         rfi                                                  ;
90 _boot_sync:
91         /* All done, jump into the loaded code */
92         blrl                                                 ;
93         /* If we ever return, reboot */
94         b _start                                             ;
95
96 .space BOOT_SIZE - 4 - (. - _boot_start), 0xFF
97 /* Reset entry point */
98         . = 0x1FC
99 _start:
100         bl _boot_start                                       ;