Discussion:
Windows drivers written in D
marisalovesusall via Digitalmars-d
2014-10-13 18:16:06 UTC
Permalink
D is a system programming language, so is it possible to write
drivers in D?
Windows drivers, as example, or Linux.
Piotrek via Digitalmars-d
2014-10-13 20:58:45 UTC
Permalink
On Monday, 13 October 2014 at 18:16:08 UTC, marisalovesusall
Post by marisalovesusall via Digitalmars-d
D is a system programming language, so is it possible to write
drivers in D?
Windows drivers, as example, or Linux.
In short: You can write in D everything you can in C. And there
is good place called D.Learn for starters.


Anyway, with all sympathy I have, please use google for it.

E.g
http://stackoverflow.com/questions/2222763/how-should-i-get-started-on-writing-device-drivers

"Writing a device driver can be pretty simple, or it can be
almost arbitrarily complicated. For instance, I've been involved
in a project where it took six of us almost three years to solve
ONE bug in a device driver. "

I do writing/debugging drivers on my daily basis. Rewarding, fun,
frustrating... So go for it. D has additional bonus as good
looking syntax/modules etc.

BTW. Don't use Windows and Linux in the same sentence ;) Drivers
are platform specific if you pass register map step.

Please share what you achieved. Wringing drivers is for the elite
;)

Piotrek
eles via Digitalmars-d
2014-10-13 21:50:18 UTC
Permalink
On Monday, 13 October 2014 at 18:16:08 UTC, marisalovesusall
Post by marisalovesusall via Digitalmars-d
D is a system programming language, so is it possible to write
drivers in D?
Windows drivers, as example, or Linux.
See those links, with the mention that thy are quite outdated.
But is better than nothing:

http://iainbuclaw.wordpress.com/2010/05/22/writing-a-linux-kernel-module-in-d/

http://wiki.osdev.org/D_Bare_Bones

Short answer is: yes, you cand write, but you cannot compile.
Until most of D's runtime/stdlib is replaced by some Linux kernel
equivalent, just as the C's ones are.

In the case of D, full port is far harder than of C, due to more
complexity.
Piotrek via Digitalmars-d
2014-10-13 23:28:04 UTC
Permalink
Post by eles via Digitalmars-d
Short answer is: yes, you cand write, but you cannot compile.
Wait, what? Do you mean link or maybe load? I don't write Linux
kernel modules, but I bet you can get it working.

Check out the "betterC" switch to get away with runtime
dependences. There were some post related to minimal executables
recently.

Piotrek
eles via Digitalmars-d
2014-10-14 05:51:09 UTC
Permalink
Post by Piotrek via Digitalmars-d
Post by eles via Digitalmars-d
Short answer is: yes, you cand write, but you cannot compile.
Wait, what? Do you mean link or maybe load? I don't write Linux
kernel modules, but I bet you can get it working.
Check out the "betterC" switch to get away with runtime
dependences. There were some post related to minimal
executables recently.
Piotrek
Yes, I should have a second look at betterC
Dan Olson via Digitalmars-d
2014-10-14 08:48:23 UTC
Permalink
Post by eles via Digitalmars-d
Post by Piotrek via Digitalmars-d
Post by eles via Digitalmars-d
Short answer is: yes, you cand write, but you cannot compile.
Wait, what? Do you mean link or maybe load? I don't write Linux
kernel modules, but I bet you can get it working.
Check out the "betterC" switch to get away with runtime
dependences. There were some post related to minimal executables
recently.
Piotrek
Yes, I should have a second look at betterC
I have time for D again! I was able to create a basic OSX kernel
extension in Xcode and then substitude the C code with a .o file
compiled by dmd. There was no reason it shouldn't work but I wanted to
see it for myself. This is a long way from a driver that interacts with
hardware, but hey, entertainment on a rainy night.

It started with this tutorial:

https://developer.apple.com/library/mac/documentation/Darwin/Conceptual/KEXTConcept/KEXTConceptKEXT/kext_tutorial.html#//apple_ref/doc/uid/20002365

Then

$ dmd -release -betterC -c hellokextd.d

add hellokextd.o to the project, removed the C src, rebuild, and
kextutil into the kernel.
Post by eles via Digitalmars-d
From kernel logs
10/14/14 1:00:09.000 AM kernel[0]: Hello from D sample driver

---- hellokextd.d ----
extern (C):

enum KERN_SUCCESS = 0;
alias kmod_info_t = void;
alias kern_return_t = int;

int printf(const(char)* fmt, ...) nothrow;

// stub out a few unresolved druntime symbols
void _d_arraybounds(string msg, uint line) {}
void _d_assert(string msg, uint line) {}
void _d_unittest(string msg, uint line) {}

kern_return_t MyKext_start(kmod_info_t * ki, void *d)
{
printf("Hello from D sample driver\n");
return KERN_SUCCESS;
}

kern_return_t MyKext_stop(kmod_info_t *ki, void *d)
{
printf("Bye from D sample driver\n");
return KERN_SUCCESS;
}
--
dano
eles via Digitalmars-d
2014-10-14 13:37:18 UTC
Permalink
Post by Piotrek via Digitalmars-d
Check out the "betterC" switch to get away with runtime
A hand here?:

http://forum.dlang.org/post/spgdillzvmnvskyzqaqs at forum.dlang.org
Loading...