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

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [rtos/] [ecos-3.0/] [packages/] [hal/] [sparclite/] [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 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, hmt
46
// Contributors: nickg, gthomas, hmt
47
// Date:         1999-02-20
48
// Purpose:      Define architecture abstractions
49
// Usage:        #include <cyg/hal/hal_arch.h>
50
// 
51
//####DESCRIPTIONEND####
52
//
53
//==========================================================================
54
 
55
#include <pkgconf/hal.h>
56
#include <pkgconf/hal_sparclite.h>
57
 
58
#include <cyg/infra/cyg_type.h>
59
 
60
#include <cyg/hal/hal_intr.h>           // HAL_DISABLE_INTERRUPTS
61
 
62
//--------------------------------------------------------------------------
63
// Processor saved states:
64
//
65
// All these structures must be doubleword (64 bit) aligned.
66
// The code that creates them on the stack will ensure this is so.
67
 
68
#define HAL_THREAD_CONTEXT_GLOBAL_BASE 0
69
#define HAL_THREAD_CONTEXT_OUT_BASE    8
70
#define HAL_THREAD_CONTEXT_LOCAL_BASE 16
71
#define HAL_THREAD_CONTEXT_IN_BASE    24
72
 
73
typedef struct
74
{
75
    // this is the save structure found at *(stack_ptr) always, note that
76
    // i[6] is the frame pointer is the previous stack pointer, and
77
    // o[6] is the stack pointer is the next frame pointer,
78
    // so they form a linked list back up the call stack.
79
    cyg_uint32  l[8];                                   /* Locals r16-r23 */
80
    cyg_uint32  i[8];                                   /* Ins    r24-r31 */
81
} HAL_SavedWindow;
82
 
83
typedef struct
84
{
85
    // Window save at stack pointer
86
    HAL_SavedWindow li;
87
//16
88
    // This is the rest of the save state:
89
    //   NOTE: g[0] is used for the CWP, for %g0 == 0.  Also note that the
90
    //   assembler routines must load/store it in the right order.
91
    cyg_uint32  g[8] ;                                  /* Globals r0- r7 */
92
    cyg_uint32  o[8] ;                                  /* Outs    r8-r15 */
93
//32 words in size
94
 
95
// There is no need to save any other state; for example, condition codes,
96
// the PC and NextPC, and Y, are preserved in local registers in the trap
97
// handling window and so preserved in the caller stack frame as viewed
98
// from an ISR.  Note that the VSR is jumped to with those locals being set
99
// up (and Y in situ), and it must preserve them itself before calling any
100
// subsequent handlers (ISRs).
101
 
102
} HAL_SavedRegisters;
103
 
104
 
105
typedef struct
106
{
107
    // Window save at stack pointer
108
    HAL_SavedWindow li;
109
    cyg_uint32      composite_return_ptr;          /* structure returns */
110
    cyg_uint32      spill_args[6];                 /* for callee to store */
111
    cyg_uint32      spare;                         /* keep this 64-bits   */
112
} HAL_FrameStructure;
113
 
114
 
115
//--------------------------------------------------------------------------
116
// Exception handling function.
117
// This function is defined by the kernel according to this prototype. It is
118
// invoked from the HAL to deal with any CPU exceptions that the HAL does
119
// not want to deal with itself. It usually invokes the kernel's exception
120
// delivery mechanism.
121
 
122
externC void cyg_hal_deliver_exception( CYG_WORD code, CYG_ADDRWORD data );
123
 
124
//--------------------------------------------------------------------------
125
// Bit manipulation macros
126
 
127
#define HAL_LSBIT_INDEX(index, mask)            \
128
    CYG_MACRO_START                             \
129
    asm volatile (                              \
130
        "scan   %1, 0, %%l7;"                   \
131
        "mov    31, %0;"                        \
132
        "sub    %0, %%l7, %0"                   \
133
        : "=r"(index)                           \
134
        : "r"(mask & ~(mask-1))                 \
135
        : "l7"                                  \
136
        );                                      \
137
CYG_MACRO_END
138
 
139
#define HAL_MSBIT_INDEX(index, mask)            \
140
    CYG_MACRO_START                             \
141
    asm volatile (                              \
142
        "scan   %1, 0, %%l7;"                   \
143
        "mov    31, %0;"                        \
144
        "sub    %0, %%l7, %0"                   \
145
        : "=r"(index)                           \
146
        : "r"(mask)                             \
147
        : "l7"                                  \
148
        );                                      \
149
CYG_MACRO_END
150
 
151
 
152
//--------------------------------------------------------------------------
153
// Context Initialization
154
// Initialize the context of a thread.
155
// Arguments:
156
// _sparg_ name of variable containing current sp, will be written with new sp
157
// _thread_ thread object address, passed as argument to entry point
158
// _entry_ entry point address.
159
// _id_ bit pattern used in initializing registers, for debugging.
160
 
161
externC CYG_ADDRESS
162
hal_thread_init_context(  CYG_WORD sparg,
163
                          CYG_WORD thread,
164
                          CYG_WORD entry,
165
                          CYG_WORD id );
166
 
167
#define HAL_THREAD_INIT_CONTEXT( _sparg_, _thread_, _entry_, _id_ )         \
168
CYG_MACRO_START                                                             \
169
    _sparg_ = hal_thread_init_context( (CYG_WORD)(_sparg_),                 \
170
                                       (CYG_WORD)(_thread_),                \
171
                                       (CYG_WORD)(_entry_),                 \
172
                                       (CYG_WORD)(_id_) );                  \
173
CYG_MACRO_END
174
 
175
//---------------------------------------------------------------------------
176
// Context switch macros.
177
// The arguments are pointers to locations where the stack pointer
178
// of the current thread is to be stored, and from where the sp of the
179
// next thread is to be fetched.
180
 
181
externC void hal_thread_switch_context( CYG_ADDRESS to, CYG_ADDRESS from );
182
externC void hal_thread_load_context( CYG_ADDRESS to )
183
    __attribute__ ((noreturn));
184
 
185
#define HAL_THREAD_SWITCH_CONTEXT(_fspptr_,_tspptr_)                    \
186
        hal_thread_switch_context((CYG_ADDRESS)_tspptr_,                \
187
                                  (CYG_ADDRESS)_fspptr_);
188
 
189
#define HAL_THREAD_LOAD_CONTEXT(_tspptr_)                               \
190
        hal_thread_load_context( (CYG_ADDRESS)_tspptr_ );
191
 
192
 
193
//---------------------------------------------------------------------------
194
// Execution reorder barrier.
195
// When optimizing the compiler can reorder code. In multithreaded systems
196
// where the order of actions is vital, this can sometimes cause problems.
197
// This macro may be inserted into places where reordering should not happen.
198
 
199
#define HAL_REORDER_BARRIER() asm volatile ( "" : : : "memory" )
200
 
201
//---------------------------------------------------------------------------
202
// Breakpoint support
203
// HAL_BREAKPOINT() is a code sequence that will cause a breakpoint to happen
204
// if executed.
205
// HAL_BREAKINST is the value of the breakpoint instruction and 
206
// HAL_BREAKINST_SIZE is its size in bytes.
207
 
208
#define HAL_BREAKPOINT(_label_)                \
209
asm volatile (" .globl  " #_label_ ";"         \
210
              #_label_":"                      \
211
              "ta 1"                           \
212
    );
213
 
214
#define HAL_BREAKINST           {0x91,0xd0,0x20,0x01}
215
#define HAL_BREAKINST_SIZE      4
216
 
217
//---------------------------------------------------------------------------
218
// Thread register state manipulation for GDB support.
219
 
220
// Translate a stack pointer as saved by the thread context macros above into
221
// a pointer to a HAL_SavedRegisters structure.
222
#define HAL_THREAD_GET_SAVED_REGISTERS( _sp_, _regs_ )  \
223
        (_regs_) = (HAL_SavedRegisters *)(_sp_)
224
 
225
// Routines in icontext.c used here because they're quite large for
226
// the SPARClite (note param order):
227
externC void
228
cyg_hal_sparc_get_gdb_regs( void *gdb_regset,
229
                            HAL_SavedRegisters *eCos_regset );
230
 
231
externC void
232
cyg_hal_sparc_set_gdb_regs( HAL_SavedRegisters *eCos_regset,
233
                            void *gdb_regset );
234
 
235
 
236
// Copy a set of registers from a HAL_SavedRegisters structure into a GDB
237
// ordered array.
238
#define HAL_GET_GDB_REGISTERS( _aregval_, _regs_ )              \
239
    CYG_MACRO_START                                             \
240
        cyg_hal_sparc_get_gdb_regs( (_aregval_), (_regs_) );    \
241
CYG_MACRO_END
242
 
243
// Copy a GDB ordered array into a HAL_SavedRegisters structure.
244
#define HAL_SET_GDB_REGISTERS( _regs_ , _aregval_ )             \
245
    CYG_MACRO_START                                             \
246
        cyg_hal_sparc_set_gdb_regs( (_regs_), (_aregval_) );    \
247
CYG_MACRO_END
248
 
249
//---------------------------------------------------------------------------
250
// HAL setjmp
251
 
252
#define CYGARC_JMP_BUF_SIZE 32 // (words)
253
 
254
// this too must be doubleword aligned (64 bit)
255
 
256
typedef cyg_uint64 hal_jmp_buf[ CYGARC_JMP_BUF_SIZE / 2 ];
257
 
258
externC int hal_setjmp(hal_jmp_buf env);
259
externC void hal_longjmp(hal_jmp_buf env, int val);
260
 
261
//---------------------------------------------------------------------------
262
// Flush Register Windows
263
//
264
// This is implemented as trap 3 in some SPARC systems.
265
// This macro is only for use from normal, foreground code.
266
// (including exception handlers and the like)
267
 
268
#define HAL_FLUSH_REGISTERS_TO_STACK()                                      \
269
    CYG_MACRO_START                                                         \
270
    cyg_uint32 _saveintr_;                                                  \
271
    HAL_DISABLE_INTERRUPTS( _saveintr_ ); /* leave traps on */              \
272
    asm volatile (                                                          \
273
        /* force out all our callers register sets onto the stack        */ \
274
        /* if necessary: the system will handily take care of this for   */ \
275
        /* us as follows:                                                */ \
276
        "save   %%sp, -16 * 4, %%sp;"   /* need all these to preserve    */ \
277
        "save   %%sp, -16 * 4, %%sp;"   /* the linked list property...   */ \
278
        "save   %%sp, -16 * 4, %%sp;"                                       \
279
        "save   %%sp, -16 * 4, %%sp;"                                       \
280
        "save   %%sp, -16 * 4, %%sp;"                                       \
281
        "save   %%sp, -16 * 4, %%sp;"                                       \
282
        "restore;"                                                          \
283
        "restore;"                                                          \
284
        "restore;"                                                          \
285
        "restore;"                                                          \
286
        "restore;"                                                          \
287
        "restore"                                                           \
288
        /* six of these is correct; a seventh would force out the        */ \
289
        /* current set that we are using right now.  Note that minimal   */ \
290
        /* space is allowed on stack for locals and ins in case this     */ \
291
        /* sequence itself gets interrupted and recurses too deep.       */ \
292
        :                                                                   \
293
        :                                                                   \
294
        : "memory"                                                          \
295
        );                                                                  \
296
    HAL_RESTORE_INTERRUPTS( _saveintr_ );                                   \
297
CYG_MACRO_END
298
 
299
//---------------------------------------------------------------------------
300
// Idle thread code.
301
// This macro is called in the idle thread loop, and gives the HAL the
302
// chance to insert code. Typical idle thread behaviour might be to halt the
303
// processor.
304
 
305
//externC void hal_idle_thread_action(cyg_uint32 loop_count);
306
 
307
#ifndef HAL_IDLE_THREAD_ACTION
308
#define HAL_IDLE_THREAD_ACTION(_count_) \
309
      /* Cyg_Clock::real_time_clock->tick() */
310
#endif
311
 
312
//---------------------------------------------------------------------------
313
 
314
// Minimal and sensible stack sizes: the intention is that applications
315
// will use these to provide a stack size in the first instance prior to
316
// proper analysis.  Idle thread stack should be this big.
317
 
318
//    THESE ARE NOT INTENDED TO BE MICROMETRICALLY ACCURATE FIGURES.
319
//           THEY ARE HOWEVER ENOUGH TO START PROGRAMMING.
320
// YOU MUST MAKE YOUR STACKS LARGER IF YOU HAVE LARGE "AUTO" VARIABLES!
321
 
322
// We define quite large stack needs for SPARClite, for it requires 576
323
// bytes (144 words) to process an interrupt and thread-switch, and
324
// momentarily, but needed in case of recursive interrupts, it needs 208
325
// words - if a sequence of saves to push out other regsets is interrupted.
326
 
327
// This is not a config option because it should not be adjusted except
328
// under "enough rope" sort of disclaimers.
329
 
330
// A minimal, optimized stack frame is 24 words, but even -O2 code seems to
331
// place a few locals in the locals area: round this up to provide a
332
// sensible overestimate:
333
#define CYGNUM_HAL_STACK_FRAME_SIZE (4 * 32)
334
 
335
// Stack needed for a context switch: this is implicit in the estimate for
336
// interrupts so not explicitly used below:
337
#define CYGNUM_HAL_STACK_CONTEXT_SIZE (4 * 32)
338
 
339
// Interrupt + call to ISR, interrupt_end() and the DSR
340
#define CYGNUM_HAL_STACK_INTERRUPT_SIZE \
341
    ((208 * 4) + 2 * CYGNUM_HAL_STACK_FRAME_SIZE)
342
 
343
// And we have lots of registers so no particular amount is added in for
344
// typical local variable usage.
345
 
346
// Typically we have 4 nestable interrupt sources, clock, serialin,
347
// serialout, (and NMI button, but you want it to not destroy context):
348
 
349
#define CYGNUM_HAL_STACK_SIZE_MINIMUM \
350
        (4 * CYGNUM_HAL_STACK_INTERRUPT_SIZE + 2 * CYGNUM_HAL_STACK_FRAME_SIZE)
351
 
352
#define CYGNUM_HAL_STACK_SIZE_TYPICAL \
353
        (CYGNUM_HAL_STACK_SIZE_MINIMUM + 8 * CYGNUM_HAL_STACK_FRAME_SIZE)
354
 
355
//--------------------------------------------------------------------------
356
// Macros for switching context between two eCos instances (jump from
357
// code in ROM to code in RAM or vice versa).
358
#define CYGARC_HAL_SAVE_GP()
359
#define CYGARC_HAL_RESTORE_GP()
360
 
361
//-----------------------------------------------------------------------------
362
 
363
#endif // CYGONCE_HAL_ARCH_H
364
// 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.