]> git.proxmox.com Git - mirror_qemu.git/blame - hw/cris/boot.c
hw: explicitly include qemu-common.h and cpu.h
[mirror_qemu.git] / hw / cris / boot.c
CommitLineData
77d4f95e
EI
1/*
2 * CRIS image loading.
3 *
4 * Copyright (c) 2010 Edgar E. Iglesias, Axis Communications AB.
5 *
6 * Permission is hereby granted, free of charge, to any person obtaining a copy
7 * of this software and associated documentation files (the "Software"), to deal
8 * in the Software without restriction, including without limitation the rights
9 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 * copies of the Software, and to permit persons to whom the Software is
11 * furnished to do so, subject to the following conditions:
12 *
13 * The above copyright notice and this permission notice shall be included in
14 * all copies or substantial portions of the Software.
15 *
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
19 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22 * THE SOFTWARE.
23 */
24
23b0d7df 25#include "qemu/osdep.h"
4771d756
PB
26#include "qemu-common.h"
27#include "cpu.h"
83c9f4ca
PB
28#include "hw/hw.h"
29#include "hw/loader.h"
77d4f95e 30#include "elf.h"
47b43a1f 31#include "boot.h"
77d4f95e
EI
32
33static void main_cpu_reset(void *opaque)
34{
1584aafd
AF
35 CRISCPU *cpu = opaque;
36 CPUCRISState *env = &cpu->env;
77d4f95e
EI
37 struct cris_load_info *li;
38
39 li = env->load_info;
40
1584aafd 41 cpu_reset(CPU(cpu));
77d4f95e
EI
42
43 if (!li) {
44 /* nothing more to do. */
45 return;
46 }
47
48 env->pc = li->entry;
49
50 if (li->image_filename) {
51 env->regs[8] = 0x56902387; /* RAM boot magic. */
52 env->regs[9] = 0x40004000 + li->image_size;
53 }
54
55 if (li->cmdline) {
56 /* Let the kernel know we are modifying the cmdline. */
57 env->regs[10] = 0x87109563;
58 env->regs[11] = 0x40000000;
59 }
60}
61
62static uint64_t translate_kernel_address(void *opaque, uint64_t addr)
63{
64 return addr - 0x80000000LL;
65}
66
5935664f 67void cris_load_image(CRISCPU *cpu, struct cris_load_info *li)
77d4f95e 68{
5935664f 69 CPUCRISState *env = &cpu->env;
77d4f95e
EI
70 uint64_t entry, high;
71 int kcmdline_len;
72 int image_size;
73
74 env->load_info = li;
75 /* Boots a kernel elf binary, os/linux-2.6/vmlinux from the axis
76 devboard SDK. */
77 image_size = load_elf(li->image_filename, translate_kernel_address, NULL,
7ef295ea 78 &entry, NULL, &high, 0, EM_CRIS, 0, 0);
77d4f95e
EI
79 li->entry = entry;
80 if (image_size < 0) {
81 /* Takes a kimage from the axis devboard SDK. */
82 image_size = load_image_targphys(li->image_filename, 0x40004000,
83 ram_size);
84 li->entry = 0x40004000;
85 }
86
87 if (image_size < 0) {
88 fprintf(stderr, "qemu: could not load kernel '%s'\n",
89 li->image_filename);
90 exit(1);
91 }
92
93 if (li->cmdline && (kcmdline_len = strlen(li->cmdline))) {
94 if (kcmdline_len > 256) {
95 fprintf(stderr, "Too long CRIS kernel cmdline (max 256)\n");
96 exit(1);
97 }
98 pstrcpy_targphys("cmdline", 0x40000000, 256, li->cmdline);
99 }
1584aafd 100 qemu_register_reset(main_cpu_reset, cpu);
77d4f95e 101}