FreeNOS
Main.cpp
Go to the documentation of this file.
1/*
2 * Copyright (C) 2025 Ivan Tan
3 * Copyright (C) 2015 Niek Linnenbank
4 *
5 * This program is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation, either version 3 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
17 */
18
19
20/* https://github.com/bztsrc/raspi3-tutorial/blob/master/03_uart1 */
21
23
24#include <FreeNOS/System.h>
25#include <FreeNOS/arm64/ARM64Kernel.h>
26#include <MemoryBlock.h>
27#include <arm64/ARM64Map.h>
28#include <arm64/ARM64Paging.h>
31#include <arm64/ARM64Control.h>
32#include <DeviceLog.h>
33#include "CoreInfo.h"
34#include "BootImage.h"
35#include "RaspberryKernel.h"
36#include "Support.h"
37#include "PL011.h"
38
39static char ALIGN(16 * 1024) SECTION(".data") tmpPageDir[sizeof(ARM64FirstTable)];
40
41extern C int kernel_main(void)
42{
43 // Fill coreInfo
44 BootImage *bootimage = (BootImage *) &__bootimg;
46 coreInfo.bootImageAddress = (Address) (bootimage);
50 coreInfo.memory.phys = RAM_ADDR;
51 coreInfo.memory.size = RAM_SIZE;
52
54 ARM64Paging paging(&mem, (Address) &tmpPageDir, RAM_ADDR);
55
56 // Activate MMU
57 paging.initialize();
58 paging.activate(true);
59
60 // Clear BSS
61 clearBSS();
62
63 // Initialize heap
65
66 // Run all constructors first
68
69 // Open the serial console as default Log
70 PL011 pl011(UART0_IRQ);
71 pl011.initialize();
72
73 DeviceLog console(pl011);
75
77
78 return kernel.run();
79}
ARM64 first level page table.
ARM64 virtual memory implementation.
Definition ARM64Paging.h:51
virtual Result activate(bool initializeMMU=false)
Activate the MemoryContext.
virtual Result initialize()
Initialize the MemoryContext.
Memory mapping for the kernel and user processes on the ARM architecture.
Definition ARMMap.h:38
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 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