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 "cpu.h"
27#include "hw/loader.h"
28#include "elf.h"
29#include "boot.h"
30#include "qemu/cutils.h"
31#include "sysemu/reset.h"
32
33static void main_cpu_reset(void *opaque)
34{
35 CRISCPU *cpu = opaque;
36 CPUCRISState *env = &cpu->env;
37 struct cris_load_info *li;
38
39 li = env->load_info;
40
41 cpu_reset(CPU(cpu));
42
43 if (!li) {
44
45 return;
46 }
47
48 env->pc = li->entry;
49
50 if (li->image_filename) {
51 env->regs[8] = 0x56902387;
52 env->regs[9] = 0x40004000 + li->image_size;
53 }
54
55 if (li->cmdline) {
56
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
67void cris_load_image(CRISCPU *cpu, struct cris_load_info *li)
68{
69 CPUCRISState *env = &cpu->env;
70 uint64_t entry;
71 int kcmdline_len;
72 int image_size;
73
74 env->load_info = li;
75
76
77 image_size = load_elf(li->image_filename, NULL,
78 translate_kernel_address, NULL,
79 &entry, NULL, NULL, NULL, 0, EM_CRIS, 0, 0);
80 li->entry = entry;
81 if (image_size < 0) {
82
83 image_size = load_image_targphys(li->image_filename, 0x40004000,
84 li->ram_size);
85 li->entry = 0x40004000;
86 }
87
88 if (image_size < 0) {
89 fprintf(stderr, "qemu: could not load kernel '%s'\n",
90 li->image_filename);
91 exit(1);
92 }
93
94 if (li->cmdline && (kcmdline_len = strlen(li->cmdline))) {
95 if (kcmdline_len > 256) {
96 fprintf(stderr, "Too long CRIS kernel cmdline (max 256)\n");
97 exit(1);
98 }
99 pstrcpy_targphys("cmdline", 0x40000000, 256, li->cmdline);
100 }
101 qemu_register_reset(main_cpu_reset, cpu);
102}
103