aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBobby <[email protected]>2026-02-20 18:08:45 +0530
committerBobby <[email protected]>2026-02-20 18:08:45 +0530
commit78c3c538e754ea43d5b52db0f64894cce78545ac (patch)
tree1782b4ee6816ea74f6cd6f86c46773a673170a90
parent11529f20f7710771bd517648a71bc044ee37e825 (diff)
downloadakiba-78c3c538e754ea43d5b52db0f64894cce78545ac.tar.xz
akiba-78c3c538e754ea43d5b52db0f64894cce78545ac.zip
feat: Refactor path handling to use location utilities and update related structures
- Replaced path references with location in various modules for consistency. - Updated attachment management to use location instead of path. - Enhanced I/O operations to handle location parameters. - Removed deprecated path utilities and integrated location utilities. - Adjusted limits and parameters for kata and attachment management.
-rw-r--r--mirai/boot/sequence/sequence.zig4
-rw-r--r--mirai/common/constants/memory.zig7
-rw-r--r--mirai/common/limits/ahci.zig1
-rw-r--r--mirai/common/limits/attachment.zig4
-rw-r--r--mirai/common/limits/fs.zig6
-rw-r--r--mirai/common/limits/io.zig6
-rw-r--r--mirai/common/limits/kata.zig26
-rw-r--r--mirai/drivers/ahci/ahci.zig11
-rw-r--r--mirai/hikari/elf/parser.zig6
-rw-r--r--mirai/hikari/loader.zig44
-rw-r--r--mirai/invocations/io/attach.zig16
-rw-r--r--mirai/invocations/kata/spawn.zig4
-rw-r--r--mirai/kata/attachment.zig4
-rw-r--r--mirai/kata/memory.zig74
-rw-r--r--mirai/utils/fs/location.zig33
-rw-r--r--mirai/utils/fs/path.zig36
-rw-r--r--mirai/utils/kata/attachment.zig4
-rw-r--r--system/ash/ash.zig36
-rw-r--r--system/libraries/io/attachment.zig14
-rw-r--r--system/libraries/io/io.zig2
-rw-r--r--system/libraries/io/location.zig8
-rw-r--r--system/libraries/io/stream.zig4
-rw-r--r--system/libraries/io/types.zig10
-rw-r--r--system/libraries/kata/kata.zig8
24 files changed, 198 insertions, 170 deletions
diff --git a/mirai/boot/sequence/sequence.zig b/mirai/boot/sequence/sequence.zig
index 3bf6128..685b8f1 100644
--- a/mirai/boot/sequence/sequence.zig
+++ b/mirai/boot/sequence/sequence.zig
@@ -22,7 +22,7 @@ const pit = @import("../../drivers/pit/pit.zig");
const pmm = @import("../../memory/pmm.zig");
const sensei = @import("../../kata/sensei/sensei.zig");
const serial = @import("../../drivers/serial/serial.zig");
-const system = @import("../../system/system.zig");
+const memory_const = @import("../../common/constants/memory.zig");
const terminal = @import("../../graphics/terminal/terminal.zig");
const tss = @import("../tss/tss.zig");
@@ -40,7 +40,7 @@ pub fn run(multiboot_addr: u64) void {
ok();
step("Initializing physical memory");
- pmm.init(system.constants.KERNEL_END(), memory_map);
+ pmm.init(memory_const.MIRAI_END(), memory_map);
ok();
step("Initializing heap");
diff --git a/mirai/common/constants/memory.zig b/mirai/common/constants/memory.zig
index 78afb46..0ec5883 100644
--- a/mirai/common/constants/memory.zig
+++ b/mirai/common/constants/memory.zig
@@ -23,6 +23,13 @@ pub fn MIRAI_END() u64 {
pub const KATA_SPACE_START: u64 = 0x1000;
pub const KATA_SPACE_END: u64 = 0x0000800000000000;
+// Stack configuration
+pub const USER_STACK_TOP: u64 = 0x00007FFFFFF00000;
+pub const USER_STACK_PAGES: u64 = 512; // 2MB
+pub const USER_STACK_SIZE: u64 = USER_STACK_PAGES * PAGE_SIZE;
+pub const KERNEL_STACK_PAGES: u64 = 4; // 16KB
+pub const KERNEL_STACK_SIZE: u64 = KERNEL_STACK_PAGES * PAGE_SIZE;
+
pub const PTE_PRESENT: u64 = 1 << 0;
pub const PTE_WRITABLE: u64 = 1 << 1;
pub const PTE_USER: u64 = 1 << 2;
diff --git a/mirai/common/limits/ahci.zig b/mirai/common/limits/ahci.zig
index 84a2106..027a992 100644
--- a/mirai/common/limits/ahci.zig
+++ b/mirai/common/limits/ahci.zig
@@ -6,4 +6,3 @@ pub const TIMEOUT_SPIN: u32 = 500000;
pub const TIMEOUT_CMD: u32 = 1000000;
pub const TIMEOUT_WAIT: u32 = 10000000;
pub const CMD_TABLE_CLEAR_SIZE: usize = 256;
-pub const PAGE_SIZE: usize = 4096;
diff --git a/mirai/common/limits/attachment.zig b/mirai/common/limits/attachment.zig
index 28aad3a..815b08f 100644
--- a/mirai/common/limits/attachment.zig
+++ b/mirai/common/limits/attachment.zig
@@ -1,3 +1,5 @@
//! Attachment limits
-pub const MAX_PATH_LENGTH: usize = 256;
+const fs_limits = @import("fs.zig");
+
+pub const MAX_LOCATION_LENGTH: usize = fs_limits.MAX_LOCATION_LENGTH;
diff --git a/mirai/common/limits/fs.zig b/mirai/common/limits/fs.zig
index b0626f2..ca7103d 100644
--- a/mirai/common/limits/fs.zig
+++ b/mirai/common/limits/fs.zig
@@ -1,6 +1,6 @@
//! Filesystem limits
-pub const MAX_LOCATION_LENGTH: usize = 255;
+pub const MAX_LOCATION_LENGTH: usize = 4096;
pub const MAX_IDENTITY_LENGTH: usize = 255;
-pub const MAX_UNIT_SIZE: u64 = 1024 * 1024;
-pub const MAX_STACK_ITEMS: usize = 32;
+pub const MAX_UNIT_SIZE: u64 = 64 * 1024 * 1024; // 64MB
+pub const MAX_STACK_ITEMS: usize = 4096;
diff --git a/mirai/common/limits/io.zig b/mirai/common/limits/io.zig
index dfc2e73..2dc80c4 100644
--- a/mirai/common/limits/io.zig
+++ b/mirai/common/limits/io.zig
@@ -1,6 +1,6 @@
//! I/O limits
-pub const MAX_MARK_SIZE: u64 = 1024 * 1024;
-pub const MAX_VIEW_SIZE: u64 = 1024 * 1024;
-pub const MIRAI_COPY_BUFFER_SIZE: usize = 256;
+pub const MAX_MARK_SIZE: u64 = 4 * 1024 * 1024; // 4MB
+pub const MAX_VIEW_SIZE: u64 = 4 * 1024 * 1024; // 4MB
+pub const MIRAI_COPY_BUFFER_SIZE: usize = 4096; // 4KB
pub const MAX_STRING_LENGTH: usize = 4096;
diff --git a/mirai/common/limits/kata.zig b/mirai/common/limits/kata.zig
index 98c85bc..106db2c 100644
--- a/mirai/common/limits/kata.zig
+++ b/mirai/common/limits/kata.zig
@@ -1,23 +1,9 @@
//! Kata Limits - Kata-related limits
-// ============================================================================
-// Kata Limits
-// ============================================================================
-
-/// Maximum number of concurrent katas
-pub const MAX_KATAS: usize = 256;
-
-/// Maximum number of attachments per kata
-pub const MAX_ATTACHMENTS: usize = 16;
-
-/// Maximum command line arguments
-pub const MAX_ARGS: usize = 32;
-
-/// Maximum environment variables
-pub const MAX_ENV_VARS: usize = 64;
-
-/// Maximum location (working directory) length
+pub const MAX_KATAS: usize = 1024;
+pub const MAX_ATTACHMENTS: usize = 256;
+pub const MAX_PARAMETERS: usize = 256;
+pub const MAX_ENV_VARS: usize = 256;
+/// Maximum location (current stack) length
pub const MAX_LOCATION_LENGTH: usize = 256;
-
-/// Maximum postman letter length
-pub const MAX_LETTER_LENGTH: usize = 256;
+pub const MAX_LETTER_LENGTH: usize = 4096; // Maximum postman letter length
diff --git a/mirai/drivers/ahci/ahci.zig b/mirai/drivers/ahci/ahci.zig
index 69373b5..c9073bd 100644
--- a/mirai/drivers/ahci/ahci.zig
+++ b/mirai/drivers/ahci/ahci.zig
@@ -11,12 +11,13 @@ const pci_const = @import("../../common/constants/pci.zig");
const pmm = @import("../../memory/pmm.zig");
const port_ops = @import("port.zig");
const serial = @import("../serial/serial.zig");
-const system = @import("../../system/system.zig");
+const memory_const = @import("../../common/constants/memory.zig");
const types = @import("types.zig");
pub const SECTOR_SIZE = ata_limits.SECTOR_SIZE;
-const HIGHER_HALF = system.constants.HIGHER_HALF_START;
+const HIGHER_HALF = memory_const.HIGHER_HALF_START;
+const PAGE_SIZE = memory_const.PAGE_SIZE;
var hba_mem: ?*volatile types.HBAMemory = null;
var port_num: u8 = 0;
@@ -97,8 +98,8 @@ fn rebase_port(port: *volatile types.HBAPort) !void {
const clb_virt = clb_phys + HIGHER_HALF;
const fb_virt = fb_phys + HIGHER_HALF;
- @memset(@as([*]u8, @ptrFromInt(clb_virt))[0..ahci_limits.PAGE_SIZE], 0);
- @memset(@as([*]u8, @ptrFromInt(fb_virt))[0..ahci_limits.PAGE_SIZE], 0);
+ @memset(@as([*]u8, @ptrFromInt(clb_virt))[0..PAGE_SIZE], 0);
+ @memset(@as([*]u8, @ptrFromInt(fb_virt))[0..PAGE_SIZE], 0);
const cmdheader = @as([*]volatile types.CmdHeader, @ptrFromInt(clb_virt));
@@ -109,7 +110,7 @@ fn rebase_port(port: *volatile types.HBAPort) !void {
const cmdtable_phys = pmm.alloc_page() orelse return error.OutOfMemory;
cmdheader[i].ctba = cmdtable_phys;
- @memset(@as([*]u8, @ptrFromInt(cmdtable_phys + HIGHER_HALF))[0..ahci_limits.PAGE_SIZE], 0);
+ @memset(@as([*]u8, @ptrFromInt(cmdtable_phys + HIGHER_HALF))[0..PAGE_SIZE], 0);
}
port.serr = 0xFFFFFFFF;
diff --git a/mirai/hikari/elf/parser.zig b/mirai/hikari/elf/parser.zig
index ac04a50..1ce2f7b 100644
--- a/mirai/hikari/elf/parser.zig
+++ b/mirai/hikari/elf/parser.zig
@@ -1,7 +1,7 @@
//! ELF parser
const elf_const = @import("../../common/constants/elf.zig");
-const system = @import("../../system/system.zig");
+const memory_limits = @import("../../common/limits/memory.zig");
const types = @import("types.zig");
pub fn parse(data: []const u8) !types.Info {
@@ -31,7 +31,7 @@ pub fn parse(data: []const u8) !types.Info {
return error.NotExecutable;
}
- if (!system.is_valid_user_pointer(header.entry)) {
+ if (!memory_limits.is_valid_kata_pointer(header.entry)) {
return error.InvalidEntryPoint;
}
@@ -60,7 +60,7 @@ pub fn parse(data: []const u8) !types.Info {
if (phdr.filesz > phdr.memsz) {
return error.InvalidSegmentSize;
}
- if (!system.is_userspace_range(phdr.vaddr, phdr.memsz)) {
+ if (!memory_limits.is_kata_range(phdr.vaddr, phdr.memsz)) {
return error.SegmentAddressOutOfRange;
}
}
diff --git a/mirai/hikari/loader.zig b/mirai/hikari/loader.zig
index dcf5191..2d33672 100644
--- a/mirai/hikari/loader.zig
+++ b/mirai/hikari/loader.zig
@@ -16,53 +16,53 @@ const multiboot = @import("../boot/multiboot/multiboot.zig");
const paging = @import("../memory/paging.zig");
const sensei = @import("../kata/sensei/sensei.zig");
const serial = @import("../drivers/serial/serial.zig");
-const system = @import("../system/system.zig");
+const fs_limits = @import("../common/limits/fs.zig");
-const INIT_PATH = "/system/akiba/pulse.akibainit";
+const INIT_LOCATION = "/system/akiba/pulse.akibainit";
pub fn init(fs: *afs.AFS(ahci.BlockDevice)) !u32 {
- const init_size = fs.get_unit_size(INIT_PATH) catch |err| {
+ const init_size = fs.get_unit_size(INIT_LOCATION) catch |err| {
serial.print("FATAL: Cannot find init at ");
- serial.print(INIT_PATH);
+ serial.print(INIT_LOCATION);
serial.print("\n");
return err;
};
if (init_size == 0) {
serial.print("FATAL: Init is empty\n");
- return error.EmptyFile;
+ return error.EmptyUnit;
}
- var args: [1][]const u8 = .{INIT_PATH};
- return load_with_args(fs, INIT_PATH, &args);
+ var args: [1][]const u8 = .{INIT_LOCATION};
+ return load_with_args(fs, INIT_LOCATION, &args);
}
-pub fn load(fs: *afs.AFS(ahci.BlockDevice), path: []const u8) !u32 {
- var args: [1][]const u8 = .{path};
- return load_with_args(fs, path, &args);
+pub fn load(fs: *afs.AFS(ahci.BlockDevice), location: []const u8) !u32 {
+ var args: [1][]const u8 = .{location};
+ return load_with_args(fs, location, &args);
}
pub fn load_with_args(
fs: *afs.AFS(ahci.BlockDevice),
- path: []const u8,
+ location: []const u8,
args: []const []const u8,
) !u32 {
- if (path.len == 0 or path.len > system.limits.MAX_PATH_LENGTH) {
- return error.InvalidPath;
+ if (location.len == 0 or location.len > fs_limits.MAX_LOCATION_LENGTH) {
+ return error.InvalidLocation;
}
- const file_size = try fs.get_unit_size(path);
+ const unit_size = try fs.get_unit_size(location);
- if (file_size == 0) return error.EmptyFile;
- if (file_size > system.limits.MAX_FILE_SIZE) return error.FileTooLarge;
+ if (unit_size == 0) return error.EmptyUnit;
+ if (unit_size > fs_limits.MAX_UNIT_SIZE) return error.UnitTooLarge;
- const buffer_ptr = heap.alloc(@intCast(file_size)) orelse return error.OutOfMemory;
- defer heap.free(buffer_ptr, @intCast(file_size));
- const buffer = buffer_ptr[0..@intCast(file_size)];
+ const buffer_ptr = heap.alloc(@intCast(unit_size)) orelse return error.OutOfMemory;
+ defer heap.free(buffer_ptr, @intCast(unit_size));
+ const buffer = buffer_ptr[0..@intCast(unit_size)];
- const bytes_read = try fs.view_unit_at(path, buffer);
+ const bytes_read = try fs.view_unit_at(location, buffer);
- if (bytes_read != file_size) {
+ if (bytes_read != unit_size) {
return error.IncompleteRead;
}
@@ -113,7 +113,7 @@ fn setup_stack_args(kata: *kata_mod.Kata, args: []const []const u8) !u64 {
var stack_top = kata.user_stack_top;
const pc: u64 = args.len;
- var string_addrs: [kata_limits.MAX_ARGS]u64 = undefined;
+ var string_addrs: [kata_limits.MAX_PARAMETERS]u64 = undefined;
for (args, 0..) |arg, i| {
const str_len = arg.len + 1;
diff --git a/mirai/invocations/io/attach.zig b/mirai/invocations/io/attach.zig
index e3dd1f1..24dc154 100644
--- a/mirai/invocations/io/attach.zig
+++ b/mirai/invocations/io/attach.zig
@@ -11,7 +11,7 @@ const heap = @import("../../memory/heap.zig");
const int = @import("../../utils/types/int.zig");
const kata_attachment = @import("../../kata/attachment.zig");
const kata_mod = @import("../../kata/kata.zig");
-const path = @import("../../utils/fs/path.zig");
+const location_util = @import("../../utils/fs/location.zig");
const result = @import("../../utils/types/result.zig");
const sensei = @import("../../kata/sensei/sensei.zig");
const string_copy = @import("../../utils/string/copy.zig");
@@ -32,7 +32,7 @@ pub fn invoke(ctx: *handler.InvocationContext) void {
const location_len = string_copy.from_kata(&location_buf, location_ptr) catch return result.set_error(ctx);
const location = location_buf[0..location_len];
- if (path.is_device(location)) {
+ if (location_util.is_device(location)) {
const fd = open_device(kata, location, flags) catch return result.set_error(ctx);
return result.set_value(ctx, fd);
}
@@ -42,7 +42,7 @@ pub fn invoke(ctx: *handler.InvocationContext) void {
}
fn open_device(kata: *kata_mod.Kata, location: []const u8, flags: u32) !u32 {
- const name = path.device_name(location);
+ const name = location_util.device_name(location);
const device_type: kata_attachment.DeviceType =
if (compare.equals(name, "source")) .Source else if (compare.equals(name, "stream")) .Stream else if (compare.equals(name, "trace")) .Trace else if (compare.equals(name, "void")) .Void else if (compare.equals(name, "chaos")) .Chaos else if (compare.equals(name, "zero")) .Zero else if (compare.equals(name, "console")) .Console else return error.UnknownDevice;
@@ -61,7 +61,7 @@ fn open_unit(kata: *kata_mod.Kata, location: []const u8, flags: u32) !u32 {
const fs = afs_instance orelse return error.NoFilesystem;
var full_location_buf: [512]u8 = undefined;
- const full_location = path.resolve(kata, location, &full_location_buf);
+ const full_location = location_util.resolve(kata, location, &full_location_buf);
const fd = try attachment_util.allocate(kata);
@@ -75,9 +75,9 @@ fn open_unit(kata: *kata_mod.Kata, location: []const u8, flags: u32) !u32 {
.unit_size = 0,
.position = 0,
.flags = flags,
- .path_len = location.len,
+ .location_len = location.len,
};
- copy.bytes(kata.attachments[fd].path[0..location.len], location);
+ copy.bytes(kata.attachments[fd].location[0..location.len], location);
return fd;
}
return error.UnitNotFound;
@@ -92,9 +92,9 @@ fn open_unit(kata: *kata_mod.Kata, location: []const u8, flags: u32) !u32 {
.unit_size = bytes_read,
.position = if (flags & attachment_const.EXTEND != 0) bytes_read else 0,
.flags = flags,
- .path_len = location.len,
+ .location_len = location.len,
};
- copy.bytes(kata.attachments[fd].path[0..location.len], location);
+ copy.bytes(kata.attachments[fd].location[0..location.len], location);
return fd;
}
diff --git a/mirai/invocations/kata/spawn.zig b/mirai/invocations/kata/spawn.zig
index bd02841..051810d 100644
--- a/mirai/invocations/kata/spawn.zig
+++ b/mirai/invocations/kata/spawn.zig
@@ -32,7 +32,7 @@ pub fn invoke(ctx: *handler.InvocationContext) void {
copy.from_ptr(&location_buf, location_ptr, location_len);
const location = location_buf[0..location_len];
- var params: [kata_limits.MAX_ARGS][]const u8 = undefined;
+ var params: [kata_limits.MAX_PARAMETERS][]const u8 = undefined;
var param_count: usize = 1;
params[0] = location;
@@ -40,7 +40,7 @@ pub fn invoke(ctx: *handler.InvocationContext) void {
const pv = slice.typed_ptr_const(u64, pv_ptr);
var i: usize = 1;
- while (i < pc and param_count < kata_limits.MAX_ARGS) : (i += 1) {
+ while (i < pc and param_count < kata_limits.MAX_PARAMETERS) : (i += 1) {
const param_ptr = pv[i];
if (!memory_limits.is_valid_kata_pointer(param_ptr)) break;
diff --git a/mirai/kata/attachment.zig b/mirai/kata/attachment.zig
index 374cfda..05bea8a 100644
--- a/mirai/kata/attachment.zig
+++ b/mirai/kata/attachment.zig
@@ -21,8 +21,8 @@ pub const DeviceType = enum {
pub const Attachment = struct {
attachment_type: Type = .Closed,
- path: [attachment_limits.MAX_PATH_LENGTH]u8 = undefined,
- path_len: usize = 0,
+ location: [attachment_limits.MAX_LOCATION_LENGTH]u8 = undefined,
+ location_len: usize = 0,
position: u64 = 0,
unit_size: u64 = 0,
buffer: ?[]u8 = null,
diff --git a/mirai/kata/memory.zig b/mirai/kata/memory.zig
index 196d702..652c859 100644
--- a/mirai/kata/memory.zig
+++ b/mirai/kata/memory.zig
@@ -1,10 +1,10 @@
//! Kata memory management
const memory_const = @import("../common/constants/memory.zig");
+const memory_limits = @import("../common/limits/memory.zig");
const paging = @import("../memory/paging.zig");
const pmm = @import("../memory/pmm.zig");
const serial = @import("../drivers/serial/serial.zig");
-const system = @import("../system/system.zig");
const types = @import("types.zig");
const HIGHER_HALF = memory_const.HIGHER_HALF_START;
@@ -77,9 +77,9 @@ pub const VirtualBuffer = struct {
pub fn setup(kata: *types.Kata, framebuffer_phys: u64, framebuffer_size: u64) !void {
kata.page_table = try paging.create_page_table();
- const user_stack_base = system.constants.USER_STACK_TOP - (system.constants.USER_STACK_PAGES * PAGE_SIZE);
+ const user_stack_base = memory_const.USER_STACK_TOP - (memory_const.USER_STACK_PAGES * PAGE_SIZE);
- for (0..system.constants.USER_STACK_PAGES) |i| {
+ for (0..memory_const.USER_STACK_PAGES) |i| {
const page = pmm.alloc_page() orelse return error.OutOfMemory;
const virt = user_stack_base + (i * PAGE_SIZE);
_ = try paging.map_page_in_table(kata.page_table, virt, page, paging.PAGE_WRITABLE | paging.PAGE_USER);
@@ -89,15 +89,51 @@ pub fn setup(kata: *types.Kata, framebuffer_phys: u64, framebuffer_size: u64) !v
page_ptr[j] = 0;
}
}
- kata.user_stack_top = system.constants.USER_STACK_TOP;
+ kata.user_stack_top = memory_const.USER_STACK_TOP;
- const kernel_stack_page = pmm.alloc_page() orelse return error.OutOfMemory;
- kata.stack_top = kernel_stack_page + HIGHER_HALF + system.constants.KERNEL_STACK_SIZE;
+ // Allocate kernel stack pages - must be contiguous for identity mapping
+ const first_page = pmm.alloc_page() orelse return error.OutOfMemory;
+ const kernel_stack_base = first_page;
+
+ // Identity map first page
+ _ = try paging.map_page_in_table(kata.page_table, first_page, first_page, paging.PAGE_WRITABLE);
+
+ // Zero the page
+ var page_ptr: [*]volatile u8 = @ptrFromInt(first_page + HIGHER_HALF);
+ for (0..PAGE_SIZE) |j| {
+ page_ptr[j] = 0;
+ }
+
+ // Allocate remaining pages, checking for contiguity
+ var i: u64 = 1;
+ while (i < memory_const.KERNEL_STACK_PAGES) : (i += 1) {
+ const page = pmm.alloc_page() orelse return error.OutOfMemory;
+ const expected = first_page + (i * PAGE_SIZE);
+
+ if (page != expected) {
+ // Non-contiguous - free what we got and use smaller stack
+ pmm.free_page(page);
+ break;
+ }
+
+ // Identity map this page
+ _ = try paging.map_page_in_table(kata.page_table, page, page, paging.PAGE_WRITABLE);
+
+ // Zero the page
+ page_ptr = @ptrFromInt(page + HIGHER_HALF);
+ for (0..PAGE_SIZE) |j| {
+ page_ptr[j] = 0;
+ }
+ }
+
+ // Stack top is at the end of allocated contiguous pages
+ const actual_stack_size = i * PAGE_SIZE;
+ kata.stack_top = kernel_stack_base + HIGHER_HALF + actual_stack_size;
if (framebuffer_phys != 0 and framebuffer_size > 0) {
const fb_pages = (framebuffer_size + PAGE_SIZE - 1) / PAGE_SIZE;
- for (0..fb_pages) |i| {
- const phys = framebuffer_phys + (i * PAGE_SIZE);
+ for (0..fb_pages) |fi| {
+ const phys = framebuffer_phys + (fi * PAGE_SIZE);
_ = try paging.map_page_in_table(
kata.page_table,
phys,
@@ -111,17 +147,17 @@ pub fn setup(kata: *types.Kata, framebuffer_phys: u64, framebuffer_size: u64) !v
pub fn load_segment(
kata: *types.Kata,
vaddr: u64,
- file_data: []const u8,
- file_offset: u64,
- file_size: u64,
+ elf_data: []const u8,
+ data_offset: u64,
+ data_size: u64,
mem_size: u64,
flags: u32,
) !void {
if (mem_size == 0) return;
- if (file_size > mem_size) return error.InvalidSegment;
- if (file_offset + file_size > file_data.len) return error.SegmentOutOfBounds;
+ if (data_size > mem_size) return error.InvalidSegment;
+ if (data_offset + data_size > elf_data.len) return error.SegmentOutOfBounds;
- if (!system.is_userspace_range(vaddr, mem_size)) {
+ if (!memory_limits.is_kata_range(vaddr, mem_size)) {
return error.InvalidAddress;
}
@@ -166,13 +202,13 @@ pub fn load_segment(
const page_offset = if (i == 0) offset_in_page else 0;
const segment_pos: u64 = if (i == 0) 0 else (i * PAGE_SIZE - offset_in_page);
- if (segment_pos < file_size) {
- const bytes_remaining = file_size - segment_pos;
+ if (segment_pos < data_size) {
+ const bytes_remaining = data_size - segment_pos;
const bytes_to_copy = @min(PAGE_SIZE - page_offset, bytes_remaining);
- const file_pos = file_offset + segment_pos;
+ const elf_pos = data_offset + segment_pos;
- if (file_pos + bytes_to_copy <= file_data.len) {
- const src = file_data[file_pos .. file_pos + bytes_to_copy];
+ if (elf_pos + bytes_to_copy <= elf_data.len) {
+ const src = elf_data[elf_pos .. elf_pos + bytes_to_copy];
for (0..bytes_to_copy) |k| {
dest_ptr[page_offset + k] = src[k];
diff --git a/mirai/utils/fs/location.zig b/mirai/utils/fs/location.zig
index 8a2d39c..a0a75ad 100644
--- a/mirai/utils/fs/location.zig
+++ b/mirai/utils/fs/location.zig
@@ -3,8 +3,11 @@
const afs = @import("../../fs/afs/afs.zig");
const ahci = @import("../../drivers/ahci/ahci.zig");
const compare = @import("../string/compare.zig");
+const kata_mod = @import("../../kata/kata.zig");
const fs_limits = @import("../../common/limits/fs.zig");
+const DEVICE_PREFIX = "/system/devices/";
+
pub fn resolve_to_cluster(
fs: *afs.AFS(ahci.BlockDevice),
location: []const u8,
@@ -127,3 +130,33 @@ fn process_components(result: *Canonical, location: []const u8) void {
}
}
}
+
+pub fn resolve(kata: *kata_mod.Kata, location: []const u8, buffer: []u8) []const u8 {
+ if (location.len > 0 and location[0] == '/') {
+ @memcpy(buffer[0..location.len], location);
+ return buffer[0..location.len];
+ }
+
+ const cwd = kata.current_location[0..kata.current_location_len];
+ var len: usize = cwd.len;
+
+ @memcpy(buffer[0..cwd.len], cwd);
+
+ if (cwd[cwd.len - 1] != '/') {
+ buffer[len] = '/';
+ len += 1;
+ }
+
+ @memcpy(buffer[len .. len + location.len], location);
+ len += location.len;
+
+ return buffer[0..len];
+}
+
+pub fn is_device(location: []const u8) bool {
+ return compare.starts_with(location, DEVICE_PREFIX);
+}
+
+pub fn device_name(location: []const u8) []const u8 {
+ return location[DEVICE_PREFIX.len..];
+}
diff --git a/mirai/utils/fs/path.zig b/mirai/utils/fs/path.zig
deleted file mode 100644
index b0df6f6..0000000
--- a/mirai/utils/fs/path.zig
+++ /dev/null
@@ -1,36 +0,0 @@
-//! Path utilities
-
-const kata_mod = @import("../../kata/kata.zig");
-const compare = @import("../string/compare.zig");
-
-const DEVICE_PREFIX = "/system/devices/";
-
-pub fn resolve(kata: *kata_mod.Kata, path: []const u8, buffer: []u8) []const u8 {
- if (path.len > 0 and path[0] == '/') {
- @memcpy(buffer[0..path.len], path);
- return buffer[0..path.len];
- }
-
- const cwd = kata.current_location[0..kata.current_location_len];
- var len: usize = cwd.len;
-
- @memcpy(buffer[0..cwd.len], cwd);
-
- if (cwd[cwd.len - 1] != '/') {
- buffer[len] = '/';
- len += 1;
- }
-
- @memcpy(buffer[len .. len + path.len], path);
- len += path.len;
-
- return buffer[0..len];
-}
-
-pub fn is_device(path: []const u8) bool {
- return compare.starts_with(path, DEVICE_PREFIX);
-}
-
-pub fn device_name(path: []const u8) []const u8 {
- return path[DEVICE_PREFIX.len..];
-}
diff --git a/mirai/utils/kata/attachment.zig b/mirai/utils/kata/attachment.zig
index 11f1cdf..2798fc7 100644
--- a/mirai/utils/kata/attachment.zig
+++ b/mirai/utils/kata/attachment.zig
@@ -7,7 +7,7 @@ const fd_mod = @import("../../kata/attachment.zig");
const heap = @import("../../memory/heap.zig");
const kata_limits = @import("../../common/limits/kata.zig");
const kata_mod = @import("../../kata/kata.zig");
-const path = @import("../fs/path.zig");
+const location_util = @import("../fs/location.zig");
pub fn allocate(kata: *kata_mod.Kata) !u32 {
var i: u32 = 3;
@@ -26,7 +26,7 @@ pub fn seal(kata: *kata_mod.Kata, fd: u32, fs: ?*afs.AFS(ahci.BlockDevice)) void
if (entry.buffer) |buffer| {
if (fs) |filesystem| {
var full_location_buf: [512]u8 = undefined;
- const full_location = path.resolve(kata, entry.path[0..entry.path_len], &full_location_buf);
+ const full_location = location_util.resolve(kata, entry.location[0..entry.location_len], &full_location_buf);
filesystem.mark_unit(full_location, buffer) catch {};
}
heap.free(@ptrCast(buffer.ptr), buffer.len);
diff --git a/system/ash/ash.zig b/system/ash/ash.zig
index 5149ab8..203becc 100644
--- a/system/ash/ash.zig
+++ b/system/ash/ash.zig
@@ -8,7 +8,7 @@ const string = @import("string");
const sys = @import("sys");
const MAX_INPUT = 256;
-const MAX_ARGS = 16;
+const MAX_PARAMETERS = 16;
var input_buffer: [MAX_INPUT]u8 = undefined;
var input_len: usize = 0;
@@ -16,8 +16,8 @@ var char_buffer: [1]u8 = undefined;
var location_buffer: [256]u8 = undefined;
var letter_buffer: [256]u8 = undefined;
-var arg_ptrs: [MAX_ARGS][*:0]const u8 = undefined;
-var arg_storage: [MAX_ARGS][128]u8 = undefined;
+var param_ptrs: [MAX_PARAMETERS][*:0]const u8 = undefined;
+var param_storage: [MAX_PARAMETERS][128]u8 = undefined;
export fn main(pc: u32, pv: [*]const [*:0]const u8) u8 {
_ = pc;
@@ -60,10 +60,10 @@ export fn main(pc: u32, pv: [*]const [*:0]const u8) u8 {
}
fn execute_command(input: []const u8) void {
- var argc: usize = 0;
+ var param_count: usize = 0;
var i: usize = 0;
- while (i < input.len and argc < MAX_ARGS) {
+ while (i < input.len and param_count < MAX_PARAMETERS) {
while (i < input.len and input[i] == ' ') : (i += 1) {}
if (i >= input.len) break;
@@ -72,26 +72,26 @@ fn execute_command(input: []const u8) void {
const end = i;
if (end > start) {
- const arg_len = end - start;
- if (arg_len < 127) {
+ const param_len = end - start;
+ if (param_len < 127) {
for (input[start..end], 0..) |c, j| {
- arg_storage[argc][j] = c;
+ param_storage[param_count][j] = c;
}
- arg_storage[argc][arg_len] = 0;
- arg_ptrs[argc] = @ptrCast(&arg_storage[argc]);
- argc += 1;
+ param_storage[param_count][param_len] = 0;
+ param_ptrs[param_count] = @ptrCast(&param_storage[param_count]);
+ param_count += 1;
}
}
}
- if (argc == 0) return;
+ if (param_count == 0) return;
- const cmd = arg_storage[0][0..string.findNull(&arg_storage[0])];
+ const cmd = param_storage[0][0..string.findNull(&param_storage[0])];
- var path_buf: [512]u8 = undefined;
- const path = string.concat3(&path_buf, "/binaries/", cmd, ".akiba");
+ var location_buf: [512]u8 = undefined;
+ const location = string.concat3(&location_buf, "/binaries/", cmd, ".akiba");
- if (try_spawn_with_args(path, arg_ptrs[0..argc])) {
+ if (try_spawn_with_params(location, param_ptrs[0..param_count])) {
process_letters();
return;
}
@@ -101,8 +101,8 @@ fn execute_command(input: []const u8) void {
format.println(".");
}
-fn try_spawn_with_args(path: []const u8, argv: [][*:0]const u8) bool {
- const pid = kata.spawnWithArgs(path, argv) catch {
+fn try_spawn_with_params(location: []const u8, params: [][*:0]const u8) bool {
+ const pid = kata.spawnWithParams(location, params) catch {
return false;
};
diff --git a/system/libraries/io/attachment.zig b/system/libraries/io/attachment.zig
index c68adf8..4672fec 100644
--- a/system/libraries/io/attachment.zig
+++ b/system/libraries/io/attachment.zig
@@ -5,28 +5,28 @@ const types = @import("types.zig");
const ERROR_RESULT: u64 = @bitCast(@as(i64, -1));
-pub fn attach(path: []const u8, flags: u32) types.Error!types.FileDescriptor {
- const result = sys.syscall(.attach, .{ @intFromPtr(path.ptr), flags });
+pub fn attach(location: []const u8, flags: u32) types.Error!types.Descriptor {
+ const result = sys.syscall(.attach, .{ @intFromPtr(location.ptr), flags });
if (result == ERROR_RESULT) {
return types.Error.NotFound;
}
return @truncate(result);
}
-pub fn seal(fd: types.FileDescriptor) void {
+pub fn seal(fd: types.Descriptor) void {
_ = sys.syscall(.seal, .{fd});
}
-pub fn viewstack(path: []const u8, entries: []types.StackEntry) types.Error!usize {
+pub fn viewstack(location: []const u8, entries: []types.StackEntry) types.Error!usize {
const result = sys.syscall(.viewstack, .{
- @intFromPtr(path.ptr),
- path.len,
+ @intFromPtr(location.ptr),
+ location.len,
@intFromPtr(entries.ptr),
entries.len,
});
if (result == ERROR_RESULT) {
- return types.Error.InvalidPath;
+ return types.Error.InvalidLocation;
}
return @intCast(result);
diff --git a/system/libraries/io/io.zig b/system/libraries/io/io.zig
index 588ff0c..f7c0da3 100644
--- a/system/libraries/io/io.zig
+++ b/system/libraries/io/io.zig
@@ -22,7 +22,7 @@ pub const sendLetter = letter.send;
pub const readLetter = letter.read;
pub const StackEntry = types.StackEntry;
-pub const FileDescriptor = types.FileDescriptor;
+pub const Descriptor = types.Descriptor;
pub const Letter = types.Letter;
pub const Error = types.Error;
diff --git a/system/libraries/io/location.zig b/system/libraries/io/location.zig
index 37d3115..0f1e114 100644
--- a/system/libraries/io/location.zig
+++ b/system/libraries/io/location.zig
@@ -18,13 +18,13 @@ pub fn get(buffer: []u8) types.Error![]u8 {
return buffer[0..@intCast(result)];
}
-pub fn set(path: []const u8) types.Error!void {
+pub fn set(location: []const u8) types.Error!void {
const result = sys.syscall(.setlocation, .{
- @intFromPtr(path.ptr),
- path.len,
+ @intFromPtr(location.ptr),
+ location.len,
});
if (result == ERROR_RESULT) {
- return types.Error.InvalidPath;
+ return types.Error.InvalidLocation;
}
}
diff --git a/system/libraries/io/stream.zig b/system/libraries/io/stream.zig
index 7f93c9d..8e65473 100644
--- a/system/libraries/io/stream.zig
+++ b/system/libraries/io/stream.zig
@@ -7,7 +7,7 @@ const types = @import("types.zig");
const ERROR_RESULT: u64 = @bitCast(@as(i64, -1));
const EAGAIN_RESULT: u64 = @bitCast(@as(i64, -2));
-pub fn view(fd: types.FileDescriptor, buffer: []u8) types.Error!usize {
+pub fn view(fd: types.Descriptor, buffer: []u8) types.Error!usize {
const result = sys.syscall(.view, .{ fd, @intFromPtr(buffer.ptr), buffer.len });
if (result == ERROR_RESULT) {
return types.Error.ReadFailed;
@@ -15,7 +15,7 @@ pub fn view(fd: types.FileDescriptor, buffer: []u8) types.Error!usize {
return result;
}
-pub fn mark(fd: types.FileDescriptor, data: []const u8, color: u32) types.Error!usize {
+pub fn mark(fd: types.Descriptor, data: []const u8, color: u32) types.Error!usize {
const result = sys.syscall(.mark, .{ fd, @intFromPtr(data.ptr), data.len, color });
if (result == ERROR_RESULT) {
return types.Error.WriteFailed;
diff --git a/system/libraries/io/types.zig b/system/libraries/io/types.zig
index d2ddb91..1b4336b 100644
--- a/system/libraries/io/types.zig
+++ b/system/libraries/io/types.zig
@@ -6,16 +6,16 @@ pub const Error = error{
InvalidDescriptor,
ReadFailed,
WriteFailed,
- InvalidPath,
+ InvalidLocation,
SendFailed,
GetLocationFailed,
};
-pub const FileDescriptor = u32;
+pub const Descriptor = u32;
-pub const source: FileDescriptor = 0;
-pub const stream: FileDescriptor = 1;
-pub const trace: FileDescriptor = 2;
+pub const source: Descriptor = 0;
+pub const stream: Descriptor = 1;
+pub const trace: Descriptor = 2;
pub const VIEW_ONLY: u32 = 0x01;
pub const MARK_ONLY: u32 = 0x02;
diff --git a/system/libraries/kata/kata.zig b/system/libraries/kata/kata.zig
index 951a742..39f4556 100644
--- a/system/libraries/kata/kata.zig
+++ b/system/libraries/kata/kata.zig
@@ -18,16 +18,16 @@ pub fn exit(code: u64) noreturn {
unreachable;
}
-pub fn spawn(path: []const u8) Error!u32 {
- const result = sys.syscall(.spawn, .{ @intFromPtr(path.ptr), path.len, @as(u64, 0), @as(u64, 0) });
+pub fn spawn(location: []const u8) Error!u32 {
+ const result = sys.syscall(.spawn, .{ @intFromPtr(location.ptr), location.len, @as(u64, 0), @as(u64, 0) });
if (result == ERROR_RESULT) {
return Error.SpawnFailed;
}
return @truncate(result);
}
-pub fn spawnWithArgs(path: []const u8, argv: [][*:0]const u8) Error!u32 {
- const result = sys.syscall(.spawn, .{ @intFromPtr(path.ptr), path.len, @intFromPtr(argv.ptr), argv.len });
+pub fn spawnWithParams(location: []const u8, params: [][*:0]const u8) Error!u32 {
+ const result = sys.syscall(.spawn, .{ @intFromPtr(location.ptr), location.len, @intFromPtr(params.ptr), params.len });
if (result == ERROR_RESULT) {
return Error.SpawnFailed;
}