Hi guys. I have been roaming in the forums quietly and just decided to restart my OS (despite not achieving much with it). So right now I am more or less using the Meaty Skeleton.
Anyways, I have been playing around with my OS. Maybe to a point of not being productive, and in my 'adventures' I bumped into an issue which I have somehow resolved, but I am still not sure why it happened and if my fix works (in the sense that the function I copied over works)
I have copied over this code from the inline assembly examples:
Code: Select all
static inline uint64_t rdtsc()
{
uint64_t ret;
asm volatile ( "rdtsc" : "=A"(ret) );
return ret;
}
I placed it in kernel/arch/i386/io.c (I notice this is not really io related function, and will rename it later). Additionally, the file solely contains this function (and a few necessary includes), and I also added io.h along with the other headers, which contains a few includes and the function declaration. For some reason, it failed, with the make process failing due to rdtsc() not being declared, despite having included io.h in the kernel and io.c being compiled and linked. After checking the object file, I discovered it does not contain the function (Practically empty save a few functions for debugging purposes judging from the names, probably those that are added into all object files by GCC). I had to edit the function declaration to the following before the object file contained the function and the make process worked.
My questions are these: Why didn't the object file contain the function initially, what is the effect of me removing static and inline (I am familiar with these two keywords, but I do not understand why do they have to be added to the function declaration) and lastly, is there a better way for me to add this function (I am thinking of just stuffing everything into io.h, but not very sure if it works or even a good way to do so)?
I do understand this might be quite simple, but I do not get it, and hope if you guys can provide me with some knowledge about this issue. Thanks.