aboutsummaryrefslogtreecommitdiff
path: root/src/kernel/system.h
blob: 47d902c6a91f359188de30223564e3b753c173e7 (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
#ifndef MELVIX_SYSTEM_H
#define MELVIX_SYSTEM_H

void init();

typedef struct __attribute__ ((packed)) {
    unsigned short di, si, bp, sp, bx, dx, cx, ax;
    unsigned short gs, fs, es, ds, eflags;
} regs16_t;

extern void int32(unsigned char intnum, regs16_t *regs);

struct far_ptr {
    union {
        uint32_t ptr;
        struct {
            uint16_t offset, segment;
        };
    };
} __attribute__ ((packed));

static inline uint16_t get_offset(const volatile void *p) {
    return (uint16_t) (uintptr_t) p & 0x000F;
}

static inline uint16_t get_segment(const volatile void *p) {
    return (uint16_t) (((uintptr_t) p) >> 4);
}

static inline struct far_ptr FAR_PTR(void *__ptr) {
    struct far_ptr __fptr;
    __fptr.offset = get_offset(__ptr);
    __fptr.segment = get_segment(__ptr);
    return __fptr;
}

static inline void *get_ptr(struct far_ptr fptr) {
    return (void *) (unsigned long) ((fptr.segment << 4) + fptr.offset);
}

#endif