summaryrefslogtreecommitdiffstats
path: root/arch/x86_64/hal/obj.c
blob: d6c9a80e6d2618ba61ac3c49a8e66b035a6764f6 (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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
#include "obj.h"
#include "sys/lock.h"
#include "lib/printf.h"
#include "paging.h"
#include "hal/obj.h"
#include "jove.h"
#include "sys/link.h"

jove_owned_obj_t*
obj_take(jove_obj_t *obj)
{
    if((uintptr_t)obj < IDENT_VIRT_BASE) {
        reterr(EBADOBJ);
    }
    take_mutex(&obj->lock);
    return (jove_owned_obj_t*)obj;
}

jove_owned_obj_t*
obj_trytake(jove_obj_t *obj)
{
    if((uintptr_t)obj < IDENT_VIRT_BASE) {
        reterr(EBADOBJ);
    }
    if(try_take_mutex(&obj->lock)) {
        reterr(EBUSY);
    }
    return (jove_owned_obj_t*)obj;
}

jove_obj_t *obj_asunowned(jove_owned_obj_t *obj)
{
    return (jove_obj_t*)obj;
}

jove_obj_t*
obj_release(jove_owned_obj_t *obj)
{
    if((uintptr_t)obj < IDENT_VIRT_BASE) {
        reterr(EBADOBJ);
    }
    release_mutex((atomic_flag*)&obj->locked.lock);
    return (jove_obj_t*)obj;
}

void*
obj_deref(jove_owned_obj_t *obj)
{
    return (void*)(((uintptr_t)obj_getvalue(obj)) | IDENT_VIRT_BASE);
}

uint8_t
obj_gettype(jove_owned_obj_t *obj)
{
    return obj->locked.type;
}

uint8_t
obj_peektype(jove_obj_t obj)
{
    return obj.type;
}

void
obj_settype(jove_owned_obj_t *obj, uint8_t type)
{
    obj->locked.type = type;
}

uintmax_t
obj_getvalue(jove_owned_obj_t *obj)
{
    return obj->locked.value;
}

void
obj_setvalue(jove_owned_obj_t *obj, uintmax_t value)
{
    obj->locked.value = value & 0x00007FFFFFFFFFFFULL;
}

bool 
obj_compare(jove_obj_t *a, jove_obj_t *b)
{
    return a->data == b->data;
}