diff options
author | Himbeer <himbeer@disroot.org> | 2024-05-11 21:24:34 +0200 |
---|---|---|
committer | Himbeer <himbeer@disroot.org> | 2024-05-11 21:24:34 +0200 |
commit | bc5211222c243fe37b7122fe294ba52649b4e601 (patch) | |
tree | 5552c3036631440f4b5ffe3e949e1b46e0c3040e /src | |
parent | 5986745bf0a9712b18643cfa41e4c33c9ee30a7f (diff) |
plic: Fix invalid context pointer alignment
Diffstat (limited to 'src')
-rw-r--r-- | src/plic.zig | 7 |
1 files changed, 4 insertions, 3 deletions
diff --git a/src/plic.zig b/src/plic.zig index 7ba6522..3529cb2 100644 --- a/src/plic.zig +++ b/src/plic.zig @@ -17,7 +17,6 @@ pub const Error = error{ }; pub const Context = packed struct { - reserved: u32, priority_threshold: u32, claim: u32, }; @@ -28,7 +27,7 @@ pub const Plic = struct { const priority_offset = 0x4; const enable_offset = 0x2000; const context_offset_zero = 0x200000; - const context_offset_nonzero = 0x200ffc; + const context_offset_nonzero = 0x201000; pub const num_contexts = 15872; @@ -98,7 +97,9 @@ pub const Plic = struct { return @alignCast(@ptrCast(&mmio_slice[context_offset_zero])); } else { const context_offset: usize = context - 1; - return @alignCast(@ptrCast(&mmio_slice[context_offset_nonzero + context_offset * @sizeOf(Context)])); + const ptr_offset = context_offset * (@sizeOf(u32) + @sizeOf(Context)); + const context_ptr = &mmio_slice[context_offset_nonzero + ptr_offset]; + return @alignCast(@ptrCast(context_ptr)); } } }; |