Thread overview | |||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
January 12, 2006 Porting makro and asm statement | ||||
---|---|---|---|---|
| ||||
I want to port rtai to D. But coming to user-space interrupts there is this peace of code: #define RTAI_SYS_VECTOR 0xf6 #define __rtai_stringize0(_s_) #_s_ #define __rtai_stringize(_s_) __rtai_stringize0(_s_) #define __rtai_trap_call(_t_) _t_ #define __rtai_do_trap0(_t_) __rtai_stringize(int $ _t_) #define __rtai_do_trap(_t_) __rtai_do_trap0(__rtai_trap_call(_t_)) #define RTAI_DO_TRAP(v, r, a1, a2) do { __asm__ __volatile__ ( __rtai_do_trap(v): : "a" (a1), "c" (a2), "d" (&r)); } while (0) How can I write the RTAI_DO_TRAP in D? Frank -- D goes real-time: http://www.drealtime.com |
January 12, 2006 Re: Porting makro and asm statement | ||||
---|---|---|---|---|
| ||||
Posted in reply to Frank Benoit | Thats a nasty looking macro , it might be beneficial to make a simple test program that calls RTAI_DO_TRAP , and run it through just the preprocesor see whats actually getting called. For gcc ( -E ) , for dmc ( -e ) . And D supports inline asm also , http://www.digitalmars.com/d/iasm.html . Great work on the wiki , I really hope you get far with this :D. Charlie "Frank Benoit" <frank_DELETE_@_DELETE_drealtime.com> wrote in message news:dq5v0r$pdf$1@digitaldaemon.com... > I want to port rtai to D. But coming to user-space interrupts there is this > peace of code: > > #define RTAI_SYS_VECTOR 0xf6 > > #define __rtai_stringize0(_s_) #_s_ > #define __rtai_stringize(_s_) __rtai_stringize0(_s_) > #define __rtai_trap_call(_t_) _t_ > #define __rtai_do_trap0(_t_) __rtai_stringize(int $ _t_) > #define __rtai_do_trap(_t_) __rtai_do_trap0(__rtai_trap_call(_t_)) > > #define RTAI_DO_TRAP(v, r, a1, a2) do { __asm__ __volatile__ > ( __rtai_do_trap(v): : "a" (a1), "c" (a2), "d" (&r)); } while (0) > > How can I write the RTAI_DO_TRAP in D? > > Frank > > > -- > D goes real-time: http://www.drealtime.com |
January 12, 2006 Re: Porting makro and asm statement | ||||
---|---|---|---|---|
| ||||
Posted in reply to Frank Benoit | Frank Benoit wrote:
> I want to port rtai to D. But coming to user-space interrupts there is this
> peace of code:
>
> #define RTAI_SYS_VECTOR 0xf6
>
> #define __rtai_stringize0(_s_) #_s_
> #define __rtai_stringize(_s_) __rtai_stringize0(_s_)
> #define __rtai_trap_call(_t_) _t_
> #define __rtai_do_trap0(_t_) __rtai_stringize(int $ _t_)
> #define __rtai_do_trap(_t_) __rtai_do_trap0(__rtai_trap_call(_t_))
>
> #define RTAI_DO_TRAP(v, r, a1, a2) do { __asm__ __volatile__
> ( __rtai_do_trap(v): : "a" (a1), "c" (a2), "d" (&r)); } while (0)
>
> How can I write the RTAI_DO_TRAP in D?
Not easily. RTAI_DO_TRAP is itself a macro, so v, r, a1, and a2 may have different types in different portions of the code. The easiest thing may be to get your hands on a C preprocessor and run it on the full source, then translate each __asm__ block by hand.
Sean
|
January 12, 2006 Re: Porting makro and asm statement | ||||
---|---|---|---|---|
| ||||
Posted in reply to Frank Benoit | "Frank Benoit" <frank_DELETE_@_DELETE_drealtime.com> wrote in message news:dq5v0r$pdf$1@digitaldaemon.com... >I want to port rtai to D. But coming to user-space interrupts there is this > peace of code: > > #define RTAI_SYS_VECTOR 0xf6 > > #define __rtai_stringize0(_s_) #_s_ > #define __rtai_stringize(_s_) __rtai_stringize0(_s_) > #define __rtai_trap_call(_t_) _t_ > #define __rtai_do_trap0(_t_) __rtai_stringize(int $ _t_) > #define __rtai_do_trap(_t_) __rtai_do_trap0(__rtai_trap_call(_t_)) > > #define RTAI_DO_TRAP(v, r, a1, a2) do { __asm__ __volatile__ > ( __rtai_do_trap(v): : "a" (a1), "c" (a2), "d" (&r)); } while (0) > > How can I write the RTAI_DO_TRAP in D? It's a bit hard to see what that macro is doing. But I suspect it can be done with a template: template RTAI_DO_TRAP(int v) { RTAI_DO_TRAP() { asm { int v; } } } void main() { RTAI_DO_TRAP!(23)(); } |
January 12, 2006 Re: Porting makro and asm statement | ||||
---|---|---|---|---|
| ||||
Posted in reply to Walter Bright | Oh, please; can you explain what is going on there. Why don't you need the other three parameters? What sense makes a asm statement with a "int 23;"? Why do I need a template? Frank |
January 12, 2006 Re: Porting makro and asm statement | ||||
---|---|---|---|---|
| ||||
Posted in reply to Frank Benoit | I run it through gcc -E. But I don't understand the asm part. Can somebody explain it to me? static inline long long rtai_srq(int srq, unsigned long args) { long long retval; do { __asm__ __volatile__ ( "int $ 0xf6": : "a" (srq), "c" (args), "d" (&retval)); } while (0); return retval; } |
January 12, 2006 Re: Porting makro and asm statement | ||||
---|---|---|---|---|
| ||||
Posted in reply to Frank Benoit | Frank Benoit wrote:
> I run it through gcc -E. But I don't understand the asm part. Can somebody
> explain it to me?
>
> static inline long long rtai_srq(int srq, unsigned long args)
> {
> long long retval;
> do { __asm__ __volatile__ ( "int $ 0xf6": : "a" (srq), "c" (args),
> "d" (&retval)); } while (0);
> return retval;
> }
GCC uses a compiler-specific asm syntax. I suggest reading the GCC docs to make sense of it. Though perhaps someone else on this list has written inline ASM with GCC.
Sean
|
January 12, 2006 Re: Porting makro and asm statement | ||||
---|---|---|---|---|
| ||||
Posted in reply to Sean Kelly | I found this solution. Can somebody correct me, if there is a mistake? Perhaps there is a better syntax for getting the address of retval? const uint RTAI_SYS_VECTOR = 0xf6; long rtai_srq( int srq, uint args ) { long retval; long* rptr = &retval; asm{ // load registers with arguments mov srq,EAX; mov args,ECX; mov rptr,EDX; // initiate software interrupt int RTAI_SYS_VECTOR; } return retval; } Frank -- D goes real-time: http://www.drealtime.com |
January 12, 2006 Re: Porting makro and asm statement | ||||
---|---|---|---|---|
| ||||
Posted in reply to Frank Benoit | > What sense makes a asm statement with a "int 23;"?
Ok, int not for integer <-> interrupt
|
January 12, 2006 Re: Porting makro and asm statement | ||||
---|---|---|---|---|
| ||||
Posted in reply to Frank Benoit | "Frank Benoit" <frank_DELETE_@_DELETE_drealtime.com> wrote in message news:dq62ic$sgb$1@digitaldaemon.com... > Oh, please; can you explain what is going on there. > Why don't you need the other three parameters? The compiler figures out for itself which registers are read and written to. > What sense makes a asm statement with a "int 23;"? That's what the RTAI macro does with its argument, too. > Why do I need a template? The int instruction takes a literal operand, not a variable, so this is the only way to parameterize it. |
Copyright © 1999-2021 by the D Language Foundation