Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion dev/boot/BootKit/BootKit.h
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,7 @@ inline Boolean BDiskFormatFactory<BootDev>::Format(const Char* part_name) {
EPM_PART_BLOCK* epm_boot = (EPM_PART_BLOCK*) RTL_ALLOCA(sizeof(EPM_PART_BLOCK));

const auto kFsName = "NeKernel";
const auto kBlockName = "OS (EPM)";
const auto kBlockName = " NeKernelOS";

epm_boot->FsVersion = 0;
epm_boot->LbaStart = sizeof(EPM_PART_BLOCK);
Expand Down
2 changes: 1 addition & 1 deletion dev/boot/amd64-desktop.make
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ run-efi-amd64-ata: run-efi-amd64-ata-pio
# img_2 is the rescue disk. img is the bootable disk, as provided by the NeKernel specs.
.PHONY: epm-img
epm-img:
qemu-img create -f raw $(IMG) 8G
qemu-img create -f raw $(IMG) 2G

.PHONY: efi
efi:
Expand Down
4 changes: 2 additions & 2 deletions dev/kernel/FirmwareKit/EPM.h
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,8 @@ typedef struct EPM_GUID {
* @note NumBlock and LbaStart are ignored on some platforms.
*/
struct PACKED EPM_PART_BLOCK {
Kernel::Char Magic[kEPMMagicLength] = {0};
Kernel::Char Name[kEPMNameLength] = {0};
Kernel::Char Magic[kEPMMagicLength];
Kernel::Char Name[kEPMNameLength];
EPM_GUID Guid;
Kernel::Int32 Version;
Kernel::Int64 NumBlocks;
Expand Down
9 changes: 9 additions & 0 deletions dev/kernel/HALKit/AMD64/HalApplicationProcessorStartup.s
Original file line number Diff line number Diff line change
@@ -1,3 +1,12 @@
/*
* ========================================================
*
* NeKernel
* Copyright (C) 2024-2025, Amlal El Mahrouss, licensed under the Apache 2.0 license.
*
* ========================================================
*/

.text

.global hal_ap_blob_start
Expand Down
16 changes: 7 additions & 9 deletions dev/kernel/HALKit/AMD64/HalKernelMain.cc
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,13 @@ EXTERN_C Int32 hal_init_platform(Kernel::HEL::BootInfoHeader* handover_hdr) {
}

EXTERN_C Kernel::Void hal_real_init(Kernel::Void) {
using namespace Kernel;
#ifdef __FSKIT_INCLUDES_OPENHEFS__
OpenHeFS::fs_init_openhefs();
#endif

#ifdef __FSKIT_INCLUDES_NEFS__
NeFS::fs_init_nefs();
#endif

HAL::Register64 idt_reg;
idt_reg.Base = reinterpret_cast<UIntPtr>(kInterruptVectorTable);
Expand All @@ -144,14 +150,6 @@ EXTERN_C Kernel::Void hal_real_init(Kernel::Void) {

HAL::mp_init_cores(kHandoverHeader->f_HardwareTables.f_VendorPtr);

#ifdef __FSKIT_INCLUDES_OPENHEFS__
OpenHeFS::fs_init_openhefs();
#endif

#ifdef __FSKIT_INCLUDES_NEFS__
NeFS::fs_init_nefs();
#endif

while (YES)
;
}
Expand Down
10 changes: 5 additions & 5 deletions dev/kernel/HALKit/AMD64/PCI/Iterator.cc
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@
#include <KernelKit/PCI/Iterator.h>

namespace Kernel::PCI {
Iterator::Iterator(const Types::PciDeviceKind& type) {
Iterator::Iterator(const Types::PciDeviceKind type, UInt32 bar) {
// probe devices.
for (int bus = 0; bus < NE_BUS_COUNT; ++bus) {
for (int device = 0; device < NE_DEVICE_COUNT; ++device) {
for (int function = 0; function < NE_FUNCTION_COUNT; ++function) {
Device dev(bus, device, function, 0x00);
for (Int32 bus = 0; bus < NE_BUS_COUNT; ++bus) {
for (Int32 device = 0; device < NE_DEVICE_COUNT; ++device) {
for (Int32 function = 0; function < NE_FUNCTION_COUNT; ++function) {
Device dev(bus, device, function, bar);

if (dev.Class() == type) {
fDevices[bus] = dev;
Expand Down
4 changes: 2 additions & 2 deletions dev/kernel/HALKit/AMD64/Storage/AHCI+Generic.cc
Original file line number Diff line number Diff line change
Expand Up @@ -397,7 +397,8 @@ STATIC Bool drv_init_command_structures_ahci() {
/// @param atapi reference value, tells whether we should detect ATAPI instead of SATA.
/// @return if the disk was successfully initialized or not.
STATIC Bool drv_std_init_ahci(UInt16& pi, BOOL& atapi) {
PCI::Iterator iterator(Types::PciDeviceKind::MassStorageController);
/// AMLALE: TODO: Iterator is good enough, but we need to expand it.
PCI::Iterator iterator(Types::PciDeviceKind::MassStorageController, 0x00);

for (SizeT device_index = 0; device_index < NE_BUS_COUNT; ++device_index) {
kSATADev = iterator[device_index].Leak(); // Leak device.
Expand Down Expand Up @@ -438,7 +439,6 @@ STATIC Bool drv_std_init_ahci(UInt16& pi, BOOL& atapi) {

if (!drv_init_command_structures_ahci()) {
err_global_get() = kErrorDisk;
return NO;
}

goto success_hba_fetch;
Expand Down
17 changes: 11 additions & 6 deletions dev/kernel/KernelKit/DriveMgr.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ enum {

/// @brief Media drive trait type.
struct DriveTrait final {
Char fName[kDriveNameLen] = {0}; // /System, /boot, //./Devices/USB...
Char fName[kDriveNameLen] = "/media/null"; // /System, /boot, //./Devices/USB...
UInt32 fKind{}; // fMassStorage, fFloppy, fOpticalDrive.
UInt32 fFlags{}; // fReadOnly, fEPMDrive...

Expand All @@ -70,11 +70,11 @@ struct DriveTrait final {
Lba fLbaStart{0}, fLbaEnd{0};
SizeT fSectorSz{kDriveSectorSz};

Void (*fInput)(DrivePacket& packet){};
Void (*fOutput)(DrivePacket& packet){};
Void (*fVerify)(DrivePacket& packet){};
Void (*fInit)(DrivePacket& packet){};
const Char* (*fProtocol)(Void){};
Void (*fInput)(DrivePacket& packet){nullptr};
Void (*fOutput)(DrivePacket& packet){nullptr};
Void (*fVerify)(DrivePacket& packet){nullptr};
Void (*fInit)(DrivePacket& packet){nullptr};
const Char* (*fProtocol)(Void){nullptr};
};

namespace Probe {
Expand Down Expand Up @@ -154,8 +154,13 @@ const Char* io_drv_kind(Void);
/// @return the new drive as a trait.
DriveTrait io_construct_blank_drive(Void) noexcept;

/// @brief Fetches the main drive.
/// @param trait the new drive as a trait.
Void io_construct_main_drive(DriveTrait& trait) noexcept;

/// @brief Fetches the main drive.
/// @return the new drive as a trait.
/// @deprecated use io_construct_main_drive(DriveTrait& trait) instead.
DriveTrait io_construct_main_drive(Void) noexcept;

namespace Detect {
Expand Down
2 changes: 1 addition & 1 deletion dev/kernel/KernelKit/PCI/Iterator.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ class Iterator final {
Iterator() = delete;

public:
explicit Iterator(const Types::PciDeviceKind& deviceType);
explicit Iterator(const Types::PciDeviceKind deviceType, UInt32 bar);

Iterator& operator=(const Iterator&) = default;
Iterator(const Iterator&) = default;
Expand Down
34 changes: 24 additions & 10 deletions dev/kernel/src/DriveMgr.cc
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,6 @@ Void io_drv_output(DriveTrait::DrivePacket& pckt) {
/// @param pckt the packet to read.
/// @return
Void io_drv_init(DriveTrait::DrivePacket& pckt) {
NE_UNUSED(pckt);

#if defined(__ATA_PIO__) || defined(__ATA_DMA__)
kATAMaster = 0;
kATAIO = 0;
Expand All @@ -97,10 +95,9 @@ Void io_drv_init(DriveTrait::DrivePacket& pckt) {
pckt.fPacketGood = YES;
#elif defined(__AHCI__)
kAHCIPortsImplemented = 0;
drv_std_init(kAHCIPortsImplemented);

if (drv_std_init(kAHCIPortsImplemented)) {
pckt.fPacketGood = YES;
}
pckt.fPacketGood = kAHCIPortsImplemented > 0;
#endif // if defined(__ATA_PIO__) || defined (__ATA_DMA__)
}

Expand Down Expand Up @@ -154,6 +151,8 @@ DriveTrait io_construct_blank_drive() noexcept {

namespace Probe {
Void io_detect_drive(DriveTrait& trait) {
trait.fInit(trait.fPacket);

EPM_PART_BLOCK block_struct;

trait.fPacket.fPacketLba = kEPMBootBlockLba;
Expand All @@ -163,8 +162,6 @@ namespace Probe {
rt_copy_memory((VoidPtr) "fs/detect-packet", trait.fPacket.fPacketMime,
rt_string_len("fs/detect-packet"));

trait.fInit(trait.fPacket);

trait.fInput(trait.fPacket);

if (rt_string_cmp(block_struct.Magic, kEPMMagic, kEPMMagicLength) == 0) {
Expand Down Expand Up @@ -215,14 +212,14 @@ namespace Probe {
trait.fPacket.fPacketSize = 0UL;
trait.fPacket.fPacketContent = nullptr;
}
} // namespace Detail
} // namespace Probe

/// @brief Fetches the main drive.
/// @return the new drive. (returns kEPMDrive if EPM formatted)
DriveTrait io_construct_main_drive() noexcept {
constexpr auto kMainDrive = "/media/main/";

DriveTrait trait{};
DriveTrait trait;

rt_copy_memory((VoidPtr) kMainDrive, trait.fName, rt_string_len(kMainDrive));
MUST_PASS(trait.fName[0] != 0);
Expand All @@ -232,9 +229,26 @@ DriveTrait io_construct_main_drive() noexcept {
trait.fInput = io_drv_input;
trait.fInit = io_drv_init;
trait.fProtocol = io_drv_kind;

Probe::io_detect_drive(trait);

return trait;
}

/// @brief Replacement for io_construct_main_drive that works with IMountpoint.
/// @return the new drive. (returns kEPMDrive if EPM formatted)
Void io_construct_main_drive(DriveTrait& trait) noexcept {
constexpr auto kMainDrive = "/media/main/";

rt_copy_memory((VoidPtr) kMainDrive, trait.fName, rt_string_len(kMainDrive));
MUST_PASS(trait.fName[0] != 0);

trait.fVerify = io_drv_unimplemented;
trait.fOutput = io_drv_output;
trait.fInput = io_drv_input;
trait.fInit = io_drv_init;
trait.fProtocol = io_drv_kind;

Probe::io_detect_drive(trait);
}
} // namespace Kernel
28 changes: 16 additions & 12 deletions dev/kernel/src/FS/OpenHeFS+FileSystemParser.cc
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ namespace Detail {
((val << 8) & 0x000000FF00000000ULL) | ((val << 24) & 0x0000FF0000000000ULL) |
((val << 40) & 0x00FF000000000000ULL) | ((val << 56) & 0xFF00000000000000ULL);
}

/// @brief Simple algorithm to hash directory entries for INDs.
/// @param path the directory path.
/// @return The hashed path.
Expand Down Expand Up @@ -759,15 +759,14 @@ _Output Bool HeFileSystemParser::Format(_Input _Output DriveTrait* mnt, _Input c
// if disk isn't good, then error out.
if (false == mnt->fPacket.fPacketGood) {
err_global_get() = kErrorDiskIsCorrupted;
return false;
return NO;
}

if (drv_std_get_size() < kHeFSMinimumDiskSize) {
(Void)(kout << "OpenHeFS recommends at least 128 GiB of free space." << kendl);
(Void)(
kout
<< "The OS will still try to format a OpenHeFS disk here anyway, don't expect perfect geometry."
<< kendl);
(Void)(kout << "The OS will still try to format a OpenHeFS disk here anyway, don't expect "
"perfect geometry."
<< kendl);
}

HEFS_BOOT_NODE* boot = (HEFS_BOOT_NODE*) RTL_ALLOCA(sizeof(HEFS_BOOT_NODE));
Expand Down Expand Up @@ -1145,23 +1144,28 @@ _Output Bool HeFileSystemParser::INodeCtlManip(_Input DriveTrait* mnt, _Input co
return NO;
}

STATIC DriveTrait kMountPoint;
STATIC IMountpoint kMountpoint;

/// @brief Initialize the OpenHeFS filesystem.
/// @return To check its status, see err_local_get().
Boolean OpenHeFS::fs_init_openhefs(Void) noexcept {
kout << "Verifying disk...\r";
io_construct_main_drive(kMountpoint.A());

kMountPoint = io_construct_main_drive();

if (kMountPoint.fPacket.fPacketReadOnly == YES) {
if (kMountpoint.A().fPacket.fPacketReadOnly == YES) {
kout << "Main disk cannot be mounted (read-only media).\r";
return NO;
}

HeFileSystemParser parser;

return parser.Format(&kMountPoint, kHeFSEncodingFlagsUTF8, kHeFSDefaultVolumeName);
if (!parser.Format(&kMountpoint.A(), kHeFSEncodingFlagsUTF8, kHeFSDefaultVolumeName)) {
kout << "Failed to format OpenHeFS partition!\r";
return NO;
}

kout << "Valid OpenHeFS disk...\r";

return YES;
}
} // namespace Kernel

Expand Down
7 changes: 2 additions & 5 deletions dev/launch/src/AppMain.cc
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,8 @@

/// @note This called by _NeMain from its own runtime.
extern "C" SInt32 nelaunch_startup_fn(Void) {
/// @todo Start LaunchHelpers.fwrk services, make the launcher manageable too (via mgmt.launch)

NELAUNCH_INFO("Turning on launcher...");

UInt32* ret = (UInt32*) libsys_syscall_arg_1(libsys_hash_64("__launch_register_pid0"));
/// Start LaunchHelpers.fwrk services, and make the launcher manageable too (via mgmt.launch)
UInt32* ret = (UInt32*) libsys_syscall_arg_1(libsys_hash_64("__launch_register_launch_service"));

if (ret) {
switch (*ret) {
Expand Down
Empty file.
29 changes: 29 additions & 0 deletions public/frameworks/LaunchHelpers.fwrk/headers/Foundation.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
/* -------------------------------------------

Copyright (C) 2025, Amlal El Mahrouss, licensed under the Apache 2.0 license.

------------------------------------------- */

#pragma once

#include <CoreFoundation.fwrk/headers/Foundation.h>
#include <CoreFoundation.fwrk/headers/String.h>

namespace LaunchHelpers {
struct LHLaunchInfo;

/// @brief Launch information structure.
/// @note This structure is read-only. Modyfing its members wo't have any effect.
struct LHLaunchInfo final {
CF::CFString fExecutablePath;
CF::CFString fWorkingDirectory;
CF::CFString fArguments;
CF::CFString fEnvironment;
CF::CFInteger64 fUID{0};
CF::CFInteger64 fGID{0};
};

/// @brief Get launch information.
/// @return the launch information structure.
LHLaunchInfo* LHGetLaunchInfo(Void) noexcept;
} // namespace LaunchHelpers
9 changes: 9 additions & 0 deletions public/tools/mgmt.launch/src/CommandLine.cc
Original file line number Diff line number Diff line change
@@ -1,5 +1,14 @@
/* -------------------------------------------

Copyright (C) 2025, Amlal El Mahrouss, licensed under the Apache 2.0 license.

------------------------------------------- */

#include <libSystem/SystemKit/System.h>

SInt32 _NeMain(SInt32 argc, Char* argv[]) {
LIBSYS_UNUSED(argc);
LIBSYS_UNUSED(argv);

return EXIT_FAILURE;
}
Loading