processor.h 6.68 KB
Newer Older
Linus Torvalds's avatar
Linus Torvalds committed
1
/* $Id: processor.h,v 1.40 1997/10/24 11:57:59 jj Exp $
Linus Torvalds's avatar
Linus Torvalds committed
2 3 4 5 6 7 8 9
 * include/asm-sparc64/processor.h
 *
 * Copyright (C) 1996 David S. Miller (davem@caip.rutgers.edu)
 */

#ifndef __ASM_SPARC64_PROCESSOR_H
#define __ASM_SPARC64_PROCESSOR_H

Linus Torvalds's avatar
Linus Torvalds committed
10
#include <asm/asi.h>
Linus Torvalds's avatar
Linus Torvalds committed
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26
#include <asm/a.out.h>
#include <asm/pstate.h>
#include <asm/ptrace.h>
#include <asm/signal.h>
#include <asm/segment.h>

/* Bus types */
#define EISA_bus 0
#define EISA_bus__is_a_macro /* for versions in ksyms.c */
#define MCA_bus 0
#define MCA_bus__is_a_macro /* for versions in ksyms.c */

/* The sparc has no problems with write protection */
#define wp_works_ok 1
#define wp_works_ok__is_a_macro /* for versions in ksyms.c */

Linus Torvalds's avatar
Linus Torvalds committed
27 28
/* User lives in his very own context, and cannot reference us. */
#define TASK_SIZE	((1UL << (PAGE_SHIFT - 3)) * PGDIR_SIZE)
Linus Torvalds's avatar
Linus Torvalds committed
29

Linus Torvalds's avatar
Linus Torvalds committed
30 31 32 33 34 35 36 37 38 39 40 41 42
#define COPY_TASK_STRUCT(dst, src)										\
do {														\
	if (src->tss.w_saved)											\
		*dst = *src;											\
	else {													\
		memcpy (dst, src, ((const unsigned long)(&((struct task_struct *)0)->tss.reg_window)));		\
		memcpy ((char *)dst + ((const unsigned long)(&((struct task_struct *)0)->tss.sig_address)),	\
			(char *)src + ((const unsigned long)(&((struct task_struct *)0)->tss.sig_address)),	\
			sizeof(struct task_struct) - 								\
			  ((const unsigned long)(&((struct task_struct *)0)->tss.sig_address)));		\
	}													\
} while (0)

Linus Torvalds's avatar
Linus Torvalds committed
43 44 45 46
#ifndef __ASSEMBLY__

#define NSWINS		8

Linus Torvalds's avatar
Linus Torvalds committed
47 48 49 50
typedef struct {
	unsigned long seg;
} mm_segment_t;

Linus Torvalds's avatar
Linus Torvalds committed
51 52
/* The Sparc processor specific thread struct. */
struct thread_struct {
Linus Torvalds's avatar
Linus Torvalds committed
53
/*DC1*/	unsigned long ksp __attribute__ ((aligned(16)));
Linus Torvalds's avatar
Linus Torvalds committed
54 55 56
	unsigned int kpc;
	unsigned short wstate;
	unsigned short cwp;
Linus Torvalds's avatar
Linus Torvalds committed
57

Linus Torvalds's avatar
Linus Torvalds committed
58 59 60 61 62 63 64 65
/*DC2*/	unsigned short flags;
	unsigned short ctx;
	unsigned short w_saved;
	unsigned short new_signal;
	mm_segment_t current_ds;

/*DC3*/	struct pt_regs *kregs;
	unsigned long *utraps;
Linus Torvalds's avatar
Linus Torvalds committed
66 67 68

	struct reg_window reg_window[NSWINS] __attribute__ ((aligned (16)));
	unsigned long rwbuf_stkptrs[NSWINS] __attribute__ ((aligned (8)));
Linus Torvalds's avatar
Linus Torvalds committed
69
	
Linus Torvalds's avatar
Linus Torvalds committed
70 71 72 73 74 75 76
	unsigned long sig_address __attribute__ ((aligned (8)));
	unsigned long sig_desc;
	struct sigstack sstk_info;
};

#endif /* !(__ASSEMBLY__) */

Linus Torvalds's avatar
Linus Torvalds committed
77 78 79 80 81 82 83
#define SPARC_FLAG_USEDFPUL	0x01    /* Used f0-f31 */
#define SPARC_FLAG_USEDFPUU	0x02    /* Used f32-f62 */
#define SPARC_FLAG_USEDFPU	0x04    /* If ever FEF bit was set while TSTATE_PEF */
#define SPARC_FLAG_KTHREAD      0x10    /* task is a kernel thread */
#define SPARC_FLAG_UNALIGNED    0x20    /* is allowed to do unaligned accesses */
#define SPARC_FLAG_NEWSIGNALS   0x40    /* task wants new-style signals */
#define SPARC_FLAG_32BIT        0x80    /* task is older 32-bit binary */
Linus Torvalds's avatar
Linus Torvalds committed
84

Linus Torvalds's avatar
Linus Torvalds committed
85
#define INIT_MMAP { &init_mm, 0xfffff80000000000, 0xfffff80001000000, \
Linus Torvalds's avatar
Linus Torvalds committed
86
		    PAGE_SHARED , VM_READ | VM_WRITE | VM_EXEC, NULL, &init_mm.mmap }
Linus Torvalds's avatar
Linus Torvalds committed
87

Linus Torvalds's avatar
Linus Torvalds committed
88 89 90 91 92 93 94 95 96 97 98 99 100
#define INIT_TSS  {						\
/* ksp, kpc, wstate, cwp */ 					\
   0,   0,   0,	     0,						\
/* flags,              ctx, w_saved, new_signal, current_ds, */	\
   SPARC_FLAG_KTHREAD, 0,   0,       0,          KERNEL_DS,	\
/* kregs,   utraps, */						\
   0,       0,							\
/* reg_window */						\
   { { { 0, }, { 0, } }, }, 					\
/* rwbuf_stkptrs */						\
   { 0, 0, 0, 0, 0, 0, 0, 0, },					\
/* sig_address, sig_desc, sstk_info */				\
   0,           0,        { 0, 0, },				\
Linus Torvalds's avatar
Linus Torvalds committed
101 102 103 104 105 106 107 108 109 110
}

#ifndef __ASSEMBLY__

/* Return saved PC of a blocked thread. */
extern __inline__ unsigned long thread_saved_pc(struct thread_struct *t)
{
	return t->kpc;
}

Linus Torvalds's avatar
Linus Torvalds committed
111 112 113 114 115 116 117
/* On Uniprocessor, even in RMO processes see TSO semantics */
#ifdef __SMP__
#define TSTATE_INITIAL_MM	TSTATE_TSO
#else
#define TSTATE_INITIAL_MM	TSTATE_RMO
#endif

Linus Torvalds's avatar
Linus Torvalds committed
118
/* Do necessary setup to start up a newly executed thread. */
Linus Torvalds's avatar
Linus Torvalds committed
119 120
#define start_thread(regs, pc, sp) \
do { \
Linus Torvalds's avatar
Linus Torvalds committed
121
	regs->tstate = (regs->tstate & (TSTATE_CWP)) | (TSTATE_INITIAL_MM|TSTATE_IE) | (ASI_PNF << 24); \
Linus Torvalds's avatar
Linus Torvalds committed
122 123 124
	regs->tpc = ((pc & (~3)) - 4); \
	regs->tnpc = regs->tpc + 4; \
	regs->y = 0; \
Linus Torvalds's avatar
Linus Torvalds committed
125
	current->tss.flags &= ~SPARC_FLAG_32BIT; \
Linus Torvalds's avatar
Linus Torvalds committed
126
	current->tss.wstate = (1 << 3); \
Linus Torvalds's avatar
Linus Torvalds committed
127 128 129 130 131 132 133
	if (current->tss.utraps) { \
		if (*(current->tss.utraps) < 2) \
			kfree (current->tss.utraps); \
		else \
			(*(current->tss.utraps))--; \
		current->tss.utraps = NULL; \
	} \
Linus Torvalds's avatar
Linus Torvalds committed
134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150
	__asm__ __volatile__( \
	"stx		%%g0, [%0 + %2 + 0x00]\n\t" \
	"stx		%%g0, [%0 + %2 + 0x08]\n\t" \
	"stx		%%g0, [%0 + %2 + 0x10]\n\t" \
	"stx		%%g0, [%0 + %2 + 0x18]\n\t" \
	"stx		%%g0, [%0 + %2 + 0x20]\n\t" \
	"stx		%%g0, [%0 + %2 + 0x28]\n\t" \
	"stx		%%g0, [%0 + %2 + 0x30]\n\t" \
	"stx		%%g0, [%0 + %2 + 0x38]\n\t" \
	"stx		%%g0, [%0 + %2 + 0x40]\n\t" \
	"stx		%%g0, [%0 + %2 + 0x48]\n\t" \
	"stx		%%g0, [%0 + %2 + 0x50]\n\t" \
	"stx		%%g0, [%0 + %2 + 0x58]\n\t" \
	"stx		%%g0, [%0 + %2 + 0x60]\n\t" \
	"stx		%%g0, [%0 + %2 + 0x68]\n\t" \
	"stx		%1,   [%0 + %2 + 0x70]\n\t" \
	"stx		%%g0, [%0 + %2 + 0x78]\n\t" \
Linus Torvalds's avatar
Linus Torvalds committed
151
	"wrpr		%%g0, (1 << 3), %%wstate\n\t" \
Linus Torvalds's avatar
Linus Torvalds committed
152
	: \
Linus Torvalds's avatar
Linus Torvalds committed
153
	: "r" (regs), "r" (sp - REGWIN_SZ - STACK_BIAS), \
Linus Torvalds's avatar
Linus Torvalds committed
154 155 156 157 158 159 160 161 162 163
	  "i" ((const unsigned long)(&((struct pt_regs *)0)->u_regs[0]))); \
} while(0)

#define start_thread32(regs, pc, sp) \
do { \
	register unsigned int zero asm("g1"); \
\
	pc &= 0x00000000ffffffffUL; \
	sp &= 0x00000000ffffffffUL; \
\
Linus Torvalds's avatar
Linus Torvalds committed
164
	regs->tstate = (regs->tstate & (TSTATE_CWP))|(TSTATE_INITIAL_MM|TSTATE_IE|TSTATE_AM); \
Linus Torvalds's avatar
Linus Torvalds committed
165 166 167 168
	regs->tpc = ((pc & (~3)) - 4); \
	regs->tnpc = regs->tpc + 4; \
	regs->y = 0; \
	current->tss.flags |= SPARC_FLAG_32BIT; \
Linus Torvalds's avatar
Linus Torvalds committed
169
	current->tss.wstate = (2 << 3); \
Linus Torvalds's avatar
Linus Torvalds committed
170 171 172 173 174 175 176
	if (current->tss.utraps) { \
		if (*(current->tss.utraps) < 2) \
			kfree (current->tss.utraps); \
		else \
			(*(current->tss.utraps))--; \
		current->tss.utraps = NULL; \
	} \
Linus Torvalds's avatar
Linus Torvalds committed
177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194
	zero = 0; \
	__asm__ __volatile__( \
	"stx		%%g0, [%0 + %2 + 0x00]\n\t" \
	"stx		%%g0, [%0 + %2 + 0x08]\n\t" \
	"stx		%%g0, [%0 + %2 + 0x10]\n\t" \
	"stx		%%g0, [%0 + %2 + 0x18]\n\t" \
	"stx		%%g0, [%0 + %2 + 0x20]\n\t" \
	"stx		%%g0, [%0 + %2 + 0x28]\n\t" \
	"stx		%%g0, [%0 + %2 + 0x30]\n\t" \
	"stx		%%g0, [%0 + %2 + 0x38]\n\t" \
	"stx		%%g0, [%0 + %2 + 0x40]\n\t" \
	"stx		%%g0, [%0 + %2 + 0x48]\n\t" \
	"stx		%%g0, [%0 + %2 + 0x50]\n\t" \
	"stx		%%g0, [%0 + %2 + 0x58]\n\t" \
	"stx		%%g0, [%0 + %2 + 0x60]\n\t" \
	"stx		%%g0, [%0 + %2 + 0x68]\n\t" \
	"stx		%1,   [%0 + %2 + 0x70]\n\t" \
	"stx		%%g0, [%0 + %2 + 0x78]\n\t" \
Linus Torvalds's avatar
Linus Torvalds committed
195
	"wrpr		%%g0, (2 << 3), %%wstate\n\t" \
Linus Torvalds's avatar
Linus Torvalds committed
196 197 198 199 200
	: \
	: "r" (regs), "r" (sp - REGWIN32_SZ), \
	  "i" ((const unsigned long)(&((struct pt_regs *)0)->u_regs[0])), \
	  "r" (zero)); \
} while(0)
Linus Torvalds's avatar
Linus Torvalds committed
201 202 203 204 205

/* Free all resources held by a thread. */
#define release_thread(tsk)		do { } while(0)

#ifdef __KERNEL__
Linus Torvalds's avatar
Linus Torvalds committed
206
/* Allocation and freeing of task_struct and kernel stack. */
Linus Torvalds's avatar
Linus Torvalds committed
207
#define alloc_task_struct()   ((struct task_struct *)__get_free_pages(GFP_KERNEL, 1))
Linus Torvalds's avatar
Linus Torvalds committed
208 209 210 211
#define free_task_struct(tsk) free_pages((unsigned long)(tsk),1)

#define init_task	(init_task_union.task)
#define init_stack	(init_task_union.stack)
Linus Torvalds's avatar
Linus Torvalds committed
212 213

#endif /* __KERNEL__ */
Linus Torvalds's avatar
Linus Torvalds committed
214 215 216 217

#endif /* !(__ASSEMBLY__) */

#endif /* !(__ASM_SPARC64_PROCESSOR_H) */