summaryrefslogtreecommitdiffhomepage
path: root/dev
diff options
context:
space:
mode:
Diffstat (limited to 'dev')
-rw-r--r--dev/boot/src/HEL/AMD64/BootEFI.cc5
-rw-r--r--dev/kernel/HALKit/AMD64/PCI/Device.cc27
-rw-r--r--dev/kernel/HALKit/AMD64/Storage/AHCI+Generic.cc41
-rw-r--r--dev/kernel/amd64-ci.make2
-rw-r--r--dev/kernel/amd64-desktop.make2
-rw-r--r--dev/kernel/src/BitMapMgr.cc10
-rw-r--r--dev/kernel/src/CxxAbi-AMD64.cc2
7 files changed, 36 insertions, 53 deletions
diff --git a/dev/boot/src/HEL/AMD64/BootEFI.cc b/dev/boot/src/HEL/AMD64/BootEFI.cc
index bd1c7860..4102d3b4 100644
--- a/dev/boot/src/HEL/AMD64/BootEFI.cc
+++ b/dev/boot/src/HEL/AMD64/BootEFI.cc
@@ -20,7 +20,7 @@
// Makes the compiler shut up.
#ifndef kMachineModel
-#define kMachineModel "NeKernel"
+#define kMachineModel "Krnl"
#endif // !kMachineModel
#ifndef kExpectedWidth
@@ -334,6 +334,9 @@ EFI_EXTERN_C EFI_API Int32 ModuleMain(EfiHandlePtr image_handle,
Boot::ExitBootServices(map_key, image_handle);
+ handover_hdr->f_BitMapStart = (VoidPtr)((UIntPtr)reader_kernel.Blob() + (UIntPtr)handover_hdr->f_BitMapStart + reader_kernel.Size());
+ handover_hdr->f_BitMapSize -= reader_kernel.Size();
+
if (kernel_thread->Start(handover_hdr, YES) != kEfiOk)
{
// ------------------------------------------ //
diff --git a/dev/kernel/HALKit/AMD64/PCI/Device.cc b/dev/kernel/HALKit/AMD64/PCI/Device.cc
index 9c27cb10..7ad19360 100644
--- a/dev/kernel/HALKit/AMD64/PCI/Device.cc
+++ b/dev/kernel/HALKit/AMD64/PCI/Device.cc
@@ -7,14 +7,15 @@
#include <ArchKit/ArchKit.h>
#include <KernelKit/PCI/Device.h>
-#define PCI_BAR_IO 0x01
-#define PCI_BAR_LOWMEM 0x02
-#define PCI_BAR_64 0x04
-#define PCI_BAR_PREFETCH 0x08
+#define PCI_BAR_IO (0x01)
+#define PCI_BAR_LOWMEM (0x02)
+#define PCI_BAR_64 (0x04)
+#define PCI_BAR_PREFETCH (0x08)
+#define PCI_ENABLE_BIT (0x80000000)
-Kernel::UInt NE_PCIReadRaw(Kernel::UInt bar, Kernel::UShort bus, Kernel::UShort dev, Kernel::UShort fun)
+static Kernel::UInt NE_PCIReadRaw(Kernel::UInt bar, Kernel::UShort bus, Kernel::UShort dev, Kernel::UShort fun)
{
- Kernel::UInt target = 0x80000000 | ((Kernel::UInt)bus << 16) |
+ Kernel::UInt target = PCI_ENABLE_BIT | ((Kernel::UInt)bus << 16) |
((Kernel::UInt)dev << 11) | ((Kernel::UInt)fun << 8) |
(bar & 0xFC);
@@ -26,7 +27,7 @@ Kernel::UInt NE_PCIReadRaw(Kernel::UInt bar, Kernel::UShort bus, Kernel::UShort
return Kernel::HAL::rt_in32((Kernel::UShort)Kernel::PCI::PciConfigKind::ConfigData);
}
-void NE_PCISetCfgTarget(Kernel::UInt bar, Kernel::UShort bus, Kernel::UShort dev, Kernel::UShort fun)
+static Kernel::Void NE_PCISetCfgTarget(Kernel::UInt bar, Kernel::UShort bus, Kernel::UShort dev, Kernel::UShort fun)
{
Kernel::UInt target = 0x80000000 | ((Kernel::UInt)bus << 16) |
((Kernel::UInt)dev << 11) | ((Kernel::UInt)fun << 8) |
@@ -70,20 +71,26 @@ namespace Kernel::PCI
NE_PCISetCfgTarget(bar & 0xFC, fBus, fDevice, fFunction);
if (sz == 4)
- HAL::rt_out32((UShort)PciConfigKind::ConfigData, (UInt)data);
+ {
+ HAL::rt_out32((UShort)PciConfigKind::ConfigAddress, (UInt)data);
+ }
else if (sz == 2)
{
UInt temp = HAL::rt_in32((UShort)PciConfigKind::ConfigData);
+
temp &= ~(0xFFFF << ((bar & 2) * 8));
temp |= (data & 0xFFFF) << ((bar & 2) * 8);
- HAL::rt_out32((UShort)PciConfigKind::ConfigData, temp);
+
+ HAL::rt_out32((UShort)PciConfigKind::ConfigAddress, temp);
}
else if (sz == 1)
{
UInt temp = HAL::rt_in32((UShort)PciConfigKind::ConfigData);
+
temp &= ~(0xFF << ((bar & 3) * 8));
temp |= (data & 0xFF) << ((bar & 3) * 8);
- HAL::rt_out32((UShort)PciConfigKind::ConfigData, temp);
+
+ HAL::rt_out32((UShort)PciConfigKind::ConfigAddress, temp);
}
}
diff --git a/dev/kernel/HALKit/AMD64/Storage/AHCI+Generic.cc b/dev/kernel/HALKit/AMD64/Storage/AHCI+Generic.cc
index e9c967dc..68a5b051 100644
--- a/dev/kernel/HALKit/AMD64/Storage/AHCI+Generic.cc
+++ b/dev/kernel/HALKit/AMD64/Storage/AHCI+Generic.cc
@@ -15,7 +15,6 @@
*
*/
-#include "NewKit/Defines.h"
#include <KernelKit/DeviceMgr.h>
#include <KernelKit/DriveMgr.h>
#include <KernelKit/ProcessScheduler.h>
@@ -70,7 +69,7 @@ STATIC Void drv_compute_disk_ahci() noexcept;
namespace AHCI::Detail
{
template <typename RetType>
- RetType* ahci_align_address(RetType* address, Int32 alignement)
+ STATIC RetType* ahci_align_address(RetType* address, Int32 alignement)
{
if (!address)
return nullptr;
@@ -91,7 +90,7 @@ STATIC Void drv_compute_disk_ahci() noexcept
const UInt16 kSzIdent = 256;
/// Push it to the stack
- UInt16* identify_data ATTRIBUTE(aligned(kib_cast(1))) = AHCI::Detail::ahci_align_address<UInt16>(new UInt16[kSzIdent], kib_cast(1));
+ UInt16* identify_data = AHCI::Detail::ahci_align_address<UInt16>(new UInt16[kSzIdent], kib_cast(1));
/// Send AHCI command for identification.
drv_std_input_output_ahci<NO, YES, YES>(0, (UInt8*)identify_data, kAHCISectorSize, kSzIdent);
@@ -198,8 +197,6 @@ STATIC Void drv_std_input_output_ahci(UInt64 lba, UInt8* buffer, SizeT sector_sz
volatile FisRegH2D* h2d_fis = (volatile FisRegH2D*)(&command_table->Cfis[0]);
- rt_set_memory((FisRegH2D*)h2d_fis, 0, sizeof(FisRegH2D));
-
h2d_fis->FisType = kFISTypeRegH2D;
h2d_fis->CmdOrCtrl = CommandOrCTRL;
h2d_fis->Command = (Identify ? (kAHCICmdIdentify) : (Write ? kAHCICmdWriteDmaEx : kAHCICmdReadDmaEx));
@@ -287,40 +284,6 @@ STATIC BOOL ahci_enable_and_probe()
break;
}
- // Command engine stopped, remap the AHCI port.
-
- auto port = &kSATAHba->Ports[kSATAIndex];
-
- // Relocate Command List Base.
-
- VoidPtr const kAHCIBasePtr = AHCI::Detail::ahci_align_address<Void>(mm_new_heap(kib_cast(64), YES, NO, 0), kib_cast(1));
- UIntPtr const kAHCIBaseAddress = reinterpret_cast<UIntPtr>(kAHCIBasePtr);
-
- port->Clb = kAHCIBaseAddress + (kSATAIndex << 10);
- port->Clbu = 0;
-
- // clean it.
- rt_set_memory(reinterpret_cast<VoidPtr>(port->Clb), 0, 1024);
-
- // Relocate Frame Info Structure now.
-
- port->Fb = (UInt32)(UIntPtr)(UIntPtr*)AHCI::Detail::ahci_align_address<UInt32>((UInt32*)(kAHCIBaseAddress + (kSATAPortCnt << 10) + (kSATAIndex << 10)), kib_cast(1));
- port->Fbu = 0;
-
- // clean it.
- rt_set_memory(reinterpret_cast<VoidPtr>(port->Fb), 0, 256);
-
- volatile HbaCmdHeader* cmd_hdr = reinterpret_cast<volatile HbaCmdHeader*>(port->Clb);
-
- for (Int32 i = 0; i < kSATAPortCnt; i++)
- {
- cmd_hdr[i].Prdtl = 8;
- cmd_hdr[i].Ctba = (UInt32)(UIntPtr)(UIntPtr*)AHCI::Detail::ahci_align_address<UInt32>((UInt32*)(kAHCIBaseAddress + (40 << 10) + (kSATAPortCnt << 10) + (kSATAIndex << 10)), kib_cast(1));
- cmd_hdr[i].Ctbau = 0;
-
- rt_set_memory(reinterpret_cast<VoidPtr>(cmd_hdr[i].Ctba), 0, 256);
- }
-
// Now we are ready.
kSATAHba->Ports[kSATAIndex].Cmd |= kHBAPxCmdFre;
diff --git a/dev/kernel/amd64-ci.make b/dev/kernel/amd64-ci.make
index a03c8fdd..d74b5523 100644
--- a/dev/kernel/amd64-ci.make
+++ b/dev/kernel/amd64-ci.make
@@ -33,7 +33,7 @@ COPY = cp
ASMFLAGS = -f win64
# Kernel subsystem is 17 and entrypoint is hal_init_platform
-LDFLAGS = -e hal_init_platform --subsystem=17 --image-base 0x4000000
+LDFLAGS = -e hal_init_platform --subsystem=17 --image-base 0x1000000
LDOBJ = obj/*.obj
# This file is the Kernel, responsible of task, memory, driver, sci, disk and device management.
diff --git a/dev/kernel/amd64-desktop.make b/dev/kernel/amd64-desktop.make
index a03c8fdd..d74b5523 100644
--- a/dev/kernel/amd64-desktop.make
+++ b/dev/kernel/amd64-desktop.make
@@ -33,7 +33,7 @@ COPY = cp
ASMFLAGS = -f win64
# Kernel subsystem is 17 and entrypoint is hal_init_platform
-LDFLAGS = -e hal_init_platform --subsystem=17 --image-base 0x4000000
+LDFLAGS = -e hal_init_platform --subsystem=17 --image-base 0x1000000
LDOBJ = obj/*.obj
# This file is the Kernel, responsible of task, memory, driver, sci, disk and device management.
diff --git a/dev/kernel/src/BitMapMgr.cc b/dev/kernel/src/BitMapMgr.cc
index 7f3f8500..51c4aed1 100644
--- a/dev/kernel/src/BitMapMgr.cc
+++ b/dev/kernel/src/BitMapMgr.cc
@@ -141,7 +141,15 @@ namespace Kernel
return (VoidPtr)ptr_bit_set;
}
- base = reinterpret_cast<VoidPtr>(reinterpret_cast<UIntPtr>(base) + ((ptr_bit_set[kBitMapMagIdx] != kBitMapMagic) ? (size + pad) : ptr_bit_set[kBitMapSizeIdx]));
+ UIntPtr raw_base = reinterpret_cast<UIntPtr>(base);
+ UIntPtr offset = (ptr_bit_set[kBitMapMagIdx] != kBitMapMagic)
+ ? (size + pad)
+ : ptr_bit_set[kBitMapSizeIdx];
+
+ base = reinterpret_cast<VoidPtr>(raw_base + offset);
+
+ if (base == nullptr)
+ return nullptr;
}
return nullptr;
diff --git a/dev/kernel/src/CxxAbi-AMD64.cc b/dev/kernel/src/CxxAbi-AMD64.cc
index 3209a1a9..9270d612 100644
--- a/dev/kernel/src/CxxAbi-AMD64.cc
+++ b/dev/kernel/src/CxxAbi-AMD64.cc
@@ -25,6 +25,8 @@ EXTERN_C Kernel::Void __cxa_pure_virtual(void* self)
EXTERN_C void ___chkstk_ms(void)
{
+ kout << "Stack smashing detected!\r";
+ dbg_break_point();
}
EXTERN_C int atexit(void (*f)(void*), void* arg, void* dso)