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>
27 /* Notify a running simulator, if any, that an exec just occurred. */
28 static void sim_notify_exec(const char *binary_name
)
33 __insn_mtspr(SPR_SIM_CONTROL
,
35 | (c
<< _SIM_CONTROL_OPERATOR_BITS
)));
40 static int notify_exec(struct mm_struct
*mm
)
43 struct vm_area_struct
*vma
;
45 if (!sim_is_simulator())
48 if (mm
->exe_file
== NULL
)
51 for (vma
= current
->mm
->mmap
; ; vma
= vma
->vm_next
) {
54 if (vma
->vm_file
== mm
->exe_file
)
58 buf
= (char *) __get_free_page(GFP_KERNEL
);
62 path
= d_path(&mm
->exe_file
->f_path
, buf
, PAGE_SIZE
);
64 free_page((unsigned long)buf
);
69 * Notify simulator of an ET_DYN object so we know the load address.
70 * The somewhat cryptic overuse of SIM_CONTROL_DLOPEN allows us
71 * to be backward-compatible with older simulator releases.
73 if (vma
->vm_start
== (ELF_ET_DYN_BASE
& PAGE_MASK
)) {
77 snprintf(buf
, sizeof(buf
), "0x%lx:@", vma
->vm_start
);
80 __insn_mtspr(SPR_SIM_CONTROL
,
82 | (c
<< _SIM_CONTROL_OPERATOR_BITS
)));
88 sim_notify_exec(path
);
89 free_page((unsigned long)buf
);
93 /* Notify a running simulator, if any, that we loaded an interpreter. */
94 static void sim_notify_interp(unsigned long load_addr
)
97 for (i
= 0; i
< sizeof(load_addr
); i
++) {
98 unsigned char c
= load_addr
>> (i
* 8);
99 __insn_mtspr(SPR_SIM_CONTROL
,
100 (SIM_CONTROL_OS_INTERP
101 | (c
<< _SIM_CONTROL_OPERATOR_BITS
)));
106 int arch_setup_additional_pages(struct linux_binprm
*bprm
,
107 int executable_stack
)
109 struct mm_struct
*mm
= current
->mm
;
112 down_write(&mm
->mmap_sem
);
115 * Notify the simulator that an exec just occurred.
116 * If we can't find the filename of the mapping, just use
117 * whatever was passed as the linux_binprm filename.
119 if (!notify_exec(mm
))
120 sim_notify_exec(bprm
->filename
);
122 retval
= setup_vdso_pages();
126 * Set up a user-interrupt mapping here; the user can't
127 * create one themselves since it is above TASK_SIZE.
128 * We make it unwritable by default, so the model for adding
129 * interrupt vectors always involves an mprotect.
132 unsigned long addr
= MEM_USER_INTRPT
;
133 addr
= mmap_region(NULL
, addr
, INTRPT_SIZE
,
135 VM_MAYREAD
|VM_MAYWRITE
|VM_MAYEXEC
, 0);
136 if (addr
> (unsigned long) -PAGE_SIZE
)
141 up_write(&mm
->mmap_sem
);
147 void elf_plat_init(struct pt_regs
*regs
, unsigned long load_addr
)
149 /* Zero all registers. */
150 memset(regs
, 0, sizeof(*regs
));
152 /* Report the interpreter's load address. */
153 sim_notify_interp(load_addr
);