make oldconfig will rebuild these...
[linux-2.4.21-pre4.git] / include / asm-s390x / processor.h
1 /*
2  *  include/asm-s390/processor.h
3  *
4  *  S390 version
5  *    Copyright (C) 1999 IBM Deutschland Entwicklung GmbH, IBM Corporation
6  *    Author(s): Hartmut Penner (hp@de.ibm.com),
7  *               Martin Schwidefsky (schwidefsky@de.ibm.com)
8  *
9  *  Derived from "include/asm-i386/processor.h"
10  *    Copyright (C) 1994, Linus Torvalds
11  */
12
13 #ifndef __ASM_S390_PROCESSOR_H
14 #define __ASM_S390_PROCESSOR_H
15
16 #include <asm/page.h>
17 #include <asm/ptrace.h>
18
19 #ifdef __KERNEL__
20 /*
21  * Default implementation of macro that returns current
22  * instruction pointer ("program counter").
23  */
24 #define current_text_addr() ({ void *pc; __asm__("basr %0,0":"=a"(pc)); pc; })
25
26 /*
27  *  CPU type and hardware bug flags. Kept separately for each CPU.
28  *  Members of this structure are referenced in head.S, so think twice
29  *  before touching them. [mj]
30  */
31
32 typedef struct
33 {
34         unsigned int version :  8;
35         unsigned int ident   : 24;
36         unsigned int machine : 16;
37         unsigned int unused  : 16;
38 } __attribute__ ((packed)) cpuid_t;
39
40 struct cpuinfo_S390
41 {
42         cpuid_t  cpu_id;
43         unsigned long loops_per_jiffy;
44         unsigned long *pgd_quick;
45         unsigned long *pmd_quick;
46         unsigned long *pte_quick;
47         unsigned long pgtable_cache_sz;
48         __u16    cpu_addr;
49         __u16    cpu_nr;
50         __u16    pad[2];
51 };
52
53 extern void print_cpu_info(struct cpuinfo_S390 *);
54
55 /* Lazy FPU handling on uni-processor */
56 extern struct task_struct *last_task_used_math;
57
58 #define S390_FLAG_31BIT 0x01UL
59
60 /*
61  * User space process size: 4TB (default).
62  */
63 #define TASK_SIZE       (0x20000000000UL)
64 #define TASK31_SIZE     (0x80000000UL)
65
66 /* This decides where the kernel will search for a free chunk of vm
67  * space during mmap's.
68  */
69 #define TASK_UNMAPPED_BASE      ((current->thread.flags & S390_FLAG_31BIT) ? \
70         (TASK31_SIZE / 2) : (TASK_SIZE / 2))
71
72 #define THREAD_SIZE (4*PAGE_SIZE)
73
74 typedef struct {
75        __u32 ar4;
76 } mm_segment_t;
77
78 /* if you change the thread_struct structure, you must
79  * update the _TSS_* defines in entry.S
80  */
81
82 struct thread_struct
83  {
84         s390_fp_regs fp_regs;
85         __u32   ar2;                   /* kernel access register 2         */
86         __u32   ar4;                   /* kernel access register 4         */
87         addr_t  ksp;                   /* kernel stack pointer             */
88         addr_t  user_seg;              /* HSTD                             */
89         addr_t  prot_addr;             /* address of protection-excep.     */
90         __u32   error_code;            /* error-code of last prog-excep.   */
91         __u32   trap_no;
92         per_struct per_info;/* Must be aligned on an 4 byte boundary*/
93         /* Used to give failing instruction back to user for ieee exceptions */
94         addr_t  ieee_instruction_pointer; 
95         unsigned long flags;            /* various flags */
96         /* pfault_wait is used to block the process on a pfault event */
97         addr_t  pfault_wait;
98 };
99
100 typedef struct thread_struct thread_struct;
101
102 #define INIT_THREAD {{0,{{0},{0},{0},{0},{0},{0},{0},{0},{0},{0}, \
103                             {0},{0},{0},{0},{0},{0}}},            \
104                      0, 0,                                        \
105                     sizeof(init_stack) + (addr_t) &init_stack,    \
106               (__pa((addr_t) &swapper_pg_dir[0]) + _REGION_TABLE),\
107                      0,0,0,                                       \
108                      (per_struct) {{{{0,}}},0,0,0,0,{{0,}}},      \
109                      0, 0, 0                                      \
110
111
112 /* need to define ... */
113 #define start_thread(regs, new_psw, new_stackp) do {            \
114         regs->psw.mask  = _USER_PSW_MASK;                       \
115         regs->psw.addr  = new_psw;                              \
116         regs->gprs[15]  = new_stackp;                           \
117 } while (0)
118
119 #define start_thread31(regs, new_psw, new_stackp) do {          \
120         regs->psw.mask  = _USER_PSW_MASK & ~(1L << 32);         \
121         regs->psw.addr  = new_psw;                              \
122         regs->gprs[15]  = new_stackp;                           \
123 } while (0)
124
125
126 /* Forward declaration, a strange C thing */
127 struct mm_struct;
128
129 /* Free all resources held by a thread. */
130 extern void release_thread(struct task_struct *);
131 extern int kernel_thread(int (*fn)(void *), void * arg, unsigned long flags);
132
133 /* Copy and release all segment info associated with a VM */
134 #define copy_segments(nr, mm)           do { } while (0)
135 #define release_segments(mm)            do { } while (0)
136
137 /*
138  * Return saved PC of a blocked thread. used in kernel/sched
139  * resume in entry.S does not create a new stack frame, it
140  * just stores the registers %r6-%r15 to the frame given by
141  * schedule. We want to return the address of the caller of
142  * schedule, so we have to walk the backchain one time to
143  * find the frame schedule() store its return address.
144  */
145 extern inline unsigned long thread_saved_pc(struct thread_struct *t)
146 {
147         unsigned long bc;
148         bc = *((unsigned long *) t->ksp);
149         return *((unsigned long *) (bc+112));
150 }
151
152 unsigned long get_wchan(struct task_struct *p);
153 #define __KSTK_PTREGS(tsk) ((struct pt_regs *) \
154         (((unsigned long) tsk + THREAD_SIZE - sizeof(struct pt_regs)) & -8L))
155 #define KSTK_EIP(tsk)   (__KSTK_PTREGS(tsk)->psw.addr)
156 #define KSTK_ESP(tsk)   (__KSTK_PTREGS(tsk)->gprs[15])
157
158 /* Allocation and freeing of basic task resources. */
159 extern struct task_struct *alloc_task_struct(void);
160 extern void free_task_struct(struct task_struct *tsk);
161 extern void get_task_struct(struct task_struct *tsk);
162
163 #define init_task       (init_task_union.task)
164 #define init_stack      (init_task_union.stack)
165
166 #define cpu_relax()     do { } while (0)
167
168 /*
169  * Set of msr bits that gdb can change on behalf of a process.
170  */
171 /* Only let our hackers near the condition codes */
172 #define PSW_MASK_DEBUGCHANGE    0x0000300000000000UL
173 /* Don't let em near the addressing mode either */    
174 #define PSW_ADDR_DEBUGCHANGE    0xFFFFFFFFFFFFFFFFUL
175 #define PSW_ADDR_MASK           0xFFFFFFFFFFFFFFFFUL
176 /* Program event recording mask */    
177 #define PSW_PER_MASK            0x4000000000000000UL
178 #define USER_STD_MASK           0x0000000000000080UL
179 #define PSW_PROBLEM_STATE       0x0001000000000000UL
180
181 /*
182  * Set PSW mask to specified value, while leaving the
183  * PSW addr pointing to the next instruction.
184  */
185
186 static inline void __load_psw_mask (unsigned long mask)
187 {
188         unsigned long addr;
189
190         psw_t psw;
191         psw.mask = mask;
192
193         asm volatile (
194                 "    larl  %0,1f\n"
195                 "    stg   %0,8(%1)\n"
196                 "    lpswe 0(%1)\n"
197                 "1:"
198                 : "=&d" (addr) : "a" (&psw) : "memory", "cc" );
199 }
200
201 /*
202  * Function to stop a processor until an interruption occured
203  */
204 static inline void enabled_wait(void)
205 {
206         unsigned long reg;
207         psw_t wait_psw;
208
209         wait_psw.mask = 0x0706000180000000;
210         asm volatile (
211                 "    larl  %0,0f\n"
212                 "    stg   %0,8(%1)\n"
213                 "    lpswe 0(%1)\n"
214                 "0:"
215                 : "=&a" (reg) : "a" (&wait_psw) : "memory", "cc" );
216 }
217
218 /*
219  * Function to drop a processor into disabled wait state
220  */
221
222 static inline void disabled_wait(addr_t code)
223 {
224         char psw_buffer[2*sizeof(psw_t)];
225         char ctl_buf[8];
226         psw_t *dw_psw = (psw_t *)(((unsigned long) &psw_buffer+sizeof(psw_t)-1)
227                                   & -sizeof(psw_t));
228
229         dw_psw->mask = 0x0002000180000000;
230         dw_psw->addr = code;
231         /* 
232          * Store status and then load disabled wait psw,
233          * the processor is dead afterwards
234          */
235         asm volatile ("    stctg 0,0,0(%1)\n"
236                       "    ni    4(%1),0xef\n" /* switch off protection */
237                       "    lctlg 0,0,0(%1)\n"
238                       "    lghi  1,0x1000\n"
239                       "    stpt  0x328(1)\n"      /* store timer */
240                       "    stckc 0x330(1)\n"      /* store clock comparator */
241                       "    stpx  0x318(1)\n"      /* store prefix register */
242                       "    stam  0,15,0x340(1)\n" /* store access registers */
243                       "    stfpc 0x31c(1)\n"      /* store fpu control */
244                       "    std   0,0x200(1)\n"    /* store f0 */
245                       "    std   1,0x208(1)\n"    /* store f1 */
246                       "    std   2,0x210(1)\n"    /* store f2 */
247                       "    std   3,0x218(1)\n"    /* store f3 */
248                       "    std   4,0x220(1)\n"    /* store f4 */
249                       "    std   5,0x228(1)\n"    /* store f5 */
250                       "    std   6,0x230(1)\n"    /* store f6 */
251                       "    std   7,0x238(1)\n"    /* store f7 */
252                       "    std   8,0x240(1)\n"    /* store f8 */
253                       "    std   9,0x248(1)\n"    /* store f9 */
254                       "    std   10,0x250(1)\n"   /* store f10 */
255                       "    std   11,0x258(1)\n"   /* store f11 */
256                       "    std   12,0x260(1)\n"   /* store f12 */
257                       "    std   13,0x268(1)\n"   /* store f13 */
258                       "    std   14,0x270(1)\n"   /* store f14 */
259                       "    std   15,0x278(1)\n"   /* store f15 */
260                       "    stmg  0,15,0x280(1)\n" /* store general registers */
261                       "    stctg 0,15,0x380(1)\n" /* store control registers */
262                       "    oi    0x384(1),0x10\n" /* fake protection bit */
263                       "    lpswe 0(%0)"
264                       : : "a" (dw_psw), "a" (&ctl_buf) : "cc", "0", "1");
265 }
266
267 #endif
268
269 #endif                                 /* __ASM_S390_PROCESSOR_H           */
270