My OS BareMetal is written in x86-64 assembly and I would like to get C programs to access to OS system calls.
How can I pass the needed information in C to my OS? The assembly os_print_string function takes a string at address RSI.
Does this code look ok? Or is there a better way to do it?
Code: Select all
// gcc -o testc.o -c testc.c -m64 -nostdlib -nostartfiles -nodefaultlibs -O2 -fomit-frame-pointer
// ld -T app.ld -o testc.bin testc.o
void printstring(char* string);
int main(void)
{
char *str = "Hello world, from C!";
printstring (str); // Print the string using the OS system call.
return 0;
}
// os_print_string -- Displays text
// IN: RSI = message location (zero-terminated string)
// OUT: All registers perserved
void printstring(char* string)
{
asm("nop"); // To see if we get here. Debug this to see how the string address is passed. Move to RSI if needed.
asm("jmp 0x00020010"); // A link to os_print_string is at this address
}
Code: Select all
char *str = "Hello world, from C!", *ch;
unsigned short *vidmem = (unsigned short*) 0xb8000;
unsigned i;
for (ch = str, i = 0; *ch; ch++, i++)
{
vidmem[i] = (unsigned char) *ch | 0x0700;
}