Andy-Python-Programmer / aero

Aero is a new modern, experimental, UNIX-like operating system following the monolithic kernel design. Supporting modern PC features such as long mode, 5-level paging, and SMP (multicore), to name a few.
https://aero.andypy.dev
GNU General Public License v3.0
1.17k stars 50 forks source link

How do I create libararies?? #9

Closed YusufKhan-gamedev closed 2 years ago

YusufKhan-gamedev commented 2 years ago

How would I go about compiling for this esteemed operating system that you intend on supporting till you die on linux? And how would I create libraries(like a libc) for it? And how would that work when I want to port c code for it? How would I access syscalls in c?

Thanks for any help you give me.

Andy-Python-Programmer commented 2 years ago

How would I go about compiling for this esteemed operating system that you intend on supporting till you die on linux?

I don't really know what you mean by that you intend on supporting till you die on linux but if you want to compile and run it in an emulator (example Qemu) or real hardware its relatively simple process and is described in the README.md too:

cc https://github.com/Andy-Python-Programmer/aero#how-to-build-and-run-aero

How would I create libraries (like a libc) for it?

Currently Aero uses mlibc (cc its patch in patches/mlibc/mlibc.patch) as it's libc for userland applications as described in bootstrap.yml but if you would like to create another libc just for Aero itself you would make it just like one would make a libc for any other operating system.

How would that work when I want to port c code for it?

Assuming you are asking how do I port applications to Aero (for example nyancat) here are the following steps:

Note: The sysroot build process might change overtime since I am trying to find the best way to structure it and introduction to more device drivers will require change to the sysroot build process. I will keep this issue updated about this.

How would I access syscalls in c?

So, it depends on the number of arguments that the syscall takes. You can always do syscall_6 but that will not be efficient. Here is how syscall_6 (syscall with 6 six arguments will look):

long syscalln6(uint64_t call, uint64_t arg0, uint64_t arg1, uint64_t arg2, uint64_t arg3, uint64_t arg4, uint64_t arg5) {
    volatile long ret;
    register uint64_t arg3r asm("r10") = arg3;
    register uint64_t arg4r asm("r9") = arg4;
    register uint64_t arg5r asm("r8") = arg5;
    asm volatile("syscall"
                 : "=a"(ret)
                 : "a"(call), "D"(arg0), "S"(arg1), "d"(arg2), "r"(arg3r), "r"(arg4r), "r"(arg5r)
                 : "memory");
    return ret;
}

Where syscalln6(SYSCALL_ID, args...). Here is the place where we define these helper syscall functions in mlibc https://github.com/Andy-Python-Programmer/aero/blob/cfc97ec5626eb797899a2d4a6c1404b16b0b9a73/patches/mlibc/mlibc.patch#L696 if you want to take a look.

We also do it in aero_syscall which is used by aero_shell currently to invoke syscalls https://github.com/Andy-Python-Programmer/aero/blob/cfc97ec5626eb797899a2d4a6c1404b16b0b9a73/src/aero_syscall/src/syscall.rs#L1