www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - Windows drivers written in D

reply "marisalovesusall" <marisalovesusall gmail.com> writes:
D is a system programming language, so is it possible to write
drivers in D?
Windows drivers, as example, or Linux.
Oct 13 2014
next sibling parent "Piotrek" <p nonexistent.pl> writes:
On Monday, 13 October 2014 at 18:16:08 UTC, marisalovesusall 
wrote:
 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
Oct 13 2014
prev sibling parent reply "eles" <eles215 gzk.dot> writes:
On Monday, 13 October 2014 at 18:16:08 UTC, marisalovesusall 
wrote:
 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.
Oct 13 2014
parent reply "Piotrek" <p nonexistent.pl> writes:
On Monday, 13 October 2014 at 21:50:20 UTC, eles wrote:
 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
Oct 13 2014
next sibling parent reply "eles" <eles215 gzk.dot> writes:
On Monday, 13 October 2014 at 23:28:05 UTC, Piotrek wrote:
 On Monday, 13 October 2014 at 21:50:20 UTC, eles wrote:
 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
Oct 13 2014
parent Dan Olson <zans.is.for.cans yahoo.com> writes:
"eles" <eles215 gzk.dot> writes:

 On Monday, 13 October 2014 at 23:28:05 UTC, Piotrek wrote:
 On Monday, 13 October 2014 at 21:50:20 UTC, eles wrote:
 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. 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
Oct 14 2014
prev sibling parent "eles" <eles eles.com> writes:
On Monday, 13 October 2014 at 23:28:05 UTC, Piotrek wrote:
 On Monday, 13 October 2014 at 21:50:20 UTC, eles wrote:
 Check out the "betterC" switch to get away with runtime
A hand here?: http://forum.dlang.org/post/spgdillzvmnvskyzqaqs forum.dlang.org
Oct 14 2014