2 Copyright © 2013-2015, The AROS Development Team. All rights reserved.
8 #include <aros/kernel.h>
9 #include <aros/symbolsets.h>
11 #include <aros/arm/cpucontext.h>
15 #include <exec/memory.h>
16 #include <exec/memheaderext.h>
17 #include <exec/tasks.h>
18 #include <exec/alerts.h>
19 #include <exec/execbase.h>
21 #include <proto/kernel.h>
22 #include <proto/exec.h>
25 #include "exec_intern.h"
30 #include "kernel_intern.h"
31 #include "kernel_debug.h"
32 #include "kernel_romtags.h"
34 #include "exec_platform.h"
36 extern struct TagItem
*BootMsg
;
38 void __attribute__((used
)) kernel_cstart(struct TagItem
*msg
);
40 uint32_t stack
[AROS_STACKSIZE
] __attribute__((used
,aligned(16)));
41 static uint32_t stack_super
[AROS_STACKSIZE
] __attribute__((used
,aligned(16)));
43 static uint32_t stack_fiq
[1024] __attribute__((used
,aligned(16)));
46 ".section .aros.init,\"ax\"\n\t"
48 ".type start,%function\n"
53 " cps #0x1f \n" /* system mode */
54 " ldr sp, stack_end \n"
55 " cps #0x11 \n" /* fiq mode */
56 " ldr sp, stack_fiq_end \n"
57 " cps #0x13 \n" /* SVC (supervisor) mode */
58 " ldr sp, stack_super_end \n"
61 ".string \"Native/CORE v3 (" __DATE__
")\"" "\n\t\n\t"
64 static uint32_t * const stack_end
__attribute__((used
, section(".aros.init"))) = &stack
[AROS_STACKSIZE
- sizeof(IPTR
)];
65 static uint32_t * const stack_super_end
__attribute__((used
, section(".aros.init"))) = &stack_super
[AROS_STACKSIZE
- sizeof(IPTR
)];
66 static uint32_t * const stack_fiq_end
__attribute__((used
, section(".aros.init"))) = &stack_fiq
[1024 - sizeof(IPTR
)];
69 struct ARM_Implementation __arm_arosintern
__attribute__((aligned(4), section(".data"))) = {0,0,NULL
,NULL
};
70 struct ExecBase
*SysBase
__attribute__((section(".data"))) = NULL
;
72 static void __attribute__((used
)) __clear_bss(struct TagItem
*msg
)
74 struct KernelBSS
*bss
= (struct KernelBSS
*)krnGetTagData(KRN_KernelBss
, 0, msg
);
75 register unsigned int dest
;
80 while (bss
->addr
&& bss
->len
)
82 dest
= (unsigned int)bss
->addr
;
85 // If the start address is unaligned, fill in the first 1-3 bytes until it is
86 while((dest
& 3) && length
)
88 *((unsigned char *)dest
) = 0;
93 // Fill in the remaining 32-bit word-aligned memory locations
94 while(length
& 0xfffffffc)
96 *((unsigned int *)dest
) = 0;
101 // Deal with the remaining 1-3 bytes, if any
106 *((unsigned char *)dest
) = 0;
113 void __attribute__((used
)) kernel_cstart(struct TagItem
*msg
)
116 struct MinList memList
;
117 struct MemHeader
*mh
;
119 long unsigned int memlower
= 0, memupper
= 0, protlower
= 0, protupper
= 0;
120 char *cmdline
= NULL
;
124 // Probe the ARM core
125 cpu_Probe(&__arm_arosintern
);
127 // Probe the ARM Implementation/Platform
128 __arm_arosintern
.ARMI_Platform
= 0;
129 while(msg
->ti_Tag
!= TAG_DONE
)
134 __arm_arosintern
.ARMI_Platform
= msg
->ti_Data
;
141 platform_Init(&__arm_arosintern
, msg
);
143 if (__arm_arosintern
.ARMI_LED_Toggle
)
145 if (__arm_arosintern
.ARMI_Delay
)
146 __arm_arosintern
.ARMI_Delay(100000);
147 __arm_arosintern
.ARMI_LED_Toggle(ARM_LED_POWER
, ARM_LED_OFF
);
150 cpu_Init(&__arm_arosintern
, msg
);
152 if (__arm_arosintern
.ARMI_LED_Toggle
)
154 if (__arm_arosintern
.ARMI_Delay
)
155 __arm_arosintern
.ARMI_Delay(100000);
156 __arm_arosintern
.ARMI_LED_Toggle(ARM_LED_POWER
, ARM_LED_ON
);
159 /* NB: the bootstrap has conveniently setup the framebuffer
160 and initialised the serial port and led for us */
162 while(msg
->ti_Tag
!= TAG_DONE
)
167 // RelocateStringData(tag);
168 cmdline
= (char *)msg
->ti_Data
;
171 memlower
= msg
->ti_Data
;
174 memupper
= msg
->ti_Data
;
176 case KRN_ProtAreaStart
:
177 protlower
= msg
->ti_Data
;
179 case KRN_ProtAreaEnd
:
181 protupper
= (msg
->ti_Data
+ 4095) & ~4095;
185 * KRN_KernelBase is actually a border between read-only
186 * (code) and read-write (data) sections of the kickstart.
187 * read-write section goes to lower addresses from this one,
188 * so we align it upwards in order not to make part of RW data
191 // addr = AROS_ROUNDUP2(msg->ti_Data, PAGE_SIZE);
198 __tls
= (void *)protupper
;
199 protupper
+= (sizeof(tls_t
) + 4095) & ~4095;
201 __tls
->KernelBase
= NULL
;
202 __tls
->SysBase
= NULL
;
203 __tls
->ThisTask
= NULL
;
205 D(bug("[Kernel] AROS ARM Native Kernel built on %s\n", __DATE__
));
207 D(bug("[Kernel] Entered kernel_cstart @ 0x%p, BootMsg @ 0x%p\n", kernel_cstart
, BootMsg
));
209 asm volatile("mcr p15, 0, %0, c13, c0, 3" : : "r"(__tls
));
212 if (__arm_arosintern
.ARMI_PutChar
)
214 bug("[Kernel] Using PutChar implementation @ %p\n", __arm_arosintern
.ARMI_PutChar
);
216 bug("[Kernel] Boot CPU TLS @ 0x%p\n", __tls
);
221 if (__arm_arosintern
.ARMI_LED_Toggle
)
222 __arm_arosintern
.ARMI_LED_Toggle(ARM_LED_POWER
, ARM_LED_OFF
);
224 D(bug("[Kernel] Platform initialised\n"));
226 if (__arm_arosintern
.ARMI_Delay
)
227 __arm_arosintern
.ARMI_Delay(1500);
229 if (__arm_arosintern
.ARMI_LED_Toggle
)
230 __arm_arosintern
.ARMI_LED_Toggle(ARM_LED_POWER
, ARM_LED_ON
);
232 D(bug("[Kernel] Preparing memory 0x%p -> 0x%p\n", memlower
, memupper
));
233 D(bug("[Kernel] - protected area 0x%p -> 0x%p)\n", protlower
, protupper
));
237 if (memlower
>= protlower
)
238 memlower
= protupper
;
240 mh
= (struct MemHeader
*)memlower
;
242 if (cmdline
&& strstr(cmdline
, "notlsf"))
245 krnCreateMemHeader("System Memory", 0, mh
, (memupper
- memlower
), MEMF_FAST
| MEMF_PUBLIC
| MEMF_KICK
| MEMF_LOCAL
);
247 if (memlower
< protlower
)
249 // AllocAbs(protupper-protlower, (void *)protlower);
255 /* Initialize TLSF memory allocator */
256 krnCreateTLSFMemHeader("System Memory", 0, mh
, (memupper
- memlower
), MEMF_FAST
| MEMF_PUBLIC
| MEMF_KICK
| MEMF_LOCAL
);
257 if (memlower
< protlower
)
259 /* Protect the bootstrap area from further use. AllocAbs will do the trick */
260 ((struct MemHeaderExt
*)mh
)->mhe_AllocAbs((struct MemHeaderExt
*)mh
, protupper
-protlower
, (void *)protlower
);
264 ranges
[0] = (UWORD
*)krnGetTagData(KRN_KernelLowest
, 0, msg
);
265 ranges
[1] = (UWORD
*)krnGetTagData(KRN_KernelHighest
, 0, msg
);
266 ranges
[2] = (UWORD
*)-1;
268 D(bug("[Kernel] Preparing ExecBase (memheader @ 0x%p)\n", mh
));
269 krnPrepareExecBase(ranges
, mh
, BootMsg
);
271 __tls
->SysBase
= SysBase
;
272 D(bug("[Kernel] SysBase @ 0x%p\n", SysBase
));
275 * Make kickstart code area read-only.
276 * We do it only after ExecBase creation because SysBase pointer is put
277 * into .rodata. This way we prevent it from ocassional modification by buggy software.
279 // core_ProtKernelArea(addr, kick_highest - addr, 1, 0, 1);
281 D(bug("[Kernel] InitCode(RTF_SINGLETASK) ... \n"));
282 InitCode(RTF_SINGLETASK
, 0);
284 D(bug("[Kernel] Dropping into USER mode ... \n"));
285 asm("cps %[mode_user]\n" : : [mode_user
] "I" (CPUMODE_USER
)); /* switch to user mode */
287 D(bug("[Kernel] InitCode(RTF_COLDSTART) ...\n"));
288 InitCode(RTF_COLDSTART
, 0);
290 /* The above should not return */
291 krnPanic(KernelBase
, "System Boot Failed!");
294 DEFINESET(ARMPLATFORMS
);