[ubicom32]: move new files out from platform support patch
[openwrt.git] / target / linux / ubicom32 / files / arch / ubicom32 / include / asm / processor.h
1 /*
2  * arch/ubicom32/include/asm/processor.h
3  *   Thread related definitions for Ubicom32 architecture.
4  *
5  * (C) Copyright 2009, Ubicom, Inc.
6  * Copyright (C) 1995 Hamish Macdonald
7  *
8  * This file is part of the Ubicom32 Linux Kernel Port.
9  *
10  * The Ubicom32 Linux Kernel Port is free software: you can redistribute
11  * it and/or modify it under the terms of the GNU General Public License
12  * as published by the Free Software Foundation, either version 2 of the
13  * License, or (at your option) any later version.
14  *
15  * The Ubicom32 Linux Kernel Port is distributed in the hope that it
16  * will be useful, but WITHOUT ANY WARRANTY; without even the implied
17  * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See
18  * the GNU General Public License for more details.
19  *
20  * You should have received a copy of the GNU General Public License
21  * along with the Ubicom32 Linux Kernel Port.  If not,
22  * see <http://www.gnu.org/licenses/>.
23  *
24  * Ubicom32 implementation derived from (with many thanks):
25  *   arch/m68knommu
26  *   arch/blackfin
27  *   arch/parisc
28  */
29
30 #ifndef _ASM_UBICOM32_PROCESSOR_H
31 #define _ASM_UBICOM32_PROCESSOR_H
32
33 /*
34  * Default implementation of macro that returns current
35  * instruction pointer ("program counter").
36  */
37 #define current_text_addr() ({ __label__ _l; _l: &&_l;})
38
39 #include <linux/compiler.h>
40 #include <linux/threads.h>
41 #include <asm/types.h>
42 #include <asm/segment.h>
43 #include <asm/fpu.h>
44 #include <asm/ptrace.h>
45 #include <asm/current.h>
46 #include <asm/thread_info.h>
47
48 #if defined(CONFIG_UBICOM32_V3)
49         #define CPU "IP5K"
50 #endif
51 #if defined(CONFIG_UBICOM32_V4)
52         #define CPU "IP7K"
53 #endif
54 #ifndef CPU
55         #define CPU "UNKNOWN"
56 #endif
57
58 /*
59  * User space process size: 1st byte beyond user address space.
60  */
61 extern unsigned long memory_end;
62 #define TASK_SIZE       (memory_end)
63
64 /*
65  * This decides where the kernel will search for a free chunk of vm
66  * space during mmap's. We won't be using it
67  */
68 #define TASK_UNMAPPED_BASE      0
69
70 /*
71  * This is the structure where we are going to save callee-saved registers.
72  * A5 is the return address, A7 is the stack pointer, A6 is the frame
73  * pointer.  This is the frame that is created because of switch_to. This
74  * is not the frame due to interrupt preemption or because of syscall entry.
75  */
76
77 struct thread_struct {
78         unsigned long  d10;             /* D10  */
79         unsigned long  d11;             /* D11  */
80         unsigned long  d12;             /* D12  */
81         unsigned long  d13;             /* D13  */
82         unsigned long  a1;              /* A1  */
83         unsigned long  a2;              /* A2  */
84         unsigned long  a5;              /* A5 return address. */
85         unsigned long  a6;              /* A6 */
86         unsigned long  sp;              /* A7 kernel stack pointer. */
87 };
88
89 #define INIT_THREAD  { \
90         0, 0, 0, 0, 0, 0, 0, 0, \
91         sizeof(init_stack) + (unsigned long) init_stack - 8, \
92 }
93
94 /*
95  * Do necessary setup to start up a newly executed thread.
96  *
97  * pass the data segment into user programs if it exists,
98  * it can't hurt anything as far as I can tell
99  */
100 /*
101  * Do necessary setup to start up a newly executed thread.
102  */
103 #define start_thread(regs, new_pc, new_sp)       \
104         do {                                     \
105                 regs->pc = new_pc & ~3;          \
106                 regs->an[5] = new_pc & ~3;       \
107                 regs->an[7] = new_sp;            \
108                 regs->nesting_level = -1;        \
109                 regs->frame_type = UBICOM32_FRAME_TYPE_NEW_THREAD; \
110                 regs->thread_type = NORMAL_THREAD; \
111         } while(0)
112
113 /* Forward declaration, a strange C thing */
114 struct task_struct;
115
116 /* Free all resources held by a thread. */
117 static inline void release_thread(struct task_struct *dead_task)
118 {
119 }
120
121 /* Prepare to copy thread state - unlazy all lazy status */
122 #define prepare_to_copy(tsk)    do { } while (0)
123
124 extern int kernel_thread(int (*fn)(void *), void * arg, unsigned long flags);
125
126 /*
127  * Free current thread data structures etc..
128  */
129 static inline void exit_thread(void)
130 {
131 }
132
133 unsigned long thread_saved_pc(struct task_struct *tsk);
134 unsigned long get_wchan(struct task_struct *p);
135
136 #define KSTK_EIP(tsk)   (tsk->thread.a5)
137 #define KSTK_ESP(tsk)   (tsk->thread.sp)
138
139 #define cpu_relax()    barrier()
140
141 extern void processor_init(void);
142 extern unsigned int processor_timers(void);
143 extern unsigned int processor_threads(void);
144 extern unsigned int processor_frequency(void);
145 extern int processor_interrupts(unsigned int *int0, unsigned int *int1);
146 extern void processor_ocm(unsigned long *socm, unsigned long *eocm);
147 extern void processor_dram(unsigned long *sdram, unsigned long *edram);
148
149 #define THREAD_SIZE_LONGS      (THREAD_SIZE/sizeof(unsigned long))
150 #define KSTK_TOP(info)                                                 \
151 ({                                                                     \
152        unsigned long *__ptr = (unsigned long *)(info);                 \
153        (unsigned long)(&__ptr[THREAD_SIZE_LONGS]);                     \
154 })
155
156 #define task_pt_regs(task)                                             \
157 ({                                                                     \
158        struct pt_regs *__regs__;                                       \
159        __regs__ = (struct pt_regs *)(KSTK_TOP(task_stack_page(task))-8); \
160        __regs__ - 1;                                                   \
161 })
162
163 #endif  /* _ASM_UBICOM32_PROCESSOR_H */