-
Notifications
You must be signed in to change notification settings - Fork 1.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
lesson 01, How CPU find kernel_main in kernel.c from boot.S #225
Comments
Notice in this file, https://github.com/s-matyukevich/raspberry-pi-os/blob/master/src/lesson01/src/mm.S how the function memzero is defined, that can be called from C. |
I think xubenji question might actually be about calling C functions from assembly files (not the other way around). Most of the time one would need to include the C header in the assembly file in order to call a function. That said, I don't know how the boot.S file (https://github.com/s-matyukevich/raspberry-pi-os/blob/master/src/lesson01/src/boot.S) is able to call kernel_main without including any header that contains a reference to it. |
Ok yeah if that's the case, there isn't really any need to pre-define it for the assembly code to use it. It just references a symbol by the given name and then the linker will try to find it. For instance, if you rename the function kernel_main2 and then try to rebuild, it will fail during the linking process as the symbol won't be found. |
If I change the kernel_mian() to kernel_main2(). What I have to do to let the linker find the new function name? |
Yes, It is what I thought |
The linker will know the name change because it sees the function name in the symbols list. So as long as you change it in your .c file and your .S file then you will be good. |
It seems like I don't have to do too many operations. But, If the CPU wants to call some functions in .S files from .c files, we need to add the necessary header files, right? In this files, https://github.com/s-matyukevich/raspberry-pi-os/blob/master/src/lesson01/src/mini_uart.c. I find it includes the function name which locals in utils.S |
Yes. In C, the compiler needs to know how to call the functions. In assembler, you have to make sure yourself that you are calling the functions correctly. |
Hi, developers. I am a beginner in developing operating systems. Before, I have learned how to develop OS in X86. Each time, in assembly files, if I want the CPU to call a certain function in .c files from assembly files, I have to include the keyword 'extern'. If I want the CPU to call a function in assembly files from C files, I have to include 'global'. But, in ARM assembly, I can't find any keyword to indicate the C function in .s files. So I really want to find the answer. Thank you.
The text was updated successfully, but these errors were encountered: