xref: /openbmc/qemu/linux-user/x86_64/elfload.c (revision 3bf5c57a11827d9fa706524d57ee3e5af68a429e)
1 /* SPDX-License-Identifier: GPL-2.0-or-later */
2 
3 #include "qemu/osdep.h"
4 #include "qemu/error-report.h"
5 #include "qemu.h"
6 #include "loader.h"
7 #include "target_elf.h"
8 
9 
10 const char *get_elf_cpu_model(uint32_t eflags)
11 {
12     return "max";
13 }
14 
15 abi_ulong get_elf_hwcap(CPUState *cs)
16 {
17     return cpu_env(cs)->features[FEAT_1_EDX];
18 }
19 
20 const char *get_elf_platform(CPUState *cs)
21 {
22     return "x86_64";
23 }
24 
25 bool init_guest_commpage(void)
26 {
27     /*
28      * The vsyscall page is at a high negative address aka kernel space,
29      * which means that we cannot actually allocate it with target_mmap.
30      * We still should be able to use page_set_flags, unless the user
31      * has specified -R reserved_va, which would trigger an assert().
32      */
33     if (reserved_va != 0 &&
34         TARGET_VSYSCALL_PAGE + TARGET_PAGE_SIZE - 1 > reserved_va) {
35         error_report("Cannot allocate vsyscall page");
36         exit(EXIT_FAILURE);
37     }
38     page_set_flags(TARGET_VSYSCALL_PAGE,
39                    TARGET_VSYSCALL_PAGE | ~TARGET_PAGE_MASK,
40                    PAGE_EXEC | PAGE_VALID, PAGE_VALID);
41     return true;
42 }
43 
44 void elf_core_copy_regs(target_elf_gregset_t *r, const CPUX86State *env)
45 {
46     r->pt.r15 = tswapal(env->regs[15]);
47     r->pt.r14 = tswapal(env->regs[14]);
48     r->pt.r13 = tswapal(env->regs[13]);
49     r->pt.r12 = tswapal(env->regs[12]);
50     r->pt.bp = tswapal(env->regs[R_EBP]);
51     r->pt.bx = tswapal(env->regs[R_EBX]);
52     r->pt.r11 = tswapal(env->regs[11]);
53     r->pt.r10 = tswapal(env->regs[10]);
54     r->pt.r9 = tswapal(env->regs[9]);
55     r->pt.r8 = tswapal(env->regs[8]);
56     r->pt.ax = tswapal(env->regs[R_EAX]);
57     r->pt.cx = tswapal(env->regs[R_ECX]);
58     r->pt.dx = tswapal(env->regs[R_EDX]);
59     r->pt.si = tswapal(env->regs[R_ESI]);
60     r->pt.di = tswapal(env->regs[R_EDI]);
61     r->pt.orig_ax = tswapal(get_task_state(env_cpu_const(env))->orig_ax);
62     r->pt.ip = tswapal(env->eip);
63     r->pt.cs = tswapal(env->segs[R_CS].selector & 0xffff);
64     r->pt.flags = tswapal(env->eflags);
65     r->pt.sp = tswapal(env->regs[R_ESP]);
66     r->pt.ss = tswapal(env->segs[R_SS].selector & 0xffff);
67     r->pt.fs_base = tswapal(env->segs[R_FS].base);
68     r->pt.gs_base = tswapal(env->segs[R_GS].base);
69     r->pt.ds = tswapal(env->segs[R_DS].selector & 0xffff);
70     r->pt.es = tswapal(env->segs[R_ES].selector & 0xffff);
71     r->pt.fs = tswapal(env->segs[R_FS].selector & 0xffff);
72     r->pt.gs = tswapal(env->segs[R_GS].selector & 0xffff);
73 }
74