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 
33 static u32 ALIGN(16 * 1024) SECTION(".data") tmpPageDir[4096];
34 
35 extern 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;
44  ctrl.set(ARMControl::SMPBit);
45 #endif
46 
47  // Fill coreInfo
48  BootImage *bootimage = (BootImage *) &__bootimg;
49  MemoryBlock::set(&coreInfo, 0, sizeof(CoreInfo));
50  coreInfo.bootImageAddress = (Address) (bootimage);
54  coreInfo.memory.phys = RAM_ADDR;
55  coreInfo.memory.size = RAM_SIZE;
56 
57  // Prepare early page tables
58  Arch::MemoryMap mem;
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
72  constructors();
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
82  RaspberryKernel kernel(&coreInfo);
83 
84  // Run the kernel
85  return kernel.run();
86 }
RaspberryKernel.h
ARMPaging::activate
virtual Result activate(bool initializeMMU=false)
Activate the MemoryContext.
Definition: ARMPaging.cpp:198
DeviceLog
Generic logger that writes to a Device object.
Definition: DeviceLog.h:38
Macros.h
Log::setMinimumLogLevel
void setMinimumLogLevel(Level level)
Set the minimum logging level.
Definition: Log.cpp:38
PL011
The PL011 is a commonly available UART device frequently found in ARM systems.
Definition: PL011.h:39
CoreInfo::bootImageSize
Address bootImageSize
Boot image size in bytes.
Definition: CoreInfo.h:84
MemoryBlock::set
static void * set(void *dest, int ch, unsigned count)
Fill memory with a constant byte.
Definition: MemoryBlock.cpp:25
__end
Address __end
Definition: Main.cpp:31
ARMPaging
ARM virtual memory implementation.
Definition: ARMPaging.h:43
Kernel::initializeHeap
static Error initializeHeap()
Initialize heap.
Definition: Kernel.cpp:108
ARMPaging.h
Address
unsigned long Address
A memory address.
Definition: Types.h:131
CoreInfo::memory
Memory::Range memory
Defines the physical memory available to the core.
Definition: CoreInfo.h:69
ARMPaging::initialize
virtual Result initialize()
Initialize the MemoryContext.
Definition: ARMPaging.cpp:55
Kernel::run
int run()
Execute the kernel.
Definition: Kernel.cpp:392
MemoryBlock.h
kernel_main
C int kernel_main(void)
Definition: Main.cpp:35
BootImage::bootImageSize
u32 bootImageSize
Total size of the boot image in bytes.
Definition: BootImage.h:53
ARMMap
Memory mapping for the kernel and user processes on the ARM architecture.
Definition: ARMMap.h:37
C
#define C
Used to define external C functions.
Definition: Macros.h:134
ARMCacheV6::invalidate
virtual Result invalidate(Type type)
Invalidate the entire cache.
Definition: ARMCacheV6.cpp:21
ARMControl
ARM System Control Coprocessor (CP15).
Definition: ARMControl.h:47
Memory::Range::phys
Address phys
Physical address.
Definition: Memory.h:58
__start
Address __start
ARMCacheV6
ARMv6 cache management implementation.
Definition: ARMCacheV6.h:42
u32
unsigned int u32
Unsigned 32-bit number.
Definition: Types.h:53
CoreInfo::bootImageAddress
Address bootImageAddress
Boot image physical memory address.
Definition: CoreInfo.h:81
Log::Notice
@ Notice
Definition: Log.h:113
constructors
C void constructors()
Invokes all function pointers inside the .ctors section.
Definition: Support.cpp:22
CoreInfo
Per-Core information structure.
Definition: CoreInfo.h:60
coreInfo
CoreInfo coreInfo
Local CoreInfo instance.
DeviceLog.h
__bootimg
Address __bootimg
Definition: Main.cpp:31
BroadcomInterrupt.h
BroadcomTimer.h
SECTION
#define SECTION(s)
Can be used to link a symbol inside a specific section.
Definition: Macros.h:145
ARMControl::set
void set(SystemControlFlags flags)
Set system control flags in CP15.
Definition: ARMControl.cpp:88
RaspberryKernel
Represents the Raspberry Pi kernel implementation.
Definition: RaspberryKernel.h:40
CoreInfo::kernel
Memory::Range kernel
Kernel memory range.
Definition: CoreInfo.h:75
ARMControl.h
BootImage
BootImage contains executable programs to be loaded at system bootup.
Definition: BootImage.h:44
PL011::initialize
virtual FileSystem::Result initialize()
Initializes the UART.
Definition: PL011.cpp:34
Cache::Unified
@ Unified
Definition: Cache.h:57
clearBSS
void clearBSS()
Generic function to clear the BSS memory section to zero.
Definition: Memory.cpp:21
Memory::Range::size
Size size
Size in number of bytes.
Definition: Memory.h:59
ALIGN
static u32 ALIGN(16 *1024) SECTION(".data") tmpPageDir[4096]
PL011.h
ARMControl::SMPBit
@ SMPBit
Definition: ARMControl.h:105