Hi, I'm trying to convert my basic 32 bit kernel to a 64 bit version.
I'm developing it on an AMD64 pc, on Linux Mandrake 2005 LE using GCC 4.0.2 (including "ld") and YASM 0.4.0 (I know at this point NASM doesn't support 64 bit code generation).
The problem is that if I use assembling, compiling and linking attributes and output formats to generate a standard x86 (32 bit) kernel, it works, but if I want to generate an x86-64 version, I obtain a not working kernel.
To give more info, here there are the kernel building steps in my makefile, where the first line is the command to produce object file for 32 bit architecture, while the second (prefixed with a '#' is to generate x86-64:
1) ASSEMBLING entry file "entry.asm"
yasm -a x86 -m x86 -f elf32 entry.asm -o entry.o
#yasm -a x86 -m amd64 -f elf64 entry.asm -o entry.o
2) COMPILING input C files "main.c", "kernel.c", "io.c" and "language.c"
gcc -c -m32 main.c kernel.c io.c language.c -ffreestanding -fomit-frame-pointer -finline-functions -nostdlib -fno-builtin -fno-exceptions
#gcc -c -m64 main.c kernel.c io.c language.c -ffreestanding -fomit-frame-pointer -nostdlib -fno-builtin -fno-exceptions
3) LINKING ALL using a script linker named "link.ld"
ld -m elf_i386 -T link.ld -o kernel.bin entry.o main.o kernel.o io.o language.o
#ld -m elf_x86_64 -T link.ld -o kernel.bin entry.o main.o kernel.o io.o language.o
Note that if in the linker script I use the value "elf_x86_64" as the directive OUTPUT_FORMAT parameter, the 32 kernel code obtained works without any problem, but using the value "elf64-x86-64", generate a 1 MB sized 64 bit kernel code not working at all.
When I initially developed the 32 bit version using DJGPP on Win, I used as assembling format (for YASM), the COFF format. But under Linux (maybe the newest version of GCC), "ld" doesn't recognize this format for linking, so I'm now working with ELF format.
Any suggestions, will be well accepted, thanks.
Hurrikam
Developing an x86-64 OS kernel
- intel_breaker
- Member
- Posts: 46
- Joined: Tue Jan 04, 2005 12:00 am
- Location: Poland
- Contact:
Re: Developing an x86-64 OS kernel
I think, that entry.asm should be 32bit compiled, it must switch into long mode and jmp into the 64bit kernel. (i've never develope 64bit kernel, this is only my suggetsion)
Re: Developing an x86-64 OS kernel
yes, you must enter LM before using any x86-64 extensions, however it is possible to skip PM and go straight into LM (not sure myself but brandon(?) over at MT found a way that seems fairly reliable)
note: neither the MNB (aka: XD/NE/DEP) nor the extended physical address space are x86-64, and both can be used in PM
if this is already accounted for, try checking that your initializing LM correctly
note: neither the MNB (aka: XD/NE/DEP) nor the extended physical address space are x86-64, and both can be used in PM
if this is already accounted for, try checking that your initializing LM correctly