OpenCores
URL https://opencores.org/ocsvn/openrisc/openrisc/trunk

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [rtos/] [ecos-2.0/] [packages/] [hal/] [frv/] [arch/] [v2_0/] [include/] [hal_arch.h] - Blame information for rev 279

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 27 unneback
#ifndef CYGONCE_HAL_ARCH_H
2
#define CYGONCE_HAL_ARCH_H
3
 
4
//==========================================================================
5
//
6
//      hal_arch.h
7
//
8
//      Architecture specific abstractions
9
//
10
//==========================================================================
11
//####ECOSGPLCOPYRIGHTBEGIN####
12
// -------------------------------------------
13
// This file is part of eCos, the Embedded Configurable Operating System.
14
// Copyright (C) 1998, 1999, 2000, 2001, 2002 Red Hat, Inc.
15
//
16
// eCos is free software; you can redistribute it and/or modify it under
17
// the terms of the GNU General Public License as published by the Free
18
// Software Foundation; either version 2 or (at your option) any later version.
19
//
20
// eCos is distributed in the hope that it will be useful, but WITHOUT ANY
21
// WARRANTY; without even the implied warranty of MERCHANTABILITY or
22
// FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
23
// for more details.
24
//
25
// You should have received a copy of the GNU General Public License along
26
// with eCos; if not, write to the Free Software Foundation, Inc.,
27
// 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
28
//
29
// As a special exception, if other files instantiate templates or use macros
30
// or inline functions from this file, or you compile this file and link it
31
// with other works to produce a work based on this file, this file does not
32
// by itself cause the resulting work to be covered by the GNU General Public
33
// License. However the source code for this file must still be made available
34
// in accordance with section (3) of the GNU General Public License.
35
//
36
// This exception does not invalidate any other reasons why a work based on
37
// this file might be covered by the GNU General Public License.
38
//
39
// Alternative licenses for eCos may be arranged by contacting Red Hat, Inc.
40
// at http://sources.redhat.com/ecos/ecos-license/
41
// -------------------------------------------
42
//####ECOSGPLCOPYRIGHTEND####
43
//==========================================================================
44
//#####DESCRIPTIONBEGIN####
45
//
46
// Author(s):    nickg, gthomas
47
// Contributors: nickg, gthomas
48
// Date:         2001-09-07
49
// Purpose:      Define architecture abstractions
50
// Usage:        #include <cyg/hal/hal_arch.h>
51
 
52
//              
53
//####DESCRIPTIONEND####
54
//
55
//==========================================================================
56
 
57
#include <pkgconf/hal.h>         // To decide on stack usage
58
#include <cyg/infra/cyg_type.h>
59
 
60
#if CYGINT_HAL_FRV_ARCH_FR400 != 0
61
#define _NGPR 32
62
#define _NFPR 32
63
#endif
64
#if CYGINT_HAL_FRV_ARCH_FR500 != 0
65
#define _NGPR 64
66
#define _NFPR 64
67
#endif
68
 
69
#ifndef _NGPR
70
#error No architecture defined?
71
#endif
72
 
73
//--------------------------------------------------------------------------
74
// Common "special" register definitions
75
 
76
// Processor status register
77
#define _PSR_PIVL_SHIFT 3
78
#define _PSR_PIVL_MASK  (0xF<<(_PSR_PIVL_SHIFT))  // Interrupt mask level
79
#define _PSR_S          (1<<2)                    // Supervisor state
80
#define _PSR_PS         (1<<1)                    // Previous supervisor state
81
#define _PSR_ET         (1<<0)                    // Enable interrupts
82
 
83
#define _PSR_INITIAL (_PSR_S|_PSR_PS|_PSR_ET)     // Supervisor mode, exceptions
84
 
85
// Hardware status register
86
#define _HSR0_ICE       (1<<31)                   // Instruction cache enable
87
#define _HSR0_DCE       (1<<30)                   // Data cache enable
88
#define _HSR0_IMMU      (1<<26)                   // Instruction MMU enable
89
#define _HSR0_DMMU      (1<<25)                   // Data MMU enable
90
 
91
// Debug Control Register
92
#define _DCR_EBE        (1 << 30)
93
#define _DCR_SE         (1 << 29)
94
#define _DCR_DRBE0      (1 << 19)
95
#define _DCR_DWBE0      (1 << 18)
96
#define _DCR_DDBE0      (1 << 17)
97
#define _DCR_DRBE1      (1 << 16)
98
#define _DCR_DWBE1      (1 << 15)
99
#define _DCR_DDBE1      (1 << 14)
100
#define _DCR_DRBE2      (1 << 13)
101
#define _DCR_DWBE2      (1 << 12)
102
#define _DCR_DDBE2      (1 << 11)
103
#define _DCR_DRBE3      (1 << 10)
104
#define _DCR_DWBE3      (1 << 9)
105
#define _DCR_DDBE3      (1 << 8)
106
#define _DCR_IBE0       (1 << 7)
107
#define _DCR_IBCE0      (1 << 6)
108
#define _DCR_IBE1       (1 << 5)
109
#define _DCR_IBCE1      (1 << 4)
110
#define _DCR_IBE2       (1 << 3)
111
#define _DCR_IBCE2      (1 << 2)
112
#define _DCR_IBE3       (1 << 1)
113
#define _DCR_IBCE3      (1 << 0)
114
 
115
// Initial contents for special registers
116
 
117
#define _CCR_INITIAL    0
118
#define _LCR_INITIAL    0
119
#define _CCCR_INITIAL   0
120
 
121
//--------------------------------------------------------------------------
122
//
123
// Saved thread state
124
//
125
typedef struct
126
{
127
    cyg_uint32 gpr[_NGPR];  // Saved general purpose registers
128
    cyg_uint32 pc;          // Current [next] instruction location
129
    cyg_uint32 psr;         // Processor status register
130
    cyg_uint32 lr;          // Link register
131
    cyg_uint32 ccr;         // Condition codes
132
    cyg_uint32 cccr;
133
    cyg_uint32 lcr;
134
    cyg_int32  vector;      // Reason for last exception
135
} HAL_SavedRegisters;
136
 
137
//-------------------------------------------------------------------------
138
// Exception handling function.
139
// This function is defined by the kernel according to this prototype. It is
140
// invoked from the HAL to deal with any CPU exceptions that the HAL does
141
// not want to deal with itself. It usually invokes the kernel's exception
142
// delivery mechanism.
143
 
144
externC void cyg_hal_deliver_exception( CYG_WORD code, CYG_ADDRWORD data );
145
 
146
//-------------------------------------------------------------------------
147
// Bit manipulation macros
148
 
149
externC int hal_lsbindex(int);
150
externC int hal_msbindex(int);
151
 
152
#define HAL_LSBIT_INDEX(index, mask) index = hal_lsbindex(mask)
153
#define HAL_MSBIT_INDEX(index, mask) index = hal_msbindex(mask)
154
 
155
//-------------------------------------------------------------------------
156
// Context Initialization
157
// Initialize the context of a thread.
158
// Arguments:
159
// _sparg_ name of variable containing current sp, will be changed to new sp
160
// _thread_ thread object address, passed as argument to entry point
161
// _entry_ entry point address.
162
// _id_ bit pattern used in initializing registers, for debugging.
163
 
164
#define _HAL_THREAD_INIT_CONTEXT( _sparg_, _thread_, _entry_, _id_ )             \
165
    CYG_MACRO_START                                                             \
166
    register CYG_WORD _sp_ = ((CYG_WORD)_sparg_) &~15;                          \
167
    register HAL_SavedRegisters *_regs_;                                        \
168
    int _i_;                                                                    \
169
    _regs_ = (HAL_SavedRegisters *)((_sp_) - sizeof(HAL_SavedRegisters));       \
170
    for( _i_ = 1;  _i_ < _NGPR;  _i_++)                                         \
171
        (_regs_)->gpr[_i_] = (_id_)|_i_;                                        \
172
    (_regs_)->gpr[8] = (CYG_WORD)(_thread_); /* R8 = arg1 = thread ptr */       \
173
    (_regs_)->gpr[1] = (CYG_WORD)(_sp_);     /* SP = top of stack      */       \
174
    (_regs_)->lr = (CYG_WORD)(_entry_);      /* LR = entry point       */       \
175
    (_regs_)->pc = (CYG_WORD)(_entry_);      /* PC = [initial] entry point */   \
176
    (_regs_)->psr = _PSR_INITIAL;            /* PSR = Interrupt enabled */      \
177
    (_regs_)->ccr = _CCR_INITIAL;                                               \
178
    (_regs_)->lcr = _LCR_INITIAL;                                               \
179
    (_regs_)->ccr = _CCCR_INITIAL;                                              \
180
    _sparg_ = (CYG_ADDRESS)_regs_;                                              \
181
    CYG_MACRO_END
182
 
183
//--------------------------------------------------------------------------
184
// Context switch macros.
185
// The arguments are pointers to locations where the stack pointer
186
// of the current thread is to be stored, and from where the sp of the
187
// next thread is to be fetched.
188
 
189
externC void hal_thread_switch_context( CYG_ADDRESS to, CYG_ADDRESS from );
190
externC void hal_thread_load_context( CYG_ADDRESS to )
191
    __attribute__ ((noreturn));
192
 
193
#define HAL_THREAD_SWITCH_CONTEXT(_fspptr_,_tspptr_)                    \
194
        hal_thread_switch_context((CYG_ADDRESS)_tspptr_,                \
195
                                  (CYG_ADDRESS)_fspptr_);
196
 
197
#define HAL_THREAD_LOAD_CONTEXT(_tspptr_)                               \
198
        hal_thread_load_context( (CYG_ADDRESS)_tspptr_ );
199
 
200
//--------------------------------------------------------------------------
201
// Execution reorder barrier.
202
// When optimizing the compiler can reorder code. In multithreaded systems
203
// where the order of actions is vital, this can sometimes cause problems.
204
// This macro may be inserted into places where reordering should not happen.
205
 
206
#define HAL_REORDER_BARRIER() asm volatile ( "" : : : "memory" )
207
 
208
//--------------------------------------------------------------------------
209
// Breakpoint support
210
// HAL_BREAKPOINT() is a code sequence that will cause a breakpoint to happen
211
// if executed.
212
// HAL_BREAKINST is the value of the breakpoint instruction and 
213
// HAL_BREAKINST_SIZE is its size in bytes.
214
 
215
// The choices for breakpoints seem to be:
216
//    break           0x801000C0
217
//    tira  gr0,#1    0xC0700001
218
#ifdef CYGSEM_HAL_FRV_USE_BREAK_INSTRUCTION 
219
#define HAL_BREAKPOINT(_label_)                   \
220
asm volatile (" .globl  " #_label_ "\n"            \
221
              #_label_":\tbreak\n"             \
222
    );
223
 
224
#define HAL_BREAKINST            0x801000C0
225
#else
226
#define HAL_BREAKPOINT(_label_)                   \
227
asm volatile (" .globl  " #_label_ "\n"            \
228
              #_label_":\ttira\tgr0,#1\n"             \
229
    );
230
 
231
#define HAL_BREAKINST            0xC0700001
232
#endif
233
#define HAL_BREAKINST_SIZE       4
234
#define HAL_BREAKINST_TYPE       cyg_uint32
235
 
236
//--------------------------------------------------------------------------
237
// Thread register state manipulation for GDB support.
238
 
239
// GDB expects the registers in this structure:
240
//   gr0..gr31, gr32..gr63       - 4 bytes each
241
//   fpr0..fpr31, fpr32..fpr63   - 4 bytes each
242
//   pc, psr, ccr, cccr          - 4 bytes each
243
//   14 <unused>                 - 4 bytes each
244
//   lr, lcr                     - 4 bytes each
245
 
246
// Translate a stack pointer as saved by the thread context macros above into
247
// a pointer to a HAL_SavedRegisters structure.
248
#define HAL_THREAD_GET_SAVED_REGISTERS( _sp_, _regs_ )  \
249
        (_regs_) = (HAL_SavedRegisters *)(_sp_)
250
 
251
// Copy a set of registers from a HAL_SavedRegisters structure into a
252
// GDB ordered array.    
253
#define HAL_GET_GDB_REGISTERS( _aregval_, _regs_ )              \
254
    CYG_MACRO_START                                             \
255
    CYG_ADDRWORD *_regval_ = (CYG_ADDRWORD *)(_aregval_);       \
256
    int _i_;                                                    \
257
                                                                \
258
    for( _i_ = 0; _i_ <= _NGPR; _i_++ )                          \
259
        _regval_[_i_] = (_regs_)->gpr[_i_];                     \
260
    _regval_[128] = (_regs_)->pc;                               \
261
    _regval_[129] = (_regs_)->psr;                              \
262
    _regval_[130] = (_regs_)->ccr;                              \
263
    _regval_[135] = (_regs_)->vector;                           \
264
    _regval_[145] = (_regs_)->lr;                               \
265
    _regval_[146] = (_regs_)->lcr;                              \
266
    CYG_MACRO_END
267
 
268
// Copy a GDB ordered array into a HAL_SavedRegisters structure.
269
#define HAL_SET_GDB_REGISTERS( _regs_ , _aregval_ )             \
270
    CYG_MACRO_START                                             \
271
    CYG_ADDRWORD *_regval_ = (CYG_ADDRWORD *)(_aregval_);       \
272
    int _i_;                                                    \
273
                                                                \
274
    for( _i_ = 0; _i_ <= _NGPR; _i_++ )                          \
275
        (_regs_)->gpr[_i_] = _regval_[_i_];                     \
276
                                                                \
277
    (_regs_)->pc  = _regval_[128];                              \
278
    (_regs_)->psr = _regval_[129];                              \
279
    (_regs_)->ccr = _regval_[130];                              \
280
    (_regs_)->lr  = _regval_[145];                              \
281
    (_regs_)->lcr  = _regval_[146];                             \
282
    CYG_MACRO_END
283
 
284
//--------------------------------------------------------------------------
285
// HAL setjmp
286
 
287
#define CYGARC_JMP_BUF_SIZE 0x110
288
 
289
typedef cyg_uint32 hal_jmp_buf[CYGARC_JMP_BUF_SIZE];
290
 
291
externC int hal_setjmp(hal_jmp_buf env);
292
externC void hal_longjmp(hal_jmp_buf env, int val);
293
 
294
//--------------------------------------------------------------------------
295
// Idle thread code.
296
// This macro is called in the idle thread loop, and gives the HAL the
297
// chance to insert code. Typical idle thread behaviour might be to halt the
298
// processor.
299
 
300
externC void hal_idle_thread_action(cyg_uint32 loop_count);
301
 
302
#define HAL_IDLE_THREAD_ACTION(_count_) hal_idle_thread_action(_count_)
303
 
304
//---------------------------------------------------------------------------
305
 
306
// Minimal and sensible stack sizes: the intention is that applications
307
// will use these to provide a stack size in the first instance prior to
308
// proper analysis.  Idle thread stack should be this big.
309
 
310
//    THESE ARE NOT INTENDED TO BE MICROMETRICALLY ACCURATE FIGURES.
311
//           THEY ARE HOWEVER ENOUGH TO START PROGRAMMING.
312
// YOU MUST MAKE YOUR STACKS LARGER IF YOU HAVE LARGE "AUTO" VARIABLES!
313
 
314
// This is not a config option because it should not be adjusted except
315
// under "enough rope" sort of disclaimers.
316
 
317
// A minimal, optimized stack frame, rounded up - no autos
318
#define CYGNUM_HAL_STACK_FRAME_SIZE (4 * 150)
319
 
320
// Stack needed for a context switch: this is implicit in the estimate for
321
// interrupts so not explicitly used below:
322
#define CYGNUM_HAL_STACK_CONTEXT_SIZE (4 * 150)
323
 
324
// Interrupt + call to ISR, interrupt_end() and the DSR
325
#define CYGNUM_HAL_STACK_INTERRUPT_SIZE \
326
    ((4 * 150) + 2 * CYGNUM_HAL_STACK_FRAME_SIZE)
327
 
328
// Space for the maximum number of nested interrupts, plus room to call functions
329
#define CYGNUM_HAL_MAX_INTERRUPT_NESTING 4
330
 
331
#define CYGNUM_HAL_STACK_SIZE_MINIMUM \
332
        (CYGNUM_HAL_MAX_INTERRUPT_NESTING * CYGNUM_HAL_STACK_INTERRUPT_SIZE + \
333
         2 * CYGNUM_HAL_STACK_FRAME_SIZE)
334
 
335
#define CYGNUM_HAL_STACK_SIZE_TYPICAL \
336
        (CYGNUM_HAL_STACK_SIZE_MINIMUM + \
337
         16 * CYGNUM_HAL_STACK_FRAME_SIZE)
338
 
339
 
340
//--------------------------------------------------------------------------
341
// Macros for switching context between two eCos instances (jump from
342
// code in ROM to code in RAM or vice versa).
343
#define CYGARC_HAL_SAVE_GP()
344
#define CYGARC_HAL_RESTORE_GP()
345
 
346
#endif // CYGONCE_HAL_ARCH_H
347
// End of hal_arch.h

powered by: WebSVN 2.1.0

© copyright 1999-2025 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.