e2k: move e2k_psp_new to cpu.c

Signed-off-by: Denis Drakhnia <numas13@gmail.com>
This commit is contained in:
Denis Drakhnia 2022-06-18 15:03:07 +03:00
parent fb9330bd0e
commit f43cc408fb
6 changed files with 56 additions and 41 deletions

View File

@ -1,7 +1,7 @@
#ifndef E2K_TARGET_CPU_H #ifndef E2K_TARGET_CPU_H
#define E2K_TARGET_CPU_H #define E2K_TARGET_CPU_H
#include "qemu/log.h" #include "user-mmap.h"
abi_long e2k_copy_from_user_crs(E2KCrs *crs, abi_ulong target_crs_addr); abi_long e2k_copy_from_user_crs(E2KCrs *crs, abi_ulong target_crs_addr);
abi_long e2k_copy_to_user_crs(abi_ulong target_crs_addr, E2KCrs *crs); abi_long e2k_copy_to_user_crs(abi_ulong target_crs_addr, E2KCrs *crs);
@ -27,8 +27,9 @@ static inline void cpu_clone_regs_child(CPUE2KState *env, target_ulong newsp,
target_ulong ps_base = env->psp.base + env->psp.index; target_ulong ps_base = env->psp.base + env->psp.index;
int i; int i;
e2k_psp_new(&pcs, E2K_DEFAULT_PCS_SIZE, false); e2k_psp_new(&pcs, E2K_DEFAULT_PCS_SIZE, e2k_mmap(E2K_DEFAULT_PCS_SIZE), 0);
e2k_psp_new(&ps, E2K_DEFAULT_PS_SIZE, true); e2k_psp_new(&ps, E2K_DEFAULT_PS_SIZE, e2k_mmap(E2K_DEFAULT_PS_SIZE),
e2k_mmap(E2K_DEFAULT_PS_SIZE / 8));
// TODO: size checks and a way to report errors // TODO: size checks and a way to report errors
// TODO: set a chain info to return to kernel // TODO: set a chain info to return to kernel

View File

@ -1614,39 +1614,6 @@ static inline void init_thread(struct target_pt_regs *regs,
typedef target_elf_greg_t target_elf_gregset_t[ELF_NREG]; typedef target_elf_greg_t target_elf_gregset_t[ELF_NREG];
#define USE_ELF_CORE_DUMP #define USE_ELF_CORE_DUMP
static abi_ulong e2k_mmap(abi_ulong size)
{
abi_ulong addr;
abi_ulong guard = TARGET_PAGE_SIZE;
if (size < TARGET_PAGE_SIZE) {
size = TARGET_PAGE_SIZE;
}
if (guard < qemu_real_host_page_size()) {
guard = qemu_real_host_page_size();
}
addr = target_mmap(0, size + guard, PROT_READ | PROT_WRITE,
MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);
if (addr == -1) {
perror("mmap e2k stack");
exit(-1);
}
target_mprotect(addr + size, guard, PROT_NONE);
return addr;
}
void e2k_psp_new(E2KPsp *psp, unsigned int size, bool tags)
{
psp->is_readable = true;
psp->is_writable = true;
psp->index = 0;
psp->size = size;
psp->base = e2k_mmap(size);
psp->base_tag = tags ? e2k_mmap(size / 8) : 0;
}
static inline void init_thread(struct target_pt_regs *regs, struct image_info *infop) static inline void init_thread(struct target_pt_regs *regs, struct image_info *infop)
{ {
abi_ulong start_stack = infop->start_stack & ~0xf; abi_ulong start_stack = infop->start_stack & ~0xf;
@ -1658,8 +1625,9 @@ static inline void init_thread(struct target_pt_regs *regs, struct image_info *i
regs->usd_lo = (0x1800UL << 48) | start_stack; regs->usd_lo = (0x1800UL << 48) | start_stack;
regs->usd_hi = (regs->sbr - start_stack) << 32; regs->usd_hi = (regs->sbr - start_stack) << 32;
e2k_psp_new(&regs->pcsp, E2K_DEFAULT_PCS_SIZE, false); e2k_psp_new(&regs->pcsp, E2K_DEFAULT_PCS_SIZE, e2k_mmap(E2K_DEFAULT_PCS_SIZE), 0);
e2k_psp_new(&regs->psp, E2K_DEFAULT_PS_SIZE, true); e2k_psp_new(&regs->psp, E2K_DEFAULT_PS_SIZE, e2k_mmap(E2K_DEFAULT_PS_SIZE),
e2k_mmap(E2K_DEFAULT_PS_SIZE / 8));
} }
static void elf_core_copy_regs(target_elf_gregset_t *regs, const CPUE2KState *env) static void elf_core_copy_regs(target_elf_gregset_t *regs, const CPUE2KState *env)

View File

@ -645,6 +645,31 @@ fail:
return -1; return -1;
} }
#ifdef TARGET_E2K
abi_ulong e2k_mmap(abi_ulong size)
{
abi_ulong addr;
abi_ulong guard = TARGET_PAGE_SIZE;
if (size < TARGET_PAGE_SIZE) {
size = TARGET_PAGE_SIZE;
}
if (guard < qemu_real_host_page_size()) {
guard = qemu_real_host_page_size();
}
addr = target_mmap(0, size + guard, PROT_READ | PROT_WRITE,
MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);
if (addr == -1) {
perror("mmap e2k stack");
exit(-1);
}
target_mprotect(addr + size, guard, PROT_NONE);
return addr;
}
#endif
static void mmap_reserve(abi_ulong start, abi_ulong size) static void mmap_reserve(abi_ulong start, abi_ulong size)
{ {
abi_ulong real_start; abi_ulong real_start;

View File

@ -31,4 +31,8 @@ abi_ulong mmap_find_vma(abi_ulong, abi_ulong, abi_ulong);
void mmap_fork_start(void); void mmap_fork_start(void);
void mmap_fork_end(int child); void mmap_fork_end(int child);
#ifdef TARGET_E2K
abi_ulong e2k_mmap(abi_ulong size);
#endif
#endif /* LINUX_USER_USER_MMAP_H */ #endif /* LINUX_USER_USER_MMAP_H */

View File

@ -330,3 +330,13 @@ void e2k_cpu_list(void)
} }
qemu_printf("\n"); qemu_printf("\n");
} }
void e2k_psp_new(E2KPsp *psp, uint32_t size, uint64_t base, uint64_t base_tags)
{
psp->is_readable = true;
psp->is_writable = true;
psp->index = 0;
psp->size = size;
psp->base = base;
psp->base_tag = base_tags;
}

View File

@ -954,9 +954,16 @@ bool e2k_cpu_tlb_fill(CPUState *cpu, vaddr address, int size,
bool probe, uintptr_t retaddr); bool probe, uintptr_t retaddr);
void e2k_update_fp_status(CPUE2KState *env); void e2k_update_fp_status(CPUE2KState *env);
void e2k_update_fx_status(CPUE2KState *env); void e2k_update_fx_status(CPUE2KState *env);
#ifdef CONFIG_USER_ONLY /*
void e2k_psp_new(E2KPsp *psp, unsigned int size, bool tags); * PCSP
#endif * @base = mmap(size)
* @base_tags = 0
*
* PSP
* @base = mmap(size)
* @base_tags = mmap(size / 8)
*/
void e2k_psp_new(E2KPsp *psp, uint32_t size, uint64_t base, uint64_t base_tags);
void e2k_proc_call(CPUE2KState *env, int base, target_ulong ret_ip, void e2k_proc_call(CPUE2KState *env, int base, target_ulong ret_ip,
bool force_fx); bool force_fx);
void e2k_proc_return(CPUE2KState *env, bool force_fx); void e2k_proc_return(CPUE2KState *env, bool force_fx);