2 * Copyright (C) 2005,2006,2007,2008 Imagination Technologies
5 #ifndef __ASM_METAG_PROCESSOR_H
6 #define __ASM_METAG_PROCESSOR_H
8 #include <linux/atomic.h>
11 #include <asm/ptrace.h>
12 #include <asm/metag_regs.h>
15 * Default implementation of macro that returns current
16 * instruction pointer ("program counter").
18 #define current_text_addr() ({ __label__ _l; _l: &&_l; })
20 /* The task stops where the kernel starts */
21 #define TASK_SIZE PAGE_OFFSET
22 /* Add an extra page of padding at the top of the stack for the guard page. */
23 #define STACK_TOP (TASK_SIZE - PAGE_SIZE)
24 #define STACK_TOP_MAX STACK_TOP
26 /* This decides where the kernel will search for a free chunk of vm
27 * space during mmap's.
29 #define TASK_UNMAPPED_BASE META_MEMORY_BASE
35 #ifdef CONFIG_METAG_FPU
36 struct meta_fpu_context {
51 struct meta_fpu_context {};
54 #ifdef CONFIG_METAG_DSP
55 struct meta_ext_context {
59 TBIDUAL ax[TBICTXEXTAXX_BYTES / sizeof(TBIDUAL)];
65 /* DSPRAM A and B save areas. */
68 /* ECH encoded size of DSPRAM save areas. */
69 unsigned int ram_sz[2];
72 struct meta_ext_context {};
75 struct thread_struct {
76 PTBICTX kernel_context;
77 /* A copy of the user process Sig.SaveMask. */
78 unsigned int user_flags;
79 struct meta_fpu_context *fpu_context;
81 unsigned short int_depth;
82 unsigned short txdefr_failure;
83 struct meta_ext_context *dsp_context;
86 #define INIT_THREAD { \
87 NULL, /* kernel_context */ \
89 NULL, /* fpu_context */ \
91 1, /* int_depth - we start in kernel */ \
92 0, /* txdefr_failure */ \
93 NULL, /* dsp_context */ \
96 /* Needed to make #define as we are referencing 'current', that is not visible
99 * Stack layout is as below.
101 argc argument counter (integer)
102 argv[0] program name (pointer)
103 argv[1...N] program args (pointers)
104 argv[argc-1] end of args (integer)
106 env[0...N] environment variables (pointers)
110 #define start_thread(regs, pc, usp) do { \
111 unsigned int *argc = (unsigned int *) bprm->exec; \
113 current->thread.int_depth = 1; \
114 /* Force this process down to user land */ \
115 regs->ctx.SaveMask = TBICTX_PRIV_BIT; \
116 regs->ctx.CurrPC = pc; \
117 regs->ctx.AX[0].U0 = usp; \
118 regs->ctx.DX[3].U1 = *((int *)argc); /* argc */ \
119 regs->ctx.DX[3].U0 = (int)((int *)argc + 1); /* argv */ \
120 regs->ctx.DX[2].U1 = (int)((int *)argc + \
121 regs->ctx.DX[3].U1 + 2); /* envp */ \
122 regs->ctx.DX[2].U0 = 0; /* rtld_fini */ \
125 /* Forward declaration, a strange C thing */
128 /* Free all resources held by a thread. */
129 static inline void release_thread(struct task_struct *dead_task)
133 #define copy_segments(tsk, mm) do { } while (0)
134 #define release_segments(mm) do { } while (0)
136 extern void exit_thread(void);
139 * Return saved PC of a blocked thread.
141 #define thread_saved_pc(tsk) \
142 ((unsigned long)(tsk)->thread.kernel_context->CurrPC)
143 #define thread_saved_sp(tsk) \
144 ((unsigned long)(tsk)->thread.kernel_context->AX[0].U0)
145 #define thread_saved_fp(tsk) \
146 ((unsigned long)(tsk)->thread.kernel_context->AX[1].U0)
148 unsigned long get_wchan(struct task_struct *p);
150 #define KSTK_EIP(tsk) ((tsk)->thread.kernel_context->CurrPC)
151 #define KSTK_ESP(tsk) ((tsk)->thread.kernel_context->AX[0].U0)
153 #define user_stack_pointer(regs) ((regs)->ctx.AX[0].U0)
155 #define cpu_relax() barrier()
157 extern void setup_priv(void);
159 static inline unsigned int hard_processor_id(void)
163 asm volatile ("MOV %0, TXENABLE\n"
167 : "I" (TXENABLE_THREAD_BITS),
168 "K" (TXENABLE_THREAD_S)
177 #define HALT_PANIC -1
180 * Halt (stop) the hardware thread. This instruction sequence is the
181 * standard way to cause a Meta hardware thread to exit. The exit code
182 * is pushed onto the stack which is interpreted by the debug adapter.
184 static inline void hard_processor_halt(int exit_code)
186 asm volatile ("MOV D1Ar1, %0\n"
188 "MSETL [A0StP],D0Ar6,D0Ar4,D0Ar2\n"
192 : : "r" (exit_code), "K" (OP3_EXIT));
195 /* Set these hooks to call SoC specific code to restart/halt/power off. */
196 extern void (*soc_restart)(char *cmd);
197 extern void (*soc_halt)(void);
199 extern void show_trace(struct task_struct *tsk, unsigned long *sp,
200 struct pt_regs *regs);
202 extern const struct seq_operations cpuinfo_op;