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