NSMBW-Decomp
A decompilation of New Super Mario Bros. Wii
Loading...
Searching...
No Matches
gki_common.h
1/******************************************************************************
2 *
3 * NOTICE OF CHANGES
4 * 2024/03/25:
5 * - Disable GKI_USE_DEFERED_ALLOC_BUF_POOLS
6 * - Modify tGKI_COM_CB structure to match RVL target
7 *
8 * Compile with REVOLUTION defined to include these changes.
9 *
10 ******************************************************************************/
11
12
13
14/******************************************************************************
15 *
16 * Copyright (C) 1999-2012 Broadcom Corporation
17 *
18 * Licensed under the Apache License, Version 2.0 (the "License");
19 * you may not use this file except in compliance with the License.
20 * You may obtain a copy of the License at:
21 *
22 * http://www.apache.org/licenses/LICENSE-2.0
23 *
24 * Unless required by applicable law or agreed to in writing, software
25 * distributed under the License is distributed on an "AS IS" BASIS,
26 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
27 * See the License for the specific language governing permissions and
28 * limitations under the License.
29 *
30 ******************************************************************************/
31#ifndef GKI_COMMON_H
32#define GKI_COMMON_H
33
34#include "gki.h"
35#include "dyn_mem.h"
36
37/* Task States: (For OSRdyTbl) */
38#define TASK_DEAD 0 /* b0000 */
39#define TASK_READY 1 /* b0001 */
40#define TASK_WAIT 2 /* b0010 */
41#define TASK_DELAY 4 /* b0100 */
42#define TASK_SUSPEND 8 /* b1000 */
43
44
45/********************************************************************
46** Internal Error codes
47*********************************************************************/
48#define GKI_ERROR_BUF_CORRUPTED 0xFFFF
49#define GKI_ERROR_NOT_BUF_OWNER 0xFFFE
50#define GKI_ERROR_FREEBUF_BAD_QID 0xFFFD
51#define GKI_ERROR_FREEBUF_BUF_LINKED 0xFFFC
52#define GKI_ERROR_SEND_MSG_BAD_DEST 0xFFFB
53#define GKI_ERROR_SEND_MSG_BUF_LINKED 0xFFFA
54#define GKI_ERROR_ENQUEUE_BUF_LINKED 0xFFF9
55#define GKI_ERROR_DELETE_POOL_BAD_QID 0xFFF8
56#define GKI_ERROR_BUF_SIZE_TOOBIG 0xFFF7
57#define GKI_ERROR_BUF_SIZE_ZERO 0xFFF6
58#define GKI_ERROR_ADDR_NOT_IN_BUF 0xFFF5
59
60
61/********************************************************************
62** Misc constants
63*********************************************************************/
64
65#define GKI_MAX_INT32 (0x7fffffffL)
66#define GKI_MAX_TIMESTAMP (0xffffffffL)
67
68/********************************************************************
69** Buffer Management Data Structures
70*********************************************************************/
71
72typedef struct _buffer_hdr
73{
74 struct _buffer_hdr *p_next; /* next buffer in the queue */
75 UINT8 q_id; /* id of the queue */
76 UINT8 task_id; /* task which allocated the buffer*/
77 UINT8 status; /* FREE, UNLINKED or QUEUED */
78 UINT8 Type;
79} BUFFER_HDR_T;
80
81typedef struct _free_queue
82{
83 BUFFER_HDR_T *p_first; /* first buffer in the queue */
84 BUFFER_HDR_T *p_last; /* last buffer in the queue */
85 UINT16 size; /* size of the buffers in the pool */
86 UINT16 total; /* toatal number of buffers */
87 UINT16 cur_cnt; /* number of buffers currently allocated */
88 UINT16 max_cnt; /* maximum number of buffers allocated at any time */
89} FREE_QUEUE_T;
90
91
92/* Buffer related defines
93*/
94#define ALIGN_POOL(pl_size) ( (((pl_size) + 3) / sizeof(UINT32)) * sizeof(UINT32))
95#define BUFFER_HDR_SIZE (sizeof(BUFFER_HDR_T)) /* Offset past header */
96#define BUFFER_PADDING_SIZE (sizeof(BUFFER_HDR_T) + sizeof(UINT32)) /* Header + Magic Number */
97#define MAX_USER_BUF_SIZE ((UINT16)0xffff - BUFFER_PADDING_SIZE) /* pool size must allow for header */
98#define MAGIC_NO 0xDDBADDBA
99
100#define BUF_STATUS_FREE 0
101#define BUF_STATUS_UNLINKED 1
102#define BUF_STATUS_QUEUED 2
103
104// btla-specific ++
105#ifndef REVOLUTION
106#define GKI_USE_DEFERED_ALLOC_BUF_POOLS
107#endif
108// btla-specific --
109
110/* Exception related structures (Used in debug mode only)
111*/
112#if (GKI_DEBUG == TRUE)
113typedef struct
114{
115 UINT16 type;
116 UINT8 taskid;
117 UINT8 msg[GKI_MAX_EXCEPTION_MSGLEN];
119#endif
120
121
122/* Put all GKI variables into one control block
123*/
124typedef struct
125{
126 /* Task management variables
127 */
128 /* The stack and stack size are not used on Windows
129 */
130// btla-specific ++
131#if (!defined GKI_USE_DEFERED_ALLOC_BUF_POOLS && (GKI_USE_DYNAMIC_BUFFERS == FALSE))
132// btla-specific --
133
134#if (GKI_NUM_FIXED_BUF_POOLS > 0)
135 UINT8 bufpool0[(ALIGN_POOL(GKI_BUF0_SIZE) + BUFFER_PADDING_SIZE) * GKI_BUF0_MAX];
136#endif
137
138#if (GKI_NUM_FIXED_BUF_POOLS > 1)
139 UINT8 bufpool1[(ALIGN_POOL(GKI_BUF1_SIZE) + BUFFER_PADDING_SIZE) * GKI_BUF1_MAX];
140#endif
141
142#if (GKI_NUM_FIXED_BUF_POOLS > 2)
143 UINT8 bufpool2[(ALIGN_POOL(GKI_BUF2_SIZE) + BUFFER_PADDING_SIZE) * GKI_BUF2_MAX];
144#endif
145
146#if (GKI_NUM_FIXED_BUF_POOLS > 3)
147 UINT8 bufpool3[(ALIGN_POOL(GKI_BUF3_SIZE) + BUFFER_PADDING_SIZE) * GKI_BUF3_MAX];
148#endif
149
150#if (GKI_NUM_FIXED_BUF_POOLS > 4)
151 UINT8 bufpool4[(ALIGN_POOL(GKI_BUF4_SIZE) + BUFFER_PADDING_SIZE) * GKI_BUF4_MAX];
152#endif
153
154#if (GKI_NUM_FIXED_BUF_POOLS > 5)
155 UINT8 bufpool5[(ALIGN_POOL(GKI_BUF5_SIZE) + BUFFER_PADDING_SIZE) * GKI_BUF5_MAX];
156#endif
157
158#if (GKI_NUM_FIXED_BUF_POOLS > 6)
159 UINT8 bufpool6[(ALIGN_POOL(GKI_BUF6_SIZE) + BUFFER_PADDING_SIZE) * GKI_BUF6_MAX];
160#endif
161
162#if (GKI_NUM_FIXED_BUF_POOLS > 7)
163 UINT8 bufpool7[(ALIGN_POOL(GKI_BUF7_SIZE) + BUFFER_PADDING_SIZE) * GKI_BUF7_MAX];
164#endif
165
166#if (GKI_NUM_FIXED_BUF_POOLS > 8)
167 UINT8 bufpool8[(ALIGN_POOL(GKI_BUF8_SIZE) + BUFFER_PADDING_SIZE) * GKI_BUF8_MAX];
168#endif
169
170#if (GKI_NUM_FIXED_BUF_POOLS > 9)
171 UINT8 bufpool9[(ALIGN_POOL(GKI_BUF9_SIZE) + BUFFER_PADDING_SIZE) * GKI_BUF9_MAX];
172#endif
173
174#if (GKI_NUM_FIXED_BUF_POOLS > 10)
175 UINT8 bufpool10[(ALIGN_POOL(GKI_BUF10_SIZE) + BUFFER_PADDING_SIZE) * GKI_BUF10_MAX];
176#endif
177
178#if (GKI_NUM_FIXED_BUF_POOLS > 11)
179 UINT8 bufpool11[(ALIGN_POOL(GKI_BUF11_SIZE) + BUFFER_PADDING_SIZE) * GKI_BUF11_MAX];
180#endif
181
182#if (GKI_NUM_FIXED_BUF_POOLS > 12)
183 UINT8 bufpool12[(ALIGN_POOL(GKI_BUF12_SIZE) + BUFFER_PADDING_SIZE) * GKI_BUF12_MAX];
184#endif
185
186#if (GKI_NUM_FIXED_BUF_POOLS > 13)
187 UINT8 bufpool13[(ALIGN_POOL(GKI_BUF13_SIZE) + BUFFER_PADDING_SIZE) * GKI_BUF13_MAX];
188#endif
189
190#if (GKI_NUM_FIXED_BUF_POOLS > 14)
191 UINT8 bufpool14[(ALIGN_POOL(GKI_BUF14_SIZE) + BUFFER_PADDING_SIZE) * GKI_BUF14_MAX];
192#endif
193
194#if (GKI_NUM_FIXED_BUF_POOLS > 15)
195 UINT8 bufpool15[(ALIGN_POOL(GKI_BUF15_SIZE) + BUFFER_PADDING_SIZE) * GKI_BUF15_MAX];
196#endif
197
198#else
199/* Definitions for dynamic buffer use */
200#if (GKI_NUM_FIXED_BUF_POOLS > 0)
201 UINT8 *bufpool0;
202#endif
203
204#if (GKI_NUM_FIXED_BUF_POOLS > 1)
205 UINT8 *bufpool1;
206#endif
207
208#if (GKI_NUM_FIXED_BUF_POOLS > 2)
209 UINT8 *bufpool2;
210#endif
211
212#if (GKI_NUM_FIXED_BUF_POOLS > 3)
213 UINT8 *bufpool3;
214#endif
215
216#if (GKI_NUM_FIXED_BUF_POOLS > 4)
217 UINT8 *bufpool4;
218#endif
219
220#if (GKI_NUM_FIXED_BUF_POOLS > 5)
221 UINT8 *bufpool5;
222#endif
223
224#if (GKI_NUM_FIXED_BUF_POOLS > 6)
225 UINT8 *bufpool6;
226#endif
227
228#if (GKI_NUM_FIXED_BUF_POOLS > 7)
229 UINT8 *bufpool7;
230#endif
231
232#if (GKI_NUM_FIXED_BUF_POOLS > 8)
233 UINT8 *bufpool8;
234#endif
235
236#if (GKI_NUM_FIXED_BUF_POOLS > 9)
237 UINT8 *bufpool9;
238#endif
239
240#if (GKI_NUM_FIXED_BUF_POOLS > 10)
241 UINT8 *bufpool10;
242#endif
243
244#if (GKI_NUM_FIXED_BUF_POOLS > 11)
245 UINT8 *bufpool11;
246#endif
247
248#if (GKI_NUM_FIXED_BUF_POOLS > 12)
249 UINT8 *bufpool12;
250#endif
251
252#if (GKI_NUM_FIXED_BUF_POOLS > 13)
253 UINT8 *bufpool13;
254#endif
255
256#if (GKI_NUM_FIXED_BUF_POOLS > 14)
257 UINT8 *bufpool14;
258#endif
259
260#if (GKI_NUM_FIXED_BUF_POOLS > 15)
261 UINT8 *bufpool15;
262#endif
263
264#endif
265
266 UINT8 *OSStack[GKI_MAX_TASKS]; /* pointer to beginning of stack */
267 UINT16 OSStackSize[GKI_MAX_TASKS]; /* stack size available to each task */
268
269
270 INT8 *OSTName[GKI_MAX_TASKS]; /* name of the task */
271
272 UINT8 OSRdyTbl[GKI_MAX_TASKS]; /* current state of the task */
273 UINT16 OSWaitEvt[GKI_MAX_TASKS]; /* events that have to be processed by the task */
274 UINT16 OSWaitForEvt[GKI_MAX_TASKS]; /* events the task is waiting for*/
275
276 UINT32 OSTicks; /* system ticks from start */
277 UINT32 OSIdleCnt; /* idle counter */
278 INT16 OSDisableNesting; /* counter to keep track of interrupt disable nesting */
279 INT16 OSLockNesting; /* counter to keep track of sched lock nesting */
280 INT16 OSIntNesting; /* counter to keep track of interrupt nesting */
281
282 /* Timer related variables
283 */
284 INT32 OSTicksTilExp; /* Number of ticks till next timer expires */
285#if (defined(GKI_DELAY_STOP_SYS_TICK) && (GKI_DELAY_STOP_SYS_TICK > 0))
286 UINT32 OSTicksTilStop; /* inactivity delay timer; OS Ticks till stopping system tick */
287#endif
288 INT32 OSNumOrigTicks; /* Number of ticks between last timer expiration to the next one */
289
290 INT32 OSWaitTmr [GKI_MAX_TASKS]; /* ticks the task has to wait, for specific events */
291
292 /* Only take up space timers used in the system (GKI_NUM_TIMERS defined in target.h) */
293#if (GKI_NUM_TIMERS > 0)
294 INT32 OSTaskTmr0 [GKI_MAX_TASKS];
295 INT32 OSTaskTmr0R [GKI_MAX_TASKS];
296#endif
297
298#if (GKI_NUM_TIMERS > 1)
299 INT32 OSTaskTmr1 [GKI_MAX_TASKS];
300 INT32 OSTaskTmr1R [GKI_MAX_TASKS];
301#endif
302
303#if (GKI_NUM_TIMERS > 2)
304 INT32 OSTaskTmr2 [GKI_MAX_TASKS];
305 INT32 OSTaskTmr2R [GKI_MAX_TASKS];
306#endif
307
308#if (GKI_NUM_TIMERS > 3)
309 INT32 OSTaskTmr3 [GKI_MAX_TASKS];
310 INT32 OSTaskTmr3R [GKI_MAX_TASKS];
311#endif
312
313
314
315 /* Buffer related variables
316 */
317 BUFFER_HDR_T *OSTaskQFirst[GKI_MAX_TASKS][NUM_TASK_MBOX]; /* array of pointers to the first event in the task mailbox */
318 BUFFER_HDR_T *OSTaskQLast [GKI_MAX_TASKS][NUM_TASK_MBOX]; /* array of pointers to the last event in the task mailbox */
319
320 /* Define the buffer pool management variables
321 */
322 FREE_QUEUE_T freeq[GKI_NUM_TOTAL_BUF_POOLS];
323
324#ifndef REVOLUTION
325 UINT16 pool_buf_size[GKI_NUM_TOTAL_BUF_POOLS];
326 UINT16 pool_max_count[GKI_NUM_TOTAL_BUF_POOLS];
327 UINT16 pool_additions[GKI_NUM_TOTAL_BUF_POOLS];
328#endif
329
330 /* Define the buffer pool start addresses
331 */
332 UINT8 *pool_start[GKI_NUM_TOTAL_BUF_POOLS]; /* array of pointers to the start of each buffer pool */
333 UINT8 *pool_end[GKI_NUM_TOTAL_BUF_POOLS]; /* array of pointers to the end of each buffer pool */
334 UINT16 pool_size[GKI_NUM_TOTAL_BUF_POOLS]; /* actual size of the buffers in a pool */
335
336 /* Define the buffer pool access control variables */
337 void *p_user_mempool; /* User O/S memory pool */
338 UINT16 pool_access_mask; /* Bits are set if the corresponding buffer pool is a restricted pool */
339 UINT8 pool_list[GKI_NUM_TOTAL_BUF_POOLS]; /* buffer pools arranged in the order of size */
340 UINT8 curr_total_no_of_pools; /* number of fixed buf pools + current number of dynamic pools */
341
342 BOOLEAN timer_nesting; /* flag to prevent timer interrupt nesting */
343
344#ifndef REVOLUTION
345 /* Time queue arrays */
346 TIMER_LIST_Q *timer_queues[GKI_MAX_TIMER_QUEUES];
347#endif
348
349#ifndef REVOLUTION
350 /* System tick callback */
351 SYSTEM_TICK_CBACK *p_tick_cb;
352 BOOLEAN system_tick_running; /* TRUE if system tick is running. Valid only if p_tick_cb is not NULL */
353#endif
354
355#if (GKI_DEBUG == TRUE)
356 UINT16 ExceptionCnt; /* number of GKI exceptions that have happened */
357 EXCEPTION_T Exception[GKI_MAX_EXCEPTION];
358#endif
359
361
362
363#ifdef __cplusplus
364extern "C" {
365#endif
366
367/* Internal GKI function prototypes
368*/
369GKI_API extern BOOLEAN gki_chk_buf_damage(void *);
370extern BOOLEAN gki_chk_buf_owner(void *);
371extern void gki_buffer_init (void);
372extern void gki_timers_init(void);
373extern void gki_adjust_timer_count (INT32);
374
375#ifdef GKI_USE_DEFERED_ALLOC_BUF_POOLS
376extern void gki_dealloc_free_queue(void);
377#endif
378
379extern void OSStartRdy(void);
380extern void OSCtxSw(void);
381extern void OSIntCtxSw(void);
382extern void OSSched(void);
383extern void OSIntEnter(void);
384extern void OSIntExit(void);
385
386
387/* Debug aids
388*/
389typedef void (*FP_PRINT)(char *, ...);
390
391#if (GKI_DEBUG == TRUE)
392
393typedef void (*PKT_PRINT)(UINT8 *, UINT16);
394
395extern void gki_print_task(FP_PRINT);
396extern void gki_print_exception(FP_PRINT);
397extern void gki_print_timer(FP_PRINT);
398extern void gki_print_stack(FP_PRINT);
399extern void gki_print_buffer(FP_PRINT);
400extern void gki_print_buffer_statistics(FP_PRINT, INT16);
401GKI_API extern void gki_print_used_bufs (FP_PRINT, UINT8);
402extern void gki_dump(UINT8 *, UINT16, FP_PRINT);
403extern void gki_dump2(UINT16 *, UINT16, FP_PRINT);
404extern void gki_dump4(UINT32 *, UINT16, FP_PRINT);
405
406#endif
407
408#ifdef __cplusplus
409}
410#endif
411
412#endif