aboutsummaryrefslogtreecommitdiffstats
path: root/src/util.c
blob: 845609bc0613a133ca3141aaf6d0a2db31ae3090 (plain)
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
#include "util.h" // usleep

// Sum the bytes in the specified area.
u8
checksum(u8 *far_data, u32 len)
{
    u32 i;
    u8 sum = 0;
    for (i=0; i<len; i++)
        sum += GET_FARPTR(far_data[i]);
    return sum;
}

// Sleep for n microseconds. currently using the
// refresh request port 0x61 bit4, toggling every 15usec
void
usleep(u32 count)
{
    count = count / 15;
    u8 kbd = inb(PORT_PS2_CTRLB);
    while (count)
        if ((inb(PORT_PS2_CTRLB) ^ kbd) & KBD_REFRESH)
            count--;
}

void
memset(void *s, int c, size_t n)
{
    while (n)
        ((char *)s)[--n] = c;
}

void *
memcpy(void *far_d1, const void *far_s1, size_t len)
{
    u8 *d = far_d1;
    u8 *s = (u8*)far_s1;

    while (len--) {
        SET_FARPTR(*d, GET_FARPTR(*s));
        d++;
        s++;
    }

    return far_d1;
}

void
__set_fail(const char *fname, struct bregs *regs)
{
    __debug_fail(fname, regs);
    set_cf(regs, 1);
}

void
__set_code_fail(const char *fname, struct bregs *regs, u8 code)
{
    __set_fail(fname, regs);
    regs->ah = code;
}