blob: 0ea4937c0b618d517d68e70f163af7925539dae7 [file] [log] [blame]
Chris Zankel9a8fd552005-06-23 22:01:26 -07001/*
2 * include/asm-xtensa/processor.h
3 *
4 * This file is subject to the terms and conditions of the GNU General Public
5 * License. See the file "COPYING" in the main directory of this archive
6 * for more details.
7 *
8 * Copyright (C) 2001 - 2005 Tensilica Inc.
9 */
10
11#ifndef _XTENSA_PROCESSOR_H
12#define _XTENSA_PROCESSOR_H
13
Chris Zankel367b8112008-11-06 06:40:46 -080014#include <variant/core.h>
Chris Zankel173d6682006-12-10 02:18:48 -080015#include <asm/coprocessor.h>
Johannes Weinere5083a62009-03-04 16:21:31 +010016#include <platform/hardware.h>
Chris Zankel9a8fd552005-06-23 22:01:26 -070017
Chase Ventersf6dc8c52006-07-08 11:10:29 -050018#include <linux/compiler.h>
Chris Zankel9a8fd552005-06-23 22:01:26 -070019#include <asm/ptrace.h>
20#include <asm/types.h>
Chris Zankel173d6682006-12-10 02:18:48 -080021#include <asm/regs.h>
Chris Zankel9a8fd552005-06-23 22:01:26 -070022
23/* Assertions. */
24
25#if (XCHAL_HAVE_WINDOWED != 1)
Chris Zankel173d6682006-12-10 02:18:48 -080026# error Linux requires the Xtensa Windowed Registers Option.
Chris Zankel9a8fd552005-06-23 22:01:26 -070027#endif
28
Oskar Schirmera81cbd22009-03-04 16:21:30 +010029#define ARCH_SLAB_MINALIGN XCHAL_DATA_WIDTH
30
Chris Zankel9a8fd552005-06-23 22:01:26 -070031/*
32 * User space process size: 1 GB.
33 * Windowed call ABI requires caller and callee to be located within the same
34 * 1 GB region. The C compiler places trampoline code on the stack for sources
35 * that take the address of a nested C function (a feature used by glibc), so
36 * the 1 GB requirement applies to the stack as well.
37 */
38
Johannes Weinere5083a62009-03-04 16:21:31 +010039#ifdef CONFIG_MMU
Chris Zankel24a9ab72007-08-05 11:24:13 -070040#define TASK_SIZE __XTENSA_UL_CONST(0x40000000)
Johannes Weinere5083a62009-03-04 16:21:31 +010041#else
42#define TASK_SIZE (PLATFORM_DEFAULT_MEM_START + PLATFORM_DEFAULT_MEM_SIZE)
43#endif
44
David Howells922a70d2008-02-08 04:19:26 -080045#define STACK_TOP TASK_SIZE
46#define STACK_TOP_MAX STACK_TOP
Chris Zankel9a8fd552005-06-23 22:01:26 -070047
48/*
49 * General exception cause assigned to debug exceptions. Debug exceptions go
50 * to their own vector, rather than the general exception vectors (user,
51 * kernel, double); and their specific causes are reported via DEBUGCAUSE
52 * rather than EXCCAUSE. However it is sometimes convenient to redirect debug
53 * exceptions to the general exception mechanism. To do this, an otherwise
54 * unused EXCCAUSE value was assigned to debug exceptions for this purpose.
55 */
56
57#define EXCCAUSE_MAPPED_DEBUG 63
58
59/*
60 * We use DEPC also as a flag to distinguish between double and regular
61 * exceptions. For performance reasons, DEPC might contain the value of
62 * EXCCAUSE for regular exceptions, so we use this definition to mark a
63 * valid double exception address.
64 * (Note: We use it in bgeui, so it should be 64, 128, or 256)
65 */
66
67#define VALID_DOUBLE_EXCEPTION_ADDRESS 64
68
69/* LOCKLEVEL defines the interrupt level that masks all
70 * general-purpose interrupts.
71 */
72#define LOCKLEVEL 1
73
74/* WSBITS and WBBITS are the width of the WINDOWSTART and WINDOWBASE
75 * registers
76 */
77#define WSBITS (XCHAL_NUM_AREGS / 4) /* width of WINDOWSTART in bits */
78#define WBBITS (XCHAL_NUM_AREGS_LOG2 - 2) /* width of WINDOWBASE in bits */
79
80#ifndef __ASSEMBLY__
81
82/* Build a valid return address for the specified call winsize.
83 * winsize must be 1 (call4), 2 (call8), or 3 (call12)
84 */
85#define MAKE_RA_FOR_CALL(ra,ws) (((ra) & 0x3fffffff) | (ws) << 30)
86
87/* Convert return address to a valid pc
88 * Note: We assume that the stack pointer is in the same 1GB ranges as the ra
89 */
90#define MAKE_PC_FROM_RA(ra,sp) (((ra) & 0x3fffffff) | ((sp) & 0xc0000000))
91
92typedef struct {
93 unsigned long seg;
94} mm_segment_t;
95
96struct thread_struct {
97
98 /* kernel's return address and stack pointer for context switching */
99 unsigned long ra; /* kernel's a0: return address and window call size */
100 unsigned long sp; /* kernel's a1: stack pointer */
101
102 mm_segment_t current_ds; /* see uaccess.h for example uses */
103
104 /* struct xtensa_cpuinfo info; */
105
106 unsigned long bad_vaddr; /* last user fault */
107 unsigned long bad_uaddr; /* last kernel fault accessing user space */
108 unsigned long error_code;
109
110 unsigned long ibreak[XCHAL_NUM_IBREAK];
111 unsigned long dbreaka[XCHAL_NUM_DBREAK];
112 unsigned long dbreakc[XCHAL_NUM_DBREAK];
113
Chris Zankel9a8fd552005-06-23 22:01:26 -0700114 /* Make structure 16 bytes aligned. */
115 int align[0] __attribute__ ((aligned(16)));
116};
117
118
119/*
120 * Default implementation of macro that returns current
121 * instruction pointer ("program counter").
122 */
123#define current_text_addr() ({ __label__ _l; _l: &&_l;})
124
125
126/* This decides where the kernel will search for a free chunk of vm
127 * space during mmap's.
128 */
129#define TASK_UNMAPPED_BASE (TASK_SIZE / 2)
130
131#define INIT_THREAD \
132{ \
133 ra: 0, \
134 sp: sizeof(init_stack) + (long) &init_stack, \
135 current_ds: {0}, \
136 /*info: {0}, */ \
137 bad_vaddr: 0, \
138 bad_uaddr: 0, \
139 error_code: 0, \
140}
141
142
143/*
144 * Do necessary setup to start up a newly executed thread.
145 * Note: We set-up ps as if we did a call4 to the new pc.
146 * set_thread_state in signal.c depends on it.
147 */
Chris Zankel173d6682006-12-10 02:18:48 -0800148#define USER_PS_VALUE ((1 << PS_WOE_BIT) | \
149 (1 << PS_CALLINC_SHIFT) | \
150 (USER_RING << PS_RING_SHIFT) | \
151 (1 << PS_UM_BIT) | \
152 (1 << PS_EXCM_BIT))
Chris Zankel9a8fd552005-06-23 22:01:26 -0700153
154/* Clearing a0 terminates the backtrace. */
155#define start_thread(regs, new_pc, new_sp) \
156 regs->pc = new_pc; \
157 regs->ps = USER_PS_VALUE; \
158 regs->areg[1] = new_sp; \
159 regs->areg[0] = 0; \
160 regs->wmask = 1; \
161 regs->depc = 0; \
162 regs->windowbase = 0; \
163 regs->windowstart = 1;
164
165/* Forward declaration */
166struct task_struct;
167struct mm_struct;
168
Chris Zankel9a8fd552005-06-23 22:01:26 -0700169/* Free all resources held by a thread. */
170#define release_thread(thread) do { } while(0)
171
Chris Zankel9a8fd552005-06-23 22:01:26 -0700172/* Prepare to copy thread state - unlazy all lazy status */
Chris Zankelc658eac2008-02-12 13:17:07 -0800173extern void prepare_to_copy(struct task_struct*);
Chris Zankel9a8fd552005-06-23 22:01:26 -0700174
Chris Zankelc658eac2008-02-12 13:17:07 -0800175/* Create a kernel thread without removing it from tasklists */
Chris Zankel9a8fd552005-06-23 22:01:26 -0700176extern int kernel_thread(int (*fn)(void *), void * arg, unsigned long flags);
177
178/* Copy and release all segment info associated with a VM */
Chris Zankel9a8fd552005-06-23 22:01:26 -0700179#define copy_segments(p, mm) do { } while(0)
180#define release_segments(mm) do { } while(0)
181#define forget_segments() do { } while (0)
182
Al Viro04fe6fa2006-01-12 01:05:50 -0800183#define thread_saved_pc(tsk) (task_pt_regs(tsk)->pc)
Chris Zankel9a8fd552005-06-23 22:01:26 -0700184
185extern unsigned long get_wchan(struct task_struct *p);
186
Al Viro04fe6fa2006-01-12 01:05:50 -0800187#define KSTK_EIP(tsk) (task_pt_regs(tsk)->pc)
188#define KSTK_ESP(tsk) (task_pt_regs(tsk)->areg[1])
Chris Zankel9a8fd552005-06-23 22:01:26 -0700189
Chase Ventersf6dc8c52006-07-08 11:10:29 -0500190#define cpu_relax() barrier()
Chris Zankel9a8fd552005-06-23 22:01:26 -0700191
192/* Special register access. */
193
194#define WSR(v,sr) __asm__ __volatile__ ("wsr %0,"__stringify(sr) :: "a"(v));
195#define RSR(v,sr) __asm__ __volatile__ ("rsr %0,"__stringify(sr) : "=a"(v));
196
197#define set_sr(x,sr) ({unsigned int v=(unsigned int)x; WSR(v,sr);})
198#define get_sr(sr) ({unsigned int v; RSR(v,sr); v; })
199
200#endif /* __ASSEMBLY__ */
201#endif /* _XTENSA_PROCESSOR_H */