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

Subversion Repositories openrisc

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

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:         1999-02-20
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
//
61
// CPSR Register defines
62
//
63
 
64
#define CPSR_IRQ_DISABLE        0x80    // IRQ disabled when =1
65
#define CPSR_FIQ_DISABLE        0x40    // FIQ disabled when =1
66
#define CPSR_THUMB_ENABLE       0x20    // Thumb mode when =1
67
#define CPSR_FIQ_MODE           0x11
68
#define CPSR_IRQ_MODE           0x12
69
#define CPSR_SUPERVISOR_MODE    0x13
70
#define CPSR_UNDEF_MODE         0x1B
71
 
72
#define CPSR_MODE_BITS          0x1F
73
 
74
#define CPSR_INITIAL (CPSR_IRQ_DISABLE|CPSR_FIQ_DISABLE|CPSR_SUPERVISOR_MODE)
75
#define CPSR_THREAD_INITIAL (CPSR_SUPERVISOR_MODE)
76
 
77
//--------------------------------------------------------------------------
78
// Processor saved states:
79
// The layout of this structure is also defined in "arm.inc", for assembly
80
// code, which will be generated automatically if this file changes.
81
 
82
#define HAL_THREAD_CONTEXT_FIRST        0
83
#define HAL_THREAD_CONTEXT_R0           (0-HAL_THREAD_CONTEXT_FIRST)
84
#define HAL_THREAD_CONTEXT_R4           (4-HAL_THREAD_CONTEXT_FIRST)
85
#define HAL_THREAD_CONTEXT_R8           (8-HAL_THREAD_CONTEXT_FIRST)
86
#define HAL_THREAD_CONTEXT_R9           (9-HAL_THREAD_CONTEXT_FIRST)
87
#define HAL_THREAD_CONTEXT_R10          (10-HAL_THREAD_CONTEXT_FIRST)
88
#define HAL_THREAD_CONTEXT_LAST         10
89
#define HAL_NUM_THREAD_CONTEXT_REGS     (HAL_THREAD_CONTEXT_LAST - \
90
                                          HAL_THREAD_CONTEXT_FIRST+1)
91
 
92
// It seems that r0-r3,r12 are considered scratch by function calls
93
 
94
typedef struct
95
{
96
    // These are common to all saved states
97
    cyg_uint32  d[HAL_NUM_THREAD_CONTEXT_REGS] ;  // Data regs (r0..r10)
98
    cyg_uint32  fp;                               // (r11) Frame pointer
99
    cyg_uint32  ip;                               // (r12)
100
    cyg_uint32  sp;                               // (r13) Stack pointer
101
    cyg_uint32  lr;                               // (r14) Link Reg
102
    cyg_uint32  pc;                               // (r15) PC place holder
103
                                                  //       (never used)
104
    cyg_uint32  cpsr;                             // Condition Reg
105
    // These are only saved for exceptions and interrupts
106
    cyg_uint32  vector;                           // Vector number
107
    cyg_uint32  svc_lr;                           // saved svc mode lr
108
    cyg_uint32  svc_sp;                           // saved svc mode sp
109
 
110
} HAL_SavedRegisters;
111
 
112
//-------------------------------------------------------------------------
113
// Exception handling function.
114
// This function is defined by the kernel according to this prototype. It is
115
// invoked from the HAL to deal with any CPU exceptions that the HAL does
116
// not want to deal with itself. It usually invokes the kernel's exception
117
// delivery mechanism.
118
 
119
externC void cyg_hal_deliver_exception( CYG_WORD code, CYG_ADDRWORD data );
120
 
121
//-------------------------------------------------------------------------
122
// Bit manipulation macros
123
 
124
externC int hal_lsbindex(int);
125
externC int hal_msbindex(int);
126
 
127
#define HAL_LSBIT_INDEX(index, mask) index = hal_lsbindex(mask)
128
#define HAL_MSBIT_INDEX(index, mask) index = hal_msbindex(mask)
129
 
130
//-------------------------------------------------------------------------
131
// Context Initialization
132
// Initialize the context of a thread.
133
// Arguments:
134
// _sparg_ name of variable containing current sp, will be changed to new sp
135
// _thread_ thread object address, passed as argument to entry point
136
// _entry_ entry point address.
137
// _id_ bit pattern used in initializing registers, for debugging.
138
 
139
#define HAL_THREAD_INIT_CONTEXT( _sparg_, _thread_, _entry_, _id_ )         \
140
    CYG_MACRO_START                                                         \
141
    register CYG_WORD _sp_ = ((CYG_WORD)_sparg_) &~15;                      \
142
    register HAL_SavedRegisters *_regs_;                                    \
143
    int _i_;                                                                \
144
    _regs_ = (HAL_SavedRegisters *)((_sp_) - sizeof(HAL_SavedRegisters));   \
145
    for( _i_ = HAL_THREAD_CONTEXT_FIRST; _i_ <= HAL_THREAD_CONTEXT_LAST;    \
146
           _i_++ )                                                          \
147
        (_regs_)->d[_i_] = (_id_)|_i_;                                      \
148
    (_regs_)->d[00] = (CYG_WORD)(_thread_); /* R0 = arg1 = thread ptr */    \
149
    (_regs_)->sp = (CYG_WORD)(_sp_);        /* SP = top of stack      */    \
150
    (_regs_)->lr = (CYG_WORD)(_entry_);     /* LR = entry point       */    \
151
    (_regs_)->pc = (CYG_WORD)(_entry_);     /* PC = [initial] entry point */\
152
    (_regs_)->cpsr = (CPSR_THREAD_INITIAL); /* PSR = Interrupt enabled */   \
153
    _sparg_ = (CYG_ADDRESS)_regs_;                                          \
154
    CYG_MACRO_END
155
 
156
//--------------------------------------------------------------------------
157
// Context switch macros.
158
// The arguments are pointers to locations where the stack pointer
159
// of the current thread is to be stored, and from where the sp of the
160
// next thread is to be fetched.
161
 
162
externC void hal_thread_switch_context( CYG_ADDRESS to, CYG_ADDRESS from );
163
externC void hal_thread_load_context( CYG_ADDRESS to )
164
    __attribute__ ((noreturn));
165
 
166
#define HAL_THREAD_SWITCH_CONTEXT(_fspptr_,_tspptr_)                    \
167
        hal_thread_switch_context((CYG_ADDRESS)_tspptr_,                \
168
                                  (CYG_ADDRESS)_fspptr_);
169
 
170
#define HAL_THREAD_LOAD_CONTEXT(_tspptr_)                               \
171
        hal_thread_load_context( (CYG_ADDRESS)_tspptr_ );
172
 
173
//--------------------------------------------------------------------------
174
// Execution reorder barrier.
175
// When optimizing the compiler can reorder code. In multithreaded systems
176
// where the order of actions is vital, this can sometimes cause problems.
177
// This macro may be inserted into places where reordering should not happen.
178
 
179
#define HAL_REORDER_BARRIER() asm volatile ( "" : : : "memory" )
180
 
181
//--------------------------------------------------------------------------
182
// Breakpoint support
183
// HAL_BREAKPOINT() is a code sequence that will cause a breakpoint to happen
184
// if executed.
185
// HAL_BREAKINST is the value of the breakpoint instruction and 
186
// HAL_BREAKINST_SIZE is its size in bytes.
187
 
188
#define _stringify1(__arg) #__arg
189
#define _stringify(__arg) _stringify1(__arg)
190
 
191
#define HAL_BREAKINST_ARM          0xE7FFDEFE
192
#define HAL_BREAKINST_ARM_SIZE     4
193
#define HAL_BREAKINST_THUMB        0xbebe  // illegal instruction currently
194
#define HAL_BREAKINST_THUMB_SIZE   2
195
 
196
#ifdef __thumb__
197
 
198
# define HAL_BREAKPOINT(_label_)                         \
199
asm volatile (" .code 16;"                               \
200
              " .globl  " #_label_ ";"                   \
201
              #_label_":"                                \
202
              " .short " _stringify(HAL_BREAKINST_THUMB) \
203
    );
204
 
205
# define HAL_BREAKINST           HAL_BREAKINST_THUMB
206
# define HAL_BREAKINST_SIZE      HAL_BREAKINST_THUMB_SIZE
207
# define HAL_BREAKINST_TYPE      cyg_uint16
208
#else // __thumb__
209
 
210
#define HAL_BREAKPOINT(_label_)                   \
211
asm volatile (" .globl  " #_label_ ";"            \
212
              #_label_":"                         \
213
              " .word " _stringify(HAL_BREAKINST_ARM) \
214
    );
215
 
216
//#define HAL_BREAKINST           {0xFE, 0xDE, 0xFF, 0xE7}
217
#define HAL_BREAKINST            HAL_BREAKINST_ARM
218
#define HAL_BREAKINST_SIZE       HAL_BREAKINST_ARM_SIZE
219
#define HAL_BREAKINST_TYPE       cyg_uint32
220
#endif // __thumb__
221
 
222
 
223
extern cyg_uint32 __arm_breakinst;
224
extern cyg_uint16 __thumb_breakinst;
225
#define HAL_BREAKINST_ADDR(x) (((x)==2)? \
226
                              ((void*)&__thumb_breakinst) : \
227
                              ((void*)&__arm_breakinst))
228
 
229
//--------------------------------------------------------------------------
230
// Thread register state manipulation for GDB support.
231
 
232
// Register layout expected by GDB
233
typedef struct
234
{
235
    cyg_uint32  gpr[16];
236
    cyg_uint32  f0[3];
237
    cyg_uint32  f1[3];
238
    cyg_uint32  f2[3];
239
    cyg_uint32  f3[3];
240
    cyg_uint32  f4[3];
241
    cyg_uint32  f5[3];
242
    cyg_uint32  f6[3];
243
    cyg_uint32  f7[3];
244
    cyg_uint32  fps;
245
    cyg_uint32  ps;
246
} GDB_Registers;
247
 
248
// Translate a stack pointer as saved by the thread context macros above into
249
// a pointer to a HAL_SavedRegisters structure.
250
#define HAL_THREAD_GET_SAVED_REGISTERS( _sp_, _regs_ )  \
251
        (_regs_) = (HAL_SavedRegisters *)(_sp_)
252
 
253
// Copy a set of coprocessor registers from a HAL_SavedRegisters structure
254
// into a GDB_Registers structure. GDB expects placeholders for FP regs
255
// even for non-FP targets, so we just zero fill the fields.
256
#define HAL_GET_GDB_COPROCESSOR_REGISTERS( _gdb_, _regs_ )      \
257
    CYG_MACRO_START                                             \
258
    cyg_uint32 *_p_ = _gdb_->f0;                                \
259
    for(_i_ = 0; _i_ < (8 * 3); _i_++)                          \
260
        *_p_++ = 0;                                             \
261
    _gdb_->fps = 0;                                             \
262
    CYG_MACRO_END
263
 
264
// Copy coprocessor registers from a GDB_Registers structure into a
265
// HAL_SavedRegisters structure.
266
#define HAL_SET_GDB_COPROCESSOR_REGISTERS( _regs_, _gdb_ )
267
 
268
// Copy a set of registers from a HAL_SavedRegisters structure into a
269
// GDB_Registers structure.
270
#define HAL_GET_GDB_REGISTERS( _aregval_, _regs_ )              \
271
    CYG_MACRO_START                                             \
272
    GDB_Registers *_gdb_ = (GDB_Registers *)(_aregval_);        \
273
    int _i_;                                                    \
274
                                                                \
275
    for( _i_ = 0; _i_ <= 10; _i_++ )                            \
276
        _gdb_->gpr[_i_] = (_regs_)->d[_i_];                     \
277
                                                                \
278
    _gdb_->gpr[11] = (_regs_)->fp;                              \
279
    _gdb_->gpr[12] = (_regs_)->ip;                              \
280
    _gdb_->gpr[13] = (_regs_)->sp;                              \
281
    _gdb_->gpr[14] = (_regs_)->lr;                              \
282
    _gdb_->gpr[15] = (_regs_)->pc;                              \
283
    _gdb_->ps = (_regs_)->cpsr;                                 \
284
    HAL_GET_GDB_COPROCESSOR_REGISTERS(_gdb_,_regs_);            \
285
    CYG_MACRO_END
286
 
287
// Copy a set of registers from a GDB_Registers structure into a
288
// HAL_SavedRegisters structure.
289
#define HAL_SET_GDB_REGISTERS( _regs_ , _aregval_ )             \
290
    CYG_MACRO_START                                             \
291
    GDB_Registers *_gdb_ = (GDB_Registers *)(_aregval_);        \
292
    int _i_;                                                    \
293
                                                                \
294
    for( _i_ = 0; _i_ <= 10; _i_++ )                            \
295
        (_regs_)->d[_i_] = _gdb_->gpr[_i_];                     \
296
                                                                \
297
    (_regs_)->fp = _gdb_->gpr[11];                              \
298
    (_regs_)->ip = _gdb_->gpr[12];                              \
299
    (_regs_)->sp = _gdb_->gpr[13];                              \
300
    (_regs_)->lr = _gdb_->gpr[14];                              \
301
    (_regs_)->pc = _gdb_->gpr[15];                              \
302
    (_regs_)->cpsr = _gdb_->ps;                                 \
303
    HAL_SET_GDB_COPROCESSOR_REGISTERS(_regs_,_gdb_);            \
304
    CYG_MACRO_END
305
 
306
#if defined(CYGDBG_HAL_DEBUG_GDB_CTRLC_SUPPORT) || defined(CYGDBG_HAL_DEBUG_GDB_BREAK_SUPPORT)
307
#define HAL_GET_PROFILE_INFO( _thepc_, _thesp_ )                \
308
    CYG_MACRO_START                                             \
309
    extern HAL_SavedRegisters *hal_saved_interrupt_state;       \
310
    if ( hal_saved_interrupt_state ) {                          \
311
        (_thepc_) = (char *)(hal_saved_interrupt_state->pc);    \
312
        (_thesp_) = (char *)(hal_saved_interrupt_state->sp);    \
313
    }                                                           \
314
    CYG_MACRO_END
315
#endif
316
 
317
//--------------------------------------------------------------------------
318
// HAL setjmp
319
 
320
#define CYGARC_JMP_BUF_SIZE 16  // Actually 11, but some room left over
321
 
322
typedef cyg_uint32 hal_jmp_buf[CYGARC_JMP_BUF_SIZE];
323
 
324
externC int hal_setjmp(hal_jmp_buf env);
325
externC void hal_longjmp(hal_jmp_buf env, int val);
326
 
327
 
328
//--------------------------------------------------------------------------
329
// Idle thread code.
330
// This macro is called in the idle thread loop, and gives the HAL the
331
// chance to insert code. Typical idle thread behaviour might be to halt the
332
// processor.
333
 
334
externC void hal_idle_thread_action(cyg_uint32 loop_count);
335
 
336
#define HAL_IDLE_THREAD_ACTION(_count_) hal_idle_thread_action(_count_)
337
 
338
//---------------------------------------------------------------------------
339
 
340
// Minimal and sensible stack sizes: the intention is that applications
341
// will use these to provide a stack size in the first instance prior to
342
// proper analysis.  Idle thread stack should be this big.
343
 
344
//    THESE ARE NOT INTENDED TO BE MICROMETRICALLY ACCURATE FIGURES.
345
//           THEY ARE HOWEVER ENOUGH TO START PROGRAMMING.
346
// YOU MUST MAKE YOUR STACKS LARGER IF YOU HAVE LARGE "AUTO" VARIABLES!
347
 
348
// This is not a config option because it should not be adjusted except
349
// under "enough rope" sort of disclaimers.
350
 
351
// A minimal, optimized stack frame, rounded up - no autos
352
#define CYGNUM_HAL_STACK_FRAME_SIZE (4 * 20)
353
 
354
// Stack needed for a context switch: this is implicit in the estimate for
355
// interrupts so not explicitly used below:
356
#define CYGNUM_HAL_STACK_CONTEXT_SIZE (4 * 20)
357
 
358
// Interrupt + call to ISR, interrupt_end() and the DSR
359
#define CYGNUM_HAL_STACK_INTERRUPT_SIZE \
360
    ((4 * 20) + 2 * CYGNUM_HAL_STACK_FRAME_SIZE)
361
 
362
// Space for the maximum number of nested interrupts, plus room to call functions
363
#define CYGNUM_HAL_MAX_INTERRUPT_NESTING 4
364
 
365
#define CYGNUM_HAL_STACK_SIZE_MINIMUM \
366
        (CYGNUM_HAL_MAX_INTERRUPT_NESTING * CYGNUM_HAL_STACK_INTERRUPT_SIZE + \
367
         2 * CYGNUM_HAL_STACK_FRAME_SIZE)
368
 
369
#define CYGNUM_HAL_STACK_SIZE_TYPICAL \
370
        (CYGNUM_HAL_STACK_SIZE_MINIMUM + \
371
         16 * CYGNUM_HAL_STACK_FRAME_SIZE)
372
 
373
//--------------------------------------------------------------------------
374
// Macros for switching context between two eCos instances (jump from
375
// code in ROM to code in RAM or vice versa).
376
#define CYGARC_HAL_SAVE_GP()
377
#define CYGARC_HAL_RESTORE_GP()
378
 
379
#endif // CYGONCE_HAL_ARCH_H
380
// End of hal_arch.h

powered by: WebSVN 2.1.0

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