Kernel: Fix 32 bit target compilation

banos is written with only 64 bit in mind so it has to be disabled
This commit is contained in:
2026-08-22 15:33:49 +03:00
parent 645b6d772d
commit 4e9cfdde97
8 changed files with 78 additions and 40 deletions
+4 -4
View File
@@ -23,16 +23,16 @@ namespace Kernel
BAN::ErrorOr<size_t> read_impl(off_t, BAN::ByteSpan) override;
BAN::ErrorOr<size_t> write_impl(off_t, BAN::ConstByteSpan) override;
bool can_read_impl() const override { return m_value > 0; }
bool can_write_impl() const override { return m_value < UINT64_MAX - 1; }
bool can_read_impl() const override;
bool can_write_impl() const override;
bool has_error_impl() const override { return false; }
bool has_hungup_impl() const override { return false; }
private:
const bool m_is_semaphore;
BAN::Atomic<uint64_t> m_value;
uint64_t m_value;
Mutex m_mutex;
mutable Mutex m_mutex;
ThreadBlocker m_thread_blocker;
};
+10 -4
View File
@@ -182,17 +182,23 @@ namespace Kernel
}
template<typename T>
static T read_gs_sized(uintptr_t offset) requires(sizeof(T) <= 8 && BAN::Math::is_power_of_two(sizeof(T)))
static T read_gs_sized(uintptr_t offset) requires(sizeof(T) <= sizeof(uintptr_t) && BAN::Math::is_power_of_two(sizeof(T)))
{
T value;
asm volatile("mov %%gs:%a[offset], %[value]" : [value]"=r"(value) : [offset]"ir"(offset));
if constexpr (sizeof(T) == 1 && ARCH(i686))
asm volatile("mov %%gs:%a[offset], %[value]" : [value]"=q"(value) : [offset]"ir"(offset) : "memory");
else
asm volatile("mov %%gs:%a[offset], %[value]" : [value]"=r"(value) : [offset]"ir"(offset) : "memory");
return value;
}
template<typename T>
static void write_gs_sized(uintptr_t offset, T value) requires(sizeof(T) <= 8 && BAN::Math::is_power_of_two(sizeof(T)))
static void write_gs_sized(uintptr_t offset, T value) requires(sizeof(T) <= sizeof(uintptr_t) && BAN::Math::is_power_of_two(sizeof(T)))
{
asm volatile("mov %[value], %%gs:%a[offset]" :: [value]"r"(value), [offset]"ir"(offset) : "memory");
if constexpr (sizeof(T) == 1 && ARCH(i686))
asm volatile("mov %[value], %%gs:%a[offset]" :: [value]"q"(value), [offset]"ir"(offset) : "memory");
else
asm volatile("mov %[value], %%gs:%a[offset]" :: [value]"r"(value), [offset]"ir"(offset) : "memory");
}
void lock_tlb_lock();
+34 -27
View File
@@ -36,34 +36,11 @@ namespace Kernel::ACPI
if (offset < 0)
return BAN::Error::from_errno(EINVAL);
if (SystemTimer::get().ms_since_boot() > m_last_read_ms + 1000)
{
auto [method_path, method_ref] = TRY(m_acpi_namespace.find_named_object(m_battery_path, m_method_name));
if (method_ref == nullptr)
return BAN::Error::from_errno(EFAULT);
auto result = TRY(AML::method_call(method_path, method_ref->node, BAN::Array<AML::Reference*, 7>{}));
if (result.type != AML::Node::Type::Package || result.as.package->num_elements < m_result_index)
return BAN::Error::from_errno(EFAULT);
auto& target_elem = result.as.package->elements[m_result_index];
if (!target_elem.resolved || !target_elem.value.node)
return BAN::Error::from_errno(EFAULT);
auto target_conv = AML::convert_node(TRY(target_elem.value.node->copy()), AML::ConvInteger, sizeof(uint64_t));
if (target_conv.is_error())
return BAN::Error::from_errno(EFAULT);
m_last_read_ms = SystemTimer::get().ms_since_boot();
m_last_value = target_conv.value().as.integer.value;
}
auto target_str = TRY(BAN::String::formatted("{}", m_last_value.load()));
auto target_str = TRY(BAN::String::formatted("{}", TRY(get_value())));
if (static_cast<size_t>(offset) >= target_str.size())
return 0;
const size_t ncopy = BAN::Math::min(buffer.size(), target_str.size() - offset);
const size_t ncopy = BAN::Math::min<size_t>(buffer.size(), target_str.size() - offset);
memcpy(buffer.data(), target_str.data() + offset, ncopy);
return ncopy;
}
@@ -85,14 +62,44 @@ namespace Kernel::ACPI
, m_result_index(index)
{ }
BAN::ErrorOr<uint64_t> get_value()
{
LockGuard _(m_mutex);
if (SystemTimer::get().ms_since_boot() < m_last_read_ms + 1000)
return m_last_value;
auto [method_path, method_ref] = TRY(m_acpi_namespace.find_named_object(m_battery_path, m_method_name));
if (method_ref == nullptr)
return BAN::Error::from_errno(EFAULT);
auto result = TRY(AML::method_call(method_path, method_ref->node, BAN::Array<AML::Reference*, 7>{}));
if (result.type != AML::Node::Type::Package || result.as.package->num_elements < m_result_index)
return BAN::Error::from_errno(EFAULT);
auto& target_elem = result.as.package->elements[m_result_index];
if (!target_elem.resolved || !target_elem.value.node)
return BAN::Error::from_errno(EFAULT);
auto target_conv = AML::convert_node(TRY(target_elem.value.node->copy()), AML::ConvInteger, sizeof(uint64_t));
if (target_conv.is_error())
return BAN::Error::from_errno(EFAULT);
m_last_read_ms = SystemTimer::get().ms_since_boot();
m_last_value = target_conv.value().as.integer.value;
return m_last_value;
}
private:
AML::Namespace& m_acpi_namespace;
AML::Scope m_battery_path;
AML::NameString m_method_name;
size_t m_result_index;
BAN::Atomic<uint64_t> m_last_read_ms = 0;
BAN::Atomic<uint64_t> m_last_value = 0;
Mutex m_mutex;
uint64_t m_last_read_ms = 0;
uint64_t m_last_value = 0;
};
BAN::ErrorOr<void> BatterySystem::initialize(AML::Namespace& acpi_namespace)
+14 -1
View File
@@ -14,6 +14,8 @@
#include <kernel/Lock/SpinLock.h>
#include <kernel/UserCopy.h>
#if ARCH(x86_64)
using namespace LibELF;
using namespace Kernel;
@@ -204,7 +206,7 @@ BAN::ErrorOr<size_t> Banos::load_driver_from_image(const char* u_image) {
// NOTE: should be more than plenty ;)
extern char g_drv_builtin_begin[];
extern char g_drv_builtin_end[];
void Banos::initialize_initial_drivers(void) {
void Banos::initialize_initial_drivers() {
import_symbols(g_banos_export, g_banos_export_end - g_banos_export);
char* head = g_drv_builtin_begin;
while(head < g_drv_builtin_end) {
@@ -213,3 +215,14 @@ void Banos::initialize_initial_drivers(void) {
head += drv->driver_size;
}
}
#else
void Banos::initialize_initial_drivers()
{
}
BAN::ErrorOr<size_t> Banos::load_driver_from_image(const char* u_image)
{
(void)u_image;
return BAN::Error::from_errno(ENOTSUP);
}
#endif
+13 -1
View File
@@ -44,7 +44,7 @@ namespace Kernel
while (m_value == 0)
TRY(Thread::current().block_or_eintr_indefinite(m_thread_blocker, &m_mutex));
const uint64_t read_value = m_is_semaphore ? 1 : m_value.load();
const uint64_t read_value = m_is_semaphore ? 1 : m_value;
m_value -= read_value;
buffer.as<uint64_t>() = read_value;
@@ -80,4 +80,16 @@ namespace Kernel
return sizeof(uint64_t);
}
bool EventFD::can_read_impl() const
{
LockGuard _(m_mutex);
return m_value > 0;
}
bool EventFD::can_write_impl() const
{
LockGuard _(m_mutex);
return m_value < UINT64_MAX - 1;
}
}
+1 -1
View File
@@ -115,7 +115,7 @@ namespace Kernel
return {};
const vaddr_t first_page = BAN::Math::max(m_vaddr, address) & PAGE_ADDR_MASK;
const vaddr_t last_page = BAN::Math::div_round_up(BAN::Math::min(m_vaddr + m_size, address + size), PAGE_SIZE) * PAGE_SIZE;
const vaddr_t last_page = BAN::Math::div_round_up<vaddr_t>(BAN::Math::min(m_vaddr + m_size, address + size), PAGE_SIZE) * PAGE_SIZE;
RWLockRDGuard _(m_shared_data->rw_lock);
for (vaddr_t page_addr = first_page; page_addr < last_page; page_addr += PAGE_SIZE)
+1 -1
View File
@@ -117,7 +117,7 @@ namespace Kernel
.shm_dtime = 0,
.shm_ctime = SystemTimer::get().real_time().tv_sec,
}));
TRY(object->paddrs.resize(BAN::Math::div_round_up(size, PAGE_SIZE), 0));
TRY(object->paddrs.resize(BAN::Math::div_round_up<size_t>(size, PAGE_SIZE), 0));
if (key != IPC_PRIVATE)
TRY(m_ids.insert(key, shmid));
+1 -1
View File
@@ -302,7 +302,7 @@ namespace Kernel
const vaddr_t buffer_vaddr = reinterpret_cast<vaddr_t>(buffer.data());
const paddr_t buffer_paddr = to_paddr(buffer_vaddr);
const size_t bytes = BAN::Math::min(buffer.size(), PAGE_SIZE - buffer_vaddr % PAGE_SIZE);
const size_t bytes = BAN::Math::min<size_t>(buffer.size(), PAGE_SIZE - buffer_vaddr % PAGE_SIZE);
bool can_extend = true;
if (prdt_count == 0)