1 // =============================================================================
2 // BareMetal -- a 64-bit OS written in Assembly for x86-64 systems
3 // Copyright (C) 2008-2011 Return Infinity -- see LICENSE.TXT
5 // The BareMetal OS C library code.
9 // This allows for a C program to access OS functions available in BareMetal OS
12 // gcc -c -m64 -nostdlib -nostartfiles -nodefaultlibs -fomit-frame-pointer -mno-red-zone -o libBareMetal.o libBareMetal.c
13 // gcc -c -m64 -nostdlib -nostartfiles -nodefaultlibs -fomit-frame-pointer -mno-red-zone -o yourapp.o yourapp.c
16 // ld -T app.ld -o yourapp.app yourapp.o
17 // =============================================================================
20 void b_print_string(char *str
)
22 asm volatile ("call *0x00100018" : : "S"(str
)); // Make sure source register (RSI) has the string address (str)
26 void b_print_char(char chr
)
28 asm volatile ("call *0x00100028" : : "a"(chr
));
32 void b_print_char_hex(char chr
)
34 asm volatile ("call *0x00100038" : : "a"(chr
));
38 void b_print_newline(void)
40 asm volatile ("call *0x00100048");
44 void b_print_string_with_color(char *str
, unsigned char clr
)
46 asm volatile ("call *0x00100388" : : "S"(str
), "b"(clr
)); // Make sure source register (RSI) has the string address (str)
50 void b_print_char_with_color(char chr
, unsigned char clr
)
52 asm volatile ("call *0x00100398" : : "a"(chr
), "b"(clr
));
57 void b_print_char_hex_with_color(char chr
, unsigned char clr
)
59 asm volatile ("call *0x00100428" : : "a"(chr
), "b"(clr
));
64 unsigned char b_input_get_key(void)
67 asm volatile ("call *0x00100058" : "=a" (chr
));
72 unsigned char b_input_wait_for_key(void)
75 asm volatile ("call *0x00100068" : "=a" (chr
));
80 unsigned long b_input_string(unsigned char *str
, unsigned long nbr
)
83 asm volatile ("call *0x00100078" : "=c" (len
) : "c"(nbr
), "D"(str
));
88 unsigned long b_string_length(unsigned char *str
)
91 asm volatile ("call *0x001000D8" : "=c" (len
) : "S"(str
));
96 unsigned long b_string_find_char(unsigned char *str
, unsigned char chr
)
99 asm volatile ("call *0x001000E8" : "=a" (pos
) : "a"(chr
), "S"(str
));
104 void b_os_string_copy(unsigned char *dst
, unsigned char *src
)
106 asm volatile ("call *0x001000F8" : : "S"(src
), "D"(dst
));
110 void b_int_to_string(unsigned long nbr
, unsigned char *str
)
112 asm volatile ("call *0x00100178" : : "a"(nbr
), "D"(str
));
116 unsigned long b_string_to_int(unsigned char *str
)
119 asm volatile ("call *0x00100188" : "=a"(tlong
) : "S"(str
));
124 void b_delay(unsigned long nbr
)
126 asm volatile ("call *0x00100088" : : "a"(nbr
));
130 unsigned long b_get_argc()
133 asm volatile ("call *0x00100268" : "=a"(tlong
));
138 char* b_get_argv(unsigned char nbr
)
141 asm volatile ("call *0x00100278" : "=S"(tchar
) : "a"(nbr
));
146 unsigned long b_get_timercounter(void)
149 asm volatile ("call *0x001002A8" : "=a"(tlong
));
154 void b_debug_dump_mem(void *data
, unsigned int size
)
156 asm volatile ("call *0x001001A8" : : "S"(data
), "c"(size
));
160 void b_serial_send(unsigned char chr
)
162 asm volatile ("call *0x00100238" : : "a"(chr
));
166 unsigned char b_serial_recv(void)
169 asm volatile ("call *0x00100248" : "=a" (chr
));
174 void b_file_read(unsigned char *name
, void *mem
)
176 asm volatile ("call *0x00100318" : : "S"(name
), "D"(mem
));
180 void b_file_write(void *data
, unsigned char *name
, unsigned int size
)
182 asm volatile ("call *0x00100328" : : "S"(data
), "D"(name
), "c"(size
));
186 void b_file_delete(unsigned char *name
)
188 asm volatile ("call *0x00100338" : : "S"(name
));
192 unsigned long b_smp_enqueue(void *ptr
, unsigned long var
)
195 asm volatile ("call *0x00100218" : "=a"(tlong
) : "a"(ptr
), "S"(var
));
200 unsigned long b_smp_dequeue(unsigned long *var
)
203 asm volatile ("call *0x00100228" : "=a"(tlong
), "=D"(var
));
208 void b_smp_run(unsigned long ptr
)
210 asm volatile ("call *0x00100358" : : "a"(ptr
));
214 unsigned long b_smp_queuelen(void)
217 asm volatile ("call *0x00100288" : "=a"(tlong
));
222 void b_smp_wait(void)
224 asm volatile ("call *0x00100298");
228 void b_smp_lock(unsigned long ptr
)
230 asm volatile ("call *0x00100368" : : "a"(ptr
));
234 void b_smp_unlock(unsigned long ptr
)
236 asm volatile ("call *0x00100378" : : "a"(ptr
));
240 unsigned long b_smp_get_id()
243 asm volatile ("call *0x00100208" : "=a"(tlong
));
248 unsigned long b_smp_numcores(void)
251 asm volatile ("call *0x001003F8" : "=a"(tlong
));
256 void b_speaker_tone(unsigned long nbr
)
258 asm volatile ("call *0x00100098" : : "a"(nbr
));
262 void b_speaker_off(void)
264 asm volatile ("call *0x001000A8");
268 void b_speaker_beep(void)
270 asm volatile ("call *0x001000B8");
274 void b_ethernet_tx(void *mem
, void *dest
, unsigned short type
, unsigned short len
)
276 asm volatile ("call *0x001003A8" : : "S"(mem
), "D"(dest
), "b"(type
), "c"(len
));
279 void b_ethernet_tx_raw(void *mem
, unsigned short len
)
281 asm volatile ("call *0x00100438" : : "S"(mem
), "c"(len
));
284 unsigned long b_ethernet_rx(void *mem
)
287 asm volatile ("call *0x001003B8" : "=c"(tlong
) : "D"(mem
));
291 unsigned long b_ethernet_avail()
294 asm volatile ("call *0x00100418" : "=a"(tlong
));
299 // =============================================================================