www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - Example uses "volatile"; compiler says "undefined identifier volatile"

reply Paul <phshaffer gmail.com> writes:
I'm trying to build a Bare Bones 'OS' via example.  Example says 
to compile with
"gdc -c kernel.main.d -o kernel.main.o -g"  I'm having trouble 
getting GDC all set up..as I'm a rank amateur.  So, I tried 
compiling the example below with DMD.  DMD spits out exceptions 
to the use of 'volatile'. DIP62 on D wiki says status:REJECTED 
for volatile.
Whats my work around here?  This is what I'm trying to do-> 
https:// wiki.osdev.org / D_Bare_Bones

Thanks for any help.

module kernel.main;

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 *(vidmem + i) = 0;
	}

	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
	}
}
Jul 31 2019
parent reply Timo Sintonen <t.sintonen luukku.com> writes:
On Thursday, 1 August 2019 at 03:04:27 UTC, Paul wrote:
 I'm trying to build a Bare Bones 'OS' via example.  Example 
 says to compile with
 "gdc -c kernel.main.d -o kernel.main.o -g"  I'm having trouble 
 getting GDC all set up..as I'm a rank amateur.  So, I tried 
 compiling the example below with DMD.  DMD spits out exceptions 
 to the use of 'volatile'. DIP62 on D wiki says status:REJECTED 
 for volatile.
 Whats my work around here?  This is what I'm trying to do-> 
 https:// wiki.osdev.org / D_Bare_Bones

 Thanks for any help.

 module kernel.main;

 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 *(vidmem + i) = 0;
 	}

 	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
 	}
 }
Accesses to peripheral regiters or memory need to be marked volatile. This tells the compiler that these operations have some other meaning than just store and load the data. Otherwise the compiler may reorder or remove operations. Unfortunately the volatile feature was removed from the language some years ago. Instead, there are volatileLoad and volatileStore in core.bitop. A simple program may work if all volatile words are just omitted and the program is compiled with all optimizations turned off. I made Volatile data type to access peripheral registers, you can see it here: https://bitbucket.org/timosi/minlibd/src/default/tools/main/volatil3.d
Jul 31 2019
parent Paul <phshaffer gmail.com> writes:
Thank you.  I'll try that.
Aug 01 2019