summaryrefslogtreecommitdiffhomepage
path: root/dev/kernel
diff options
context:
space:
mode:
Diffstat (limited to 'dev/kernel')
-rw-r--r--dev/kernel/FSKit/HeFS.h2
-rw-r--r--dev/kernel/FirmwareKit/EFI/API.h4
-rw-r--r--dev/kernel/HALKit/AMD64/HalDescriptorLoader.cc38
-rw-r--r--dev/kernel/HALKit/AMD64/HalKernelMain.cc4
-rw-r--r--dev/kernel/HALKit/AMD64/Storage/AHCI+Generic.cc45
-rw-r--r--dev/kernel/HALKit/AMD64/Storage/DMA+Generic.cc13
-rw-r--r--dev/kernel/StorageKit/DMA.h6
-rw-r--r--dev/kernel/src/FS/HeFS.cc14
-rw-r--r--dev/kernel/src/Utils.cc7
9 files changed, 78 insertions, 55 deletions
diff --git a/dev/kernel/FSKit/HeFS.h b/dev/kernel/FSKit/HeFS.h
index fd462b17..bdc8a338 100644
--- a/dev/kernel/FSKit/HeFS.h
+++ b/dev/kernel/FSKit/HeFS.h
@@ -164,7 +164,7 @@ struct PACKED ALIGN(8) HEFS_INDEX_NODE final {
enum {
kHeFSInvalidColor = 0,
- kHeFSRed = 100,
+ kHeFSRed = 100,
kHeFSBlack,
kHeFSColorCount,
};
diff --git a/dev/kernel/FirmwareKit/EFI/API.h b/dev/kernel/FirmwareKit/EFI/API.h
index 0b937477..47b9e4d1 100644
--- a/dev/kernel/FirmwareKit/EFI/API.h
+++ b/dev/kernel/FirmwareKit/EFI/API.h
@@ -29,7 +29,7 @@ inline EfiSystemTable* ST = nullptr;
inline EfiBootServices* BS = nullptr;
EXTERN_C void rt_cli();
-EXTERN_C void rt_hlt();
+EXTERN_C void rt_halt();
namespace Boot {
/// @brief Halt and clear interrupts.
@@ -37,7 +37,7 @@ namespace Boot {
inline Void Stop() noexcept {
while (YES) {
rt_cli();
- rt_hlt();
+ rt_halt();
}
}
diff --git a/dev/kernel/HALKit/AMD64/HalDescriptorLoader.cc b/dev/kernel/HALKit/AMD64/HalDescriptorLoader.cc
index e6d57be2..2fb6ad4c 100644
--- a/dev/kernel/HALKit/AMD64/HalDescriptorLoader.cc
+++ b/dev/kernel/HALKit/AMD64/HalDescriptorLoader.cc
@@ -15,26 +15,20 @@ namespace Detail {
STATIC ::Kernel::Detail::AMD64::InterruptDescriptorAMD64 kInterruptVectorTable[kKernelIdtSize] =
{};
-#if 0
- STATIC void hal_set_irq_mask(UInt8 irql) [[maybe_unused]]
- {
- UInt16 port;
- UInt8 value;
-
- if (irql < 8)
- {
- port = kPICData;
- }
- else
- {
- port = kPIC2Data;
- irql -= 8;
- }
-
- value = rt_in8(port) | (1 << irql);
- rt_out8(port, value);
- }
-#endif // make gcc shut up
+ STATIC ATTRIBUTE(unused) void hal_set_irq_mask(UInt8 irql) [[maybe_unused]] {
+ UInt16 port;
+ UInt8 value;
+
+ if (irql < 8) {
+ port = kPICData;
+ } else {
+ port = kPIC2Data;
+ irql -= 8;
+ }
+
+ value = rt_in8(port) | (1 << irql);
+ rt_out8(port, value);
+ }
STATIC void hal_clear_irq_mask(UInt8 irql) [[maybe_unused]] {
UInt16 port;
@@ -70,7 +64,9 @@ namespace Detail {
/// @param gdt
/// @return
Void GDTLoader::Load(Register64& gdt) {
+#ifndef __NE_MODULAR_KERNEL_COMPONENTS__
hal_load_gdt(gdt);
+#endif // __NE_MODULAR_KERNEL_COMPONENTS__
}
Void IDTLoader::Load(Register64& idt) {
@@ -98,7 +94,9 @@ Void IDTLoader::Load(Register64& idt) {
Detail::hal_enable_pit(kPITTickForScheduler);
+#ifndef __NE_MODULAR_KERNEL_COMPONENTS__
hal_load_idt(idt);
+#endif // __NE_MODULAR_KERNEL_COMPONENTS__
rt_sti();
}
diff --git a/dev/kernel/HALKit/AMD64/HalKernelMain.cc b/dev/kernel/HALKit/AMD64/HalKernelMain.cc
index 8f4b55cb..5a826a9d 100644
--- a/dev/kernel/HALKit/AMD64/HalKernelMain.cc
+++ b/dev/kernel/HALKit/AMD64/HalKernelMain.cc
@@ -17,6 +17,7 @@
#include <modules/ACPI/ACPIFactoryInterface.h>
#include <modules/CoreGfx/TextGfx.h>
+#ifndef __NE_MODULAR_KERNEL_COMPONENTS__
EXTERN_C Kernel::VoidPtr kInterruptVectorTable[];
STATIC Kernel::Void hal_pre_init_scheduler() noexcept {
@@ -105,7 +106,9 @@ EXTERN_C Int32 hal_init_platform(Kernel::HEL::BootInfoHeader* handover_hdr) {
EXTERN_C Kernel::Void hal_real_init(Kernel::Void) noexcept {
hal_pre_init_scheduler();
+#if defined(__FSKIT_INCLUDES_HEFS__)
Kernel::HeFS::fs_init_hefs();
+#endif
Kernel::HAL::mp_init_cores(kHandoverHeader->f_HardwareTables.f_VendorPtr);
@@ -141,3 +144,4 @@ EXTERN_C Kernel::Void hal_real_init(Kernel::Void) noexcept {
++team_index;
}
}
+#endif // ifndef __NE_MODULAR_KERNEL_COMPONENTS__ \ No newline at end of file
diff --git a/dev/kernel/HALKit/AMD64/Storage/AHCI+Generic.cc b/dev/kernel/HALKit/AMD64/Storage/AHCI+Generic.cc
index fd138513..1591fa56 100644
--- a/dev/kernel/HALKit/AMD64/Storage/AHCI+Generic.cc
+++ b/dev/kernel/HALKit/AMD64/Storage/AHCI+Generic.cc
@@ -55,11 +55,11 @@ using namespace Kernel;
STATIC PCI::Device kSATADev;
STATIC HbaMemRef kSATAHba;
-STATIC Lba kSATASectorCount = 0UL;
-STATIC UInt16 kSATAIndex = 0U;
-STATIC Char kCurrentDiskModel[50] = {"GENERIC SATA"};
-STATIC UInt16 kSATAPortsImplemented = 0U;
-STATIC ALIGN(4096) UInt8 kIdentifyData[kAHCISectorSize] = {0};
+STATIC Lba kSATASectorCount = 0UL;
+STATIC UInt16 kSATAIndex = 0U;
+STATIC Char kCurrentDiskModel[50] = {"GENERIC SATA"};
+STATIC UInt16 kSATAPortsImplemented = 0U;
+STATIC ALIGN(kib_cast(4)) UInt8 kIdentifyData[kAHCISectorSize] = {0};
template <BOOL Write, BOOL CommandOrCTRL, BOOL Identify>
STATIC Void drv_std_input_output_ahci(UInt64 lba, UInt8* buffer, SizeT sector_sz,
@@ -153,6 +153,10 @@ STATIC Void drv_std_input_output_ahci(UInt64 lba, UInt8* buffer, SizeT sector_sz
VoidPtr ptr = Kernel::rtl_dma_alloc(size_buffer, 4096);
+ if (Write) {
+ Kernel::rt_copy_memory(buffer, ptr, size_buffer);
+ }
+
// Build the PRDT
SizeT bytes_remaining = size_buffer;
SizeT prdt_index = 0;
@@ -160,8 +164,8 @@ STATIC Void drv_std_input_output_ahci(UInt64 lba, UInt8* buffer, SizeT sector_sz
while (bytes_remaining > 0 && prdt_index < 8) {
SizeT chunk_size = bytes_remaining;
- if (chunk_size > 8 * 1024) // AHCI recommends ~8 KiB per PRDT
- chunk_size = 8 * 1024;
+
+ if (chunk_size > kib_cast(32)) chunk_size = kib_cast(32);
command_table->Prdt[prdt_index].Dba = (UInt32) (buffer_phys & 0xFFFFFFFF);
command_table->Prdt[prdt_index].Dbau = (UInt32) (buffer_phys >> 32);
@@ -170,12 +174,16 @@ STATIC Void drv_std_input_output_ahci(UInt64 lba, UInt8* buffer, SizeT sector_sz
buffer_phys += chunk_size;
bytes_remaining -= chunk_size;
+
++prdt_index;
}
+ command_table->Prdt[prdt_index - 1].Ie = YES;
+
if (bytes_remaining > 0) {
kout << "Warning: AHCI PRDT overflow, cannot map full buffer.\r";
err_global_get() = kErrorDisk;
+
return;
}
@@ -197,9 +205,10 @@ STATIC Void drv_std_input_output_ahci(UInt64 lba, UInt8* buffer, SizeT sector_sz
h2d_fis->Lba4 = (lba >> 32) & 0xFF;
h2d_fis->Lba5 = (lba >> 40) & 0xFF;
+ h2d_fis->Device = 0;
+
if (Identify) {
- h2d_fis->Device = 0; // DO NOT set LBAMODE flag
- h2d_fis->CountLow = 1; // IDENTIFY always transfers 1 sector
+ h2d_fis->CountLow = 1;
h2d_fis->CountHigh = 0;
} else {
h2d_fis->Device = kSATALBAMode;
@@ -220,12 +229,15 @@ STATIC Void drv_std_input_output_ahci(UInt64 lba, UInt8* buffer, SizeT sector_sz
if (kSATAHba->Is & kHBAErrTaskFile) {
kout << "AHCI Task File Error during I/O.\r";
-
+
rtl_dma_free(size_buffer);
err_global_get() = kErrorDiskIsCorrupted;
return;
} else {
+ rtl_dma_flush(ptr, size_buffer);
rt_copy_memory(ptr, buffer, size_buffer);
+ rtl_dma_flush(ptr, size_buffer);
+
rtl_dma_free(size_buffer);
err_global_get() = kErrorSuccess;
@@ -289,11 +301,11 @@ STATIC Bool drv_init_command_structures_ahci() {
UIntPtr clb_phys = HAL::hal_get_phys_address(clb_mem);
- kSATAHba->Ports[kSATAIndex].Clb = (UInt32)(clb_phys & 0xFFFFFFFF);
- kSATAHba->Ports[kSATAIndex].Clbu = (UInt32)(clb_phys >> 32);
+ kSATAHba->Ports[kSATAIndex].Clb = (UInt32) (clb_phys & 0xFFFFFFFF);
+ kSATAHba->Ports[kSATAIndex].Clbu = (UInt32) (clb_phys >> 32);
// Clear it
- rt_set_memory(clb_mem, 0, 4096);
+ rt_set_memory(clb_mem, 0, kib_cast(4));
// For each command slot (up to 32)
volatile HbaCmdHeader* header = (volatile HbaCmdHeader*) clb_mem;
@@ -302,15 +314,15 @@ STATIC Bool drv_init_command_structures_ahci() {
// Allocate 4KiB for Command Table
VoidPtr ct_mem = Kernel::rtl_dma_alloc(4096, 128);
if (!ct_mem) {
- kout << "Failed to allocate CTB memory for slot " << hex_number(i);
+ (Void)(kout << "Failed to allocate CTB memory for slot " << hex_number(i));
kout << "!\r";
return NO;
}
UIntPtr ct_phys = HAL::hal_get_phys_address(ct_mem);
- header[i].Ctba = (UInt32)(ct_phys & 0xFFFFFFFF);
- header[i].Ctbau = (UInt32)(ct_phys >> 32);
+ header[i].Ctba = (UInt32) (ct_phys & 0xFFFFFFFF);
+ header[i].Ctbau = (UInt32) (ct_phys >> 32);
// Clear the command table
rt_set_memory((VoidPtr) ct_mem, 0, 4096);
@@ -319,7 +331,6 @@ STATIC Bool drv_init_command_structures_ahci() {
return YES;
}
-
/// @brief Initializes an AHCI disk.
/// @param pi the amount of ports that have been detected.
/// @param atapi reference value, tells whether we should detect ATAPI instead of SATA.
diff --git a/dev/kernel/HALKit/AMD64/Storage/DMA+Generic.cc b/dev/kernel/HALKit/AMD64/Storage/DMA+Generic.cc
index a7361778..ca3e9ee4 100644
--- a/dev/kernel/HALKit/AMD64/Storage/DMA+Generic.cc
+++ b/dev/kernel/HALKit/AMD64/Storage/DMA+Generic.cc
@@ -28,11 +28,11 @@ using namespace Kernel::HAL;
/// BUGS: 0
-STATIC Boolean kATADetected = false;
-STATIC Int32 kATADeviceType = kATADeviceCount;
-STATIC UInt16 kATAIdentifyData[kATADataLen] = {0};
+STATIC Boolean kATADetected = false;
+STATIC Int32 kATADeviceType ATTRIBUTE(unused) = kATADeviceCount;
+STATIC UInt16 kATAIdentifyData[kATADataLen] = {0};
STATIC Kernel::PCI::Device kATADevice;
-STATIC Char kATADiskModel[50] = {"GENERIC DMA"};
+STATIC Char kATADiskModel[50] ATTRIBUTE(unused) = {"GENERIC DMA"};
Boolean drv_std_wait_io(UInt16 IO) {
for (int i = 0; i < 400; i++) rt_in8(IO + ATA_REG_STATUS);
@@ -60,6 +60,11 @@ Void drv_std_select(UInt16 Bus) {
}
Boolean drv_std_init(UInt16 Bus, UInt8 Drive, UInt16& OutBus, UInt8& OutMaster) {
+ NE_UNUSED(Bus);
+ NE_UNUSED(Drive);
+ NE_UNUSED(OutBus);
+ NE_UNUSED(OutMaster);
+
PCI::Iterator iterator(Types::PciDeviceKind::MassStorageController);
for (SizeT device_index = 0; device_index < NE_BUS_COUNT; ++device_index) {
diff --git a/dev/kernel/StorageKit/DMA.h b/dev/kernel/StorageKit/DMA.h
index 17dda29a..c572ffa3 100644
--- a/dev/kernel/StorageKit/DMA.h
+++ b/dev/kernel/StorageKit/DMA.h
@@ -52,15 +52,13 @@ inline VoidPtr rtl_dma_alloc(SizeT size, SizeT align) {
}
inline Void rtl_dma_free(SizeT size) {
- if (!size)
- return;
+ if (!size) return;
kDmaPoolPtr = (UInt8*) (kDmaPoolPtr - size);
}
inline Void rtl_dma_flush(Void* ptr, SizeT size_buffer) {
- if (ptr > (Void*)(DMA_POOL_START + DMA_POOL_SIZE))
- {
+ if (ptr > (Void*) (DMA_POOL_START + DMA_POOL_SIZE)) {
return;
}
diff --git a/dev/kernel/src/FS/HeFS.cc b/dev/kernel/src/FS/HeFS.cc
index eb6e6fc1..a27712e3 100644
--- a/dev/kernel/src/FS/HeFS.cc
+++ b/dev/kernel/src/FS/HeFS.cc
@@ -737,7 +737,7 @@ namespace Detail {
auto old_start = start;
hefsi_traverse_tree(dir, root, start);
-
+
if (start == 0 || start == old_start) break;
}
@@ -824,7 +824,7 @@ _Output Bool HeFileSystemParser::Format(_Input _Output DriveTrait* drive, _Input
root->fSectorSize = drive->fSectorSz;
- root->fStartIND = drive->fLbaStart + sizeof(HEFS_BOOT_NODE) + sizeof(HEFS_BOOT_NODE);
+ root->fStartIND = drive->fLbaStart + sizeof(HEFS_BOOT_NODE);
root->fEndIND = drive->fLbaEnd;
root->fINDCount = 0;
@@ -870,7 +870,7 @@ _Output Bool HeFileSystemParser::Format(_Input _Output DriveTrait* drive, _Input
/// @note this allocates 4 ind at format.
SizeT cnt = 4UL;
- Lba next = drive->fLbaStart + sizeof(HEFS_BOOT_NODE) + sizeof(HEFS_BOOT_NODE);
+ Lba next = root->fStartIND + sizeof(HEFS_BOOT_NODE);
HEFS_INDEX_NODE_DIRECTORY* index_node = new HEFS_INDEX_NODE_DIRECTORY();
@@ -889,11 +889,11 @@ _Output Bool HeFileSystemParser::Format(_Input _Output DriveTrait* drive, _Input
index_node->fChecksum = 0;
index_node->fIndexNodeChecksum = 0;
- index_node->fUID = 0;
- index_node->fGID = 0;
- index_node->fMode = 0;
+ index_node->fUID = 0;
+ index_node->fGID = 0;
+ index_node->fMode = 0;
- index_node->fColor = kHeFSBlack;
+ index_node->fColor = kHeFSBlack;
index_node->fChild = 0;
index_node->fParent = 0;
index_node->fNext = 0;
diff --git a/dev/kernel/src/Utils.cc b/dev/kernel/src/Utils.cc
index eed6f076..ea0ff7a7 100644
--- a/dev/kernel/src/Utils.cc
+++ b/dev/kernel/src/Utils.cc
@@ -179,6 +179,8 @@ Char* rt_string_has_char(Char* str, Char chr) {
}
} // namespace Kernel
+////// @note These symbols were written to satisfy gcc, clang and other compiler complaints.
+
EXTERN_C void* memset(void* dst, int c, long long unsigned int len) {
return Kernel::rt_set_memory(dst, c, len);
}
@@ -187,3 +189,8 @@ EXTERN_C void* memcpy(void* dst, const void* src, long long unsigned int len) {
Kernel::rt_copy_memory(const_cast<void*>(src), dst, len);
return dst;
}
+
+EXTERN_C Kernel::Int32 strcmp(const char* dst, const char* src) {
+ return Kernel::rt_string_cmp(dst, src, Kernel::rt_string_len(dst));
+}
+