Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RV32 Memory Protection #14

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/kernel/components/memory/protection.zig
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ pub fn change(range: Range, protection: Protection) void {
std.debug.assert(std.mem.isAligned(range.base, page_size));
std.debug.assert(std.mem.isAligned(range.length, page_size));

log.debug("Change 0x{X:0>8}+0x{X:0>8} to {s}", .{
log.info("Change 0x{X:0>8}+0x{X:0>8} to {s}", .{
range.base, range.length, @tagName(protection),
});

Expand Down
5 changes: 5 additions & 0 deletions src/kernel/main.zig
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,11 @@ fn main() !void {
log.info("initialize memory protection...", .{});
try memory.protection.initialize();

const page = try memory.page_allocator.alloc(u8, 4096);
log.warn("here!", .{});
memory.protection.change(memory.Range.from_slice(page), .read_only);
page[0] = 0;

// Initialize the entropy pool so it can begin gathering bits
// for critical start-up applications. The pool needs at least
// some amount of hardware entropy to be safe to use in later
Expand Down
11 changes: 7 additions & 4 deletions src/kernel/port/machine/rv32_virt/linker.ld
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,17 @@ SECTIONS {
*(.text._start)
*(.text)
*(.text.*)
. = ALIGN(4096);
} > flash

.rodata : {
. = ALIGN(4);
*(.rodata)
*(.rodata.*)
. = ALIGN(4096);
} > flash

. = ALIGN(4);
. = ALIGN(4096);

__kernel_flash_end = . ;

Expand All @@ -43,23 +45,24 @@ SECTIONS {
*(.sdata)
*(.sdata.*)

. = ALIGN(4);
. = ALIGN(4096);
__kernel_data_end = .;
} > dram


.bss (NOLOAD) : {
. = ALIGN(4096);
__kernel_bss_start = .;

*(.bss)
*(.bss.*)
*(.sbss)
*(.sbss.*)

. = ALIGN(4);
. = ALIGN(4096);
__kernel_bss_end = .;

. = ALIGN(4096);

__machine_linmem_start = .;
} > dram

Expand Down
8 changes: 7 additions & 1 deletion src/kernel/port/machine/rv32_virt/rv32_virt.zig
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,13 @@ const VPBA_UART_BASE = 0x10000000;

pub const machine_config = ashet.ports.MachineConfig{
.load_sections = .{ .data = true, .bss = true },
.memory_protection = null, // TODO: No memory protection on RISC-V yet!
.memory_protection = .{
.initialize = rv32.vmm.initialize,
.update = rv32.vmm.update,
.activate = rv32.vmm.activate,
.get_protection = rv32.vmm.get_protection,
.get_info = rv32.vmm.query_address,
},
};

const virtio_config = ashet.drivers.VirtIoConfiguration{
Expand Down
Loading