Skip to content
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
4 changes: 2 additions & 2 deletions dev_build.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ def main():
if not BUILD_DIR.exists():
BUILD_DIR.mkdir()

tool_rebuild = f"cd {CWD / 'tool/microkit'} && cargo build --release"
tool_rebuild = f"cd {CWD / 'tool/microkit'} && cargo build"
r = system(tool_rebuild)
assert r == 0

Expand All @@ -90,7 +90,7 @@ def main():
make_env["MICROKIT_BOARD"] = args.board
make_env["MICROKIT_CONFIG"] = args.config
make_env["MICROKIT_SDK"] = str(release)
make_env["MICROKIT_TOOL"] = (CWD / "tool/microkit/target/release/microkit").absolute()
make_env["MICROKIT_TOOL"] = (CWD / "tool/microkit/target/debug/microkit").absolute()
make_env["LLVM"] = str(args.llvm)

# Choose the makefile based on the `--example-from-sdk` command line flag
Expand Down
14 changes: 8 additions & 6 deletions libmicrokit/src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -18,20 +18,22 @@
#define PD_MASK 0xff
#define CHANNEL_MASK 0x3f

#define SECTION(sec) __attribute__((__section__(sec)))

/* All globals are prefixed with microkit_* to avoid clashes with user defined globals. */

bool microkit_passive;
char microkit_name[MICROKIT_PD_NAME_LENGTH];
bool microkit_passive SECTION(".data.patched");
char microkit_name[MICROKIT_PD_NAME_LENGTH] SECTION(".data.patched");
/* We use seL4 typedefs as this variable is exposed to the libmicrokit header
* and we do not want to rely on compiler built-in defines. */
seL4_Bool microkit_have_signal = seL4_False;
seL4_CPtr microkit_signal_cap;
seL4_MessageInfo_t microkit_signal_msg;

seL4_Word microkit_irqs;
seL4_Word microkit_notifications;
seL4_Word microkit_pps;
seL4_Word microkit_ioports;
seL4_Word microkit_irqs SECTION(".data.patched");
seL4_Word microkit_notifications SECTION(".data.patched");
seL4_Word microkit_pps SECTION(".data.patched");
seL4_Word microkit_ioports SECTION(".data.patched");

extern seL4_IPCBuffer __sel4_ipc_buffer_obj;

Expand Down
9 changes: 9 additions & 0 deletions loader/src/cutil.c
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,14 @@ void *memcpy(void *dst, const void *src, size_t sz)
return dst;
}

void memzero(void *dst, size_t sz)
{
char *dst_ = dst;
for (size_t i = 0; i < sz; i++) {
dst_[i] = 0x0;
}
}

void *memmove(void *restrict dest, const void *restrict src, size_t n)
{
unsigned char *d = (unsigned char *)dest;
Expand All @@ -44,3 +52,4 @@ void *memmove(void *restrict dest, const void *restrict src, size_t n)

return dest;
}

2 changes: 2 additions & 0 deletions loader/src/cutil.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,6 @@

void *memcpy(void *dst, const void *src, size_t sz);

void memzero(void *dst, size_t sz);

void *memmove(void *restrict dest, const void *restrict src, size_t n);
11 changes: 8 additions & 3 deletions loader/src/loader.c
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,10 @@ static void print_loader_data(void)
puthex32(i);
puts(" addr: ");
puthex64(r->load_addr);
puts(" size: ");
puthex64(r->size);
puts(" file size: ");
puthex64(r->file_size);
puts(" memory size: ");
puthex64(r->memory_size);
puts(" offset: ");
puthex64(r->offset);
puts(" type: ");
Expand All @@ -102,7 +104,10 @@ static void copy_data(void)
puts("LDR|INFO: copying region ");
puthex32(i);
puts("\n");
memcpy((void *)(uintptr_t)r->load_addr, base + r->offset, r->size);
memcpy((void *)(uintptr_t)r->load_addr, base + r->offset, r->file_size);

// we are guaranteed by the microkit tool that memory_size >= file_size
memzero((void *)(r->load_addr + r->file_size), r->memory_size - r->file_size);
}
}

Expand Down
5 changes: 4 additions & 1 deletion loader/src/loader.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,10 @@

struct region {
uintptr_t load_addr;
uintptr_t size;
// The size of this region in the loader data 'file'
uintptr_t file_size;
// The size of this region in memory, zero-padded
uintptr_t memory_size;
uintptr_t offset;
uintptr_t type;
};
Expand Down
13 changes: 8 additions & 5 deletions monitor/src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -50,16 +50,19 @@
#define BASE_SCHED_CONTEXT_CAP 138
#define BASE_NOTIFICATION_CAP 202

#define SECTION(sec) __attribute__((__section__(sec)))
#define UNUSED __attribute__((unused))

extern seL4_IPCBuffer __sel4_ipc_buffer_obj;
seL4_IPCBuffer *__sel4_ipc_buffer = &__sel4_ipc_buffer_obj;

char pd_names[MAX_PDS][MAX_NAME_LEN];
seL4_Word pd_names_len;
char vm_names[MAX_VMS][MAX_NAME_LEN] __attribute__((unused));
seL4_Word vm_names_len;
char pd_names[MAX_PDS][MAX_NAME_LEN] SECTION(".data.patched");
seL4_Word pd_names_len SECTION(".data.patched");
char vm_names[MAX_VMS][MAX_NAME_LEN] SECTION(".data.patched") UNUSED;
seL4_Word vm_names_len SECTION(".data.patched");

/* For reporting potential stack overflows, keep track of the stack regions for each PD. */
seL4_Word pd_stack_bottom_addrs[MAX_PDS];
seL4_Word pd_stack_bottom_addrs[MAX_PDS] SECTION(".data.patched");

/* Sanity check that the architecture specific macro have been set. */
#if defined(ARCH_aarch64)
Expand Down
13 changes: 4 additions & 9 deletions tool/microkit/src/capdl/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -176,19 +176,14 @@ impl CapDLSpec {
// For each loadable segment in the ELF, map it into the address space of this PD.
let mut frame_sequence = 0; // For object naming purpose only.
for (seg_idx, segment) in elf.loadable_segments().iter().enumerate() {
if segment.data().is_empty() {
continue;
}

let seg_base_vaddr = segment.virt_addr;
let seg_mem_size: u64 = segment.mem_size();

let page_size = PageSize::Small;
let page_size_bytes = page_size as u64;

// Create and map all frames for this segment.
let mut cur_vaddr = round_down(seg_base_vaddr, page_size_bytes);
while cur_vaddr < seg_base_vaddr + seg_mem_size {
while cur_vaddr < seg_base_vaddr + segment.memory_size {
let mut frame_init_maybe: Option<FrameInit> = None;

// Now compute the ELF file offset to fill in this page.
Expand All @@ -203,10 +198,10 @@ impl CapDLSpec {

let target_vaddr_start = cur_vaddr + dest_offset;
let section_offset = target_vaddr_start - seg_base_vaddr;
if section_offset < seg_mem_size {
if section_offset < segment.memory_size {
// We have data to load
let len_to_cpy =
min(page_size_bytes - dest_offset, seg_mem_size - section_offset);
min(page_size_bytes - dest_offset, segment.memory_size - section_offset);

frame_init_maybe = Some(FrameInit::Fill(Fill {
entries: [FillEntry {
Expand Down Expand Up @@ -581,7 +576,7 @@ pub fn build_capdl_spec(

for elf_seg in elf_obj.loadable_segments().iter() {
let elf_seg_vaddr_range = elf_seg.virt_addr
..elf_seg.virt_addr + round_up(elf_seg.mem_size(), PageSize::Small as u64);
..elf_seg.virt_addr + round_up(elf_seg.memory_size, PageSize::Small as u64);
if ranges_overlap(&mr_vaddr_range, &elf_seg_vaddr_range) {
return Err(format!("ERROR: mapping MR '{}' to PD '{}' with vaddr [0x{:x}..0x{:x}) will overlap with an ELF segment at [0x{:x}..0x{:x})", map.mr, pd.name, mr_vaddr_range.start, mr_vaddr_range.end, elf_seg_vaddr_range.start, elf_seg_vaddr_range.end));
}
Expand Down
18 changes: 9 additions & 9 deletions tool/microkit/src/capdl/initialiser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@

use std::ops::Range;

use crate::elf::ElfSegmentData;
use crate::util::round_up;
use crate::{elf::ElfFile, sel4::PageSize};
use crate::{serialise_ut, UntypedObject};
Expand All @@ -16,7 +15,7 @@ use crate::{serialise_ut, UntypedObject};
pub const DEFAULT_INITIALISER_HEAP_MULTIPLIER: f64 = 2.0;
const INITIALISER_HEAP_ADD_ON_CONSTANT: u64 = 64 * 4096;
// Page size used for allocating the spec and heap segments.
pub const INITIALISER_GRANULE_SIZE: PageSize = PageSize::Small;
pub const INITIALISER_PAGE_SIZE: PageSize = PageSize::Small;

pub struct CapDLInitialiserSpecMetadata {
pub spec_size: u64,
Expand All @@ -41,22 +40,23 @@ impl CapDLInitialiser {
}

pub fn image_bound(&self) -> Range<u64> {
self.elf.lowest_vaddr()..round_up(self.elf.highest_vaddr(), INITIALISER_GRANULE_SIZE as u64)
self.elf.lowest_vaddr()..round_up(self.elf.highest_vaddr(), INITIALISER_PAGE_SIZE as u64)
}

pub fn add_spec(&mut self, payload: Vec<u8>) {
if self.spec_metadata.is_some() {
unreachable!("internal bug: CapDLInitialiser::add_spec() called more than once");
}

let spec_vaddr = self.elf.next_vaddr(INITIALISER_GRANULE_SIZE);
let spec_vaddr = self.elf.next_vaddr(INITIALISER_PAGE_SIZE);
let spec_size = payload.len() as u64;
self.elf.add_segment(
true,
false,
false,
spec_vaddr,
ElfSegmentData::RealData(payload),
spec_size,
payload,
);

// These symbol names must match rust-sel4/crates/sel4-capdl-initializer/src/main.rs
Expand All @@ -73,18 +73,18 @@ impl CapDLInitialiser {
)
.unwrap();

// Very important to make the heap the last region in memory so we can optimise the bootable image size later.
let heap_vaddr = self.elf.next_vaddr(INITIALISER_GRANULE_SIZE);
let heap_vaddr = self.elf.next_vaddr(INITIALISER_PAGE_SIZE);
let heap_size = round_up(
(spec_size as f64 * self.heap_multiplier) as u64 + INITIALISER_HEAP_ADD_ON_CONSTANT,
INITIALISER_GRANULE_SIZE as u64,
INITIALISER_PAGE_SIZE as u64,
);
self.elf.add_segment(
true,
true,
false,
heap_vaddr,
ElfSegmentData::UninitialisedData(heap_size),
heap_size,
vec![],
);
self.elf
.write_symbol(
Expand Down
2 changes: 1 addition & 1 deletion tool/microkit/src/capdl/packaging.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ fn reserialise_spec(
.segments
.get(data.elf_seg_idx)
.unwrap()
.data()[data.elf_seg_data_range.clone()],
.data[data.elf_seg_data_range.clone()],
)),
});

Expand Down
Loading
Loading