1 | /** |
---|
2 | * @file |
---|
3 | * |
---|
4 | * @brief Initialize Context Area |
---|
5 | * @ingroup ScoreContext |
---|
6 | */ |
---|
7 | |
---|
8 | /* |
---|
9 | * COPYRIGHT (c) 1989-2008. |
---|
10 | * On-Line Applications Research Corporation (OAR). |
---|
11 | * |
---|
12 | * The license and distribution terms for this file may be |
---|
13 | * found in the file LICENSE in this distribution or at |
---|
14 | * http://www.rtems.org/license/LICENSE. |
---|
15 | */ |
---|
16 | |
---|
17 | #ifdef HAVE_CONFIG_H |
---|
18 | #include "config.h" |
---|
19 | #endif |
---|
20 | |
---|
21 | #include <stdint.h> |
---|
22 | #include <rtems/system.h> |
---|
23 | |
---|
24 | typedef struct { |
---|
25 | uint16_t sbLow; |
---|
26 | uint16_t sbHigh; /* push/pop sb */ |
---|
27 | uint16_t flg; /* push/pop flg */ |
---|
28 | uint32_t a1; /* pushm */ |
---|
29 | uint32_t a0; |
---|
30 | uint32_t r0r2; |
---|
31 | uint32_t r1r3; |
---|
32 | uint16_t frameLow; /* exitd */ |
---|
33 | uint16_t frameHigh; |
---|
34 | uint16_t startLow; |
---|
35 | uint16_t startHigh; |
---|
36 | uint16_t zero; |
---|
37 | } Starting_Frame; |
---|
38 | |
---|
39 | #if defined(__r8c_cpu__) |
---|
40 | #warning "_get_sb: not implemented on R8C" |
---|
41 | #define _get_sb( _sb ) |
---|
42 | #else |
---|
43 | #define _get_sb( _sb ) \ |
---|
44 | __asm__ volatile( "stc sb, %0" : "=r" (_sb)) |
---|
45 | #endif |
---|
46 | |
---|
47 | void _CPU_Context_Initialize( |
---|
48 | Context_Control *the_context, |
---|
49 | uint32_t *stack_base, |
---|
50 | size_t size, |
---|
51 | uint32_t new_level, |
---|
52 | void *entry_point, |
---|
53 | bool is_fp, |
---|
54 | void *tls_area |
---|
55 | ) |
---|
56 | { |
---|
57 | void *stackEnd = stack_base; |
---|
58 | register uint32_t sb; |
---|
59 | Starting_Frame *frame; |
---|
60 | |
---|
61 | _get_sb( sb ); |
---|
62 | stackEnd += size; |
---|
63 | |
---|
64 | frame = (Starting_Frame *)stackEnd; |
---|
65 | frame--; |
---|
66 | |
---|
67 | frame->zero = 0; |
---|
68 | frame->sbLow = ((uint32_t)sb) & 0xffff; |
---|
69 | frame->sbHigh = ((uint32_t)sb >> 16) & 0xffff; |
---|
70 | frame->flg = 0x80; /* User stack */ |
---|
71 | if ( !new_level ) /* interrupt level 0 --> enabled */ |
---|
72 | frame->flg |= 0x40; |
---|
73 | frame->a0 = 0x01020304; |
---|
74 | frame->a1 =0xa1a2a3a4; |
---|
75 | frame->r0r2 = 0; |
---|
76 | frame->r1r3 = 0; |
---|
77 | #if defined(__r8c_cpu__) |
---|
78 | #warning "not implemented on R8C" |
---|
79 | #else |
---|
80 | frame->frameLow = (uint16_t) (((uint32_t)frame) & 0xffff); |
---|
81 | frame->frameHigh = (uint16_t) (((uint32_t)frame >> 16) & 0xffff); |
---|
82 | frame->startLow = (uint16_t) (((uint32_t)entry_point) & 0xffff); |
---|
83 | frame->startHigh = (uint16_t) (((uint32_t)entry_point >> 16) & 0xffff); |
---|
84 | #endif |
---|
85 | the_context->sp = (uintptr_t)frame; |
---|
86 | the_context->fb = (uintptr_t)&frame->frameLow; |
---|
87 | } |
---|