A question about 64 bit kernel linking

Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
Post Reply
nbdd0121
Member
Member
Posts: 60
Joined: Thu Jul 25, 2013 8:10 am

A question about 64 bit kernel linking

Post by nbdd0121 »

Currently I am coding a 64 bit kernel, so I added "-mcmodel-large" to the cflags, and it works fine. Because in assembly, every 64 bit immediate number should be stored in general registers first because the only command taking imm64 is "mov GPR, imm64". As a result, my kernel became very big. When I only added a printf function to the kernel, the kernel became 3KB larger. I came up an idea that to use -fPIC instead of -mcmodel-large to compile the kernel. It works fine, but I wondered if the usage will cause any potential problem, because it seems that every solution given by the Internet said "use mcmodel option". What's your opinion?
User avatar
Combuster
Member
Member
Posts: 9301
Joined: Wed Oct 18, 2006 3:45 am
Libera.chat IRC: [com]buster
Location: On the balcony, where I can actually keep 1½m distance
Contact:

Re: A question about 64 bit kernel linking

Post by Combuster »

If you can use either the regular or kernel memory model, you don't lose bytes and cycles to indirect address calculations typical of PIC, even though it is still more efficient compared to the large memory model. Efficiency and practicality is basically the reason why you'll find all of the examples using -mcmodel=kernel. Consider why you actually need arbitrary kernel placement, and perhaps related, what paging doesn't solve for you already.

Beyond that, there's no fundamental reason why PIC shouldn't work that I can think of.
"Certainly avoid yourself. He is a newbie and might not realize it. You'll hate his code deeply a few years down the road." - Sortie
[ My OS ] [ VDisk/SFS ]
Post Reply