summaryrefslogtreecommitdiff
path: root/cpu/amd/geode_lx/gplvsa_ii/sysmgr/errors.c
blob: 7d23c22c4980ef01d4bb781769a7a3c3663abc11 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
/*
* Copyright (c) 2006-2008 Advanced Micro Devices,Inc. ("AMD").
*
* This library is free software; you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of the
* License, or (at your option) any later version.
*
* This code is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.

* You should have received a copy of the GNU Lesser General
* Public License along with this library; if not, write to the
* Free Software Foundation, Inc., 59 Temple Place, Suite 330,
* Boston, MA 02111-1307 USA 
*/

//*****************************************************************************
//*    Implements the error reporting code.  
//*****************************************************************************




#include "VSA2.H"
#include "SYSMGR.H"
#include "PROTOS.H"

extern void pascal write_flat_size(ULONG, ULONG, UCHAR);
extern ULONG pascal Get_SysCall_Address(ULONG, UCHAR);
extern ULONG VSMs_EAX;
extern ULONG Saved_EAX, Saved_EBX, Saved_ECX, Saved_EDX, Saved_ESI, Saved_EDI;
extern ULONG Current_VSM;


#define MAX_ERROR_BUFFER  500
UCHAR ErrorStrings[MAX_ERROR_BUFFER];
UCHAR * ErrorBuffer = ErrorStrings;
UCHAR * CurrentError;
UCHAR * PreviousError = ErrorStrings;
UCHAR DuplicateFlag;

int letbase;


//***************************************************************************
// Input:
//    BH - 1 to clear error log
//    CL - Error number (0 for 1st)
// Exit:
//    AL - 0 if last error
//***************************************************************************
void Get_Errors()
{ USHORT ErrorNumber, Flag;
  ULONG Destination;

  // Get parameters passed in from INFO
  Flag = (UCHAR)(Saved_EBX >> 8);
  ErrorNumber = (UCHAR)Saved_ECX;
  Destination = Saved_EDI;

  (UCHAR)Saved_EAX = 0x00;

  // If no errors, return AL = 0;
  if (ErrorBuffer == ErrorStrings) {
	 return;
  }  

  // If request for 1st error, initialize buffer ptr
  if (ErrorNumber == 0) {
    CurrentError = ErrorStrings;
  } 


  // Copy next message to EDI
  while (CurrentError < ErrorBuffer) {
    // Copy 1 byte of error message
    write_flat_size(Destination++, (ULONG)*CurrentError, BYTE_IO);
    // If end of this message, return
    if (*CurrentError++ == 0) {

       write_flat_size(Destination-1, '$', BYTE_IO);

      (UCHAR)Saved_EAX = 1;

      // Is this the last message ?
      if (*CurrentError == 0) {
        // Clear error log ? (/E flag)
        if (Flag == 1) {
          PreviousError = ErrorBuffer = ErrorStrings;
        }
      }
      return;
    }
  }
} 






//*****************************************************************************
//*****************************************************************************
static void printchar(char **str, int c)
{
  out_8(DBG_PORT, (UCHAR)c);
  in_8(0x80);
  if (ErrorBuffer < &ErrorStrings[MAX_ERROR_BUFFER-2]) {
    *ErrorBuffer = c;
    if (*ErrorBuffer++ != *PreviousError++) {
	  DuplicateFlag = 0;
    }
  }	 
}

#define PAD_RIGHT 1
#define PAD_ZERO 2

//*****************************************************************************
//*****************************************************************************
static int prints(char **out, const char *string, int width, int pad)
{ register int pc = 0, padchar = ' ';

  if (width > 0) {
    register int len = 0;
    register const char *ptr;

    for (ptr = string; *ptr; ++ptr) {
      ++len;
    }

    if (len >= width) {
      width = 0;
    } else {
      width -= len;
    }

    if (pad & PAD_ZERO) {
      padchar = '0';
    }
  }


  if (!(pad & PAD_RIGHT)) {
    for ( ; width > 0; --width) {
      printchar(out, padchar);
      ++pc;
    }
  }

  for ( ; *string ; ++string) {
    printchar(out, *string);
    ++pc;
  }

  for ( ; width > 0; --width) {
    printchar(out, padchar);
    ++pc;
  }

  return pc;
}

/* the following should be enough for 32 bit int */
#define PRINT_BUF_LEN 12

//*****************************************************************************
// Prints an integer with the specified formatting
//*****************************************************************************
static int printi(char **out, unsigned long u, int base, int sg, int width, int pad)
{ char print_buf[PRINT_BUF_LEN];
  register char *s;
  register int t, neg = 0, pc = 0;

  if (u == 0) {
    print_buf[0] = '0';
    print_buf[1] = '\0';
    return prints (out, print_buf, width, pad);
  }
  if (sg && (base == 10) && (u & 0x8000)) {
    neg = 1;
    u = ~u;
    u++;
  }

  s = print_buf + PRINT_BUF_LEN-1;
  *s = '\0';

  while (u) {
    t = (int)(u % base);
    if (t >= 10 ) {
      t += letbase - '0' - 10;
    }
    *--s = t + '0';
    u /= base;
  }

  if (neg) {
    if (width && (pad & PAD_ZERO) ) {
      printchar(out, '-');
      ++pc;
      --width;
    } else {
      *--s = '-';
    }
  }

  return pc + prints(out, s, width, pad);
}

//*****************************************************************************
//*****************************************************************************
static int print(char **out, int *varg)
{ register int width, pad;
  register int pc = 0;
  register char *format = (char *)(*varg++);
  char scr[2];
  unsigned long number;
  char *s;


  for (; *format != 0; ++format) {
    if (*format == '%') {
      ++format;
      pad = 0;
      if (*format == '\0') {
        break;
      }

      switch (*format) {
        case '%':
          printchar(out, *format);
          ++pc;
          continue;
      
        case '-':
          ++format;
          pad = PAD_RIGHT;
          break;
      }

      while (*format == '0') {
        ++format;
        pad |= PAD_ZERO;
      }

      for (width = 0; *format >= '0' && *format <= '9'; ++format) {
        width *= 10;
        width += *format - '0';
      }

      letbase = 'a';
      switch (*format) {

        case 's':
          s = *((char **)varg++);
          pc += prints (out, s ? s :"(null)", width, pad);
          break;

        case 'u':
          number = *varg++;
          pc += printi (out, number, 10, 0, width, pad);
          break;

        case 'd':
          number = *varg++;
          pc += printi (out, number, 10, 1, width, pad);
          break;

        case 'x':
//        pc += printi (out, number, 16, 0, width, pad);
//        break;

        case 'X':
          letbase = 'A';
          number = (USHORT)*varg++;
          if (width > 4) {
            number |= (ULONG)(*varg++) << 16;
          }
          pc += printi (out, number, 16, 0, width, pad);
          break;

        case 'c':
          // char are converted to int then pushed on the stack
          scr[0] = *varg++;
          scr[1] = '\0';
          pc += prints (out, scr, width, pad);
          break;

      } // end switch

    } else {
      printchar(out, *format);
      ++pc;
    }
  } // end for

	if (out) {
      **out = '\0';
    }
	return pc;
}

//*****************************************************************************
//*****************************************************************************
void Log_Error(const char *format, ...)
{ register int *varg = (int *)(&format);
  UCHAR * SavedErrorBuffer;
  UCHAR * SavedPrevious;

  SavedErrorBuffer = ErrorBuffer;
  SavedPrevious = PreviousError;
  if (PreviousError == ErrorStrings) {
    DuplicateFlag = 0;
  } else {
    DuplicateFlag = 1;
  }

  // Store a formatted error message
  print(0, varg);

  // Terminate the error buffer
  if (ErrorBuffer < &ErrorStrings[MAX_ERROR_BUFFER]) {
    *(ErrorBuffer++) = 0;
  }

  // Same error as previous?
  if (DuplicateFlag) {
    // Yes, then restore ptrs
	PreviousError = SavedPrevious;
    ErrorBuffer = SavedErrorBuffer;
    *(ErrorBuffer) = 0;
  }	else {
    // No, then advance previous error buffer ptr
    PreviousError = SavedErrorBuffer;
  }

}



//*****************************************************************************
// Inserts an error entry into the error log.
//*****************************************************************************
void pascal Error_Report(UCHAR ErrorCode, ULONG Info1, ULONG Info2, ULONG Vsm, UCHAR Depth)
{ ULONG CallingAddress;
  static UCHAR ErrorString[50];

  CallingAddress = Get_SysCall_Address(Vsm, Depth);

  Log_Error("Error code 0x%02X reported at %08X. Parameters: 0x%08X and 0x%08X.", \
            ErrorCode, CallingAddress, Info1, Info2);
}


//*****************************************************************************
// Reports an error from a VSM.
//*****************************************************************************
void pascal Report_VSM_Error(UCHAR ErrorCode, ULONG Info1, ULONG Info2)
{
  if (Current_VSM == 0) {
    Error_Report(ErrorCode, Info1, Info2, SysMgr_VSM,  0);
  }	else {
    Error_Report(ErrorCode, Info1, Info2, Current_VSM, 1);
  }
}