From 14ccb3c7f87385cfed7ea6c7a9888d153926853a Mon Sep 17 00:00:00 2001
From: Max Tyson <98maxt98@gmail.com>
Date: Sat, 1 Nov 2025 16:58:10 +1300
Subject: [PATCH 01/12] DOXY Structs: typedef and packed & other missed
functions
---
docs/CODE_OF_CONDUCT.md | 2 +-
docs/Notes.md | 8 +-
docs/Styles/.clang-format | 72 +++++++-
docs/Styles/Coding Style.md | 6 +-
docs/Styles/Interface Style.md | 4 +-
docs/doxy/Doxyfile | 4 +-
kernel/include/common/macros.h | 22 +++
kernel/include/common/time.h | 10 +-
kernel/include/drivers/clock/clock.h | 7 +-
.../include/drivers/ethernet/amd_am79c973.h | 165 ++++++++++--------
kernel/include/drivers/ethernet/ethernet.h | 1 +
kernel/include/drivers/ethernet/intel_i217.h | 53 ++++--
kernel/include/drivers/peripherals/keyboard.h | 42 +++--
kernel/include/filesystem/filesystem.h | 138 +++++++--------
kernel/include/filesystem/format/ext2.h | 42 +++--
kernel/include/filesystem/format/fat32.h | 37 ++--
kernel/include/filesystem/partition/msdos.h | 15 +-
kernel/include/gui/widget.h | 23 ++-
kernel/include/hardwarecommunication/acpi.h | 29 ++-
kernel/include/hardwarecommunication/apic.h | 51 ++++--
.../hardwarecommunication/interrupts.h | 19 +-
kernel/include/memory/physical.h | 42 +++--
kernel/include/memory/virtual.h | 26 ++-
kernel/include/net/arp.h | 7 +-
kernel/include/net/ethernetframe.h | 16 +-
kernel/include/net/icmp.h | 9 +-
kernel/include/net/ipv4.h | 13 +-
kernel/include/net/tcp.h | 20 ++-
kernel/include/net/udp.h | 9 +-
kernel/include/processes/elf.h | 15 ++
kernel/include/processes/process.h | 15 +-
kernel/include/processes/resource.h | 4 +-
kernel/include/runtime/cplusplus.h | 25 ++-
kernel/include/runtime/ubsan.h | 51 ++++++
kernel/include/system/cpu.h | 46 +++--
kernel/include/system/gdt.h | 10 +-
kernel/include/system/syscalls.h | 7 +-
kernel/src/drivers/clock/clock.cpp | 6 +-
kernel/src/drivers/console/serial.cpp | 2 +-
kernel/src/drivers/ethernet/amd_am79c973.cpp | 2 +-
kernel/src/drivers/ethernet/intel_i217.cpp | 6 -
kernel/src/kernel.cpp | 3 +
kernel/src/memory/physical.cpp | 8 +-
kernel/src/runtime/cplusplus.cpp | 12 +-
toolchain/pre_process/symbols.sh | 14 +-
toolchain/pre_process/version.sh | 79 +++++++--
46 files changed, 830 insertions(+), 367 deletions(-)
create mode 100644 kernel/include/common/macros.h
diff --git a/docs/CODE_OF_CONDUCT.md b/docs/CODE_OF_CONDUCT.md
index 5429b311..5b995fe9 100644
--- a/docs/CODE_OF_CONDUCT.md
+++ b/docs/CODE_OF_CONDUCT.md
@@ -38,7 +38,7 @@ The following behaviors are considered harassment and are unacceptable within ou
* Personal insults, particularly those related to gender, sexual orientation, race, religion, or disability.
* Inappropriate photography or recording.
* Inappropriate physical contact. You should have someone's consent before touching them.
- * Unwelcome sexual attention. This includes, sexualized comments or jokes; inappropriate touching, groping, and unwelcomed sexual advances.
+ * Unwelcome sexual attention. This includes, sexualised comments or jokes; inappropriate touching, groping, and unwelcomed sexual advances.
* Deliberate intimidation, stalking or following (online or in person).
* Advocating for, or encouraging, any of the above behavior.
* Sustained disruption of community events, including talks and presentations.
diff --git a/docs/Notes.md b/docs/Notes.md
index ff994afc..794a8308 100644
--- a/docs/Notes.md
+++ b/docs/Notes.md
@@ -63,7 +63,7 @@ This relates to "port.cpp", directly used by "interrupts.cpp, mouse.cpp, keyboar
outb(portNumber, data)
outb(0x20, 0x1) //Example using PIC (port 32) and the data 1
```
-- To initialize the PIC ICWs (Initialization Control Words) must be sent
+- To initialise the PIC ICWs (Initialization Control Words) must be sent
### Interrupts
This relates to "interrupts.cpp, interruptstubs.s", which are extended by "keyboard.cpp, mouse.cpp".
@@ -364,16 +364,16 @@ See also [List of syscalls](https://x64.syscall.sh/)
### Driver am79c971
See also [OSDev - PCNET](https://wiki.osdev.org/AMD_PCNET), [LowLevel - PCNET](http://www.lowlevel.eu/wiki/AMD_PCnet), [Logical and Physical Adresses](https://www.geeksforgeeks.org/logical-and-physical-address-in-operating-system/) [AMD_AM79C973](https://www.amd.com/system/files/TechDocs/20550.pdf)
-- To get networking capability in the OS a driver for the virtualized network chip (am79c971) has to be written
+- To get networking capability in the OS a driver for the virtualised network chip (am79c971) has to be written
- This device is a complicated one to write a driver for. However, it will follow the same implementation as the other drivers: a class derived from driver, a class derived from interrupt handler (interrupt number and port number can be gotten from PCI)
-- The device takes a lot of code to initialize (similar to loads for setting VGA graphics mode).
+- The device takes a lot of code to initialise (similar to loads for setting VGA graphics mode).
- The networking device can have multiple send and receive buffers and for every m_buffer there needs to be an instance of a struct (which mainly has a pointer to that m_buffer)
- A problem with this though is that this is one of those devices that use some bits in the address for other purposes meaning it needs to be a multiple of 16 (similar to bar)
- So the m_buffer will be 2KB but then an additional 15 bytes are added on and then 4 bytes are removed. This allows for the multiple of 16 to be found
### Handler
See also [Wikipedia - Ethernet Frame](https://en.wikipedia.org/wiki/Ethernet_frame)
-- The driver written for the am79c971 can be utilized to receive and send data, however for the device to be useful a protocol handler has to be written.
+- The driver written for the am79c971 can be utilised to receive and send data, however for the device to be useful a protocol handler has to be written.
- This protocol handler will look at the incoming data and decide what protocol should be used to interpret the data.
- The data that is received by the am79c971 will be call raw data
- The raw data is structured like this (Encoded in big endian):
diff --git a/docs/Styles/.clang-format b/docs/Styles/.clang-format
index 2d90114e..67533a75 100644
--- a/docs/Styles/.clang-format
+++ b/docs/Styles/.clang-format
@@ -1,8 +1,66 @@
+# Generated from CLion C/C++ Code Style settings
BasedOnStyle: LLVM
-IndentWidth: 2
-ContinuationIndentWidth: 2
-BreakConstructorInitializers: AfterColon
-ConstructorInitializerIndentWidth: 2
-ConstructorInitializerAllOnOneLineOrOnePerLine: false
-AllowShortFunctionsOnASingleLine: None
-ColumnLimit: 0
\ No newline at end of file
+AccessModifierOffset: 0
+AlignAfterOpenBracket: Align
+AlignConsecutiveAssignments: None
+AlignOperands: Align
+AllowAllArgumentsOnNextLine: false
+AllowAllConstructorInitializersOnNextLine: false
+AllowAllParametersOfDeclarationOnNextLine: false
+AllowShortBlocksOnASingleLine: Always
+AllowShortCaseLabelsOnASingleLine: false
+AllowShortFunctionsOnASingleLine: All
+AllowShortIfStatementsOnASingleLine: Always
+AllowShortLambdasOnASingleLine: All
+AllowShortLoopsOnASingleLine: true
+AlwaysBreakAfterReturnType: None
+AlwaysBreakTemplateDeclarations: No
+BreakBeforeBraces: Custom
+BraceWrapping:
+ AfterCaseLabel: false
+ AfterClass: false
+ AfterControlStatement: Never
+ AfterEnum: false
+ AfterFunction: false
+ AfterNamespace: false
+ AfterUnion: false
+ BeforeCatch: false
+ BeforeElse: false
+ IndentBraces: false
+ SplitEmptyFunction: false
+ SplitEmptyRecord: true
+BreakBeforeBinaryOperators: None
+BreakBeforeTernaryOperators: true
+BreakConstructorInitializers: BeforeColon
+BreakInheritanceList: BeforeColon
+ColumnLimit: 0
+CompactNamespaces: false
+ContinuationIndentWidth: 8
+IndentCaseLabels: true
+IndentPPDirectives: None
+IndentWidth: 4
+KeepEmptyLinesAtTheStartOfBlocks: true
+MaxEmptyLinesToKeep: 2
+NamespaceIndentation: All
+ObjCSpaceAfterProperty: false
+ObjCSpaceBeforeProtocolList: true
+PointerAlignment: Left
+ReflowComments: false
+SpaceAfterCStyleCast: true
+SpaceAfterLogicalNot: false
+SpaceAfterTemplateKeyword: false
+SpaceBeforeAssignmentOperators: true
+SpaceBeforeCpp11BracedList: true
+SpaceBeforeCtorInitializerColon: true
+SpaceBeforeInheritanceColon: true
+SpaceBeforeParens: ControlStatements
+SpaceBeforeRangeBasedForLoopColon: true
+SpaceInEmptyParentheses: false
+SpacesBeforeTrailingComments: 0
+SpacesInAngles: false
+SpacesInCStyleCastParentheses: false
+SpacesInContainerLiterals: false
+SpacesInParentheses: false
+SpacesInSquareBrackets: false
+TabWidth: 4
+UseTab: ForIndentation
diff --git a/docs/Styles/Coding Style.md b/docs/Styles/Coding Style.md
index 8260ddb5..893ba2d7 100644
--- a/docs/Styles/Coding Style.md
+++ b/docs/Styles/Coding Style.md
@@ -2,13 +2,15 @@
# MaxOS C++ coding style
+TODO: order import alphabetically (libc then project headers last), must typedef structs
+
This document describes the coding style used for C++ code in the Max Operating System project. All new code should conform to this style.
### Names
A combination of CamelCase, snake\_case, and SCREAMING\_CASE:
-- Use CamelCase (Capitalize the m_first_memory_chunk letter, including all letters in an acronym) in a class, struct, or namespace name
+- Use CamelCase (Capitalise the m_first_memory_chunk letter, including all letters in an acronym) in a class, struct, or namespace name
- Use snake\_case (all lowercase, with underscores separating words) for variable and function names
- Use SCREAMING\_CASE for constants (both global and static member variables)
@@ -145,7 +147,7 @@ Prefer `const` to `#define`. Prefer inline functions to macros.
### Other Punctuation
-Constructors for C++ classes should initialize their members using C++ initializer syntax. Each member (and superclass) should be indented on a separate line, with the colon or comma preceding the member on that line. Prefer initialization at member definition whenever possible.
+Constructors for C++ classes should initialise their members using C++ initialiser syntax. Each member (and superclass) should be indented on a separate line, with the colon or comma preceding the member on that line. Prefer initialization at member definition whenever possible.
###### Right:
diff --git a/docs/Styles/Interface Style.md b/docs/Styles/Interface Style.md
index 1bdc7284..f894a00e 100644
--- a/docs/Styles/Interface Style.md
+++ b/docs/Styles/Interface Style.md
@@ -9,7 +9,7 @@ MaxOS employs two capitalization styles:
### Book m_title capitalization
-In this style, we capitalize the m_first_memory_chunk letter of the m_first_memory_chunk and last word,
+In this style, we capitalise the m_first_memory_chunk letter of the m_first_memory_chunk and last word,
as well as all words in between, *except* articles (a, an, the);
the seven coordinating conjunctions (for, and, nor, but, or, yet, so);
and prepositions with up to four letters (at, by, for, with, into, ...)
@@ -34,7 +34,7 @@ and prepositions with up to four letters (at, by, for, with, into, ...)
### Sentence-style capitalization
This style follows basic English sentence capitalization.
-We capitalize the m_first_memory_chunk letter of the m_first_memory_chunk word, along with the m_first_memory_chunk letter
+We capitalise the m_first_memory_chunk letter of the m_first_memory_chunk word, along with the m_first_memory_chunk letter
of proper names, weekdays, etc.
#### Examples:
diff --git a/docs/doxy/Doxyfile b/docs/doxy/Doxyfile
index 22bacb80..4b567f8a 100644
--- a/docs/doxy/Doxyfile
+++ b/docs/doxy/Doxyfile
@@ -1,6 +1,6 @@
DOXYFILE_ENCODING = UTF-8
PROJECT_NAME = "Max OS"
-PROJECT_NUMBER = 0.1
+PROJECT_NUMBER = 0.3
PROJECT_LOGO = ../Screenshots/Logo.png
OUTPUT_DIRECTORY = .
CREATE_SUBDIRS = NO
@@ -94,7 +94,7 @@ WARN_IF_UNDOCUMENTED = YES
WARN_IF_DOC_ERROR = YES
WARN_IF_INCOMPLETE_DOC = YES
WARN_NO_PARAMDOC = YES
-WARN_AS_ERROR = NO #Go thru docs again when can be bothered
+WARN_AS_ERROR = YES
WARN_FORMAT = "$file:$line: $text"
WARN_LINE_FORMAT = "at line $line of file $file"
INPUT = ../../kernel
diff --git a/kernel/include/common/macros.h b/kernel/include/common/macros.h
new file mode 100644
index 00000000..d1cf3839
--- /dev/null
+++ b/kernel/include/common/macros.h
@@ -0,0 +1,22 @@
+//
+// Created by 98max on 1/11/2025.
+//
+
+#ifndef MAXOS_COMMON_MACROS_H
+#define MAXOS_COMMON_MACROS_H
+
+namespace MaxOS{
+
+ #ifdef DOXYGEN
+ /// Ensure no padding added to the struct
+ #define PACKED
+ #else
+ /// Ensure no padding added to the struct
+ #define PACKED __attribute__((packed))
+ #endif
+
+}
+
+
+
+#endif //MAXOS_COMMON_MACROS_H
diff --git a/kernel/include/common/time.h b/kernel/include/common/time.h
index 57679ee1..92c9db8a 100644
--- a/kernel/include/common/time.h
+++ b/kernel/include/common/time.h
@@ -18,6 +18,9 @@ namespace MaxOS{
/**
* @struct Time
* @brief Stores the year, month, day, hour, minute and second of a time.
+ *
+ * @typedef time_t
+ * @brief Alias for Time struct
*/
typedef struct Time{
@@ -39,6 +42,7 @@ namespace MaxOS{
} time_t;
+ /// List of month names indexed by month number - 1
static const char* Months[] = {
"January",
"February",
@@ -54,6 +58,7 @@ namespace MaxOS{
"December"
};
+ /// List of day names starting from Sunday ending on Saturday
static const char* Days[] = {
"Sunday",
"Monday",
@@ -64,6 +69,7 @@ namespace MaxOS{
"Saturday"
};
+ /// Number of days in each month indexed by month number - 1
constexpr uint8_t DAYS_IN_MONTH[] = {
31, // January
28, // February
@@ -79,8 +85,8 @@ namespace MaxOS{
31 // December
};
- constexpr uint16_t DAYS_PER_YEAR = 365;
- constexpr uint16_t DAYS_PER_LEAP_YEAR = 366;
+ constexpr uint16_t DAYS_PER_YEAR = 365; ///< Number of days in a non-leap year
+ constexpr uint16_t DAYS_PER_LEAP_YEAR = 366; ///< Number of days in a leap year
/**
* @brief Converts a time to an epoch
diff --git a/kernel/include/drivers/clock/clock.h b/kernel/include/drivers/clock/clock.h
index 9aca511f..896ec22f 100644
--- a/kernel/include/drivers/clock/clock.h
+++ b/kernel/include/drivers/clock/clock.h
@@ -71,12 +71,17 @@ namespace MaxOS {
/**
* @struct PITCommand
* @brief The command byte to send to the PIT, specifies the channel, access mode, operating mode and BCD mode
+ *
+ * @typedef pit_command_t
+ * @brief Alias for PITCommand struct
*/
typedef struct PITCommand {
+
uint8_t bcd_mode: 1; ///< 0 = binary, 1 = BCD
uint8_t operating_mode: 3; ///< What mode the PIT should operate in
uint8_t access_mode: 2; ///< How the data is accessed
uint8_t channel: 2; ///< Which channel to configure
+
} pit_command_t;
@@ -162,7 +167,7 @@ namespace MaxOS {
string device_name() final;
static Clock* active_clock();
- common::Time get_time();
+ common::time_t get_time();
};
}
diff --git a/kernel/include/drivers/ethernet/amd_am79c973.h b/kernel/include/drivers/ethernet/amd_am79c973.h
index 80b4e910..4b89c340 100644
--- a/kernel/include/drivers/ethernet/amd_am79c973.h
+++ b/kernel/include/drivers/ethernet/amd_am79c973.h
@@ -10,107 +10,122 @@
#define MAXOS_DRIVERS_ETHERNET_AMD_AM79C973_H
#include
+#include
#include
#include
#include
#include
+namespace MaxOS {
-namespace MaxOS{
+ namespace drivers {
+
+ namespace ethernet {
+
+ /**
+ * @struct InitializationBlock
+ * @brief The initialization block for the AMD AM79C973 Ethernet Controller
+ *
+ * @typedef initialisation_block_t
+ * @brief Alias for InitializationBlock struct
+ */
+ typedef struct PACKED InitializationBlock {
- namespace drivers{
+ uint16_t mode; ///< The operation mode
+ unsigned reserved1: 4; ///< Unused, must be zero
+ unsigned numSendBuffers: 4; ///< How many buffers are used for sending
+ unsigned reserved2: 4; ///< Unused, must be zero
+ unsigned numRecvBuffers: 4; ///< How many buffers are used for receiving
+ uint64_t physicalAddress: 48; ///< The physical (MAC) address of the device (Not 64 bits but will be treated like it is)
+ uint16_t reserved3; ///< Unused, must be zero
+ uint64_t logicalAddress; ///< The logical address filter for the device to use when deciding whether to accept a packet (0 = no filtering)
+ uint32_t recvBufferDescrAddress; ///< Physical address of the first receive buffer descriptor
+ uint32_t sendBufferDescrAddress; ///< Physical address of the first send buffer descriptor
- namespace ethernet{
+ }
+ initialisation_block_t;
+ /**
+ * @struct BufferDescriptor
+ * @brief Defines the layout of a buffer descriptor for the AMD AM79C973 Ethernet Controller
+ *
+ * @typedef buffer_descriptor_t
+ * @brief Alias for BufferDescriptor struct
+ */
+ typedef struct PACKED BufferDescriptor {
- /**
- * @class AMD_AM79C973
- * @brief Driver for the AMD AM79C973 Ethernet Controller
- */
- class AMD_AM79C973 : public EthernetDriver, public hardwarecommunication::InterruptHandler{
+ uint64_t address; ///< Physical address of the buffer
+ uint32_t flags; ///< Flags for the buffer
+ uint32_t flags2; ///< Additional flags for the buffer (@todo enum this)
+ uint32_t avail; ///< Indicates whether the buffer is available to be used
- struct InitializationBlock{
+ }
+ buffer_descriptor_t;
- uint16_t mode;
- unsigned reserved1 : 4;
- unsigned numSendBuffers : 4;
- unsigned reserved2 : 4;
- unsigned numRecvBuffers : 4;
- uint64_t physicalAddress : 48; //Not 64 bits but will be treated like it is
- uint16_t reserved3;
- uint64_t logicalAddress;
- uint32_t recvBufferDescrAddress;
- uint32_t sendBufferDescrAddress;
+ /**
+ * @class AMD_AM79C973
+ * @brief Driver for the AMD AM79C973 Ethernet Controller
+ */
+ class AMD_AM79C973 : public EthernetDriver, public hardwarecommunication::InterruptHandler {
+ private:
- } __attribute__((packed));
+ //Reading the media access control address (MAC address)
+ hardwarecommunication::Port16Bit MACAddress0Port;
+ hardwarecommunication::Port16Bit MACAddress2Port;
+ hardwarecommunication::Port16Bit MACAddress4Port;
- struct BufferDescriptor{
+ //Register ports
+ hardwarecommunication::Port16Bit registerDataPort;
+ hardwarecommunication::Port16Bit registerAddressPort;
+ hardwarecommunication::Port16Bit busControlRegisterDataPort;
- uint64_t address;
- uint32_t flags;
- uint32_t flags2;
- uint32_t avail;
+ hardwarecommunication::Port16Bit resetPort;
- } __attribute__((packed));
+ //The main purpose of the initialization block it to hold a pointer to the array of BufferDescriptors, which hold the pointers to the buffers
+ initialisation_block_t initBlock { };
- //Reading the media access control address (MAC address)
- hardwarecommunication::Port16Bit MACAddress0Port;
- hardwarecommunication::Port16Bit MACAddress2Port;
- hardwarecommunication::Port16Bit MACAddress4Port;
+ buffer_descriptor_t* sendBufferDescr; //Descriptor entry
+ uint8_t sendBuffers[2 * 1024 + 15][8] { }; //8 Send Buffers, 2KB + 15 bytes
+ uint8_t currentSendBuffer; //Which buffers are active
- //Register ports
- hardwarecommunication::Port16Bit registerDataPort;
- hardwarecommunication::Port16Bit registerAddressPort;
- hardwarecommunication::Port16Bit busControlRegisterDataPort;
+ buffer_descriptor_t* recvBufferDescr; //Descriptor entry
+ uint8_t recvBuffers[2 * 1024 + 15][8] { }; //8 Send Buffers, 2KB + 15 bytes
+ uint8_t currentRecvBuffer; //Which buffers are active
- hardwarecommunication::Port16Bit resetPort;
+ //Ethernet Driver functions
+ MediaAccessControlAddress ownMAC; //MAC address of the device
+ volatile bool active; //Is the device active
+ volatile bool initDone; //Is the device initialised
- //The main purpose of the initialization block it to hold a pointer to the array of BufferDescriptors, which hold the pointers to the buffers
- InitializationBlock initBlock{};
+ void FetchDataReceived(); //Fetches the data from the buffer
+ void FetchDataSent(); //Fetches the data from the buffer
+ public:
+ AMD_AM79C973(hardwarecommunication::PeripheralComponentInterconnectDeviceDescriptor* device_descriptor);
+ ~AMD_AM79C973();
- BufferDescriptor* sendBufferDescr; //Descriptor entry
- uint8_t sendBuffers[2*1024+15][8]{}; //8 Send Buffers, 2KB + 15 bytes
- uint8_t currentSendBuffer; //Which buffers are active
+ // Override driver default methods
+ uint32_t reset() final;
+ void activate() final;
+ void deactivate() final;
- BufferDescriptor* recvBufferDescr; //Descriptor entry
- uint8_t recvBuffers[2*1024+15][8]{}; //8 Send Buffers, 2KB + 15 bytes
- uint8_t currentRecvBuffer; //Which buffers are active
+ // Naming
+ string vendor_name() final;
+ string device_name() final;
- //Ethernet Driver functions
- MediaAccessControlAddress ownMAC; //MAC address of the device
- volatile bool active; //Is the device active
- volatile bool initDone; //Is the device initialised
-
- void FetchDataReceived(); //Fetches the data from the buffer
- void FetchDataSent(); //Fetches the data from the buffer
-
- public:
- AMD_AM79C973(hardwarecommunication::PeripheralComponentInterconnectDeviceDescriptor* device_descriptor);
- ~AMD_AM79C973();
-
- //Override driver default methods
- uint32_t reset() final;
- void activate() final;
- void deactivate() final;
-
- // Naming
- string vendor_name() final;
- string device_name() final;
-
- //Override Interrupt default methods
- void handle_interrupt() final;
-
- //Ethernet Driver functions
- void DoSend(uint8_t* buffer, uint32_t size) final;
- uint64_t GetMediaAccessControlAddress() final;
- };
-
-
- }
- }
+ //Override Interrupt default methods
+ void handle_interrupt() final;
+
+ //Ethernet Driver functions
+ void DoSend(uint8_t* buffer, uint32_t size) final;
+ uint64_t GetMediaAccessControlAddress() final;
+ };
+
+
+ }
+ }
}
diff --git a/kernel/include/drivers/ethernet/ethernet.h b/kernel/include/drivers/ethernet/ethernet.h
index d38ef6a3..1d991b9f 100644
--- a/kernel/include/drivers/ethernet/ethernet.h
+++ b/kernel/include/drivers/ethernet/ethernet.h
@@ -20,6 +20,7 @@ namespace MaxOS{
namespace ethernet {
+ /// Used to make MAC addresses more readable @todo make a MacAddress class and use mac_t
typedef uint64_t MediaAccessControlAddress;
/**
diff --git a/kernel/include/drivers/ethernet/intel_i217.h b/kernel/include/drivers/ethernet/intel_i217.h
index 16041e92..911e2e5b 100644
--- a/kernel/include/drivers/ethernet/intel_i217.h
+++ b/kernel/include/drivers/ethernet/intel_i217.h
@@ -11,6 +11,7 @@
#include
#include
+#include
#include
#include
#include
@@ -25,6 +26,39 @@ namespace MaxOS{
namespace ethernet{
+ /**
+ * @struct ReceiveDescriptor
+ * @brief The receive descriptor for the Intel I217 Ethernet Controller
+ *
+ * @typedef receive_descriptor_t
+ * @brief Alias for ReceiveDescriptor struct
+ */
+ typedef struct PACKED ReceiveDescriptor {
+ uint64_t bufferAddress; ///< The address of the receive buffer
+ uint16_t length; ///< The length of the received frame
+ uint16_t checksum; ///< The checksum of the received frame
+ uint8_t status; ///< The status of the received frame
+ uint8_t errors; ///< Any errors that occurred
+ uint16_t special; ///< Special
+ } receive_descriptor_t;
+
+ /**
+ * @struct SendDescriptor
+ * @brief The send descriptor for the Intel I217 Ethernet Controller
+ *
+ * @typedef send_descriptor_t
+ * @brief Alias for SendDescriptor struct
+ */
+ typedef struct PACKED SendDescriptor {
+ uint64_t bufferAddress; ///< The address of the send buffer
+ uint16_t length; ///< The length of the send frame
+ uint8_t cso; ///< The checksum offset
+ uint8_t cmd; ///< The command
+ uint8_t status; ///< The status
+ uint8_t css; ///< The checksum start
+ uint16_t special; ///< Special
+ } send_descriptor_t;
+
/**
* @class IntelI217
@@ -32,25 +66,6 @@ namespace MaxOS{
*/
class IntelI217 : public EthernetDriver, public hardwarecommunication::InterruptHandler {
- struct receiveDescriptor {
- uint64_t bufferAddress; // The address of the receive buffer
- uint16_t length; // The length of the received frame
- uint16_t checksum; // The checksum of the received frame
- uint8_t status; // The status of the received frame
- uint8_t errors; // Any errors that occurred
- uint16_t special; // Special
- } __attribute__((packed));
-
- struct sendDescriptor {
- uint64_t bufferAddress; // The address of the send buffer
- uint16_t length; // The length of the send frame
- uint8_t cso; // The checksum offset
- uint8_t cmd; // The command
- uint8_t status; // The status
- uint8_t css; // The checksum start
- uint16_t special; // Special
- } __attribute__((packed));
-
uint8_t bar_type = { 0 };
uint16_t portBase = { 0 };
uint64_t memBase = { 0 };
diff --git a/kernel/include/drivers/peripherals/keyboard.h b/kernel/include/drivers/peripherals/keyboard.h
index 64cfe92a..def2e33d 100644
--- a/kernel/include/drivers/peripherals/keyboard.h
+++ b/kernel/include/drivers/peripherals/keyboard.h
@@ -25,12 +25,20 @@ namespace MaxOS {
namespace peripherals {
+ /**
+ * @enum ScanCodeType
+ * @brief The type of scan code being sent by the keyboard
+ */
enum class ScanCodeType : int {
REGULAR,
- EXTENDED,
+ EXTENDED,237
EXTENDED_BUFFER
};
+ /**
+ * @enum KeyCode
+ * @brief A mapping of key codes to their values
+ */
enum class KeyCode : uint16_t {
// Alphabet
@@ -213,20 +221,24 @@ namespace MaxOS {
~KeyboardState();
// Left and Right
- bool left_shift = false; ///< Is the left shift key pressed
- bool right_shift = false; ///< Is the right shift key pressed
- bool left_control = false; ///< Is the left control key pressed
- bool right_control = false; ///< Is the right control key pressed
- bool left_alt = false; ///< Is the left alt key pressed
- bool right_alt = false; ///< Is the right alt key pressed
+ bool left_shift = false; ///< Is the left shift key pressed
+ bool right_shift = false; ///< Is the right shift key pressed
+ bool left_control = false; ///< Is the left control key pressed
+ bool right_control = false; ///< Is the right control key pressed
+ bool left_alt = false; ///< Is the left alt key pressed
+ bool right_alt = false; ///< Is the right alt key pressed
// Other Stuff
- bool caps_lock = false; ///< Is caps lock enabled
- bool number_pad_lock = false; ///< Is number pad lock enabled
- bool scroll_lock = false; ///< Is scroll lock enabled
+ bool caps_lock = false; ///< Is caps lock enabled
+ bool number_pad_lock = false; ///< Is number pad lock enabled
+ bool scroll_lock = false; ///< Is scroll lock enabled
};
- enum KeyboardEvents {
+ /**
+ * @enum KeyboardEvents
+ * @brief The events that can be triggered by the Keyboard Driver
+ */
+ enum class KeyboardEvents {f
KEYDOWN,
KEYUP
};
@@ -279,11 +291,11 @@ namespace MaxOS {
class KeyboardInterpreter : public common::InputStreamEventHandler, public common::EventManager {
protected:
- KeyboardState m_keyboard_state; ///< The current state of what special keys are pressed on the keyboard
+ KeyboardState m_keyboard_state; ///< The current state of what special keys are pressed on the keyboard
- bool m_next_is_first_extended_code = false; ///< If true, the next code should be interpreted as an extended code (set when receiving 0xE0)
- uint8_t m_extended_scan_code_bytes = 0; ///< How many bytes are left to read for the current extended scan code
- uint16_t m_extended_code_buffer = 0; ///< The storage for scan codes that take more than one byte
+ bool m_next_is_first_extended_code = false; ///< If true, the next code should be interpreted as an extended code (set when receiving 0xE0)
+ uint8_t m_extended_scan_code_bytes = 0; ///< How many bytes are left to read for the current extended scan code
+ uint16_t m_extended_code_buffer = 0; ///< The storage for scan codes that take more than one byte
public:
KeyboardInterpreter();
diff --git a/kernel/include/filesystem/filesystem.h b/kernel/include/filesystem/filesystem.h
index 31b1c762..6aa44f49 100644
--- a/kernel/include/filesystem/filesystem.h
+++ b/kernel/include/filesystem/filesystem.h
@@ -17,102 +17,98 @@
#include
#include
-namespace MaxOS{
+namespace MaxOS {
- namespace filesystem{
+ namespace filesystem {
- // Easier to read
- typedef uint32_t lba_t;
- typedef syscore::filesystem::SeekType SeekType;
- /**
- * @class File
- * @brief Handles file operations and information
- */
- class File
- {
+ typedef uint32_t lba_t; ///< Logical Block Addressing type
+ typedef syscore::filesystem::SeekType SeekType; ///< Seek type for file operations
- protected:
- uint32_t m_offset; ///< The current offset in the file
- string m_name; ///< The name of the file
- size_t m_size; ///< The size of the file
+ /**
+ * @class File
+ * @brief Handles file operations and information
+ */
+ class File {
- public:
- File();
- virtual ~File();
+ protected:
+ uint32_t m_offset; ///< The current offset in the file
+ string m_name; ///< The name of the file
+ size_t m_size; ///< The size of the file
- virtual void write(const common::buffer_t* data, size_t size);
- virtual void read(common::buffer_t* data, size_t size);
- virtual void flush();
+ public:
+ File();
+ virtual ~File();
- void seek(SeekType seek_type, size_t offset);
- uint32_t position();
+ virtual void write(const common::buffer_t* data, size_t size);
+ virtual void read(common::buffer_t* data, size_t size);
+ virtual void flush();
- size_t size();
- string name();
- };
+ void seek(SeekType seek_type, size_t offset);
+ uint32_t position();
+ size_t size();
+ string name();
+ };
- /**
- * @class Directory
- * @brief Handles a group of files (directory)
- */
- class Directory
- {
- protected:
- common::Vector m_files; ///< The files in this directory
- common::Vector m_subdirectories; ///< The subdirectories in this directory
+ /**
+ * @class Directory
+ * @brief Handles a group of files (directory)
+ */
+ class Directory {
+ protected:
+ common::Vector m_files; ///< The files in this directory
+ common::Vector m_subdirectories; ///< The subdirectories in this directory
- string m_name; ///< The name of this directory
+ string m_name; ///< The name of this directory
- public:
- Directory();
- virtual ~Directory();
+ public:
+ Directory();
+ virtual ~Directory();
- virtual void read_from_disk();
+ virtual void read_from_disk();
- common::Vector files();
- common::Vector subdirectories();
+ common::Vector files();
+ common::Vector subdirectories();
- File* open_file(const string& name);
- Directory* open_subdirectory(const string& name);
+ File* open_file(const string &name);
+ Directory* open_subdirectory(const string &name);
- virtual File* create_file(const string& name);
- virtual void remove_file(const string& name);
+ virtual File* create_file(const string &name);
+ virtual void remove_file(const string &name);
- void rename_file(File* file, const string& new_name);
- virtual void rename_file(const string& old_name, const string& new_name);
+ void rename_file(File* file, const string &new_name);
+ virtual void rename_file(const string &old_name, const string &new_name);
- void rename_subdirectory(Directory* directory, const string& new_name);
- virtual void rename_subdirectory(const string& old_name, const string& new_name);
+ void rename_subdirectory(Directory* directory, const string &new_name);
+ virtual void rename_subdirectory(const string &old_name, const string &new_name);
- virtual Directory* create_subdirectory(const string& name);
- virtual void remove_subdirectory(const string& name);
+ virtual Directory* create_subdirectory(const string &name);
+ virtual void remove_subdirectory(const string &name);
- string name();
- size_t size();
- };
+ string name();
+ size_t size();
+ };
- /**
- * @class FileSystem
- * @brief Handles the disk operations and file system information
- */
- class FileSystem
- {
- protected:
- Directory* m_root_directory; ///< The fist directory in the file system (not be confused with the system root)
+ /**
+ * @class FileSystem
+ * @brief Handles the disk operations and file system information
+ */
+ class FileSystem {
+ protected:
+ Directory* m_root_directory; ///< The fist directory in the file system (not be confused with the system root)
- public:
- FileSystem();
- virtual ~FileSystem();
+ public:
+ FileSystem();
+ virtual ~FileSystem();
- Directory* root_directory();
- Directory* get_directory(const string& path);
+ Directory* root_directory();
+ Directory* get_directory(const string &path);
- bool exists(const string& path);
- };
+ bool exists(const string &path);
+ };
- }
+ }
}
diff --git a/kernel/include/filesystem/format/ext2.h b/kernel/include/filesystem/format/ext2.h
index 35c13f22..831128f1 100644
--- a/kernel/include/filesystem/format/ext2.h
+++ b/kernel/include/filesystem/format/ext2.h
@@ -9,12 +9,13 @@
#ifndef MAXOS_FILESYSTEM_EXT2_H
#define MAXOS_FILESYSTEM_EXT2_H
-#include
-#include
#include
-#include
#include
+#include
+#include
#include
+#include
+#include
namespace MaxOS {
namespace filesystem {
@@ -24,8 +25,11 @@ namespace MaxOS {
/**
* @struct SuperBlock
* @brief The metadata of the ext2 filesystem. Found at an offset of 1024 bytes from the start of the partition.
+ *
+ * @typedef superblock_t
+ * @brief Alias for SuperBlock struct
*/
- typedef struct SuperBlock {
+ typedef struct PACKED SuperBlock {
uint32_t total_inodes; ///< Total number of inodes
uint32_t total_blocks; ///< Total number of blocks
uint32_t reserved_blocks; ///< Number of reserved blocks for superuser
@@ -72,7 +76,7 @@ namespace MaxOS {
uint32_t orphan_inodes_start; ///< The start of the list of inodes without a directory entry that need to be deleted
uint8_t free[276]; ///< Reserved for future expansion
- } __attribute__((packed)) superblock_t;
+ } superblock_t;
/**
* @enum FileSystemState
@@ -145,9 +149,12 @@ namespace MaxOS {
* @struct BlockGroupDescriptor
* @brief The metadata for a block group in ext2
*
+ * @typedef block_group_descriptor_t
+ * @brief Alias for BlockGroupDescriptor struct
+ *
* @todo Support updating directory_count when creating/deleting directories
*/
- typedef struct BlockGroupDescriptor {
+ typedef struct PACKED BlockGroupDescriptor {
uint32_t block_usage_bitmap; ///< The block address of the block usage bitmap
uint32_t block_inode_bitmap; ///< The block address of the inode usage bitmap
uint32_t inode_table_address; ///< The starting block address of the inode table
@@ -156,13 +163,16 @@ namespace MaxOS {
uint16_t directory_count; ///< How many directories are in this block group
uint8_t free[14]; ///< Reserved for future expansion
- } __attribute__((packed)) block_group_descriptor_t;
+ } block_group_descriptor_t;
/**
* @struct Inode
* @brief The metadata for a file or directory in ext2
+ *
+ * @typedef inode_t
+ * @brief Alias for Inode struct
*/
- typedef struct Inode {
+ typedef struct PACKED Inode {
union {
uint16_t type_permissions; ///< The type and permissions of the inode
struct {
@@ -189,7 +199,7 @@ namespace MaxOS {
uint32_t extended_attribute; ///< File extended attribute block (Access Control List)
uint32_t size_upper; ///< The upper 32 bits of the size of the file in bytes (for files larger than 4GB). If this is a directory, this is the Directory Access Control List.
uint32_t os_2[3]; ///< Second OS specific value (see InodeOS2Linux, ...)
- } __attribute__((packed)) inode_t;
+ } inode_t;
/**
* @enum InodeType
@@ -258,28 +268,34 @@ namespace MaxOS {
* @struct InodeOS2Linux
* @brief The OS specific data for Linux created ext2 inodes
*
+ * @typedef linux_os_2_t
+ * @brief Alias for InodeOS2Linux struct
+ *
* @todo HURD, MASIX
*/
- typedef struct InodeOS2Linux {
+ typedef struct PACKED InodeOS2Linux {
uint8_t fragment; ///< The fragment number
uint8_t fragment_size; ///< How many 1024 byte fragments are in the file
uint16_t high_type_permissions; ///< The high bits of the type & permissions
uint16_t high_user_id; ///< The high bits of the user ID
uint16_t high_group_id; ///< The high bits of the group ID
uint32_t author_id; ///< The user who created the inode (0xFFFFFFFF if use UID/GID fields)
- } __attribute__((packed)) linux_os_2_t;
+ } linux_os_2_t;
/**
* @struct DirectoryEntry
* @brief An entry in a directory that points to a file or subdirectory (the name follows this struct)
+ *
+ * @typedef directory_entry_t
+ * @brief Alias for DirectoryEntry struct
*/
- typedef struct DirectoryEntry {
+ typedef struct PACKED DirectoryEntry {
uint32_t inode; ///< The inode number this entry points to (0 = unused)
uint16_t size; ///< The total size of this entry (including name)
uint8_t name_length; ///< The length of the name
uint8_t type; ///< The type of the entry (see EntryType) (only if the high bit of the superblock's optional_features is set)
// Rest are name chars
- } __attribute__((packed)) directory_entry_t;
+ } directory_entry_t;
/**
* @enum EntryType
diff --git a/kernel/include/filesystem/format/fat32.h b/kernel/include/filesystem/format/fat32.h
index d3fb8325..aef84795 100644
--- a/kernel/include/filesystem/format/fat32.h
+++ b/kernel/include/filesystem/format/fat32.h
@@ -13,19 +13,23 @@
#ifndef MAXOS_FILESYSTEM_FAT32_H
#define MAXOS_FILESYSTEM_FAT32_H
+#include
+#include
#include
#include
-#include
namespace MaxOS {
namespace filesystem {
namespace format {
/**
- * @struct BiosParameterBlock32
- * @brief Stores information about the FAT32 filesystem
- */
- typedef struct BiosParameterBlock32 {
+ * @struct BiosParameterBlock32
+ * @brief Stores information about the FAT32 filesystem
+ *
+ * @typedef bpb32_t
+ * @brief Alias for BiosParameterBlock32 struct
+ */
+ typedef struct PACKED BiosParameterBlock32 {
uint8_t jump[3]; ///< Jump instruction to boot code
uint8_t OEM_name[8]; ///< OEM Name in ASCII
@@ -56,13 +60,16 @@ namespace MaxOS {
uint8_t volume_label[11]; ///< Volume label in ASCII (spaces padded)
uint8_t file_system_type[8]; ///< System type in ASCII (not null-terminated)
- } __attribute__((packed)) bpb32_t;
+ } bpb32_t;
/**
* @struct FSInfo
* @brief Stores extra information about the FAT32 filesystem
+ *
+ * @typedef fs_info_t
+ * @brief Alias for FSInfo struct
*/
- typedef struct FSInfo {
+ typedef struct PACKED FSInfo {
uint32_t lead_signature; ///< FSInfo lead signature (0x41615252)
uint8_t reserved1[480]; ///< Reserved (should be zero)
uint32_t structure_signature; ///< FSInfo structure signature (0x61417272)
@@ -70,13 +77,16 @@ namespace MaxOS {
uint32_t next_free_cluster; ///< Cluster number of the next free cluster (or 0xFFFFFFFF if unknown, start searching from cluster 2)
uint8_t reserved2[12]; ///< Reserved (should be zero)
uint32_t trail_signature; ///< FSInfo trail signature (0xAA550000)
- } __attribute__((packed)) fs_info_t;
+ } fs_info_t;
/**
* @struct DirectoryEntry
* @brief Stores information about a file or directory
+ *
+ * @typedef dir_entry_t
+ * @brief Alias for DirectoryEntry struct
*/
- typedef struct DirectoryEntry {
+ typedef struct PACKED DirectoryEntry {
uint8_t name[8]; ///< File name
uint8_t extension[3]; ///< File extension
@@ -97,7 +107,7 @@ namespace MaxOS {
uint32_t size; ///< File size in bytes
- } __attribute__((packed)) dir_entry_t;
+ } dir_entry_t;
/**
* @enum DirectoryEntryAttributes
@@ -126,8 +136,11 @@ namespace MaxOS {
/**
* @struct LongFileNameEntry
* @brief Directory entry for a long file name
+ *
+ * @typedef long_file_name_entry_t
+ * @brief Alias for LongFileNameEntry struct
*/
- typedef struct LongFileNameEntry {
+ typedef struct PACKED LongFileNameEntry {
uint8_t order; ///< Index of this entry in the sequence of LFN entries
uint16_t name1[5]; ///< First 5 characters of the long file name
uint8_t attributes; ///< Attributes (always 0x0F for LFN entries)
@@ -137,7 +150,7 @@ namespace MaxOS {
uint16_t zero; ///< Must be zero
uint16_t name3[2]; ///< Last 2 characters of the long file name
- } __attribute__((packed)) long_file_name_entry_t;
+ } long_file_name_entry_t;
/**
* @enum ClusterState
diff --git a/kernel/include/filesystem/partition/msdos.h b/kernel/include/filesystem/partition/msdos.h
index 6165a885..7eb5c36c 100644
--- a/kernel/include/filesystem/partition/msdos.h
+++ b/kernel/include/filesystem/partition/msdos.h
@@ -21,7 +21,6 @@ namespace MaxOS {
namespace partition {
-
/// Credit: http://www.osdever.net/documents/pdf/partitiontypes.pdf
enum class PartitionType {
EMPTY, // 0x00
@@ -302,8 +301,11 @@ namespace MaxOS {
/**
* @struct PartitionTableEntry
* @brief Stores information about a partition
+ *
+ * @typedef partition_table_entry_t
+ * @brief Alias for PartitionTableEntry struct
*/
- struct PartitionTableEntry {
+ typedef struct PACKED PartitionTableEntry {
uint8_t bootable; ///< Is this partition bootable? (0x80 = bootable, 0x00 = not bootable)
@@ -320,13 +322,16 @@ namespace MaxOS {
uint32_t start_LBA; ///< The starting LBA of the partition
uint32_t length; ///< The length of the partition in sectors
- } __attribute__((packed));
+ } partition_table_entry_t;
/**
* @struct MasterBootRecord
* @brief Stores information about the master boot record
+ *
+ * @typedef master_boot_record_t
+ * @brief Alias for MasterBootRecord struct
*/
- struct MasterBootRecord {
+ typedef struct PACKED MasterBootRecord {
uint8_t bootloader[440]; ///< The assembly bytes that make up the bootloader software
uint32_t disk_signature; ///< Unique disk signature (optional)
@@ -336,7 +341,7 @@ namespace MaxOS {
uint16_t magic; ///< The magic number that identifies this as a valid MBR (0xAA55)
- } __attribute__((packed));
+ } master_boot_record_t;
/**
diff --git a/kernel/include/gui/widget.h b/kernel/include/gui/widget.h
index 87bbe515..9d4656bb 100644
--- a/kernel/include/gui/widget.h
+++ b/kernel/include/gui/widget.h
@@ -135,23 +135,20 @@ namespace MaxOS{
};
- typedef WidgetMoverResizer<1, 1, 0, 0> WidgetMover;
+ typedef WidgetMoverResizer<1, 1, 0, 0> WidgetMover; ///< A widget mover that moves the widget without resizing it
- typedef WidgetMoverResizer<0, 1, 0, -1> WidgetMoverResizerTop;
- typedef WidgetMoverResizer<0, 0, 0, 1> WidgetMoverResizerBottom;
- typedef WidgetMoverResizer<1, 0, -1, 0> WidgetMoverResizerLeft;
- typedef WidgetMoverResizer<0, 0, 1, 0> WidgetMoverResizerRight;
+ typedef WidgetMoverResizer<0, 1, 0, -1> WidgetMoverResizerTop; ///< A widget mover and resizer that resizes the top edge of the widget
+ typedef WidgetMoverResizer<0, 0, 0, 1> WidgetMoverResizerBottom; ///< A widget mover andresizer that resizes the bottom edge of the widget
+ typedef WidgetMoverResizer<1, 0, -1, 0> WidgetMoverResizerLeft; ///< A widget mover and resizer that resizes the left edge of the widget
+ typedef WidgetMoverResizer<0, 0, 1, 0> WidgetMoverResizerRight; ///< A widget mover and resizer that resizes the right edge of the widget
- typedef WidgetMoverResizer<1, 1, -1, -1> WidgetMoverResizerTopLeft;
- typedef WidgetMoverResizer<0, 1, 1, -1> WidgetMoverResizerTopRight;
- typedef WidgetMoverResizer<1, 0, -1, 1> WidgetMoverResizerBottomLeft;
- typedef WidgetMoverResizer<0, 0, 1, 1> WidgetMoverResizerBottomRight;
+ typedef WidgetMoverResizer<1, 1, -1, -1> WidgetMoverResizerTopLeft; ///< A widget mover and resizer that resizes the top-left corner of the widget
+ typedef WidgetMoverResizer<0, 1, 1, -1> WidgetMoverResizerTopRight; ///< A widget mover and resizer that resizes the top-right corner of the widget
+ typedef WidgetMoverResizer<1, 0, -1, 1> WidgetMoverResizerBottomLeft; ///< A widget mover and resizer that resizes the bottom-left corner of the widget
+ typedef WidgetMoverResizer<0, 0, 1, 1> WidgetMoverResizerBottomRight; ///< A widget mover and resizer that resizes the bottom-right corner of the widget
-
- ///________________________________Tempaltes________________________________///
+ ////@TODO move this to the cpp file
/**
-
-
* @details WidgetMoverResizer is a template class that allows you to move and resize a widget
*
* @tparam Left The left edge of the widget
diff --git a/kernel/include/hardwarecommunication/acpi.h b/kernel/include/hardwarecommunication/acpi.h
index aa7beb77..542be048 100644
--- a/kernel/include/hardwarecommunication/acpi.h
+++ b/kernel/include/hardwarecommunication/acpi.h
@@ -22,33 +22,42 @@ namespace MaxOS {
/**
* @struct RSDPDescriptor
- * @brief Root System Description Pointer (RSDP) structure for ACPI 1. Ide
+ * @brief Root System Description Pointer (RSDP) structure for ACPI 1.
+ *
+ * @typedef rsdp_descriptor_t
+ * @brief Alias for RSDPDescriptor struct
*/
- typedef struct RSDPDescriptor {
+ typedef struct PACKED RSDPDescriptor {
char signature[8]; ///< Indicates a valid RSDP structure if it contains "RSD PTR " (null-terminated)
uint8_t checksum; ///< This byte added to all bytes in the table must equal zero for the table to be valid
char OEMID[6]; ///< A string supplied by the OEM to identify the OEM
uint8_t revision; ///< The version of the ACPI specification that is supported (higher means more features and is backwards compatible)
uint32_t rsdt_address; ///< The physical address of the RSDT (@deprecated in ACPI 2 and above)
- } __attribute__ ((packed)) rsdp_descriptor_t;
+ } rsdp_descriptor_t;
/**
* @struct RSDPDescriptor2
* @brief Root System Description Pointer (RSDP) structure for ACPI 2 and above
+ *
+ * @typedef rsdp_descriptor2_t
+ * @brief Alias for RSDPDescriptor2 struct
*/
- typedef struct RSDPDescriptor2 {
+ typedef struct PACKED RSDPDescriptor2 {
RSDPDescriptor version_1_info; ///< The ACPI 1 RSDP structure (see rsdp_descriptor_t)
uint32_t length; ///< The total length of the RSDP structure (including the version 1 part)
uint64_t xsdt_address; ///< The physical address of the XSDT
uint8_t extended_checksum; ///< This byte added to all bytes in the table must equal zero for the table to be valid (including the version 1 part)
uint8_t reserved[3]; ///< Reserved, must be zero
- } __attribute__ ((packed)) rsdp_descriptor2_t;
+ } rsdp_descriptor2_t;
/**
* @struct ACPISDTHeader
* @brief Common header for all ACPI System Description Tables (SDTs)
+ *
+ * @typedef acpi_sdt_header_t
+ * @brief Alias for ACPISDTHeader struct
*/
- typedef struct ACPISDTHeader {
+ typedef struct PACKED ACPISDTHeader {
char signature[4]; ///< The signature that identifies the type of the table
uint32_t length; ///< The size of the entire table, including the header, in bytes
uint8_t revision; ///< The version of the ACPI specification that is supported (higher means more features and is backwards compatible)
@@ -58,11 +67,14 @@ namespace MaxOS {
uint32_t OEM_revision; ///< The revision number of the table as supplied by the OEM
uint32_t creator_id; ///< A vendor ID of the utility that created the table
uint32_t creator_revision; ///< The revision number of the utility that created the table
- } __attribute__ ((packed)) acpi_sdt_header_t;
+ } acpi_sdt_header_t;
/**
* @struct RSDT
* @brief Root System Description Table (RSDT) structure for ACPI 1. Contains the header and an array of pointers to other SDTs
+ *
+ * @typedef rsdt_t
+ * @brief Alias for RSDT struct
*/
typedef struct RSDT {
ACPISDTHeader header; ///< The common header for all ACPI SDTs (see acpi_sdt_header_t)
@@ -72,6 +84,9 @@ namespace MaxOS {
/**
* @struct XSDT
* @brief Extended System Description Table (XSDT) structure for ACPI 2 and above. Contains the header and an array of pointers to other SDTs
+ *
+ * @typedef xsdt_t
+ * @brief Alias for XSDT struct
*/
typedef struct XSDT {
ACPISDTHeader header; ///< The common header for all ACPI SDTs (see acpi_sdt_header_t)
diff --git a/kernel/include/hardwarecommunication/apic.h b/kernel/include/hardwarecommunication/apic.h
index dfe4371f..f9ee9e50 100644
--- a/kernel/include/hardwarecommunication/apic.h
+++ b/kernel/include/hardwarecommunication/apic.h
@@ -9,6 +9,7 @@
#ifndef MAXOS_HARDWARECOMMUNICATION_APIC_H
#define MAXOS_HARDWARECOMMUNICATION_APIC_H
+#include
#include
#include
#include
@@ -47,21 +48,27 @@ namespace MaxOS {
* @struct MADT
* @brief Multiple APIC Description Table (MADT) (ACPI 2 or higher). Provides information about the APICs in
* the system. Following this header are multiple entries describing the APICs (see MADTEntry).
+ *
+ * @typedef madt_t
+ * @brief Alias for MADT struct
*/
- typedef struct MADT {
+ typedef struct PACKED MADT {
ACPISDTHeader header; ///< Common ACPI SDT header
uint32_t local_apic_address; ///< The physical address of the local APIC
uint32_t flags; ///< Flags indicating the capabilities of the system (1 = Legacy PICs are present)
- } __attribute__((packed)) madt_t;
+ } madt_t;
/**
* @struct MADTEntry
* @brief An item in the MADT table
+ *
+ * @typedef madt_entry_t
+ * @brief Alias for MADTEntry struct
*/
- typedef struct MADTEntry {
+ typedef struct PACKED MADTEntry {
uint8_t type; ///< The type of the MADT entry (see MADT_TYPE)
uint8_t length; ///< How many bytes this entry takes up (including the type and length fields)
- } __attribute__((packed)) madt_entry_t;
+ } madt_entry_t;
/**
* @enum MADT_TYPE
@@ -81,31 +88,40 @@ namespace MaxOS {
* @struct MADT_IO_APIC
* @brief An entry in the MADT table describing an IO APIC
*
+ * @typedef madt_io_apic_t
+ * @brief Alias for MADT_IO_APIC struct
+ *
* @todo Rename for consistency
*/
- typedef struct MADT_IO_APIC {
+ typedef struct PACKED MADT_IO_APIC {
uint8_t io_apic_id; ///< The ID of the IO APIC
uint8_t reserved; ///< Reserved
uint32_t io_apic_address; ///< The physical address of the IO APIC
uint32_t global_system_interrupt_base; ///< The first GSI number that this IO APIC handles
- } __attribute__((packed)) madt_io_apic_t;
+ } madt_io_apic_t;
/**
* @struct MADT_PROCESSOR_APIC
* @brief An entry in the MADT table describing a processor local APIC
+ *
+ * @typedef madt_processor_apic_t
+ * @brief Alias for MADT_PROCESSOR_APIC struct
*/
- typedef struct MADT_PROCESSOR_APIC {
+ typedef struct PACKED MADT_PROCESSOR_APIC {
uint8_t processor_id; ///< The ID for the core
uint8_t apic_id; ///< The ID for the APIC that the core uses
uint32_t flags; ///< Flags indicating the status of the core (bit 0 = core enabled, bit 1 = can be enabled)
- } __attribute__((packed)) madt_processor_apic_t;
+ } madt_processor_apic_t;
/**
- * @struct RedirectionEntry
+ * @union RedirectionEntry
* @brief An IO APIC redirection entry. Describes how an interrupt is routed.
+ *
+ * @typedef redirection_entry_t
+ * @brief Alias for RedirectionEntry union
*/
typedef union RedirectionEntry {
- struct {
+ struct PACKED {
uint64_t vector: 8; ///< The interrupt that will be triggered when this redirection entry is used
uint64_t delivery_mode: 3; ///< How the interrupt will be delvied to the core(s) (see DeliveryMode)
uint64_t destination_mode: 1; ///< How to interpret the destination field (0 = means its the core ID, 1 = means a bitmask of cores)
@@ -116,7 +132,7 @@ namespace MaxOS {
uint64_t mask: 1; ///< Whether the interrupt is disabled or not
uint64_t reserved: 39; ///< Reserved bits (should be zero)
uint64_t destination: 8; ///< The core(s) the interrupt should be sent to (interpreted based on destination_mode)
- } __attribute__((packed)); ///< Packed because the bitfields should be one uint64_t together
+ }; ///< Packed because the bitfields should be one uint64_t together
uint64_t raw; ///< The raw 64-bit value of the redirection entry
} redirection_entry_t;
@@ -139,8 +155,12 @@ namespace MaxOS {
/**
* @struct InterruptRedirect
* @brief Defines how an interrupt input is redirected to a specific processor via the I/O APIC
+ *
+ * @typedef interrupt_redirect_t
+ * @brief Alias for InterruptRedirect struct
*/
typedef struct InterruptRedirect {
+
uint8_t type; ///< The type of redirect (should be 0 for normal interrupts)
uint8_t index; ///< Where in the IO APIC redirection table this redirect should be placed
uint8_t interrupt; ///< The interrupt number to trigger when this redirect is used
@@ -153,13 +173,18 @@ namespace MaxOS {
/**
* @struct Override
* @brief Specifies how a specific interrupt source is mapped to a global system interrupt
+ *
+ * @typedef override_t
+ * @brief Alias for Override struct
*/
- typedef struct Override {
+ typedef struct PACKED Override {
+
uint8_t bus; ///< Identifies the hardware bus the interrupt comes from (0 = ISA, 1 = PCI)
uint8_t source; ///< The interrupt source number on the specified bus
uint32_t global_system_interrupt; ///< The global system interrupt that the source is mapped to
uint16_t flags; ///< Flags describing the polarity and trigger mode of the interrupt source (see MADT override flags)
- } __attribute__((packed)) override_t;
+
+ } override_t;
/**
* @class IOAPIC
diff --git a/kernel/include/hardwarecommunication/interrupts.h b/kernel/include/hardwarecommunication/interrupts.h
index 6768ce6a..95d0c56d 100644
--- a/kernel/include/hardwarecommunication/interrupts.h
+++ b/kernel/include/hardwarecommunication/interrupts.h
@@ -22,7 +22,6 @@
namespace MaxOS {
namespace hardwarecommunication {
-
class InterruptManager;
/**
@@ -45,17 +44,24 @@ namespace MaxOS {
/**
* @struct IDTR
* @brief A struct that holds the Interrupt Descriptor Table Register (IDTR)
+ *
+ * @typedef idtr_t
+ * @brief Alias for IDTR struct
*/
- typedef struct IDTR {
+ typedef struct PACKED IDTR {
uint16_t limit; ///< The size of the IDT
uint64_t base; ///< The start address of the IDT
- } __attribute__((packed)) idtr_t;
+ } idtr_t;
- /**
+ /**
* @struct InterruptDescriptor
* @brief An entry in the Interrupt Descriptor Table (IDT)
+ *
+ * @typedef interrupt_descriptor_t
+ * @brief Alias for InterruptDescriptor struct
*/
- typedef struct InterruptDescriptor{
+ typedef struct PACKED InterruptDescriptor{
+
uint16_t address_low_bits; ///< The low bits of the handler function address
uint16_t segment_selector; ///< The code segment selector in the GDT to use when this interrupt fires
uint8_t ist; ///< The offset into the Interrupt Stack Table (0 if not used) (see TSS)
@@ -63,7 +69,8 @@ namespace MaxOS {
uint16_t address_mid_bits; ///< The middle bits of the handler function address
uint32_t address_high_bits; ///< The high bits of the handler function address
uint32_t reserved; ///< Reserved, must be zero
- } __attribute__((packed)) interrupt_descriptor_t;
+
+ } interrupt_descriptor_t;
constexpr uint16_t HARDWARE_INTERRUPT_OFFSET = 0x20; ///< The offset in the IDT where interrupts from hardware start
constexpr uint16_t MAX_INTERRUPT_HANDLERS = 256; ///< The maximum number of interrupt handlers
diff --git a/kernel/include/memory/physical.h b/kernel/include/memory/physical.h
index 72f1f6bf..1aeceeb2 100644
--- a/kernel/include/memory/physical.h
+++ b/kernel/include/memory/physical.h
@@ -11,6 +11,7 @@
#include
#include
+#include
#include
#include
@@ -19,23 +20,25 @@ namespace MaxOS {
namespace memory {
- #define ENTRIES_TO_ADDRESS(pml4, pdpr, pd, pt)((pml4 << 39) | (pdpr << 30) | (pd << 21) | (pt << 12))
- #define PMLX_GET_INDEX(ADDR, LEVEL) (((uint64_t)ADDR & ((uint64_t)0x1ff << (12 + LEVEL * 9))) >> (12 + LEVEL * 9))
+ #define ENTRIES_TO_ADDRESS(pml4, pdpr, pd, pt)((pml4 << 39) | (pdpr << 30) | (pd << 21) | (pt << 12)) ///< Convert page map level indices to a virtual address
+ #define PMLX_GET_INDEX(ADDR, LEVEL) (((uint64_t)ADDR & ((uint64_t)0x1ff << (12 + LEVEL * 9))) >> (12 + LEVEL * 9)) ///< Get the index for a given page map level from a virtual address
- #define PML4_GET_INDEX(ADDR) PMLX_GET_INDEX(ADDR, 3)
- #define PML3_GET_INDEX(ADDR) PMLX_GET_INDEX(ADDR, 2)
- #define PML2_GET_INDEX(ADDR) PMLX_GET_INDEX(ADDR, 1)
- #define PML1_GET_INDEX(ADDR) PMLX_GET_INDEX(ADDR, 0)
+ #define PML4_GET_INDEX(ADDR) PMLX_GET_INDEX(ADDR, 3) ///< Get the PML4 index from a virtual address
+ #define PML3_GET_INDEX(ADDR) PMLX_GET_INDEX(ADDR, 2) ///< Get the PDPT index from a virtual address
+ #define PML2_GET_INDEX(ADDR) PMLX_GET_INDEX(ADDR, 1) ///< Get the PDP index from a virtual address
+ #define PML1_GET_INDEX(ADDR) PMLX_GET_INDEX(ADDR, 0) ///< Get the PT index from a virtual address
- // Useful for readability
- typedef void virtual_address_t;
- typedef void physical_address_t;
+ typedef void virtual_address_t; ///< A type representing a virtual address (used for readability)
+ typedef void physical_address_t; ///< A type representing a physical address (used for readability)
/**
* @enum PageFlags
* @brief Flags for page table entries
*
- * @todo: fix. this is stupid. Leave as enum not enum class for bitwise operations
+ * @typedef page_flags_t
+ * @brief Alias for PageFlags enum
+ *
+ * @todo: fix. this is stupid: Leave as enum not enum class for bitwise operations
*/
typedef enum PageFlags {
NONE = 0, ///< No flags
@@ -54,8 +57,12 @@ namespace MaxOS {
/**
* @struct PageTableEntry
* @brief Struct for a page table entry
+ *
+ * @typedef pte_t
+ * @brief Alias for PageTableEntry struct
*/
- typedef struct PageTableEntry {
+ typedef struct PACKED PageTableEntry {
+
bool present: 1; ///< *copydoc PageFlags::PRESENT
bool write: 1; ///< *copydoc PageFlags::WRITE
bool user: 1; ///< *copydoc PageFlags::USER
@@ -67,16 +74,21 @@ namespace MaxOS {
bool global: 1; ///< *copydoc PageFlags::GLOBAL
uint8_t available: 3; ///< Extra metadata bytes available for OS use
uint64_t physical_address: 52; ///< The address the page represents in memory
- } __attribute__((packed)) pte_t;
+
+ } pte_t;
/**
* @struct PageMapLevel
* @brief Struct for a page map level (PML4, PDPT, PD, PT)
+ *
+ * @typedef pml_t
+ * @brief Alias for PageMapLevel struct
*/
- typedef struct PageMapLevel {
+ typedef struct PACKED PageMapLevel {
+
pte_t entries[512]; ///< The entries in this page map level. If it is a PT then these are page table entries, otherwise they are pointers to the next level. Indexed by the relevant bits in the virtual address.
- } __attribute__((packed)) pml_t;
+ } pml_t;
constexpr uint64_t PAGE_SIZE = 0x1000; ///< The size of a page (4KB)
constexpr uint8_t ROW_BITS = 64; ///< The number of bits in the bitmap row
@@ -114,7 +126,7 @@ namespace MaxOS {
uint64_t* m_pml4_root_address;
pte_t* m_pml4_root;
- bool m_initialized;
+ bool m_initialised;
bool m_nx_allowed;
common::Spinlock m_lock;
diff --git a/kernel/include/memory/virtual.h b/kernel/include/memory/virtual.h
index 577ddcf2..98489ddb 100644
--- a/kernel/include/memory/virtual.h
+++ b/kernel/include/memory/virtual.h
@@ -22,10 +22,14 @@ namespace MaxOS {
* @enum VirtualFlags
* @brief Flags for chunks used in virtual memory allocation
*
+ * @typedef virtual_flags_t
+ * @brief Alias for VirtualFlags enum
+ *
* @see PageFlags
* @note 0 - (1 << 8) are reserved for the page flags
*/
typedef enum VirtualFlags {
+
RESERVE = (1 << 9), ///< Reserve the memory but do not map any physical memory to it
SHARED = (1 << 10), ///< The memory is shared between multiple processes
@@ -35,9 +39,13 @@ namespace MaxOS {
* @struct VirtualMemoryChunk
* @brief A container for a region of virtual memory that has been allocated by the Virtual Memory Manager
*
+ * @typedef virtual_memory_chunk_t
+ * @brief Alias for VirtualMemoryChunk struct
+ *
* @see VirtualFlags
*/
typedef struct VirtualMemoryChunk {
+
uintptr_t start_address; ///< The first virtual address that this chunk covers
size_t size; ///< The size of the chunk's memory region in bytes
size_t flags; ///< The flags for the memory (see VirtualFlags)
@@ -47,26 +55,37 @@ namespace MaxOS {
/**
* @struct FreeChunk
* @brief A chunk of memory that has been freed and is available for allocation. A node in a linked list.
+ *
+ * @typedef free_chunk_t
+ * @brief Alias for FreeChunk struct
*/
typedef struct FreeChunk {
+
uintptr_t start_address; ///< *copydoc VirtualMemoryChunk::start_address
size_t size; ///< *copydoc VirtualMemoryChunk::size
struct FreeChunk* next; ///< Pointer to the next free chunk in the list (not sequential in memory)
+
} free_chunk_t;
- static const size_t CHUNKS_PER_PAGE = PAGE_SIZE / sizeof(virtual_memory_chunk_t) - 1; ///< Number of chunks per virtual memory region (limited to fit in one page)
+ static const size_t CHUNKS_PER_PAGE = PAGE_SIZE / sizeof(virtual_memory_chunk_t) -
+ 1; ///< Number of chunks per virtual memory region (limited to fit in one page)
static const size_t VMM_RESERVED = 0x138000000; ///< The starting address for the VMM to start allocating from when in higher half (otherwise can cause conflicts with kernel space)
/**
* @struct VirtualMemoryRegion
* @brief A region of virtual memory containing multiple chunks (should fit in one page).
*
+ * @typedef virtual_memory_region_t
+ * @brief Alias for VirtualMemoryRegion struct
+ *
* @note This stores the metadata for the chunks, not the actual memory they represent. (ie chunks are not slices of this region)
*/
- typedef struct VirtualMemoryRegion {
+ typedef struct PACKED VirtualMemoryRegion {
+
virtual_memory_chunk_t chunks[CHUNKS_PER_PAGE]; ///< The metadata for the chunks in this region
struct VirtualMemoryRegion* next; ///< Pointer to the next region in the list
- } __attribute__((packed)) virtual_memory_region_t;
+
+ } virtual_memory_region_t;
/**
* @class VirtualMemoryManager
@@ -92,7 +111,6 @@ namespace MaxOS {
void new_region();
void fill_up_to_address(uintptr_t address, size_t flags, bool mark_used);
-
public:
VirtualMemoryManager();
~VirtualMemoryManager();
diff --git a/kernel/include/net/arp.h b/kernel/include/net/arp.h
index c8282e11..c4e71b9a 100644
--- a/kernel/include/net/arp.h
+++ b/kernel/include/net/arp.h
@@ -20,8 +20,11 @@ namespace MaxOS {
/**
* @struct ARPMessage
* @brief An ARP message
+ *
+ * @typedef arp_message_t
+ * @brief Alias for ARPMessage struct
*/
- struct ARPMessage {
+ typedef struct PACKED ARPMessage {
uint16_t hardwareType; ///< The type of device that sent the ARP message (1 = Ethernet)
uint16_t protocol; ///< The protocol being used (0x0800 = IPv4)
@@ -36,7 +39,7 @@ namespace MaxOS {
uint32_t dstIP; ///< The IP address of the target
- }__attribute__((packed));
+ } arp_message_t;
/**
* @class AddressResolutionProtocol
diff --git a/kernel/include/net/ethernetframe.h b/kernel/include/net/ethernetframe.h
index 7476b5e9..e6c36937 100644
--- a/kernel/include/net/ethernetframe.h
+++ b/kernel/include/net/ethernetframe.h
@@ -23,23 +23,31 @@ namespace MaxOS {
/**
* @struct EthernetFrameHeader
* @brief Structure the raw data. This is the header of an Ethernet Frame
+ *
+ * @typedef ethernet_frame_header_t
+ * @brief Alias for EthernetFrameHeader struct
*/
- struct EthernetFrameHeader {
+ typedef struct PACKED EthernetFrameHeader {
uint64_t destinationMAC: 48; ///< The mac address of the target (Big Endian)
uint64_t sourceMAC: 48; ///< The mac address of the sender (Big Endian)
uint16_t type; ///< The type (Big Endian) 0x0800 = IPv4, 0x0806 = ARP, 0x86DD = IPv6
- }__attribute__ ((packed));
+ } ethernet_frame_header_t;
/**
* @struct EthernetFrameFooter
* @brief Structure the raw data. This is the footer of an Ethernet Frame
+ *
+ * @typedef ethernet_frame_footer_t
+ * @brief Alias for EthernetFrameFooter struct
*/
- struct EthernetFrameFooter {
+ typedef struct PACKED EthernetFrameFooter {
+
uint32_t checksum; ///< Checksum of the payload
- }__attribute__ ((packed));
+
+ } ethernet_frame_footer_t;
class EthernetFrameHandler;
diff --git a/kernel/include/net/icmp.h b/kernel/include/net/icmp.h
index 44cbac2b..9e60e804 100644
--- a/kernel/include/net/icmp.h
+++ b/kernel/include/net/icmp.h
@@ -21,14 +21,19 @@ namespace MaxOS {
/**
* @struct ICMPHeader
* @brief The header of an ICMP packet
+ *
+ * @typedef icmp_header_t
+ * @brief Alias for ICMPHeader struct
*/
- struct ICMPHeader {
+ typedef struct PACKED ICMPHeader {
+
uint8_t type; ///< The type of ICMP message
uint8_t code; ///< The code of the ICMP message
uint16_t checksum; ///< Checksum to verify integrity
uint32_t data; ///< Payload data (Varies by type and code)
- }__attribute__((packed));
+
+ } icmp_header_t;
/**
* @class InternetControlMessageProtocol
diff --git a/kernel/include/net/ipv4.h b/kernel/include/net/ipv4.h
index 278bbef4..9a6caad2 100644
--- a/kernel/include/net/ipv4.h
+++ b/kernel/include/net/ipv4.h
@@ -16,14 +16,18 @@ namespace MaxOS {
namespace net {
- typedef uint32_t InternetProtocolAddress;
- typedef uint32_t SubnetMask;
+ typedef uint32_t InternetProtocolAddress; ///< An IPv4 address @todo: Make IPv4Address class and do ip_t
+ typedef uint32_t SubnetMask; ///< A subnet mask @todo: Make SubnetMask class and do subnetmask_t
/**
* @struct IPV4Header
* @brief The header of an IPv4 packet
+ *
+ * @typedef ipv4_header_t
+ * @brief Alias for IPV4Header struct
*/
- struct IPV4Header {
+ typedef struct PACKED IPV4Header {
+
uint8_t headerLength: 4; ///< The length of the header in 32-bit words (min 5, max 15)
uint8_t version: 4; ///< The version of the IP protocol (4 for IPv4)
uint8_t typeOfService; ///< The type of service (low delay, high throughput, high reliability, etc. @todo: enum
@@ -38,7 +42,8 @@ namespace MaxOS {
uint32_t sourceIP; ///< The IP of the sender
uint32_t destinationIP; ///< The IP of the receiver
- } __attribute__((packed));
+
+ } ipv4_header_t;
class InternetProtocolHandler;
diff --git a/kernel/include/net/tcp.h b/kernel/include/net/tcp.h
index 396d3b7b..5dc13015 100644
--- a/kernel/include/net/tcp.h
+++ b/kernel/include/net/tcp.h
@@ -17,7 +17,7 @@ namespace MaxOS {
namespace net {
- typedef uint16_t TransmissionControlProtocolPort;
+ typedef uint16_t TransmissionControlProtocolPort; ///< TCP port @todo: Make TCPPort class and do tcp_port_t
/**
* @enum TCPSocketState
@@ -59,8 +59,12 @@ namespace MaxOS {
/**
* @struct TCPHeader
* @brief The header of a TCP packet
+ *
+ * @typedef tcp_header_t
+ * @brief Alias for TCPHeader struct
*/
- struct TCPHeader {
+ typedef struct PACKED TCPHeader {
+
uint16_t srcPort; ///< The port of the sender
uint16_t dstPort; ///< The port of the receiver
uint32_t sequenceNumber; ///< Where this packet's data fits in the overall order of the data stream
@@ -75,7 +79,8 @@ namespace MaxOS {
uint16_t urgentPtr; ///< Where in the data the urgent data *ends* (if the URG flag is set)
uint32_t options; ///< The options for the TCP packet (MSS, Window Scale, SACK Permitted) @todo: make this a struct
- } __attribute__((packed));
+
+ } tcp_header_t;
/**
* @struct TCPPseudoHeader
@@ -83,13 +88,18 @@ namespace MaxOS {
*
* @details The pseudo header is used to calculate the checksum of the TCP header. It is a copy of the IP
* header, but with the protocol field set to 6 (TCP) and the length field set to the length of the TCP header.
+ *
+ * @typedef tcp_pseudo_header_t
+ * @brief Alias for TCPPseudoHeader struct
*/
- struct TCPPseudoHeader {
+ typedef struct PACKED TCPPseudoHeader {
+
uint32_t srcIP; ///< The IP address of the sender
uint32_t dstIP; ///< The IP address of the receiver
uint16_t protocol; ///< The protocol (set to 6 for TCP)
uint16_t totalLength; ///< The total length of the TCP header and data
- } __attribute__((packed));
+
+ } tcp_pseudo_header_t;
// Forward declarations
diff --git a/kernel/include/net/udp.h b/kernel/include/net/udp.h
index 3c9e56c3..d93f6bec 100644
--- a/kernel/include/net/udp.h
+++ b/kernel/include/net/udp.h
@@ -21,15 +21,18 @@ namespace MaxOS {
/**
* @struct UDPHeader
* @brief The header of a UDP packet
+ *
+ * @typedef udp_header_t
+ * @brief Alias for UDPHeader struct
*/
- struct UDPHeader {
+ typedef struct PACKED UDPHeader {
uint16_t sourcePort; ///< The port of the sender
uint16_t destinationPort; ///< The port of the receiver
uint16_t length; ///< The length of the UDP header and data
uint16_t checksum; ///< The checksum of the header and data
- } __attribute__((packed));
+ } udp_header_t;
/**
* @enum UDPEvents
@@ -43,7 +46,7 @@ namespace MaxOS {
class UDPSocket;
class UserDatagramProtocolHandler;
- typedef uint16_t UserDatagramProtocolPort;
+ typedef uint16_t UserDatagramProtocolPort; ///< UDP port @todo: Make UDPPort class and do udp_port_t (or generic port that can be used for TCP and UDP)
/**
* @class UDPDataReceivedEvent
diff --git a/kernel/include/processes/elf.h b/kernel/include/processes/elf.h
index e2054e90..58dfb374 100644
--- a/kernel/include/processes/elf.h
+++ b/kernel/include/processes/elf.h
@@ -103,8 +103,12 @@ namespace MaxOS {
/**
* @struct ELFHeader64
* @brief The header of a 64-bit ELF file
+ *
+ * @typedef elf_64_header_t
+ * @brief Alias for ELFHeader64 struct
*/
typedef struct ELFHeader64 {
+
unsigned char identification[16]; ///< Identifies the file as an ELF file and contains metadata about the file (class, data encoding, version, OS ABI, etc.)
uint16_t type; ///< The type of the ELF file (see ELFType)
uint16_t machine; ///< The target architecture of the ELF file (see ELFMachine)
@@ -119,6 +123,7 @@ namespace MaxOS {
uint16_t section_header_size; ///< The size of each entry in the section header table
uint16_t section_header_count; ///< The number of entries in the section header table
uint16_t section_header_string_table_index; ///< Where the section header string table is located (index into the section header table)
+
} elf_64_header_t;
/**
@@ -150,8 +155,12 @@ namespace MaxOS {
/**
* @struct ELFProgramHeader64
* @brief The header for the program segments in a 64-bit ELF file
+ *
+ * @typedef elf_64_program_header_t
+ * @brief Alias for ELFProgramHeader64 struct
*/
typedef struct ELFProgramHeader64 {
+
uint32_t type; ///< The type of the program header (see ELFProgramType)
uint32_t flags; ///< The flags of the program header (see ELFProgramFlags)
uint64_t offset; ///< The offset in the file where the segment is located
@@ -160,6 +169,7 @@ namespace MaxOS {
uint64_t file_size; ///< The size of the segment in the file
uint64_t memory_size; ///< The size of the segment in memory (should be >= file_size)
uint64_t align; ///< The required alignment of the segment in memory (normally 2^n)
+
} elf_64_program_header_t;
/**
@@ -181,8 +191,12 @@ namespace MaxOS {
/**
* @struct ELFSectionHeader64
* @brief The header for the sections in a 64-bit ELF file
+ *
+ * @typedef elf_64_section_header_t
+ * @brief Alias for ELFSectionHeader64 struct
*/
typedef struct ELFSectionHeader64 {
+
uint32_t name_index; ///< The index into the section header string table where the name of this section is located
uint32_t type; ///< The type of the section (see ELFSectionType)
uint64_t sh_flags; ///< The flags of the section (see ELFSectionFlags)
@@ -193,6 +207,7 @@ namespace MaxOS {
uint32_t info; ///< Extra information (meaning depends on section type)
uint64_t address_alignment; ///< The required alignment of the section in memory (normally 2^n)
uint64_t entry_size; ///< The size of each entry in the section if it contains a table of fixed-size entries
+
} elf_64_section_header_t;
/**
diff --git a/kernel/include/processes/process.h b/kernel/include/processes/process.h
index 622584da..20d1864f 100644
--- a/kernel/include/processes/process.h
+++ b/kernel/include/processes/process.h
@@ -20,12 +20,19 @@
#include
#include
-
namespace MaxOS
{
namespace processes
{
-
+ class Process;
+
+ /**
+ * @enum ThreadState
+ * @brief The different operational states a thread can be in
+ *
+ * @typedef thread_state_t
+ * @brief Alias for ThreadState enum
+ */
typedef enum class ThreadState{
NEW,
RUNNING,
@@ -35,9 +42,7 @@ namespace MaxOS
STOPPED
} thread_state_t;
-
- // Forward declaration
- class Process;
+ /// The size of the stack for each thread (4KB)
constexpr size_t STACK_SIZE = 0x10000;
/**
diff --git a/kernel/include/processes/resource.h b/kernel/include/processes/resource.h
index f47dfa8f..34fc0b5e 100644
--- a/kernel/include/processes/resource.h
+++ b/kernel/include/processes/resource.h
@@ -19,8 +19,8 @@
namespace MaxOS {
namespace processes {
- typedef ::syscore::ResourceType resource_type_t;
- typedef ::syscore::ResourceErrorBase resource_error_base_t;
+ typedef ::syscore::ResourceType resource_type_t; ///< Alias to make the libsyscore ResourceType accessible here
+ typedef ::syscore::ResourceErrorBase resource_error_base_t; ///< Alias to make the libsyscore ResourceErrorBase accessible here
/**
* @class Resource
diff --git a/kernel/include/runtime/cplusplus.h b/kernel/include/runtime/cplusplus.h
index bd424d04..48bea211 100644
--- a/kernel/include/runtime/cplusplus.h
+++ b/kernel/include/runtime/cplusplus.h
@@ -16,8 +16,8 @@
namespace MaxOS {
namespace runtime {
- typedef void (* constructor)();
- typedef unsigned uarch_t;
+ typedef void (* constructor)(); ///< A pointer to a constructor function
+ typedef unsigned uarch_t; ///< An unsigned architecture specific type
extern "C" {
@@ -31,13 +31,30 @@ namespace MaxOS {
void* dso_handle; ///< The DSO handle (not used)
};
+ /**
+ * @brief Register a function to be called at program exit
+ *
+ * @param f The function to call
+ * @param objptr The object pointer to pass to the function
+ * @param dso The DSO handle (not used)
+ * @return int 0 on success, non-zero on failure
+ */
int __cxa_atexit(void (* f)(void*), void* objptr, void* dso);
+
+ /**
+ * @brief Finalise all global objects by calling their destructors
+ *
+ * @param f The DSO handle to finalise (nullptr for all)
+ */
void __cxa_finalize(void* f);
- // Stack Gaurd
+ /// The stack canary value used to detect stack buffer overflows (@todo make random at runtime)
uintptr_t __stack_chk_guard = 0x595e9fbd94fda766;
- void __stack_chk_fail(void);
+ /**
+ * @brief Called when a stack buffer overflow is detected
+ */
+ void __stack_chk_fail(void);
}
}
}
diff --git a/kernel/include/runtime/ubsan.h b/kernel/include/runtime/ubsan.h
index 485f6a3d..6e1bceca 100644
--- a/kernel/include/runtime/ubsan.h
+++ b/kernel/include/runtime/ubsan.h
@@ -14,103 +14,154 @@
namespace MaxOS {
namespace runtime {
+ /// Check if a value is aligned to the given alignment
#define ubsan_aligned(value, alignment) !(value & (alignment - 1))
/**
* @struct SourceLocation
* @brief The location in the source code where the undefined behaviour occurred
+ *
+ * @typedef source_location_t
+ * @brief Alias for SourceLocation struct
*/
typedef struct SourceLocation {
+
const char* file; ///< The name of the source file
uint32_t line; ///< The line number in the source file
uint32_t column; ///< The column number in the source file
+
} source_location_t;
/**
* @struct TypeDescriptor
* @brief Describes a type in the program
+ *
+ * @typedef type_descriptor_t
+ * @brief Alias for TypeDescriptor struct
*/
typedef struct TypeDescriptor {
+
uint16_t kind; ///< The kind of type (e.g., struct, class, union)
uint16_t info; ///< Additional type information
char name[]; ///< The name of the type
+
} type_descriptor_t;
/**
* @struct TypeMismatchInfo
* @brief Information about a type mismatch error
+ *
+ * @typedef type_mismatch_info_t
+ * @brief Alias for TypeMismatchInfo struct
*/
typedef struct TypeMismatchInfo {
+
source_location_t location; ///< The location of the type mismatch
type_descriptor_t* type; ///< The type that was expected
uintptr_t alignment; ///< The required alignment
uint8_t type_check_kind; ///< The kind of type check that failed
+
} type_mismatch_info_t;
/**
* @struct TypeMismatchInfoV1
* @brief Information about a type mismatch error (version 1)
+ *
+ * @typedef type_mismatch_info_v1_t
+ * @brief Alias for TypeMismatchInfoV1 struct
*/
typedef struct TypeMismatchInfoV1 {
+
source_location_t location; ///< The location of the type mismatch
type_descriptor_t* type; ///< The type that was expected
unsigned char log_alignment; ///< The log2 of the required alignment
unsigned char type_check_kind; ///< The kind of type check that failed
+
} type_mismatch_info_v1_t;
/**
* @struct OverflowInfo
* @brief Information about an overflow error
+ *
+ * @typedef overflow_info_t
+ * @brief Alias for OverflowInfo struct
*/
typedef struct OverflowInfo {
+
source_location_t location; ///< The location of the overflow
type_descriptor_t* base_type; ///< The base type of the operation
+
} overflow_info_t;
/**
* @struct ShiftOutOfBoundsInfo
* @brief Information about a shift out of bounds error
+ *
+ * @typedef shift_out_of_bounds_info_t
+ * @brief Alias for ShiftOutOfBoundsInfo struct
*/
typedef struct ShiftOutOfBoundsInfo {
+
source_location_t location; ///< The location of the shift out of bounds
type_descriptor_t* left_type; ///< The type of the left operand
type_descriptor_t* right_type; ///< The type of the right operand
+
} shift_out_of_bounds_info_t;
/**
* @struct OutOfBoundsInfo
* @brief Information about an out of bounds error
+ *
+ * @typedef out_of_bounds_info_t
+ * @brief Alias for OutOfBoundsInfo struct
*/
typedef struct OutOfBoundsInfo {
+
source_location_t location; ///< The location of the out of bounds access
type_descriptor_t* array_type; ///< The type of the array
type_descriptor_t* index_type; ///< The type of the index
+
} out_of_bounds_info_t;
/**
* @struct LocationOnlyInfo
* @brief Information that an error that only has a location
+ *
+ * @typedef location_only_info_t
+ * @brief Alias for LocationOnlyInfo struct
*/
typedef struct LocationOnlyInfo {
+
source_location_t location; ///< The location of the error
+
} location_only_info_t;
/**
* @struct InvaildValueInfo
* @brief Information about an invalid value error
+ *
+ * @typedef invalid_value_info_t
+ * @brief Alias for InvaildValueInfo struct
*/
typedef struct InvaildValueInfo {
+
source_location_t location; ///< The location of the invalid value
type_descriptor_t* type; ///< The type of the invalid value
+
} invalid_value_info_t;
/**
* @struct VLABoundNotPositiveInfo
* @brief Information about a VLA bound not positive error
+ *
+ * @typedef vla_bound_not_positive_info_t
+ * @brief Alias for VLABoundNotPositiveInfo struct
*/
typedef struct VLABoundNotPositiveInfo {
+
source_location_t location; ///< The location of the VLA bound not positive
type_descriptor_t* type; ///< The type of the VLA bound
+
} vla_bound_not_positive_info_t;
/// List of type check errors
diff --git a/kernel/include/system/cpu.h b/kernel/include/system/cpu.h
index 2f51ae2e..0333d5f1 100644
--- a/kernel/include/system/cpu.h
+++ b/kernel/include/system/cpu.h
@@ -28,8 +28,15 @@ namespace MaxOS {
namespace system {
- /// The state of the CPU when an interrupt occurs (must align with the interrupt handler assembly code)
- typedef struct {
+ /**
+ * @struct CPUStatus
+ * @brief Structure representing the CPU state during an interrupt
+ *
+ * @typedef cpu_status_t
+ * @brief Alias for CPUStatus struct
+ */
+ typedef struct PACKED CPUStatus {
+
uint64_t r15; ///< Register r15
uint64_t r14; ///< Register r14
uint64_t r13; ///< Register r13
@@ -54,10 +61,18 @@ namespace MaxOS {
uint64_t rflags; ///< Flags register
uint64_t rsp; ///< Stack pointer
uint64_t ss; ///< Stack segment
- } __attribute__((__packed__)) cpu_status_t;
- /// Task State Segment (TSS) structure for x86_64
- typedef struct TaskStateSegment {
+ } cpu_status_t;
+
+ /**
+ * @struct TaskStateSegment
+ * @brief Structure representing the Task State Segment (TSS)
+ *
+ * @typedef tss_t
+ * @brief Alias for TaskStateSegment struct
+ */
+ typedef struct PACKED TaskStateSegment {
+
uint32_t reserved0; ///< Unused, must be zero
uint64_t rsp0; ///< Stack pointer for ring 0
uint64_t rsp1; ///< Stack pointer for ring 1
@@ -74,7 +89,8 @@ namespace MaxOS {
uint64_t reserved3; ///< Unused, must be zero
uint16_t reserved4; ///< Unused, must be zero
uint16_t io_bitmap_offset; ///< Offset to the I/O bitmap
- }__attribute__((__packed__)) tss_t;
+
+ } tss_t;
/**
* @enum CPU_FEATURE_ECX
@@ -158,23 +174,33 @@ namespace MaxOS {
/**
* @struct StackFrame
* @brief A snapshot of the a frame in the call stack
+ *
+ * @typedef stack_frame_t
+ * @brief Alias for StackFrame struct
*/
- typedef struct StackFrame {
+ typedef struct PACKED StackFrame {
+
StackFrame* next; ///< Pointer to the next stack frame (up the call stack)
uintptr_t rip; ///< The instruction pointer at this frame
- }__attribute__((__packed__)) stack_frame_t;
+
+ } stack_frame_t;
/**
* @struct CoreBootInfo
* @brief Information needed when booting a core
+ *
+ * @typedef core_boot_info_t
+ * @brief Alias for CoreBootInfo struct
*/
- typedef struct CoreBootInfo {
+ typedef struct PACKED CoreBootInfo {
+
uint64_t stack; ///< The stack pointer for the core
uint64_t p4_table; ///< The physical address of the P4 page table
uint8_t id; ///< The ID of the core
bool activated; ///< Whether the core has been activated
void* gdt_64_base; ///< The base of the 64-bit GDT
- }__attribute__((__packed__)) core_boot_info_t;
+
+ } core_boot_info_t;
/// The size of the stack allocated for booting a core (should align with the startup assembly code for the kernel)
constexpr size_t BOOT_STACK_SIZE = 16384;
diff --git a/kernel/include/system/gdt.h b/kernel/include/system/gdt.h
index 9402fb04..d1ebb7cb 100644
--- a/kernel/include/system/gdt.h
+++ b/kernel/include/system/gdt.h
@@ -10,6 +10,7 @@
#define MAX_OS_SYSTEM_GDT_H
#include
+#include
#include
namespace MaxOS {
@@ -34,11 +35,16 @@ namespace MaxOS {
/**
* @struct GDTRegister
* @brief How the CPU stores the GDT
+ *
+ * @typedef gdtr_t
+ * @brief Alias for GDTRegister struct
*/
- typedef struct GDTRegister {
+ typedef struct PACKED GDTRegister {
+
uint16_t size; ///< The size of the GDT
uint64_t address; ///< The address of the GDT
- } __attribute__((packed)) gdtr_t;
+
+ } gdtr_t;
/**
* @class GlobalDescriptorTable
diff --git a/kernel/include/system/syscalls.h b/kernel/include/system/syscalls.h
index c6fc4b61..e0b1b298 100644
--- a/kernel/include/system/syscalls.h
+++ b/kernel/include/system/syscalls.h
@@ -29,8 +29,12 @@ namespace MaxOS {
/**
* @struct SyscallArguments
* @brief The arguments passed to a syscall (simplified representation of values in registers)
+ *
+ * @typedef syscall_args_t
+ * @brief Alias for SyscallArguments struct
*/
typedef struct SyscallArguments {
+
uint64_t arg0; ///< First argument (in rdi)
uint64_t arg1; ///< Second argument (in rsi)
uint64_t arg2; ///< Third argument (in rdx)
@@ -39,6 +43,7 @@ namespace MaxOS {
uint64_t arg5; ///< Sixth argument (in r9)
uint64_t return_value; ///< The return value of the syscall (in rax)
cpu_status_t* return_state; ///< The CPU state to return to after the syscall
+
} syscall_args_t;
/// @todo Could use a class based response but a single class might want multiple handlers e.g. fs
@@ -79,9 +84,7 @@ namespace MaxOS {
static syscall_args_t* syscall_thread_sleep(syscall_args_t* args);
static syscall_args_t* syscall_thread_close(syscall_args_t* args);
};
-
}
-
}
#endif //MAXOS_SYSTEM_SYSCALLS_H
diff --git a/kernel/src/drivers/clock/clock.cpp b/kernel/src/drivers/clock/clock.cpp
index add9654b..25f7bdbc 100644
--- a/kernel/src/drivers/clock/clock.cpp
+++ b/kernel/src/drivers/clock/clock.cpp
@@ -179,14 +179,14 @@ void Clock::setup_apic_clock(hardwarecommunication::LocalAPIC* local_apic) const
*
* @return The current time in a Time struct format
*/
-common::Time Clock::get_time() {
+common::time_t Clock::get_time() {
// Wait for the clock to be ready
while (read_hardware_clock(0xA) & 0x80)
asm volatile("nop");
// Read the time from the clock
- Time time{};
+ time_t time{};
time.year = binary_representation(read_hardware_clock(0x9)) + 2000;
time.month = binary_representation(read_hardware_clock(0x8));
time.day = binary_representation(read_hardware_clock(0x7));
@@ -210,7 +210,7 @@ Clock *Clock::active_clock() {
}
/**
- * @brief Constructor for the PIT class. Registers a handler for interrupt 0x22 and initializes ports
+ * @brief Constructor for the PIT class. Registers a handler for interrupt 0x22 and initialises ports
* @param apic The APIC controller for the BSP core
*/
PIT::PIT(AdvancedProgrammableInterruptController *apic)
diff --git a/kernel/src/drivers/console/serial.cpp b/kernel/src/drivers/console/serial.cpp
index 5ec944b7..e1363737 100644
--- a/kernel/src/drivers/console/serial.cpp
+++ b/kernel/src/drivers/console/serial.cpp
@@ -12,7 +12,7 @@ using namespace MaxOS;
using namespace MaxOS::drivers;
/**
- * @brief Constructs a new Serial Console object and initializes the serial port
+ * @brief Constructs a new Serial Console object and initialises the serial port
* @param logger The logger which will use this serial console as a log writer
*/
SerialConsole::SerialConsole(Logger* logger)
diff --git a/kernel/src/drivers/ethernet/amd_am79c973.cpp b/kernel/src/drivers/ethernet/amd_am79c973.cpp
index 98cde7a2..2b27da78 100644
--- a/kernel/src/drivers/ethernet/amd_am79c973.cpp
+++ b/kernel/src/drivers/ethernet/amd_am79c973.cpp
@@ -36,7 +36,7 @@ AMD_AM79C973::AMD_AM79C973(PeripheralComponentInterconnectDeviceDescriptor *dev)
currentSendBuffer = 0;
currentRecvBuffer = 0;
- //Not active or initialized
+ //Not active or initialised
active = false;
initDone = false;
diff --git a/kernel/src/drivers/ethernet/intel_i217.cpp b/kernel/src/drivers/ethernet/intel_i217.cpp
index ba74ee76..5100a08f 100644
--- a/kernel/src/drivers/ethernet/intel_i217.cpp
+++ b/kernel/src/drivers/ethernet/intel_i217.cpp
@@ -22,13 +22,7 @@ using namespace memory;
/// See OSDEV wiki for the credit for this driver
// Buffer Sizes
-#define buffer256 (3 << 16)
-#define buffer512 (2 << 16)
-#define buffer1024 (1 << 16)
-#define buffer2048 (0 << 16)
-#define buffer4096 ((3 << 16) | (1 << 25))
#define buffer8192 ((2 << 16) | (1 << 25))
-#define buffer16384 ((1 << 16) | (1 << 25))
///__DRIVER___
diff --git a/kernel/src/kernel.cpp b/kernel/src/kernel.cpp
index c2fbb91e..50f663f5 100644
--- a/kernel/src/kernel.cpp
+++ b/kernel/src/kernel.cpp
@@ -122,6 +122,9 @@ extern "C" [[noreturn]] void kernel_main(unsigned long addr, unsigned long magic
}
/**
+ * @todo Proper file formatting
+ * @todo Full doxygen comments
+ * @todo Kernel configuration (debug/release)
* @todo Clean up warnings
* @todo Test suite of common functions & other statics (paths)
* @todo Thread storage (when clib)
diff --git a/kernel/src/memory/physical.cpp b/kernel/src/memory/physical.cpp
index bed7de6b..ad434e56 100644
--- a/kernel/src/memory/physical.cpp
+++ b/kernel/src/memory/physical.cpp
@@ -73,7 +73,7 @@ PhysicalMemoryManager::PhysicalMemoryManager(Multiboot* multiboot)
reserve_kernel_regions(multiboot);
// Initialisation Done
- m_initialized = true;
+ m_initialised = true;
Logger::DEBUG() << "Memory used at start: " << (int) (memory_used() / 1024 / 1024) << "mb \n";
}
@@ -191,7 +191,7 @@ void* PhysicalMemoryManager::allocate_frame() {
// If not initialised, cant use the bitmap or higher half mapped physical memory so use leftover kernel memory already
// mapped in loader.s
- if (!m_initialized) {
+ if (!m_initialised) {
// Use frames at the start of the mmap free
void* address = (void*)m_mmap->addr + (m_setup_frames * PAGE_SIZE);
@@ -391,7 +391,7 @@ pml_t* PhysicalMemoryManager::get_or_create_table(pml_t* table, size_t index, si
}
/**
- * @brief Creates a page table entry when the higher half is not initialized
+ * @brief Creates a page table entry when the higher half is not initialised
*
* @param parent_table The parent table to create the entry in
* @param table_index The index of the table to create
@@ -444,7 +444,7 @@ pte_t* PhysicalMemoryManager::get_entry(virtual_address_t* virtual_address, pml_
pml_t* pt_table = nullptr;
// If it is before initialization then cant rely on the direct map
- if (!m_initialized) {
+ if (!m_initialised) {
pdpr_table = get_and_create_table(pml4_table, pml4_index, get_higher_half_table(pml4_index));
pd_table = get_and_create_table(pdpr_table, pdpr_index, get_higher_half_table(pdpr_index, pml4_index));
pt_table = get_and_create_table(pd_table, pd_index, get_higher_half_table(pd_index, pdpr_index, pml4_index));
diff --git a/kernel/src/runtime/cplusplus.cpp b/kernel/src/runtime/cplusplus.cpp
index d9eb7c9e..80af8143 100644
--- a/kernel/src/runtime/cplusplus.cpp
+++ b/kernel/src/runtime/cplusplus.cpp
@@ -15,17 +15,27 @@ using namespace MaxOS::runtime;
// Define static constructors (DSO = Dynamic Shared Object)
extern "C" void* __dso_handle = nullptr;
-// Pure virtual function call
+/**
+ * @brief Called when a virtual function is called on an object with no implementation
+ */
extern "C" void __cxa_pure_virtual() {
ASSERT(false, "Pure virtual function call failed");
}
+/**
+ * @brief Called when stack smashing is detected
+ */
extern "C" void __stack_chk_fail(void)
{
ASSERT(false, "Stack Smashed");
}
+
extern "C" constructor start_ctors;
extern "C" constructor end_ctors;
+
+/**
+ * @brief Calls all global constructors
+ */
extern "C" void call_constructors() {
// Loop through and initialise all the global constructors
for (constructor* i = &start_ctors; i != &end_ctors; i++)
diff --git a/toolchain/pre_process/symbols.sh b/toolchain/pre_process/symbols.sh
index f22c2c69..c8c79ceb 100755
--- a/toolchain/pre_process/symbols.sh
+++ b/toolchain/pre_process/symbols.sh
@@ -75,15 +75,19 @@ namespace MaxOS{
namespace common{
- /**
- * @struct KernelSymbol
- * @brief Holds the address and name of a kernel symbol
- */
+ /**
+ * @struct KernelSymbol
+ * @brief Holds the address and name of a kernel symbol
+ *
+ * @typedef kernel_sym_t
+ * @brief alias for KernelSymbol
+ */
typedef struct KernelSymbol {
uintptr_t address; ///< The address of the symbol (loaded address)
const char* name; ///< The stripped name of the symbol (including namespaces)
} kernel_sym_t;
+ /// Holds a list of address/name pairs for kernel symbols
const kernel_sym_t kernel_symbols[] = {
EOF
if [ ! -s "$RAW" ]; then
@@ -134,6 +138,8 @@ fi
# Write the footer
cat >> "$OUT" < .buildCount
@@ -12,12 +11,13 @@ fi
# Increment the buildCount by 1
new_value=$(($(cat .buildCount) + 1))
echo "$new_value" > .buildCount
+msg "New build count: $new_value"
msg "Writing version header"
# Version data
MAJOR_VERSION="0"
MINOR_VERSION="3"
-VERSION_NAME="Development Version"
+VERSION_NAME="Kernel Focus"
BUILD_NUMBER=$(cat .buildCount)
BUILD_YEAR="$(date +'%-Y')"
BUILD_MONTH="$(date +'%-m')"
@@ -25,6 +25,7 @@ BUILD_DAY="$(date +'%-d')"
BUILD_HOUR="$(date +'%-H')"
BUILD_MINUTE="$(date +'%-M')"
BUILD_SECOND="$(date +'%-S')"
+BUILD_TYPE="Debug" #/release
GIT_REVISION="$(git rev-parse --short HEAD)"
GIT_BRANCH="$(git rev-parse --abbrev-ref HEAD)"
GIT_COMMIT="$(git rev-list --count HEAD)"
@@ -40,6 +41,50 @@ fi
# Write the version header
cat > "${OUTPUT_FILE}" << EOF
+/**
+ * @file version.h
+ * @brief Defines version information for MaxOS
+ *
+ * @date 2025-11-1
+ * @author Max Tyson
+ */
+#ifndef MAX_OS_COMMON_VERSION_H
+#define MAX_OS_COMMON_VERSION_H
+
+
+#include
+#include
+#include
+
+namespace MaxOS {
+
+ namespace common {
+
+ /**
+ * @typedef vstring
+ * @brief A type alias for a const char* string
+ */
+ typedef const char* vstring;
+
+ const uint8_t MAJOR_VERSION = ${MAJOR_VERSION}; ///< The official release version
+ const uint8_t MINOR_VERSION = ${MINOR_VERSION}; ///< The significant feature update version
+ const vstring VERSION_STRING = "${MAJOR_VERSION}.${MINOR_VERSION}"; ///< A c style string representing the MAJOR.MINOR version
+ const vstring VERSION_NAME = "${VERSION_NAME}"; ///< The human readable version name
+ const int BUILD_NUMBER = ${BUILD_NUMBER}; ///< How many times the code has been built on this device
+ const time_t BUILD_DATE = {${BUILD_YEAR}, ${BUILD_MONTH}, ${BUILD_DAY}, ${BUILD_HOUR}, ${BUILD_MINUTE}, ${BUILD_SECOND}}; ///< The build date and time
+ const vstring BUILD_TYPE = "${BUILD_TYPE}"; ///< The build type (Debug/Release)
+ const vstring GIT_REVISION = "${GIT_REVISION}"; ///< The git revision hash
+ const vstring GIT_BRANCH = "${GIT_BRANCH}"; ///< The name of the git branch that was built
+ const int GIT_COMMIT = ${GIT_COMMIT}; ///< The commit number in the git repository that this build was made from
+ const vstring GIT_AUTHOR = "${GIT_AUTHOR}"; ///< Who authored the build of this version
+
+ }
+
+}
+
+#endif //MAX_OS_VERSION_H
+
+
/**
* @file version.h
* @brief Defines version information for MaxOS
@@ -60,22 +105,30 @@ namespace MaxOS{
namespace common
{
+ /**
+ * @typedef vstring
+ * @brief A type alias for a const char* string
+ */
typedef const char* vstring;
- const uint8_t MAJOR_VERSION = ${MAJOR_VERSION};
- const uint8_t MINOR_VERSION = ${MINOR_VERSION};
- const vstring VERSION_STRING = "${MAJOR_VERSION}.${MINOR_VERSION}";
- const vstring VERSION_NAME = "${VERSION_NAME}";
- const int BUILD_NUMBER = ${BUILD_NUMBER};
- const Time BUILD_DATE = {${BUILD_YEAR}, ${BUILD_MONTH}, ${BUILD_DAY}, ${BUILD_HOUR}, ${BUILD_MINUTE}, ${BUILD_SECOND}};
- const vstring GIT_REVISION = "${GIT_REVISION}";
- const vstring GIT_BRANCH = "${GIT_BRANCH}";
- const int GIT_COMMIT = ${GIT_COMMIT};
- const vstring GIT_AUTHOR = "${GIT_AUTHOR}";
+ const uint8_t MAJOR_VERSION = ${MAJOR_VERSION};
+ const uint8_t MINOR_VERSION = ${MINOR_VERSION};
+ const vstring VERSION_STRING = "${MAJOR_VERSION}.${MINOR_VERSION}";
+ const vstring VERSION_NAME = "${VERSION_NAME}";
+ const int BUILD_NUMBER = ${BUILD_NUMBER};
+ const Time BUILD_DATE = {${BUILD_YEAR}, ${BUILD_MONTH}, ${BUILD_DAY}, ${BUILD_HOUR}, ${BUILD_MINUTE}, ${BUILD_SECOND}};
+ const vstring GIT_REVISION = "${GIT_REVISION}";
+ const vstring GIT_BRANCH = "${GIT_BRANCH}";
+ const int GIT_COMMIT = ${GIT_COMMIT};
+ const vstring GIT_AUTHOR = "${GIT_AUTHOR}";
}
}
#endif //MAX_OS_VERSION_H
-EOF
\ No newline at end of file
+EOF
+
+# Copy the version to the doxygen file (replace PROJECT_NUMBER = x.x with the VERSION_STRING value)
+sed -i.bak "s/PROJECT_NUMBER = .*/PROJECT_NUMBER = ${MAJOR_VERSION}.${MINOR_VERSION}/" "${SCRIPTDIR}/../../docs/doxy/Doxyfile"
+rm "${SCRIPTDIR}/../../docs/Doxyfile.bak"
\ No newline at end of file
From bc6b4f893cf0b7cb96003b731efa3017e9ac84c1 Mon Sep 17 00:00:00 2001
From: Max Tyson <98maxt98@gmail.com>
Date: Sun, 2 Nov 2025 20:25:28 +1300
Subject: [PATCH 02/12] Doxy happy
---
kernel/include/common/buffer.h | 14 +-
kernel/include/common/eventHandler.h | 12 +-
kernel/include/common/graphicsContext.h | 98 +--
kernel/include/common/logger.h | 157 ++--
kernel/include/common/macros.h | 11 +
kernel/include/common/string.h | 128 +--
kernel/include/common/vector.h | 819 +++++++++---------
kernel/include/drivers/disk/ide.h | 2 +-
.../include/drivers/ethernet/amd_am79c973.h | 2 +-
kernel/include/drivers/ethernet/intel_i217.h | 172 ++--
kernel/include/drivers/peripherals/keyboard.h | 4 +-
kernel/include/drivers/peripherals/mouse.h | 168 ++--
kernel/include/filesystem/format/fat32.h | 12 +-
.../hardwarecommunication/interrupts.h | 6 +-
kernel/include/hardwarecommunication/pci.h | 180 ++--
kernel/include/processes/process.h | 2 +-
kernel/include/processes/resource.h | 8 +-
kernel/include/system/cpu.h | 1 +
kernel/src/asm/interrupts.s | 12 +-
kernel/src/common/buffer.cpp | 3 +
kernel/src/common/graphicsContext.cpp | 4 +
kernel/src/common/logger.cpp | 8 +-
kernel/src/common/outputStream.cpp | 3 +
kernel/src/common/string.cpp | 176 ++--
kernel/src/drivers/console/console.cpp | 4 +-
kernel/src/drivers/console/vesaboot.cpp | 2 +
kernel/src/drivers/disk/ide.cpp | 6 +-
kernel/src/drivers/driver.cpp | 25 +-
kernel/src/drivers/ethernet/amd_am79c973.cpp | 8 +-
kernel/src/drivers/ethernet/ethernet.cpp | 20 +-
kernel/src/drivers/ethernet/intel_i217.cpp | 24 +-
.../src/drivers/ethernet/rawdatahandler.cpp | 4 +-
kernel/src/drivers/peripherals/keyboard.cpp | 9 +
kernel/src/drivers/peripherals/mouse.cpp | 3 +
kernel/src/drivers/video/vga.cpp | 7 +
kernel/src/filesystem/filesystem.cpp | 8 +-
kernel/src/filesystem/format/ext2.cpp | 6 +-
kernel/src/filesystem/vfs.cpp | 9 +
kernel/src/gui/widget.cpp | 4 +-
kernel/src/gui/widgets/button.cpp | 1 +
kernel/src/gui/window.cpp | 1 +
kernel/src/hardwarecommunication/apic.cpp | 6 +
.../src/hardwarecommunication/interrupts.cpp | 10 +-
kernel/src/hardwarecommunication/pci.cpp | 33 +-
kernel/src/memory/memorymanagement.cpp | 3 +
kernel/src/memory/physical.cpp | 18 +-
kernel/src/memory/virtual.cpp | 16 +-
kernel/src/net/ethernetframe.cpp | 1 +
kernel/src/net/ipv4.cpp | 19 +-
kernel/src/net/tcp.cpp | 61 +-
kernel/src/net/udp.cpp | 8 +-
kernel/src/processes/elf.cpp | 2 +
kernel/src/processes/ipc.cpp | 3 +
kernel/src/processes/process.cpp | 7 +
kernel/src/processes/resource.cpp | 14 +-
kernel/src/processes/scheduler.cpp | 7 +-
kernel/src/runtime/cplusplus.cpp | 8 +-
kernel/src/runtime/ubsan.cpp | 72 ++
kernel/src/system/cpu.cpp | 11 +-
kernel/src/system/gdt.cpp | 3 +
kernel/src/system/syscalls.cpp | 4 +-
61 files changed, 1417 insertions(+), 1032 deletions(-)
diff --git a/kernel/include/common/buffer.h b/kernel/include/common/buffer.h
index 1164dfba..8533301d 100644
--- a/kernel/include/common/buffer.h
+++ b/kernel/include/common/buffer.h
@@ -14,23 +14,23 @@
#include
#include
-namespace MaxOS{
+namespace MaxOS {
- namespace common{
+ namespace common {
/**
* @class Buffer
* @brief Wrapper class for a region of bytes in memor in an attempt to add some memory safety. Automatically
* allocates the size specified and frees it once done, adds boundary to I/O.
*/
- class Buffer{
+ class Buffer {
private:
- uint8_t* m_bytes = nullptr;
- size_t m_capacity;
- bool m_dont_delete = false;
+ uint8_t* m_bytes = nullptr;
+ size_t m_capacity;
+ bool m_dont_delete = false;
- size_t m_offset = 0;
+ size_t m_offset = 0;
public:
Buffer(size_t size, bool update_offset = true);
diff --git a/kernel/include/common/eventHandler.h b/kernel/include/common/eventHandler.h
index 1f16df7f..7d061e2e 100644
--- a/kernel/include/common/eventHandler.h
+++ b/kernel/include/common/eventHandler.h
@@ -79,8 +79,14 @@ namespace MaxOS{
Vector*> raise_event(Event* event);
};
-
- /// ___________________________ Template Implementation ___________________________
+ ///@todo move to a c++ files
+
+ /**
+ * @brief Constructs a new Event object
+ *
+ * @tparam EventType The type of event
+ * @param type The type of the event
+ */
template Event::Event(EventType type) {
this->type = type;
}
@@ -98,6 +104,8 @@ namespace MaxOS{
*
* @tparam EventType The type of event
* @param event The event that was raised
+ *
+ * @return The event after it has been handled
*/
template Event* EventHandler::on_event(Event* event) {
return event;
diff --git a/kernel/include/common/graphicsContext.h b/kernel/include/common/graphicsContext.h
index 3841ac9a..6c1b5df5 100644
--- a/kernel/include/common/graphicsContext.h
+++ b/kernel/include/common/graphicsContext.h
@@ -14,74 +14,74 @@
namespace MaxOS {
- namespace common {
+ namespace common {
- /**
- * @class GraphicsContext
- * @brief Draws pixels to the screen, and handles drawing lines, rectangles and circles
- */
- class GraphicsContext {
+ /**
+ * @class GraphicsContext
+ * @brief Draws pixels to the screen, and handles drawing lines, rectangles and circles
+ */
+ class GraphicsContext {
- protected:
- bool mirror_y_axis { false }; ///< Should the y axis be mirrored (0,0 is top left if false, bottom left if true)
+ protected:
+ bool mirror_y_axis { false }; ///< Should the y axis be mirrored (0,0 is top left if false, bottom left if true)
- int32_t m_width { 0 }; ///< The width of the screen in pixels
- int32_t m_height { 0 }; ///< The height of the screen in pixels
- uint32_t m_color_depth { 0 }; ///< The color depth of the screen in bits per pixel
+ int32_t m_width { 0 }; ///< The width of the screen in pixels
+ int32_t m_height { 0 }; ///< The height of the screen in pixels
+ uint32_t m_color_depth { 0 }; ///< The color depth of the screen in bits per pixel
- Colour m_colour_pallet[256]; ///< The colour pallet for 8 bit color depth @todo make const
+ Colour m_colour_pallet[256]; ///< The colour pallet for 8 bit color depth @todo make const
- uint64_t* m_framebuffer_address { nullptr }; ///< The address of the framebuffer
+ uint64_t* m_framebuffer_address { nullptr }; ///< The address of the framebuffer
- virtual void render_pixel(uint32_t x, uint32_t y, uint32_t colour);
- virtual void render_pixel_8_bit(uint32_t x, uint32_t y, uint8_t colour);
- virtual void render_pixel_16_bit(uint32_t x, uint32_t y, uint16_t colour);
- virtual void render_pixel_24_bit(uint32_t x, uint32_t y, uint32_t colour);
- virtual void render_pixel_32_bit(uint32_t x, uint32_t y, uint32_t colour);
+ virtual void render_pixel(uint32_t x, uint32_t y, uint32_t colour);
+ virtual void render_pixel_8_bit(uint32_t x, uint32_t y, uint8_t colour);
+ virtual void render_pixel_16_bit(uint32_t x, uint32_t y, uint16_t colour);
+ virtual void render_pixel_24_bit(uint32_t x, uint32_t y, uint32_t colour);
+ virtual void render_pixel_32_bit(uint32_t x, uint32_t y, uint32_t colour);
- virtual uint32_t get_rendered_pixel(uint32_t x, uint32_t y);
- virtual uint8_t get_rendered_pixel_8_bit(uint32_t x, uint32_t y);
- virtual uint16_t get_rendered_pixel_16_bit(uint32_t x, uint32_t y);
- virtual uint32_t get_rendered_pixel_24_bit(uint32_t x, uint32_t y);
- virtual uint32_t get_rendered_pixel_32_bit(uint32_t x, uint32_t y);
+ virtual uint32_t get_rendered_pixel(uint32_t x, uint32_t y);
+ virtual uint8_t get_rendered_pixel_8_bit(uint32_t x, uint32_t y);
+ virtual uint16_t get_rendered_pixel_16_bit(uint32_t x, uint32_t y);
+ virtual uint32_t get_rendered_pixel_24_bit(uint32_t x, uint32_t y);
+ virtual uint32_t get_rendered_pixel_32_bit(uint32_t x, uint32_t y);
- public:
- GraphicsContext();
- ~GraphicsContext();
+ public:
+ GraphicsContext();
+ ~GraphicsContext();
- uint32_t colour_to_int(const Colour&);
- Colour int_to_colour(uint32_t);
+ uint32_t colour_to_int(const Colour&);
+ Colour int_to_colour(uint32_t);
- // Convert uint32_t to uint64s?
- [[nodiscard]] uint32_t width() const;
- uint32_t height() const;
- uint32_t color_depth() const;
+ // Convert uint32_t to uint64s?
+ [[nodiscard]] uint32_t width() const;
+ uint32_t height() const;
+ uint32_t color_depth() const;
- uint64_t* framebuffer_address();
+ uint64_t* framebuffer_address();
- void put_pixel(int32_t x, int32_t y, const Colour& colour);
- void putPixel(int32_t x, int32_t y, uint32_t colour);
- Colour get_pixel(int32_t x, int32_t y);
- void invert_pixel(int32_t x, int32_t y);
+ void put_pixel(int32_t x, int32_t y, const Colour& colour);
+ void putPixel(int32_t x, int32_t y, uint32_t colour);
+ Colour get_pixel(int32_t x, int32_t y);
+ void invert_pixel(int32_t x, int32_t y);
- void draw_line(int32_t x0, int32_t y0, int32_t x1, int32_t y1, const Colour& colour);
- void drawLine(int32_t x0, int32_t y0, int32_t x1, int32_t y1, uint32_t colour);
+ void draw_line(int32_t x0, int32_t y0, int32_t x1, int32_t y1, const Colour& colour);
+ void drawLine(int32_t x0, int32_t y0, int32_t x1, int32_t y1, uint32_t colour);
- void draw_rectangle(int32_t x0, int32_t y0, int32_t x1, int32_t y1, const Colour& colour);
- void draw_rectangle(int32_t x0, int32_t y0, int32_t x1, int32_t y1, uint32_t colour);
+ void draw_rectangle(int32_t x0, int32_t y0, int32_t x1, int32_t y1, const Colour& colour);
+ void draw_rectangle(int32_t x0, int32_t y0, int32_t x1, int32_t y1, uint32_t colour);
- void fill_rectangle(int32_t x0, int32_t y0, int32_t x1, int32_t y1, const Colour& colour);
- void fill_rectangle(int32_t x0, int32_t y0, int32_t x1, int32_t y1, uint32_t colour);
+ void fill_rectangle(int32_t x0, int32_t y0, int32_t x1, int32_t y1, const Colour& colour);
+ void fill_rectangle(int32_t x0, int32_t y0, int32_t x1, int32_t y1, uint32_t colour);
- void draw_circle(int32_t x0, int32_t y0, int32_t radius, const Colour& colour);
- void draw_circle(int32_t x0, int32_t y0, int32_t radius, uint32_t colour);
+ void draw_circle(int32_t x0, int32_t y0, int32_t radius, const Colour& colour);
+ void draw_circle(int32_t x0, int32_t y0, int32_t radius, uint32_t colour);
- void fill_circle(int32_t x0, int32_t y0, int32_t radius, const Colour& colour);
- void fillCircle(int32_t x0, int32_t y0, int32_t radius, uint32_t colour);
+ void fill_circle(int32_t x0, int32_t y0, int32_t radius, const Colour& colour);
+ void fillCircle(int32_t x0, int32_t y0, int32_t radius, uint32_t colour);
- };
+ };
- }
+ }
}
#endif //MaxOS_COMMON_GRAPHICSCONTEX_H
diff --git a/kernel/include/common/logger.h b/kernel/include/common/logger.h
index 0f9ee010..55c72378 100644
--- a/kernel/include/common/logger.h
+++ b/kernel/include/common/logger.h
@@ -13,85 +13,86 @@
#include
#include
+namespace MaxOS{
- /**
- * @enum LogLevel
- * @brief Priority levels for logging messages. Different levels may be used to filter messages based on their importance depending on build type.
- */
- enum class LogLevel
- {
- WARNING,
- ERROR,
- HEADER,
- INFO,
- DEBUG,
- };
-
-
- constexpr uint8_t MAX_LOG_WRITERS = 5; ///< The maximum number of log writers that can be added to the logger
- constexpr LogLevel MAX_LOG_LEVEL = LogLevel::DEBUG; ///< The maximum log level for this build (messages above this level will not be logged)
-
- /**
- * @class Logger
- * @brief A class that handles logging messages to the console and files.
- */
- class Logger : public MaxOS::common::OutputStream
- {
- private:
-
- // Cant use vector as this needs to be init before the heap
- uint8_t m_log_writer_count = 0;
- OutputStream* m_log_writers[MAX_LOG_WRITERS] = {nullptr, nullptr, nullptr, nullptr, nullptr};
- bool m_log_writers_enabled[MAX_LOG_WRITERS] = {false, false, false, false, false};
-
- // Progress bar
- static inline uint8_t s_progress_total = 100;
- uint8_t m_progress_current = 0;
-
- static inline Logger* s_active_logger = nullptr;
-
- LogLevel m_log_level = LogLevel::INFO;
-
- public:
- Logger();
- ~Logger();
-
- void add_log_writer(OutputStream* log_writer);
- void disable_log_writer(OutputStream* log_writer);
-
- void set_log_level(LogLevel log_level);
-
- void write_char(char c) final;
- void printf(const char* format, ...);
-
- static void ASSERT(bool condition, const char* message, ...);
-
- static Logger* active_logger();
-
- static Logger& Out();
-
- static Logger HEADER();
- static Logger INFO();
- static Logger DEBUG();
- static Logger WARNING();
- static Logger ERROR();
-
- using OutputStream::operator<<;
- Logger& operator << (LogLevel log_level);
- };
-
- /**
- * @brief If the specified condition is not met then the kernel will crash with the specified message.
- *
- * This macro wraps Logger::ASSERT and supports printf-style formatting with variadic arguments.
- *
- * @param condition The condition to check.
- * @param format The format string (like printf).
- * @param ... Additional arguments to format.
- *
- * @see Logger::ASSERT
- */
- #define ASSERT(condition, format, ...) Logger::ASSERT(condition, format, ##__VA_ARGS__)
+/**
+ * @enum LogLevel
+ * @brief Priority levels for logging messages. Different levels may be used to filter messages based on their importance depending on build type.
+ */
+ enum class LogLevel {
+ WARNING,
+ ERROR,
+ HEADER,
+ INFO,
+ DEBUG,
+ };
+
+
+ constexpr uint8_t MAX_LOG_WRITERS = 5; ///< The maximum number of log writers that can be added to the logger
+ constexpr LogLevel MAX_LOG_LEVEL = LogLevel::DEBUG; ///< The maximum log level for this build (messages above this level will not be logged)
+
+/**
+ * @class Logger
+ * @brief A class that handles logging messages to the console and files.
+ */
+ class Logger : public MaxOS::common::OutputStream {
+ private:
+
+ // Cant use vector as this needs to be init before the heap
+ uint8_t m_log_writer_count = 0;
+ OutputStream* m_log_writers[MAX_LOG_WRITERS] = { nullptr, nullptr, nullptr, nullptr, nullptr };
+ bool m_log_writers_enabled[MAX_LOG_WRITERS] = { false, false, false, false, false };
+
+ // Progress bar
+ static inline uint8_t s_progress_total = 100;
+ uint8_t m_progress_current = 0;
+
+ static inline Logger* s_active_logger = nullptr;
+
+ LogLevel m_log_level = LogLevel::INFO;
+
+ public:
+ Logger();
+ ~Logger();
+
+ void add_log_writer(OutputStream* log_writer);
+ void disable_log_writer(OutputStream* log_writer);
+
+ void set_log_level(LogLevel log_level);
+
+ void write_char(char c) final;
+ void printf(const char* format, ...);
+
+ static void ASSERT(bool condition, const char* message, ...);
+
+ static Logger* active_logger();
+
+ static Logger &Out();
+
+ static Logger HEADER();
+ static Logger INFO();
+ static Logger DEBUG();
+ static Logger WARNING();
+ static Logger ERROR();
+
+ using OutputStream::operator<<;
+ Logger &operator<<(LogLevel log_level);
+ };
+
+ /**
+ * @brief If the specified condition is not met then the kernel will crash with the specified message.
+ *
+ * This macro wraps Logger::ASSERT and supports printf-style formatting with variadic arguments.
+ *
+ * @param condition The condition to check.
+ * @param format The format string (like printf).
+ * @param ... Additional arguments to format.
+ *
+ * @see Logger::ASSERT
+ */
+ #define ASSERT(condition, format, ...) Logger::ASSERT(condition, format, ##__VA_ARGS__)
+
+}
#endif // MAXOS_COMMON_LOGGER_H
diff --git a/kernel/include/common/macros.h b/kernel/include/common/macros.h
index d1cf3839..fad02a8b 100644
--- a/kernel/include/common/macros.h
+++ b/kernel/include/common/macros.h
@@ -15,6 +15,17 @@ namespace MaxOS{
#define PACKED __attribute__((packed))
#endif
+ #ifdef DOXYGEN
+ /// Align to page size (4096 bytes)
+ #define PAGE_ALIGNED
+ #else
+ /// Align to page size (4096 bytes)
+ #define PAGE_ALIGNED __attribute__((aligned(4096)))
+ #endif
+
+
+
+
}
diff --git a/kernel/include/common/string.h b/kernel/include/common/string.h
index a8fbe3c2..00ffed65 100644
--- a/kernel/include/common/string.h
+++ b/kernel/include/common/string.h
@@ -19,75 +19,75 @@ namespace MaxOS {
/// How many characters can be stored in the small string optimization array
constexpr int MAX_STRING_SMALL_STORAGE = 0x99;
- /**
- * @class String
- * @brief Dynamically sized string with various operations
- */
- typedef class String {
- private:
- char* m_string = nullptr;
- int m_length = 0; // Does not include the null terminator
+ /**
+ * @class String
+ * @brief Dynamically sized string with various operations
+ */
+ typedef class String {
+ private:
+ char* m_string = nullptr;
+ int m_length = 0; // Does not include the null terminator
- char m_small_string[MAX_STRING_SMALL_STORAGE] = {0};
- bool m_using_small = true;
+ char m_small_string[MAX_STRING_SMALL_STORAGE] = { 0 };
+ bool m_using_small = true;
- [[nodiscard]] static int lex_value(String const &other) ;
- void allocate_self();
+ [[nodiscard]] static int lex_value(String const &other);
+ void allocate_self();
- public:
+ public:
- String();
- explicit String(char c);
- String(char const* string);
- String(uint8_t const* string, int length);
- String(String const &other);
- explicit String(int value);
- explicit String(uint64_t value);
- explicit String(float value);
- explicit String(bool value);
- ~String();
+ String();
+ explicit String(char c);
+ String(char const* string);
+ String(uint8_t const* string, int length);
+ String(String const &other);
+ explicit String(int value);
+ explicit String(uint64_t value);
+ explicit String(float value);
+ explicit String(bool value);
+ ~String();
- void copy(String const &other);
+ void copy(String const &other);
- static String formatted(char const *format, ...);
- static String formatted(char const *format, va_list parameters);
+ static String formatted(char const* format, ...);
+ static String formatted(char const* format, va_list parameters);
- [[nodiscard]] int length(bool count_ansi = true) const;
- char* c_str();
- const char* c_str() const;
+ [[nodiscard]] int length(bool count_ansi = true) const;
+ char* c_str();
+ const char* c_str() const;
- bool starts_with(String const &other);
- [[nodiscard]] String substring(int start, int length) const;
+ bool starts_with(String const &other);
+ [[nodiscard]] String substring(int start, int length) const;
- [[nodiscard]] common::Vector split(String const &delimiter) const;
- [[nodiscard]] String strip(char strip_char = ' ') const;
+ [[nodiscard]] common::Vector split(String const &delimiter) const;
+ [[nodiscard]] String strip(char strip_char = ' ') const;
- [[nodiscard]] String center(int width, char fill = ' ') const;
+ [[nodiscard]] String center(int width, char fill = ' ') const;
- // Operator functions
- [[nodiscard]] bool equals(String const &other) const;
+ // Operator functions
+ [[nodiscard]] bool equals(String const &other) const;
- // Operators
- String &operator = (String const &other);
- String operator + (String const &other) const;
- String &operator += (String const &other);
+ // Operators
+ String &operator=(String const &other);
+ String operator+(String const &other) const;
+ String &operator+=(String const &other);
- String operator * (int times) const;
+ String operator*(int times) const;
- bool operator == (String const &other) const;
- bool operator != (String const &other) const;
+ bool operator==(String const &other) const;
+ bool operator!=(String const &other) const;
- bool operator < (String const &other) const;
- bool operator > (String const &other) const;
+ bool operator<(String const &other) const;
+ bool operator>(String const &other) const;
- bool operator <= (String const &other) const;
- bool operator >= (String const &other) const;
+ bool operator<=(String const &other) const;
+ bool operator>=(String const &other) const;
- char& operator [] (int index);
- char& operator [] (int index) const;
+ char &operator[](int index);
+ char &operator[](int index) const;
- } string; ///< Typedef for String
+ } string; ///< Typedef for String
/**
* @class StringBuilder
@@ -98,34 +98,34 @@ namespace MaxOS {
class StringBuilder {
public:
String out; ///< The output string
- operator String() const { return out; } ///< Convert to string
+ operator String() const { return out; } ///< Convert to string
- StringBuilder& operator << (char const* str) { out += string(str); return *this; } ///< Append C-string
- StringBuilder& operator << (String const &other) { out += other; return *this; } ///< Append String
- StringBuilder& operator << (int value) { out += string(value); return *this; } ///< Append int
- StringBuilder& operator << (uint64_t value) { out += string(value); return *this; } ///< Append hex
- StringBuilder& operator << (float value) { out += string(value); return *this; } ///< Append decimal
- StringBuilder& operator << (bool value) { out += string(value); return *this; } ///< Append bool
+ StringBuilder &operator<<(char const* str);
+ StringBuilder &operator<<(String const &other);
+ StringBuilder &operator<<(int value);
+ StringBuilder &operator<<(uint64_t value);
+ StringBuilder &operator<<(float value);
+ StringBuilder &operator<<(bool value);
};
}
// Convert functions
int strlen(const char* str);
-char* itoa(int base, int64_t number);
+char* itoa(int base, int64_t number);
char* htoa(uint64_t number);
char* ftoa(float number);
// Compare functions
-bool strcmp(char const *str1, char const *str2);
-bool strcmp(char const *str1, MaxOS::String const &str2);
-bool strcmp(MaxOS::String const &str1, char const *str2);
+bool strcmp(char const* str1, char const* str2);
+bool strcmp(char const* str1, MaxOS::String const &str2);
+bool strcmp(MaxOS::String const &str1, char const* str2);
bool strcmp(MaxOS::String const &str1, MaxOS::String const &str2);
// Compare limited functions
-bool strncmp(char const *str1, char const *str2, int length);
-bool strncmp(char const *str1, MaxOS::String const &str2, int length);
-bool strncmp(MaxOS::String const &str1, char const *str2, int length);
+bool strncmp(char const* str1, char const* str2, int length);
+bool strncmp(char const* str1, MaxOS::String const &str2, int length);
+bool strncmp(MaxOS::String const &str1, char const* str2, int length);
bool strncmp(MaxOS::String const &str1, MaxOS::String const &str2, int length);
#endif //MAXOS_STRING_H
diff --git a/kernel/include/common/vector.h b/kernel/include/common/vector.h
index 12e7f363..37928c6c 100644
--- a/kernel/include/common/vector.h
+++ b/kernel/include/common/vector.h
@@ -12,107 +12,105 @@
#include
#include
-namespace MaxOS{
-
- namespace common{
-
- /**
- * @class VectorIterationHandler
- * @brief Handles the iteration of a Vector providing read and end of stream functions
- *
- * @tparam Type Type of the Vector
- */
- template class VectorIterationHandler
- {
- public:
- VectorIterationHandler();
- ~VectorIterationHandler();
-
- virtual void on_read(Type);
- virtual void on_end_of_stream();
- };
-
- /**
- * @class Vector
- * @brief Dynamically stores an array of elements
- *
- * @tparam Type Type of the Vector
- */
- template class Vector
- {
- protected:
- Type* m_elements; ///< The array of elements
- uint32_t m_size { 0 }; ///< How many elements are currently stored
- uint32_t m_capacity { 1 }; ///< How many elements can be stored without resizing
-
- public:
- typedef Type* iterator; ///< The iterator type for the Vector
-
- Vector();
- Vector(int Size, Type element);
- Vector(const Vector& other);
- Vector(Vector&& other);
- ~Vector();
-
- Type& operator[](uint32_t index) const;
- Vector& operator=(const Vector& other);
- Vector& operator=(Vector&& other);
-
- [[nodiscard]] bool empty() const;
- [[nodiscard]] uint32_t size() const;
-
- iterator begin() const;
- iterator end() const;
- iterator find(Type) const;
-
- iterator push_back(Type);
- Type pop_back();
-
- iterator push_front(Type);
- Type pop_front();
-
- void erase(Type);
- void erase(typename Vector::iterator position);
- void clear();
-
- void reserve(size_t amount);
- void increase_size();
-
- void iterate(VectorIterationHandler*);
- void Iterate(void callback(Type&));
- };
-
- ///______________________________________Implementation__________________________________________________
- /**
- * @brief Constructor for Vector
- *
- * @tparam Type Type of the Vector
- */
- template Vector::Vector() {
-
- // Allocate space for the array
- m_elements = new Type[m_capacity];
-
- }
-
- /**
- * @brief Constructor for Vector
- *
- * @tparam Type Type of the Vector
- * @param size Size of the Vector
- * @param element Element to fill the Vector with
- */
- template Vector::Vector(int size, Type element) {
-
- // Allocate space for the array
- m_elements = new Type[size];
- m_capacity = size > 0 ? size : 1;
- m_size = 0;
-
- // Push all the elements to the Vector
- for (int i = 0; i < size; ++i)
- push_back(element);
- }
+namespace MaxOS {
+
+ namespace common {
+
+ /**
+ * @class VectorIterationHandler
+ * @brief Handles the iteration of a Vector providing read and end of stream functions
+ *
+ * @tparam Type Type of the Vector
+ */
+ template class VectorIterationHandler {
+ public:
+ VectorIterationHandler();
+ ~VectorIterationHandler();
+
+ virtual void on_read(Type);
+ virtual void on_end_of_stream();
+ };
+
+ /**
+ * @class Vector
+ * @brief Dynamically stores an array of elements
+ *
+ * @tparam Type Type of the Vector
+ */
+ template class Vector {
+ protected:
+ Type* m_elements; ///< The array of elements
+ uint32_t m_size { 0 }; ///< How many elements are currently stored
+ uint32_t m_capacity { 1 }; ///< How many elements can be stored without resizing
+
+ public:
+ typedef Type* iterator; ///< The iterator type for the Vector
+
+ Vector();
+ Vector(int Size, Type element);
+ Vector(const Vector& other);
+ Vector(Vector&& other);
+ ~Vector();
+
+ Type& operator [](uint32_t index) const;
+ Vector& operator =(const Vector& other);
+ Vector& operator =(Vector&& other);
+
+ [[nodiscard]] bool empty() const;
+ [[nodiscard]] uint32_t size() const;
+
+ iterator begin() const;
+ iterator end() const;
+ iterator find(Type) const;
+
+ iterator push_back(Type);
+ Type pop_back();
+
+ iterator push_front(Type);
+ Type pop_front();
+
+ void erase(Type);
+ void erase(typename Vector::iterator position);
+ void clear();
+
+ void reserve(size_t amount);
+ void increase_size();
+
+ void iterate(VectorIterationHandler*);
+ void Iterate(void callback(Type&));
+ };
+
+ ///______________________________________Implementation__________________________________________________
+ /**
+ * @brief Constructor for Vector
+ *
+ * @tparam Type Type of the Vector
+ */
+ template Vector::Vector() {
+
+ // Allocate space for the array
+ m_elements = new Type[m_capacity];
+
+ }
+
+ /**
+ * @brief Constructor for Vector
+ *
+ * @tparam Type Type of the Vector
+ * @param size Size of the Vector
+ * @param element Element to fill the Vector with
+ */
+ template Vector::Vector(int size, Type element) {
+
+ // Allocate space for the array
+ m_elements = new Type[size];
+ m_capacity = size > 0 ? size : 1;
+ m_size = 0;
+
+ // Push all the elements to the Vector
+ for (int i = 0; i < size; ++i)
+ push_back(element);
+ }
/**
* @brief Copy constructor for Vector
@@ -120,15 +118,14 @@ namespace MaxOS{
* @tparam Type The type of data to be stored
* @param other The vector to copy from
*/
- template Vector::Vector(const Vector& other)
- : m_size(other.m_size),
- m_capacity(other.m_capacity)
- {
+ template Vector::Vector(const Vector& other)
+ : m_size(other.m_size),
+ m_capacity(other.m_capacity) {
// Copy each element into a new array
- m_elements = new Type[m_capacity];
- for (uint32_t i = 0; i < m_size; ++i)
- m_elements[i] = other.m_elements[i];
- }
+ m_elements = new Type[m_capacity];
+ for (uint32_t i = 0; i < m_size; ++i)
+ m_elements[i] = other.m_elements[i];
+ }
/**
* @brief Move constructor for Vector
@@ -136,34 +133,38 @@ namespace MaxOS{
* @tparam Type The type of data to be stored
* @param other The vector to copy from
*/
- template Vector::Vector(Vector &&other)
+ template Vector::Vector(Vector&& other)
: m_elements(other.m_elements),
- m_size(other.m_size),
- m_capacity(other.m_capacity)
- {
+ m_size(other.m_size),
+ m_capacity(other.m_capacity) {
// Clear the other Vector
other.m_elements = nullptr;
other.m_size = 0;
other.m_capacity = 0;
- }
+ }
- template Vector::~Vector() {
+ /**
+ * @brief Destructor for Vector, de-allocates the array
+ *
+ * @tparam Type Type data stored in the Vector
+ */
+ template Vector::~Vector() {
- // De-allocate the array
- delete[] m_elements;
+ // De-allocate the array
+ delete[] m_elements;
- }
+ }
- /**
- * @brief Increases the size of the Vector by doubling the capacity
- *
- * @tparam Type Type of the Vector
- */
- template void Vector::increase_size() {
- reserve(m_capacity * 2);
- }
+ /**
+ * @brief Increases the size of the Vector by doubling the capacity
+ *
+ * @tparam Type Type of the Vector
+ */
+ template void Vector::increase_size() {
+ reserve(m_capacity * 2);
+ }
/**
* @brief Reserves space in the Vector for a certain amount of elements
@@ -171,45 +172,45 @@ namespace MaxOS{
* @tparam Type Type of the Vector
* @param amount The amount of elements to reserve space for
*/
- template void Vector::reserve(size_t amount) {
+ template void Vector::reserve(size_t amount) {
- // Increase the capacity of the Vector
- if(m_capacity < amount)
+ // Increase the capacity of the Vector
+ if (m_capacity < amount)
m_capacity = amount;
- // Allocate more space for the array
- Type* new_elements = new Type[amount];
+ // Allocate more space for the array
+ Type* new_elements = new Type[amount];
- // Copy the elements to the new array
- for (uint32_t i = 0; i < m_size; ++i)
- new_elements[i] = m_elements[i];
+ // Copy the elements to the new array
+ for (uint32_t i = 0; i < m_size; ++i)
+ new_elements[i] = m_elements[i];
- // De-allocate the old array
- delete[] m_elements;
+ // De-allocate the old array
+ delete[] m_elements;
- // Set the new array
- m_elements = new_elements;
- }
+ // Set the new array
+ m_elements = new_elements;
+ }
- /**
- * @brief Overloads the [] operator to return the element at the index
- *
- * @tparam Type Type of the Vector
- * @param index The index of the element
- * @return the element at the index or the end of the Vector if the index is out of bounds
- */
- template Type &Vector::operator[](uint32_t index) const{
+ /**
+ * @brief Overloads the [] operator to return the element at the index
+ *
+ * @tparam Type Type of the Vector
+ * @param index The index of the element
+ * @return the element at the index or the end of the Vector if the index is out of bounds
+ */
+ template Type& Vector::operator [](uint32_t index) const {
- // If the index is in the Vector
- if (index < m_size)
- return m_elements[index];
+ // If the index is in the Vector
+ if (index < m_size)
+ return m_elements[index];
- // Return the last element of the Vector
- return m_elements[m_size - 1];
+ // Return the last element of the Vector
+ return m_elements[m_size - 1];
- }
+ }
/**
* @brief Assignment by copy, data is copied into a new buffer stored in this vector
@@ -218,283 +219,283 @@ namespace MaxOS{
* @param other The vector to copy from
* @return This vector, with the copied elements
*/
- template Vector& Vector::operator=(const Vector& other) {
+ template Vector& Vector::operator =(const Vector& other) {
// Setting to itself?
if (this == &other)
return *this;
// Create a new buffer to store the elements
- delete[] m_elements;
+ delete[] m_elements;
m_elements = new Type[other.m_capacity];
// Copy data
- m_size = other.m_size;
- m_capacity = other.m_capacity;
- for (uint32_t i = 0; i < m_size; ++i)
- m_elements[i] = other.m_elements[i];
+ m_size = other.m_size;
+ m_capacity = other.m_capacity;
+ for (uint32_t i = 0; i < m_size; ++i)
+ m_elements[i] = other.m_elements[i];
- return *this;
- }
+ return *this;
+ }
- /**
+ /**
* @brief Assignment by move, data is moved into the buffer stored in this vector and the other vector is cleared
*
* @tparam Type Type of the Vector
* @param other The vector to copy from
* @return This vector, with the copied elements
*/
- template Vector& Vector::operator=(Vector&& other) noexcept {
+ template Vector& Vector::operator =(Vector&& other) noexcept {
- // Moving to itself?
- if (this == &other)
- return *this;
+ // Moving to itself?
+ if (this == &other)
+ return *this;
- // Move into this vector
- delete[] m_elements;
- m_elements = other.m_elements;
- m_size = other.m_size;
- m_capacity = other.m_capacity;
+ // Move into this vector
+ delete[] m_elements;
+ m_elements = other.m_elements;
+ m_size = other.m_size;
+ m_capacity = other.m_capacity;
// Remove from other vector
- other.m_elements = nullptr;
- other.m_size = 0;
- other.m_capacity = 0;
-
- return *this;
- }
-
- /**
- * @brief Returns the number of elements in the Vector
- *
- * @tparam Type Type of the Vector
- * @return The size of the Vector
- */
- template uint32_t Vector::size() const{
- return m_size;
- }
-
- /**
- * @brief Returns the first element of the Vector
- *
- * @tparam Type Type of the Vector
- * @return The first element of the Vector
- */
- template typename Vector::iterator Vector::begin() const{
- return &m_elements[0];
- }
-
- /**
- * @brief Returns the last element of the Vector
- *
- * @tparam Type Type of the Vector
- * @return The last element of the Vector
- */
- template typename Vector::iterator Vector::end() const{
- return &m_elements[0] + m_size;
- }
-
- /**
- * @brief Finds an element in the Vector and returns the iterator of the element
- *
- * @tparam Type Type of the Vector
- * @param element The element to find
- * @return The iterator of the element or the end of the Vector if the element is not found
- */
- template typename Vector::iterator Vector::find(Type element) const{
-
- // Find the element
- for (iterator i = begin(); i != end(); ++i)
- if (*i == element)
- return i;
-
- // The element must not be in the Vector
- return end();
- }
-
- /**
- * @brief Checks if the Vector is empty
- *
- * @tparam Type Type of the Vector
- * @return True if the Vector is empty, false otherwise
- */
- template bool Vector::empty() const{
- return begin() == end();
- }
-
-
- /**
- * @brief Adds an element to the end of the vector and returns the iterator of the element
- *
- * @tparam Type Type of the Vector
- * @param element The element to add
- * @return The iterator of the element, if the Vector is full it returns the end of the Vector
- */
- template typename Vector::iterator Vector::push_back(Type element) {
-
- // Check if we need to allocate more space for the array
- if(m_size == m_capacity)
- increase_size();
-
- // Add the element to the Vector and return the iterator of the element
- m_elements[m_size++] = element;
- return end() - 1;
- }
-
- /**
- * @brief Removes the last element from the Vector
- * @tparam Type Type of the Vector
- */
- template Type Vector::pop_back() {
-
- // Remove the last element from the Vector
- if (m_size > 0)
- --m_size;
-
- return m_elements[m_size];
- }
-
- /**
- * @brief Adds an element to the front of the Vector and returns the iterator of the element
- *
- * @tparam Type Type of the Vector
- * @param element The element to add
- * @return The iterator of the element, if the Vector is full it returns the end of the Vector
- */
- template typename Vector::iterator Vector::push_front(Type element) {
-
- // Check if we need to allocate more space for the array
- if(m_size == m_capacity)
- increase_size();
-
- // Move all elements one index to the right
- for (iterator i = end(); i > begin(); --i)
- *i = *(i - 1);
-
- // Add the element to the front of the Vector
- m_elements[0] = element;
- ++m_size;
-
- // Return the iterator of the element
- return begin();
- }
-
- /**
- * @brief Removes the m_first_memory_chunk element from the Vector
- *
- * @tparam Type Type of the Vector
- * @return The element that was removed, or a default constructed element if the Vector is empty
- */
- template Type Vector::pop_front() {
-
- // Make sure the Vector is not empty
- if (m_size == 0)
- return Type();
+ other.m_elements = nullptr;
+ other.m_size = 0;
+ other.m_capacity = 0;
+
+ return *this;
+ }
+
+ /**
+ * @brief Returns the number of elements in the Vector
+ *
+ * @tparam Type Type of the Vector
+ * @return The size of the Vector
+ */
+ template uint32_t Vector::size() const {
+ return m_size;
+ }
+
+ /**
+ * @brief Returns the first element of the Vector
+ *
+ * @tparam Type Type of the Vector
+ * @return The first element of the Vector
+ */
+ template typename Vector::iterator Vector::begin() const {
+ return &m_elements[0];
+ }
+
+ /**
+ * @brief Returns the last element of the Vector
+ *
+ * @tparam Type Type of the Vector
+ * @return The last element of the Vector
+ */
+ template typename Vector::iterator Vector::end() const {
+ return &m_elements[0] + m_size;
+ }
+
+ /**
+ * @brief Finds an element in the Vector and returns the iterator of the element
+ *
+ * @tparam Type Type of the Vector
+ * @param element The element to find
+ * @return The iterator of the element or the end of the Vector if the element is not found
+ */
+ template typename Vector::iterator Vector::find(Type element) const {
+
+ // Find the element
+ for (iterator i = begin(); i != end(); ++i)
+ if (*i == element)
+ return i;
+
+ // The element must not be in the Vector
+ return end();
+ }
+
+ /**
+ * @brief Checks if the Vector is empty
+ *
+ * @tparam Type Type of the Vector
+ * @return True if the Vector is empty, false otherwise
+ */
+ template bool Vector::empty() const {
+ return begin() == end();
+ }
+
+
+ /**
+ * @brief Adds an element to the end of the vector and returns the iterator of the element
+ *
+ * @tparam Type Type of the Vector
+ * @param element The element to add
+ * @return The iterator of the element, if the Vector is full it returns the end of the Vector
+ */
+ template typename Vector::iterator Vector::push_back(Type element) {
+
+ // Check if we need to allocate more space for the array
+ if (m_size == m_capacity)
+ increase_size();
+
+ // Add the element to the Vector and return the iterator of the element
+ m_elements[m_size++] = element;
+ return end() - 1;
+ }
+
+ /**
+ * @brief Removes the last element from the Vector
+ * @tparam Type Type of the Vector
+ *
+ * @return The element that was removed
+ */
+ template Type Vector::pop_back() {
+
+ // Remove the last element from the Vector
+ if (m_size > 0)
+ --m_size;
+
+ return m_elements[m_size];
+ }
+
+ /**
+ * @brief Adds an element to the front of the Vector and returns the iterator of the element
+ *
+ * @tparam Type Type of the Vector
+ * @param element The element to add
+ * @return The iterator of the element, if the Vector is full it returns the end of the Vector
+ */
+ template typename Vector::iterator Vector::push_front(Type element) {
+
+ // Check if we need to allocate more space for the array
+ if (m_size == m_capacity)
+ increase_size();
+
+ // Move all elements one index to the right
+ for (iterator i = end(); i > begin(); --i)
+ *i = *(i - 1);
+
+ // Add the element to the front of the Vector
+ m_elements[0] = element;
+ ++m_size;
+
+ // Return the iterator of the element
+ return begin();
+ }
+
+ /**
+ * @brief Removes the m_first_memory_chunk element from the Vector
+ *
+ * @tparam Type Type of the Vector
+ * @return The element that was removed, or a default constructed element if the Vector is empty
+ */
+ template Type Vector::pop_front() {
+
+ // Make sure the Vector is not empty
+ if (m_size == 0)
+ return Type();
// Store the element to return
Type element = m_elements[0];
- // Move all elements one index to the left
- for (uint32_t i = 0; i < m_size - 1; ++i)
- m_elements[i] = m_elements[i + 1];
-
- // Decrease the size of the Vector
- --m_size;
- return element;
- }
-
- /**
- * @brief Removes all elements from the Vector that are equal to the element
- *
- * @tparam Type Type of the Vector
- * @param element The element to remove
- */
- template void Vector::erase(Type element) {
-
- // Search for the element
- int hits = 0;
- for (iterator i = begin(); i != end(); ++i)
- {
- // If it is the element we are looking for
- if (*i == element)
- {
- ++hits;
- } else {
-
- // If there are hits move the element to the left
- if (hits > 0)
- *(i - hits) = *i;
- }
-
- }
-
- // Decrease the size of the Vector
- m_size -= hits;
- }
-
- /**
- * @brief Removes the element at the m_position
- *
- * @tparam Type The type of the Vector
- * @param position The m_position of the element to remove
- */
- template void Vector::erase(typename Vector::iterator position) {
-
- // If the m_position is not in the Vector
- if (position < begin() || position >= end())
- return;
-
- // Move all elements one index to the left
- for (++position; position != end(); ++position)
- *(position - 1) = *position;
-
- // Decrease the size of the Vector
- --m_size;
- }
-
- /**
- * @brief Removes all elements from the Vector
- *
- * @tparam Type Type of the Vector
- */
- template void Vector::clear() {
- m_size = 0;
- }
-
- /**
- * @brief Iterates over the Vector and calls the OnRead function of the handler for each element
- *
- * @tparam Type Type of the Vector
- * @param vector_iteration_handler The handler
- */
- template void Vector::iterate(VectorIterationHandler *vector_iteration_handler) {
-
- // Call the OnRead function of the handler for each element
- for(auto& element : m_elements)
- vector_iteration_handler->on_read(element);
-
- // Call the OnEndOfStream function of the handler
- vector_iteration_handler->on_end_of_stream();
- }
-
-
- /**
- * @brief Iterates over the Vector and calls the callback function for each element
- *
- * @tparam Type Type of the Vector
- * @param callback The callback function
- */
- template void Vector::Iterate(void callback(Type &)) {
-
- // Call the callback function for each element
- for(auto& element : m_elements)
- callback(element);
- }
-
- template VectorIterationHandler::VectorIterationHandler() = default;
-
- template VectorIterationHandler::~VectorIterationHandler() = default;
+ // Move all elements one index to the left
+ for (uint32_t i = 0; i < m_size - 1; ++i)
+ m_elements[i] = m_elements[i + 1];
+
+ // Decrease the size of the Vector
+ --m_size;
+ return element;
+ }
+
+ /**
+ * @brief Removes all elements from the Vector that are equal to the element
+ *
+ * @tparam Type Type of the Vector
+ * @param element The element to remove
+ */
+ template void Vector::erase(Type element) {
+
+ // Search for the element
+ int hits = 0;
+ for (iterator i = begin(); i != end(); ++i) {
+ // If it is the element we are looking for
+ if (*i == element) {
+ ++hits;
+ } else {
+
+ // If there are hits move the element to the left
+ if (hits > 0)
+ *(i - hits) = *i;
+ }
+
+ }
+
+ // Decrease the size of the Vector
+ m_size -= hits;
+ }
+
+ /**
+ * @brief Removes the element at the m_position
+ *
+ * @tparam Type The type of the Vector
+ * @param position The m_position of the element to remove
+ */
+ template void Vector::erase(typename Vector::iterator position) {
+
+ // If the m_position is not in the Vector
+ if (position < begin() || position >= end())
+ return;
+
+ // Move all elements one index to the left
+ for (++position; position != end(); ++position)
+ *(position - 1) = *position;
+
+ // Decrease the size of the Vector
+ --m_size;
+ }
+
+ /**
+ * @brief Removes all elements from the Vector
+ *
+ * @tparam Type Type of the Vector
+ */
+ template void Vector::clear() {
+ m_size = 0;
+ }
+
+ /**
+ * @brief Iterates over the Vector and calls the OnRead function of the handler for each element
+ *
+ * @tparam Type Type of the Vector
+ * @param vector_iteration_handler The handler
+ */
+ template void Vector::iterate(VectorIterationHandler* vector_iteration_handler) {
+
+ // Call the OnRead function of the handler for each element
+ for (auto& element : m_elements)
+ vector_iteration_handler->on_read(element);
+
+ // Call the OnEndOfStream function of the handler
+ vector_iteration_handler->on_end_of_stream();
+ }
+
+
+ /**
+ * @brief Iterates over the Vector and calls the callback function for each element
+ *
+ * @tparam Type Type of the Vector
+ * @param callback The callback function
+ */
+ template void Vector::Iterate(void callback(Type&)) {
+
+ // Call the callback function for each element
+ for (auto& element : m_elements)
+ callback(element);
+ }
+
+ template VectorIterationHandler::VectorIterationHandler() = default;
+
+ template VectorIterationHandler::~VectorIterationHandler() = default;
/**
@@ -502,19 +503,19 @@ namespace MaxOS{
*
* @tparam Type Type of the values stored in the Vector
*/
- template void VectorIterationHandler::on_end_of_stream() {
+ template void VectorIterationHandler::on_end_of_stream() {
- }
+ }
/**
* @brief Called when an element is read from the Vector (overridden by subclasses, no default behavior)
*
* @tparam Type Type of the values stored in the Vector
*/
- template void VectorIterationHandler::on_read(Type) {
+ template void VectorIterationHandler::on_read(Type) {
- }
- }
+ }
+ }
}
diff --git a/kernel/include/drivers/disk/ide.h b/kernel/include/drivers/disk/ide.h
index 440b5393..2364d9ff 100644
--- a/kernel/include/drivers/disk/ide.h
+++ b/kernel/include/drivers/disk/ide.h
@@ -31,7 +31,7 @@ namespace MaxOS {
common::Map devices;
public:
- IntegratedDriveElectronicsController(hardwarecommunication::PeripheralComponentInterconnectDeviceDescriptor* device_descriptor);
+ IntegratedDriveElectronicsController(hardwarecommunication::PCIDeviceDescriptor* device_descriptor);
~IntegratedDriveElectronicsController();
void initialise() final;
diff --git a/kernel/include/drivers/ethernet/amd_am79c973.h b/kernel/include/drivers/ethernet/amd_am79c973.h
index 4b89c340..586269e1 100644
--- a/kernel/include/drivers/ethernet/amd_am79c973.h
+++ b/kernel/include/drivers/ethernet/amd_am79c973.h
@@ -103,7 +103,7 @@ namespace MaxOS {
void FetchDataSent(); //Fetches the data from the buffer
public:
- AMD_AM79C973(hardwarecommunication::PeripheralComponentInterconnectDeviceDescriptor* device_descriptor);
+ AMD_AM79C973(hardwarecommunication::PCIDeviceDescriptor* dev);
~AMD_AM79C973();
// Override driver default methods
diff --git a/kernel/include/drivers/ethernet/intel_i217.h b/kernel/include/drivers/ethernet/intel_i217.h
index 911e2e5b..61adc625 100644
--- a/kernel/include/drivers/ethernet/intel_i217.h
+++ b/kernel/include/drivers/ethernet/intel_i217.h
@@ -20,11 +20,11 @@
#include
#include
-namespace MaxOS{
+namespace MaxOS {
- namespace drivers {
+ namespace drivers {
- namespace ethernet{
+ namespace ethernet {
/**
* @struct ReceiveDescriptor
@@ -33,14 +33,14 @@ namespace MaxOS{
* @typedef receive_descriptor_t
* @brief Alias for ReceiveDescriptor struct
*/
- typedef struct PACKED ReceiveDescriptor {
- uint64_t bufferAddress; ///< The address of the receive buffer
- uint16_t length; ///< The length of the received frame
- uint16_t checksum; ///< The checksum of the received frame
- uint8_t status; ///< The status of the received frame
- uint8_t errors; ///< Any errors that occurred
- uint16_t special; ///< Special
- } receive_descriptor_t;
+ typedef struct PACKED ReceiveDescriptor {
+ uint64_t bufferAddress; ///< The address of the receive buffer
+ uint16_t length; ///< The length of the received frame
+ uint16_t checksum; ///< The checksum of the received frame
+ uint8_t status; ///< The status of the received frame
+ uint8_t errors; ///< Any errors that occurred
+ uint16_t special; ///< Special
+ } receive_descriptor_t;
/**
* @struct SendDescriptor
@@ -49,110 +49,110 @@ namespace MaxOS{
* @typedef send_descriptor_t
* @brief Alias for SendDescriptor struct
*/
- typedef struct PACKED SendDescriptor {
- uint64_t bufferAddress; ///< The address of the send buffer
- uint16_t length; ///< The length of the send frame
- uint8_t cso; ///< The checksum offset
- uint8_t cmd; ///< The command
- uint8_t status; ///< The status
- uint8_t css; ///< The checksum start
- uint16_t special; ///< Special
- } send_descriptor_t;
+ typedef struct PACKED SendDescriptor {
+ uint64_t bufferAddress; ///< The address of the send buffer
+ uint16_t length; ///< The length of the send frame
+ uint8_t cso; ///< The checksum offset
+ uint8_t cmd; ///< The command
+ uint8_t status; ///< The status
+ uint8_t css; ///< The checksum start
+ uint16_t special; ///< Special
+ } send_descriptor_t;
- /**
- * @class IntelI217
- * @brief Driver for the Intel I217 Ethernet Controller
- */
- class IntelI217 : public EthernetDriver, public hardwarecommunication::InterruptHandler {
+ /**
+ * @class IntelI217
+ * @brief Driver for the Intel I217 Ethernet Controller
+ */
+ class IntelI217 : public EthernetDriver, public hardwarecommunication::InterruptHandler {
- uint8_t bar_type = { 0 };
- uint16_t portBase = { 0 };
- uint64_t memBase = { 0 };
- uint8_t macAddress[6] = { 0 };
+ uint8_t bar_type = { 0 };
+ uint16_t portBase = { 0 };
+ uint64_t memBase = { 0 };
+ uint8_t macAddress[6] = { 0 };
- //Registers Addresses (Main Registers)
- uint16_t controlRegister; // The control register
- uint16_t statusRegister; // The status register
- uint16_t epromRegister; // The address of the eeprom register
- uint16_t controlExtRegister; // The control extension register
- uint16_t interruptMaskRegister; // The interrupt mask register
+ //Registers Addresses (Main Registers)
+ uint16_t controlRegister; // The control register
+ uint16_t statusRegister; // The status register
+ uint16_t epromRegister; // The address of the eeprom register
+ uint16_t controlExtRegister; // The control extension register
+ uint16_t interruptMaskRegister; // The interrupt mask register
- //Registers Addresses (Receive Registers)
- uint16_t receiveControlRegister; // The receive control register
- uint16_t receiveDescriptorLowRegister; // The receive descriptor low register
- uint16_t receiveDescriptorHighRegister; // The receive descriptor high register
- uint16_t receiveDescriptorLengthRegister;// The receive descriptor length register
- uint16_t receiveDescriptorHeadRegister; // The receive descriptor head register
- uint16_t receiveDescriptorTailRegister; // The receive descriptor tail register
+ //Registers Addresses (Receive Registers)
+ uint16_t receiveControlRegister; // The receive control register
+ uint16_t receiveDescriptorLowRegister; // The receive descriptor low register
+ uint16_t receiveDescriptorHighRegister; // The receive descriptor high register
+ uint16_t receiveDescriptorLengthRegister;// The receive descriptor length register
+ uint16_t receiveDescriptorHeadRegister; // The receive descriptor head register
+ uint16_t receiveDescriptorTailRegister; // The receive descriptor tail register
- //Registers Addresses (Send Registers)
- uint16_t sendControlRegister; // The send control register
- uint16_t sendDescriptorLowRegister; // The send descriptor low register
- uint16_t sendDescriptorHighRegister; // The send descriptor high register
- uint16_t sendDescriptorLengthRegister; // The send descriptor length register
- uint16_t sendDescriptorHeadRegister; // The send descriptor head register
- uint16_t sendDescriptorTailRegister; // The send descriptor tail register
+ //Registers Addresses (Send Registers)
+ uint16_t sendControlRegister; // The send control register
+ uint16_t sendDescriptorLowRegister; // The send descriptor low register
+ uint16_t sendDescriptorHighRegister; // The send descriptor high register
+ uint16_t sendDescriptorLengthRegister; // The send descriptor length register
+ uint16_t sendDescriptorHeadRegister; // The send descriptor head register
+ uint16_t sendDescriptorTailRegister; // The send descriptor tail register
- //Buffers
- struct receiveDescriptor *receiveDsrctrs[32]; // The receive descriptors
- uint16_t currentReceiveBuffer; // The current receive buffer
+ //Buffers
+ receive_descriptor_t* receiveDsrctrs[32]; // The receive descriptors
+ uint16_t currentReceiveBuffer; // The current receive buffer
- struct sendDescriptor *sendDsrctrs[8]; // The send descriptors
- uint16_t currentSendBuffer; // The current send buffer
+ send_descriptor_t * sendDsrctrs[8]; // The send descriptors
+ uint16_t currentSendBuffer; // The current send buffer
- // write Commands and read results From NICs either using MemIO or IO Ports
- void Write(uint16_t address, uint32_t data) const;
- uint32_t Read(uint16_t address) const;
+ // write Commands and read results From NICs either using MemIO or IO Ports
+ void Write(uint16_t address, uint32_t data) const;
+ uint32_t Read(uint16_t address) const;
- //EPROM (Device Memory)
- bool epromPresent; // Whether the EPROM is present
- bool detectEEProm(); // Return true if EEProm exist, else it returns false and set the error_exists data member
- uint32_t eepromRead( uint8_t addr); // read 4 bytes from a specific EEProm Address
+ //EPROM (Device Memory)
+ bool epromPresent; // Whether the EPROM is present
+ bool detectEEProm(); // Return true if EEProm exist, else it returns false and set the error_exists data member
+ uint32_t eepromRead(uint8_t addr); // read 4 bytes from a specific EEProm Address
- bool readMACAddress(); // read MAC Address
+ bool readMACAddress(); // read MAC Address
- void receiveInit(); // Initialise receive descriptors buffers
- void sendInit(); // Initialise transmit descriptors buffers
+ void receiveInit(); // Initialise receive descriptors buffers
+ void sendInit(); // Initialise transmit descriptors buffers
- //Ethernet Driver functions
- MediaAccessControlAddress ownMAC; //MAC address of the device
- volatile bool active; //Is the device active
- volatile bool initDone; //Is the device initialised
+ //Ethernet Driver functions
+ MediaAccessControlAddress ownMAC; //MAC address of the device
+ volatile bool active; //Is the device active
+ volatile bool initDone; //Is the device initialised
- void FetchDataReceived(); //Fetches the data from the buffer
+ void FetchDataReceived(); //Fetches the data from the buffer
- public:
+ public:
- IntelI217(hardwarecommunication::PeripheralComponentInterconnectDeviceDescriptor* deviceDescriptor);
- ~IntelI217(); // Default Destructor
+ IntelI217(hardwarecommunication::PCIDeviceDescriptor* deviceDescriptor);
+ ~IntelI217(); // Default Destructor
- //Override driver default methods
- uint32_t reset() final;
- void activate() final;
- void deactivate() final;
+ //Override driver default methods
+ uint32_t reset() final;
+ void activate() final;
+ void deactivate() final;
- //Override Interrupt default methods
- void handle_interrupt() final;
+ //Override Interrupt default methods
+ void handle_interrupt() final;
- //Ethernet Driver functions
- string vendor_name() final;
- string device_name() final;
+ //Ethernet Driver functions
+ string vendor_name() final;
+ string device_name() final;
- void DoSend(uint8_t* buffer, uint32_t size) final;
- uint64_t GetMediaAccessControlAddress() final;
- };
+ void DoSend(uint8_t* buffer, uint32_t size) final;
+ uint64_t GetMediaAccessControlAddress() final;
+ };
- }
- }
+ }
+ }
}
diff --git a/kernel/include/drivers/peripherals/keyboard.h b/kernel/include/drivers/peripherals/keyboard.h
index def2e33d..dca10bde 100644
--- a/kernel/include/drivers/peripherals/keyboard.h
+++ b/kernel/include/drivers/peripherals/keyboard.h
@@ -31,7 +31,7 @@ namespace MaxOS {
*/
enum class ScanCodeType : int {
REGULAR,
- EXTENDED,237
+ EXTENDED,
EXTENDED_BUFFER
};
@@ -238,7 +238,7 @@ namespace MaxOS {
* @enum KeyboardEvents
* @brief The events that can be triggered by the Keyboard Driver
*/
- enum class KeyboardEvents {f
+ enum class KeyboardEvents {
KEYDOWN,
KEYUP
};
diff --git a/kernel/include/drivers/peripherals/mouse.h b/kernel/include/drivers/peripherals/mouse.h
index 2b188699..ab49bf5e 100644
--- a/kernel/include/drivers/peripherals/mouse.h
+++ b/kernel/include/drivers/peripherals/mouse.h
@@ -19,94 +19,96 @@
#include
namespace MaxOS {
- namespace drivers {
- namespace peripherals {
+ namespace drivers {
+ namespace peripherals {
/**
* @enum MouseEvents
* @brief The different types of mouse events that can be triggered
*/
- enum class MouseEvents{
- MOVE,
- DOWN,
- UP
- };
-
- /**
- * @class MouseMoveEvent
- * @brief Event that is triggered when the mouse moves, holds the x and y coordinates
- */
- class MouseMoveEvent : public common::Event{
- public:
- int8_t x; ///< The x coordinate of the mouse
- int8_t y; ///< The y coordinate of the mouse
- MouseMoveEvent(int8_t x, int8_t y);
- ~MouseMoveEvent();
- };
-
- /**
- * @class MouseDownEvent
- * @brief Event that is triggered when a mouse button is pressed, holds the button that was pressed
- */
- class MouseDownEvent : public common::Event{
- public:
- uint8_t button; ///< The button that was pressed
- MouseDownEvent(uint8_t);
- ~MouseDownEvent();
- };
-
- /**
- * @class MouseUpEvent
- * @brief Event that is triggered when a mouse button is released, holds the button that was released
- */
- class MouseUpEvent : public common::Event{
- public:
- uint8_t button; ///< The button that was released
- MouseUpEvent(uint8_t);
- ~MouseUpEvent();
- };
-
- /**
- * @class MouseEventHandler
- * @brief Handles events that are triggered by the mouse driver
- */
- class MouseEventHandler : public common::EventHandler{
-
- public:
- MouseEventHandler();
- ~MouseEventHandler();
-
- common::Event*
- on_event(common::Event*) override;
-
- virtual void on_mouse_down_event(uint8_t button);
- virtual void on_mouse_up_event(uint8_t button);
- virtual void on_mouse_move_event(int8_t x, int8_t y);
- };
-
- /**
- * @class MouseDriver
- * @brief Driver for the PS/2 mouse, manages the mouse and triggers events when the mouse moves or a button is pressed
- */
- class MouseDriver : public hardwarecommunication::InterruptHandler, public Driver, public common::EventManager{
- hardwarecommunication::Port8Bit data_port;
- hardwarecommunication::Port8Bit command_port;
-
- void handle_interrupt() final;
-
- uint8_t m_buffer[3] = {};
- uint8_t m_offset = 0;
- uint8_t m_buttons = 0;
-
- public:
- MouseDriver();
- ~MouseDriver();
-
- void activate() final;
- string device_name() final;
- };
- }
- }
+ enum class MouseEvents {
+ MOVE,
+ DOWN,
+ UP
+ };
+
+ /**
+ * @class MouseMoveEvent
+ * @brief Event that is triggered when the mouse moves, holds the x and y coordinates
+ */
+ class MouseMoveEvent : public common::Event {
+ public:
+ int8_t x; ///< The x coordinate of the mouse
+ int8_t y; ///< The y coordinate of the mouse
+ MouseMoveEvent(int8_t x, int8_t y);
+ ~MouseMoveEvent();
+ };
+
+ /**
+ * @class MouseDownEvent
+ * @brief Event that is triggered when a mouse button is pressed, holds the button that was pressed
+ */
+ class MouseDownEvent : public common::Event {
+ public:
+ uint8_t button; ///< The button that was pressed
+ MouseDownEvent(uint8_t);
+ ~MouseDownEvent();
+ };
+
+ /**
+ * @class MouseUpEvent
+ * @brief Event that is triggered when a mouse button is released, holds the button that was released
+ */
+ class MouseUpEvent : public common::Event {
+ public:
+ uint8_t button; ///< The button that was released
+ MouseUpEvent(uint8_t);
+ ~MouseUpEvent();
+ };
+
+ /**
+ * @class MouseEventHandler
+ * @brief Handles events that are triggered by the mouse driver
+ */
+ class MouseEventHandler : public common::EventHandler {
+
+ public:
+ MouseEventHandler();
+ ~MouseEventHandler();
+
+ common::Event*
+ on_event(common::Event*) override;
+
+ virtual void on_mouse_down_event(uint8_t button);
+ virtual void on_mouse_up_event(uint8_t button);
+ virtual void on_mouse_move_event(int8_t x, int8_t y);
+ };
+
+ /**
+ * @class MouseDriver
+ * @brief Driver for the PS/2 mouse, manages the mouse and triggers events when the mouse moves or a button is pressed
+ */
+ class MouseDriver : public hardwarecommunication::InterruptHandler, public Driver, public common::EventManager {
+
+ private:
+ hardwarecommunication::Port8Bit data_port;
+ hardwarecommunication::Port8Bit command_port;
+
+ void handle_interrupt() final;
+
+ uint8_t m_buffer[3] = { };
+ uint8_t m_offset = 0;
+ uint8_t m_buttons = 0;
+
+ public:
+ MouseDriver();
+ ~MouseDriver();
+
+ void activate() final;
+ string device_name() final;
+ };
+ }
+ }
}
diff --git a/kernel/include/filesystem/format/fat32.h b/kernel/include/filesystem/format/fat32.h
index aef84795..9e52b297 100644
--- a/kernel/include/filesystem/format/fat32.h
+++ b/kernel/include/filesystem/format/fat32.h
@@ -222,7 +222,11 @@ namespace MaxOS {
void read(common::buffer_t* data, size_t amount) final;
void flush() final;
- uint32_t first_cluster() const { return m_first_cluster; } ///< Get the first cluster of the file
+ /**
+ * @brief Get the first cluster of the directory
+ * @return The first cluster of the directory
+ */
+ [[nodiscard]] uint32_t first_cluster() const { return m_first_cluster; }
};
/**
@@ -269,7 +273,11 @@ namespace MaxOS {
Directory* create_subdirectory(const string &name) final;
void remove_subdirectory(const string &name) final;
- [[nodiscard]] lba_t first_cluster() const { return m_first_cluster; } ///< Get the first cluster of the directory
+ /**
+ * @brief Get the first cluster of the directory
+ * @return The first cluster of the directory
+ */
+ [[nodiscard]] lba_t first_cluster() const { return m_first_cluster; }
};
/**
diff --git a/kernel/include/hardwarecommunication/interrupts.h b/kernel/include/hardwarecommunication/interrupts.h
index 95d0c56d..54b97478 100644
--- a/kernel/include/hardwarecommunication/interrupts.h
+++ b/kernel/include/hardwarecommunication/interrupts.h
@@ -174,7 +174,11 @@ namespace MaxOS {
void activate();
void deactivate();
- static void ForceInterruptReturn(system::cpu_status_t* state); ///< Force the CPU to return from an interrupt (see interrupts.s)
+ /**
+ * @brief Force the CPU to return from an interrupt (see interrupts.s)
+ * @param state the state to return to
+ */
+ static void ForceInterruptReturn(system::cpu_status_t* state);
};
}
diff --git a/kernel/include/hardwarecommunication/pci.h b/kernel/include/hardwarecommunication/pci.h
index 0b6aac10..bd25e368 100644
--- a/kernel/include/hardwarecommunication/pci.h
+++ b/kernel/include/hardwarecommunication/pci.h
@@ -17,100 +17,98 @@
#include
#include
-namespace MaxOS
-{
- namespace hardwarecommunication
- {
+namespace MaxOS {
+ namespace hardwarecommunication {
+
/**
- * @enum BaseAddressRegisterType
+ * @enum BARType
* @brief Determines whether the PCI device communicates via IO ports or memory.
*/
- enum class BaseAddressRegisterType{
- MemoryMapped,
- InputOutput
- };
-
- /**
- * @class BaseAddressRegister
- * @brief Used to store the base address register
- *
- * @todo Should be a struct
- */
- class BaseAddressRegister{
- public:
- bool pre_fetchable; ///< Reading from this address wont change the state of the device and data can be cached by the CPU
- uint8_t* address; ///< The address of the device (IO port or memory address, can be 32 or 64 bit)
- uint32_t size; ///< @todo Document Size of the address space
- BaseAddressRegisterType type; ///< Where to access the device
-
- };
-
-
- /**
- * @class PeripheralComponentInterconnectDeviceDescriptor
- * @brief Stores information about a PCI device
- *
- * @todo Should be a struct aswell
- */
- class PeripheralComponentInterconnectDeviceDescriptor {
- public:
- bool has_port_base = false; ///< Whether the device has an IO port base address
- uint32_t port_base = 0; ///< The IO port base address
-
- bool has_memory_base = false; ///< Whether the device has a memory base address
- uint32_t memory_base = 0; ///< The memory base address
-
- uint32_t interrupt = 0; ///< The interrupt number the device uses to communicate with the CPU
-
- uint16_t bus = 0; ///< The PCI bus the device is connected to
- uint16_t device = 0; ///< The device number on the PCI bus
- uint16_t function = 0; ///< The function number of the device
-
- uint16_t vendor_id = 0; ///< The company's that made the device unique identifier
- uint16_t device_id = 0; ///< The device's unique identifier
-
- uint8_t class_id = 0; ///< The class type of the device
- uint8_t subclass_id = 0; ///< The subclass type of the device
- uint8_t interface_id = 0; ///< The interface type of the device
-
- uint8_t revision = 0; ///< The device version number
-
- PeripheralComponentInterconnectDeviceDescriptor();
- ~PeripheralComponentInterconnectDeviceDescriptor();
-
- string get_type() const;
- };
-
-
- /**
- * @class PeripheralComponentInterconnectController
- * @brief Handles the selecting and loading of drivers for PCI devices
- */
- class PeripheralComponentInterconnectController : public drivers::DriverSelector
- {
- private:
- // Ports
- Port32Bit m_data_port;
- Port32Bit m_command_port;
-
- // I/O
- uint32_t read(uint16_t bus, uint16_t device, uint16_t function, uint32_t register_offset);
- void write(uint16_t bus, uint16_t device, uint16_t function, uint32_t register_offset, uint32_t value);
-
- // Device
- PeripheralComponentInterconnectDeviceDescriptor get_device_descriptor(uint16_t bus, uint16_t device, uint16_t function);
- BaseAddressRegister get_base_address_register(uint16_t bus, uint16_t device, uint16_t function, uint16_t bar);
- bool device_has_functions(uint16_t bus, uint16_t device);
-
- public:
- PeripheralComponentInterconnectController();
- ~PeripheralComponentInterconnectController();
-
- void select_drivers(drivers::DriverSelectorEventHandler* handler) override;
- static drivers::Driver* get_driver(PeripheralComponentInterconnectDeviceDescriptor dev);
- static void list_known_device(const PeripheralComponentInterconnectDeviceDescriptor& dev);
- };
- }
+ enum class BARType {
+ MemoryMapped,
+ InputOutput
+ };
+
+ /**
+ * @class BaseAddressRegister
+ * @brief Used to store the Base Address Register (BAR) of a PCI device
+ *
+ * @todo Should be a struct
+ */
+ class BaseAddressRegister {
+ public:
+ bool pre_fetchable; ///< Reading from this address wont change the state of the device and data can be cached by the CPU
+ uint8_t* address; ///< The address of the device (IO port or memory address, can be 32 or 64 bit)
+ uint32_t size; ///< @todo Document Size of the address space
+ BARType type; ///< Where to access the device
+
+ };
+
+
+ /**
+ * @class PCIDeviceDescriptor
+ * @brief Stores information about a PCI device
+ *
+ * @todo Should be a struct aswell
+ */
+ class PCIDeviceDescriptor {
+ public:
+ bool has_port_base = false; ///< Whether the device has an IO port base address
+ uint32_t port_base = 0; ///< The IO port base address
+
+ bool has_memory_base = false; ///< Whether the device has a memory base address
+ uint32_t memory_base = 0; ///< The memory base address
+
+ uint32_t interrupt = 0; ///< The interrupt number the device uses to communicate with the CPU
+
+ uint16_t bus = 0; ///< The PCI bus the device is connected to
+ uint16_t device = 0; ///< The device number on the PCI bus
+ uint16_t function = 0; ///< The function number of the device
+
+ uint16_t vendor_id = 0; ///< The company's that made the device unique identifier
+ uint16_t device_id = 0; ///< The device's unique identifier
+
+ uint8_t class_id = 0; ///< The class type of the device
+ uint8_t subclass_id = 0; ///< The subclass type of the device
+ uint8_t interface_id = 0; ///< The interface type of the device
+
+ uint8_t revision = 0; ///< The device version number
+
+ PCIDeviceDescriptor();
+ ~PCIDeviceDescriptor();
+
+ string get_type() const;
+ };
+
+
+ /**
+ * @class PCIController
+ * @brief Handles the selecting and loading of drivers for PCI devices
+ */
+ class PCIController : public drivers::DriverSelector {
+ private:
+ // Ports
+ Port32Bit m_data_port;
+ Port32Bit m_command_port;
+
+ // I/O
+ uint32_t read(uint16_t bus, uint16_t device, uint16_t function, uint32_t register_offset);
+ void write(uint16_t bus, uint16_t device, uint16_t function, uint32_t register_offset, uint32_t value);
+
+ // Device
+ PCIDeviceDescriptor get_device_descriptor(uint16_t bus, uint16_t device, uint16_t function);
+ BaseAddressRegister get_base_address_register(uint16_t bus, uint16_t device, uint16_t function, uint16_t bar);
+ bool device_has_functions(uint16_t bus, uint16_t device);
+
+ public:
+ PCIController();
+ ~PCIController();
+
+ void select_drivers(drivers::DriverSelectorEventHandler* handler) override;
+ static drivers::Driver* get_driver(PCIDeviceDescriptor dev);
+ static void list_known_device(const PCIDeviceDescriptor& dev);
+ };
+ }
}
#endif //MAX_OS_HARDWARECOMMUNICATION_PCI_H
diff --git a/kernel/include/processes/process.h b/kernel/include/processes/process.h
index 20d1864f..0e6522fa 100644
--- a/kernel/include/processes/process.h
+++ b/kernel/include/processes/process.h
@@ -73,7 +73,7 @@ namespace MaxOS
size_t ticks; ///< The number of ticks the thread has run for
size_t wakeup_time; ///< The time at which the thread should wake up (if sleeping)
- [[nodiscard]] uintptr_t tss_pointer() const { return m_tss_stack_pointer; } ///< Gets the stack pointer to use for the TSS when switching to this thread
+ [[nodiscard]] uintptr_t tss_pointer() const { return m_tss_stack_pointer; } ///< Gets the stack pointer to use for the TSS when switching to this thread @return tss
void save_sse_state();
void restore_sse_state();
diff --git a/kernel/include/processes/resource.h b/kernel/include/processes/resource.h
index 34fc0b5e..f1c3fe6d 100644
--- a/kernel/include/processes/resource.h
+++ b/kernel/include/processes/resource.h
@@ -84,7 +84,13 @@ namespace MaxOS {
explicit ResourceRegistry(resource_type_t type);
~ResourceRegistry() = default;
- /// Creates a resource of the specific type
+ /**
+ * @brief Create a new resource of the specific type
+ *
+ * @param name The name of the resource
+ * @param flags The flags to open the resource with
+ * @return The created resource, or nullptr on failure
+ */
Resource* create_resource(const string &name, size_t flags) override {
auto resource = new Type(name, flags, type());
diff --git a/kernel/include/system/cpu.h b/kernel/include/system/cpu.h
index 0333d5f1..6e6a7375 100644
--- a/kernel/include/system/cpu.h
+++ b/kernel/include/system/cpu.h
@@ -34,6 +34,7 @@ namespace MaxOS {
*
* @typedef cpu_status_t
* @brief Alias for CPUStatus struct
+ *
*/
typedef struct PACKED CPUStatus {
diff --git a/kernel/src/asm/interrupts.s b/kernel/src/asm/interrupts.s
index b20054fb..ab390b24 100644
--- a/kernel/src/asm/interrupts.s
+++ b/kernel/src/asm/interrupts.s
@@ -10,7 +10,7 @@
; */
[bits 64]
-[extern _ZN5MaxOS21hardwarecommunication16InterruptManager15HandleInterruptEPNS_6system12cpu_status_tE]
+[extern _ZN5MaxOS21hardwarecommunication16InterruptManager15HandleInterruptEPNS_6system9CPUStatusE]
%macro HandleException 1
[global _ZN5MaxOS21hardwarecommunication16InterruptManager19HandleException%1Ev]
@@ -21,7 +21,7 @@ _ZN5MaxOS21hardwarecommunication16InterruptManager19HandleException%1Ev:
save_context ; Now we can save the general purpose registers
mov rdi, rsp ; Let's set the current stack pointer as a parameter of the interrupts_handler
cld ; Clear the direction flag
- call _ZN5MaxOS21hardwarecommunication16InterruptManager15HandleInterruptEPNS_6system12cpu_status_tE ; Now we call the interrupt handler
+ call _ZN5MaxOS21hardwarecommunication16InterruptManager15HandleInterruptEPNS_6system9CPUStatusE ; Now we call the interrupt handler
mov rsp, rax ; use the returned context
restore_context ; We served the interrupt let's restore the previous context
add rsp, 16 ; We can discard the interrupt number and the error code
@@ -37,7 +37,7 @@ _ZN5MaxOS21hardwarecommunication16InterruptManager26HandleInterruptRequest%1Ev:
save_context ; Now we can save the general purpose registers
mov rdi, rsp ; Let's set the current stack pointer as a parameter of the interrupts_handler
cld ; Clear the direction flag
- call _ZN5MaxOS21hardwarecommunication16InterruptManager15HandleInterruptEPNS_6system12cpu_status_tE ; Now we call the interrupt handler
+ call _ZN5MaxOS21hardwarecommunication16InterruptManager15HandleInterruptEPNS_6system9CPUStatusE ; Now we call the interrupt handler
mov rsp, rax ; use the returned context
restore_context ; We served the interrupt let's restore the previous context
add rsp, 16 ; We can discard the interrupt number and the error code
@@ -51,7 +51,7 @@ _ZN5MaxOS21hardwarecommunication16InterruptManager24HandleInterruptError%1Ev:
save_context
mov rdi, rsp
cld
- call _ZN5MaxOS21hardwarecommunication16InterruptManager15HandleInterruptEPNS_6system12cpu_status_tE
+ call _ZN5MaxOS21hardwarecommunication16InterruptManager15HandleInterruptEPNS_6system9CPUStatusE
mov rsp, rax ; use the returned context
restore_context
add rsp, 16
@@ -59,8 +59,8 @@ _ZN5MaxOS21hardwarecommunication16InterruptManager24HandleInterruptError%1Ev:
%endmacro
-[global _ZN5MaxOS21hardwarecommunication16InterruptManager20ForceInterruptReturnEPNS_6system12cpu_status_tE]
-_ZN5MaxOS21hardwarecommunication16InterruptManager20ForceInterruptReturnEPNS_6system12cpu_status_tE:
+[global _ZN5MaxOS21hardwarecommunication16InterruptManager20ForceInterruptReturnEPNS_6system9CPUStatusE]
+_ZN5MaxOS21hardwarecommunication16InterruptManager20ForceInterruptReturnEPNS_6system9CPUStatusE:
mov rsp, rdi ; use the returned context
restore_context
diff --git a/kernel/src/common/buffer.cpp b/kernel/src/common/buffer.cpp
index d8d945d0..0f0cba4f 100644
--- a/kernel/src/common/buffer.cpp
+++ b/kernel/src/common/buffer.cpp
@@ -160,6 +160,7 @@ void Buffer::write(size_t offset, uint8_t byte) {
/**
* @brief Safely reads a byte from the buffer at the current offset
*
+ * @return The read byte
*/
uint8_t Buffer::read() {
set_offset(m_offset + 1);
@@ -170,6 +171,8 @@ uint8_t Buffer::read() {
* @brief Safely reads a byte from the buffer at the specified offset
*
* @param offset The offset into the buffer storage array
+ *
+ * @return The read byte
*/
uint8_t Buffer::read(size_t offset) {
diff --git a/kernel/src/common/graphicsContext.cpp b/kernel/src/common/graphicsContext.cpp
index edc349b1..dbd3571c 100644
--- a/kernel/src/common/graphicsContext.cpp
+++ b/kernel/src/common/graphicsContext.cpp
@@ -10,6 +10,10 @@
using namespace MaxOS::common;
+
+/**
+ * @brief Constructs a GraphicsContext object and initializes the color palette
+ */
GraphicsContext::GraphicsContext() {
diff --git a/kernel/src/common/logger.cpp b/kernel/src/common/logger.cpp
index 3c908549..8a6092a7 100644
--- a/kernel/src/common/logger.cpp
+++ b/kernel/src/common/logger.cpp
@@ -19,6 +19,9 @@ using namespace MaxOS::drivers::console;
using namespace MaxOS::processes;
using namespace MaxOS::system;
+/**
+ * @brief Constructs a Logger object and sets it as the active logger
+ */
Logger::Logger()
: m_log_writers()
{
@@ -31,10 +34,7 @@ Logger::Logger()
}
-Logger::~Logger() {
-
-
-}
+Logger::~Logger() = default;
/**
* @brief Adds an output stream to the logger
diff --git a/kernel/src/common/outputStream.cpp b/kernel/src/common/outputStream.cpp
index 6ef00a4f..5ea43630 100644
--- a/kernel/src/common/outputStream.cpp
+++ b/kernel/src/common/outputStream.cpp
@@ -11,6 +11,9 @@
using namespace MaxOS;
using namespace MaxOS::common;
+/**
+ * @brief Constructs an OutputStream object that uses strings as the underlying data type
+ */
OutputStream::OutputStream()
: GenericOutputStream::GenericOutputStream()
{
diff --git a/kernel/src/common/string.cpp b/kernel/src/common/string.cpp
index 322f6b7f..c15a6774 100644
--- a/kernel/src/common/string.cpp
+++ b/kernel/src/common/string.cpp
@@ -43,7 +43,7 @@ String::String(char c) {
* @brief Constructs a String from a pointer to an array of chars
* @param string An array of chars, must be null terminated and of length less than 10,000
*/
-String::String(char const *string) {
+String::String(char const* string) {
// Get the length of the string, prevent longer than 10000 because this should mean something's gone wrong
m_length = 0;
@@ -56,7 +56,7 @@ String::String(char const *string) {
m_string[i] = string[i];
// If the length is more than 10,000 Replace the end with a warning incase future use actually requires that
- const char *warning = "MAXOS: String length exceeded 10000 - might be a bug";
+ const char* warning = "MAXOS: String length exceeded 10000 - might be a bug";
if (m_length > 10000)
for (int i = 0; i < 52; i++)
m_string[m_length - 52 + i] = warning[i];
@@ -70,7 +70,7 @@ String::String(char const *string) {
* @param string The string bytes
* @param length How large the string byte buffer is
*/
-String::String(uint8_t const *string, int length) {
+String::String(uint8_t const* string, int length) {
// Allocate memory for the string (and null terminator)
m_length = length;
allocate_self();
@@ -91,7 +91,7 @@ String::String(uint8_t const *string, int length) {
String::String(int value) {
// Convert to a string
- const char *str = itoa(10, value);
+ const char* str = itoa(10, value);
m_length = strlen(str);
// Create space to store
@@ -112,7 +112,7 @@ String::String(int value) {
String::String(uint64_t value) {
// Convert to a string
- const char *str = htoa(value);
+ const char* str = htoa(value);
m_length = strlen(str);
// Create space to store
@@ -131,7 +131,7 @@ String::String(uint64_t value) {
String::String(float value) {
// Convert to a string
- const char *str = ftoa(value);
+ const char* str = ftoa(value);
m_length = strlen(str);
// Create space to store
@@ -150,7 +150,7 @@ String::String(float value) {
*/
String::String(bool value) {
- if(value)
+ if (value)
*this = string("true");
else
*this = string("false");
@@ -162,11 +162,13 @@ String::String(bool value) {
*
* @param other String to copy from
*/
-String::String(String const &other) {
+String::String(String const& other) {
copy(other);
}
-
+/**
+ * @brief Destructor for the string, cleans up memory if needed
+ */
String::~String() {
// Free the memory
@@ -180,7 +182,7 @@ String::~String() {
*
* @param other The other string
*/
-void String::copy(String const &other) {
+void String::copy(String const& other) {
// Allocate memory for the string (and null terminator)
m_length = other.length();
@@ -201,7 +203,7 @@ void String::copy(String const &other) {
* @param string The string
* @return The sum of the ascii values of the characters in the string
*/
-int String::lex_value(String const &string) {
+int String::lex_value(String const& string) {
// Sum the ascii values of the characters in the string
int sum = 0;
@@ -232,7 +234,7 @@ void String::allocate_self() {
* @param other The string for this one to be updated to
* @return String The string
*/
-String &String::operator=(String const &other) {
+String& String::operator =(String const& other) {
// Self assignment check
if (this == &other)
@@ -248,7 +250,7 @@ String &String::operator=(String const &other) {
*
* @return The char* string
*/
-char *String::c_str() {
+char* String::c_str() {
return m_string;
}
@@ -258,7 +260,7 @@ char *String::c_str() {
*
* @return The string as an array of characters
*/
-const char *String::c_str() const {
+const char* String::c_str() const {
return m_string;
}
@@ -269,7 +271,7 @@ const char *String::c_str() const {
* @param other The other string
* @return True if the string starts with the other string, false otherwise
*/
-bool String::starts_with(String const &other) {
+bool String::starts_with(String const& other) {
// Must at least be able to fit the other string
if (m_length < other.length())
@@ -295,11 +297,11 @@ String String::substring(int start, int length) const {
// Ensure the start is within bounds
if (start < 0 || start >= m_length)
- return {};
+ return { };
// Ensure the length is within bounds
if (length < 0 || start + length > m_length)
- return {};
+ return { };
// Allocate memory for the substring (and null terminator)
String substring;
@@ -322,7 +324,7 @@ String String::substring(int start, int length) const {
* @param delimiter What to split the string by
* @return A vector of strings that were split by the delimiter
*/
-common::Vector String::split(String const &delimiter) const {
+common::Vector String::split(String const& delimiter) const {
common::Vector