ps2sdk  1.1
A collection of Open Source libraries used for developing applications on Sony's PlayStation 2® (PS2).
debug.h File Reference
#include <tamtypes.h>
+ Include dependency graph for debug.h:
+ This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Macros

#define DEBUG_BGCOLOR(col)   *((u64 *) 0x120000e0) = (u64) (col)
 

Functions

void init_scr (void)
 
void scr_printf (const char *,...)
 
void scr_putchar (int x, int y, u32 color, int ch)
 
void ps2GetStackTrace (unsigned int *results, int max)
 
void scr_setXY (int x, int y)
 
int scr_getX (void)
 
int scr_getY (void)
 
void scr_clear (void)
 
void scr_setbgcolor (u32 color)
 

Detailed Description

EE Debug prototypes

Definition in file debug.h.

Macro Definition Documentation

◆ DEBUG_BGCOLOR

#define DEBUG_BGCOLOR (   col)    *((u64 *) 0x120000e0) = (u64) (col)

Definition at line 21 of file debug.h.

Function Documentation

◆ init_scr()

void init_scr ( void  )

Definition at line 185 of file scr_printf.c.

186 {
187  static struct t_setupscr setupscr __attribute__ (( aligned (16) )) = {
188  { 0x100000000000800E, 0xE, 0xA0000, 0x4C, 0x8C, 0x4E }, //GIFtag (REGS: A+D, NREG 1, FLG PACKED, EOP, NLOOP 14), FRAME_1 (PSM PSMCT32, FBW 10, FBP 0), ZBUF_1 (PSM PSMZ32, ZBP 140)
189  { 27648, 30976 }, { 0x18 }, //XYOFFSET_1 (OFX 1728.0, OFY 1936.0)
190  { 0, 639, 0, 223 }, //SCISSOR_1 (SCAX0 0, SCAX1 639, SCAY0 0, SCAY1 223)
191  { 0x40, 1, 0x1a, 1, 0x46, 0, 0x45, 0x70000, //PRMODECONT (AC PRIM), COLCLAMP (CLAMP 1), DTHE (DTHE 0)
192  0x47, 0x30000, 0x47, 6, 0, 0x3F80000000000000, 1, 0x79006C00, 5, //TEST_1 (ZTST GREATER, ZTE 1), TEST_1 (ZTST ALWAYS, ZTE 1), PMODE (CRTMD 1, EN2 1), RGBAQ (Q 1.0, A 0, B 0, G 0, R 0), XYZ2 (Z 0.0, Y 1728.0, X 1936.0)
193  0x87009400, 5, 0x70000, 0x47 } //XYZ2 (Z 0, Y 2160.0, X 2368.0), TEST_1 (ZTST GREATER, ZTE 1)
194  };
195 
196  X = Y = 0;
197  DmaReset();
198 
199  Init_GS( 1, debug_detect_signal() == 1 ? 3 : 2, 0); // Interlaced, NTSC/PAL and FIELD mode
200 
201  SetVideoMode();
202  Dma02Wait();
203  progdma( &setupscr, 15);
204  Dma02Wait();
205 }
static void Init_GS(int interlace, int omode, int ffmd)
Definition: scr_printf.c:55
static short int X
Definition: scr_printf.c:24
static short int Y
Definition: scr_printf.c:24
static void SetVideoMode(void)
Definition: scr_printf.c:65
static void progdma(void *addr, int size)
Definition: scr_printf.c:163
static int debug_detect_signal()
Definition: scr_printf.c:48
static void DmaReset(void)
Definition: scr_printf.c:123
static void Dma02Wait(void)
Definition: scr_printf.c:103

References debug_detect_signal(), Dma02Wait(), DmaReset(), Init_GS(), progdma(), SetVideoMode(), X, and Y.

Referenced by main().

◆ ps2GetStackTrace()

void ps2GetStackTrace ( unsigned int *  results,
int  max 
)

Definition at line 119 of file callstack.c.

120 {
121  unsigned int* ra;
122  unsigned int* ra_limit;
123  unsigned int* sp;
124  unsigned int inst;
125  unsigned int mainCall;
126  unsigned short const_upper;
127  unsigned short const_lower;
128  int ra_offset;
129  int sp_adjust;
130  Bool found_ra_offset, found_sp_adjust;
131  Bool found_const_upper, found_const_lower;
132  ReturnCachePtr rc;
133 
136  mainCall = CALL(main);
137 
138  while (ra && max)
139  {
140  rc = &returnCache[HASH(ra)];
141  if (rc->returnAddress != ra)
142  {
143  found_ra_offset = FALSE;
144  found_sp_adjust = FALSE;
145  found_const_upper = FALSE;
146  found_const_lower = FALSE;
147  const_upper = 0;
148  const_lower = 0;
149  rc->returnAddress = ra;
150  ra_limit = (unsigned int *) 0x200000;
151  ra_offset = 0;
152  sp_adjust = -1;
153 
154  while ((!found_ra_offset || !found_sp_adjust) && ra < ra_limit)
155  {
156  inst = *ra;
157  /* look for the offset of the PC in the stack frame */
159  {
160  ra_offset = inst & ~RESTORE_RETURNVAL_MASK;
161  found_ra_offset = TRUE;
162  }
163  else if ((inst & RESTORE_RETURNVAL_MASK) == RESTORE_RETURNVAL2)
164  {
165  ra_offset = inst & ~RESTORE_RETURNVAL_MASK;
166  found_ra_offset = TRUE;
167  }
168  else if ((inst & RESTORE_RETURNVAL_MASK) == RESTORE_RETURNVAL3)
169  {
170  ra_offset = inst & ~RESTORE_RETURNVAL_MASK;
171  found_ra_offset = TRUE;
172  }
173  else if ((inst & ADJUST_STACKP_C_MASK) == ADJUST_STACKP_C)
174  {
175  sp_adjust = inst & ~ADJUST_STACKP_C_MASK;
176  found_sp_adjust = TRUE;
177  }
178  else if ((inst & ADJUST_STACKP_V_MASK) == ADJUST_STACKP_V)
179  {
180  sp_adjust = 0;
181  found_sp_adjust = TRUE;
182  }
183  else if ((inst & SET_UPPER_C_MASK) == SET_UPPER_C)
184  {
185  const_upper = inst & ~SET_UPPER_C_MASK;
186  const_lower = 0;
187  found_const_upper = TRUE;
188  }
189  else if ((inst & OR_LOWER_C_MASK) == OR_LOWER_C)
190  {
191  const_lower = inst & ~OR_LOWER_C_MASK;
192  found_const_lower = TRUE;
193  }
194  else if ((inst & SET_LOWER_C_MASK) == SET_LOWER_C)
195  {
196  const_lower = inst & ~SET_LOWER_C_MASK;
197  const_upper = 0;
198  found_const_lower = TRUE;
199  }
200  else if (inst == RETURN)
201  ra_limit = ra + 2;
202  ra++;
203  }
204 
205  if (sp_adjust == 0 && (found_const_upper || found_const_lower))
206  sp_adjust = (const_upper << 16) | const_lower;
207  rc->raOffset = ra_offset;
208  rc->spAdjust = sp_adjust;
209  }
210  /* if something went wrong, punt */
211  if (rc->spAdjust <= 0)
212  {
213  *results++ = 0;
214  break;
215  }
216 
217  ra = (unsigned int *) sp[rc->raOffset>>2];
218  sp += rc->spAdjust >> 2;
219 
220  if (ra == 0)
221  {
222  *results++ = 0;
223  break;
224  }
225 
226  *results++ = ((unsigned int) ra) - 8;
227  if (ra[-2] == mainCall)
228  {
229  *results++ = 0;
230  break;
231  }
232  max--;
233  }
234 }
#define ra
Definition: as_reg_compat.h:87
#define sp
Definition: as_reg_compat.h:85
static ReturnCacheRec returnCache[HASH_SIZE]
Definition: callstack.c:102
#define ADJUST_STACKP_C
Definition: callstack.c:56
#define ADJUST_STACKP_V_MASK
Definition: callstack.c:63
#define RESTORE_RETURNVAL_MASK
Definition: callstack.c:41
#define CALL(f)
Definition: callstack.c:86
#define RESTORE_RETURNVAL3
Definition: callstack.c:51
#define OR_LOWER_C
Definition: callstack.c:74
#define RESTORE_RETURNVAL2
Definition: callstack.c:46
#define HASH(ra)
Definition: callstack.c:104
#define RETURN
Definition: callstack.c:84
#define RESTORE_RETURNVAL
Definition: callstack.c:40
#define OR_LOWER_C_MASK
Definition: callstack.c:75
#define TRUE
Definition: callstack.c:109
#define FALSE
Definition: callstack.c:112
unsigned int * ps2GetReturnAddress()
#define SET_LOWER_C
Definition: callstack.c:80
unsigned int * ps2GetStackPointer()
#define SET_LOWER_C_MASK
Definition: callstack.c:81
#define SET_UPPER_C_MASK
Definition: callstack.c:69
#define ADJUST_STACKP_C_MASK
Definition: callstack.c:57
#define ADJUST_STACKP_V
Definition: callstack.c:62
int main()
Definition: callstacktest.c:45
#define SET_UPPER_C
Definition: callstack.c:68
int Bool
Definition: callstack.c:106
#define max(a, b)
Definition: standard.h:57

References ADJUST_STACKP_C, ADJUST_STACKP_C_MASK, ADJUST_STACKP_V, ADJUST_STACKP_V_MASK, CALL, FALSE, HASH, main(), max, OR_LOWER_C, OR_LOWER_C_MASK, ps2GetReturnAddress(), ps2GetStackPointer(), ra, RESTORE_RETURNVAL, RESTORE_RETURNVAL2, RESTORE_RETURNVAL3, RESTORE_RETURNVAL_MASK, RETURN, returnCache, SET_LOWER_C, SET_LOWER_C_MASK, SET_UPPER_C, SET_UPPER_C_MASK, sp, and TRUE.

Referenced by TestFunction3().

◆ scr_clear()

void scr_clear ( void  )

Definition at line 313 of file scr_printf.c.

314 {
315  int y;
316  for(y=0;y<MY;y++)
317  clear_line(y);
318  scr_setXY(0,0);
319 }
s32 y
Definition: libmouse.c:34
static void clear_line(int Y)
Definition: scr_printf.c:245
void scr_setXY(int x, int y)
Definition: scr_printf.c:297
static short int MY
Definition: scr_printf.c:25

References clear_line(), MY, scr_setXY(), and y.

Referenced by main().

◆ scr_getX()

int scr_getX ( void  )

Definition at line 303 of file scr_printf.c.

304 {
305  return X;
306 }

References X.

◆ scr_getY()

int scr_getY ( void  )

Definition at line 308 of file scr_printf.c.

309 {
310  return Y;
311 }

References Y.

Referenced by main().

◆ scr_printf()

void scr_printf ( const char *  format,
  ... 
)

Definition at line 252 of file scr_printf.c.

253 {
254  va_list opt;
255  char buff[2048], c;
256  int i, bufsz, j;
257 
258 
259  va_start(opt, format);
260  bufsz = vsnprintf(buff, sizeof(buff), format, opt);
261 
262  for (i = 0; i < bufsz; i++)
263  {
264  c = buff[i];
265  switch (c)
266  {
267  case '\n':
268  X = 0;
269  Y ++;
270  if (Y == MY)
271  Y = 0;
272  clear_line(Y);
273  break;
274  case '\t':
275  for (j = 0; j < 5; j++) {
276  scr_putchar( X*7 , Y * 8, 0xffffff, ' ');
277  X++;
278  }
279  break;
280  default:
281  scr_putchar( X*7 , Y * 8, 0xffffff, c);
282  X++;
283  if (X == MX)
284  {
285  X = 0;
286  Y++;
287  if (Y == MY)
288  Y = 0;
289  clear_line(Y);
290  }
291  }
292  }
293  scr_putchar( X*7 , Y * 8, 0xffffff, 219);
294  va_end(opt);
295 }
void scr_putchar(int x, int y, u32 color, int ch)
Definition: scr_printf.c:210
static short int MX
Definition: scr_printf.c:25

References clear_line(), MX, MY, scr_putchar(), X, and Y.

Referenced by ethPrintIPConfig(), ethPrintLinkStatus(), and main().

◆ scr_putchar()

void scr_putchar ( int  x,
int  y,
u32  color,
int  ch 
)

Definition at line 210 of file scr_printf.c.

211 {
212  static struct t_setupchar setupchar __attribute__((aligned(16))) = {
213  { 0x1000000000000004, 0xE, 0xA000000000000, 0x50 }, //GIFtag (REGS: A+D, NREG 1, FLG PACKED, NLOOP 4), BITBLTBUF (DPSM PSMCT32, DBW 10, DBP 0)
214  { 0 }, 100, 100, { 0x51 }, //TRXPOS (DSAX 100, DSAY 100)
215  { 8, 8 }, //TRXREG (RRW 8, RRH 8)
216  { 0x52, 0, 0x53, 0x800000000008010, 0} //TRXDIR (XDIR Host -> Local), GIFtag (FLG IMAGE, EOP, NLOOP 16)
217  };
218  /* charmap must be aligned to a 16-bye boundary. */
219  static u32 charmap[64] __attribute__((aligned(16)));
220  int i, j, l;
221  u8 *font;
222  u32 pixel;
223 
224  ((struct t_setupchar*)UNCACHED_SEG(&setupchar))->x = x;
225  ((struct t_setupchar*)UNCACHED_SEG(&setupchar))->y = y;
226 
227  progdma(&setupchar, 6);
228 
229  font = &msx[ ch * 8];
230  for (i=l=0; i < 8; i++, l+= 8, font++)
231  {
232  for (j=0; j < 8; j++)
233  {
234  pixel = ((*font & (128 >> j))) ? color : bgcolor;
235  *(u32*)UNCACHED_SEG(&charmap[ l + j]) = pixel;
236  }
237  }
238 
239  Dma02Wait();
240 
241  progdma(charmap, (8*8*4) / 16);
242  Dma02Wait();
243 }
#define UNCACHED_SEG(x)
Definition: kernel.h:35
s32 x
Definition: libmouse.c:34
static u32 bgcolor
Definition: scr_printf.c:26
u8 msx[]
Definition: font.c:18
unsigned int u32
Definition: tamtypes.h:30
unsigned char u8
Definition: tamtypes.h:23

References bgcolor, Dma02Wait(), msx, progdma(), UNCACHED_SEG, x, and y.

Referenced by clear_line(), and scr_printf().

◆ scr_setbgcolor()

void scr_setbgcolor ( u32  color)

Definition at line 180 of file scr_printf.c.

181 {
182  bgcolor = color;
183 }

References bgcolor.

◆ scr_setXY()

void scr_setXY ( int  x,
int  y 
)

Definition at line 297 of file scr_printf.c.

298 {
299  if( x<MX && x>=0 ) X=x;
300  if( y<MY && y>=0 ) Y=y;
301 }

References X, x, Y, and y.

Referenced by main(), and scr_clear().