Removed extraneous code from ACTION_FORMAT that prevented unformatted
[AROS.git] / arch / arm-sun4i / kernel / kernel_startup.c
bloba793d24a325dc2efd7814be113b1094ead1f89fc
1 /*
2 Copyright © 2014, The AROS Development Team. All rights reserved.
3 $Id$
5 Desc:
6 Lang: english
7 */
9 #include <utility/tagitem.h>
10 #include <proto/arossupport.h>
11 #include <strings.h>
12 #include <inttypes.h>
14 #include <string.h>
16 #include <aros/arm/cpucontext.h>
17 #include <aros/arm/cpu.h>
19 #include <kernel_base.h>
20 #include <kernel_debug.h>
22 #include <hardware/sun4i/platform.h>
24 #define D(x) x
26 #define _STR(x) #x
27 #define STR(x) _STR(x)
29 #define SYS_STACK_SIZE (16384)
31 extern void start();
33 asm(" .section .aros.init,\"ax\" \n"
34 " .globl start \n"
35 " .type start,%function \n"
36 " \n"
38 Allocate enough stack space at bootstrap to last a life time
39 Divide the stack evenly for each system mode (aligned to 4kb)
40 Swap physical stack pointers to virtual address range
41 Protect each stack with two level MMU according to system mode (when and if possible)
42 - Atleast some of the stacks are then protected
44 "start: \n"
45 " cps #"STR(CPUMODE_SYSTEM)" \n" // Enter System mode
46 " ldr sp, sys_stack_end \n" // Load system mode stack
47 " cps #"STR(CPUMODE_IRQ)" \n"
48 " ldr sp, irq_stack_end \n"
49 " cps #"STR(CPUMODE_ABORT)" \n"
50 " ldr sp, abt_stack_end \n"
51 " cps #"STR(CPUMODE_SUPERVISOR)" \n"
52 " ldr sp, svc_stack_end \n"
53 " ldr pc, 2f \n" // jump to the kernel
54 " b . \n" // we never return from here
55 "2: .word startup \n"
56 "tmp_stack_end: .word temporary + " STR(127*4)" \n"
57 "sys_stack_end: .word sys_stack + " STR((SYS_STACK_SIZE - 4))" \n"
58 "svc_stack_end: .word svc_stack + " STR((SYS_STACK_SIZE - 4))" \n"
59 "irq_stack_end: .word irq_stack + " STR((SYS_STACK_SIZE - 4))" \n"
60 "abt_stack_end: .word abt_stack + " STR((SYS_STACK_SIZE - 4))" \n"
63 static uintptr_t early_mmu __attribute__((used, section(".data"))) = 0;
66 * Temporary stack for very early init. It's used only during clearing of
67 * .bss sections in all modules. Rest of this space is occupied by TagItem
68 * boot message. prepared by the bootstrap.
70 static union {
71 uint32_t stack[128];
72 struct TagItem tags[64];
73 } temporary __attribute__((aligned(32),used,section(".data")));
75 static uint8_t sys_stack[SYS_STACK_SIZE] __attribute__((used,aligned(16)));
76 static uint8_t svc_stack[SYS_STACK_SIZE] __attribute__((used,aligned(16)));
77 static uint8_t abt_stack[SYS_STACK_SIZE] __attribute__((used,aligned(16)));
78 static uint8_t irq_stack[SYS_STACK_SIZE] __attribute__((used,aligned(16)));
80 static char CmdLine[200] __attribute__((used, section(".data")));
82 __attribute__((section(".data"))) struct ExecBase *SysBase = NULL;
84 struct TagItem *BootMsg;
86 static void __used __attribute__((section(".aros.init"))) clear_bss(struct TagItem *msg) {
87 struct TagItem *tag = LibFindTagItem(KRN_KernelBss, msg);
89 if (tag) {
90 struct KernelBSS *bss = (struct KernelBSS *)tag->ti_Data;
92 if (bss) {
93 __clear_bss(bss);
98 void startup(struct TagItem *tags) {
99 bug("\n[KRN] AROS for sun4i (" SUN4I_PLATFORM_NAME ") built on %s starting...\n", __DATE__);
100 bug("[KRN] BootMsg @ %08x\n", tags);
101 bug("[KRN] Kernel entry @ %08x\n", start);
102 bug("[KRN] Kernel c entry @ %08x\n", startup);
103 bug("[KRN] Early MMU @ %08x\n", early_mmu);
105 /* Check if the taglist is copied into safe place */
106 if (tags != temporary.tags) {
107 /* Nope, copy taglist... */
108 struct TagItem *msg = tags;
109 struct TagItem *tmp = temporary.tags;
111 while(msg->ti_Tag != TAG_DONE) {
112 /* Copy the tag */
113 *tmp = *msg;
115 if (tmp->ti_Tag == KRN_CmdLine) {
116 strcpy(CmdLine, (char*) msg->ti_Data);
117 tmp->ti_Data = (STACKIPTR) CmdLine;
118 D(bug("[KRN] CmdLine: %s\n", tmp->ti_Data));
119 } else if (tmp->ti_Tag == KRN_MEMLower) {
120 D(bug("[KRN] MemLower: %08x\n", tmp->ti_Data));
121 } else if (tmp->ti_Tag == KRN_MEMUpper) {
122 D(bug("[KRN] MemUpper: %08x\n", tmp->ti_Data));
125 else if (tmp->ti_Tag == KRN_KernelLowest) {
126 D(bug("[KRN] KernelLowest: %08x\n", tmp->ti_Data));
127 } else if (tmp->ti_Tag == KRN_KernelHighest) {
128 D(bug("[KRN] KernelHighest: %08x\n", tmp->ti_Data));
131 else if (tmp->ti_Tag == KRN_KernelBss) {
132 D(bug("[KRN] kernelBSS: %08x\n", tmp->ti_Data));
135 tmp++;
136 msg++;
140 while(1);