summaryrefslogtreecommitdiffhomepage
path: root/dev/kernel
diff options
context:
space:
mode:
authorAmlal <amlal@nekernel.org>2025-05-07 11:14:25 +0200
committerAmlal <amlal@nekernel.org>2025-05-07 11:14:25 +0200
commit8acaf9b721973fdd852abc01fc44ba1152b8f72a (patch)
treed3626413ddc890445d431451439a9abe225f4e5f /dev/kernel
parenta3ee1df87feddec339c710068e0922a40c6fd494 (diff)
feat(kernel): HeFS fixes, AHCI improvements, and MBCI tweaks.
why? - Some parts were causing issues on the filesystem. - The slot probe code was naive. - Made the current MBCI implementation clearer. Signed-off-by: Amlal <amlal@nekernel.org>
Diffstat (limited to 'dev/kernel')
-rw-r--r--dev/kernel/HALKit/AMD64/HalDebugOutput.cc64
-rw-r--r--dev/kernel/HALKit/AMD64/Storage/AHCI+Generic.cc18
-rw-r--r--dev/kernel/src/FS/HeFS+FileSystemParser.cc15
3 files changed, 75 insertions, 22 deletions
diff --git a/dev/kernel/HALKit/AMD64/HalDebugOutput.cc b/dev/kernel/HALKit/AMD64/HalDebugOutput.cc
index 34b99ffe..a9759fc0 100644
--- a/dev/kernel/HALKit/AMD64/HalDebugOutput.cc
+++ b/dev/kernel/HALKit/AMD64/HalDebugOutput.cc
@@ -57,6 +57,54 @@ namespace Detail {
TerminalDevice::~TerminalDevice() = default;
+EXTERN_C void ke_utf_io_write(IDeviceObject<const Utf8Char*>* obj, const Utf8Char* bytes) {
+ NE_UNUSED(bytes);
+ NE_UNUSED(obj);
+
+#ifdef __DEBUG__
+ Detail::hal_serial_init<Detail::kPort>();
+
+ if (!bytes || Detail::kState != kStateReady) return;
+
+ if (*bytes == 0) return;
+
+ Detail::kState = kStateTransmit;
+
+ SizeT index = 0;
+ SizeT len = 0;
+
+ index = 0;
+ len = urt_string_len(bytes);
+
+ static BOOL not_important = YES;
+
+ while (index < len) {
+ if (bytes[index] == '\r') HAL::rt_out8(Detail::kPort, '\r');
+
+ HAL::rt_out8(Detail::kPort, bytes[index] == '\r' ? '\n' : bytes[index]);
+
+ char tmp_str[2];
+ tmp_str[0] = bytes[index];
+ tmp_str[1] = 0;
+
+ if (bytes[index] == '*') {
+ if (not_important)
+ not_important = NO;
+ else
+ not_important = YES;
+
+ ++index;
+
+ continue;
+ }
+
+ ++index;
+ }
+
+ Detail::kState = kStateReady;
+#endif // __DEBUG__
+}
+
EXTERN_C void ke_io_write(IDeviceObject<const Char*>* obj, const Char* bytes) {
NE_UNUSED(bytes);
NE_UNUSED(obj);
@@ -74,7 +122,7 @@ EXTERN_C void ke_io_write(IDeviceObject<const Char*>* obj, const Char* bytes) {
SizeT len = 0;
index = 0;
- len = rt_string_len(bytes, 256U);
+ len = rt_string_len(bytes);
static SizeT x = kFontSizeX, y = kFontSizeY;
@@ -172,20 +220,8 @@ TerminalDevice TerminalDevice::The() noexcept {
Utf8TerminalDevice::~Utf8TerminalDevice() = default;
-STATIC Void ke_io_write_utf(IDeviceObject<const Utf8Char*>*, const Utf8Char* str) {
- auto len = urt_string_len(str);
-
- for (auto size = 0ul; size < len; ++size) {
- Char buf[2];
- buf[0] = str[size];
- buf[1] = 0;
-
- Kernel::ke_io_write(nullptr, buf);
- }
-}
-
Utf8TerminalDevice Utf8TerminalDevice::The() noexcept {
- Utf8TerminalDevice out(Kernel::ke_io_write_utf,
+ Utf8TerminalDevice out(Kernel::ke_utf_io_write,
[](IDeviceObject<const Utf8Char*>*, const Utf8Char*) -> Void {});
return out;
}
diff --git a/dev/kernel/HALKit/AMD64/Storage/AHCI+Generic.cc b/dev/kernel/HALKit/AMD64/Storage/AHCI+Generic.cc
index cf1841bd..4b0270ab 100644
--- a/dev/kernel/HALKit/AMD64/Storage/AHCI+Generic.cc
+++ b/dev/kernel/HALKit/AMD64/Storage/AHCI+Generic.cc
@@ -154,10 +154,18 @@ STATIC Void drv_std_input_output_ahci(UInt64 lba, UInt8* buffer, SizeT sector_sz
UIntPtr slot = drv_find_cmd_slot_ahci(&kSATAHba->Ports[kSATAIndex]);
- if (slot == ~0UL) {
- kout << "No free command slot!\r";
- err_global_get() = kErrorDisk;
- return;
+ UInt16 timeout = 0;
+
+ while (slot == ~0UL) {
+ kout << "No free command slot found, AHCI disk is busy!\r";
+
+ if (timeout > 0x1000) {
+ err_global_get() = kErrorDisk;
+ return;
+ }
+
+ slot = drv_find_cmd_slot_ahci(&kSATAHba->Ports[kSATAIndex]);
+ ++timeout;
}
volatile HbaCmdHeader* command_header =
@@ -173,7 +181,7 @@ STATIC Void drv_std_input_output_ahci(UInt64 lba, UInt8* buffer, SizeT sector_sz
rt_set_memory((VoidPtr) command_table, 0, sizeof(HbaCmdTbl));
- VoidPtr ptr = rtl_dma_alloc(size_buffer, 4096);
+ VoidPtr ptr = rtl_dma_alloc(size_buffer, kib_cast(4));
rtl_dma_flush(ptr, size_buffer);
diff --git a/dev/kernel/src/FS/HeFS+FileSystemParser.cc b/dev/kernel/src/FS/HeFS+FileSystemParser.cc
index 465cfc32..1cd7e61a 100644
--- a/dev/kernel/src/FS/HeFS+FileSystemParser.cc
+++ b/dev/kernel/src/FS/HeFS+FileSystemParser.cc
@@ -514,10 +514,14 @@ namespace Detail {
if (start > root->fEndIND) break;
}
- node_arr[start_cnt + 1].fDeleted = 1UL;
err_global_get() = kErrorSuccess;
delete dir;
+ if (start_cnt == 0) {
+ delete[] node_arr;
+ node_arr = nullptr;
+ }
+
return node_arr;
}
@@ -577,7 +581,7 @@ namespace Detail {
node->fOffsetSlices = root->fStartBlock;
- auto offset = 0;
+ auto offset = kHeFSBlockLen;
SizeT cnt = 0ULL;
@@ -1031,6 +1035,10 @@ _Output Bool HeFileSystemParser::INodeManip(_Input DriveTrait* mnt, VoidPtr bloc
mnt->fPacket.fPacketSize = kHeFSBlockLen;
mnt->fPacket.fPacketContent = block;
+ if (mnt->fPacket.fPacketLba > root->fEndBlock) {
+ goto inode_manip_fail;
+ }
+
in ? mnt->fInput(mnt->fPacket) : mnt->fOutput(mnt->fPacket);
sz_out += kHeFSBlockLen;
@@ -1049,6 +1057,7 @@ _Output Bool HeFileSystemParser::INodeManip(_Input DriveTrait* mnt, VoidPtr bloc
}
}
+inode_manip_fail:
delete[] nodes;
return NO;
}
@@ -1174,7 +1183,7 @@ Boolean fs_init_hefs(Void) {
Utf8Char contents_1[kHeFSBlockLen] = u8"ロケットにはジエットエンジン\r";
MUST_PASS(parser.INodeManip(&kMountPoint, contents_1, kHeFSBlockLen, u8"/boot",
- kHeFSFileKindRegular, u8"ジェット警察.txt", NO));
+ kHeFSFileKindRegular, u8"ジェット警察.txt", YES));
return YES;
}