Does python have the capability for driver development ?

M

MalC0de

hello there, I've a question :
I want to know does python have any capability for using Ring0 and
kernel functions for driver and device development stuff .
if there's such a feature it is very good, and if there something for
this kind that you know please refer me to some reference and show me
some snippet .

thanks

- Malc0de
 
D

Diez B. Roggisch

MalC0de said:
hello there, I've a question :
I want to know does python have any capability for using Ring0 and
kernel functions for driver and device development stuff .
if there's such a feature it is very good, and if there something for
this kind that you know please refer me to some reference and show me
some snippet .

No, it can't do such things. At least it isn't embedded in the kernel -
in theory that might be possible, but given the timing-constraints and
concurrency-requirements, it's not really feasible.

Diez
 
R

Rodrigo S Wanderley

Martin P. Hellwig said:
Python is interpreted, so the first requirement would be that the
interpreter (the python VM to be more precise) would run in the kernel
or that there is a way for the interpreter to delegate operations to
kernel restricted operations. Most notably access to the memory
location of the hardware you want to write a driver for and possibly
also a way to pass through a callback function for triggered
interrupt coming from the hardware.

So technically speaking it shouldn't be impossible. And there is
perhaps something to say for being able to write drivers in a
readable/easy programming language however I am afraid that if such a
beast would be made that it would remain an academical exercise only
due to performance constraints.

What about user level device drivers? Think the Python VM could
communicate with the driver through the user space API. Is there a
Python module for that?
 
D

David Lyon

MalC0de said:
hello there, I've a question :
I want to know does python have any capability for using Ring0 and
kernel functions for driver and device development stuff .
if there's such a feature it is very good, and if there something for
this kind that you know please refer me to some reference and show me
some snippet .

What operating system are you talking about?

Most device drivers run at ring 3 (or lower) and not zero. This way if
there
is a driver crash the whole operating system doesn't freeze.

Python is generally considered a high-level language. If you want
to play around with drivers.. usb serial.. etc do it at a python
level through the existing device drivers.

imho the performance of interpreted python isn't compatible with
writing block-mode device drivers (hard-disks) and so forth.

What hardware do you have that you need to write a device driver
for ? Isn't there a device driver available already? or do you
mean just a device controller?

David
 
M

Martin P. Hellwig

Rodrigo said:
<cut>
What about user level device drivers? Think the Python VM could
communicate with the driver through the user space API. Is there a
Python module for that?
Sure why not?
Look for example to libusb, which provides a userspace environment and
pyusb which uses that and provides an interface to Python.
 
M

MalC0de

actually I mean driver programming under Windows operating system, if
you know, there's A kit name DDK available at microsoft's website for
developing device drivers under C / C++ environment, now i'm working
with this kind of toolkit, but when I started programming with Python,
I saw this is very good and easy to develop application in all aspects
of a programmer or customer .
I love python cuze I can write every application i want, it's easy and
it's very robust, But i thought if there's any available toolkit like
Microsoft DDK which can program driver under windows but based on
python it's very good and well, I don't know it's the lack of python
or interpreter concept but cuze of the extensibility of python if such
a good feature can be added to python it will be good enough.
actually I want to write device drivers in Ring0 mode or kernel
mode ...
please introduce me some resource for system programming, I know that
python is very well at system programming level.
thanks

- Malc0de
 
D

Diez B. Roggisch

Nick said:
You can write FUSE (file systems in userspace) drivers in python I believe.
Not the same as running in ring0 but in most senses a kernel driver...

No. That's why it is called "userspace". The kernel just hooks into a
running program.

Diez
 
M

Michael Torrie

MalC0de said:
please introduce me some resource for system programming, I know that
python is very well at system programming level.
thanks

Although it is possible (as others have said) to embed Python the
interpreter into a driver, no one has done that that I know of. You'd
have to write the driver in C or C++, though, and then provide embed a
python interpreter and then provide a python interface (wrapper code
written in C++) that would expose binary primitives and structures to
python that the OS and driver use. Sounds like quite an undertaking. I
embedded a python interpreter in a gina dll once (to write login code in
python). That's a form of system programming, but not what you're
asking about.

Someone years ago someone embedded the perl interpreter into a Linux
driver allowing some kinds of device drivers to be written in perl. It
was made more as a curiosity though.

Python is not well-suited to system programming. It takes extra work
(via the ctypes library or other wrappers) to interface with C structs,
plus calls all have to be marshalled to and from the native C APIs.
Might be cool, though.

System programming in Win32 is very complicated and messy. What little
system programming I've done in Linux was a dream compared. Definitely
you'll have to master win32 system programming in C and C++ before you
try to embed python in anything. I'm sure there are a number of books
on the subject. That's where I'd start.
 
S

sturlamolden

actually I mean driver programming under Windows operating system, if
you know, there's A kit name DDK available at microsoft's website for
developing device drivers under C / C++ environment,

Actually, Microsoft has replaced DDK with a new kit called WDK for
Vista. The funny thing about WDK is that there are a lot of illegal C
and C++ in the headers, which even Microsoft's own compiler refuse to
accept. So good luck on getting anything to compile.
 
J

John Nagle

MalC0de said:
hello there, I've a question :
I want to know does python have any capability for using Ring0 and
kernel functions for driver and device development stuff .
if there's such a feature it is very good, and if there something for
this kind that you know please refer me to some reference and show me
some snippet .

thanks

- Malc0de

With the CPython interpretive system, it's not likely to work. But
using ShedSkin, which generates hard machine code, it might be possible.
The main problem is that Shed Skin uses a garbage-collected environment,
which few kernels have.

Under QNX, which is a a real message-passing operating system with
all drivers in user space, it should be possible to write a driver in
Python. There's Python for QNX. It would probably be too slow to
be useful, though.

I've actually written a handler for Baudot Teletype machines in
Python. See

https://sourceforge.net/projects/baudotrss/

Those machines are so slow (45.45 baud) that Python isn't the bottleneck.

John Nagle
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,763
Messages
2,569,563
Members
45,039
Latest member
CasimiraVa

Latest Threads

Top