1 | /* |
---|
2 | * PowerPC CPU Dependent Source |
---|
3 | */ |
---|
4 | |
---|
5 | /* |
---|
6 | * Author: Andrew Bray <andy@i-cubed.co.uk> |
---|
7 | * |
---|
8 | * COPYRIGHT (c) 1995 by i-cubed ltd. |
---|
9 | * |
---|
10 | * To anyone who acknowledges that this file is provided "AS IS" |
---|
11 | * without any express or implied warranty: |
---|
12 | * permission to use, copy, modify, and distribute this file |
---|
13 | * for any purpose is hereby granted without fee, provided that |
---|
14 | * the above copyright notice and this notice appears in all |
---|
15 | * copies, and that the name of i-cubed limited not be used in |
---|
16 | * advertising or publicity pertaining to distribution of the |
---|
17 | * software without specific, written prior permission. |
---|
18 | * i-cubed limited makes no representations about the suitability |
---|
19 | * of this software for any purpose. |
---|
20 | * |
---|
21 | * Derived from c/src/exec/cpu/no_cpu/cpu.c: |
---|
22 | * |
---|
23 | * COPYRIGHT (c) 1989-1997. |
---|
24 | * On-Line Applications Research Corporation (OAR). |
---|
25 | * |
---|
26 | * The license and distribution terms for this file may be found in |
---|
27 | * the file LICENSE in this distribution or at |
---|
28 | * http://www.rtems.org/license/LICENSE. |
---|
29 | */ |
---|
30 | |
---|
31 | #include <string.h> |
---|
32 | |
---|
33 | #include <rtems/system.h> |
---|
34 | #include <rtems/score/isr.h> |
---|
35 | #include <rtems/score/context.h> |
---|
36 | #include <rtems/score/thread.h> |
---|
37 | #include <rtems/score/interr.h> |
---|
38 | #include <rtems/score/cpu.h> |
---|
39 | #include <rtems/score/tls.h> |
---|
40 | #include <rtems/powerpc/powerpc.h> |
---|
41 | |
---|
42 | /* _CPU_Initialize |
---|
43 | * |
---|
44 | * This routine performs processor dependent initialization. |
---|
45 | */ |
---|
46 | void _CPU_Initialize(void) |
---|
47 | { |
---|
48 | #if defined(__ALTIVEC__) && !defined(PPC_MULTILIB_ALTIVEC) |
---|
49 | _CPU_Initialize_altivec(); |
---|
50 | #endif |
---|
51 | } |
---|
52 | |
---|
53 | /* |
---|
54 | * _CPU_Context_Initialize |
---|
55 | */ |
---|
56 | void _CPU_Context_Initialize( |
---|
57 | Context_Control *the_context, |
---|
58 | uint32_t *stack_base, |
---|
59 | uint32_t size, |
---|
60 | uint32_t new_level, |
---|
61 | void *entry_point, |
---|
62 | bool is_fp, |
---|
63 | void *tls_area |
---|
64 | ) |
---|
65 | { |
---|
66 | ppc_context *the_ppc_context; |
---|
67 | uint32_t msr_value; |
---|
68 | uint32_t sp; |
---|
69 | |
---|
70 | sp = (uint32_t)stack_base + size - PPC_MINIMUM_STACK_FRAME_SIZE; |
---|
71 | |
---|
72 | sp &= ~(CPU_STACK_ALIGNMENT-1); |
---|
73 | |
---|
74 | *((uint32_t*)sp) = 0; |
---|
75 | |
---|
76 | _CPU_MSR_GET( msr_value ); |
---|
77 | |
---|
78 | the_ppc_context = ppc_get_context( the_context ); |
---|
79 | |
---|
80 | /* |
---|
81 | * Setting the interrupt mask here is not strictly necessary |
---|
82 | * since the IRQ level will be established from _Thread_Handler() |
---|
83 | * again, as soon as the task starts execution. |
---|
84 | * Because we have to establish a defined state anyways we |
---|
85 | * can as well leave this code here. |
---|
86 | * I.e., simply (and unconditionally) saying |
---|
87 | * |
---|
88 | * msr_value &= ~ppc_interrupt_get_disable_mask(); |
---|
89 | * |
---|
90 | * would be an alternative. |
---|
91 | */ |
---|
92 | |
---|
93 | if (!(new_level & CPU_MODES_INTERRUPT_MASK)) { |
---|
94 | msr_value |= ppc_interrupt_get_disable_mask(); |
---|
95 | } |
---|
96 | else { |
---|
97 | msr_value &= ~ppc_interrupt_get_disable_mask(); |
---|
98 | } |
---|
99 | |
---|
100 | #ifdef PPC_MULTILIB_FPU |
---|
101 | /* |
---|
102 | * The FP bit of the MSR should only be enabled if this is a floating |
---|
103 | * point task. Unfortunately, the vfprintf_r routine in newlib |
---|
104 | * ends up pushing a floating point register regardless of whether or |
---|
105 | * not a floating point number is being printed. Serious restructuring |
---|
106 | * of vfprintf.c will be required to avoid this behavior. At this |
---|
107 | * time (7 July 1997), this restructuring is not being done. |
---|
108 | */ |
---|
109 | msr_value |= MSR_FP; |
---|
110 | #endif |
---|
111 | |
---|
112 | #ifdef PPC_MULTILIB_ALTIVEC |
---|
113 | msr_value |= MSR_VE; |
---|
114 | |
---|
115 | the_ppc_context->vrsave = 0; |
---|
116 | #endif |
---|
117 | |
---|
118 | the_ppc_context->gpr1 = sp; |
---|
119 | the_ppc_context->msr = msr_value; |
---|
120 | the_ppc_context->lr = (uint32_t) entry_point; |
---|
121 | the_ppc_context->isr_dispatch_disable = 0; |
---|
122 | |
---|
123 | #if defined(__ALTIVEC__) && !defined(PPC_MULTILIB_ALTIVEC) |
---|
124 | _CPU_Context_initialize_altivec( the_ppc_context ); |
---|
125 | #endif |
---|
126 | |
---|
127 | if ( tls_area != NULL ) { |
---|
128 | void *tls_block = _TLS_TCB_before_TLS_block_initialize( tls_area ); |
---|
129 | |
---|
130 | the_ppc_context->gpr2 = (uint32_t) tls_block + 0x7000; |
---|
131 | } else { |
---|
132 | register uint32_t gpr2 __asm__("2"); |
---|
133 | |
---|
134 | the_ppc_context->gpr2 = gpr2; |
---|
135 | } |
---|
136 | } |
---|