1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25#include "qemu/osdep.h"
26#include "qemu-common.h"
27#include "cpu.h"
28#include "hw/hw.h"
29#include "hw/loader.h"
30#include "elf.h"
31#include "boot.h"
32#include "qemu/cutils.h"
33
34static void main_cpu_reset(void *opaque)
35{
36 CRISCPU *cpu = opaque;
37 CPUCRISState *env = &cpu->env;
38 struct cris_load_info *li;
39
40 li = env->load_info;
41
42 cpu_reset(CPU(cpu));
43
44 if (!li) {
45
46 return;
47 }
48
49 env->pc = li->entry;
50
51 if (li->image_filename) {
52 env->regs[8] = 0x56902387;
53 env->regs[9] = 0x40004000 + li->image_size;
54 }
55
56 if (li->cmdline) {
57
58 env->regs[10] = 0x87109563;
59 env->regs[11] = 0x40000000;
60 }
61}
62
63static uint64_t translate_kernel_address(void *opaque, uint64_t addr)
64{
65 return addr - 0x80000000LL;
66}
67
68void cris_load_image(CRISCPU *cpu, struct cris_load_info *li)
69{
70 CPUCRISState *env = &cpu->env;
71 uint64_t entry, high;
72 int kcmdline_len;
73 int image_size;
74
75 env->load_info = li;
76
77
78 image_size = load_elf(li->image_filename, NULL,
79 translate_kernel_address, NULL,
80 &entry, NULL, &high, 0, EM_CRIS, 0, 0);
81 li->entry = entry;
82 if (image_size < 0) {
83
84 image_size = load_image_targphys(li->image_filename, 0x40004000,
85 ram_size);
86 li->entry = 0x40004000;
87 }
88
89 if (image_size < 0) {
90 fprintf(stderr, "qemu: could not load kernel '%s'\n",
91 li->image_filename);
92 exit(1);
93 }
94
95 if (li->cmdline && (kcmdline_len = strlen(li->cmdline))) {
96 if (kcmdline_len > 256) {
97 fprintf(stderr, "Too long CRIS kernel cmdline (max 256)\n");
98 exit(1);
99 }
100 pstrcpy_targphys("cmdline", 0x40000000, 256, li->cmdline);
101 }
102 qemu_register_reset(main_cpu_reset, cpu);
103}
104