summaryrefslogtreecommitdiffstats
path: root/c/src/lib/libbsp/m68k/ods68302/startup/trace.c
blob: 2c7613ceb7a362885f2bd66916ecdac1ed685165 (plain) (blame)
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
/*****************************************************************************/
/*
  $Id$

  Trace Exception dumps a back trace to the debug serial port

 */
/*****************************************************************************/

#include <bsp.h>
#include <debugport.h>

#if 0
/* FIXME : could get the string to print when in the BSP */
static const char *exception_names[] =
{
  "RESET STACK TOP",
  "RESET",
  "BUS ERROR",
  "ADDRESS ERROR",
  "ILLEGAL OPCODE",
  "ZERO DIVIDE",
  "CHK",
  "OVERFLOW",
  "PRIVILEGE",
  "TRACE",
  "LINE 1010 EMULATOR",
  "LINE 1111 EMULATOR",
  "UNASSIGNED 12",
  "UNASSIGNED 13",
  "FORMAT ERROR",
  "UNINITIALISED INTERRUPT",
  "UNASSIGNED 16",
  "NODE ANCHOR",
  "SYSTEM ANCHOR",
  "UNASSIGNED 19",
  "UNASSIGNED 20",
  "UNASSIGNED 21",
  "UNASSIGNED 22",
  "UNASSIGNED 23",
  "SPURIOUS HANDLER",
  "LEVEL 1",
  "LEVEL 2",
  "LEVEL 3",
  "LEVEL 4",
  "LEVEL 5",
  "LEVEL 6",
  "LEVEL 7",
  "TRAP 0",
  "TRAP 1",
  "TRAP 2",
  "TRAP 3",
  "TRAP 4",
  "TRAP 5",
  "TRAP 6",
  "TRAP 7",
  "TRAP 8",
  "TRAP 9",
  "TRAP 10",
  "TRAP 11",
  "TRAP 12",
  "TRAP 13",
  "TRAP 14",
  "TRAP 15"
};
#endif

void trace_exception(unsigned long d0,
                     unsigned long d1,
                     unsigned long d2,
                     unsigned long d3,
                     unsigned long d4,
                     unsigned long d5,
                     unsigned long d6,
                     unsigned long d7,
                     unsigned long a0,
                     unsigned long a1,
                     unsigned long a2,
                     unsigned long a3,
                     unsigned long a4,
                     unsigned long a5,
                     unsigned long a6,
                     unsigned long a7,
                     unsigned long sr_pch,
                     unsigned long pcl_format)
{
  unsigned int sr = sr_pch >> 16;
  unsigned long pc = (sr_pch << 16) | (pcl_format >> 16);
  unsigned int format = pcl_format & 0xFFFF;
  unsigned int index;
  unsigned char ch;

  __asm__ volatile(" orw #0x0700,%sr");

  debug_port_banner();

  debug_port_write("unhandled exception=");
  debug_port_write_hex_uint(format >> 2);
  debug_port_write("\n");

  debug_port_write("sr=");
  debug_port_write_hex_uint(sr);
  debug_port_write(", pc=");
  debug_port_write_hex_ulong(pc);
  debug_port_write("\n");

  for (index = 0; index < 16; index++)
  {
    if (index == 8)
    {
      debug_port_write("\n\r");
    }
    if (index < 8)
    {
      debug_port_out('d');
      debug_port_out('0' + index);
    }
    else
    {
      debug_port_out('a');
      debug_port_out('0' + index - 8);
    }
    debug_port_out('=');
    debug_port_write_hex_ulong(*(((unsigned long*) &d0) + index));
    debug_port_out(' ');
  }

  for (index = 0; index < (16 * 10); index++)
  {
    if ((index % 16) == 0)
    {
      debug_port_write("\n");
      debug_port_write_hex_ulong((unsigned long) (((char*) &index) + index));
      debug_port_write(" : ");
    }
    else
    {
      debug_port_out(' ');
    }

    ch = (*(((char*) &index) + index) >> 4) & 0x0F;

    if (ch < 10)
    {
      ch += '0';
    }
    else
    {
      ch += 'a' - 10;
    }

    debug_port_out((char) ch);

    ch = *(((char*) &index) + index) & 0x0F;

    if (ch < 10)
    {
      ch += '0';
    }
    else
    {
      ch += 'a' - 10;
    }
    debug_port_out((char) ch);
  }

  debug_port_write("\nhalting cpu...");

#if defined(UPDATE_DISPLAY)
  UPDATE_DISPLAY("HALT");
#endif

  WATCHDOG_TRIGGER();
  while (1 == 1);
}