[Zion] Add an argument to memory align a mapping.
This commit is contained in:
parent
c8931a01c8
commit
d44be91099
|
@ -13,9 +13,9 @@ class NaiveAllocator {
|
|||
uint64_t vmmo_cap;
|
||||
uint64_t err = ZMemoryObjectCreate(kSize, &vmmo_cap);
|
||||
if (err != 0) {
|
||||
ZProcessExit(err);
|
||||
(void)ZProcessExit(err);
|
||||
}
|
||||
err = ZAddressSpaceMap(gSelfVmasCap, 0, vmmo_cap, &next_addr_);
|
||||
err = ZAddressSpaceMap(gSelfVmasCap, 0, vmmo_cap, 0, &next_addr_);
|
||||
max_addr_ = next_addr_ + kSize;
|
||||
}
|
||||
|
||||
|
@ -23,7 +23,7 @@ class NaiveAllocator {
|
|||
uint64_t addr = next_addr_;
|
||||
next_addr_ += size;
|
||||
if (next_addr_ >= max_addr_) {
|
||||
ZProcessExit(0xBEEF);
|
||||
(void)ZProcessExit(0xBEEF);
|
||||
return 0;
|
||||
}
|
||||
return reinterpret_cast<void*>(addr);
|
||||
|
|
|
@ -81,7 +81,7 @@ uint64_t LoadElfProgram(uint64_t base, uint64_t as_cap) {
|
|||
dbgln("Map Local");
|
||||
#endif
|
||||
uint64_t vaddr;
|
||||
check(ZAddressSpaceMap(gSelfVmasCap, 0, mem_cap, &vaddr));
|
||||
check(ZAddressSpaceMap(gSelfVmasCap, 0, mem_cap, 0, &vaddr));
|
||||
uint8_t* offset = reinterpret_cast<uint8_t*>(vaddr);
|
||||
for (uint64_t j = 0; j < size; j++) {
|
||||
offset[j] = 0;
|
||||
|
@ -95,8 +95,8 @@ uint64_t LoadElfProgram(uint64_t base, uint64_t as_cap) {
|
|||
#if MAM_PROC_DEBUG
|
||||
dbgln("Map Foreign");
|
||||
#endif
|
||||
check(
|
||||
ZAddressSpaceMap(as_cap, program.vaddr - page_offset, mem_cap, &vaddr));
|
||||
check(ZAddressSpaceMap(as_cap, program.vaddr - page_offset, mem_cap, 0,
|
||||
&vaddr));
|
||||
}
|
||||
return header->entry;
|
||||
}
|
||||
|
|
|
@ -3,7 +3,9 @@
|
|||
#include <glacier/status/error.h>
|
||||
#include <zcall.h>
|
||||
|
||||
void dbgln(const glcr::String& string) { (void)ZDebug(string.cstr()); }
|
||||
void dbgln(glcr::StringView string) {
|
||||
(void)ZDebug(string.data(), string.size());
|
||||
}
|
||||
|
||||
void check(uint64_t code) {
|
||||
switch (code) {
|
||||
|
|
|
@ -6,7 +6,7 @@
|
|||
#include <ztypes.h>
|
||||
|
||||
// TODO: Take StringView here instead.
|
||||
void dbgln(const glcr::String& string);
|
||||
void dbgln(glcr::StringView string);
|
||||
|
||||
template <typename... Args>
|
||||
void dbgln(const glcr::StringView& fmt, Args... args) {
|
||||
|
|
|
@ -36,7 +36,7 @@ OwnedMemoryRegion::~OwnedMemoryRegion() {
|
|||
|
||||
OwnedMemoryRegion OwnedMemoryRegion::FromCapability(z_cap_t vmmo_cap) {
|
||||
uint64_t vaddr;
|
||||
check(ZAddressSpaceMap(gSelfVmasCap, 0, vmmo_cap, &vaddr));
|
||||
check(ZAddressSpaceMap(gSelfVmasCap, 0, vmmo_cap, 0, &vaddr));
|
||||
|
||||
uint64_t size;
|
||||
check(ZMemoryObjectInspect(vmmo_cap, &size));
|
||||
|
@ -50,7 +50,7 @@ OwnedMemoryRegion OwnedMemoryRegion::ContiguousPhysical(uint64_t size,
|
|||
check(ZMemoryObjectCreateContiguous(size, &vmmo_cap, paddr));
|
||||
|
||||
uint64_t vaddr;
|
||||
check(ZAddressSpaceMap(gSelfVmasCap, 0, vmmo_cap, &vaddr));
|
||||
check(ZAddressSpaceMap(gSelfVmasCap, 0, vmmo_cap, 0, &vaddr));
|
||||
|
||||
return OwnedMemoryRegion(vmmo_cap, vaddr, size);
|
||||
}
|
||||
|
@ -61,7 +61,7 @@ OwnedMemoryRegion OwnedMemoryRegion::DirectPhysical(uint64_t paddr,
|
|||
check(ZMemoryObjectCreatePhysical(paddr, size, &vmmo_cap));
|
||||
|
||||
uint64_t vaddr;
|
||||
check(ZAddressSpaceMap(gSelfVmasCap, 0, vmmo_cap, &vaddr));
|
||||
check(ZAddressSpaceMap(gSelfVmasCap, 0, vmmo_cap, 0, &vaddr));
|
||||
return OwnedMemoryRegion(vmmo_cap, vaddr, size);
|
||||
}
|
||||
|
||||
|
|
|
@ -18,7 +18,7 @@ PciDeviceHeader* PciHeader(uint64_t base, uint64_t bus, uint64_t dev,
|
|||
|
||||
PciReader::PciReader() {
|
||||
uint64_t vaddr;
|
||||
check(ZAddressSpaceMap(gSelfVmasCap, 0, gBootPciVmmoCap, &vaddr));
|
||||
check(ZAddressSpaceMap(gSelfVmasCap, 0, gBootPciVmmoCap, 0, &vaddr));
|
||||
|
||||
PciDump(vaddr);
|
||||
|
||||
|
|
|
@ -17,8 +17,8 @@ SYS4(ThreadStart, z_cap_t, thread_cap, uint64_t, entry, uint64_t, arg1,
|
|||
SYS0(ThreadExit);
|
||||
SYS1(ThreadWait, z_cap_t, thread_cap);
|
||||
|
||||
SYS4(AddressSpaceMap, z_cap_t, vmas_cap, uint64_t, vmas_offset, z_cap_t,
|
||||
vmmo_cap, uint64_t*, vaddr);
|
||||
SYS5(AddressSpaceMap, z_cap_t, vmas_cap, uint64_t, vmas_offset, z_cap_t,
|
||||
vmmo_cap, uint64_t, align, uint64_t*, vaddr);
|
||||
SYS3(AddressSpaceUnmap, z_cap_t, vmas_cap, uint64_t, lower_addr, uint64_t,
|
||||
upper_addr);
|
||||
|
||||
|
@ -68,4 +68,4 @@ SYS1(SemaphoreCreate, z_cap_t*, semaphore_cap);
|
|||
SYS1(SemaphoreWait, z_cap_t, semaphore_cap);
|
||||
SYS1(SemaphoreSignal, z_cap_t, semaphore_cap);
|
||||
|
||||
SYS1(Debug, const char*, message);
|
||||
SYS2(Debug, const char*, message, uint64_t, size);
|
||||
|
|
|
@ -26,11 +26,17 @@ void AddressSpace::FreeUserStack(uint64_t rsp) {
|
|||
return user_stacks_.FreeUserStack(rsp);
|
||||
}
|
||||
|
||||
uint64_t AddressSpace::GetNextMemMapAddr(uint64_t size) {
|
||||
uint64_t AddressSpace::GetNextMemMapAddr(uint64_t size, uint64_t align) {
|
||||
if (size == 0) {
|
||||
panic("Zero size memmap");
|
||||
}
|
||||
size = ((size - 1) & ~0xFFF) + 0x1000;
|
||||
// FIXME: We need to validate that align is a power of 2;
|
||||
if (align > 0) {
|
||||
while ((next_memmap_addr_ & (align - 1)) != 0) {
|
||||
next_memmap_addr_ += kPageSize;
|
||||
}
|
||||
}
|
||||
uint64_t addr = next_memmap_addr_;
|
||||
next_memmap_addr_ += size;
|
||||
if (next_memmap_addr_ >= 0x30'00000000) {
|
||||
|
@ -45,8 +51,8 @@ glcr::ErrorCode AddressSpace::MapInMemoryObject(
|
|||
}
|
||||
|
||||
glcr::ErrorOr<uint64_t> AddressSpace::MapInMemoryObject(
|
||||
const glcr::RefPtr<MemoryObject>& mem_obj) {
|
||||
uint64_t vaddr = GetNextMemMapAddr(mem_obj->size());
|
||||
const glcr::RefPtr<MemoryObject>& mem_obj, uint64_t align) {
|
||||
uint64_t vaddr = GetNextMemMapAddr(mem_obj->size(), align);
|
||||
RET_ERR(mapping_tree_.AddInMemoryObject(vaddr, mem_obj));
|
||||
return vaddr;
|
||||
}
|
||||
|
|
|
@ -67,7 +67,7 @@ class AddressSpace : public KernelObject {
|
|||
// User Mappings.
|
||||
uint64_t AllocateUserStack();
|
||||
void FreeUserStack(uint64_t);
|
||||
uint64_t GetNextMemMapAddr(uint64_t size);
|
||||
uint64_t GetNextMemMapAddr(uint64_t size, uint64_t align);
|
||||
|
||||
// Maps in a memory object at a specific address.
|
||||
// Note this is unsafe for now as it may clobber other mappings.
|
||||
|
@ -75,7 +75,7 @@ class AddressSpace : public KernelObject {
|
|||
uint64_t vaddr, const glcr::RefPtr<MemoryObject>& mem_obj);
|
||||
|
||||
[[nodiscard]] glcr::ErrorOr<uint64_t> MapInMemoryObject(
|
||||
const glcr::RefPtr<MemoryObject>& mem_obj);
|
||||
const glcr::RefPtr<MemoryObject>& mem_obj, uint64_t align);
|
||||
|
||||
[[nodiscard]] glcr::ErrorCode FreeAddressRange(uint64_t vaddr_base,
|
||||
uint64_t vaddr_limit) {
|
||||
|
|
|
@ -18,7 +18,7 @@ z_err_t AddressSpaceMap(ZAddressSpaceMapReq* req) {
|
|||
RET_ERR(vmas->MapInMemoryObject(req->vmas_offset, vmmo));
|
||||
*req->vaddr = req->vmas_offset;
|
||||
} else {
|
||||
ASSIGN_OR_RETURN(*req->vaddr, vmas->MapInMemoryObject(vmmo));
|
||||
ASSIGN_OR_RETURN(*req->vaddr, vmas->MapInMemoryObject(vmmo, req->align));
|
||||
}
|
||||
return glcr::OK;
|
||||
}
|
||||
|
|
|
@ -5,6 +5,6 @@
|
|||
#include "debug/debug.h"
|
||||
|
||||
z_err_t Debug(ZDebugReq* req) {
|
||||
dbgln_large("[Debug] {}", req->message);
|
||||
dbgln_large("[Debug] {}", glcr::StringView(req->message, req->size));
|
||||
return glcr::OK;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue