aboutsummaryrefslogtreecommitdiff
path: root/src/sbi/error.zig
blob: 5aaeb7d6c557e15e524ce900d352ea068d2467dd (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
// SPDX-FileCopyrightText: 2024 Himbeer <himbeer@disroot.org>
//
// SPDX-License-Identifier: AGPL-3.0-or-later

pub const SbiError = error{
    Success,
    Failed,
    NotSupported,
    InvalidParam,
    Denied,
    InvalidAddr,
    AlreadyAvail,
    AlreadyStarted,
    AlreadyStopped,
    NoSharedMem,
    Unknown,
};

pub fn errorFromCode(code: isize) SbiError {
    return switch (code) {
        0 => SbiError.Success,
        -1 => SbiError.Failed,
        -2 => SbiError.NotSupported,
        -3 => SbiError.InvalidParam,
        -4 => SbiError.Denied,
        -5 => SbiError.InvalidAddr,
        -6 => SbiError.AlreadyAvail,
        -7 => SbiError.AlreadyStarted,
        -8 => SbiError.AlreadyStopped,
        -9 => SbiError.NoSharedMem,
        else => SbiError.Unknown,
    };
}