-
Notifications
You must be signed in to change notification settings - Fork 11
/
klibc.h
58 lines (47 loc) · 1.31 KB
/
klibc.h
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
// -*- c++ -*-
//
// Standalone base libc functions suitable for in-kernel use
//
// Copyright 1997-2008 Matt T. Yourst <[email protected]>
//
// This program is free software; it is licensed under the
// GNU General Public License, Version 2.
//
#ifndef _BASELIBC_H
#define _BASELIBC_H
#include <syscalls.h>
//
// Division functions
//
#ifdef __x86_64__
#define do_div(n,base) ({ \
W32 __base = (base); \
W32 __rem; \
__rem = ((W64)(n)) % __base; \
(n) = ((W64)(n)) / __base; \
__rem; \
})
#else
// 32-bit x86
#define do_div(n,base) ({ \
W32 __upper, __low, __high, __mod, __base; \
__base = (base); \
asm("":"=a" (__low), "=d" (__high):"A" (n)); \
__upper = __high; \
if (__high) { \
__upper = __high % (__base); \
__high = __high / (__base); \
} \
asm("divl %2":"=a" (__low), "=d" (__mod):"rm" (__base), "0" (__low), "1" (__upper)); \
asm("":"=A" (n):"a" (__low),"d" (__high)); \
__mod; \
})
#endif
char* format_number(char* buf, char* end, W64 num, int base, int size, int precision, int type);
int format_integer(char* buf, int bufsize, W64s v, int size = 0, int flags = 0, int base = 10, int precision = 0);
int format_float(char* buf, int bufsize, double v, int precision = 6, int pad = 0);
//
// Fundamental system calls
//
void call_global_constuctors();
#endif // _BASELIBC_H