Skip to content

Commit f73670e

Browse files
committed
unicore32 core architecture: process/thread related codes
This patch implements process/thread related codes. Backtrace and stacktrace are here. Signed-off-by: Guan Xuetao <gxt@mprc.pku.edu.cn> Reviewed-by: Arnd Bergmann <arnd@arndb.de>
1 parent 141c943 commit f73670e

6 files changed

Lines changed: 912 additions & 0 deletions

File tree

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
/*
2+
* linux/arch/unicore32/include/asm/stacktrace.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_STACKTRACE_H__
14+
#define __UNICORE_STACKTRACE_H__
15+
16+
struct stackframe {
17+
unsigned long fp;
18+
unsigned long sp;
19+
unsigned long lr;
20+
unsigned long pc;
21+
};
22+
23+
#ifdef CONFIG_FRAME_POINTER
24+
extern int unwind_frame(struct stackframe *frame);
25+
#else
26+
#define unwind_frame(f) (-EINVAL)
27+
#endif
28+
extern void walk_stackframe(struct stackframe *frame,
29+
int (*fn)(struct stackframe *, void *), void *data);
30+
31+
#endif /* __UNICORE_STACKTRACE_H__ */
Lines changed: 154 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,154 @@
1+
/*
2+
* linux/arch/unicore32/include/asm/thread_info.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_THREAD_INFO_H__
13+
#define __UNICORE_THREAD_INFO_H__
14+
15+
#ifdef __KERNEL__
16+
17+
#include <linux/compiler.h>
18+
#include <asm/fpstate.h>
19+
20+
#define THREAD_SIZE_ORDER 1
21+
#define THREAD_SIZE 8192
22+
#define THREAD_START_SP (THREAD_SIZE - 8)
23+
24+
#ifndef __ASSEMBLY__
25+
26+
struct task_struct;
27+
struct exec_domain;
28+
29+
#include <asm/types.h>
30+
31+
typedef struct {
32+
unsigned long seg;
33+
} mm_segment_t;
34+
35+
struct cpu_context_save {
36+
__u32 r4;
37+
__u32 r5;
38+
__u32 r6;
39+
__u32 r7;
40+
__u32 r8;
41+
__u32 r9;
42+
__u32 r10;
43+
__u32 r11;
44+
__u32 r12;
45+
__u32 r13;
46+
__u32 r14;
47+
__u32 r15;
48+
__u32 r16;
49+
__u32 r17;
50+
__u32 r18;
51+
__u32 r19;
52+
__u32 r20;
53+
__u32 r21;
54+
__u32 r22;
55+
__u32 r23;
56+
__u32 r24;
57+
__u32 r25;
58+
__u32 r26;
59+
__u32 fp;
60+
__u32 sp;
61+
__u32 pc;
62+
};
63+
64+
/*
65+
* low level task data that entry.S needs immediate access to.
66+
* __switch_to() assumes cpu_context follows immediately after cpu_domain.
67+
*/
68+
struct thread_info {
69+
unsigned long flags; /* low level flags */
70+
int preempt_count; /* 0 => preemptable */
71+
/* <0 => bug */
72+
mm_segment_t addr_limit; /* address limit */
73+
struct task_struct *task; /* main task structure */
74+
struct exec_domain *exec_domain; /* execution domain */
75+
__u32 cpu; /* cpu */
76+
struct cpu_context_save cpu_context; /* cpu context */
77+
__u32 syscall; /* syscall number */
78+
__u8 used_cp[16]; /* thread used copro */
79+
#ifdef CONFIG_UNICORE_FPU_F64
80+
struct fp_state fpstate __attribute__((aligned(8)));
81+
#endif
82+
struct restart_block restart_block;
83+
};
84+
85+
#define INIT_THREAD_INFO(tsk) \
86+
{ \
87+
.task = &tsk, \
88+
.exec_domain = &default_exec_domain, \
89+
.flags = 0, \
90+
.preempt_count = INIT_PREEMPT_COUNT, \
91+
.addr_limit = KERNEL_DS, \
92+
.restart_block = { \
93+
.fn = do_no_restart_syscall, \
94+
}, \
95+
}
96+
97+
#define init_thread_info (init_thread_union.thread_info)
98+
#define init_stack (init_thread_union.stack)
99+
100+
/*
101+
* how to get the thread information struct from C
102+
*/
103+
static inline struct thread_info *current_thread_info(void) __attribute_const__;
104+
105+
static inline struct thread_info *current_thread_info(void)
106+
{
107+
register unsigned long sp asm ("sp");
108+
return (struct thread_info *)(sp & ~(THREAD_SIZE - 1));
109+
}
110+
111+
#define thread_saved_pc(tsk) \
112+
((unsigned long)(task_thread_info(tsk)->cpu_context.pc))
113+
#define thread_saved_sp(tsk) \
114+
((unsigned long)(task_thread_info(tsk)->cpu_context.sp))
115+
#define thread_saved_fp(tsk) \
116+
((unsigned long)(task_thread_info(tsk)->cpu_context.fp))
117+
118+
#endif
119+
120+
/*
121+
* We use bit 30 of the preempt_count to indicate that kernel
122+
* preemption is occurring. See <asm/hardirq.h>.
123+
*/
124+
#define PREEMPT_ACTIVE 0x40000000
125+
126+
/*
127+
* thread information flags:
128+
* TIF_SYSCALL_TRACE - syscall trace active
129+
* TIF_SIGPENDING - signal pending
130+
* TIF_NEED_RESCHED - rescheduling necessary
131+
* TIF_NOTIFY_RESUME - callback before returning to user
132+
*/
133+
#define TIF_SIGPENDING 0
134+
#define TIF_NEED_RESCHED 1
135+
#define TIF_NOTIFY_RESUME 2 /* callback before returning to user */
136+
#define TIF_SYSCALL_TRACE 8
137+
#define TIF_MEMDIE 18
138+
#define TIF_FREEZE 19
139+
#define TIF_RESTORE_SIGMASK 20
140+
141+
#define _TIF_SIGPENDING (1 << TIF_SIGPENDING)
142+
#define _TIF_NEED_RESCHED (1 << TIF_NEED_RESCHED)
143+
#define _TIF_NOTIFY_RESUME (1 << TIF_NOTIFY_RESUME)
144+
#define _TIF_SYSCALL_TRACE (1 << TIF_SYSCALL_TRACE)
145+
#define _TIF_FREEZE (1 << TIF_FREEZE)
146+
#define _TIF_RESTORE_SIGMASK (1 << TIF_RESTORE_SIGMASK)
147+
148+
/*
149+
* Change these and you break ASM code in entry-common.S
150+
*/
151+
#define _TIF_WORK_MASK 0x000000ff
152+
153+
#endif /* __KERNEL__ */
154+
#endif /* __UNICORE_THREAD_INFO_H__ */

‎arch/unicore32/kernel/init_task.c‎

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
/*
2+
* linux/arch/unicore32/kernel/init_task.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/mm.h>
13+
#include <linux/module.h>
14+
#include <linux/fs.h>
15+
#include <linux/sched.h>
16+
#include <linux/init.h>
17+
#include <linux/init_task.h>
18+
#include <linux/mqueue.h>
19+
#include <linux/uaccess.h>
20+
21+
#include <asm/pgtable.h>
22+
23+
static struct signal_struct init_signals = INIT_SIGNALS(init_signals);
24+
static struct sighand_struct init_sighand = INIT_SIGHAND(init_sighand);
25+
/*
26+
* Initial thread structure.
27+
*
28+
* We need to make sure that this is 8192-byte aligned due to the
29+
* way process stacks are handled. This is done by making sure
30+
* the linker maps this in the .text segment right after head.S,
31+
* and making head.S ensure the proper alignment.
32+
*
33+
* The things we do for performance..
34+
*/
35+
union thread_union init_thread_union __init_task_data = {
36+
INIT_THREAD_INFO(init_task) };
37+
38+
/*
39+
* Initial task structure.
40+
*
41+
* All other task structs will be allocated on slabs in fork.c
42+
*/
43+
struct task_struct init_task = INIT_TASK(init_task);
44+
EXPORT_SYMBOL(init_task);

0 commit comments

Comments
 (0)