import of upstream 2.4.34.4 from kernel.org
[linux-2.4.git] / include / asm-s390 / 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         __u16    cpu_addr;
44         __u16    cpu_nr;
45         unsigned long loops_per_jiffy;
46         unsigned long *pgd_quick;
47         unsigned long *pte_quick;
48         unsigned long pgtable_cache_sz;
49 };
50
51 extern void print_cpu_info(struct cpuinfo_S390 *);
52
53 extern void show_trace(unsigned long* esp);
54
55 /* Lazy FPU handling on uni-processor */
56 extern struct task_struct *last_task_used_math;
57
58 /*
59  * User space process size: 2GB (default).
60  */
61 #define TASK_SIZE       (0x80000000)
62 /* This decides where the kernel will search for a free chunk of vm
63  * space during mmap's.
64  */
65 #define TASK_UNMAPPED_BASE      (TASK_SIZE / 2)
66
67 #define THREAD_SIZE (2*PAGE_SIZE)
68
69 typedef struct {
70         unsigned long ar4;
71 } mm_segment_t;
72
73 /* if you change the thread_struct structure, you must
74  * update the _TSS_* defines in entry.S
75  */
76
77 struct thread_struct
78  {
79         s390_fp_regs fp_regs;
80         __u32   ar2;                   /* kernel access register 2         */
81         __u32   ar4;                   /* kernel access register 4         */
82         __u32   ksp;                   /* kernel stack pointer             */
83         __u32   user_seg;              /* HSTD                             */
84         __u32   error_code;            /* error-code of last prog-excep.   */
85         __u32   prot_addr;             /* address of protection-excep.     */
86         __u32   trap_no;
87         per_struct per_info;/* Must be aligned on an 4 byte boundary*/
88         /* Used to give failing instruction back to user for ieee exceptions */
89         addr_t  ieee_instruction_pointer; 
90         /* pfault_wait is used to block the process on a pfault event */
91         addr_t  pfault_wait;
92 };
93
94 typedef struct thread_struct thread_struct;
95
96 #define INIT_THREAD {{0,{{0},{0},{0},{0},{0},{0},{0},{0},{0},{0}, \
97                             {0},{0},{0},{0},{0},{0}}},            \
98                      0, 0,                                        \
99                     sizeof(init_stack) + (__u32) &init_stack,     \
100               (__pa((__u32) &swapper_pg_dir[0]) + _SEGMENT_TABLE),\
101                      0,0,0,                                       \
102                      (per_struct) {{{{0,}}},0,0,0,0,{{0,}}},      \
103                      0, 0                                         \
104 }
105
106 /* need to define ... */
107 #define start_thread(regs, new_psw, new_stackp) do {            \
108         regs->psw.mask  = _USER_PSW_MASK;                       \
109         regs->psw.addr  = new_psw | 0x80000000;                 \
110         regs->gprs[15]  = new_stackp ;                          \
111 } while (0)
112
113 /* Forward declaration, a strange C thing */
114 struct mm_struct;
115
116 /* Free all resources held by a thread. */
117 extern void release_thread(struct task_struct *);
118 extern int arch_kernel_thread(int (*fn)(void *), void * arg, unsigned long flags);
119
120 /* Copy and release all segment info associated with a VM */
121 #define copy_segments(nr, mm)           do { } while (0)
122 #define release_segments(mm)            do { } while (0)
123
124 /*
125  * Return saved PC of a blocked thread. used in kernel/sched.
126  * resume in entry.S does not create a new stack frame, it
127  * just stores the registers %r6-%r15 to the frame given by
128  * schedule. We want to return the address of the caller of
129  * schedule, so we have to walk the backchain one time to
130  * find the frame schedule() store its return address.
131  */
132 extern inline unsigned long thread_saved_pc(struct thread_struct *t)
133 {
134         unsigned long bc;
135         bc = *((unsigned long *) t->ksp);
136         return *((unsigned long *) (bc+56));
137 }
138
139 unsigned long get_wchan(struct task_struct *p);
140 #define __KSTK_PTREGS(tsk) ((struct pt_regs *) \
141         (((unsigned long) tsk + THREAD_SIZE - sizeof(struct pt_regs)) & -8L))
142 #define KSTK_EIP(tsk)   (__KSTK_PTREGS(tsk)->psw.addr)
143 #define KSTK_ESP(tsk)   (__KSTK_PTREGS(tsk)->gprs[15])
144
145 /* Allocation and freeing of basic task resources. */
146 /*
147  * NOTE! The task struct and the stack go together
148  */
149 #define alloc_task_struct() \
150         ((struct task_struct *) __get_free_pages(GFP_KERNEL,1))
151 #define free_task_struct(p)     free_pages((unsigned long)(p),1)
152 #define get_task_struct(tsk)      atomic_inc(&virt_to_page(tsk)->count)
153
154 #define init_task       (init_task_union.task)
155 #define init_stack      (init_task_union.stack)
156
157 #define cpu_relax()     do { } while (0)
158
159 /*
160  * Set of msr bits that gdb can change on behalf of a process.
161  */
162 /* Only let our hackers near the condition codes */
163 #define PSW_MASK_DEBUGCHANGE    0x00003000UL
164 /* Don't let em near the addressing mode either */    
165 #define PSW_ADDR_DEBUGCHANGE    0x7FFFFFFFUL
166 #define PSW_ADDR_MASK           0x7FFFFFFFUL
167 /* Program event recording mask */    
168 #define PSW_PER_MASK            0x40000000UL
169 #define USER_STD_MASK           0x00000080UL
170 #define PSW_PROBLEM_STATE       0x00010000UL
171
172 /*
173  * Set PSW mask to specified value, while leaving the
174  * PSW addr pointing to the next instruction.
175  */
176
177 static inline void __load_psw_mask (unsigned long mask)
178 {
179         unsigned long addr;
180
181         psw_t psw;
182         psw.mask = mask;
183
184         asm volatile (
185                 "    basr %0,0\n"
186                 "0:  ahi  %0,1f-0b\n"
187                 "    st   %0,4(%1)\n"
188                 "    lpsw 0(%1)\n"
189                 "1:"
190                 : "=&d" (addr) : "a" (&psw) : "memory", "cc" );
191 }
192  
193 /*
194  * Function to stop a processor until an interruption occured
195  */
196 static inline void enabled_wait(void)
197 {
198         unsigned long reg;
199         psw_t wait_psw;
200
201         wait_psw.mask = 0x070e0000;
202         asm volatile (
203                 "    basr %0,0\n"
204                 "0:  la   %0,1f-0b(%0)\n"
205                 "    st   %0,4(%1)\n"
206                 "    oi   4(%1),0x80\n"
207                 "    lpsw 0(%1)\n"
208                 "1:"
209                 : "=&a" (reg) : "a" (&wait_psw) : "memory", "cc" );
210 }
211
212 /*
213  * Function to drop a processor into disabled wait state
214  */
215
216 static inline void disabled_wait(unsigned long code)
217 {
218         char psw_buffer[2*sizeof(psw_t)];
219         char ctl_buf[4];
220         psw_t *dw_psw = (psw_t *)(((unsigned long) &psw_buffer+sizeof(psw_t)-1)
221                                   & -sizeof(psw_t));
222
223         dw_psw->mask = 0x000a0000;
224         dw_psw->addr = code;
225         /* 
226          * Store status and then load disabled wait psw,
227          * the processor is dead afterwards
228          */
229
230         asm volatile ("    stctl 0,0,0(%1)\n"
231                       "    ni    0(%1),0xef\n" /* switch off protection */
232                       "    lctl  0,0,0(%1)\n"
233                       "    stpt  0xd8\n"       /* store timer */
234                       "    stckc 0xe0\n"       /* store clock comparator */
235                       "    stpx  0x108\n"      /* store prefix register */
236                       "    stam  0,15,0x120\n" /* store access registers */
237                       "    std   0,0x160\n"    /* store f0 */
238                       "    std   2,0x168\n"    /* store f2 */
239                       "    std   4,0x170\n"    /* store f4 */
240                       "    std   6,0x178\n"    /* store f6 */
241                       "    stm   0,15,0x180\n" /* store general registers */
242                       "    stctl 0,15,0x1c0\n" /* store control registers */
243                       "    oi    0(%1),0x10\n" /* fake protection bit */
244                       "    lpsw 0(%0)"
245                       : : "a" (dw_psw), "a" (&ctl_buf) : "cc" );
246 }
247
248 #endif
249
250 #endif                                 /* __ASM_S390_PROCESSOR_H           */