FreeNOS
Main.cpp
Go to the documentation of this file.
1/*
2 * Copyright (C) 2019 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 <arm/ARMPaging.h>
22#include <arm/ARMControl.h>
23#include <arm/ARMCore.h>
24#include <NS16550.h>
25#include <DeviceLog.h>
26#include <SunxiCoreServer.h>
27#include <Macros.h>
28#include <MemoryBlock.h>
29#include <Memory.h>
30#include "SunxiKernel.h"
31
33
34static u32 ALIGN(16 * 1024) SECTION(".data") tmpPageDir[4096];
35
36extern C int kernel_main(void)
37{
38#ifdef ARMV7
39 // Raise the SMP bit for ARMv7
40 ARMControl ctrl;
42#endif
43
44 if (read_core_id() == 0)
45 {
46 // Invalidate all caches now
47 Arch::Cache cache;
49 }
50
51 // Setup memory map with the memory base physical memory address
53 Address memoryBaseAddr = RAM_ADDR;
54
55 if (read_core_id() != 0) {
56 CoreInfo tmpInfo;
57 MemoryBlock::copy((void *)&tmpInfo,
59 memoryBaseAddr = tmpInfo.memory.phys;
60 }
61
62 // Prepare early page tables and re-map the temporary stack
63 ARMPaging paging(&mem, (Address) &tmpPageDir, memoryBaseAddr);
64
65 // Activate MMU
66 paging.initialize();
67 paging.activate(true);
68
69 // Fill coreInfo for boot core
70 if (read_core_id() == 0)
71 {
72 BootImage *bootimage = (BootImage *) &__bootimg;
74 coreInfo.bootImageAddress = (Address) (bootimage);
78 coreInfo.memory.phys = RAM_ADDR;
79 coreInfo.memory.size = RAM_SIZE;
80 }
81 // Copy CoreInfo prepared by the CoreServer
82 else
83 {
86 }
87
88 // Clear BSS
89 clearBSS();
90
91 // Initialize heap
93
94 // Run all constructors first
96
97 // Open serial console as default Log
98 NS16550 *uart = new NS16550(UART0_IRQ);
99 uart->initialize();
100 DeviceLog *console = new DeviceLog(*uart);
101
102 // Only the boot core outputs notifications
103 if (read_core_id() == 0)
105 else
107
108 // Create the kernel
109 SunxiKernel *kernel = new SunxiKernel(&coreInfo);
110
111 // Run the kernel
112 return kernel->run();
113}
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
@ Warning
Definition Log.h:112
@ Notice
Definition Log.h:113
static void * set(void *dest, int ch, unsigned count)
Fill memory with a constant byte.
static Size copy(void *dest, const void *src, Size count)
Copy memory from one place to another.
The NS16550 is a commonly available UART device.
Definition NS16550.h:39
virtual FileSystem::Result initialize()
Initializes the UART.
Definition NS16550.cpp:33
static const Address SecondaryCoreInfoAddress
Physical memory address for CoreInfo passed to secondary cores during bootup.
Represents the Sunxi kernel implementation.
Definition SunxiKernel.h:37
C void constructors()
Invokes all function pointers inside the .ctors section.
Definition Support.cpp:22
#define read_core_id()
Read unique core identifier.
Definition ARMCore.h:145
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