* mikeOS 16 bit and amd64 baremetal
[mascara-docs.git] / amd64 / bareMetalOS-0.5.2 / baremetal0.5.2 / programs / libBareMetal.c
blob8981936dfad508bad9bd7f47cf627089d7a774f7
1 // =============================================================================
2 // BareMetal -- a 64-bit OS written in Assembly for x86-64 systems
3 // Copyright (C) 2008-2011 Return Infinity -- see LICENSE.TXT
4 //
5 // The BareMetal OS C library code.
6 //
7 // Version 2.0
8 //
9 // This allows for a C program to access OS functions available in BareMetal OS
11 // Compile:
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
15 // Link:
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)
66 unsigned char chr;
67 asm volatile ("call *0x00100058" : "=a" (chr));
68 return chr;
72 unsigned char b_input_wait_for_key(void)
74 unsigned char chr;
75 asm volatile ("call *0x00100068" : "=a" (chr));
76 return chr;
80 unsigned long b_input_string(unsigned char *str, unsigned long nbr)
82 unsigned long len;
83 asm volatile ("call *0x00100078" : "=c" (len) : "c"(nbr), "D"(str));
84 return len;
88 unsigned long b_string_length(unsigned char *str)
90 unsigned long len;
91 asm volatile ("call *0x001000D8" : "=c" (len) : "S"(str));
92 return len;
96 unsigned long b_string_find_char(unsigned char *str, unsigned char chr)
98 unsigned long pos;
99 asm volatile ("call *0x001000E8" : "=a" (pos) : "a"(chr), "S"(str));
100 return pos;
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)
118 unsigned long tlong;
119 asm volatile ("call *0x00100188" : "=a"(tlong) : "S"(str));
120 return tlong;
124 void b_delay(unsigned long nbr)
126 asm volatile ("call *0x00100088" : : "a"(nbr));
130 unsigned long b_get_argc()
132 unsigned long tlong;
133 asm volatile ("call *0x00100268" : "=a"(tlong));
134 return tlong;
138 char* b_get_argv(unsigned char nbr)
140 char* tchar;
141 asm volatile ("call *0x00100278" : "=S"(tchar) : "a"(nbr));
142 return tchar;
146 unsigned long b_get_timercounter(void)
148 unsigned long tlong;
149 asm volatile ("call *0x001002A8" : "=a"(tlong));
150 return 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)
168 unsigned char chr;
169 asm volatile ("call *0x00100248" : "=a" (chr));
170 return 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)
194 unsigned long tlong;
195 asm volatile ("call *0x00100218" : "=a"(tlong) : "a"(ptr), "S"(var));
196 return tlong;
200 unsigned long b_smp_dequeue(unsigned long *var)
202 unsigned long tlong;
203 asm volatile ("call *0x00100228" : "=a"(tlong), "=D"(var));
204 return tlong;
208 void b_smp_run(unsigned long ptr)
210 asm volatile ("call *0x00100358" : : "a"(ptr));
214 unsigned long b_smp_queuelen(void)
216 unsigned long tlong;
217 asm volatile ("call *0x00100288" : "=a"(tlong));
218 return 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()
242 unsigned long tlong;
243 asm volatile ("call *0x00100208" : "=a"(tlong));
244 return tlong;
248 unsigned long b_smp_numcores(void)
250 unsigned long tlong;
251 asm volatile ("call *0x001003F8" : "=a"(tlong));
252 return 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)
286 unsigned long tlong;
287 asm volatile ("call *0x001003B8" : "=c"(tlong) : "D"(mem));
288 return tlong;
291 unsigned long b_ethernet_avail()
293 unsigned long tlong;
294 asm volatile ("call *0x00100418" : "=a"(tlong));
295 return tlong;
299 // =============================================================================
300 // EOF