.githooks/
compiler/
kernel/
lib/
scripts/
seed/
sublime/
test/
boot/
bootstrap/
compiler/
cycles/
dispatch/
format/
host/
integration/
kernel/
loader/
manifests/
mmio/
native/
packages/
runtime/
scheduling/
root.rad
2.6 KiB
scheduler.rad
2.8 KiB
shared/
slots/
smp/
std/
sync/
termination/
tests/
trap/
verify/
Makefile
9.2 KiB
kernel.rad
776 B
runner.rad
11.6 KiB
vim/
.gitignore
333 B
.gitsigners
224 B
AGENTS.md
8.3 KiB
CONTRIBUTING
2.1 KiB
LICENSE
1.1 KiB
Makefile
2.5 KiB
README
3.4 KiB
STYLE
3.2 KiB
std.lib
2.1 KiB
std.lib.test
1.1 KiB
test/scheduling/root.rad
raw
| 1 | //! Root resource handoff for user-space scheduling tests. |
| 2 | export mod abi; |
| 3 | export mod sys; |
| 4 | |
| 5 | /// Transfer root's resource bundle and parent duties before normal exit. |
| 6 | @default fn main(env: *abi::Env) -> ! { |
| 7 | assert env.argsSize == @sizeOf(abi::BootInfo) as u64; |
| 8 | let args = abi::Handle(env.args); |
| 9 | // The boot record is in the Page that the startup arguments name. Root updates it in |
| 10 | // place, and moves the Page to the scheduler as its arguments. |
| 11 | let records = try! sys::bootInfoMut(args); |
| 12 | assert records.len == 1; |
| 13 | let mut info = records[0]; |
| 14 | let self = abi::Handle(info.handles[0]); |
| 15 | let scheduler = try! sys::domainCreate(self, info.schedulerImage); |
| 16 | let context = try! sys::queryContext(scheduler, 0); |
| 17 | let authority = try! sys::capabilityGrant(scheduler, scheduler, abi::RIGHTS_MASK as u64); |
| 18 | let stack = try! sys::pageAllocate(self, 16); |
| 19 | let sharedStack = try! sys::capabilityTransfer(stack, scheduler, abi::RIGHTS_MASK as u64); |
| 20 | let clock = info.clock; |
| 21 | let shutdown = info.shutdown; |
| 22 | let budgets = 2 + info.devices as u32 + info.interrupts as u32; |
| 23 | for i in 2 .. budgets { |
| 24 | let old = abi::Handle(info.handles[i]); |
| 25 | let moved = try! sys::capabilityTransfer(old, scheduler, abi::RIGHTS_MASK as u64); |
| 26 | set info.handles[i] = *moved; |
| 27 | if old == clock { |
| 28 | set info.clock = moved; |
| 29 | } |
| 30 | if old == shutdown { |
| 31 | set info.shutdown = moved; |
| 32 | } |
| 33 | } |
| 34 | for i in budgets .. info.count as u32 { |
| 35 | let budget = abi::Handle(info.handles[i]); |
| 36 | let window = try! sys::queryBudget(budget); |
| 37 | if window.hart == 0 { |
| 38 | let future = try! sys::budgetSplit(budget, window.start + info.timebase * 2); |
| 39 | set info.handles[i] = *try! sys::budgetBind(future, scheduler, context.context); |
| 40 | } else { |
| 41 | set info.handles[i] = *try! sys::capabilityTransfer( |
| 42 | budget, scheduler, abi::RIGHTS_MASK as u64 |
| 43 | ); |
| 44 | } |
| 45 | } |
| 46 | set info.handles[0] = *authority; |
| 47 | set info.handles[1] = 0; |
| 48 | set info.rootImage = try! sys::capabilityTransfer( |
| 49 | info.rootImage, scheduler, abi::RIGHTS_MASK as u64 |
| 50 | ); |
| 51 | set info.schedulerImage = try! sys::capabilityTransfer( |
| 52 | info.schedulerImage, scheduler, abi::RIGHTS_MASK as u64 |
| 53 | ); |
| 54 | assert info.arguments == args; |
| 55 | let moved = try! sys::capabilityTransfer(args, scheduler, abi::RIGHTS_MASK as u64); |
| 56 | set info.arguments = moved; |
| 57 | try! sys::domainReparent(self, scheduler); |
| 58 | set records[0] = info; |
| 59 | try! sys::domainActivate(scheduler, sharedStack, moved, @sizeOf(abi::BootInfo) as u64); |
| 60 | sys::exit(0); |
| 61 | } |