David Howells | b920de1 | 2008-02-08 04:19:31 -0800 | [diff] [blame] | 1 | /* 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 Howells | b920de1 | 2008-02-08 04:19:31 -0800 | [diff] [blame] | 19 | #ifdef CONFIG_4KSTACKS |
| 20 | #define THREAD_SIZE (4096) |
Thomas Gleixner | c03a6a7 | 2012-05-05 15:05:45 +0000 | [diff] [blame] | 21 | #define THREAD_SIZE_ORDER (0) |
David Howells | b920de1 | 2008-02-08 04:19:31 -0800 | [diff] [blame] | 22 | #else |
| 23 | #define THREAD_SIZE (8192) |
Thomas Gleixner | c03a6a7 | 2012-05-05 15:05:45 +0000 | [diff] [blame] | 24 | #define THREAD_SIZE_ORDER (1) |
David Howells | b920de1 | 2008-02-08 04:19:31 -0800 | [diff] [blame] | 25 | #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 Howells | 7c7fcf7 | 2010-10-27 17:29:01 +0100 | [diff] [blame] | 37 | typedef struct { |
| 38 | unsigned long seg; |
| 39 | } mm_segment_t; |
David Howells | b920de1 | 2008-02-08 04:19:31 -0800 | [diff] [blame] | 40 | |
| 41 | struct thread_info { |
| 42 | struct task_struct *task; /* main task structure */ |
| 43 | struct exec_domain *exec_domain; /* execution domain */ |
David Howells | 7c7fcf7 | 2010-10-27 17:29:01 +0100 | [diff] [blame] | 44 | struct pt_regs *frame; /* current exception frame */ |
David Howells | b920de1 | 2008-02-08 04:19:31 -0800 | [diff] [blame] | 45 | unsigned long flags; /* low level flags */ |
| 46 | __u32 cpu; /* current CPU */ |
| 47 | __s32 preempt_count; /* 0 => preemptable, <0 => BUG */ |
| 48 | |
| 49 | mm_segment_t addr_limit; /* thread address space: |
| 50 | 0-0xBFFFFFFF for user-thead |
| 51 | 0-0xFFFFFFFF for kernel-thread |
| 52 | */ |
David Howells | b920de1 | 2008-02-08 04:19:31 -0800 | [diff] [blame] | 53 | |
| 54 | __u8 supervisor_stack[0]; |
| 55 | }; |
| 56 | |
David Howells | 7c7fcf7 | 2010-10-27 17:29:01 +0100 | [diff] [blame] | 57 | #define thread_info_to_uregs(ti) \ |
| 58 | ((struct pt_regs *) \ |
| 59 | ((unsigned long)ti + THREAD_SIZE - sizeof(struct pt_regs))) |
| 60 | |
David Howells | b920de1 | 2008-02-08 04:19:31 -0800 | [diff] [blame] | 61 | #else /* !__ASSEMBLY__ */ |
| 62 | |
| 63 | #ifndef __ASM_OFFSETS_H__ |
| 64 | #include <asm/asm-offsets.h> |
| 65 | #endif |
| 66 | |
| 67 | #endif |
| 68 | |
| 69 | /* |
| 70 | * macros/functions for gaining access to the thread information structure |
David Howells | b920de1 | 2008-02-08 04:19:31 -0800 | [diff] [blame] | 71 | */ |
| 72 | #ifndef __ASSEMBLY__ |
| 73 | |
| 74 | #define INIT_THREAD_INFO(tsk) \ |
| 75 | { \ |
| 76 | .task = &tsk, \ |
| 77 | .exec_domain = &default_exec_domain, \ |
| 78 | .flags = 0, \ |
| 79 | .cpu = 0, \ |
Peter Zijlstra | c99e6ef | 2009-07-10 14:57:56 +0200 | [diff] [blame] | 80 | .preempt_count = INIT_PREEMPT_COUNT, \ |
David Howells | b920de1 | 2008-02-08 04:19:31 -0800 | [diff] [blame] | 81 | .addr_limit = KERNEL_DS, \ |
David Howells | b920de1 | 2008-02-08 04:19:31 -0800 | [diff] [blame] | 82 | } |
| 83 | |
| 84 | #define init_thread_info (init_thread_union.thread_info) |
| 85 | #define init_stack (init_thread_union.stack) |
| 86 | #define init_uregs \ |
| 87 | ((struct pt_regs *) \ |
| 88 | ((unsigned long) init_stack + THREAD_SIZE - sizeof(struct pt_regs))) |
| 89 | |
| 90 | extern struct thread_info *__current_ti; |
| 91 | |
| 92 | /* how to get the thread information struct from C */ |
| 93 | static inline __attribute__((const)) |
| 94 | struct thread_info *current_thread_info(void) |
| 95 | { |
| 96 | struct thread_info *ti; |
| 97 | asm("mov sp,%0\n" |
| 98 | "and %1,%0\n" |
| 99 | : "=d" (ti) |
| 100 | : "i" (~(THREAD_SIZE - 1)) |
| 101 | : "cc"); |
| 102 | return ti; |
| 103 | } |
| 104 | |
David Howells | 7c7fcf7 | 2010-10-27 17:29:01 +0100 | [diff] [blame] | 105 | static inline __attribute__((const)) |
| 106 | struct pt_regs *current_frame(void) |
| 107 | { |
| 108 | return current_thread_info()->frame; |
| 109 | } |
| 110 | |
David Howells | b920de1 | 2008-02-08 04:19:31 -0800 | [diff] [blame] | 111 | /* how to get the current stack pointer from C */ |
| 112 | static inline unsigned long current_stack_pointer(void) |
| 113 | { |
| 114 | unsigned long sp; |
| 115 | asm("mov sp,%0; ":"=r" (sp)); |
| 116 | return sp; |
| 117 | } |
| 118 | |
David Howells | 5141c46 | 2011-03-18 16:54:32 +0000 | [diff] [blame] | 119 | #ifndef CONFIG_KGDB |
David Howells | 43224b73 | 2012-07-11 16:11:20 +0100 | [diff] [blame] | 120 | void arch_release_thread_info(struct thread_info *ti); |
David Howells | 5141c46 | 2011-03-18 16:54:32 +0000 | [diff] [blame] | 121 | #endif |
David Howells | b920de1 | 2008-02-08 04:19:31 -0800 | [diff] [blame] | 122 | #define get_thread_info(ti) get_task_struct((ti)->task) |
| 123 | #define put_thread_info(ti) put_task_struct((ti)->task) |
| 124 | |
| 125 | #else /* !__ASSEMBLY__ */ |
| 126 | |
| 127 | #ifndef __VMLINUX_LDS__ |
| 128 | /* how to get the thread information struct from ASM */ |
| 129 | .macro GET_THREAD_INFO reg |
| 130 | mov sp,\reg |
| 131 | and -THREAD_SIZE,\reg |
| 132 | .endm |
| 133 | #endif |
| 134 | #endif |
| 135 | |
| 136 | /* |
| 137 | * thread information flags |
| 138 | * - these are process state flags that various assembly files may need to |
| 139 | * access |
| 140 | * - pending work-to-be-done flags are in LSW |
| 141 | * - other flags in MSW |
| 142 | */ |
| 143 | #define TIF_SYSCALL_TRACE 0 /* syscall trace active */ |
| 144 | #define TIF_NOTIFY_RESUME 1 /* resumption notification requested */ |
| 145 | #define TIF_SIGPENDING 2 /* signal pending */ |
| 146 | #define TIF_NEED_RESCHED 3 /* rescheduling necessary */ |
| 147 | #define TIF_SINGLESTEP 4 /* restore singlestep on return to user mode */ |
| 148 | #define TIF_RESTORE_SIGMASK 5 /* restore signal mask in do_signal() */ |
| 149 | #define TIF_POLLING_NRFLAG 16 /* true if poll_idle() is polling TIF_NEED_RESCHED */ |
Andreas Dilger | 0ddc932 | 2010-05-14 11:13:27 +0200 | [diff] [blame] | 150 | #define TIF_MEMDIE 17 /* is terminating due to OOM killer */ |
David Howells | b920de1 | 2008-02-08 04:19:31 -0800 | [diff] [blame] | 151 | |
| 152 | #define _TIF_SYSCALL_TRACE +(1 << TIF_SYSCALL_TRACE) |
| 153 | #define _TIF_NOTIFY_RESUME +(1 << TIF_NOTIFY_RESUME) |
| 154 | #define _TIF_SIGPENDING +(1 << TIF_SIGPENDING) |
| 155 | #define _TIF_NEED_RESCHED +(1 << TIF_NEED_RESCHED) |
| 156 | #define _TIF_SINGLESTEP +(1 << TIF_SINGLESTEP) |
David Howells | b920de1 | 2008-02-08 04:19:31 -0800 | [diff] [blame] | 157 | #define _TIF_POLLING_NRFLAG +(1 << TIF_POLLING_NRFLAG) |
David Howells | b920de1 | 2008-02-08 04:19:31 -0800 | [diff] [blame] | 158 | |
| 159 | #define _TIF_WORK_MASK 0x0000FFFE /* work to do on interrupt/exception return */ |
| 160 | #define _TIF_ALLWORK_MASK 0x0000FFFF /* work to do on any return to u-space */ |
| 161 | |
David Howells | b920de1 | 2008-02-08 04:19:31 -0800 | [diff] [blame] | 162 | #endif /* __KERNEL__ */ |
| 163 | |
| 164 | #endif /* _ASM_THREAD_INFO_H */ |