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

Subversion Repositories openrisc_me

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

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
 
45
#include <pkgconf/hal.h>
46
#include <cyg/infra/cyg_type.h>
47
 
48
// Include some variant specific architectural defines.
49
#include <cyg/hal/var_arch.h>
50
 
51
#ifdef CYGDBG_HAL_DEBUG_GDB_INCLUDE_STUBS
52
#include <cyg/hal/m68k_stub.h>
53
#endif // CYGDBG_HAL_DEBUG_GDB_INCLUDE_STUBS
54
 
55
#ifndef HAL_NORMAL_SAVED_CONTEXT
56
/*****************************************************************************
57
HAL_NORMAL_SAVED_CONTEXT -- Saved by a normal context switch
58
 
59
     Define  a  generic   structure  to  save   a  thread  context.    Some
60
architecture variants will want to redefine this.
61
 
62
*****************************************************************************/
63
typedef struct
64
{
65
 
66
    //   Data regs D0-D7
67
 
68
    #define HAL_NORMAL_SAVED_NUM_D_REGS 8
69
    CYG_WORD32 d[HAL_NORMAL_SAVED_NUM_D_REGS];
70
 
71
    //   Address regs A0-A6
72
 
73
    #define HAL_NORMAL_SAVED_NUM_A_REGS 7
74
    CYG_ADDRESS a[HAL_NORMAL_SAVED_NUM_A_REGS];
75
 
76
    //   Program Counter
77
 
78
    CYG_ADDRESS pc;
79
 
80
} __attribute__ ((aligned, packed)) HAL_SavedRegisters_normal;
81
#endif // HAL_NORMAL_SAVED_CONTEXT
82
 
83
#ifndef HAL_GENERIC_SAVED_CONTEXT
84
/*****************************************************************************
85
HAL_GENERIC_SAVED_CONTEXT -- Generic saved context structure
86
 
87
     This is  a  generic  structure  that  should  describe  various  saved
88
processor contexts on this platform.
89
 
90
     If the variant HAL does not define this, just define a saved  register
91
structure with a normal context.
92
 
93
*****************************************************************************/
94
#define HAL_GENERIC_SAVED_CONTEXT \
95
typedef union \
96
{ \
97
    HAL_SavedRegisters_normal normal; \
98
} __attribute__ ((aligned, packed)) HAL_SavedRegisters;
99
#endif // HAL_GENERIC_SAVED_CONTEXT
100
HAL_GENERIC_SAVED_CONTEXT;
101
 
102
#ifndef HAL_THREAD_SWITCH_CONTEXT
103
/*****************************************************************************
104
HAL_THREAD_SWITCH_CONTEXT
105
 
106
     This macro saves the state of the currently running thread and  writes
107
its stack pointer to *(_fspptr_).
108
 
109
     It then switches to the thread context that *(_tspptr_) points to.
110
 
111
INPUT:
112
 
113
     _fspptr_: A pointer to the location to save the current thread's stack
114
pointer to.
115
 
116
     _tspptr_: A pointer to  the location containing  the stack pointer  of
117
the thread context to switch to.
118
 
119
OUTPUT:
120
 
121
     *(_fspptr_): Contains the  stack  pointer  of  the  previous  thread's
122
context.
123
 
124
*****************************************************************************/
125
#define HAL_THREAD_SWITCH_CONTEXT(_fspptr_,_tspptr_) \
126
CYG_MACRO_START \
127
    asm volatile (" pea     1f(%%pc)\n" \
128
                  " lea     -(8+7)*4(%%sp),%%sp\n" \
129
                  " movem.l %%d0-%%d7/%%a0-%%a6,(%%sp)\n" \
130
                  " move.l  %%sp,%0\n" \
131
                  " move.l  %1,%%sp\n" \
132
                  " movem.l (%%sp),%%d0-%%d7/%%a0-%%a6\n" \
133
                  " lea     (8+7)*4(%%sp),%%sp\n" \
134
                  " rts\n" \
135
                  "1:\n" \
136
                  : "=g" (*(_fspptr_)) \
137
                  : "g" (*(_tspptr_)) \
138
                  : "memory"); \
139
CYG_MACRO_END
140
#if HAL_NORMAL_SAVED_NUM_D_REGS != 8
141
    #error
142
#endif
143
#if HAL_NORMAL_SAVED_NUM_A_REGS != 7
144
    #error
145
#endif
146
#endif // HAL_THREAD_SWITCH_CONTEXT
147
 
148
#ifndef HAL_THREAD_LOAD_CONTEXT
149
/*****************************************************************************
150
HAL_THREAD_LOAD_CONTEXT
151
 
152
     This macro loads the thread context that *(_tspptr_) points to.
153
 
154
     This macro does not return.
155
 
156
INPUT:
157
 
158
     _tspptr_: A pointer to  the location containing  the stack pointer  of
159
the thread context to switch to.
160
 
161
*****************************************************************************/
162
#define HAL_THREAD_LOAD_CONTEXT(_tspptr_) \
163
CYG_MACRO_START \
164
    asm volatile (" move.l  %0,%%sp\n" \
165
                  " movem.l (%%sp),%%d0-%%d7/%%a0-%%a6\n" \
166
                  " lea     (8+7)*4(%%sp),%%sp\n" \
167
                  " rts\n" \
168
                  : \
169
                  : "g" (*(_tspptr_)) \
170
                  : "memory"); \
171
CYG_MACRO_END
172
#if HAL_NORMAL_SAVED_NUM_D_REGS != 8
173
    #error
174
#endif
175
#if HAL_NORMAL_SAVED_NUM_A_REGS != 7
176
    #error
177
#endif
178
#endif // HAL_THREAD_LOAD_CONTEXT
179
 
180
#ifndef HAL_THREAD_INIT_CONTEXT
181
/*****************************************************************************
182
HAL_THREAD_INIT_CONTEXT -- Context Initialization
183
 
184
     Initialize the context of a thread.
185
 
186
INPUT:
187
 
188
     _sparg_: The name of  the variable  containing the  current sp.   This
189
will be written with the new sp.
190
 
191
     _thread_: The thread object  address,  passed  as  argument  to  entry
192
point.
193
 
194
     _entry_: The thread's entry point address.
195
 
196
     _id_: A bit pattern used in initializing registers, for debugging.
197
 
198
OUTPUT:
199
 
200
     _sparg_: Updated with the value of the new sp.
201
 
202
*****************************************************************************/
203
#define HAL_THREAD_INIT_CONTEXT(_sparg_, _thread_, _entry_, _id_) \
204
    CYG_MACRO_START \
205
    CYG_WORD32 * _sp_ = ((CYG_WORD32*)((CYG_WORD32)(_sparg_) & ~15)); \
206
    HAL_SavedRegisters_normal * _regs_; \
207
    int _i_; \
208
 \
209
    *(--_sp_) = (CYG_WORD32)(_thread_); /* Thread's parameter. */ \
210
    *(--_sp_) = (CYG_WORD32)0xDEADC0DE; /* Thread's return addr. */ \
211
 \
212
    _regs_ = (HAL_SavedRegisters_normal*) \
213
              ((CYG_WORD32)_sp_ - sizeof(HAL_SavedRegisters_normal)); \
214
 \
215
    for (_i_=0; _i_ < HAL_NORMAL_SAVED_NUM_A_REGS; _i_++) \
216
        _regs_->a[_i_] = _regs_->d[_i_] = (_id_); \
217
    _regs_->d[_i_] = (_id_); /* D7 */ \
218
    /* A6, initial frame pointer should be null */ \
219
    _regs_->a[HAL_NORMAL_SAVED_NUM_A_REGS-1] = (CYG_ADDRESS)0; \
220
    /* Thread's starting PC */ \
221
    _regs_->pc = (CYG_ADDRESS)(_entry_); \
222
 \
223
    (_sparg_) = (CYG_ADDRESS)_regs_; \
224
    CYG_MACRO_END
225
#endif // HAL_THREAD_INIT_CONTEXT
226
 
227
//-----------------------------------------------------------------------------
228
// Bit manipulation routines
229
 
230
externC cyg_uint32 hal_lsbit_index(cyg_uint32 mask);
231
externC cyg_uint32 hal_msbit_index(cyg_uint32 mask);
232
 
233
#define HAL_LSBIT_INDEX(index, mask) (index) = hal_lsbit_index(mask);
234
 
235
#define HAL_MSBIT_INDEX(index, mask) (index) = hal_msbit_index(mask);
236
 
237
//-----------------------------------------------------------------------------
238
// Idle thread code.
239
// This macro is called in the idle thread loop, and gives the HAL the
240
// chance to insert code. Typical idle thread behaviour might be to halt the
241
// processor.
242
 
243
externC void hal_idle_thread_action(cyg_uint32 loop_count);
244
 
245
#define HAL_IDLE_THREAD_ACTION(_count_) hal_idle_thread_action(_count_)
246
 
247
//-----------------------------------------------------------------------------
248
// Execution reorder barrier.
249
// When optimizing the compiler can reorder code. In multithreaded systems
250
// where the order of actions is vital, this can sometimes cause problems.
251
// This macro may be inserted into places where reordering should not happen.
252
 
253
#define HAL_REORDER_BARRIER() asm volatile ( "" : : : "memory" )
254
 
255
//-----------------------------------------------------------------------------
256
// Breakpoint support
257
// HAL_BREAKPOINT() is a code sequence that will cause a breakpoint to happen
258
// if executed.
259
// HAL_BREAKINST is the value of the breakpoint instruction and
260
// HAL_BREAKINST_SIZE is its size in bytes.
261
 
262
#define HAL_BREAKPOINT(_label_)                 \
263
asm volatile (" .globl  " #_label_ ";"          \
264
              #_label_":"                       \
265
              " trap #1"                        \
266
    );
267
 
268
#define HAL_BREAKINST           0x4E41
269
 
270
#define HAL_BREAKINST_SIZE      2
271
 
272
#if defined(CYGFUN_HAL_COMMON_KERNEL_SUPPORT) && \
273
      defined(CYGPKG_HAL_EXCEPTIONS)
274
 
275
//-----------------------------------------------------------------------------
276
// Exception handling function.
277
// This function is defined by the kernel according to this prototype. It is
278
// invoked from the HAL to deal with any CPU exceptions that the HAL does
279
// not want to deal with itself. It usually invokes the kernel's exception
280
// delivery mechanism.
281
 
282
externC void cyg_hal_deliver_exception( CYG_WORD code, CYG_ADDRWORD data );
283
 
284
#endif /* defined(CYGFUN_HAL_COMMON_KERNEL_SUPPORT) */
285
 
286
//-----------------------------------------------------------------------------
287
// Minimal and sensible stack sizes: the intention is that applications
288
// will use these to provide a stack size in the first instance prior to
289
// proper analysis.  Idle thread stack should be this big.
290
 
291
//    THESE ARE NOT INTENDED TO BE MICROMETRICALLY ACCURATE FIGURES.
292
//           THEY ARE HOWEVER ENOUGH TO START PROGRAMMING.
293
// YOU MUST MAKE YOUR STACKS LARGER IF YOU HAVE LARGE "AUTO" VARIABLES!
294
 
295
// This is not a config option because it should not be adjusted except
296
// under "enough rope" sort of disclaimers.
297
 
298
//      Stack frame overhead per call.  6 data registers, 5 address registers,
299
// frame pointer, and return address.  We  can't guess the local variables  so
300
// just assume that using all of the registers averages out.
301
 
302
#define CYGNUM_HAL_STACK_FRAME_SIZE ((6 + 5 + 1 + 1) * 4)
303
 
304
// Stack needed for a context switch.
305
//      All registers + pc + sr + vector
306
 
307
#ifndef CYGNUM_HAL_STACK_CONTEXT_SIZE
308
#define CYGNUM_HAL_STACK_CONTEXT_SIZE ((8+8+1+1+1)*4)
309
#endif // CYGNUM_HAL_STACK_CONTEXT_SIZE
310
 
311
// Interrupt + call to ISR, interrupt_end() and the DSR
312
 
313
#define CYGNUM_HAL_STACK_INTERRUPT_SIZE \
314
    ((CYGNUM_HAL_STACK_CONTEXT_SIZE) + (8*CYGNUM_HAL_STACK_FRAME_SIZE))
315
 
316
// We define a minimum stack size as the minimum any thread could ever
317
// legitimately get away with. We can throw asserts if users ask for less
318
// than this. Allow enough for four interrupt sources - clock, serial,
319
// nic, and one other
320
 
321
// No separate interrupt stack exists.  Make sure all threads contain
322
// a stack sufficiently large
323
 
324
#define CYGNUM_HAL_STACK_SIZE_MINIMUM                   \
325
        ((4*CYGNUM_HAL_STACK_INTERRUPT_SIZE)            \
326
         + (16*CYGNUM_HAL_STACK_FRAME_SIZE))
327
 
328
// Now make a reasonable choice for a typical thread size. Pluck figures
329
// from thin air and say 30 call frames with an average of 16 words of
330
// automatic variables per call frame
331
 
332
#define CYGNUM_HAL_STACK_SIZE_TYPICAL                   \
333
        (CYGNUM_HAL_STACK_SIZE_MINIMUM +                \
334
         (30 * (CYGNUM_HAL_STACK_FRAME_SIZE+(16*4))))
335
 
336
//--------------------------------------------------------------------------
337
// Macros for switching context between two eCos instances (jump from
338
// code in ROM to code in RAM or vice versa).
339
#define CYGARC_HAL_SAVE_GP()
340
#define CYGARC_HAL_RESTORE_GP()
341
 
342
#ifndef HAL_SETJMP
343
#define HAL_SETJMP
344
/*****************************************************************************
345
hal_setjmp/hal_longjmp
346
 
347
     We do the best  we can to define  generic setjmp and longjmp  routines
348
for the m68k architecture.  Some architectures will need to override this.
349
 
350
*****************************************************************************/
351
 
352
//      We must save all of  the registers that  are preserved across  routine
353
// calls.  The assembly code assumes  that this  structure is  defined in  the
354
// following format.  Any changes to this structure will result in changes  to
355
// the assembly code!!
356
 
357
typedef struct {
358
    cyg_uint32 d2;
359
    cyg_uint32 d3;
360
    cyg_uint32 d4;
361
    cyg_uint32 d5;
362
    cyg_uint32 d6;
363
    cyg_uint32 d7;
364
    cyg_uint32 a2;
365
    cyg_uint32 a3;
366
    cyg_uint32 a4;
367
    cyg_uint32 a5;
368
    cyg_uint32 a6;
369
    cyg_uint32 sp;
370
    cyg_uint32 pc;
371
} hal_jmp_buf_t;
372
 
373
//      This type is used by normal  routines  to  pass  the  address  of  the
374
// structure into our routines without  having to explicitly take the  address
375
// of the structure.
376
 
377
typedef cyg_uint32 hal_jmp_buf[sizeof(hal_jmp_buf_t) / sizeof(cyg_uint32)];
378
 
379
//      Define the generic setjmp and longjmp routines.
380
 
381
externC int hal_m68k_setjmp(hal_jmp_buf env);
382
externC void hal_m68k_longjmp(hal_jmp_buf env, int val);
383
#define hal_setjmp(_env) hal_m68k_setjmp(_env)
384
#define hal_longjmp(_env, _val) hal_m68k_longjmp(_env, _val)
385
#endif // HAL_SETJMP
386
 
387
//-----------------------------------------------------------------------------
388
#endif // CYGONCE_HAL_ARCH_H
389
// End of hal_arch.h
390
 

powered by: WebSVN 2.1.0

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