1/*
2 * Copyright 2017, Data61
3 * Commonwealth Scientific and Industrial Research Organisation (CSIRO)
4 * ABN 41 687 119 230.
5 *
6 * This software may be distributed and modified according to the terms of
7 * the BSD 2-Clause license. Note that NO WARRANTY is provided.
8 * See "LICENSE_BSD2.txt" for details.
9 *
10 * @TAG(DATA61_BSD)
11 */
12
13#pragma once
14
15#include <sel4/types.h>
16#include <assert.h>
17#include <autoconf.h>
18#include <sel4vka/gen_config.h>
19#include <utils/util.h>
20
21enum _x86_mode_kobject_type {
22    KOBJECT_PML4,
23    KOBJECT_PDPT,
24    KOBJECT_FRAME,
25    KOBJECT_MODE_NUM_TYPES,
26};
27
28typedef int kobject_t;
29
30/*
31 * Get the size (in bits) of the untyped memory required to
32 * create an object of the given size.
33 */
34static inline seL4_Word x86_mode_kobject_get_size(kobject_t type, seL4_Word objectSize)
35{
36    switch (type) {
37    case KOBJECT_FRAME:
38        switch (objectSize) {
39        case seL4_HugePageBits:
40            return objectSize;
41        default:
42            return 0;
43        }
44    case KOBJECT_PDPT:
45        return seL4_PDPTBits;
46    default:
47        ZF_LOGE("Unknown object type");
48        return 0;
49    }
50}
51
52static inline seL4_Word x86_mode_kobject_get_type(kobject_t type, seL4_Word objectSize)
53{
54    switch (type) {
55    case KOBJECT_FRAME:
56        switch (objectSize) {
57        case seL4_HugePageBits:
58            return seL4_X64_HugePageObject;
59        default:
60            return -1;
61        }
62    case KOBJECT_PML4:
63        return seL4_X64_PML4Object;
64    case KOBJECT_PDPT:
65        return seL4_X86_PDPTObject;
66    default:
67        /* Unknown object type. */
68        ZF_LOGE("Unknown object type %d", type);
69        return -1;
70    }
71}
72
73