test/termination/spin.rad 1.2 KiB raw
1
//! User termination and CPU-fault entry paths.
2
export mod cases;
3
export mod abi;
4
export mod sys;
5
6
/// Issue a raw call to test the kernel error boundary.
7
@intrinsic fn ecall(operation: u32, a0: i64, a1: i64, a2: i64, a3: i64) -> i64;
8
9
/// Exercise an explicit exit, explicit abort, or a user breakpoint fault. The
10
/// parent selects the case with the first word of the arguments Page, and no
11
/// Page selects exit. The second word holds the device handle of the last case.
12
@default fn main(env: *abi::Env) {
13
    if env.argsSize == 0 {
14
        sys::exit(cases::EXIT_STATUS);
15
    }
16
    let words = try! sys::pageWords(abi::Handle(env.args));
17
    let mode = words[0];
18
    if mode == cases::Scenario::Abort as u64 {
19
        sys::abort();
20
    }
21
    if mode == cases::Scenario::DestroySelf as u64 {
22
        try! sys::domainDestroy(abi::Handle(0), 0);
23
    }
24
    if mode == cases::Scenario::InvalidSelfQuery as u64 {
25
        let result = ecall(abi::Operation::QueryDomain as u32, 0, 0, 0, 0);
26
        sys::exit(99);
27
    }
28
    if mode == cases::Scenario::DeviceQuery as u64 {
29
        let device = sys::queryDevice(abi::Handle(words[1]));
30
        assert device.base == cases::FINISH_ADDRESS and device.size >= 4;
31
        sys::exit(cases::DEVICE_STATUS);
32
    }
33
    assert false;
34
}