Browse Source

Call C function

compile-me
garritfra 5 years ago
parent
commit
6e1f7d5351
  1. 3
      .gitignore
  2. 22
      kmain.c
  3. 8
      loader.s

3
.gitignore vendored

@ -2,4 +2,5 @@ boot.bin
dittoOS.img
**/*.o
**/*.elf
**/*.iso
**/*.iso
bochslog.txt

22
kmain.c

@ -1,9 +1,27 @@
void fb_write_cell(unsigned int i, char c, unsigned char fg, unsigned char bg);
int main() {
fb_write_cell(0, 'A', 2, 8);
return 0;
}
int sum_of_three(int arg1, int arg2, int arg3) {
return arg1 + arg2 + arg3;
/** fb_write_cell:
* Writes a character with the given foreground and background to position i
* in the framebuffer.
*
* @param i The location in the framebuffer
* @param c The character
* @param fg The foreground color
* @param bg The background color
*
* @example fb_write_cell(0, 'A', 2, 8);
*/
void fb_write_cell(unsigned int i, char c, unsigned char fg, unsigned char bg) {
char *fb = (char *) 0x000B8000;
fb[i] = c;
fb[i + 1] = ((fg & 0x0F) << 4) | (bg & 0x0F);
}
struct example {

8
loader.s

@ -1,5 +1,5 @@
global loader ; the entry symbol for ELF
extern sum_of_three
extern main
MAGIC_NUMBER equ 0x1BADB002 ; define the magic number constant
FLAGS equ 0x0 ; multiboot flags
@ -24,10 +24,6 @@ loader: ; the loader label (defined as entry point in li
mov esp, kernel_stack + KERNEL_STACK_SIZE ; point esp to the start of the
; stack (end of memory area)
push dword 3 ; arg3
push dword 2 ; arg2
push dword 1 ; arg1
call sum_of_three ; call the function, the result will be in eax
call main
.loop:
jmp .loop ; loop forever
Loading…
Cancel
Save