D Bare Bones: Difference between revisions

m
Bot: Replace deprecated source tag with syntaxhighlight
[unchecked revision][unchecked revision]
(Fix D Bare bones: you can't pass non-standard arguments to void main())
m (Bot: Replace deprecated source tag with syntaxhighlight)
 
(2 intermediate revisions by 2 users not shown)
Line 20:
==start.asm==
 
<sourcesyntaxhighlight lang="asm">
 
global start
Line 81:
resb STACKSIZE
 
</syntaxhighlight>
</source>
 
Assemble that with:
 
<sourcesyntaxhighlight lang="bash">nasm -f elf -o start.o start.asm</sourcesyntaxhighlight>
 
==kernel.main.d==
<sourcesyntaxhighlight lang="d">
module kernel.main;
import core.bitopvolatile;
extern(C) void kmain(uint magic, uint addr) {
Line 107:
}
}
</syntaxhighlight>
</source>
 
You then compile that with:
 
<sourcesyntaxhighlight lang="bash">gdc -fno-druntime -m32 -c kernel.main.d -o kernel.main.o -g</sourcesyntaxhighlight>
 
==linker.ld==
<sourcesyntaxhighlight lang="c">
OUTPUT_FORMAT(elf32-i386)
ENTRY (start)
Line 147:
end = .; _end = .; __end = .;
}
</syntaxhighlight>
</source>
 
Now finally you can link all of that with:
 
<sourcesyntaxhighlight lang="bash">ld -melf_i386 -T linker.ld -o kernel.bin start.o kernel.main.o</sourcesyntaxhighlight>
 
Your kernel is now kernel.bin, and can now be booted by grub, or run in qemu:
 
<sourcesyntaxhighlight lang="bash">qemu-system-i386 -kernel kernel.bin</sourcesyntaxhighlight>
 
Note the "-fno-druntime" argument above. This is how gdc spells the -betterC flag from other D compilers, and the "Better C" page of the D language reference explains how this limits the language. If you want to drop that you'll have to add the D runtime to your kernel.