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

[patches-axel] #7

Draft
wants to merge 25 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
fcabdef
CI: use proper step name
Apr 4, 2024
cf1982c
WIP libsel4platsupport: debug log
axel-h Jun 28, 2022
ad1be47
Merge patch-axel-8
axel-h Apr 15, 2024
2d73fd0
libsel4utils: add sel4utils_set_arg0 for RISC-V
axel-h May 9, 2020
a7d6613
style: remove empty line
axel-h Apr 6, 2023
3e78cd2
use proper printf format specifiers
axel-h Jan 2, 2022
52fb382
print slots for extra boot info pages
axel-h May 24, 2022
4c279fe
print more information and memory map
axel-h May 24, 2022
39bb115
libsel4utils: use proper types for printing
axel-h Nov 26, 2021
b59ec81
Merge patch-axel-6
axel-h Apr 15, 2024
d3ed8ca
libsel4platsupport: use ZF_LOGE() instead of printf()
axel-h Jan 12, 2024
15bdb11
libsel4platsupport: define USE_DEBUG_PUTCHAR
axel-h Jan 12, 2024
218e3d8
libsel4platsupport: cleanup __serial_setup()
axel-h Jan 12, 2024
7fdbec2
libsel4platsupport: inline things into __map_device_page()
axel-h Jan 12, 2024
6e14884
libsel4platsupport: add unrechable marker
axel-h Jan 12, 2024
a7a1351
libsel4platsupport: always clear vka
axel-h Feb 22, 2024
1844f3f
libsel4platsupport: use switch/case
axel-h Feb 22, 2024
30de680
libsel4platsupport: add global context
axel-h Feb 22, 2024
5a6850f
libsel4platsupport: inline io_ops
axel-h Feb 22, 2024
9059b21
Merge patch-axel-3
axel-h Apr 15, 2024
99ed01e
libsel4allocman: simplify code
axel-h Apr 12, 2024
55b4963
libsel4allocman: add error check
axel-h Apr 12, 2024
96cb46f
libsel4allocman: inline loop variable
axel-h Nov 3, 2023
070911a
libsel4allocman: cleanup
axel-h Apr 12, 2024
fb49721
Merge patch-axel-12
axel-h Apr 15, 2024
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 .github/workflows/sel4test-sim.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ concurrency:
cancel-in-progress: ${{ github.event_name == 'pull_request' }}

jobs:
cparser:
simulation:
name: Simulation
runs-on: ubuntu-latest
strategy:
Expand Down
39 changes: 22 additions & 17 deletions libsel4allocman/src/bootstrap.c
Original file line number Diff line number Diff line change
Expand Up @@ -227,13 +227,19 @@ int bootstrap_add_untypeds_from_bootinfo(bootstrap_info_t *bs, seL4_BootInfo *bi

static int bootstrap_add_untypeds_from_simple(bootstrap_info_t *bs, simple_t *simple) {
int error;
int i;
/* if we do not have a boot cspace, or we have added some uts that aren't in the
* current space then just bail */
if (!bs->have_boot_cspace || (bs->uts && !bs->uts_in_current_cspace)) {
return 1;
}
for (i = 0; i < simple_get_untyped_count(simple); i++) {

int cnt = simple_get_untyped_count(simple);
if (cnt < 0) {
ZF_LOGW("Could not get untyped count (%d)", cnt);
return 1;
}

for (int i = 0; i < cnt; i++) {
size_t size_bits;
uintptr_t paddr;
bool device;
Expand Down Expand Up @@ -1005,10 +1011,7 @@ static int handle_device_untyped_cap(add_untypeds_state_t *state, uintptr_t padd
bool cap_tainted = false;
int error;
uintptr_t ut_end = paddr + BIT(size_bits);
int num_regions = 0;
if (state != NULL) {
num_regions = state->num_regions;
}
int num_regions = state ? state->num_regions : 0;
for (int i = 0; i < num_regions; i++) {
pmem_region_t *region = &state->regions[i];
uint64_t region_end = region->base_addr + region->length;
Expand Down Expand Up @@ -1111,23 +1114,25 @@ int allocman_add_simple_untypeds_with_regions(allocman_t *alloc, simple_t *simpl
int error = prepare_handle_device_untyped_cap(alloc, simple, &state, num_regions, region_list);
ZF_LOGF_IF(error, "bootstrap_prepare_handle_device_untyped_cap Failed");

size_t i;
size_t total_untyped = simple_get_untyped_count(simple);
int total_untyped = simple_get_untyped_count(simple);
if (total_untyped < 0) {
ZF_LOGW("Could not get untyped count (%d)", total_untyped);
return 0; /* don't report an error, just do nothing */
}

for(i = 0; i < total_untyped; i++) {
for(int i = 0; i < total_untyped; i++) {
size_t size_bits;
uintptr_t paddr;
bool device;
cspacepath_t path = allocman_cspace_make_path(alloc, simple_get_nth_untyped(simple, i, &size_bits, &paddr, &device));
int dev_type = device ? ALLOCMAN_UT_DEV : ALLOCMAN_UT_KERNEL;
// If it is regular UT memory, then we add cap and move on.
if (dev_type == ALLOCMAN_UT_KERNEL) {
error = allocman_utspace_add_uts(alloc, 1, &path, &size_bits, &paddr, dev_type);
ZF_LOGF_IF(error, "Could not add kernel untyped.");
} else {
// Otherwise we are Device untyped.
if (device) {
// Separates device RAM memory into separate untyped caps
error = handle_device_untyped_cap(state, paddr, size_bits, &path, alloc);
ZF_LOGF_IF(error, "bootstrap_arch_handle_device_untyped_cap failed.");
ZF_LOGF_IF(error, "handle_device_untyped_cap failed (%d).", error);
} else {
// for regular UT memory we add cap
error = allocman_utspace_add_uts(alloc, 1, &path, &size_bits, &paddr, ALLOCMAN_UT_KERNEL);
ZF_LOGF_IF(error, "Could not add kernel untyped (%d).", error);
}
}
if (state) {
Expand Down
106 changes: 80 additions & 26 deletions libsel4debug/src/bootinfo.c
Original file line number Diff line number Diff line change
Expand Up @@ -8,41 +8,95 @@
#include <sel4debug/gen_config.h>

#include <stdio.h>
#include <assert.h>

#include <sel4/sel4.h>
#include <utils/util.h>

static void print_slot_reg_info(char const *descr, seL4_SlotRegion *reg)
{
if (reg->end == reg->start) {
printf("%snone\n", descr);
} else {
printf("%s[%"SEL4_PRIu_word" --> %"SEL4_PRIu_word")\n",
descr, reg->start, reg->end);
}
}

void debug_print_bootinfo(seL4_BootInfo *info)
{
printf("Node: %"SEL4_PRIu_word" of %"SEL4_PRIu_word"\n",
info->nodeID, info->numNodes);
printf("Domain: %"SEL4_PRIu_word"\n",
info->initThreadDomain);
printf("IPC buffer: %p\n", info->ipcBuffer);
printf("IO-MMU page table levels: %"SEL4_PRIu_word"\n",
info->numIOPTLevels);
printf("Root cnode size: 2^%"SEL4_PRIu_word" (%lu)\n",
info->initThreadCNodeSizeBits,
LIBSEL4_BIT(info->initThreadCNodeSizeBits));
print_slot_reg_info("Shared pages: ", &info->sharedFrames);
print_slot_reg_info("User image MMU tables: ", &info->userImagePaging);
print_slot_reg_info("Extra boot info pages: ", &info->extraBIPages);
print_slot_reg_info("User image pages: ", &info->userImageFrames);
print_slot_reg_info("Untyped memory: ", &info->untyped);
print_slot_reg_info("Empty slots: ", &info->empty);

printf("Node %lu of %lu\n", (long)info->nodeID, (long)info->numNodes);
printf("IOPT levels: %u\n", (int)info->numIOPTLevels);
printf("IPC buffer: %p\n", info->ipcBuffer);
printf("Empty slots: [%lu --> %lu)\n", (long)info->empty.start, (long)info->empty.end);
printf("sharedFrames: [%lu --> %lu)\n", (long)info->sharedFrames.start, (long)info->sharedFrames.end);
printf("userImageFrames: [%lu --> %lu)\n", (long)info->userImageFrames.start, (long)info->userImageFrames.end);
printf("userImagePaging: [%lu --> %lu)\n", (long)info->userImagePaging.start, (long)info->userImagePaging.end);
printf("untypeds: [%lu --> %lu)\n", (long)info->untyped.start, (long)info->untyped.end);
printf("Initial thread domain: %u\n", (int)info->initThreadDomain);
printf("Initial thread cnode size: %u\n", (int)info->initThreadCNodeSizeBits);
printf("List of untypeds\n");
printf("------------------\n");
printf("Paddr | Size | Device\n");

int sizes[CONFIG_WORD_SIZE] = {0};
for (int i = 0; i < CONFIG_MAX_NUM_BOOTINFO_UNTYPED_CAPS && i < (info->untyped.end - info->untyped.start); i++) {
int index = info->untypedList[i].sizeBits;
assert(index < ARRAY_SIZE(sizes));
sizes[index]++;
printf("%p | %zu | %d\n", (void *)info->untypedList[i].paddr, (size_t)info->untypedList[i].sizeBits,
(int)info->untypedList[i].isDevice);
printf("Extra boot info blobs:\n");
seL4_Word offs = 0;
while (offs < info->extraLen) {
seL4_BootInfoHeader *h = (seL4_BootInfoHeader *)((seL4_Word)info + seL4_BootInfoFrameSize + offs);
printf(" type: %"SEL4_PRIu_word", offset: %"SEL4_PRIu_word", len: %"SEL4_PRIu_word"\n",
h->id, offs, h->len);
offs += h->len;
}

printf("Untyped summary\n");
for (int i = 0; i < ARRAY_SIZE(sizes); i++) {
if (sizes[i] != 0) {
printf("%d untypeds of size %d\n", sizes[i], i);
seL4_Word numUntypeds = info->untyped.end - info->untyped.start;
printf("Used bootinfo untyped descriptors: %"SEL4_PRIu_word" of %d\n",
numUntypeds, CONFIG_MAX_NUM_BOOTINFO_UNTYPED_CAPS);
/* Sanity check that the boot info is consistent. */
assert(info->empty.end == LIBSEL4_BIT(info->initThreadCNodeSizeBits));
assert(numUntypeds < CONFIG_MAX_NUM_BOOTINFO_UNTYPED_CAPS);
assert(info->extraLen <= (LIBSEL4_BIT(seL4_PageBits) * (info->extraBIPages.end - info->extraBIPages.start)));

printf("Physical memory map with available untypeds:\n");
printf("---------------------+------+----------+-------\n");
printf(" Phys Addr | Size | Type | Slot\n");
printf("---------------------+------+----------+-------\n");

for (seL4_Word pos = 0; pos < (seL4_Word)(-1); pos++) {
/* Find the next descriptor according to our current position. */
seL4_UntypedDesc *d = NULL;
int idx = -1;
for (int i = 0; i < numUntypeds; i++) {
seL4_UntypedDesc *d_tmp = &info->untypedList[i];
if (d_tmp->paddr < pos) {
continue;
}
if (d && (d_tmp->paddr >= d->paddr)) {
/* Two descriptors for the same region are not allowed. */
assert(d_tmp->paddr != d->paddr);
continue;
}
d = d_tmp; /* Found a better match. */
idx = i;
}
/* No adjacent descriptor found means there is reserved space. */
if ((!d) || (pos < d->paddr)) {
printf(" %#*"SEL4_PRIx_word" | - | reserved | -\n",
2 + (CONFIG_WORD_SIZE / 4), pos);
if (!d) {
break; /* No descriptors found at all means we are done. */
}
}
printf(" %#*"SEL4_PRIx_word" | 2^%-2u | %s | %"SEL4_PRIu_word"\n",
2 + (CONFIG_WORD_SIZE / 4),
d->paddr,
d->sizeBits,
d->isDevice ? "device " : "free ",
info->untyped.start + idx);
seL4_Word pos_new = d->paddr + LIBSEL4_BIT(d->sizeBits) - 1;
assert(pos_new >= pos); /* Regions must not overflow. */
pos = pos_new;
}
}

17 changes: 16 additions & 1 deletion libsel4muslcsys/src/sys_morecore.c
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,11 @@ long sys_mmap_impl(void *addr, size_t length, int prot, int flags, int fd, off_t
if (length > morecore_top - morecore_base) {
return -ENOMEM;
}

ZF_LOGI(
"morecore %p - %p, len %#x, return address: 0x%"PRIxPTR,
morecore_base, morecore_top, length, morecore_top-length);

/* Steal from the top */
morecore_top -= length;
return morecore_top;
Expand Down Expand Up @@ -116,6 +121,8 @@ static void init_morecore_region(void)
morecore_base = (uintptr_t) morecore_area;
morecore_top = (uintptr_t) &morecore_area[morecore_size];
}

ZF_LOGI("morecore %p - %p (%#zd)", morecore_base, morecore_top, morecore_size);
}

static long sys_brk_static(va_list ap)
Expand Down Expand Up @@ -199,8 +206,16 @@ static long sys_mmap_impl_static(void *addr, size_t length, int prot, int flags,
if (base < morecore_base) {
return -ENOMEM;
}
ZF_LOGF_IF(
(base % 0x1000) != 0,
"morecore %p - %p, len %#zx, return address: %p (not 4 KiB aligned)",
(void*)morecore_base, (void*)morecore_top, length, (void*)base);

ZF_LOGI(
"morecore %p - %p, len %#zx, return address: %p",
(void*)morecore_base, (void*)morecore_top, length, (void*)base);

morecore_top = base;
ZF_LOGF_IF((base % 0x1000) != 0, "return address: 0x%"PRIxPTR" requires alignment: 0x%x ", base, 0x1000);
return base;
}
assert(!"not implemented");
Expand Down
Loading
Loading