GEMLIB  0.44.0
gem_vdiP.h
1 /*
2  * $Id: gem_vdiP.h,v 1.14 2015/12/13 19:40:09 landemarre Exp $
3  */
4 
5 #ifndef _GEM_VDI_P_
6 # define _GEM_VDI_P_
7 
8 # ifndef _GEMLIB_H_
9 # include "mt_gem.h"
10 # endif
11 
12 
13 #define vdi_control_ptr(n) *((void**)(vdi_control +n))
14 #define vdi_intin_ptr(n) *((void**)(vdi_intin +n))
15 #define vdi_intout_long(n) *((long*) (vdi_intout +n))
16 
17 #if defined(__GNUC__) && !defined(__NO_INLINE__)
18 
19 static inline void
20 _vdi_trap_esc (VDIPB * vdipb,
21  long cntrl_0_1, long cntrl_3, long cntrl_5, short handle)
22 {
23  __asm__ volatile (
24  "movea.l %0,a0\n\t" /* &vdipb */
25  "move.l a0,d1\n\t"
26  "move.l (a0),a0\n\t" /* vdipb->control */
27  "move.l %1,(a0)+\n\t" /* cntrl_0, cntrl_1 */
28  "move.l %2,(a0)+\n\t" /* cntrl_2, cntrl_3 */
29  "move.l %3,(a0)+\n\t" /* cntrl_4, cntrl_5 */
30  "move.w %4,(a0)\n\t" /* handle */
31  "move.w #115,d0\n\t" /* 0x0073 */
32  "trap #2"
33  :
34  : "g"(vdipb), "g"(cntrl_0_1), "g"(cntrl_3), "g"(cntrl_5), "g"(handle)
35  : "d0", "d1", "d2", "a0", "a1", "a2", "memory"
36  );
37 }
38 #define VDI_TRAP_ESC(vdipb, handle, opcode, subop, cntrl_1, cntrl_3) \
39  _vdi_trap_esc (&vdipb, (opcode##uL<<16)|cntrl_1, cntrl_3, subop, handle)
40 
41 static inline void
42 _vdi_trap_00 (VDIPB * vdipb, long cntrl_0_1, short handle)
43 {
44  __asm__ volatile (
45  "movea.l %0,a0\n\t" /* &vdipb */
46  "move.l a0,d1\n\t"
47  "move.l (a0),a0\n\t" /* vdipb->control */
48  "move.l %1,(a0)+\n\t" /* cntrl_0, cntrl_1 */
49  "moveq #0,d0\n\t"
50  "move.l d0,(a0)+\n\t" /* cntrl_2, cntrl_3 */
51  "move.l d0,(a0)+\n\t" /* cntrl_4, cntrl_5 */
52  "move.w %2,(a0)\n\t" /* handle */
53  "move.w #115,d0\n\t" /* 0x0073 */
54  "trap #2"
55  :
56  : "g"(vdipb), "g"(cntrl_0_1), "g"(handle)
57  : "d0", "d1", "d2", "a0", "a1", "a2", "memory"
58  );
59 }
60 #define VDI_TRAP_00(vdipb, handle, opcode) \
61  _vdi_trap_00 (&vdipb, (opcode##uL<<16), handle)
62 
63 
64 #else
65 
66 #if defined(__VBCC__)
67 
68 __regsused("d0/d1/a0/a1") void _vdi_trap_esc(
69  __reg("a0")VDIPB *,__reg("d0")long,__reg("d1")long,
70  __reg("d2")long,__reg("d3")short) =
71  "\tmove.l\td2,-(sp)\n"
72  "\tmove.l\ta2,-(sp)\n"
73  "\tmove.l\t(a0),a1\n"
74  "\tmovem.l\td0-d2,(a1)\n"
75  "\tmove.w\td3,12(a1)\n"
76  "\tmove.l\ta0,d1\n"
77  "\tmoveq\t#115,d0\n"
78  "\ttrap\t#2\n"
79  "\tmove.l\t(sp)+,a2\n"
80  "\tmove.l\t(sp)+,d2";
81 
82 #define VDI_TRAP_ESC(vdipb, handle, opcode, subop, cntrl_1, cntrl_3) \
83  _vdi_trap_esc (&vdipb, (opcode##uL<<16)|cntrl_1, cntrl_3, subop, handle)
84 
85 __regsused("d0/d1/a0/a1") void _vdi_trap_00(
86  __reg("a0")VDIPB *,__reg("d0")long,__reg("d1")short) =
87  "\tmove.l\td2,-(sp)\n"
88  "\tmove.l\ta2,-(sp)\n"
89  "\tmove.l\t(a0),a1\n"
90  "\tmove.l\td0,(a1)+\n"
91  "\tmoveq\t#0,d0\n"
92  "\tmove.l\td0,(a1)+\n"
93  "\tmove.l\td0,(a1)+\n"
94  "\tmove.w\td1,(a1)\n"
95  "\tmove.l\ta0,d1\n"
96  "\tmoveq\t#115,d0\n"
97  "\ttrap\t#2\n"
98  "\tmove.l\t(sp)+,a2\n"
99  "\tmove.l\t(sp)+,d2";
100 
101 #define VDI_TRAP_00(vdipb, handle, opcode) \
102  _vdi_trap_00 (&vdipb, (opcode##uL<<16), handle)
103 
104 #else /* no usage of inlines, go the old way */
105 
106 #define VDI_TRAP_ESC(vdipb, handle, opcode, subop, cntrl_1, cntrl_3) \
107  vdipb.control[0] = opcode; \
108  vdipb.control[1] = cntrl_1; \
109  vdipb.control[3] = cntrl_3; \
110  vdipb.control[5] = subop; \
111  vdipb.control[6] = handle; \
112  vdi (&vdipb);
113 
114 #define VDI_TRAP_00(vdipb, handle, opcode) \
115  VDI_TRAP_ESC (vdipb, handle, opcode, 0, 0, 0)
116 #endif /* __VBCC__ */
117 #endif
118 
119 
120 #define VDI_TRAP(vdipb, handle, opcode, cntrl_1, cntrl_3) \
121  VDI_TRAP_ESC(vdipb, handle, opcode, 0, cntrl_1, cntrl_3)
122 
123 #define VDI_PARAMS(a,b,c,d,e) \
124  VDIPB vdi_params; \
125  vdi_params.control = a; \
126  vdi_params.intin = b; \
127  vdi_params.ptsin = c; \
128  vdi_params.intout = d; \
129  vdi_params.ptsout = e;
130 
131 
132 /* special feature for VDI bindings: pointer in parameters (for return values)
133  * could be NULL (nice idea by Martin Elsasser against dummy variables)
134  */
135 #define CHECK_NULLPTR 1
136 
137 /* special feature for VDI bindings: set VDIPB::intout and VDIPB::ptsout to
138  * vdi_dummy array intead of NULL against crashes if some crazy VDI drivers
139  * tries to write something in ptsout/intout.
140  */
141 #define USE_VDI_DUMMY 1
142 
143 #if USE_VDI_DUMMY
144  /* use dummy array vdi_dummy[] from vdi_dummy.c */
145  extern short vdi_dummy[];
146 #else
147  /* replace vdi_dummy in VDIPB by NULL pointer */
148  #define vdi_dummy 0L
149 #endif
150 
151 # endif /* _GEM_VDI_P_ */
Definition: mt_gem.h:3020