writing 64bit kernel using c++ !

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
weezo
Posts: 9
Joined: Wed Jul 23, 2008 4:33 am
Location: Egypt

writing 64bit kernel using c++ !

Post 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 !
User avatar
JamesM
Member
Member
Posts: 2935
Joined: Tue Jul 10, 2007 5:27 am
Location: York, United Kingdom
Contact:

Re: writing 64bit kernel using c++ !

Post by JamesM »

Google. Wiki.
weezo
Posts: 9
Joined: Wed Jul 23, 2008 4:33 am
Location: Egypt

Re: writing 64bit kernel using c++ !

Post 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
gerryg400
Member
Member
Posts: 1801
Joined: Thu Mar 25, 2010 11:26 pm
Location: Melbourne, Australia

Re: writing 64bit kernel using c++ !

Post 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.
If a trainstation is where trains stop, what is a workstation ?
User avatar
JamesM
Member
Member
Posts: 2935
Joined: Tue Jul 10, 2007 5:27 am
Location: York, United Kingdom
Contact:

Re: writing 64bit kernel using c++ !

Post 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.
TylerH
Member
Member
Posts: 285
Joined: Tue Apr 13, 2010 8:00 pm
Contact:

Re: writing 64bit kernel using c++ !

Post 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.
TylerH
Member
Member
Posts: 285
Joined: Tue Apr 13, 2010 8:00 pm
Contact:

Re: writing 64bit kernel using c++ !

Post 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.
gerryg400
Member
Member
Posts: 1801
Joined: Thu Mar 25, 2010 11:26 pm
Location: Melbourne, Australia

Re: writing 64bit kernel using c++ !

Post by gerryg400 »

I use uintptr_t. You can set and clear bits (like the paging bits) without casting.
If a trainstation is where trains stop, what is a workstation ?
TylerH
Member
Member
Posts: 285
Joined: Tue Apr 13, 2010 8:00 pm
Contact:

Re: writing 64bit kernel using c++ !

Post 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?
Fanael
Member
Member
Posts: 38
Joined: Fri Oct 16, 2009 9:20 am

Re: writing 64bit kernel using c++ !

Post 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.
gerryg400
Member
Member
Posts: 1801
Joined: Thu Mar 25, 2010 11:26 pm
Location: Melbourne, Australia

Re: writing 64bit kernel using c++ !

Post 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.
If a trainstation is where trains stop, what is a workstation ?
gerryg400
Member
Member
Posts: 1801
Joined: Thu Mar 25, 2010 11:26 pm
Location: Melbourne, Australia

Re: writing 64bit kernel using c++ !

Post 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.
If a trainstation is where trains stop, what is a workstation ?
Fanael
Member
Member
Posts: 38
Joined: Fri Oct 16, 2009 9:20 am

Re: writing 64bit kernel using c++ !

Post 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).
Fanael
Member
Member
Posts: 38
Joined: Fri Oct 16, 2009 9:20 am

Re: writing 64bit kernel using c++ !

Post 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.
gerryg400
Member
Member
Posts: 1801
Joined: Thu Mar 25, 2010 11:26 pm
Location: Melbourne, Australia

Re: writing 64bit kernel using c++ !

Post 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. 不正確でした。
If a trainstation is where trains stop, what is a workstation ?
Post Reply