dol: initial dol commit
[jump.git] / dol / src / dol / visitor / cell / lib / ppu / dolSupport.h
1 #ifndef DOLSUPPORT_H\r
2 #define DOLSUPPORT_H\r
3 \r
4 #include "dol.h"\r
5 #include "pt.h"\r
6 \r
7 #include "ProcessWrapper.h"\r
8 \r
9 #include "Fifo.h"\r
10 #include "WindowedFifo.h"\r
11 \r
12 typedef struct _process_data {\r
13     int lc;\r
14     ProcessWrapper *wrapper;\r
15 } process_data;\r
16 \r
17 \r
18 #define DOL_read(port, buf, size, process) \\r
19     PT_WAIT_UNTIL((pt*)(p->wptr), read(port, buf, size, process) == size);\r
20 \r
21 #define DOL_write(port, buf, size, process) \\r
22     PT_WAIT_UNTIL((pt*)(p->wptr), write(port, buf, size, process) == size);\r
23 \r
24 #define DOL_reserve(port, buf, size, process) \\r
25     PT_WAIT_UNTIL((pt*)(p->wptr), reserve(port, (void**)buf, size, process) == size);\r
26 \r
27 #define DOL_release(port, process) \\r
28     release(port, process);\r
29 \r
30 #define DOL_capture(port, buf, size, process) \\r
31     PT_WAIT_UNTIL((pt*)(p->wptr), capture(port, (void**)buf, size, process) == size);\r
32 \r
33 #define DOL_consume(port, process) \\r
34     consume(port, process);\r
35 \r
36 void DOL_detach(DOLProcess* p);\r
37 \r
38 //macros to deal with iterated ports\r
39 /**\r
40  * macro to create a variable to store a port name\r
41  *\r
42  * @param name name of the variable\r
43  */\r
44 #define CREATEPORTVAR(name) static Fifo *name\r
45 \r
46 /**\r
47  * Create the port name of an iterated port based on its basename and the\r
48  * given indices.\r
49  *\r
50  * @param port buffer where the result is stored (created using\r
51  *             CREATEPORTVAR)\r
52  * @param base basename of the port\r
53  * @param number_of_indices number of dimensions of the port\r
54  * @param index_range_pairs index and range values for each dimension\r
55  */\r
56 \r
57 #define CREATEPORT(port, base, number_of_indices, index_range_pairs...) \\r
58   createPort((void**)(&port), base, number_of_indices, index_range_pairs)\r
59 \r
60 #define GETINDEX(dimension) \\r
61   static_cast<ProcessWrapper *>((static_cast<process_data *>(p->wptr))->wrapper)->getIndex(dimension)\r
62 \r
63 void createPort(void** port, void* base, int number_of_indices, int index0, int range0);\r
64 void createPort(void** port, void* base, int number_of_indices, int index0, int range0, int index1, int range1);\r
65 void createPort(void** port, void* base, int number_of_indices, int index0, int range0, int index1, int range1, int index2, int range2);\r
66 void createPort(void** port, void* base, int number_of_indices, int index0, int range0, int index1, int range1, int index2, int range2, int index3, int range3);\r
67 \r
68 //fifo access functions\r
69 unsigned write(void* fifo, void* buf, unsigned len, DOLProcess* p);\r
70 unsigned read(void* fifo, void* buf, unsigned len, DOLProcess* p);\r
71 \r
72 //windowed fifo access functions\r
73 unsigned reserve(void* fifo, void** destination, unsigned len, DOLProcess* p);\r
74 void release(void* fifo, DOLProcess* p);\r
75 unsigned capture(void* fifo, void** destination, unsigned len, DOLProcess* p);\r
76 void consume(void* fifo, DOLProcess* p);\r
77 \r
78 #endif\r