blob: f5f90bbf019d6842c0cf2cb2b4ae11fcdc362b07 [file] [log] [blame]
David Howellsb920de12008-02-08 04:19:31 -08001/* MN10300 Low-level thread information
2 *
3 * Copyright (C) 2007 Red Hat, Inc. All Rights Reserved.
4 * Written by David Howells (dhowells@redhat.com)
5 *
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public Licence
8 * as published by the Free Software Foundation; either version
9 * 2 of the Licence, or (at your option) any later version.
10 */
11
12#ifndef _ASM_THREAD_INFO_H
13#define _ASM_THREAD_INFO_H
14
15#ifdef __KERNEL__
16
17#include <asm/page.h>
18
David Howellsb920de12008-02-08 04:19:31 -080019#ifdef CONFIG_4KSTACKS
20#define THREAD_SIZE (4096)
Thomas Gleixnerc03a6a72012-05-05 15:05:45 +000021#define THREAD_SIZE_ORDER (0)
David Howellsb920de12008-02-08 04:19:31 -080022#else
23#define THREAD_SIZE (8192)
Thomas Gleixnerc03a6a72012-05-05 15:05:45 +000024#define THREAD_SIZE_ORDER (1)
David Howellsb920de12008-02-08 04:19:31 -080025#endif
26
27#define STACK_WARN (THREAD_SIZE / 8)
28
29/*
30 * low level task data that entry.S needs immediate access to
31 * - this struct should fit entirely inside of one cache line
32 * - this struct shares the supervisor stack pages
33 * - if the contents of this structure are changed, the assembly constants
34 * must also be changed
35 */
36#ifndef __ASSEMBLY__
David Howells7c7fcf72010-10-27 17:29:01 +010037typedef struct {
38 unsigned long seg;
39} mm_segment_t;
David Howellsb920de12008-02-08 04:19:31 -080040
41struct thread_info {
42 struct task_struct *task; /* main task structure */
David Howells7c7fcf72010-10-27 17:29:01 +010043 struct pt_regs *frame; /* current exception frame */
David Howellsb920de12008-02-08 04:19:31 -080044 unsigned long flags; /* low level flags */
45 __u32 cpu; /* current CPU */
46 __s32 preempt_count; /* 0 => preemptable, <0 => BUG */
47
48 mm_segment_t addr_limit; /* thread address space:
49 0-0xBFFFFFFF for user-thead
50 0-0xFFFFFFFF for kernel-thread
51 */
David Howellsb920de12008-02-08 04:19:31 -080052
53 __u8 supervisor_stack[0];
54};
55
David Howells7c7fcf72010-10-27 17:29:01 +010056#define thread_info_to_uregs(ti) \
57 ((struct pt_regs *) \
58 ((unsigned long)ti + THREAD_SIZE - sizeof(struct pt_regs)))
59
David Howellsb920de12008-02-08 04:19:31 -080060#else /* !__ASSEMBLY__ */
61
62#ifndef __ASM_OFFSETS_H__
63#include <asm/asm-offsets.h>
64#endif
65
66#endif
67
68/*
69 * macros/functions for gaining access to the thread information structure
David Howellsb920de12008-02-08 04:19:31 -080070 */
71#ifndef __ASSEMBLY__
72
73#define INIT_THREAD_INFO(tsk) \
74{ \
75 .task = &tsk, \
David Howellsb920de12008-02-08 04:19:31 -080076 .flags = 0, \
77 .cpu = 0, \
Peter Zijlstrac99e6ef2009-07-10 14:57:56 +020078 .preempt_count = INIT_PREEMPT_COUNT, \
David Howellsb920de12008-02-08 04:19:31 -080079 .addr_limit = KERNEL_DS, \
David Howellsb920de12008-02-08 04:19:31 -080080}
81
82#define init_thread_info (init_thread_union.thread_info)
83#define init_stack (init_thread_union.stack)
84#define init_uregs \
85 ((struct pt_regs *) \
86 ((unsigned long) init_stack + THREAD_SIZE - sizeof(struct pt_regs)))
87
88extern struct thread_info *__current_ti;
89
90/* how to get the thread information struct from C */
91static inline __attribute__((const))
92struct thread_info *current_thread_info(void)
93{
94 struct thread_info *ti;
95 asm("mov sp,%0\n"
96 "and %1,%0\n"
97 : "=d" (ti)
98 : "i" (~(THREAD_SIZE - 1))
99 : "cc");
100 return ti;
101}
102
David Howells7c7fcf72010-10-27 17:29:01 +0100103static inline __attribute__((const))
104struct pt_regs *current_frame(void)
105{
106 return current_thread_info()->frame;
107}
108
David Howellsb920de12008-02-08 04:19:31 -0800109/* how to get the current stack pointer from C */
110static inline unsigned long current_stack_pointer(void)
111{
112 unsigned long sp;
113 asm("mov sp,%0; ":"=r" (sp));
114 return sp;
115}
116
David Howells5141c462011-03-18 16:54:32 +0000117#ifndef CONFIG_KGDB
Linus Torvaldsb235bee2016-06-24 15:09:37 -0700118void arch_release_thread_stack(unsigned long *stack);
David Howells5141c462011-03-18 16:54:32 +0000119#endif
David Howellsb920de12008-02-08 04:19:31 -0800120#define get_thread_info(ti) get_task_struct((ti)->task)
121#define put_thread_info(ti) put_task_struct((ti)->task)
122
123#else /* !__ASSEMBLY__ */
124
125#ifndef __VMLINUX_LDS__
126/* how to get the thread information struct from ASM */
127.macro GET_THREAD_INFO reg
128 mov sp,\reg
129 and -THREAD_SIZE,\reg
130.endm
131#endif
132#endif
133
134/*
135 * thread information flags
136 * - these are process state flags that various assembly files may need to
137 * access
138 * - pending work-to-be-done flags are in LSW
139 * - other flags in MSW
140 */
141#define TIF_SYSCALL_TRACE 0 /* syscall trace active */
142#define TIF_NOTIFY_RESUME 1 /* resumption notification requested */
143#define TIF_SIGPENDING 2 /* signal pending */
144#define TIF_NEED_RESCHED 3 /* rescheduling necessary */
145#define TIF_SINGLESTEP 4 /* restore singlestep on return to user mode */
146#define TIF_RESTORE_SIGMASK 5 /* restore signal mask in do_signal() */
147#define TIF_POLLING_NRFLAG 16 /* true if poll_idle() is polling TIF_NEED_RESCHED */
Andreas Dilger0ddc9322010-05-14 11:13:27 +0200148#define TIF_MEMDIE 17 /* is terminating due to OOM killer */
David Howellsb920de12008-02-08 04:19:31 -0800149
150#define _TIF_SYSCALL_TRACE +(1 << TIF_SYSCALL_TRACE)
151#define _TIF_NOTIFY_RESUME +(1 << TIF_NOTIFY_RESUME)
152#define _TIF_SIGPENDING +(1 << TIF_SIGPENDING)
153#define _TIF_NEED_RESCHED +(1 << TIF_NEED_RESCHED)
154#define _TIF_SINGLESTEP +(1 << TIF_SINGLESTEP)
David Howellsb920de12008-02-08 04:19:31 -0800155#define _TIF_POLLING_NRFLAG +(1 << TIF_POLLING_NRFLAG)
David Howellsb920de12008-02-08 04:19:31 -0800156
157#define _TIF_WORK_MASK 0x0000FFFE /* work to do on interrupt/exception return */
158#define _TIF_ALLWORK_MASK 0x0000FFFF /* work to do on any return to u-space */
159
David Howellsb920de12008-02-08 04:19:31 -0800160#endif /* __KERNEL__ */
161
162#endif /* _ASM_THREAD_INFO_H */