-
Notifications
You must be signed in to change notification settings - Fork 74
Enable mapping extra TCB and SC caps into PD's #406
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
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,71 @@ | ||
| # | ||
| # Copyright 2026, UNSW | ||
| # | ||
| # SPDX-License-Identifier: BSD-2-Clause | ||
| # | ||
| ifeq ($(strip $(BUILD_DIR)),) | ||
| $(error BUILD_DIR must be specified) | ||
| endif | ||
|
|
||
| ifeq ($(strip $(MICROKIT_SDK)),) | ||
| $(error MICROKIT_SDK must be specified) | ||
| endif | ||
|
|
||
| ifeq ($(strip $(MICROKIT_BOARD)),) | ||
| $(error MICROKIT_BOARD must be specified) | ||
| endif | ||
|
|
||
| ifeq ($(strip $(MICROKIT_CONFIG)),) | ||
| $(error MICROKIT_CONFIG must be specified) | ||
| endif | ||
|
|
||
| BOARD_DIR := $(MICROKIT_SDK)/board/$(MICROKIT_BOARD)/$(MICROKIT_CONFIG) | ||
|
|
||
| ARCH := ${shell grep 'CONFIG_SEL4_ARCH ' $(BOARD_DIR)/include/kernel/gen_config.h | cut -d' ' -f4} | ||
|
|
||
| ifeq ($(ARCH),aarch64) | ||
| TARGET_TRIPLE := aarch64-none-elf | ||
| CFLAGS_ARCH := -mstrict-align | ||
| else ifeq ($(ARCH),riscv64) | ||
| TARGET_TRIPLE := riscv64-unknown-elf | ||
| CFLAGS_ARCH := -march=rv64imafdc_zicsr_zifencei -mabi=lp64d | ||
| else ifeq ($(ARCH),x86_64) | ||
| TARGET_TRIPLE := x86_64-linux-gnu | ||
| CFLAGS_ARCH := -march=x86-64 -mtune=generic | ||
| else | ||
| $(error Unsupported ARCH) | ||
| endif | ||
|
|
||
| ifeq ($(strip $(LLVM)),True) | ||
| CC := clang -target $(TARGET_TRIPLE) | ||
| AS := clang -target $(TARGET_TRIPLE) | ||
| LD := ld.lld | ||
| else | ||
| CC := $(TARGET_TRIPLE)-gcc | ||
| LD := $(TARGET_TRIPLE)-ld | ||
| AS := $(TARGET_TRIPLE)-as | ||
| endif | ||
|
|
||
| MICROKIT_TOOL ?= $(MICROKIT_SDK)/bin/microkit | ||
|
|
||
| IMAGES := cap_sharing.elf secondary.elf | ||
| CFLAGS := -nostdlib -ffreestanding -g -O3 -Wall -Wno-unused-function -Werror -I$(BOARD_DIR)/include $(CFLAGS_ARCH) | ||
| LDFLAGS := -L$(BOARD_DIR)/lib | ||
| LIBS := -lmicrokit -Tmicrokit.ld | ||
|
|
||
| IMAGE_FILE = $(BUILD_DIR)/loader.img | ||
| REPORT_FILE = $(BUILD_DIR)/report.txt | ||
|
|
||
| all: $(IMAGE_FILE) | ||
|
|
||
| $(BUILD_DIR): | ||
| mkdir -p $@ | ||
|
|
||
| $(BUILD_DIR)/%.o: %.c Makefile | $(BUILD_DIR) | ||
| $(CC) -c $(CFLAGS) $< -o $@ | ||
|
|
||
| $(BUILD_DIR)/%.elf: $(BUILD_DIR)/%.o | ||
| $(LD) $(LDFLAGS) $^ $(LIBS) -o $@ | ||
|
|
||
| $(IMAGE_FILE) $(REPORT_FILE): $(addprefix $(BUILD_DIR)/, $(IMAGES)) cap_sharing.system | ||
| $(MICROKIT_TOOL) cap_sharing.system --search-path $(BUILD_DIR) --board $(MICROKIT_BOARD) --config $(MICROKIT_CONFIG) -o $(IMAGE_FILE) -r $(REPORT_FILE) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,44 @@ | ||
| <!-- | ||
| Copyright 2026, UNSW | ||
| SPDX-License-Identifier: CC-BY-SA-4.0 | ||
| --> | ||
| # Example - Cap Sharing | ||
|
|
||
| This is a basic example that demonstrates how one can use the `<cspace>` element | ||
| of a PD to give delegated access of specific capabilities associated with other | ||
| (or its own) protection domain. | ||
|
|
||
| See `cap_sharing.system` for some comments on the internal setup of this system. | ||
| The idea behind this example is that we have two PDs, one of which has control | ||
| over the TCB and scheduling context of the other; this could be the basis of | ||
| (e.g.) a user space scheduler. | ||
|
|
||
| All supported platforms are supported in this example. | ||
|
|
||
| ## Building | ||
|
|
||
| ```sh | ||
| mkdir build | ||
| make BUILD_DIR=build MICROKIT_BOARD=<board> MICROKIT_CONFIG=<debug/release/benchmark> MICROKIT_SDK=/path/to/sdk | ||
| ``` | ||
|
|
||
| ## Running | ||
|
|
||
| See instructions for your board in the manual. | ||
|
|
||
| You should see the following output: | ||
|
|
||
| ``` | ||
| INFO [sel4_capdl_initializer::initialize] Starting CapDL initializer | ||
| INFO [sel4_capdl_initializer::initialize] Starting threads | ||
| MON|INFO: Microkit Monitor started! | ||
| |secondary| hello, world | ||
| |primary | hello, world | ||
| |primary | notifying secondary | ||
| |secondary| notified | ||
| |primary | suspending secondary | ||
| |primary | notifying secondary (it should not print) | ||
| |primary | resuming secondary (it should then print) | ||
| |secondary| notified | ||
| |primary | halting (success)... | ||
| ``` |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,63 @@ | ||
| /* | ||
| * Copyright 2026, UNSW | ||
| * | ||
| * SPDX-License-Identifier: BSD-2-Clause | ||
| */ | ||
| #include <stdint.h> | ||
| #include <microkit.h> | ||
|
|
||
| #define CH_SECONDARY ((microkit_channel)0) | ||
|
|
||
| // As per cap_sharing.system | ||
| #define CAP_SECONDARY_SC (microkit_cspace_slot_to_cptr(1)) | ||
| #define CAP_SECONDARY_TCB (microkit_cspace_slot_to_cptr(2)) | ||
| #define CAP_MY_SC (microkit_cspace_slot_to_cptr(3)) | ||
| #define CAP_MY_TCB (microkit_cspace_slot_to_cptr(4)) | ||
|
|
||
| static void halt(void) | ||
| { | ||
| seL4_Error error = seL4_TCB_Suspend(CAP_MY_TCB); | ||
| if (error != seL4_NoError) { | ||
| microkit_dbg_puts("|primary | error suspending TCB\n"); | ||
| } | ||
|
|
||
| microkit_dbg_puts("|primary | error: should not reach this point! we should have suspended ourself!\n"); | ||
| while (1) { } | ||
| } | ||
|
|
||
| void init(void) | ||
| { | ||
| seL4_Error err; | ||
|
|
||
| microkit_dbg_puts("|primary | hello, world\n"); | ||
|
|
||
| /* Notify the secondary. This will print output from secondary as it is | ||
| higher priority. */ | ||
| microkit_dbg_puts("|primary | notifying secondary\n"); | ||
| microkit_notify(CH_SECONDARY); | ||
|
|
||
| microkit_dbg_puts("|primary | suspending secondary\n"); | ||
| err = seL4_TCB_Suspend(CAP_SECONDARY_TCB); | ||
| if (err != seL4_NoError) { | ||
| microkit_dbg_puts("|primary | error suspending TCB\n"); | ||
| halt(); | ||
| } | ||
|
|
||
| /* Notify the secondary. It is suspended so it will not print. */ | ||
| microkit_dbg_puts("|primary | notifying secondary (it should not print)\n"); | ||
| microkit_notify(CH_SECONDARY); | ||
|
|
||
| microkit_dbg_puts("|primary | resuming secondary (it should then print)\n"); | ||
| err = seL4_TCB_Resume(CAP_SECONDARY_TCB); | ||
| if (err != seL4_NoError) { | ||
| microkit_dbg_puts("|primary | error resuming TCB\n"); | ||
| halt(); | ||
| } | ||
|
|
||
| microkit_dbg_puts("|primary | halting (success)...\n"); | ||
| halt(); | ||
| } | ||
|
|
||
| void notified(microkit_channel ch) | ||
| { | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,30 @@ | ||
| <?xml version="1.0" encoding="UTF-8"?> | ||
| <!-- | ||
| Copyright 2026, UNSW | ||
|
|
||
| SPDX-License-Identifier: BSD-2-Clause | ||
| --> | ||
| <system> | ||
| <protection_domain name="primary" priority="1"> | ||
| <program_image path="cap_sharing.elf" /> | ||
|
|
||
| <cspace> | ||
| <!-- You can have the SC or TCB of another PD --> | ||
| <cap_sc slot="1" pd="secondary" /> | ||
| <cap_tcb slot="2" pd="secondary" /> | ||
|
|
||
| <!-- You can also have it of yourself --> | ||
| <cap_sc slot="3" pd="primary" /> | ||
| <cap_tcb slot="4" pd="primary" /> | ||
| </cspace> | ||
| </protection_domain> | ||
|
|
||
| <protection_domain name="secondary" priority="2"> | ||
| <program_image path="secondary.elf" /> | ||
| </protection_domain> | ||
|
|
||
| <channel> | ||
| <end pd="primary" id="0" /> | ||
| <end pd="secondary" id="0" /> | ||
| </channel> | ||
| </system> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,18 @@ | ||
| /* | ||
| * Copyright 2026, UNSW | ||
| * | ||
| * SPDX-License-Identifier: BSD-2-Clause | ||
| */ | ||
| #include <stdint.h> | ||
| #include <microkit.h> | ||
|
|
||
| void init(void) | ||
| { | ||
| microkit_dbg_puts("|secondary| hello, world\n"); | ||
|
midnightveil marked this conversation as resolved.
|
||
| } | ||
|
|
||
| void notified(microkit_channel ch) | ||
| { | ||
| microkit_dbg_puts("|secondary| notified\n"); | ||
| microkit_notify(ch); | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.