Liblor / advanced_operating_systems_2020

Advanced Operating System Course at ETHZ
MIT License
19 stars 3 forks source link

[shell/shell] provide implementation of a shell #135

Closed abertschi closed 4 years ago

abertschi commented 4 years ago

This branch is frequently updated with a partial implementation of a shell. It is meant to be pulled into other branches if shell functionality is needed during development of other features.

Liblor commented 4 years ago

When init is started, it receives a cap in its TASKCN_SLOT_DEV which contains most register regions for the devices on the Toradex board. Your job is to manage this region and retype it to smaller capabilities of type ObjType_DevFrame accord- ing to the sizes and base addresses of register regions for individual devices. This will also be required for other projects so talk to your teammates! If you decide to run the driver for the LPUART within init you simply need to map the device frame with its registers into init’s virtual address space.

Book p. 202

I'd say we start with keeping everything in init/0 as said in previous discussions.

eikendev commented 4 years ago

I tried mapping the device capability like I'll outline in the following. Unfortunately, the paging system seems not to be able to map it. Anyone ran into the same issue?

struct capref cap;
const genpaddr_t base = 0x5B040000;
const gensize_t size = 0x1000;

struct capability capy;
err = cap_direct_identify(cap_dev, &capy);
if (err_is_fail(err)) {
    debug_printf("cap_direct_identify() failed: %s\n", err_getstring(err));
    return err_push(err, LIB_ERR_CAP_IDENTIFY);
}

const genpaddr_t realbase = get_address(&capy);
debug_printf("base of the root device cap: %p\n", (void *) realbase);
debug_printf("retyping with offset %p and size 0x%zx\n", (void *) (base - realbase), size);

err = slot_alloc(&cap);
if (err_is_fail(err)) {
    debug_printf("slot_alloc() failed: %s\n", err_getstring(err));
    return err_push(err, LIB_ERR_SLOT_ALLOC);
}

err = cap_retype(
    cap,
    cap_dev,
    base - realbase,
    ObjType_DevFrame,
    ROUND_UP(size, BASE_PAGE_SIZE),
    1
);
if (err_is_fail(err)) {
    debug_printf("cap_retype() failed: %s\n", err_getstring(err));
    return err_push(err, LIB_ERR_CAP_RETYPE);
}

char buf[100];
debug_print_cap_at_capref(buf, sizeof(buf), cap);
debug_printf("%s\n", buf);
debug_print_capref(buf, sizeof(buf), cap);
debug_printf("%s\n", buf);

void *vaddr;
err = paging_map_frame(
    get_current_paging_state(),
    &vaddr,
    size,
    cap,
    NULL,
    NULL
);
if (err_is_fail(err)) {
    debug_printf("paging_map_frame_attr() failed: %s\n", err_getstring(err));
    return err_push(err, LIB_ERR_VSPACE_MAP);
}
abertschi commented 4 years ago

When init is started, it receives a cap in its TASKCN_SLOT_DEV which contains most register regions for the devices on the Toradex board. Your job is to manage this region and retype it to smaller capabilities of type ObjType_DevFrame accord- ing to the sizes and base addresses of register regions for individual devices. This will also be required for other projects so talk to your teammates! If you decide to run the driver for the LPUART within init you simply need to map the device frame with its registers into init’s virtual address space.

Book p. 202

I'd say we start with keeping everything in init/0 as said in previous discussions.

Yes, I named the cref as follows

https://github.com/Liblor/advanced_operating_systems_2020/blob/6f2b2ac2b8f51e5dc236024c995163dd3d97795f/lib/aos/capabilities.c#L202-L207

Liblor commented 4 years ago

I tried mapping the device capability like I'll outline in the following. Unfortunately, the paging system seems not to be able to map it. Anyone ran into the same issue? [...]

I've just started... but on moodle it is mentioned to map it VREGION_FLAGS_READ_WRITE_NOCACHE, which is not the case for paging_map_frame

eikendev commented 4 years ago

I tried mapping the device capability like I'll outline in the following. Unfortunately, the paging system seems not to be able to map it. Anyone ran into the same issue? [...]

I've just started... but on moodle it is mentioned to map it VREGION_FLAGS_READ_WRITE_NOCACHE, which is not the case for paging_map_frame

Thank you. The error persists.

Liblor commented 4 years ago

Maybe, we should move the discussion instead of spamming @abertschi. But what error do you get? For me mapping seems to work (I didn't try accessing the driver or anything). Checkout filesystem/block-driver.

I will put a generalized version in paging.c

Edit: I pushed my changes to filesystem/filesystem (3cd775d25050ceec35ad43109ab711b672c0025b), can you test whether map_driver works for you?

Liblor commented 4 years ago

Motivation gif for my friiiiiiiiiiiend :)

eikendev commented 4 years ago

@abertschi, I changed the base, and merged @leopoldsedev's branch. Unfortunately, I forgot to add a merge blocker before that, so your pull request was recognized as being merged. Please branch off from milestone7, and open a new pull request if needed.