D Bare Bones II: Difference between revisions

m
Bot: Replace deprecated source tag with syntaxhighlight
[unchecked revision][unchecked revision]
(Created page with "{{TutorialExplain}} {{BeginnersWarning}} {{Rating|1}}{{Template:Kernel designs}} In this Tutorial, we will continue to write the kernel in D, making a basic output to the cons...")
 
m (Bot: Replace deprecated source tag with syntaxhighlight)
 
(4 intermediate revisions by 3 users not shown)
Line 13:
==start.asm==
 
<sourcesyntaxhighlight lang="asm">
 
global start
extern mainkmain ; Allow mainkmain() to be called from the assembly code
extern start_ctors, end_ctors, start_dtors, end_dtors
 
Line 74:
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): // We denote that all functions in our file will have the extern(C) flag
Line 91:
 
// Creating variables to indicate the cursor position.
// All global dynamic variables need to be marked with the shared flag, because there is no TLS in our kernel
shared int xpos = 0;
shared int ypos = 0;
Line 129 ⟶ 130:
}
void mainkmain(uint magic, uint addr) {
puts("Hello, world".ptr); // Output "Hello, world!" to the console
Line 137 ⟶ 138:
}
}
</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 176 ⟶ 177:
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>
 
[[Category:Bare bones tutorials|D bare bones]]