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