move delay code into separate function.
[AROS.git] / arch / arm-raspi / kernel / kernel_startup.c
blobe37ffef807c80f60c7c2439984e01593b9875a5f
1 /*
2 Copyright � 2013-2015, The AROS Development Team. All rights reserved.
3 $Id$
4 */
6 #define DEBUG 0
8 #include <aros/kernel.h>
9 #include <aros/symbolsets.h>
11 #include <aros/arm/cpucontext.h>
13 #include <exec/memory.h>
14 #include <exec/tasks.h>
15 #include <exec/alerts.h>
16 #include <exec/execbase.h>
17 #include <asm/io.h>
18 #include <proto/kernel.h>
19 #include <proto/exec.h>
20 #include <strings.h>
22 #include "exec_intern.h"
23 #include "etask.h"
25 #include "kernel_intern.h"
26 #include "kernel_debug.h"
27 #include "kernel_fb.h"
28 #include "kernel_romtags.h"
30 extern void krnCreateMemHeader(CONST_STRPTR name, BYTE pri, APTR start, IPTR size, ULONG flags);
32 void __attribute__((used)) kernel_cstart(struct TagItem *msg);
34 uint32_t stack[STACK_SIZE] __attribute__((used,aligned(16)));
35 static uint32_t stack_super[STACK_SIZE] __attribute__((used,aligned(16)));
36 static uint32_t stack_abort[STACK_SIZE] __attribute__((used,aligned(16)));
37 static uint32_t stack_irq[STACK_SIZE] __attribute__((used,aligned(16)));
39 asm (
40 ".section .aros.init,\"ax\"\n\t"
41 ".globl start\n\t"
42 ".type start,%function\n"
43 "start:\n"
44 " push {r0} \n"
45 " bl __clear_bss \n"
46 " pop {r0} \n"
47 " cps #0x1f \n" /* system mode */
48 " ldr sp, stack_end \n"
49 " cps #0x17 \n" /* abort mode */
50 " ldr sp, stack_abort_end \n"
51 " cps #0x12 \n" /* IRQ mode */
52 " ldr sp, stack_irq_end \n"
53 " cps #0x13 \n" /* SVC (supervisor) mode */
54 " ldr sp, stack_super_end \n"
55 " b kernel_cstart \n"
57 ".string \"Native/CORE v3 (" __DATE__ ")\"" "\n\t\n\t"
60 static uint32_t * const stack_end __attribute__((used, section(".aros.init"))) = &stack[STACK_SIZE - sizeof(IPTR)];
61 static uint32_t * const stack_super_end __attribute__((used, section(".aros.init"))) = &stack_super[STACK_SIZE - sizeof(IPTR)];
62 static uint32_t * const stack_abort_end __attribute__((used, section(".aros.init"))) = &stack_abort[STACK_SIZE - sizeof(IPTR)];
63 static uint32_t * const stack_irq_end __attribute__((used, section(".aros.init"))) = &stack_irq[STACK_SIZE - sizeof(IPTR)];
65 struct ExecBase *SysBase __attribute__((section(".data"))) = NULL;
66 struct ARM_Implementation krnARMImpl __attribute__((section(".data")));
68 extern struct TagItem *BootMsg;
70 static void __attribute__((used)) __clear_bss(struct TagItem *msg)
72 struct KernelBSS *bss = (struct KernelBSS *)krnGetTagData(KRN_KernelBss, 0, msg);
73 register unsigned int dest;
74 unsigned int length;
76 if (bss)
78 while (bss->addr && bss->len)
80 dest = bss->addr;
81 length = bss->len;
83 // If the start address is unaligned, fill in the first 1-3 bytes until it is
84 while((dest & 3) && length)
86 *((unsigned char *)dest) = 0;
87 dest++;
88 length--;
91 // Fill in the remaining 32-bit word-aligned memory locations
92 while(length & 0xfffffffc)
94 *((unsigned int *)dest) = 0;
95 dest += 4;
96 length -= 4;
99 // Deal with the remaining 1-3 bytes, if any
100 while(length)
102 dest++;
103 length--;
104 *((unsigned char *)dest) = 0;
106 bss++;
111 uint32_t __arm_periiobase = 0;
113 void __attribute__((used)) kernel_cstart(struct TagItem *msg)
115 UWORD *ranges[3];
116 struct MinList memList;
117 struct MemHeader *mh;
118 struct MemChunk *mc;
119 long unsigned int memlower = 0, memupper = 0, protlower = 0, protupper = 0;
120 BootMsg = msg;
122 cpu_Probe(&krnARMImpl);
123 platform_Init(&krnARMImpl, msg);
124 cpu_Init(&krnARMImpl, msg);
126 /* NB: the bootstrap has conveniently setup the framebuffer
127 and initialised the serial port and led for us */
129 while(msg->ti_Tag != TAG_DONE)
131 switch (msg->ti_Tag)
133 case KRN_FuncPutC:
134 _KrnPutC = msg->ti_Data;
135 _KrnPutC(0xFF); // Clear the display
136 break;
137 case KRN_MEMLower:
138 memlower = msg->ti_Data;
139 break;
140 case KRN_MEMUpper:
141 memupper = msg->ti_Data;
142 break;
143 case KRN_ProtAreaStart:
144 protlower = msg->ti_Data;
145 break;
146 case KRN_ProtAreaEnd:
147 protupper = msg->ti_Data;
148 break;
149 case KRN_KernelBase:
151 * KRN_KernelBase is actually a border between read-only
152 * (code) and read-write (data) sections of the kickstart.
153 * read-write section goes to lower addresses from this one,
154 * so we align it upwards in order not to make part of RW data
155 * read-only.
157 // addr = AROS_ROUNDUP2(msg->ti_Data, PAGE_SIZE);
158 break;
160 msg++;
162 msg = BootMsg;
164 D(bug("[KRN] AROS Raspberry Pi Kernel built on %s\n", __DATE__));
166 D(bug("[KRN] Entered kernel_cstart @ 0x%p, BootMsg @ %p\n", kernel_cstart, BootMsg));
169 if (_KrnPutC)
171 bug("[KRN] Using boostrap PutC implementation @ %p\n", _KrnPutC);
175 core_SetupIntr();
177 if (krnARMImpl.ARMI_LED_Toggle)
179 krnARMImpl.ARMI_LED_Toggle(ARM_LED_POWER, ARM_LED_OFF);
180 if (krnARMImpl.ARMI_Delay)
181 krnARMImpl.ARMI_Delay(1500);
182 krnARMImpl.ARMI_LED_Toggle(ARM_LED_POWER, ARM_LED_ON);
185 NEWLIST(&memList);
187 mh = (struct MemHeader *)memlower;
188 krnCreateMemHeader("System Memory", 0, mh, protlower - (long unsigned int)mh, MEMF_FAST | MEMF_PUBLIC | MEMF_KICK | MEMF_LOCAL);
190 mc = (struct MemChunk *)((protupper + MEMCHUNK_TOTAL-1) & ~(MEMCHUNK_TOTAL-1));
191 mc->mc_Bytes = memupper - (long unsigned int)mc;
192 mc->mc_Next = NULL;
194 if (mh->mh_First->mc_Next == NULL)
196 mh->mh_First->mc_Next = mc;
197 mh->mh_Upper = memupper;
198 mh->mh_Free += mc->mc_Bytes;
201 ranges[0] = (UWORD *)krnGetTagData(KRN_KernelLowest, 0, msg);
202 ranges[1] = (UWORD *)krnGetTagData(KRN_KernelHighest, 0, msg);
203 ranges[2] = (UWORD *)-1;
205 D(bug("[KRN] Preparing ExecBase (memheader @ 0x%p)\n", mh));
206 krnPrepareExecBase(ranges, mh, BootMsg);
209 * Make kickstart code area read-only.
210 * We do it only after ExecBase creation because SysBase pointer is put
211 * into .rodata. This way we prevent it from ocassional modification by buggy software.
213 // core_ProtKernelArea(addr, kick_highest - addr, 1, 0, 1);
215 D(bug("[KRN] InitCode(RTF_SINGLETASK) ... \n"));
216 InitCode(RTF_SINGLETASK, 0);
218 D(bug("[KRN] InitCode(RTF_COLDSTART) ...\n"));
220 asm("cps %[mode_user]\n" : : [mode_user] "I" (CPUMODE_USER)); /* switch to user mode */
222 InitCode(RTF_COLDSTART, 0);
224 /* The above should not return */
225 krnPanic(KernelBase, "System Boot Failed!");