Creating a 64-bit kernel: Difference between revisions
Jump to navigation
Jump to search
[unchecked revision] | [unchecked revision] |
Content deleted Content added
→Compiling: -mcmodel=large is discouraged; check the SysV AMD64 ABI spec |
→Compiling: Do not use SSE ops, or several #UD and #NM exceptions will get triggered |
||
Line 25: | Line 25: | ||
Linking will be done later... |
Linking will be done later... |
||
<source lang="bash">gcc \ |
|||
<source lang="bash">x86_64-pc-elf-gcc -ffreestanding -mcmodel=large -mno-red-zone -nostdlib <other options> -c -o <object file> <source file></source> |
|||
-m64 \ |
|||
-ffreestanding \ |
|||
-nostdlib \ |
|||
-mcmodel=large \ |
|||
-mno-red-zone \ |
|||
-mno-mmx \ |
|||
-mno-sse \ |
|||
-mno-sse2 \ |
|||
-mno-sse3 \ |
|||
-mno-3dnow \ |
|||
<other options> \ |
|||
-c -o <object file> <source file></source> |
|||
The -mcmodel=large argument enables us to run the kernel at any 64-bit virtual memory address we want (only in GCC 4.3+), and -nostdlib makes sure that GCC doesn't add any userspace-dependent code to our kernel. In fact, using the 'large' code model is discouraged due to its inefficiency, but it can be fine as a start. Check the SysV AMD64 ABI document for extra details. |
The -mcmodel=large argument enables us to run the kernel at any 64-bit virtual memory address we want (only in GCC 4.3+), and -nostdlib makes sure that GCC doesn't add any userspace-dependent code to our kernel. In fact, using the 'large' code model is discouraged due to its inefficiency, but it can be fine as a start. Check the SysV AMD64 ABI document for extra details. |
||
You will need to instruct GCC not to use the the AMD64 ABI 128-byte 'red zone', which resides below the stack pointer, or your kernel will be ''interrupt unsafe''. Check this [http://forum.osdev.org/viewtopic.php?t=21720 thread] on the forums for extra context. |
You will need to instruct GCC not to use the the AMD64 ABI 128-byte 'red zone', which resides below the stack pointer, or your kernel will be ''interrupt unsafe''. Check this [http://forum.osdev.org/viewtopic.php?t=21720 thread] on the forums for extra context. |
||
We disable [[SSE]] floating point ops. They need special %cr0 and %cr4 setup that we're not ready for. Otherwise, several #UD and #NM exceptions will be triggered. |
|||
== Linking == |
== Linking == |