wip.
[AROS.git] / arch / arm-native / kernel / kernel_startup.c
blobd669ffaf9f51b8c4ebeecc30722b3b953cdd0560
1 /*
2 Copyright � 2013-2015, The AROS Development Team. All rights reserved.
3 $Id$
4 */
6 #define DEBUG 1
8 #include <aros/kernel.h>
9 #include <aros/symbolsets.h>
11 #include <aros/arm/cpucontext.h>
13 #include <aros/cpu.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>
20 #include <asm/io.h>
21 #include <proto/kernel.h>
22 #include <proto/exec.h>
23 #include <strings.h>
25 #include "exec_intern.h"
26 #include "etask.h"
28 #include "tlsf.h"
30 #include "kernel_intern.h"
31 #include "kernel_debug.h"
32 #include "kernel_romtags.h"
34 extern struct TagItem *BootMsg;
36 void __attribute__((used)) kernel_cstart(struct TagItem *msg);
38 uint32_t stack[AROS_STACKSIZE] __attribute__((used,aligned(16)));
39 static uint32_t stack_super[AROS_STACKSIZE] __attribute__((used,aligned(16)));
40 static uint32_t stack_abort[AROS_STACKSIZE] __attribute__((used,aligned(16)));
41 static uint32_t stack_irq[AROS_STACKSIZE] __attribute__((used,aligned(16)));
43 asm (
44 ".section .aros.init,\"ax\"\n\t"
45 ".globl start\n\t"
46 ".type start,%function\n"
47 "start:\n"
48 " push {r0} \n"
49 " bl __clear_bss \n"
50 " pop {r0} \n"
51 " cps #0x1f \n" /* system mode */
52 " ldr sp, stack_end \n"
53 " cps #0x17 \n" /* abort mode */
54 " ldr sp, stack_abort_end \n"
55 " cps #0x12 \n" /* IRQ mode */
56 " ldr sp, stack_irq_end \n"
57 " cps #0x13 \n" /* SVC (supervisor) mode */
58 " ldr sp, stack_super_end \n"
59 " b kernel_cstart \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_abort_end __attribute__((used, section(".aros.init"))) = &stack_abort[AROS_STACKSIZE - sizeof(IPTR)];
67 static uint32_t * const stack_irq_end __attribute__((used, section(".aros.init"))) = &stack_irq[AROS_STACKSIZE - 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;
76 unsigned int length;
78 if (bss)
80 while (bss->addr && bss->len)
82 dest = (unsigned int)bss->addr;
83 length = bss->len;
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;
89 dest++;
90 length--;
93 // Fill in the remaining 32-bit word-aligned memory locations
94 while(length & 0xfffffffc)
96 *((unsigned int *)dest) = 0;
97 dest += 4;
98 length -= 4;
101 // Deal with the remaining 1-3 bytes, if any
102 while(length)
104 dest++;
105 length--;
106 *((unsigned char *)dest) = 0;
108 bss++;
113 uint32_t __arm_periiobase __attribute__((section(".data"))) = 0;
115 void __attribute__((used)) kernel_cstart(struct TagItem *msg)
117 UWORD *ranges[3];
118 struct MinList memList;
119 struct MemHeader *mh;
120 struct MemChunk *mc;
121 long unsigned int memlower = 0, memupper = 0, protlower = 0, protupper = 0;
122 BootMsg = msg;
124 cpu_Probe(&__arm_arosintern);
125 platform_Init(&__arm_arosintern, msg);
126 cpu_Init(&__arm_arosintern, msg);
128 /* NB: the bootstrap has conveniently setup the framebuffer
129 and initialised the serial port and led for us */
131 while(msg->ti_Tag != TAG_DONE)
133 switch (msg->ti_Tag)
135 case KRN_MEMLower:
136 memlower = msg->ti_Data;
137 break;
138 case KRN_MEMUpper:
139 memupper = msg->ti_Data;
140 break;
141 case KRN_ProtAreaStart:
142 protlower = msg->ti_Data;
143 break;
144 case KRN_ProtAreaEnd:
145 protupper = msg->ti_Data;
146 break;
147 case KRN_KernelBase:
149 * KRN_KernelBase is actually a border between read-only
150 * (code) and read-write (data) sections of the kickstart.
151 * read-write section goes to lower addresses from this one,
152 * so we align it upwards in order not to make part of RW data
153 * read-only.
155 // addr = AROS_ROUNDUP2(msg->ti_Data, PAGE_SIZE);
156 break;
158 msg++;
160 msg = BootMsg;
162 D(bug("[KRN] AROS ARM Native Kernel built on %s\n", __DATE__));
164 D(bug("[KRN] Entered kernel_cstart @ 0x%p, BootMsg @ %p\n", kernel_cstart, BootMsg));
167 if (__arm_arosintern.ARMI_PutChar)
169 bug("[KRN] Using PutChar implementation @ %p\n", __arm_arosintern.ARMI_PutChar);
173 core_SetupIntr();
175 if (__arm_arosintern.ARMI_LED_Toggle)
177 __arm_arosintern.ARMI_LED_Toggle(ARM_LED_POWER, ARM_LED_OFF);
178 if (__arm_arosintern.ARMI_Delay)
179 __arm_arosintern.ARMI_Delay(1500);
180 __arm_arosintern.ARMI_LED_Toggle(ARM_LED_POWER, ARM_LED_ON);
183 NEWLIST(&memList);
185 mh = (struct MemHeader *)memlower;
187 /* Initialize TLSF memory allocator */
188 krnCreateTLSFMemHeader("System Memory", 0, mh, (memupper - memlower), MEMF_FAST | MEMF_PUBLIC | MEMF_KICK | MEMF_LOCAL);
190 /* Protect the bootstrap area from further use. AllocAbs will do the trick */
191 ((struct MemHeaderExt *)mh)->mhe_AllocAbs((struct MemHeaderExt *)mh, protupper-protlower, (void *)protlower);
193 ranges[0] = (UWORD *)krnGetTagData(KRN_KernelLowest, 0, msg);
194 ranges[1] = (UWORD *)krnGetTagData(KRN_KernelHighest, 0, msg);
195 ranges[2] = (UWORD *)-1;
197 D(bug("[KRN] Preparing ExecBase (memheader @ 0x%p)\n", mh));
198 krnPrepareExecBase(ranges, mh, BootMsg);
201 * Make kickstart code area read-only.
202 * We do it only after ExecBase creation because SysBase pointer is put
203 * into .rodata. This way we prevent it from ocassional modification by buggy software.
205 // core_ProtKernelArea(addr, kick_highest - addr, 1, 0, 1);
207 D(bug("[KRN] InitCode(RTF_SINGLETASK) ... \n"));
208 InitCode(RTF_SINGLETASK, 0);
210 D(bug("[KRN] InitCode(RTF_COLDSTART) ...\n"));
212 asm("cps %[mode_user]\n" : : [mode_user] "I" (CPUMODE_USER)); /* switch to user mode */
214 InitCode(RTF_COLDSTART, 0);
216 /* The above should not return */
217 krnPanic(KernelBase, "System Boot Failed!");
220 DEFINESET(ARMPLATFORMS);