wip commit. acpi button driver.
[AROS.git] / compiler / arossupport / rt.h
blob3787b698cb4de71d44a22b8fc253d342af9d4be7
1 #ifndef _RT_H
2 #define _RT_H
4 /*
5 Copyright © 1995-96, The AROS Development Team. All rights reserved.
6 $Id$
8 Desc: Common header file for RT
9 Lang: english
11 #define ENABLE_RT 0 /* no RT inside this file */
12 #define RT_INTERNAL 1
13 #include <aros/rt.h>
15 #include <exec/lists.h>
16 #include <stdarg.h>
18 #include <aros/system.h>
19 #include <exec/tasks.h>
20 #include <exec/ports.h>
21 #include <exec/memory.h>
22 #include <exec/execbase.h>
23 #include <stdlib.h>
24 #include <stdio.h>
25 #include <proto/exec.h>
26 #include <proto/dos.h>
27 #include <proto/intuition.h>
28 #include <proto/arossupport.h>
29 #include <proto/alib.h>
31 #include "etask.h"
33 #define RT_VERSION 1 /* Current version of RT */
35 #define HASH_BITS 4 /* Size of hash in bits and entries */
36 #define HASH_SIZE (1L << HASH_BITS)
38 typedef struct
40 const char * Function;
41 const char * File;
42 ULONG Line;
44 RTStack;
46 #define STACKDEPTH 256
49 /* This is what is behind etask->iet_RT */
50 typedef struct
52 ULONG rtd_Version; /* RT_VERSION */
53 struct MinList rtd_ResHash[RTT_MAX][HASH_SIZE];
54 ULONG rtd_StackPtr;
55 RTStack rtd_CallStack[STACKDEPTH];
56 } RTData;
58 extern RTData * intRT; /* Global variable in case no ETask is available */
60 typedef struct
62 struct MinNode Node;
63 const char * File;
64 ULONG Line;
65 ULONG Flags;
67 RTNode;
69 /* Private flags of resource nodes */
70 #define RTNF_DONT_FREE 0x80000000 /* Resource must not be freed */
72 typedef struct
74 RTNode Node;
75 APTR Resource; /* This should be common to every resource */
77 Resource;
79 typedef struct __RTDesc RTDesc;
81 typedef IPTR (* RT_AllocFunc) (RTData * rtd, RTNode *, va_list, BOOL * success);
82 typedef IPTR (* RT_FreeFunc) (RTData * rtd, RTNode *);
83 typedef IPTR (* RT_SearchFunc) (RTData * rtd, int, RTNode **, va_list);
84 typedef IPTR (* RT_ShowError) (RTData * rtd, int, RTNode *, IPTR, int, const char * file, ULONG line, va_list);
85 typedef IPTR (* RT_CheckFunc) (RTData * rtd, int, const char * file, ULONG line, ULONG op, va_list);
87 #define HASH_BASE(rtn) (((Resource *)rtn)->Resource)
89 #if HASH_BITS==4
90 #if __WORDSIZE == 64
91 #define CALCHASH(res) \
92 ((((IPTR)res) + (((IPTR)res)>>4) + (((IPTR)res)>>8 ) + (((IPTR)res)>>12) + \
93 (((IPTR)res)>>16) + (((IPTR)res)>>20) +(((IPTR)res)>>24) + (((IPTR)res)>>28) + \
94 (((IPTR)res)>>32) + (((IPTR)res)>>36) +(((IPTR)res)>>40) + (((IPTR)res)>>44) + \
95 (((IPTR)res)>>48) + (((IPTR)res)>>52) +(((IPTR)res)>>56) + (((IPTR)res)>>60)) \
96 & 0x0000000FL)
97 #else
98 #define CALCHASH(res) \
99 ((((ULONG)res) + (((ULONG)res)>>4) +(((ULONG)res)>>8) + (((ULONG)res)>>12) + \
100 (((ULONG)res)>>16) + (((ULONG)res)>>20) +(((ULONG)res)>>24) + (((ULONG)res)>>28)) \
101 & 0x0000000FL)
102 #endif
103 #endif
105 struct __RTDesc
107 const ULONG Size;
108 RT_AllocFunc AllocFunc;
109 RT_FreeFunc FreeFunc;
110 RT_SearchFunc SearchFunc;
111 RT_ShowError ShowError;
112 RT_CheckFunc CheckFunc;
115 #define GetRTData() \
116 ({ \
117 struct IntETask * et; \
119 et = (struct IntETask *)GetETask (FindTask(NULL)); \
121 et \
122 && et->iet_RT \
123 && ((RTData *)et->iet_RT)->rtd_Version == RT_VERSION \
124 ? et->iet_RT \
125 : intRTD; \
127 #define SetRTData(rtd) \
129 struct IntETask * et; \
131 et = (struct IntETask *)GetETask (FindTask(NULL)); \
133 if (et) \
134 et->iet_RT = rtd; \
135 else \
136 intRTD = rtd; \
139 /* Return values of SearchFunc */
140 #define RT_SEARCH_FOUND 0
141 #define RT_SEARCH_NOT_FOUND 1
142 #define RT_SEARCH_SIZE_MISMATCH 2
144 #define RT_FREE 0
145 #define RT_CHECK 1
146 #define RT_EXIT 2
148 extern RTDesc const * RT_Resources[RTT_MAX];
150 #define GetRTDesc(no) RT_Resources[no]
151 #define GetRTField(no,f) (GetRTDesc(no) ? GetRTDesc(no)->f : NULL)
152 #define GetRTSize(no) (GetRTDesc(no) ? GetRTDesc(no)->Size : 0)
153 #define GetRTAllocFunc(no) (GetRTField(no,AllocFunc))
154 #define GetRTFreeFunc(no) (GetRTField(no,FreeFunc))
155 #define GetRTSearchFunc(no) (GetRTField(no,SearchFunc))
156 #define GetRTShowError(no) (GetRTField(no,ShowError))
157 #define GetRTCheckFunc(no) (GetRTField(no,CheckFunc))
159 extern void RT_FreeResource (RTData * rtd, int rtt, RTNode * rtnode);
161 #define ALIGNED_PTR 0x00000001 /* Must be aligned */
162 #define NULL_PTR 0x00000002 /* May be NULL */
163 extern BOOL CheckPtr (APTR ptr, ULONG flags);
164 extern BOOL CheckArea (APTR ptr, ULONG size, ULONG flags);
166 extern IPTR RT_Search (RTData * rtd, int rtt, RTNode ** rtptr, va_list args);
168 #endif /* _RT_H */