Developing an x86-64 OS kernel
Posted: Wed Dec 28, 2005 12:00 am
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
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