FreeNOS
Main.cpp
Go to the documentation of this file.
1/*
2 * Copyright (C) 2015 Niek Linnenbank
3 *
4 * This program is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation, either version 3 of the License, or
7 * (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program. If not, see <http://www.gnu.org/licenses/>.
16 */
17
18#include <FreeNOS/Config.h>
19#include <FreeNOS/Support.h>
20#include <FreeNOS/System.h>
21#include <Macros.h>
22#include <MemoryBlock.h>
23#include <arm/ARMControl.h>
24#include <arm/ARMPaging.h>
27#include <PL011.h>
28#include <DeviceLog.h>
29#include "RaspberryKernel.h"
30
32
33static u32 ALIGN(16 * 1024) SECTION(".data") tmpPageDir[4096];
34
35extern C int kernel_main(void)
36{
37 // Invalidate all caches now
38 Arch::Cache cache;
40
41#ifdef ARMV7
42 // Raise the SMP bit for ARMv7
43 ARMControl ctrl;
45#endif
46
47 // Fill coreInfo
48 BootImage *bootimage = (BootImage *) &__bootimg;
50 coreInfo.bootImageAddress = (Address) (bootimage);
54 coreInfo.memory.phys = RAM_ADDR;
55 coreInfo.memory.size = RAM_SIZE;
56
57 // Prepare early page tables
59 ARMPaging paging(&mem, (Address) &tmpPageDir, RAM_ADDR);
60
61 // Activate MMU
62 paging.initialize();
63 paging.activate(true);
64
65 // Clear BSS
66 clearBSS();
67
68 // Initialize heap
70
71 // Run all constructors first
73
74 // Open the serial console as default Log
75 PL011 pl011(UART0_IRQ);
76 pl011.initialize();
77
78 DeviceLog console(pl011);
80
81 // Create the kernel
83
84 // Run the kernel
85 return kernel.run();
86}
ARMv6 cache management implementation.
Definition ARMCacheV6.h:43
virtual Result invalidate(Type type)
Invalidate the entire cache.
ARM System Control Coprocessor (CP15).
Definition ARMControl.h:48
void set(SystemControlFlags flags)
Set system control flags in CP15.
Memory mapping for the kernel and user processes on the ARM architecture.
Definition ARMMap.h:38
ARM virtual memory implementation.
Definition ARMPaging.h:44
virtual Result activate(bool initializeMMU=false)
Activate the MemoryContext.
virtual Result initialize()
Initialize the MemoryContext.
Definition ARMPaging.cpp:55
@ Unified
Definition Cache.h:57
Generic logger that writes to a Device object.
Definition DeviceLog.h:39
static Error initializeHeap()
Initialize heap.
Definition Kernel.cpp:108
int run()
Execute the kernel.
Definition Kernel.cpp:392
void setMinimumLogLevel(Level level)
Set the minimum logging level.
Definition Log.cpp:38
@ Notice
Definition Log.h:113
static void * set(void *dest, int ch, unsigned count)
Fill memory with a constant byte.
The PL011 is a commonly available UART device frequently found in ARM systems.
Definition PL011.h:40
virtual FileSystem::Result initialize()
Initializes the UART.
Definition PL011.cpp:34
Represents the Raspberry Pi kernel implementation.
C void constructors()
Invokes all function pointers inside the .ctors section.
Definition Support.cpp:22
CoreInfo coreInfo
Local CoreInfo instance.
void clearBSS()
Generic function to clear the BSS memory section to zero.
Definition Memory.cpp:21
unsigned int u32
Unsigned 32-bit number.
Definition Types.h:53
unsigned long Address
A memory address.
Definition Types.h:131
#define C
Used to define external C functions.
Definition Macros.h:134
#define ALIGN(n)
Aligns a symbol at the given boundary.
Definition Macros.h:167
#define SECTION(s)
Can be used to link a symbol inside a specific section.
Definition Macros.h:145
Address __bootimg
Definition Main.cpp:31
Address __start
C int kernel_main(void)
Definition Main.cpp:35
Address __end
Definition Main.cpp:31
BootImage contains executable programs to be loaded at system bootup.
Definition BootImage.h:45
u32 bootImageSize
Total size of the boot image in bytes.
Definition BootImage.h:53
Per-Core information structure.
Definition CoreInfo.h:61
Address bootImageSize
Boot image size in bytes.
Definition CoreInfo.h:84
Memory::Range kernel
Kernel memory range.
Definition CoreInfo.h:75
Address bootImageAddress
Boot image physical memory address.
Definition CoreInfo.h:81
Memory::Range memory
Defines the physical memory available to the core.
Definition CoreInfo.h:69
Size size
Size in number of bytes.
Definition Memory.h:59
Address phys
Physical address.
Definition Memory.h:58