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

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [rtos/] [ecos-3.0/] [packages/] [hal/] [arm/] [arch/] [current/] [include/] [hal_arch.h] - Blame information for rev 786

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 786 skrzyp
#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, 2003, 2004, 2005, 2007, 2008 Free Software Foundation, 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      
19
// version.                                                                 
20
//
21
// eCos is distributed in the hope that it will be useful, but WITHOUT      
22
// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or    
23
// FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License    
24
// for more details.                                                        
25
//
26
// You should have received a copy of the GNU General Public License        
27
// along with eCos; if not, write to the Free Software Foundation, Inc.,    
28
// 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.            
29
//
30
// As a special exception, if other files instantiate templates or use      
31
// macros or inline functions from this file, or you compile this file      
32
// and link it with other works to produce a work based on this file,       
33
// this file does not by itself cause the resulting work to be covered by   
34
// the GNU General Public License. However the source code for this file    
35
// must still be made available in accordance with section (3) of the GNU   
36
// General Public License v2.                                               
37
//
38
// This exception does not invalidate any other reasons why a work based    
39
// on this file might be covered by the GNU General Public License.         
40
// -------------------------------------------                              
41
// ####ECOSGPLCOPYRIGHTEND####                                              
42
//==========================================================================
43
//#####DESCRIPTIONBEGIN####
44
//
45
// Author(s):    nickg, gthomas
46
// Contributors: nickg, gthomas
47
// Date:         1999-02-20
48
// Purpose:      Define architecture abstractions
49
// Usage:        #include <cyg/hal/hal_arch.h>
50
 
51
//              
52
//####DESCRIPTIONEND####
53
//
54
//==========================================================================
55
 
56
#include <pkgconf/hal.h>         // To decide on stack usage
57
#include <cyg/infra/cyg_type.h>
58
 
59
#ifdef CYGBLD_HAL_ARM_PLF_ARCH_H
60
#include <cyg/hal/plf_arch.h>
61
#endif
62
 
63
#ifdef CYGBLD_HAL_ARM_VAR_ARCH_H
64
#include <cyg/hal/var_arch.h>
65
#endif
66
 
67
//
68
// CPSR Register defines
69
//
70
 
71
#define CPSR_IRQ_DISABLE        0x80    // IRQ disabled when =1
72
#define CPSR_FIQ_DISABLE        0x40    // FIQ disabled when =1
73
#define CPSR_THUMB_ENABLE       0x20    // Thumb mode when =1
74
#define CPSR_USER_MODE          0x10
75
#define CPSR_FIQ_MODE           0x11
76
#define CPSR_IRQ_MODE           0x12
77
#define CPSR_SUPERVISOR_MODE    0x13
78
#define CPSR_UNDEF_MODE         0x1B
79
 
80
// The following are not supported by every CPU, but if
81
// they are, they have the following values:
82
#define CPSR_ICACHE_ENABLE      0x1000
83
#define CPSR_BIG_ENDIAN         0x80
84
#define CPSR_DCACHE_ENABLE      0x4
85
#define CPSR_ALIGN_FAULT_ENABLE 0x2
86
#define CPSR_MMU_ENABLE         0x1
87
 
88
#define CPSR_MODE_BITS          0x1F
89
 
90
#define CPSR_INITIAL (CPSR_IRQ_DISABLE|CPSR_FIQ_DISABLE|CPSR_SUPERVISOR_MODE)
91
#define CPSR_THREAD_INITIAL (CPSR_SUPERVISOR_MODE)
92
 
93
//
94
// Vector table offsets
95
//
96
 
97
#define HAL_ARM_RESET_VECTOR                    0x00
98
#define HAL_ARM_UNDEFINED_VECTOR                0x04
99
#define HAL_ARM_SWI_VECTOR                      0x08
100
#define HAL_ARM_PREFETCH_VECTOR                 0x0C
101
#define HAL_ARM_ABORT_VECTOR                    0x10
102
#define HAL_ARM_RESERVED_VECTOR                 0x14
103
#define HAL_ARM_IRQ_VECTOR                      0x18
104
#define HAL_ARM_FIQ_VECTOR                      0x1C
105
#define HAL_ARM_RESET_VECTOR_ADDR               0x20
106
#define HAL_ARM_UNDEFINED_VECTOR_ADDR           0x24
107
#define HAL_ARM_SWI_VECTOR_ADDR                 0x28
108
#define HAL_ARM_PREFETCH_VECTOR_ADDR            0x2C
109
#define HAL_ARM_ABORT_VECTOR_ADDR               0x30
110
#define HAL_ARM_RESERVED_VECTOR_ADDR            0x34
111
#define HAL_ARM_IRQ_VECTOR_ADDR                 0x38
112
#define HAL_ARM_FIQ_VECTOR_ADDR                 0x3C
113
 
114
//--------------------------------------------------------------------------
115
// Processor saved states:
116
// The layout of this structure is also defined in "arm.inc", for assembly
117
// code, which will be generated automatically if this file changes.
118
 
119
#define HAL_THREAD_CONTEXT_FIRST        0
120
#define HAL_THREAD_CONTEXT_R0           (0-HAL_THREAD_CONTEXT_FIRST)
121
#define HAL_THREAD_CONTEXT_R4           (4-HAL_THREAD_CONTEXT_FIRST)
122
#define HAL_THREAD_CONTEXT_R8           (8-HAL_THREAD_CONTEXT_FIRST)
123
#define HAL_THREAD_CONTEXT_R9           (9-HAL_THREAD_CONTEXT_FIRST)
124
#define HAL_THREAD_CONTEXT_R10          (10-HAL_THREAD_CONTEXT_FIRST)
125
#define HAL_THREAD_CONTEXT_LAST         10
126
#define HAL_NUM_THREAD_CONTEXT_REGS     (HAL_THREAD_CONTEXT_LAST - \
127
                                          HAL_THREAD_CONTEXT_FIRST+1)
128
 
129
// It seems that r0-r3,r12 are considered scratch by function calls
130
 
131
typedef struct
132
{
133
    // These are common to all saved states
134
    cyg_uint32  d[HAL_NUM_THREAD_CONTEXT_REGS] ;  // Data regs (r0..r10)
135
    cyg_uint32  fp;                               // (r11) Frame pointer
136
    cyg_uint32  ip;                               // (r12)
137
    cyg_uint32  sp;                               // (r13) Stack pointer
138
    cyg_uint32  lr;                               // (r14) Link Reg
139
    cyg_uint32  pc;                               // (r15) PC place holder
140
                                                  //       (never used)
141
    cyg_uint32  cpsr;                             // Condition Reg
142
    // These are only saved for exceptions and interrupts
143
    cyg_uint32  vector;                           // Vector number
144
    cyg_uint32  svc_lr;                           // saved svc mode lr
145
    cyg_uint32  svc_sp;                           // saved svc mode sp
146
 
147
} HAL_SavedRegisters;
148
 
149
//-------------------------------------------------------------------------
150
// Exception handling function.
151
// This function is defined by the kernel according to this prototype. It is
152
// invoked from the HAL to deal with any CPU exceptions that the HAL does
153
// not want to deal with itself. It usually invokes the kernel's exception
154
// delivery mechanism.
155
 
156
externC void cyg_hal_deliver_exception( CYG_WORD code, CYG_ADDRWORD data );
157
 
158
//-------------------------------------------------------------------------
159
// Bit manipulation macros
160
 
161
externC int hal_lsbindex(int);
162
externC int hal_msbindex(int);
163
 
164
#define HAL_LSBIT_INDEX(index, mask) index = hal_lsbindex(mask)
165
#define HAL_MSBIT_INDEX(index, mask) index = hal_msbindex(mask)
166
 
167
//-------------------------------------------------------------------------
168
// Context Initialization
169
// Initialize the context of a thread.
170
// Arguments:
171
// _sparg_ name of variable containing current sp, will be changed to new sp
172
// _thread_ thread object address, passed as argument to entry point
173
// _entry_ entry point address.
174
// _id_ bit pattern used in initializing registers, for debugging.
175
 
176
#define HAL_THREAD_INIT_CONTEXT( _sparg_, _thread_, _entry_, _id_ )         \
177
    CYG_MACRO_START                                                         \
178
    register CYG_WORD _sp_ = ((CYG_WORD)_sparg_) &~15;                      \
179
    register HAL_SavedRegisters *_regs_;                                    \
180
    int _i_;                                                                \
181
    _regs_ = (HAL_SavedRegisters *)((_sp_) - sizeof(HAL_SavedRegisters));   \
182
    for( _i_ = HAL_THREAD_CONTEXT_FIRST; _i_ <= HAL_THREAD_CONTEXT_LAST;    \
183
           _i_++ )                                                          \
184
        (_regs_)->d[_i_] = (_id_)|_i_;                                      \
185
    (_regs_)->d[00] = (CYG_WORD)(_thread_); /* R0 = arg1 = thread ptr */    \
186
    (_regs_)->sp = (CYG_WORD)(_sp_);        /* SP = top of stack      */    \
187
    (_regs_)->lr = (CYG_WORD)(_entry_);     /* LR = entry point       */    \
188
    (_regs_)->pc = (CYG_WORD)(_entry_);     /* PC = [initial] entry point */\
189
    (_regs_)->cpsr = (CPSR_THREAD_INITIAL); /* PSR = Interrupt enabled */   \
190
    _sparg_ = (CYG_ADDRESS)_regs_;                                          \
191
    CYG_MACRO_END
192
 
193
//--------------------------------------------------------------------------
194
// Context switch macros.
195
// The arguments are pointers to locations where the stack pointer
196
// of the current thread is to be stored, and from where the sp of the
197
// next thread is to be fetched.
198
 
199
externC void hal_thread_switch_context( CYG_ADDRESS to, CYG_ADDRESS from );
200
externC void hal_thread_load_context( CYG_ADDRESS to )
201
    __attribute__ ((noreturn));
202
 
203
#define HAL_THREAD_SWITCH_CONTEXT(_fspptr_,_tspptr_)                    \
204
        hal_thread_switch_context((CYG_ADDRESS)_tspptr_,                \
205
                                  (CYG_ADDRESS)_fspptr_);
206
 
207
#define HAL_THREAD_LOAD_CONTEXT(_tspptr_)                               \
208
        hal_thread_load_context( (CYG_ADDRESS)_tspptr_ );
209
 
210
//--------------------------------------------------------------------------
211
// Execution reorder barrier.
212
// When optimizing the compiler can reorder code. In multithreaded systems
213
// where the order of actions is vital, this can sometimes cause problems.
214
// This macro may be inserted into places where reordering should not happen.
215
 
216
#define HAL_REORDER_BARRIER() asm volatile ( "" : : : "memory" )
217
 
218
//--------------------------------------------------------------------------
219
// Breakpoint support
220
// HAL_BREAKPOINT() is a code sequence that will cause a breakpoint to happen
221
// if executed.
222
// HAL_BREAKINST is the value of the breakpoint instruction and 
223
// HAL_BREAKINST_SIZE is its size in bytes.
224
 
225
#define _stringify1(__arg) #__arg
226
#define _stringify(__arg) _stringify1(__arg)
227
 
228
#define HAL_BREAKINST_ARM          0xE7FFDEFE
229
#define HAL_BREAKINST_ARM_SIZE     4
230
#define HAL_BREAKINST_THUMB        0xbebe  // illegal instruction currently
231
#define HAL_BREAKINST_THUMB_SIZE   2
232
 
233
#ifdef __thumb__
234
 
235
# define HAL_BREAKPOINT(_label_)                         \
236
asm volatile (" .code 16;"                               \
237
              " .globl  " #_label_ ";"                   \
238
              #_label_":"                                \
239
              " .short " _stringify(HAL_BREAKINST_THUMB) \
240
    );
241
 
242
# define HAL_BREAKINST           HAL_BREAKINST_THUMB
243
# define HAL_BREAKINST_SIZE      HAL_BREAKINST_THUMB_SIZE
244
# define HAL_BREAKINST_TYPE      cyg_uint16
245
#else // __thumb__
246
 
247
#define HAL_BREAKPOINT(_label_)                   \
248
asm volatile (" .globl  " #_label_ ";"            \
249
              #_label_":"                         \
250
              " .word " _stringify(HAL_BREAKINST_ARM) \
251
    );
252
 
253
//#define HAL_BREAKINST           {0xFE, 0xDE, 0xFF, 0xE7}
254
#define HAL_BREAKINST            HAL_BREAKINST_ARM
255
#define HAL_BREAKINST_SIZE       HAL_BREAKINST_ARM_SIZE
256
#define HAL_BREAKINST_TYPE       cyg_uint32
257
#endif // __thumb__
258
 
259
 
260
extern cyg_uint32 __arm_breakinst;
261
extern cyg_uint16 __thumb_breakinst;
262
#define HAL_BREAKINST_ADDR(x) (((x)==2)? \
263
                              ((void*)&__thumb_breakinst) : \
264
                              ((void*)&__arm_breakinst))
265
 
266
//--------------------------------------------------------------------------
267
// Thread register state manipulation for GDB support.
268
 
269
// Register layout expected by GDB
270
typedef struct
271
{
272
    cyg_uint32  gpr[16];
273
    cyg_uint32  f0[3];
274
    cyg_uint32  f1[3];
275
    cyg_uint32  f2[3];
276
    cyg_uint32  f3[3];
277
    cyg_uint32  f4[3];
278
    cyg_uint32  f5[3];
279
    cyg_uint32  f6[3];
280
    cyg_uint32  f7[3];
281
    cyg_uint32  fps;
282
    cyg_uint32  ps;
283
} GDB_Registers;
284
 
285
// Translate a stack pointer as saved by the thread context macros above into
286
// a pointer to a HAL_SavedRegisters structure.
287
#define HAL_THREAD_GET_SAVED_REGISTERS( _sp_, _regs_ )  \
288
        (_regs_) = (HAL_SavedRegisters *)(_sp_)
289
 
290
// Copy a set of coprocessor registers from a HAL_SavedRegisters structure
291
// into a GDB_Registers structure. GDB expects placeholders for FP regs
292
// even for non-FP targets, so we just zero fill the fields.
293
#define HAL_GET_GDB_COPROCESSOR_REGISTERS( _gdb_, _regs_ )      \
294
    CYG_MACRO_START                                             \
295
    cyg_uint32 *_p_ = _gdb_->f0;                                \
296
    for(_i_ = 0; _i_ < (8 * 3); _i_++)                          \
297
        *_p_++ = 0;                                             \
298
    _gdb_->fps = 0;                                             \
299
    CYG_MACRO_END
300
 
301
// Copy coprocessor registers from a GDB_Registers structure into a
302
// HAL_SavedRegisters structure.
303
#define HAL_SET_GDB_COPROCESSOR_REGISTERS( _regs_, _gdb_ )
304
 
305
// Copy a set of registers from a HAL_SavedRegisters structure into a
306
// GDB_Registers structure.
307
#define HAL_GET_GDB_REGISTERS( _aregval_, _regs_ )              \
308
    CYG_MACRO_START                                             \
309
    GDB_Registers *_gdb_ = (GDB_Registers *)(_aregval_);        \
310
    int _i_;                                                    \
311
                                                                \
312
    for( _i_ = 0; _i_ <= 10; _i_++ )                            \
313
        _gdb_->gpr[_i_] = (_regs_)->d[_i_];                     \
314
                                                                \
315
    _gdb_->gpr[11] = (_regs_)->fp;                              \
316
    _gdb_->gpr[12] = (_regs_)->ip;                              \
317
    _gdb_->gpr[13] = (_regs_)->sp;                              \
318
    _gdb_->gpr[14] = (_regs_)->lr;                              \
319
    _gdb_->gpr[15] = (_regs_)->pc;                              \
320
    _gdb_->ps = (_regs_)->cpsr;                                 \
321
    HAL_GET_GDB_COPROCESSOR_REGISTERS(_gdb_,_regs_);            \
322
    CYG_MACRO_END
323
 
324
// Copy a set of registers from a GDB_Registers structure into a
325
// HAL_SavedRegisters structure.
326
#define HAL_SET_GDB_REGISTERS( _regs_ , _aregval_ )             \
327
    CYG_MACRO_START                                             \
328
    GDB_Registers *_gdb_ = (GDB_Registers *)(_aregval_);        \
329
    int _i_;                                                    \
330
                                                                \
331
    for( _i_ = 0; _i_ <= 10; _i_++ )                            \
332
        (_regs_)->d[_i_] = _gdb_->gpr[_i_];                     \
333
                                                                \
334
    (_regs_)->fp = _gdb_->gpr[11];                              \
335
    (_regs_)->ip = _gdb_->gpr[12];                              \
336
    (_regs_)->sp = _gdb_->gpr[13];                              \
337
    (_regs_)->lr = _gdb_->gpr[14];                              \
338
    (_regs_)->pc = _gdb_->gpr[15];                              \
339
    (_regs_)->cpsr = _gdb_->ps;                                 \
340
    HAL_SET_GDB_COPROCESSOR_REGISTERS(_regs_,_gdb_);            \
341
    CYG_MACRO_END
342
 
343
#if defined(CYGDBG_HAL_DEBUG_GDB_CTRLC_SUPPORT) || defined(CYGDBG_HAL_DEBUG_GDB_BREAK_SUPPORT)
344
#define HAL_GET_PROFILE_INFO( _thepc_, _thesp_ )                \
345
    CYG_MACRO_START                                             \
346
    extern HAL_SavedRegisters *hal_saved_interrupt_state;       \
347
    if ( hal_saved_interrupt_state ) {                          \
348
        (_thepc_) = (char *)(hal_saved_interrupt_state->pc);    \
349
        (_thesp_) = (char *)(hal_saved_interrupt_state->sp);    \
350
    }                                                           \
351
    CYG_MACRO_END
352
#endif
353
 
354
//--------------------------------------------------------------------------
355
// HAL setjmp
356
 
357
#define CYGARC_JMP_BUF_SIZE 16  // Actually 11, but some room left over
358
 
359
typedef cyg_uint32 hal_jmp_buf[CYGARC_JMP_BUF_SIZE];
360
 
361
externC int hal_setjmp(hal_jmp_buf env);
362
externC void hal_longjmp(hal_jmp_buf env, int val);
363
 
364
 
365
//--------------------------------------------------------------------------
366
// Idle thread code.
367
// This macro is called in the idle thread loop, and gives the HAL the
368
// chance to insert code. Typical idle thread behaviour might be to halt the
369
// processor. Here we only supply a default fallback if the variant/platform
370
// doesn't define anything.
371
 
372
#ifndef HAL_IDLE_THREAD_ACTION
373
#define HAL_IDLE_THREAD_ACTION(_count_) CYG_EMPTY_STATEMENT
374
#endif
375
 
376
//---------------------------------------------------------------------------
377
 
378
// Minimal and sensible stack sizes: the intention is that applications
379
// will use these to provide a stack size in the first instance prior to
380
// proper analysis.  Idle thread stack should be this big.
381
 
382
//    THESE ARE NOT INTENDED TO BE MICROMETRICALLY ACCURATE FIGURES.
383
//           THEY ARE HOWEVER ENOUGH TO START PROGRAMMING.
384
// YOU MUST MAKE YOUR STACKS LARGER IF YOU HAVE LARGE "AUTO" VARIABLES!
385
 
386
// This is not a config option because it should not be adjusted except
387
// under "enough rope" sort of disclaimers.
388
 
389
// A minimal, optimized stack frame, rounded up - no autos
390
#define CYGNUM_HAL_STACK_FRAME_SIZE (4 * 20)
391
 
392
// Stack needed for a context switch: this is implicit in the estimate for
393
// interrupts so not explicitly used below:
394
#define CYGNUM_HAL_STACK_CONTEXT_SIZE (4 * 20)
395
 
396
// Interrupt + call to ISR, interrupt_end() and the DSR
397
#define CYGNUM_HAL_STACK_INTERRUPT_SIZE \
398
    ((4 * 20) + 2 * CYGNUM_HAL_STACK_FRAME_SIZE)
399
 
400
// Space for the maximum number of nested interrupts, plus room to call functions
401
#define CYGNUM_HAL_MAX_INTERRUPT_NESTING 4
402
 
403
#define CYGNUM_HAL_STACK_SIZE_MINIMUM \
404
        (CYGNUM_HAL_MAX_INTERRUPT_NESTING * CYGNUM_HAL_STACK_INTERRUPT_SIZE + \
405
         2 * CYGNUM_HAL_STACK_FRAME_SIZE)
406
 
407
#define CYGNUM_HAL_STACK_SIZE_TYPICAL \
408
        (CYGNUM_HAL_STACK_SIZE_MINIMUM + \
409
         16 * CYGNUM_HAL_STACK_FRAME_SIZE)
410
 
411
//--------------------------------------------------------------------------
412
// Macros for switching context between two eCos instances (jump from
413
// code in ROM to code in RAM or vice versa).
414
#define CYGARC_HAL_SAVE_GP()
415
#define CYGARC_HAL_RESTORE_GP()
416
 
417
#endif // CYGONCE_HAL_ARCH_H
418
// 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.