Well, I think it *is* more portable, because from XML, you can compile it to C, ASM, but also to Pascal and every other language you like. Only if you have embedded real source code, you have to compile them separately and link them together correctly. But real code would _only_ be acceptable if it didn't use any relevant functions. A relevant function is one that relies on the OS; so it would be ok to write a function to multiply three numbers, but it wouldn't if it mapped a function to an irq. If you look at the PIT code, it says at the beginnig:
Code: Select all
...
<irq index="0" handler="method:timer_handler"/>
...
If you noticed, I modified this line in the old post to be more XML-compliant ;D. But anyway, the trick is that every OS implements this kind of things different, and with real code, you must always port the code so that it works in you kernel. But here, the only thing that has to be ported by the developer (that is, *you*) is the module that compiles and links device drivers out of this XML code.
The main advantage of C is that it is shorter for some things, e.g. variable declarations, etc. So, modifying the PIT code to use C everywhere it is possible (non-relevant function calls), it would look like this:
Code: Select all
<device name="PIT">
<init>
<global> // Used to declare global variables
<var name="ticks" type="vulong" val="0"/>
</global>
<irq index="0" handler="method:timer_handler"/>
<code lang="c"> // This snippet is only to demonstrate
setfreq(1000);
</code>
</init>
<method name="timer_handler" type="irq_handler">
<code lang="c">
ticks = ticks + 1;
</code>
</method>
<method name="setfreq" param="freq,uint">
<code lang="c">
int divisor = 1193180 / freq;
int lb = divisor & 0xFF;
int hb = divisor >> 8;
</code>
<out port="0x43" val="0x36"/>
<out port="0x40" val="var:lb"/>
<out port="0x40" val="var:hb"/>
</method>
</device>
I rewrote the driver in order to show the new concepts, but yes, I will try to provide a more complex driver in this format... As I said, I'm implementing my memory manager...