D Bare Bones: Difference between revisions

Jump to navigation Jump to search
update D code to use volatileStore and update commands to assume a non-i386 compilation environment
[unchecked revision][unchecked revision]
No edit summary
(update D code to use volatileStore and update commands to assume a non-i386 compilation environment)
Line 90:
<source lang="d">
module kernel.main;
import core.bitop; // will be core.volatile in later gdc
 
extern(C) void main(uint magic, uint addr) {
int ypos = 0; //Starting points of the cursor
int xpos = 0;
const uint COLUMNS = 80; //Screensize
const uint LINES = 25;
 
ubyte* vidmem = cast(ubyte*)0xFFFF_8000_000B_8000; //Video memory address
 
for (int i = 0; i < COLUMNS * LINES * 2; i++) { //Loops through the screen and clears it
volatile *volatileStore(vidmem + i) =, 0);
}
 
volatile *volatileStore(vidmem + (xpos + ypos * COLUMNS) * 2) =, 'D' & 0xFF); //Prints the letter D
volatile *volatileStore(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
}
Line 113 ⟶ 114:
You then compile that with:
 
<source lang="bash">gdc -fno-druntime -m32 -c kernel.main.d -o kernel.main.o -g</source>
 
==linker.ld==
Line 153 ⟶ 154:
Now finally you can link all of that with:
 
<source lang="bash">ld -melf_i386 -T linker.ld -o kernel.bin start.o kernel.main.o</source>
 
Your kernel is now kernel.bin, and can now be booted by grub., or run in qemu:
 
<source lang="bash">qemu-system-i386 -kernel kernel.bin</source>
Your kernel is now kernel.bin, and can now be booted by grub.
 
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.
Keep in mind that to add other classes, functions, enums, etc. You must add the D runtime.
 
Hopefully this has gotten you started on writing your operating system in the D programming language.
Anonymous user
Cookies help us deliver our services. By using our services, you agree to our use of cookies.

Navigation menu