2 * Copyright 2010 Tilera Corporation. All Rights Reserved.
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License
6 * as published by the Free Software Foundation, version 2.
8 * This program is distributed in the hope that it will be useful, but
9 * WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE, GOOD TITLE or
11 * NON INFRINGEMENT. See the GNU General Public License for
16 #include <linux/pagemap.h>
17 #include <linux/binfmts.h>
18 #include <linux/compat.h>
19 #include <linux/mman.h>
20 #include <linux/elf.h>
21 #include <asm/pgtable.h>
22 #include <asm/pgalloc.h>
23 #include <asm/sections.h>
24 #include <arch/sim_def.h>
26 /* Notify a running simulator, if any, that an exec just occurred. */
27 static void sim_notify_exec(const char *binary_name)
32 __insn_mtspr(SPR_SIM_CONTROL,
34 | (c << _SIM_CONTROL_OPERATOR_BITS)));
39 static int notify_exec(struct mm_struct *mm)
41 int retval = 0; /* failure */
44 char *buf = (char *) __get_free_page(GFP_KERNEL);
46 char *path = d_path(&mm->exe_file->f_path,
49 sim_notify_exec(path);
52 free_page((unsigned long)buf);
58 /* Notify a running simulator, if any, that we loaded an interpreter. */
59 static void sim_notify_interp(unsigned long load_addr)
62 for (i = 0; i < sizeof(load_addr); i++) {
63 unsigned char c = load_addr >> (i * 8);
64 __insn_mtspr(SPR_SIM_CONTROL,
65 (SIM_CONTROL_OS_INTERP
66 | (c << _SIM_CONTROL_OPERATOR_BITS)));
71 /* Kernel address of page used to map read-only kernel data into userspace. */
72 static void *vdso_page;
74 /* One-entry array used for install_special_mapping. */
75 static struct page *vdso_pages[1];
77 static int __init vdso_setup(void)
79 vdso_page = (void *)get_zeroed_page(GFP_ATOMIC);
80 memcpy(vdso_page, __rt_sigreturn, __rt_sigreturn_end - __rt_sigreturn);
81 vdso_pages[0] = virt_to_page(vdso_page);
84 device_initcall(vdso_setup);
86 const char *arch_vma_name(struct vm_area_struct *vma)
88 if (vma->vm_private_data == vdso_pages)
91 if (vma->vm_start == MEM_USER_INTRPT)
97 int arch_setup_additional_pages(struct linux_binprm *bprm,
100 struct mm_struct *mm = current->mm;
101 unsigned long vdso_base;
104 down_write(&mm->mmap_sem);
107 * Notify the simulator that an exec just occurred.
108 * If we can't find the filename of the mapping, just use
109 * whatever was passed as the linux_binprm filename.
111 if (!notify_exec(mm))
112 sim_notify_exec(bprm->filename);
115 * MAYWRITE to allow gdb to COW and set breakpoints
117 vdso_base = VDSO_BASE;
118 retval = install_special_mapping(mm, vdso_base, PAGE_SIZE,
120 VM_MAYREAD|VM_MAYWRITE|VM_MAYEXEC,
125 * Set up a user-interrupt mapping here; the user can't
126 * create one themselves since it is above TASK_SIZE.
127 * We make it unwritable by default, so the model for adding
128 * interrupt vectors always involves an mprotect.
131 unsigned long addr = MEM_USER_INTRPT;
132 addr = mmap_region(NULL, addr, INTRPT_SIZE,
134 VM_MAYREAD|VM_MAYWRITE|VM_MAYEXEC, 0);
135 if (addr > (unsigned long) -PAGE_SIZE)
140 up_write(&mm->mmap_sem);
146 void elf_plat_init(struct pt_regs *regs, unsigned long load_addr)
148 /* Zero all registers. */
149 memset(regs, 0, sizeof(*regs));
151 /* Report the interpreter's load address. */
152 sim_notify_interp(load_addr);