Skip to content

Commit 87c1a3f

Browse files
committed
unicore32 core architecture: generic elf and ksyms stuff
This patch includes some generic stuff including elf and ksyms. Because all one-line asm-generic headers are auto-generated by ASM_GENERIC_HEADERS in arch/unicore32/Makefile, so the rest seems very little. ELF handling functions and module handling functions are also here. Signed-off-by: Guan Xuetao <gxt@mprc.pku.edu.cn> Reviewed-by: Arnd Bergmann <arnd@arndb.de>
1 parent 790edb6 commit 87c1a3f

8 files changed

Lines changed: 571 additions & 0 deletions

File tree

‎arch/unicore32/include/asm/elf.h‎

Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
/*
2+
* linux/arch/unicore32/include/asm/elf.h
3+
*
4+
* Code specific to PKUnity SoC and UniCore ISA
5+
*
6+
* Copyright (C) 2001-2010 GUAN Xue-tao
7+
*
8+
* This program is free software; you can redistribute it and/or modify
9+
* it under the terms of the GNU General Public License version 2 as
10+
* published by the Free Software Foundation.
11+
*/
12+
13+
#ifndef __UNICORE_ELF_H__
14+
#define __UNICORE_ELF_H__
15+
16+
#include <asm/hwcap.h>
17+
18+
/*
19+
* ELF register definitions..
20+
*/
21+
#include <asm/ptrace.h>
22+
23+
typedef unsigned long elf_greg_t;
24+
typedef unsigned long elf_freg_t[3];
25+
26+
#define ELF_NGREG (sizeof(struct pt_regs) / sizeof(elf_greg_t))
27+
typedef elf_greg_t elf_gregset_t[ELF_NGREG];
28+
29+
typedef struct fp_state elf_fpregset_t;
30+
31+
#define EM_UNICORE 110
32+
33+
#define R_UNICORE_NONE 0
34+
#define R_UNICORE_PC24 1
35+
#define R_UNICORE_ABS32 2
36+
#define R_UNICORE_CALL 28
37+
#define R_UNICORE_JUMP24 29
38+
39+
/*
40+
* These are used to set parameters in the core dumps.
41+
*/
42+
#define ELF_CLASS ELFCLASS32
43+
#define ELF_DATA ELFDATA2LSB
44+
#define ELF_ARCH EM_UNICORE
45+
46+
/*
47+
* This yields a string that ld.so will use to load implementation
48+
* specific libraries for optimization. This is more specific in
49+
* intent than poking at uname or /proc/cpuinfo.
50+
*
51+
*/
52+
#define ELF_PLATFORM_SIZE 8
53+
#define ELF_PLATFORM (elf_platform)
54+
55+
extern char elf_platform[];
56+
57+
struct elf32_hdr;
58+
59+
/*
60+
* This is used to ensure we don't load something for the wrong architecture.
61+
*/
62+
extern int elf_check_arch(const struct elf32_hdr *);
63+
#define elf_check_arch elf_check_arch
64+
65+
struct task_struct;
66+
int dump_task_regs(struct task_struct *t, elf_gregset_t *elfregs);
67+
#define ELF_CORE_COPY_TASK_REGS dump_task_regs
68+
69+
#define ELF_EXEC_PAGESIZE 4096
70+
71+
/* This is the location that an ET_DYN program is loaded if exec'ed. Typical
72+
use of this is to invoke "./ld.so someprog" to test out a new version of
73+
the loader. We need to make sure that it is out of the way of the program
74+
that it will "exec", and that there is sufficient room for the brk. */
75+
76+
#define ELF_ET_DYN_BASE (2 * TASK_SIZE / 3)
77+
78+
/* When the program starts, a1 contains a pointer to a function to be
79+
registered with atexit, as per the SVR4 ABI. A value of 0 means we
80+
have no such handler. */
81+
#define ELF_PLAT_INIT(_r, load_addr) {(_r)->UCreg_00 = 0; }
82+
83+
extern void elf_set_personality(const struct elf32_hdr *);
84+
#define SET_PERSONALITY(ex) elf_set_personality(&(ex))
85+
86+
struct mm_struct;
87+
extern unsigned long arch_randomize_brk(struct mm_struct *mm);
88+
#define arch_randomize_brk arch_randomize_brk
89+
90+
extern int vectors_user_mapping(void);
91+
#define arch_setup_additional_pages(bprm, uses_interp) vectors_user_mapping()
92+
#define ARCH_HAS_SETUP_ADDITIONAL_PAGES
93+
94+
#endif
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
/*
2+
* linux/arch/unicore32/include/asm/string.h
3+
*
4+
* Code specific to PKUnity SoC and UniCore ISA
5+
*
6+
* Copyright (C) 2001-2010 GUAN Xue-tao
7+
*
8+
* This program is free software; you can redistribute it and/or modify
9+
* it under the terms of the GNU General Public License version 2 as
10+
* published by the Free Software Foundation.
11+
*/
12+
#ifndef __UNICORE_STRING_H__
13+
#define __UNICORE_STRING_H__
14+
15+
/*
16+
* We don't do inline string functions, since the
17+
* optimised inline asm versions are not small.
18+
*/
19+
20+
#define __HAVE_ARCH_STRRCHR
21+
extern char *strrchr(const char *s, int c);
22+
23+
#define __HAVE_ARCH_STRCHR
24+
extern char *strchr(const char *s, int c);
25+
26+
#define __HAVE_ARCH_MEMCPY
27+
extern void *memcpy(void *, const void *, __kernel_size_t);
28+
29+
#define __HAVE_ARCH_MEMMOVE
30+
extern void *memmove(void *, const void *, __kernel_size_t);
31+
32+
#define __HAVE_ARCH_MEMCHR
33+
extern void *memchr(const void *, int, __kernel_size_t);
34+
35+
#define __HAVE_ARCH_MEMSET
36+
extern void *memset(void *, int, __kernel_size_t);
37+
38+
#endif
Lines changed: 112 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,112 @@
1+
/*
2+
* linux/arch/unicore32/kernel/asm-offsets.c
3+
*
4+
* Code specific to PKUnity SoC and UniCore ISA
5+
*
6+
* Copyright (C) 2001-2010 GUAN Xue-tao
7+
*
8+
* Generate definitions needed by assembly language modules.
9+
* This code generates raw asm output which is post-processed to extract
10+
* and format the required data.
11+
*
12+
* This program is free software; you can redistribute it and/or modify
13+
* it under the terms of the GNU General Public License version 2 as
14+
* published by the Free Software Foundation.
15+
*/
16+
#include <linux/sched.h>
17+
#include <linux/mm.h>
18+
#include <linux/dma-mapping.h>
19+
#include <linux/kbuild.h>
20+
#include <linux/suspend.h>
21+
#include <linux/thread_info.h>
22+
#include <asm/memory.h>
23+
#include <asm/suspend.h>
24+
25+
/*
26+
* GCC 3.0, 3.1: general bad code generation.
27+
* GCC 3.2.0: incorrect function argument offset calculation.
28+
* GCC 3.2.x: miscompiles NEW_AUX_ENT in fs/binfmt_elf.c
29+
* (http://gcc.gnu.org/PR8896) and incorrect structure
30+
* initialisation in fs/jffs2/erase.c
31+
*/
32+
#if (__GNUC__ < 4)
33+
#error Your compiler should upgrade to uc4
34+
#error Known good compilers: 4.2.2
35+
#endif
36+
37+
int main(void)
38+
{
39+
DEFINE(TSK_ACTIVE_MM, offsetof(struct task_struct, active_mm));
40+
BLANK();
41+
DEFINE(TI_FLAGS, offsetof(struct thread_info, flags));
42+
DEFINE(TI_PREEMPT, offsetof(struct thread_info, preempt_count));
43+
DEFINE(TI_ADDR_LIMIT, offsetof(struct thread_info, addr_limit));
44+
DEFINE(TI_TASK, offsetof(struct thread_info, task));
45+
DEFINE(TI_EXEC_DOMAIN, offsetof(struct thread_info, exec_domain));
46+
DEFINE(TI_CPU, offsetof(struct thread_info, cpu));
47+
DEFINE(TI_CPU_SAVE, offsetof(struct thread_info, cpu_context));
48+
DEFINE(TI_USED_CP, offsetof(struct thread_info, used_cp));
49+
#ifdef CONFIG_UNICORE_FPU_F64
50+
DEFINE(TI_FPSTATE, offsetof(struct thread_info, fpstate));
51+
#endif
52+
BLANK();
53+
DEFINE(S_R0, offsetof(struct pt_regs, UCreg_00));
54+
DEFINE(S_R1, offsetof(struct pt_regs, UCreg_01));
55+
DEFINE(S_R2, offsetof(struct pt_regs, UCreg_02));
56+
DEFINE(S_R3, offsetof(struct pt_regs, UCreg_03));
57+
DEFINE(S_R4, offsetof(struct pt_regs, UCreg_04));
58+
DEFINE(S_R5, offsetof(struct pt_regs, UCreg_05));
59+
DEFINE(S_R6, offsetof(struct pt_regs, UCreg_06));
60+
DEFINE(S_R7, offsetof(struct pt_regs, UCreg_07));
61+
DEFINE(S_R8, offsetof(struct pt_regs, UCreg_08));
62+
DEFINE(S_R9, offsetof(struct pt_regs, UCreg_09));
63+
DEFINE(S_R10, offsetof(struct pt_regs, UCreg_10));
64+
DEFINE(S_R11, offsetof(struct pt_regs, UCreg_11));
65+
DEFINE(S_R12, offsetof(struct pt_regs, UCreg_12));
66+
DEFINE(S_R13, offsetof(struct pt_regs, UCreg_13));
67+
DEFINE(S_R14, offsetof(struct pt_regs, UCreg_14));
68+
DEFINE(S_R15, offsetof(struct pt_regs, UCreg_15));
69+
DEFINE(S_R16, offsetof(struct pt_regs, UCreg_16));
70+
DEFINE(S_R17, offsetof(struct pt_regs, UCreg_17));
71+
DEFINE(S_R18, offsetof(struct pt_regs, UCreg_18));
72+
DEFINE(S_R19, offsetof(struct pt_regs, UCreg_19));
73+
DEFINE(S_R20, offsetof(struct pt_regs, UCreg_20));
74+
DEFINE(S_R21, offsetof(struct pt_regs, UCreg_21));
75+
DEFINE(S_R22, offsetof(struct pt_regs, UCreg_22));
76+
DEFINE(S_R23, offsetof(struct pt_regs, UCreg_23));
77+
DEFINE(S_R24, offsetof(struct pt_regs, UCreg_24));
78+
DEFINE(S_R25, offsetof(struct pt_regs, UCreg_25));
79+
DEFINE(S_R26, offsetof(struct pt_regs, UCreg_26));
80+
DEFINE(S_FP, offsetof(struct pt_regs, UCreg_fp));
81+
DEFINE(S_IP, offsetof(struct pt_regs, UCreg_ip));
82+
DEFINE(S_SP, offsetof(struct pt_regs, UCreg_sp));
83+
DEFINE(S_LR, offsetof(struct pt_regs, UCreg_lr));
84+
DEFINE(S_PC, offsetof(struct pt_regs, UCreg_pc));
85+
DEFINE(S_PSR, offsetof(struct pt_regs, UCreg_asr));
86+
DEFINE(S_OLD_R0, offsetof(struct pt_regs, UCreg_ORIG_00));
87+
DEFINE(S_FRAME_SIZE, sizeof(struct pt_regs));
88+
BLANK();
89+
DEFINE(VMA_VM_MM, offsetof(struct vm_area_struct, vm_mm));
90+
DEFINE(VMA_VM_FLAGS, offsetof(struct vm_area_struct, vm_flags));
91+
BLANK();
92+
DEFINE(VM_EXEC, VM_EXEC);
93+
BLANK();
94+
DEFINE(PAGE_SZ, PAGE_SIZE);
95+
BLANK();
96+
DEFINE(SYS_ERROR0, 0x9f0000);
97+
BLANK();
98+
DEFINE(PBE_ADDRESS, offsetof(struct pbe, address));
99+
DEFINE(PBE_ORIN_ADDRESS, offsetof(struct pbe, orig_address));
100+
DEFINE(PBE_NEXT, offsetof(struct pbe, next));
101+
DEFINE(SWSUSP_CPU, offsetof(struct swsusp_arch_regs, \
102+
cpu_context));
103+
#ifdef CONFIG_UNICORE_FPU_F64
104+
DEFINE(SWSUSP_FPSTATE, offsetof(struct swsusp_arch_regs, \
105+
fpstate));
106+
#endif
107+
BLANK();
108+
DEFINE(DMA_BIDIRECTIONAL, DMA_BIDIRECTIONAL);
109+
DEFINE(DMA_TO_DEVICE, DMA_TO_DEVICE);
110+
DEFINE(DMA_FROM_DEVICE, DMA_FROM_DEVICE);
111+
return 0;
112+
}

‎arch/unicore32/kernel/elf.c‎

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
/*
2+
* linux/arch/unicore32/kernel/elf.c
3+
*
4+
* Code specific to PKUnity SoC and UniCore ISA
5+
*
6+
* Copyright (C) 2001-2010 GUAN Xue-tao
7+
*
8+
* This program is free software; you can redistribute it and/or modify
9+
* it under the terms of the GNU General Public License version 2 as
10+
* published by the Free Software Foundation.
11+
*/
12+
#include <linux/module.h>
13+
#include <linux/sched.h>
14+
#include <linux/personality.h>
15+
#include <linux/binfmts.h>
16+
#include <linux/elf.h>
17+
18+
int elf_check_arch(const struct elf32_hdr *x)
19+
{
20+
/* Make sure it's an UniCore executable */
21+
if (x->e_machine != EM_UNICORE)
22+
return 0;
23+
24+
/* Make sure the entry address is reasonable */
25+
if (x->e_entry & 3)
26+
return 0;
27+
28+
return 1;
29+
}
30+
EXPORT_SYMBOL(elf_check_arch);
31+
32+
void elf_set_personality(const struct elf32_hdr *x)
33+
{
34+
unsigned int personality = PER_LINUX;
35+
36+
set_personality(personality);
37+
}
38+
EXPORT_SYMBOL(elf_set_personality);

‎arch/unicore32/kernel/ksyms.c‎

Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
/*
2+
* linux/arch/unicore32/kernel/ksyms.c
3+
*
4+
* Code specific to PKUnity SoC and UniCore ISA
5+
*
6+
* Copyright (C) 2001-2010 GUAN Xue-tao
7+
*
8+
* This program is free software; you can redistribute it and/or modify
9+
* it under the terms of the GNU General Public License version 2 as
10+
* published by the Free Software Foundation.
11+
*/
12+
#include <linux/module.h>
13+
#include <linux/sched.h>
14+
#include <linux/string.h>
15+
#include <linux/cryptohash.h>
16+
#include <linux/delay.h>
17+
#include <linux/in6.h>
18+
#include <linux/syscalls.h>
19+
#include <linux/uaccess.h>
20+
#include <linux/io.h>
21+
22+
#include <asm/checksum.h>
23+
#include <asm/system.h>
24+
25+
#include "ksyms.h"
26+
27+
EXPORT_SYMBOL(__uc32_find_next_zero_bit);
28+
EXPORT_SYMBOL(__uc32_find_next_bit);
29+
30+
EXPORT_SYMBOL(__backtrace);
31+
32+
/* platform dependent support */
33+
EXPORT_SYMBOL(__udelay);
34+
EXPORT_SYMBOL(__const_udelay);
35+
36+
/* networking */
37+
EXPORT_SYMBOL(csum_partial);
38+
EXPORT_SYMBOL(csum_partial_copy_from_user);
39+
EXPORT_SYMBOL(csum_partial_copy_nocheck);
40+
EXPORT_SYMBOL(__csum_ipv6_magic);
41+
42+
/* io */
43+
#ifndef __raw_readsb
44+
EXPORT_SYMBOL(__raw_readsb);
45+
#endif
46+
#ifndef __raw_readsw
47+
EXPORT_SYMBOL(__raw_readsw);
48+
#endif
49+
#ifndef __raw_readsl
50+
EXPORT_SYMBOL(__raw_readsl);
51+
#endif
52+
#ifndef __raw_writesb
53+
EXPORT_SYMBOL(__raw_writesb);
54+
#endif
55+
#ifndef __raw_writesw
56+
EXPORT_SYMBOL(__raw_writesw);
57+
#endif
58+
#ifndef __raw_writesl
59+
EXPORT_SYMBOL(__raw_writesl);
60+
#endif
61+
62+
/* string / mem functions */
63+
EXPORT_SYMBOL(strchr);
64+
EXPORT_SYMBOL(strrchr);
65+
EXPORT_SYMBOL(memset);
66+
EXPORT_SYMBOL(memcpy);
67+
EXPORT_SYMBOL(memmove);
68+
EXPORT_SYMBOL(memchr);
69+
70+
/* user mem (segment) */
71+
EXPORT_SYMBOL(__strnlen_user);
72+
EXPORT_SYMBOL(__strncpy_from_user);
73+
74+
EXPORT_SYMBOL(copy_page);
75+
76+
EXPORT_SYMBOL(__copy_from_user);
77+
EXPORT_SYMBOL(__copy_to_user);
78+
EXPORT_SYMBOL(__clear_user);
79+
80+
EXPORT_SYMBOL(__get_user_1);
81+
EXPORT_SYMBOL(__get_user_2);
82+
EXPORT_SYMBOL(__get_user_4);
83+
84+
EXPORT_SYMBOL(__put_user_1);
85+
EXPORT_SYMBOL(__put_user_2);
86+
EXPORT_SYMBOL(__put_user_4);
87+
EXPORT_SYMBOL(__put_user_8);
88+
89+
EXPORT_SYMBOL(__ashldi3);
90+
EXPORT_SYMBOL(__ashrdi3);
91+
EXPORT_SYMBOL(__divsi3);
92+
EXPORT_SYMBOL(__lshrdi3);
93+
EXPORT_SYMBOL(__modsi3);
94+
EXPORT_SYMBOL(__muldi3);
95+
EXPORT_SYMBOL(__ucmpdi2);
96+
EXPORT_SYMBOL(__udivsi3);
97+
EXPORT_SYMBOL(__umodsi3);
98+
EXPORT_SYMBOL(__bswapsi2);
99+

0 commit comments

Comments
 (0)