Wip, I will need to copy some of taglist elements into kernel protected
[AROS.git] / arch / arm-efika / kernel / kernel_startup.c
blob4917fa1af876605dfa8b7ded2064216b6a915d09
1 /*
2 Copyright © 1995-2010, 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 #define D(x) x
24 #define _STR(x) #x
25 #define STR(x) _STR(x)
27 #define SYS_STACK_SIZE (16384)
29 extern void start();
31 asm(".section .aros.init,\"ax\"\n\t"
32 ".globl start\n\t"
33 ".type start,%function\n"
34 "start: ldr sp, tmp_stack_end \n" // Load address of top of stack pointer
35 " mov r4, r0 \n"
36 " bl clear_bss \n" // clear bss regions
37 " mov r0, r4 \n" // restore boot msg parameter
38 " cps #" STR(CPUMODE_SYSTEM) "\n" // Enter System mode
39 " ldr sp, sys_stack_end \n" // Load system mode stack
40 " cps #" STR(CPUMODE_IRQ) "\n"
41 " ldr sp, irq_stack_end \n"
42 " cps #" STR(CPUMODE_ABORT) "\n"
43 " ldr sp, abt_stack_end \n"
44 " cps #" STR(CPUMODE_SUPERVISOR) "\n"
45 " ldr sp, svc_stack_end \n"
46 " ldr pc, 2f \n" // jump to the kernel
47 "1: b 1b \n" // we never return from here
48 "2: .word startup \n"
49 "tmp_stack_end: .word temporary + " STR(127*4) "\n"
50 "sys_stack_end: .word sys_stack + " STR((SYS_STACK_SIZE - 4)) "\n"
51 "svc_stack_end: .word svc_stack + " STR((SYS_STACK_SIZE - 4)) "\n"
52 "irq_stack_end: .word irq_stack + " STR((SYS_STACK_SIZE - 4)) "\n"
53 "abt_stack_end: .word abt_stack + " STR((SYS_STACK_SIZE - 4)) "\n"
57 * Temporary stack for very early init. It's used only during clearing of
58 * .bss sections in all modules. Rest of this space is occupied by TagItem
59 * boot message. prepared by the bootstrap.
61 static union {
62 uint32_t stack[128];
63 struct TagItem tags[64];
64 } temporary __attribute__((aligned(32),used,section(".data")));
66 static uint8_t sys_stack[SYS_STACK_SIZE] __attribute__((used,aligned(16)));
67 static uint8_t svc_stack[SYS_STACK_SIZE] __attribute__((used,aligned(16)));
68 static uint8_t abt_stack[SYS_STACK_SIZE] __attribute__((used,aligned(16)));
69 static uint8_t irq_stack[SYS_STACK_SIZE] __attribute__((used,aligned(16)));
71 static char CmdLine[200] __attribute__((used, section(".data")));
73 __attribute__((section(".data"))) struct ExecBase *SysBase = NULL;
75 struct TagItem *BootMsg;
77 static void __used __attribute__((section(".aros.init"))) clear_bss(struct TagItem *msg)
79 struct TagItem *tag = LibFindTagItem(KRN_KernelBss, msg);
81 if (tag)
83 struct KernelBSS *bss = (struct KernelBSS *)tag->ti_Data;
85 if (bss)
87 __clear_bss(bss);
92 void startup(struct TagItem *tags)
94 bug("\n[KRN] AROS for EfikaMX built on %s starting...\n", __DATE__);
95 bug("[KRN] BootMsg @ %08x\n", tags);
96 bug("[KRN] Kernel entry @ %08x\n", start);
98 /* Check if the taglist is copied into safe place */
99 if (tags != temporary.tags)
101 /* Nope, copy taglist... */
102 struct TagItem *msg = tags;
103 struct TagItem *tmp = temporary.tags;
105 while(msg->ti_Tag != TAG_DONE)
107 /* Copy the tag */
108 *tmp = *msg;
110 if (tmp->ti_Tag == KRN_CmdLine)
112 strcpy(CmdLine, (char*) msg->ti_Data);
113 tmp->ti_Data = (STACKIPTR) CmdLine;
114 D(bug("[KRN] CmdLine: %s\n", tmp->ti_Data));
116 else if (tmp->ti_Tag == KRN_MEMLower)
118 D(bug("[KRN] MemLower: %08x\n", tmp->ti_Data));
120 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)
127 D(bug("[KRN] KernelLowest: %08x\n", tmp->ti_Data));
130 else if (tmp->ti_Tag == KRN_KernelHighest)
132 D(bug("[KRN] KernelHighest: %08x\n", tmp->ti_Data));
135 else if (tmp->ti_Tag == KRN_KernelBss)
137 D(bug("[KRN] kernelBSS: %08x\n", tmp->ti_Data));
140 tmp++;
141 msg++;
146 while(1);