972
edits
[unchecked revision] | [unchecked revision] |
m (Bot: Replace deprecated source tag with syntaxhighlight) |
|||
(22 intermediate revisions by 11 users not shown) | |||
Line 1:
{{Disputed|Talk:D Bare Bones}}
{{TutorialExplain}}
{{BeginnersWarning}}
{{Rating|1}}{{Template:Kernel designs}}
==Preface==
Line 19 ⟶ 20:
==start.asm==
<
global start
extern
extern start_ctors, end_ctors, start_dtors, end_dtors
Line 39 ⟶ 40:
dd CHECKSUM
STACKSIZE equ 0x4000 ;
static_ctors_loop:
Line 57 ⟶ 58:
push ebx
call
static_dtors_loop:
Line 80 ⟶ 81:
resb STACKSIZE
</syntaxhighlight>
Assemble that with:
<
==kernel.main.d==
<
module kernel.main;
import core.volatile;
extern(C) void
▲ ubyte* vidmem = cast(ubyte*)0xFFFF8000000B8000; //Video memory address
▲ for (int i = 0; i < COLUMNS * LINES * 2; i++) { //Loops through the screen and clears it
▲ volatile *(vidmem + i) = 0;
}
for (;;) { //Loop forever. You can add your kernel logic here▼
▲ volatile *(vidmem + (xpos + ypos * COLUMNS) * 2) = 'D' & 0xFF; //Prints the letter D
▲ volatile *(vidmem + (xpos + ypos * COLUMNS) * 2 + 1) = 0x07; //Sets the colour for D to be light grey (0x07)
▲ for (;;) { //Loop forever. You can add your kernel logic here
}
}
</syntaxhighlight>
You then compile that with:
<
==linker.ld==
<syntaxhighlight lang="c">
OUTPUT_FORMAT(elf32-i386)
ENTRY (start)
Line 137 ⟶ 136:
start_ctors = .; *(.ctors) end_ctors = .;
start_dtors = .; *(.dtors) end_dtors = .;
}
Line 149 ⟶ 147:
end = .; _end = .; __end = .;
}
</syntaxhighlight>
Now finally you can link all of that with:
<
Your kernel is now kernel.bin, and can now be booted by grub
<syntaxhighlight lang="bash">qemu-system-i386 -kernel kernel.bin</syntaxhighlight>
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.
Hopefully this has gotten you started on writing your operating system in the D programming language.
== Further reading ==
[[D_Bare_Bones_II|Creating a minimal output to the console]]
[[D_barebone_with_ldc2|D BareBone with 64 bit and ldc2]]
[[Category:Bare bones tutorials|D bare bones]]
[[Category:D]]
|