Hello! I am writing my own OS. I really liked MikeOS, but it is all in assembly language. I'm trying to make my own. There is an assembly code:

BITS 16 extern main start: mov ax, 07C0h add ax, 288 mov ss, ax mov sp, 4096 mov ax, 07C0h mov ds, ax mov si, text_string call clear_screen call print_string jmp $ text_string db 'EOS ready', 0 ;call main clear_screen: pusha mov dx, 0 mov ah, 6 mov al, 0 mov bh, 7 mov cx, 0 mov dh, 24 mov dl, 79 int 10h popa ret print_string: mov ah, 0Eh .repeat: lodsb cmp al, 0 je .done int 10h jmp .repeat .done: ret times 510-($-$$) db 0 dw 0xAA55 

This is a pitiful semblance of a system loader. There is also a C code describing the main function.

 #include <stdio.h> extern int main (void) { char* str = "print from C :)"; printf("%s", str); return 0; } 

How is it all glue together? (Mix C and Assembler)?


How to call a function described in a C file in an assembler program? When trying to compile such code:

 void kernel_main(){ ... } ... call kernel_main ... 

writes:

 boot/boot.s:16: error: symbol `kernel_main' undefined 

What should I tell the nasm compiler where this function is?

  • It is unlikely to take off in this form. If you run code like the system loader, you will not have a runtime library available, so you can forget about printf . - VladD
  • As then? Write all the libraries yourself? - user26699
  • What is your use? Tell us what problem you actually solve. - VladD
  • one
    I am writing my own OS. I really liked MikeOS, but it is all in assembly language. I'm trying to make my own. - user26699
  • 2
    Okay, got it. See it. If the OS is under your control, then access to the files and the shared library loader are also in your hands. This means you can load dynamic libraries at the right time. The only question is whether this is all available immediately after working out your assembly part, or the system must first be initialized. - VladD

1 answer 1

 extern void kernel_main(); void kernel_main() {...} 

asm: .globl _kernel_main ....

 call _kernel_main 

This is if you don’t "dig" further, but there are extensive discussions on these issues in the internet, first of all assemblers have different and different keywords used by them, and the most unpleasant is that they are oriented to a specific processor family (intel and arm are not compatible at the level of executable codes ) ... (en) gcc & asm: x86 wasm.ru something strongly under reconstruction something older

  • but still the question remains to start with such difficulties ?! I hope that the heat will not cool, and in addition to the wasp-shirt there are operating systems that would be boring to understand ...
  • ps Sishny runtime can also be used in assembler, if you connect it, the "c" is not so fat, and it is often located in the dynamic library, but the kernels have their own runtime.
  • Okay thank you! Instead of -f bin added -f aout - user26699