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>
25 /* Notify a running simulator, if any, that an exec just occurred. */
26 static void sim_notify_exec(const char *binary_name)
31 __insn_mtspr(SPR_SIM_CONTROL,
33 | (c << _SIM_CONTROL_OPERATOR_BITS)));
38 static int notify_exec(void)
40 int retval = 0; /* failure */
41 struct vm_area_struct *vma = current->mm->mmap;
43 if ((vma->vm_flags & VM_EXECUTABLE) && vma->vm_file)
48 char *buf = (char *) __get_free_page(GFP_KERNEL);
50 char *path = d_path(&vma->vm_file->f_path,
53 sim_notify_exec(path);
56 free_page((unsigned long)buf);
62 /* Notify a running simulator, if any, that we loaded an interpreter. */
63 static void sim_notify_interp(unsigned long load_addr)
66 for (i = 0; i < sizeof(load_addr); i++) {
67 unsigned char c = load_addr >> (i * 8);
68 __insn_mtspr(SPR_SIM_CONTROL,
69 (SIM_CONTROL_OS_INTERP
70 | (c << _SIM_CONTROL_OPERATOR_BITS)));
75 /* Kernel address of page used to map read-only kernel data into userspace. */
76 static void *vdso_page;
78 /* One-entry array used for install_special_mapping. */
79 static struct page *vdso_pages[1];
81 static int __init vdso_setup(void)
83 vdso_page = (void *)get_zeroed_page(GFP_ATOMIC);
84 memcpy(vdso_page, __rt_sigreturn, __rt_sigreturn_end - __rt_sigreturn);
85 vdso_pages[0] = virt_to_page(vdso_page);
88 device_initcall(vdso_setup);
90 const char *arch_vma_name(struct vm_area_struct *vma)
92 if (vma->vm_private_data == vdso_pages)
95 if (vma->vm_start == MEM_USER_INTRPT)
101 int arch_setup_additional_pages(struct linux_binprm *bprm,
102 int executable_stack)
104 struct mm_struct *mm = current->mm;
105 unsigned long vdso_base;
109 * Notify the simulator that an exec just occurred.
110 * If we can't find the filename of the mapping, just use
111 * whatever was passed as the linux_binprm filename.
114 sim_notify_exec(bprm->filename);
116 down_write(&mm->mmap_sem);
119 * MAYWRITE to allow gdb to COW and set breakpoints
121 vdso_base = VDSO_BASE;
122 retval = install_special_mapping(mm, vdso_base, PAGE_SIZE,
124 VM_MAYREAD|VM_MAYWRITE|VM_MAYEXEC,
129 * Set up a user-interrupt mapping here; the user can't
130 * create one themselves since it is above TASK_SIZE.
131 * We make it unwritable by default, so the model for adding
132 * interrupt vectors always involves an mprotect.
135 unsigned long addr = MEM_USER_INTRPT;
136 addr = mmap_region(NULL, addr, INTRPT_SIZE,
137 MAP_FIXED|MAP_ANONYMOUS|MAP_PRIVATE,
139 VM_MAYREAD|VM_MAYWRITE|VM_MAYEXEC, 0);
140 if (addr > (unsigned long) -PAGE_SIZE)
145 up_write(&mm->mmap_sem);
151 void elf_plat_init(struct pt_regs *regs, unsigned long load_addr)
153 /* Zero all registers. */
154 memset(regs, 0, sizeof(*regs));
156 /* Report the interpreter's load address. */
157 sim_notify_interp(load_addr);