972
edits
[unchecked revision] | [unchecked revision] |
(Remove misleading information.) |
m (Bot: Replace deprecated source tag with syntaxhighlight) |
||
(4 intermediate revisions by 4 users not shown) | |||
Line 15:
=== kernel.c ===
<
void kernel_main(void)
{
/* What goes here is up to you */
}
</syntaxhighlight>
== Compiling ==
Line 26:
Linking will be done later...
<
x86_64-elf-gcc -ffreestanding -mcmodel=large -mno-red-zone -mno-mmx -mno-sse -mno-sse2 -c foo.c -o foo.o
</syntaxhighlight>
The -mcmodel=large argument enables us to run the kernel at any 64-bit virtual memory address we want. In fact, using the 'large' code model is discouraged due to its inefficiency, but it can be fine as a start. Check the [[System V ABI|SysV AMD64 ABI]] document for extra details.
Line 93:
You can link the kernel like this:
<
'''Note''': Obviously there is no bootstrap assembly yet, which is the hard part of starting out, and you can't link without it.
Line 193:
Note that, although nasm will not complain about this, Microsoft link will. It complains about address relocations, due to the memory model settings (/LARGEADDRESSAWARE, which is required for /DRIVER).
As such, you need a method of generating the correct 32 bit code, while fooling link into generating a 64 bit relocation. Here is a macro for you:
<
;Encode 32 bit moves without the ADDR32 issue
%macro mov_abs32 2
Line 221:
;mov_abs32 eax, (gdtr-KADDR_OFFSET)
;lgdt [eax]
</syntaxhighlight>
== Possible Problems ==
Line 252:
[[Category:Tutorials|Creating a 64-bit kernel]]
[[Category:X86-64|Creating a 64-bit kernel]]
[[Category:Kernel]]
|