Page 1 of 1
writing 64bit kernel using c++ !
Posted: Sat Nov 13, 2010 4:10 am
by weezo
hello everyone
*what steps required to write & compile 64bit kernel using c++ suppose i will write all from scratch ,bootloader,entering long mode and loading the kernel how to compile and link c++ against asm code,command line options ,ld script?
*what about the model i use in c++ coding i want to use LP64 how to use it?
= i read the tutorial about writing 64bit kernel and doing kernel in c++ but i couldnt get them all together
thnx for ur time !
Re: writing 64bit kernel using c++ !
Posted: Sat Nov 13, 2010 12:25 pm
by JamesM
Google. Wiki.
Re: writing 64bit kernel using c++ !
Posted: Sat Nov 13, 2010 2:28 pm
by weezo
thnx for reply but i did search google,wiki but found nothing i dont want to know how to code but how to compile link c++ 64bit code with the 32bit code of my bootstrab+kernel also how to choose the model LP64?
thnx
Re: writing 64bit kernel using c++ !
Posted: Sat Nov 13, 2010 4:54 pm
by gerryg400
LP64 is the default for gcc. So if you use gcc there is nothing to do. Build your cross-compiler and it will work.
You should write your code, including your kernel, in such a way that it is portable between data models. This basically means don't rely on the size of integer types and don't cast pointers to and from ints.
Re: writing 64bit kernel using c++ !
Posted: Sat Nov 13, 2010 9:26 pm
by JamesM
weezo wrote:thnx for reply but i did search google,wiki but found nothing i dont want to know how to code but how to compile link c++ 64bit code with the 32bit code of my bootstrab+kernel also how to choose the model LP64?
thnx
That's because you can't. Look up long mode in the wiki, I think you have your ideas mixed up about compatibility.
Re: writing 64bit kernel using c++ !
Posted: Sat Nov 13, 2010 11:46 pm
by TylerH
You have to specify that your 32bit code be put in a amd64 elf object file, which is opposite the default. Just specify args to the linker telling it to link it as "elf64-x86-64". That should be all.
Re: writing 64bit kernel using c++ !
Posted: Sun Nov 14, 2010 12:55 am
by TylerH
gerryg400 wrote:You should write your code, including your kernel, in such a way that it is portable between data models. This basically means don't rely on the size of integer types and don't cast pointers to and from ints.
My solution for that is to typedef an integral type for physical and virtual offsets. One typedef assures that a * will fit into the integer type, and I get the safety of 1 to 1 "pointer" arithmetic without GCC void* extensions.
Re: writing 64bit kernel using c++ !
Posted: Sun Nov 14, 2010 1:12 am
by gerryg400
I use uintptr_t. You can set and clear bits (like the paging bits) without casting.
Re: writing 64bit kernel using c++ !
Posted: Sun Nov 14, 2010 2:10 am
by TylerH
gerryg400 wrote:I use uintptr_t. You can set and clear bits (like the paging bits) without casting.
Won't all go to hell when and if you decide to use PAE?
Re: writing 64bit kernel using c++ !
Posted: Sun Nov 14, 2010 4:00 am
by Fanael
gerryg400 wrote:LP64 is the default for gcc.
You forgot to mention it's true only for some targets, but not for others.
Re: writing 64bit kernel using c++ !
Posted: Sun Nov 14, 2010 4:52 am
by gerryg400
Fanael wrote:gerryg400 wrote:LP64 is the default for gcc.
You forgot to mention it's true only for some targets, but not for others.
True. I assumed it was a PC because the OP called 64bit mode long mode.
Re: writing 64bit kernel using c++ !
Posted: Sun Nov 14, 2010 5:05 am
by gerryg400
TylerAnon wrote:gerryg400 wrote:I use uintptr_t. You can set and clear bits (like the paging bits) without casting.
Won't all go to hell when and if you decide to use PAE?
You're correct. uintptr_t is not really suitable for physical addresses. Scratch my comment about paging bits.
Re: writing 64bit kernel using c++ !
Posted: Sun Nov 14, 2010 10:50 am
by Fanael
gerryg400 wrote:Fanael wrote:gerryg400 wrote:LP64 is the default for gcc.
You forgot to mention it's true only for some targets, but not for others.
True. I assumed it was a PC because the OP called 64bit mode long mode.
Even on x86-64 LP64 is not always the default, see e.g. x86_64-w64-mingw32 (or however the Win64 MinGW target is called).
Re: writing 64bit kernel using c++ !
Posted: Sun Nov 14, 2010 1:20 pm
by Fanael
berkus wrote:Data models are mostly defined by the OS used. Many compilers stick to LP64 model, but mingw most probably would stick to Windows LLP64 model just because it's the default for target OS.
Yeah, they're defined by the OS. Belive me or not, there really are people who use executable and object file formats other than ELF for their systems. If they use PE, the can either use Win64 MinGW target or (the "proper" way) port the compiler so they'll have their own target. In the former case, they'll get LLP64 model.
But it's not that important, really - my point was that LP64 is not necessarily default. Nothing more.
Re: writing 64bit kernel using c++ !
Posted: Sun Nov 14, 2010 7:58 pm
by gerryg400
Fanael wrote:gerryg400 wrote:Fanael wrote:
You forgot to mention it's true only for some targets, but not for others.
True. I assumed it was a PC because the OP called 64bit mode long mode.
Even on x86-64 LP64 is not always the default, see e.g. x86_64-w64-mingw32 (or however the Win64 MinGW target is called).
Okay, I give up. 不正確でした。