OpenCores
URL https://opencores.org/ocsvn/openrisc/openrisc/trunk

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [orpsocv2/] [bench/] [sysc/] [src/] [GdbServerSC.cpp] - Blame information for rev 425

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 63 julius
// ----------------------------------------------------------------------------
2
 
3
// SystemC GDB RSP server: implementation
4
 
5
// Copyright (C) 2008  Embecosm Limited <info@embecosm.com>
6
 
7
// Contributor Jeremy Bennett <jeremy.bennett@embecosm.com>
8
// Contributor Julius Baxter <julius@orsoc.se>
9
 
10
// This file is part of the GDB interface to the cycle accurate model of the
11
// OpenRISC 1000 based system-on-chip, ORPSoC, built using Verilator.
12
 
13
// This program is free software: you can redistribute it and/or modify it
14
// under the terms of the GNU Lesser General Public License as published by
15
// the Free Software Foundation, either version 3 of the License, or (at your
16
// option) any later version.
17
 
18
// This program is distributed in the hope that it will be useful, but WITHOUT
19
// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
20
// FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public
21
// License for more details.
22
 
23
// You should have received a copy of the GNU Lesser General Public License
24
// along with this program.  If not, see <http://www.gnu.org/licenses/>.
25
 
26
// ----------------------------------------------------------------------------
27
 
28
// $Id$
29
 
30
#include <iostream>
31
#include <iomanip>
32
 
33
#include "GdbServerSC.h"
34
#include "Utils.h"
35
 
36
#include <errno.h>
37
#include <fcntl.h>
38
extern int monitor_to_gdb_pipe[2][2]; // [0][] - monitor to gdb, [1][] - gdb to monitor, [][0] - read, [][1] - write
39
 
40
using std::cerr;
41
using std::dec;
42
using std::endl;
43
using std::hex;
44
 
45
using sc_core::sc_fifo;
46
using sc_core::sc_module_name;
47
using sc_core::sc_stop;
48
using sc_core::sc_time;
49
 
50
 
51
SC_HAS_PROCESS (GdbServerSC);
52
 
53
//-----------------------------------------------------------------------------
54
//! Constructor for the GDB RSP server.
55
 
56
//! We create a SC_THREAD which will act as the listener. Must be a
57
//! thread, since we need to wait for the actions to complete.
58
 
59
//! The current scan chain is marked as undefined.
60
 
61
//! This makes use of the Embecosm cycle accurate SystemC JTAG interface.
62
 
63
//! @see Embecosm Application Note 5 "Using JTAG with SystemC: Implementation
64
//!      of a Cycle Accurate Interface"
65
//!      (http://www.embecosm.com/download/ean5.html)
66
 
67
//! @todo We do not handle a user coded l.trap properly (i.e. one that is not
68
//!       a breakpoint). Effectively it is ignored, whereas we ought to set up
69
//!       the exception registers and redirect through the trap vector.
70
 
71
//! @param[in] name             Name of this module, passed to the parent
72
//!                             constructor. 
73
//! @param[in] _tapActionQueue  Pointer to fifo of actions to be performed by
74
//!                             the JTAG interface
75
//-----------------------------------------------------------------------------
76
GdbServerSC::GdbServerSC (sc_module_name        name,
77
                          uint32_t              _flashStart,
78
                          uint32_t              _flashEnd,
79
                          int                   rspPort,
80
                          sc_fifo<TapAction *> *tapActionQueue) :
81
  sc_module (name),
82
  flashStart (_flashStart),
83
  flashEnd (_flashEnd)
84
{
85
  pkt       = new RspPacket (RSP_PKT_MAX);
86
  rsp       = new RspConnection (rspPort);
87
  debugUnit = new DebugUnitSC ("debug-unit", tapActionQueue);
88
  mpHash    = new MpHash ();
89
 
90
  /* Setup the pipes between or1200 monitor module and GDB stub */
91
  pipe(monitor_to_gdb_pipe[0]);
92
  pipe(monitor_to_gdb_pipe[1]);
93
 
94
  // Set non-blocking reads
95
#ifdef O_NONBLOCK /* The POSIX way */
96
  fcntl (monitor_to_gdb_pipe[0][0], F_SETFL, O_NONBLOCK);
97
  fcntl (monitor_to_gdb_pipe[1][0], F_SETFL, O_NONBLOCK);
98
#elif defined (O_NDELAY)
99
  fcntl (monitor_to_gdb_pipe[0][0], F_SETFL, O_NDELAY);
100
  fcntl (monitor_to_gdb_pipe[1][0], F_SETFL, O_NDELAY);
101
#endif /* O_NONBLOCK */
102
 
103
  SC_THREAD (rspServer);
104
 
105
}       // GdbServerSC ()
106
 
107
 
108
//-----------------------------------------------------------------------------
109
//! Destructor
110
 
111
//! Free up data structures
112
//-----------------------------------------------------------------------------
113
GdbServerSC::~GdbServerSC ()
114
{
115
  delete  mpHash;
116
  delete  debugUnit;
117
  delete  rsp;
118
  delete  pkt;
119
 
120
}       // ~GdbServerSC
121
 
122
 
123
//-----------------------------------------------------------------------------
124
//! SystemC thread to listen for RSP requests
125
 
126
//! JTAG actions will be queued as appropriate. Runs forever
127
 
128
//! We don't allow any actions until the target is out of its startup mode
129
//! (where the ROM is mapped into RAM space). This is determined by seeing if
130
//! the PPC is still in flash memory.
131
 
132
//! Have to use a thread, since we will end up waiting for actions to
133
//! complete.
134
//-----------------------------------------------------------------------------
135
void
136
GdbServerSC::rspServer ()
137
{
138
  // Reset the debug unit, and wait for ORPSoC to be ready, by noting when it
139
  // accesses an address outside of flash. Note that we use NPC, not PPC since
140
  // at reset PPC is zero, and would trigger a false positive.
141
 
142
  debugUnit->resetDebugUnit ();
143
  rsp_sigval = TARGET_SIGNAL_NONE;
144
  /*
145
  uint32_t npc;
146
  do
147
    {
148
      npc = debugUnit->readSpr (SPR_NPC);
149
    }
150
  while ((flashStart <= npc) && (npc <= flashEnd));
151
  */
152
  debugUnit->stall ();
153
  targetStopped = true;
154
 
155
  // Make sure we are connected.
156
  while (!rsp->isConnected ())
157
    {
158
      // Reconnect and stall the processor on a new connection
159
      if (!rsp->rspConnect ())
160
        {
161
          // Serious failure. Must abort execution.
162
          cerr << "*** Unable to continue: ABORTING" << endl;
163
          sc_stop ();
164
        }
165
 
166
      // Stall the processor until we get a command to handle.
167
      if (!debugUnit->isStalled ())
168
        {
169
          debugUnit->stall ();
170
        }
171
 
172
      targetStopped = true;             // Processor now not running
173
    }
174
 
175
 
176
  // Loop processing commands forever
177
  while (true)
178
    {
179
      if (!rsp->isConnected())
180
        {
181
          sc_stop ();
182
          return;
183
        }
184
      // Wait until the target has stopped. In this simplified implementation,
185
      // the only reasons for stopping are hitting a breakpoint (l.trap),
186
      // hardware single stepping or hitting a non-breakpoint l.trap. This
187
      // last is not cleanly handled at the moment (we ought to redirect the
188
      // restart through the trap exception vector).
189
      while (!targetStopped)
190
        {
191
 
192
          /* First check to see if the or1200 monitor module wants us to stall*/
193
          if (checkMonitorPipe())
194
            break;
195
 
196
          rspCheckForException();
197
 
198
          if (debugUnit->isStalled())
199
            {
200
              targetStopped = true;
201
 
202
              // If it's a breakpoint, then we need to back up one
203
              // instruction, so on restart we execute the actual
204
              // instruction.
205
              uint32_t  ppc = debugUnit->readSpr (SPR_PPC);
206
 
207
              if (NULL != mpHash->lookup (BP_MEMORY, ppc) && rsp_sigval == TARGET_SIGNAL_TRAP)
208
                {
209
                  writeNpc (ppc);
210
                }
211
 
212
              // Tell the client we've stopped.
213
              rspReportException ();
214
            }
215
          else if (rsp->rspSocketPeek() > 0)
216
            {
217
              if (rsp->rspSocketPeek() == 0x03) // ETX, end of text control char
218
                {
219
                  // Got an interrupt command from GDB, this function should
220
                  // pull the packet off the socket and stall the processor.
221
                  // and then send a stop reply packet with signal 
222
                  // TARGET_SIGNAL_NONE.
223
                  rspInterrupt();
224
                  targetStopped = true;         // Processor now not running
225
                }
226
            }
227
        }
228
 
229
      // Get a RSP client request
230
      rspClientRequest ();
231
    }
232
}       // rspServer ()
233
 
234
 
235
//-----------------------------------------------------------------------------
236
//! Deal with a request from the GDB client session
237
 
238
//! In general, apart from the simplest requests, this function replies on
239
//! other functions to implement the functionality.
240
 
241
//! @note It is the responsibility of the recipient to delete the packet when
242
//!       it is finished with. It is permissible to reuse the packet for a
243
//!       reply.
244
 
245
//! @todo Is this the implementation of the 'D' packet really the intended
246
//!       meaning? Or does it just mean that only vAttach will be recognized
247
//!       after this?
248
 
249
//! @param[in] pkt  The received RSP packet
250
//-----------------------------------------------------------------------------
251
void
252
GdbServerSC::rspClientRequest ()
253
{
254
  if (!rsp->getPkt (pkt))
255
    {
256
      rsp->rspClose ();                 // Comms failure
257
      return;
258
    }
259 66 julius
  //Uncomment the next line for the RSP client to print out every packet it gets from GDB
260 63 julius
  //cerr << "rspClientRequest: " << pkt->data/*[0]*/ << endl;
261
  switch (pkt->data[0])
262
    {
263
    case '!':
264
      // Request for extended remote mode
265
      pkt->packStr ("OK");
266
      rsp->putPkt (pkt);
267
      return;
268
 
269
    case '?':
270
      // Return last signal ID
271
      rspReportException ();
272
      return;
273
 
274
    case 'A':
275
      // Initialization of argv not supported
276
      cerr << "Warning: RSP 'A' packet not supported: ignored" << endl;
277
      pkt->packStr ("E01");
278
      rsp->putPkt (pkt);
279
      return;
280
 
281
    case 'b':
282
      // Setting baud rate is deprecated
283
      cerr << "Warning: RSP 'b' packet is deprecated and not "
284
           << "supported: ignored" << endl;
285
      return;
286
 
287
    case 'B':
288
      // Breakpoints should be set using Z packets
289
      cerr << "Warning: RSP 'B' packet is deprecated (use 'Z'/'z' "
290
           << "packets instead): ignored" << endl;
291
      return;
292
 
293
    case 'c':
294
      // Continue
295
      rspContinue (EXCEPT_NONE);
296
      return;
297
 
298
    case 'C':
299
      // Continue with signal (in the packet)
300
      rspContinue ();
301
      return;
302
 
303
    case 'd':
304
      // Disable debug using a general query
305
      cerr << "Warning: RSP 'd' packet is deprecated (define a 'Q' "
306
           << "packet instead: ignored" << endl;
307
      return;
308
 
309
    case 'D':
310
      // Detach GDB. Do this by closing the client. The rules say that
311
      // execution should continue, so unstall the processor.
312
      pkt->packStr("OK");
313
      rsp->putPkt (pkt);
314
      rsp->rspClose ();
315
      //debugUnit->unstall ();      
316
      return;
317
 
318
    case 'F':
319
      // File I/O is not currently supported
320
      cerr << "Warning: RSP file I/O not currently supported: 'F' "
321
           << "packet ignored" << endl;
322
      return;
323
 
324
    case 'g':
325
      rspReadAllRegs ();
326
      return;
327
 
328
    case 'G':
329
      rspWriteAllRegs ();
330
      return;
331
 
332
    case 'H':
333
      // Set the thread number of subsequent operations. For now ignore
334
      // silently and just reply "OK"
335
      pkt->packStr ("OK");
336
      rsp->putPkt (pkt);
337
      return;
338
 
339
    case 'i':
340
    case 'I':
341
      // Single cycle step not currently supported. Mark the target as
342
      // running, so that next time it will be detected as stopped (it is
343
      // still stalled in reality) and an ack sent back to the client.
344
      cerr << "Warning: RSP cycle stepping not supported: target "
345
           << "stopped immediately" << endl;
346
      targetStopped = false;
347
      return;
348
 
349
    case 'k':
350
      // Kill request. Do nothing for now.
351
      return;
352
 
353
    case 'm':
354
      // Read memory (symbolic)
355
      rspReadMem ();
356
      return;
357
 
358
    case 'M':
359
      // Write memory (symbolic)
360
      rspWriteMem ();
361
      return;
362
 
363
    case 'p':
364
      // Read a register
365
      rspReadReg ();
366
      return;
367
 
368
    case 'P':
369
      // Write a register
370
      rspWriteReg ();
371
      return;
372
 
373
    case 'q':
374
      // Any one of a number of query packets
375
      rspQuery ();
376
      return;
377
 
378
    case 'Q':
379
      // Any one of a number of set packets
380
      rspSet ();
381
      return;
382
 
383
    case 'r':
384
      // Reset the system. Deprecated (use 'R' instead)
385
      cerr << "Warning: RSP 'r' packet is deprecated (use 'R' "
386
                << "packet instead): ignored" << endl;
387
      return;
388
 
389
    case 'R':
390
      // Restart the program being debugged.
391
      rspRestart ();
392
      return;
393
 
394
    case 's':
395
      // Single step one machine instruction.
396
      rspStep (EXCEPT_NONE);
397
      return;
398
 
399
    case 'S':
400
      // Single step one machine instruction.
401
      rspStep ();
402
      return;
403
 
404
    case 't':
405
      // Search. This is not well defined in the manual and for now we don't
406
      // support it. No response is defined.
407
      cerr << "Warning: RSP 't' packet not supported: ignored"
408
                << endl;
409
      return;
410
 
411
    case 'T':
412
      // Is the thread alive. We are bare metal, so don't have a thread
413
      // context. The answer is always "OK".
414
      pkt->packStr ("OK");
415
      rsp->putPkt (pkt);
416
      return;
417
 
418
    case 'v':
419
      // Any one of a number of packets to control execution
420
      rspVpkt ();
421
      return;
422
 
423
    case 'X':
424
      // Write memory (binary)
425
      rspWriteMemBin ();
426
      return;
427
 
428
    case 'z':
429
      // Remove a breakpoint/watchpoint.
430
      rspRemoveMatchpoint ();
431
      return;
432
 
433
    case 'Z':
434
      // Insert a breakpoint/watchpoint.
435
      rspInsertMatchpoint ();
436
      return;
437
 
438
    default:
439
      // Unknown commands are ignored
440
      cerr << "Warning: Unknown RSP request" << pkt->data << endl;
441
      return;
442
    }
443
}       // rspClientRequest ()
444
 
445
 
446
 
447
//-----------------------------------------------------------------------------
448
//! Check if processor is stalled. If it is, read the DRR and return the
449
//! target signal code.
450
//-----------------------------------------------------------------------------
451
void
452
GdbServerSC::rspCheckForException()
453
{
454
 
455
  uint32_t drr;
456
 
457
  if (!debugUnit->isStalled())
458
    {
459
      // Processor not stalled. Just return;
460
      return;
461
    }
462
 
463
  switch ((debugUnit->readSpr(SPR_DRR)&0xffffffff))
464
    {
465
    case SPR_DRR_RSTE:  rsp_sigval = TARGET_SIGNAL_PWR;  break;
466
    case SPR_DRR_BUSEE: rsp_sigval = TARGET_SIGNAL_BUS;  break;
467
    case SPR_DRR_DPFE:  rsp_sigval = TARGET_SIGNAL_SEGV; break;
468
    case SPR_DRR_IPFE:  rsp_sigval = TARGET_SIGNAL_SEGV; break;
469
    case SPR_DRR_TTE:   rsp_sigval = TARGET_SIGNAL_ALRM; break;
470
    case SPR_DRR_AE:    rsp_sigval = TARGET_SIGNAL_BUS;  break;
471
    case SPR_DRR_IIE:   rsp_sigval = TARGET_SIGNAL_ILL;  break;
472
    case SPR_DRR_IE:    rsp_sigval = TARGET_SIGNAL_INT;  break;
473
    case SPR_DRR_DME:   rsp_sigval = TARGET_SIGNAL_SEGV; break;
474
    case SPR_DRR_IME:   rsp_sigval = TARGET_SIGNAL_SEGV; break;
475
    case SPR_DRR_RE:    rsp_sigval = TARGET_SIGNAL_FPE;  break;
476
    case SPR_DRR_SCE:   rsp_sigval = TARGET_SIGNAL_USR2; break;
477
    case SPR_DRR_FPE:   rsp_sigval = TARGET_SIGNAL_FPE;  break;
478
    case SPR_DRR_TE:    rsp_sigval = TARGET_SIGNAL_TRAP; break;
479
 
480
    default:
481
      // This must be the case of single step (which does not set DRR)
482
      rsp_sigval = TARGET_SIGNAL_TRAP; break;
483
    }
484
 
485
  return;
486
}
487
 
488
//-----------------------------------------------------------------------------
489
//! Send a packet acknowledging an exception has occurred
490
 
491
//! The only signal we ever see in this implementation is TRAP.
492
//-----------------------------------------------------------------------------
493
void
494
GdbServerSC::rspReportException ()
495
{
496
  // Construct a signal received packet
497
  pkt->data[0] = 'S';
498
  pkt->data[1] = Utils::hex2Char (rsp_sigval >> 4);
499
  pkt->data[2] = Utils::hex2Char (rsp_sigval % 16);
500
  pkt->data[3] = '\0';
501
  pkt->setLen (strlen (pkt->data));
502
 
503
  rsp->putPkt (pkt);
504
 
505
}       // rspReportException ()
506
 
507
 
508
//-----------------------------------------------------------------------------
509
//! Handle a RSP continue request
510
 
511
//! This version is typically used for the 'c' packet, to continue without
512
//! signal, in which case EXCEPT_NONE is passed in as the exception to use.
513
 
514
//! At present other exceptions are not supported
515
 
516
//! @param[in] except  The OpenRISC 1000 exception to use
517
//-----------------------------------------------------------------------------
518
void
519
GdbServerSC::rspContinue (uint32_t   except)
520
{
521
  uint32_t  addr;                       // Address to continue from, if any
522
 
523
  // Reject all except 'c' packets
524
  if ('c' != pkt->data[0])
525
    {
526
      cerr << "Warning: Continue with signal not currently supported: "
527
           << "ignored" << endl;
528
      return;
529
    }
530
 
531
  // Get an address if we have one
532
  if (0 == strcmp ("c", pkt->data))
533
    {
534
      addr = readNpc ();                // Default uses current NPC
535
    }
536
  else if (1 != sscanf (pkt->data, "c%lx", &addr))
537
    {
538
      cerr << "Warning: RSP continue address " << pkt->data
539
                << " not recognized: ignored" << endl;
540
      addr = readNpc ();                // Default uses current NPC
541
    }
542
 
543
  rspContinue (addr, EXCEPT_NONE);
544
 
545
}       // rspContinue ()
546
 
547
 
548
//-----------------------------------------------------------------------------
549
//! Handle a RSP continue with signal request
550
 
551
//! @todo Currently does nothing. Will use the underlying generic continue
552
//!       function. 
553
//-----------------------------------------------------------------------------
554
void
555
GdbServerSC::rspContinue ()
556
{
557
  cerr << "RSP continue with signal '" << pkt->data
558
       << "' received" << endl;
559
 
560
}       // rspContinue ()
561
 
562
 
563
//-----------------------------------------------------------------------------
564
//! Generic processing of a continue request
565
 
566
//! The signal may be EXCEPT_NONE if there is no exception to be
567
//! handled. Currently the exception is ignored.
568
 
569
//! The single step flag is cleared in the debug registers and then the
570
//! processor is unstalled.
571
 
572
//! @param[in] addr    Address from which to step
573
//! @param[in] except  The exception to use (if any)                         
574
//-----------------------------------------------------------------------------
575
void
576
GdbServerSC::rspContinue (uint32_t  addr,
577
                          uint32_t  except)
578
{
579
  // Set the address as the value of the next program counter
580
  writeNpc (addr);
581
 
582
  /*
583
  // If we're continuing from a breakpoint, replace that instruction in the memory
584
  // ... actually no, I was wrong about this.
585
  if (NULL != mpHash->lookup (BP_MEMORY, addr) && rsp_sigval == TARGET_SIGNAL_TRAP)
586
    {
587
      MpEntry *entry = mpHash->lookup (BP_MEMORY, addr);
588
      debugUnit->writeMem32(entry->addr, entry->instr);
589
    }
590
  */
591
 
592
  // Clear Debug Reason Register and watchpoint break generation in Debug Mode
593
  // Register 2 for watchpoints that we triggered to stop this time.
594
  debugUnit->writeSpr (SPR_DRR,  0);
595
  if (rsp_sigval == TARGET_SIGNAL_TRAP)
596
    {
597
      /*
598
         Disable last trap generation on watchpoint if this is why we stopped
599
         last time.
600
      */
601
      uint32_t temp_dmr2 = debugUnit->readSpr (SPR_DMR2);
602
      if (temp_dmr2 & SPR_DMR2_WBS)
603
        {
604
          /*
605
             One of these breakpoints is responsible for our stopping, so
606
             disable it this time we start. GDB will send a packet re-enabling
607
             it next time we continue.
608
          */
609
          debugUnit->writeSpr (SPR_DMR2, temp_dmr2 & ~((temp_dmr2&SPR_DMR2_WBS)>>10));
610
        }
611
    }
612
 
613
  // Clear the single step trigger in Debug Mode Register 1 and set traps to
614
  // be handled by the debug unit in the Debug Stop Register
615
  debugUnit->andSpr (SPR_DMR1, ~SPR_DMR1_ST);
616
  debugUnit->orSpr ( SPR_DSR,  SPR_DSR_TE);
617
 
618
  // Unstall the processor. Note the GDB client is now waiting for a reply,
619
  // which it will get as soon as the processor stalls again.
620
  debugUnit->unstall ();
621
  targetStopped = false;
622
 
623
}       // rspContinue ()
624
 
625
 
626
 
627
//------------------------------------------------------------------------------
628
//!Handle an interrupt from GDB
629
 
630
//! Detect an interrupt from GDB and stall the processor                        
631
//------------------------------------------------------------------------------
632
void
633
GdbServerSC::rspInterrupt()
634
{
635
  unsigned char  c;
636
 
637
  c = rsp->getRspChar();
638
  if (c < 0)
639
    {
640
      // Had issues, just return
641
      return;
642
    }
643
 
644
  // Ensure this is a ETX control char (0x3), currently, we only call this
645
  // function when we've peeked and seen it, otherwise, ignore, return and pray
646
  // things go back to normal...
647
  if (c != 0x03)
648
    {
649
      cerr << "* Warning: Interrupt character expected but not found on socket" << endl;
650
      return;
651
    }
652
 
653
  // Otherwise, it's an interrupt packet, stall the processor, and upon return
654
  // to the main handle_rsp() loop, it will inform GDB.
655
 
656
  debugUnit->stall ();
657
 
658
  // Send a stop reply response, manually set rsp.sigval to TARGET_SIGNAL_NONE
659
  rsp_sigval = TARGET_SIGNAL_NONE;
660
  rspReportException();
661
 
662
  return;
663
 
664
}
665
 
666
//-----------------------------------------------------------------------------
667
//! Handle a RSP read all registers request
668
 
669
//! The registers follow the GDB sequence for OR1K: GPR0 through GPR31, PPC
670
//! (i.e. SPR PPC), NPC (i.e. SPR NPC) and SR (i.e. SPR SR). Each register is
671
//! returned as a sequence of bytes in target endian order.
672
 
673
//! Each byte is packed as a pair of hex digits.                             
674
//-----------------------------------------------------------------------------
675
void
676
GdbServerSC::rspReadAllRegs ()
677
{
678
  // The GPRs
679
  for (int  r = 0; r < max_gprs; r++)
680
    {
681
      Utils::reg2Hex (readGpr (r), &(pkt->data[r * 8]));
682
    }
683
 
684
  // PPC, NPC and SR
685
  Utils::reg2Hex (debugUnit->readSpr (SPR_PPC), &(pkt->data[PPC_REGNUM * 8]));
686
  Utils::reg2Hex (readNpc (),                   &(pkt->data[NPC_REGNUM * 8]));
687
  Utils::reg2Hex (debugUnit->readSpr (SPR_SR),  &(pkt->data[SR_REGNUM  * 8]));
688
 
689
  // Finalize the packet and send it
690
  pkt->data[NUM_REGS * 8] = 0;
691
  pkt->setLen (NUM_REGS * 8);
692
  rsp->putPkt (pkt);
693
 
694
}       // rspReadAllRegs ()
695
 
696
 
697
//-----------------------------------------------------------------------------
698
//! Handle a RSP write all registers request
699
 
700
//! The registers follow the GDB sequence for OR1K: GPR0 through GPR31, PPC
701
//! (i.e. SPR PPC), NPC (i.e. SPR NPC) and SR (i.e. SPR SR). Each register is
702
//! supplied as a sequence of bytes in target endian order.
703
 
704
//! Each byte is packed as a pair of hex digits.
705
 
706
//! @todo There is no error checking at present. Non-hex chars will generate a
707
//!       warning message, but there is no other check that the right amount
708
//!       of data is present. The result is always "OK".
709
//-----------------------------------------------------------------------------
710
void
711
GdbServerSC::rspWriteAllRegs ()
712
{
713
  // The GPRs
714
  for (int  r = 0; r < max_gprs; r++)
715
    {
716
      writeGpr (r, Utils::hex2Reg (&(pkt->data[r * 8])));
717
    }
718
 
719
  // PPC, NPC and SR
720
  debugUnit->writeSpr (SPR_PPC, Utils::hex2Reg (&(pkt->data[PPC_REGNUM * 8])));
721
  debugUnit->writeSpr (SPR_SR,  Utils::hex2Reg (&(pkt->data[SR_REGNUM  * 8])));
722
  writeNpc (                    Utils::hex2Reg (&(pkt->data[NPC_REGNUM * 8])));
723
 
724
  // Acknowledge (always OK for now).
725
  pkt->packStr ("OK");
726
  rsp->putPkt (pkt);
727
 
728
}       // rspWriteAllRegs ()
729
 
730
 
731
//-----------------------------------------------------------------------------
732
//! Handle a RSP read memory (symbolic) request
733
 
734
//! Syntax is:
735
 
736
//!   m<addr>,<length>:
737
 
738
//! The response is the bytes, lowest address first, encoded as pairs of hex
739
//! digits.
740
 
741
//! The length given is the number of bytes to be read.
742
//-----------------------------------------------------------------------------
743
void
744
GdbServerSC::rspReadMem ()
745
{
746
  unsigned int    addr;                 // Where to read the memory
747
  int             len;                  // Number of bytes to read
748
  int             off;                  // Offset into the memory
749
 
750
  if (2 != sscanf (pkt->data, "m%x,%x:", &addr, &len))
751
    {
752
      cerr << "Warning: Failed to recognize RSP read memory command: "
753
                << pkt->data << endl;
754
      pkt->packStr ("E01");
755
      rsp->putPkt (pkt);
756
      return;
757
    }
758
 
759
  // Make sure we won't overflow the buffer (2 chars per byte)
760
  if ((len * 2) >= pkt->getBufSize())
761
    {
762
      cerr << "Warning: Memory read " << pkt->data
763
           << " too large for RSP packet: truncated" << endl;
764
      len = (pkt->getBufSize() - 1) / 2;
765
    }
766
  //cerr << "rspReadMem: " << len << " bytes@0x"<< hex << addr << endl;
767
  // Refill the buffer with the reply
768
  for (off = 0; off < len; off++)
769
    {
770
      unsigned char  ch = debugUnit->readMem8 (addr + off);
771
 
772
      pkt->data[off * 2]     = Utils::hex2Char(ch >>   4);
773
      pkt->data[off * 2 + 1] = Utils::hex2Char(ch &  0xf);
774
    }
775
 
776
  pkt->data[off * 2] = '\0';                    // End of string
777
  pkt->setLen (strlen (pkt->data));
778
  rsp->putPkt (pkt);
779
 
780
}       // rsp_read_mem ()
781
 
782
 
783
//-----------------------------------------------------------------------------
784
//! Handle a RSP write memory (symbolic) request
785
 
786
//! Syntax is:
787
 
788
//!   m<addr>,<length>:<data>
789
 
790
//! The data is the bytes, lowest address first, encoded as pairs of hex
791
//! digits.
792
 
793
//! The length given is the number of bytes to be written.
794
//-----------------------------------------------------------------------------
795
void
796
GdbServerSC::rspWriteMem ()
797
{
798
  uint32_t  addr;                       // Where to write the memory
799
  int       len;                        // Number of bytes to write
800
 
801
  if (2 != sscanf (pkt->data, "M%x,%x:", &addr, &len))
802
    {
803
      cerr << "Warning: Failed to recognize RSP write memory "
804
                << pkt->data << endl;
805
      pkt->packStr ("E01");
806
      rsp->putPkt (pkt);
807
      return;
808
    }
809
 
810
  // Find the start of the data and check there is the amount we expect.
811
  char *symDat = (char *)(memchr (pkt->data, ':', pkt->getBufSize())) + 1;
812
  int   datLen = pkt->getLen() - (symDat - pkt->data);
813
 
814
  // Sanity check
815
  if (len * 2 != datLen)
816
    {
817
      cerr << "Warning: Write of " << len * 2 << "digits requested, but "
818
                << datLen << " digits supplied: packet ignored" << endl;
819
      pkt->packStr ("E01");
820
      rsp->putPkt (pkt);
821
      return;
822
    }
823
 
824
  // Write the bytes to memory (no check the address is OK here)
825
  for (int  off = 0; off < len; off++)
826
    {
827
      uint8_t  nyb1 = Utils::char2Hex (symDat[off * 2]);
828
      uint8_t  nyb2 = Utils::char2Hex (symDat[off * 2 + 1]);
829
 
830
      if (!debugUnit->writeMem8 (addr + off, (nyb1 << 4) | nyb2))
831
        {
832
          pkt->packStr ("E01");
833
          rsp->putPkt (pkt);
834
          return;
835
        }
836
    }
837
 
838
  pkt->packStr ("OK");
839
  rsp->putPkt (pkt);
840
 
841
}       // rspWriteMem ()
842
 
843
 
844
//-----------------------------------------------------------------------------
845
//! Read a single register
846
 
847
//! The registers follow the GDB sequence for OR1K: GPR0 through GPR31, PC
848
//! (i.e. SPR NPC) and SR (i.e. SPR SR). The register is returned as a
849
//! sequence of bytes in target endian order.
850
 
851
//! Each byte is packed as a pair of hex digits.
852
//-----------------------------------------------------------------------------
853
void
854
GdbServerSC::rspReadReg ()
855
{
856
  unsigned int  regNum;
857
 
858
  // Break out the fields from the data
859
  if (1 != sscanf (pkt->data, "p%x", &regNum))
860
    {
861
      cerr << "Warning: Failed to recognize RSP read register command: "
862
                << pkt->data << endl;
863
      pkt->packStr ("E01");
864
      rsp->putPkt (pkt);
865
      return;
866
    }
867
 
868
  // Get the relevant register
869
  if (regNum < max_gprs)
870
    {
871
      Utils::Utils::reg2Hex (readGpr (regNum), pkt->data);
872
    }
873
  else if (PPC_REGNUM == regNum)
874
    {
875
      Utils::Utils::reg2Hex (debugUnit->readSpr (SPR_PPC), pkt->data);
876
    }
877
  else if (NPC_REGNUM == regNum)
878
    {
879
      Utils::Utils::reg2Hex (readNpc (), pkt->data);
880
    }
881
  else if (SR_REGNUM == regNum)
882
    {
883
      Utils::Utils::reg2Hex (debugUnit->readSpr (SPR_SR), pkt->data);
884
    }
885
  else
886
    {
887
      // Error response if we don't know the register
888
      cerr << "Warning: Attempt to read unknown register" << regNum
889
                << ": ignored" << endl;
890
      pkt->packStr ("E01");
891
      rsp->putPkt (pkt);
892
      return;
893
    }
894
 
895
  pkt->setLen (strlen (pkt->data));
896
  rsp->putPkt (pkt);
897
 
898
}       // rspWriteReg ()
899
 
900
 
901
//-----------------------------------------------------------------------------
902
//! Write a single register
903
 
904
//! The registers follow the GDB sequence for OR1K: GPR0 through GPR31, PC
905
//! (i.e. SPR NPC) and SR (i.e. SPR SR). The register is specified as a
906
//! sequence of bytes in target endian order.
907
 
908
//! Each byte is packed as a pair of hex digits.
909
//-----------------------------------------------------------------------------
910
void
911
GdbServerSC::rspWriteReg ()
912
{
913
  unsigned int  regNum;
914
  char          valstr[9];              // Allow for EOS on the string
915
 
916
  // Break out the fields from the data
917
  if (2 != sscanf (pkt->data, "P%x=%8s", &regNum, valstr))
918
    {
919
      cerr << "Warning: Failed to recognize RSP write register command "
920
           << pkt->data << endl;
921
      pkt->packStr ("E01");
922
      rsp->putPkt (pkt);
923
      return;
924
    }
925
 
926
  // Set the relevant register
927
  if (regNum < max_gprs)
928
    {
929
      writeGpr (regNum, Utils::hex2Reg (valstr));
930
    }
931
  else if (PPC_REGNUM == regNum)
932
    {
933
      debugUnit->writeSpr (SPR_PPC, Utils::hex2Reg (valstr));
934
    }
935
  else if (NPC_REGNUM == regNum)
936
    {
937
      writeNpc (Utils::hex2Reg (valstr));
938
    }
939
  else if (SR_REGNUM == regNum)
940
    {
941
      debugUnit->writeSpr (SPR_SR, Utils::hex2Reg (valstr));
942
    }
943
  else
944
    {
945
      // Error response if we don't know the register
946
      cerr << "Warning: Attempt to write unknown register " << regNum
947
                << ": ignored" << endl;
948
      pkt->packStr ("E01");
949
      rsp->putPkt (pkt);
950
      return;
951
    }
952
 
953
  pkt->packStr ("OK");
954
  rsp->putPkt (pkt);
955
 
956
}       // rspWriteReg ()
957
 
958
 
959
//-----------------------------------------------------------------------------
960
//! Handle a RSP query request
961
//-----------------------------------------------------------------------------
962
void
963
GdbServerSC::rspQuery ()
964
{
965 425 julius
  if (0 == strcmp ("qAttached", pkt->data))
966 63 julius
    {
967 425 julius
      // We are always attaching to an existing process with the bare metal
968
      // embedded system. 
969
      pkt->packStr ("1");
970
      rsp->putPkt (pkt);
971
    }
972
  else if (0 == strcmp ("qC", pkt->data))
973
    {
974 63 julius
      // Return the current thread ID (unsigned hex). A null response
975
      // indicates to use the previously selected thread. We use the constant
976
      // OR1KSIM_TID to represent our single thread of control.
977
      sprintf (pkt->data, "QC%x", OR1KSIM_TID);
978
      pkt->setLen (strlen (pkt->data));
979
      rsp->putPkt (pkt);
980
    }
981
  else if (0 == strncmp ("qCRC", pkt->data, strlen ("qCRC")))
982
    {
983
      // Return CRC of memory area
984
      cerr << "Warning: RSP CRC query not supported" << endl;
985
      pkt->packStr ("E01");
986
      rsp->putPkt (pkt);
987
    }
988
  else if (0 == strcmp ("qfThreadInfo", pkt->data))
989
    {
990
      // Return info about active threads. We return just the constant
991
      // OR1KSIM_TID to represent our single thread of control.
992
      sprintf (pkt->data, "m%x", OR1KSIM_TID);
993
      pkt->setLen (strlen (pkt->data));
994
      rsp->putPkt (pkt);
995
    }
996
  else if (0 == strcmp ("qsThreadInfo", pkt->data))
997
    {
998
      // Return info about more active threads. We have no more, so return the
999
      // end of list marker, 'l'
1000
      pkt->packStr ("l");
1001
      rsp->putPkt (pkt);
1002
    }
1003
  else if (0 == strncmp ("qGetTLSAddr:", pkt->data, strlen ("qGetTLSAddr:")))
1004
    {
1005
      // We don't support this feature
1006
      pkt->packStr ("");
1007
      rsp->putPkt (pkt);
1008
    }
1009
  else if (0 == strncmp ("qL", pkt->data, strlen ("qL")))
1010
    {
1011
      // Deprecated and replaced by 'qfThreadInfo'
1012
      cerr << "Warning: RSP qL deprecated: no info returned" << endl;
1013
      pkt->packStr ("qM001");
1014
      rsp->putPkt (pkt);
1015
    }
1016
  else if (0 == strcmp ("qOffsets", pkt->data))
1017
    {
1018
      // Report any relocation
1019
      pkt->packStr ("Text=0;Data=0;Bss=0");
1020
      rsp->putPkt (pkt);
1021
    }
1022
  else if (0 == strncmp ("qP", pkt->data, strlen ("qP")))
1023
    {
1024
      // Deprecated and replaced by 'qThreadExtraInfo'
1025
      cerr << "Warning: RSP qP deprecated: no info returned" << endl;
1026
      pkt->packStr ("");
1027
      rsp->putPkt (pkt);
1028
    }
1029
  else if (0 == strncmp ("qRcmd,", pkt->data, strlen ("qRcmd,")))
1030
    {
1031
      // This is used to interface to commands to do "stuff"
1032
      rspCommand ();
1033
    }
1034
  else if (0 == strncmp ("qSupported", pkt->data, strlen ("qSupported")))
1035
    {
1036
      // Report a list of the features we support. For now we just ignore any
1037
      // supplied specific feature queries, but in the future these may be
1038
      // supported as well. Note that the packet size allows for 'G' + all the
1039
      // registers sent to us, or a reply to 'g' with all the registers and an
1040
      // EOS so the buffer is a well formed string.
1041
      sprintf (pkt->data, "PacketSize=%x", pkt->getBufSize());
1042
      pkt->setLen (strlen (pkt->data));
1043
      rsp->putPkt (pkt);
1044
    }
1045
  else if (0 == strncmp ("qSymbol:", pkt->data, strlen ("qSymbol:")))
1046
    {
1047
      // Offer to look up symbols. Nothing we want (for now). TODO. This just
1048
      // ignores any replies to symbols we looked up, but we didn't want to
1049
      // do that anyway!
1050
      pkt->packStr ("OK");
1051
      rsp->putPkt (pkt);
1052
    }
1053
  else if (0 == strncmp ("qThreadExtraInfo,", pkt->data,
1054
                         strlen ("qThreadExtraInfo,")))
1055
    {
1056
      // Report that we are runnable, but the text must be hex ASCI
1057
      // digits. For now do this by steam, reusing the original packet
1058
      sprintf (pkt->data, "%02x%02x%02x%02x%02x%02x%02x%02x%02x",
1059
               'R', 'u', 'n', 'n', 'a', 'b', 'l', 'e', 0);
1060
      pkt->setLen (strlen (pkt->data));
1061
      rsp->putPkt (pkt);
1062
    }
1063 425 julius
  else if (0 == strncmp ("qTStatus", pkt->data, strlen ("qTstatus")))
1064
    {
1065
      // We don't support tracing, return empty packet
1066
      pkt->packStr ("");
1067
      rsp->putPkt (pkt);
1068
    }
1069 63 julius
  else if (0 == strncmp ("qXfer:", pkt->data, strlen ("qXfer:")))
1070
    {
1071
      // For now we support no 'qXfer' requests, but these should not be
1072
      // expected, since they were not reported by 'qSupported'
1073
      cerr << "Warning: RSP 'qXfer' not supported: ignored" << endl;
1074
      pkt->packStr ("");
1075
      rsp->putPkt (pkt);
1076
    }
1077
  else
1078
    {
1079
      cerr << "Unrecognized RSP query: ignored" << endl;
1080
    }
1081
}       // rspQuery ()
1082
 
1083
 
1084
//-----------------------------------------------------------------------------
1085
//! Handle a RSP qRcmd request
1086
 
1087
//! The actual command follows the "qRcmd," in ASCII encoded to hex
1088
//-----------------------------------------------------------------------------
1089
void
1090
GdbServerSC::rspCommand ()
1091
{
1092
  char  cmd[RSP_PKT_MAX];
1093
 
1094
  Utils::hex2Ascii (cmd, &(pkt->data[strlen ("qRcmd,")]));
1095
 
1096
  // Work out which command it is
1097
  if (0 == strncmp ("readspr ", cmd, strlen ("readspr")))
1098
    {
1099
      unsigned int       sprNum;
1100
 
1101
      // Parse and return error if we fail
1102
      if( 1 != sscanf (cmd, "readspr %4x", &sprNum))
1103
        {
1104
          cerr << "Warning: qRcmd " << cmd
1105
                    << "not recognized: ignored" << endl;
1106
          pkt->packStr ("E01");
1107
          rsp->putPkt (pkt);
1108
          return;
1109
        }
1110
 
1111
      // SPR out of range
1112
      if (sprNum > MAX_SPRS)
1113
        {
1114
          cerr <<  "Warning: qRcmd readspr " << hex << sprNum
1115
                    << dec << " too large: ignored" << endl;
1116
          pkt->packStr ("E01");
1117
          rsp->putPkt (pkt);
1118
          return;
1119
        }
1120
 
1121
      // Construct the reply
1122
      sprintf (cmd, "%8lx", debugUnit->readSpr (sprNum));
1123
      Utils::ascii2Hex (pkt->data, cmd);
1124
      pkt->setLen (strlen (pkt->data));
1125
      rsp->putPkt (pkt);
1126
    }
1127
  else if (0 == strncmp ("writespr ", cmd, strlen ("writespr")))
1128
    {
1129
      unsigned int  sprNum;
1130
      uint32_t      val;
1131
 
1132
      // Parse and return error if we fail
1133
      if( 2 != sscanf (cmd, "writespr %4x %8lx", &sprNum, &val))
1134
        {
1135
          cerr << "Warning: qRcmd " << cmd << " not recognized: ignored"
1136
                    << endl;
1137
          pkt->packStr ("E01");
1138
          rsp->putPkt (pkt);
1139
          return;
1140
        }
1141
 
1142
      // SPR out of range
1143
      if (sprNum > MAX_SPRS)
1144
        {
1145
          cerr <<  "Warning: qRcmd writespr " << hex << sprNum
1146
                    << dec << " too large: ignored" << endl;
1147
          pkt->packStr ("E01");
1148
          rsp->putPkt (pkt);
1149
          return;
1150
        }
1151
 
1152
      // Update the SPR and reply "OK"
1153
      debugUnit->writeSpr (sprNum, val);
1154
      pkt->packStr ("OK");
1155
      rsp->putPkt (pkt);
1156
    }
1157
 
1158
}       // rspCommand ()
1159
 
1160
 
1161
//-----------------------------------------------------------------------------
1162
//! Handle a RSP set request
1163
//-----------------------------------------------------------------------------
1164
void
1165
GdbServerSC::rspSet ()
1166
{
1167
  if (0 == strncmp ("QPassSignals:", pkt->data, strlen ("QPassSignals:")))
1168
    {
1169
      // Passing signals not supported
1170
      pkt->packStr ("");
1171
      rsp->putPkt (pkt);
1172
    }
1173
  else if ((0 == strncmp ("QTDP",    pkt->data, strlen ("QTDP")))   ||
1174
           (0 == strncmp ("QFrame",  pkt->data, strlen ("QFrame"))) ||
1175
           (0 == strcmp  ("QTStart", pkt->data))                    ||
1176
           (0 == strcmp  ("QTStop",  pkt->data))                    ||
1177
           (0 == strcmp  ("QTinit",  pkt->data))                    ||
1178
           (0 == strncmp ("QTro",    pkt->data, strlen ("QTro"))))
1179
    {
1180
      // All tracepoint features are not supported. This reply is really only
1181
      // needed to 'QTDP', since with that the others should not be
1182
      // generated.
1183
      pkt->packStr ("");
1184
      rsp->putPkt (pkt);
1185
    }
1186
  else
1187
    {
1188
      cerr << "Unrecognized RSP set request: ignored" << endl;
1189
      delete  pkt;
1190
    }
1191
}       // rspSet ()
1192
 
1193
 
1194
//-----------------------------------------------------------------------------
1195
//! Handle a RSP restart request
1196
 
1197
//! For now we just put the program counter back to the reset vector. If we
1198
//! supported the vRun request, we should use the address specified
1199
//! there. There is no point in unstalling the processor, since we'll never
1200
//! get control back.
1201
//-----------------------------------------------------------------------------
1202
void
1203
GdbServerSC::rspRestart ()
1204
{
1205
  writeNpc (EXCEPT_RESET);
1206
 
1207
}       // rspRestart ()
1208
 
1209
 
1210
//-----------------------------------------------------------------------------
1211
//! Handle a RSP step request
1212
 
1213
//! This version is typically used for the 's' packet, to continue without
1214
//! signal, in which case EXCEPT_NONE is passed in as the exception to use.
1215
 
1216
//! @param[in] except  The exception to use. Only EXCEPT_NONE should be set
1217
//!                    this way.
1218
//-----------------------------------------------------------------------------
1219
void
1220
GdbServerSC::rspStep (uint32_t   except)
1221
{
1222
  uint32_t  addr;               // The address to step from, if any
1223
 
1224
  // Reject all except 's' packets
1225
  if ('s' != pkt->data[0])
1226
    {
1227
      cerr << "Warning: Step with signal not currently supported: "
1228
           << "ignored" << endl;
1229
      return;
1230
    }
1231
 
1232
  if (0 == strcmp ("s", pkt->data))
1233
    {
1234
      addr = readNpc ();                // Default uses current NPC
1235
    }
1236
  else if (1 != sscanf (pkt->data, "s%lx", &addr))
1237
    {
1238
      cerr << "Warning: RSP step address " << pkt->data
1239
           << " not recognized: ignored" << endl;
1240
      addr = readNpc ();                // Default uses current NPC
1241
    }
1242
 
1243
  rspStep (addr, EXCEPT_NONE);
1244
 
1245
}       // rspStep ()
1246
 
1247
 
1248
//-----------------------------------------------------------------------------
1249
//! Handle a RSP step with signal request
1250
 
1251
//! @todo Currently null. Will use the underlying generic step function.
1252
//-----------------------------------------------------------------------------
1253
void
1254
GdbServerSC::rspStep ()
1255
{
1256
  cerr << "RSP step with signal '" << pkt->data << "' received" << endl;
1257
 
1258
}       // rspStep ()
1259
 
1260
 
1261
//-----------------------------------------------------------------------------
1262
//! Generic processing of a step request
1263
 
1264
//! The signal may be EXCEPT_NONE if there is no exception to be
1265
//! handled. Currently the exception is ignored.
1266
 
1267
//! The single step flag is set in the debug registers and then the processor
1268
//! is unstalled.
1269
 
1270
//! @todo There appears to be a bug in the ORPSoC debug unit, whereby multiple
1271
//!       single steps make a mess of the pipeline, leading to multiple
1272
//!       executions of the same instruction. A fix would be to use l.trap (as
1273
//!       for continue) for any consecutive calls to step.
1274
 
1275
//! @param[in] addr    Address from which to step
1276
//! @param[in] except  The exception to use (if any)                         
1277
//-----------------------------------------------------------------------------
1278
void
1279
GdbServerSC::rspStep (uint32_t  addr,
1280
                      uint32_t  except)
1281
{
1282
  // Set the address as the value of the next program counter
1283
  writeNpc (addr);
1284
 
1285
  /*
1286
  // If we're continuing from a breakpoint, replace that instruction in the memory
1287
  // ... actually no, I was wrong about this.
1288
  if (NULL != mpHash->lookup (BP_MEMORY, addr) && rsp_sigval == TARGET_SIGNAL_TRAP)
1289
    {
1290
      MpEntry *entry = mpHash->lookup (BP_MEMORY, addr);
1291
      debugUnit->writeMem32(entry->addr, entry->instr);
1292
    }
1293
  */
1294
 
1295
  // Clear Debug Reason Register and watchpoint break generation in Debug Mode
1296
  // Register 2 for watchpoints that we triggered to stop this time.
1297
  debugUnit->writeSpr (SPR_DRR,  0);
1298
  if (rsp_sigval == TARGET_SIGNAL_TRAP)
1299
    {
1300
      /*
1301
         Disable last trap generation on watchpoint if this is why we stopped
1302
         last time.
1303
      */
1304
      uint32_t temp_dmr2 = debugUnit->readSpr (SPR_DMR2);
1305
      if (temp_dmr2 & SPR_DMR2_WBS)
1306
        {
1307
          /*
1308
             One of these breakpoints is responsible for our stopping, so
1309
             disable it this time we start. GDB will send a packet re-enabling
1310
             it next time we continue.
1311
          */
1312
          debugUnit->writeSpr (SPR_DMR2, temp_dmr2 & ~((temp_dmr2&SPR_DMR2_WBS)>>10));
1313
        }
1314
    }
1315
 
1316
  // Set the single step trigger in Debug Mode Register 1 and set traps to be
1317
  // handled by the debug unit in the Debug Stop Register
1318
  debugUnit->orSpr (SPR_DMR1, SPR_DMR1_ST);
1319
  debugUnit->orSpr (SPR_DSR,  SPR_DSR_TE);
1320
 
1321
  // Unstall the processor. Note the GDB client is now waiting for a reply,
1322
  // which it will get as soon as the processor stalls again.
1323
  debugUnit->unstall ();
1324
  targetStopped = false;
1325
 
1326
}       // rspStep ()
1327
 
1328
 
1329
//-----------------------------------------------------------------------------
1330
//! Handle a RSP 'v' packet
1331
 
1332
//! These are commands associated with executing the code on the target
1333
//-----------------------------------------------------------------------------
1334
void
1335
GdbServerSC::rspVpkt ()
1336
{
1337
  if (0 == strncmp ("vAttach;", pkt->data, strlen ("vAttach;")))
1338
    {
1339
      // Attaching is a null action, since we have no other process. We just
1340
      // return a stop packet (using TRAP) to indicate we are stopped.
1341
      pkt->packStr ("S05");
1342
      rsp->putPkt (pkt);
1343
      return;
1344
    }
1345
  else if (0 == strcmp ("vCont?", pkt->data))
1346
    {
1347
      // For now we don't support this.
1348
      pkt->packStr ("");
1349
      rsp->putPkt (pkt);
1350
      return;
1351
    }
1352
  else if (0 == strncmp ("vCont", pkt->data, strlen ("vCont")))
1353
    {
1354
      // This shouldn't happen, because we've reported non-support via vCont?
1355
      // above
1356
      cerr << "Warning: RSP vCont not supported: ignored" << endl;
1357
      return;
1358
    }
1359
  else if (0 == strncmp ("vFile:", pkt->data, strlen ("vFile:")))
1360
    {
1361
      // For now we don't support this.
1362
      cerr << "Warning: RSP vFile not supported: ignored" << endl;
1363
      pkt->packStr ("");
1364
      rsp->putPkt (pkt);
1365
      return;
1366
    }
1367
  else if (0 == strncmp ("vFlashErase:", pkt->data, strlen ("vFlashErase:")))
1368
    {
1369
      // For now we don't support this.
1370
      cerr << "Warning: RSP vFlashErase not supported: ignored" << endl;
1371
      pkt->packStr ("E01");
1372
      rsp->putPkt (pkt);
1373
      return;
1374
    }
1375
  else if (0 == strncmp ("vFlashWrite:", pkt->data, strlen ("vFlashWrite:")))
1376
    {
1377
      // For now we don't support this.
1378
      cerr << "Warning: RSP vFlashWrite not supported: ignored" << endl;
1379
      pkt->packStr ("E01");
1380
      rsp->putPkt (pkt);
1381
      return;
1382
    }
1383
  else if (0 == strcmp ("vFlashDone", pkt->data))
1384
    {
1385
      // For now we don't support this.
1386
      cerr << "Warning: RSP vFlashDone not supported: ignored" << endl;;
1387
      pkt->packStr ("E01");
1388
      rsp->putPkt (pkt);
1389
      return;
1390
    }
1391
  else if (0 == strncmp ("vRun;", pkt->data, strlen ("vRun;")))
1392
    {
1393
      // We shouldn't be given any args, but check for this
1394
      if (pkt->getLen () > strlen ("vRun;"))
1395
        {
1396
          cerr << "Warning: Unexpected arguments to RSP vRun "
1397
            "command: ignored" << endl;
1398
        }
1399
 
1400
      // Restart the current program. However unlike a "R" packet, "vRun"
1401
      // should behave as though it has just stopped. We use signal 5 (TRAP).
1402
      rspRestart ();
1403
      pkt->packStr ("S05");
1404
      rsp->putPkt (pkt);
1405
    }
1406
  else
1407
    {
1408
      cerr << "Warning: Unknown RSP 'v' packet type " << pkt->data
1409
           << ": ignored" << endl;
1410
      pkt->packStr ("E01");
1411
      rsp->putPkt (pkt);
1412
      return;
1413
    }
1414
}       // rspVpkt ()
1415
 
1416
 
1417
//-----------------------------------------------------------------------------
1418
//! Handle a RSP write memory (binary) request
1419
 
1420
//! Syntax is:
1421
 
1422
//!   X<addr>,<length>:
1423
 
1424
//! Followed by the specified number of bytes as raw binary. Response should be
1425
//! "OK" if all copied OK, E<nn> if error <nn> has occurred.
1426
 
1427
//! The length given is the number of bytes to be written. The data buffer has
1428
//! already been unescaped, so will hold this number of bytes.
1429
 
1430
//! The data is in model-endian format, so no transformation is needed.
1431
//-----------------------------------------------------------------------------
1432
void
1433
GdbServerSC::rspWriteMemBin ()
1434
{
1435
  uint32_t  addr;                       // Where to write the memory
1436
  int       len;                        // Number of bytes to write
1437
 
1438
  if (2 != sscanf (pkt->data, "X%x,%x:", &addr, &len))
1439
    {
1440
      cerr << "Warning: Failed to recognize RSP write memory command: %s"
1441
           << pkt->data << endl;
1442
      pkt->packStr ("E01");
1443
      rsp->putPkt (pkt);
1444
      return;
1445
    }
1446
 
1447
  // Find the start of the data and "unescape" it. Bindat must be unsigned, or
1448
  // all sorts of horrible sign extensions will happen when val is computed
1449
  // below!
1450
  uint8_t *bindat = (uint8_t *)(memchr (pkt->data, ':',
1451
                                        pkt->getBufSize ())) + 1;
1452
  int   off       = (char *)bindat - pkt->data;
1453
  int   newLen    = Utils::rspUnescape ((char *)bindat, pkt->getLen () - off);
1454
 
1455
  // Sanity check
1456
  if (newLen != len)
1457
    {
1458
      int  minLen = len < newLen ? len : newLen;
1459
 
1460
      cerr << "Warning: Write of " << len << " bytes requested, but "
1461
           << newLen << " bytes supplied. " << minLen << " will be written"
1462
           << endl;
1463
      len = minLen;
1464
    }
1465
 
1466
  // Write the bytes to memory. More efficent to do this in 32-bit chunks
1467
  int  startBytes = addr & 0x3;
1468
  int  endBytes   = (addr + len) & 0x3;
1469
 
1470
  // First partial word. Access bindat in an endian independent fashion.
1471
  for (off = 0 ; off < startBytes ; off++)
1472
    {
1473
      if (!debugUnit->writeMem8 (addr + off, bindat[off]))
1474
        {
1475
          pkt->packStr ("E01");
1476
          rsp->putPkt (pkt);
1477
          return;
1478
        }
1479
    }
1480
 
1481
  // The bulk as words. Convert to model endian before writing.
1482
  for (off = startBytes; off < len; off += 4)
1483
    {
1484
      uint32_t val = *((uint32_t *)(&(bindat[off])));
1485
 
1486
      if (!debugUnit->writeMem32 (addr + off, Utils::htotl (val)))
1487
        {
1488
          pkt->packStr ("E01");
1489
          rsp->putPkt (pkt);
1490
          return;
1491
        }
1492
    }
1493
 
1494
  // Last partial word. Access bindat in an endian independent fashion.
1495
  for (off = len - endBytes; off < len ; off++)
1496
    {
1497
      uint32_t  base = (addr + len) & 0xfffffffc;
1498
 
1499
      if (!debugUnit->writeMem8 (base + off, bindat[off]))
1500
        {
1501
          pkt->packStr ("E01");
1502
          rsp->putPkt (pkt);
1503
          return;
1504
        }
1505
    }
1506
 
1507
  pkt->packStr ("OK");
1508
  rsp->putPkt (pkt);
1509
 
1510
}       // rspWriteMemBin ()
1511
 
1512
 
1513
//-----------------------------------------------------------------------------
1514
//! Handle a RSP remove breakpoint or matchpoint request
1515
 
1516
//! For now only memory breakpoints are implemented, which are implemented by
1517
//! substituting a breakpoint at the specified address. The implementation must
1518
//! cope with the possibility of duplicate packets.
1519
 
1520
//! @todo This doesn't work with icache/immu yet
1521
//-----------------------------------------------------------------------------
1522
void
1523
GdbServerSC::rspRemoveMatchpoint ()
1524
{
1525
  MpType     type;                      // What sort of matchpoint
1526
  uint32_t   addr;                      // Address specified
1527
  uint32_t   instr;                     // Instruction value found
1528
  int        len;                       // Matchpoint length (not used)
1529
 
1530
  // Break out the instruction
1531
  if (3 != sscanf (pkt->data, "z%1d,%lx,%1d", (int *)&type, &addr, &len))
1532
    {
1533
      cerr << "Warning: RSP matchpoint deletion request not "
1534
           << "recognized: ignored" << endl;
1535
      pkt->packStr ("E01");
1536
      rsp->putPkt (pkt);
1537
      return;
1538
    }
1539
 
1540
  // Sanity check that the length is 4
1541
  if (4 != len)
1542
    {
1543
      cerr << "Warning: RSP matchpoint deletion length " << len
1544
           << "not valid: 4 assumed" << endl;
1545
      len = 4;
1546
    }
1547
 
1548
  // Sort out the type of matchpoint
1549
  switch (type)
1550
    {
1551
    case BP_MEMORY:
1552
      // Memory breakpoint - replace the original instruction.
1553
      if (mpHash->remove (type, addr, &instr))
1554
        {
1555
          //cerr << "rspRemoveMatchpoint at 0x" << hex << addr << " restoring instruction: 0x" << hex << instr <<endl;
1556
          debugUnit->writeMem32 (addr, instr);
1557
        }
1558
 
1559
      pkt->packStr ("OK");
1560
      rsp->putPkt (pkt);
1561
      return;
1562
 
1563
    case BP_HARDWARE:
1564
      int off;
1565
      for (off=0;off<8;off++)
1566
        if ((debugUnit->readSpr (SPR_DCR0+off) == (0x23)) &&
1567
            (debugUnit->readSpr (SPR_DVR0+off) == addr))
1568
          break;
1569
      if (off > 7)
1570
        {
1571
          pkt->packStr ("E02"); // Failed ot find breakpoint
1572
          rsp->putPkt (pkt);
1573
          return;
1574
        }
1575
      // Clear DCR's CT and DVR, WGB bit
1576
      debugUnit->writeSpr (SPR_DCR0+off,0);
1577
      debugUnit->writeSpr (SPR_DVR0+off,0);
1578
      debugUnit->writeSpr (SPR_DMR2,debugUnit->readSpr (SPR_DMR2) & ~((1<<off)<<SPR_DMR2_WGB_SHIFT));
1579
      pkt->packStr ("OK");
1580
      rsp->putPkt (pkt);
1581
      return;
1582
 
1583
    case WP_WRITE:
1584
      {
1585
        int off;
1586
        for (off=0;off<8;off++)
1587
          {
1588
            if ((debugUnit->readSpr (SPR_DCR0+off) == (0x63)) &&
1589
                (debugUnit->readSpr (SPR_DVR0+off) == addr))
1590
              break;
1591
          }
1592
        if (off > 7)
1593
          {
1594
            pkt->packStr ("E02"); // Failed ot find breakpoint
1595
            rsp->putPkt (pkt);
1596
          return;
1597
          }
1598
 
1599
        // Clear DCR's CT and DVR, WGB bit
1600
        debugUnit->writeSpr (SPR_DCR0+off,0);
1601
        debugUnit->writeSpr (SPR_DVR0+off,0);
1602
        debugUnit->writeSpr (SPR_DMR2,debugUnit->readSpr (SPR_DMR2) & ~((1<<off)<<SPR_DMR2_WGB_SHIFT));
1603
        pkt->packStr ("OK");
1604
        rsp->putPkt (pkt);
1605
        return;
1606
      }
1607
 
1608
    case WP_READ:
1609
      {
1610
        int off;
1611
        for (off=0;off<8;off++)
1612
          {
1613
            if ((debugUnit->readSpr (SPR_DCR0+off) == (0x43)) &&
1614
                (debugUnit->readSpr (SPR_DVR0+off) == addr))
1615
              break;
1616
          }
1617
        if (off > 7)
1618
          {
1619
            pkt->packStr ("E02"); // Failed ot find breakpoint
1620
            rsp->putPkt (pkt);
1621
          return;
1622
          }
1623
 
1624
        // Clear DCR's CT and DVR, WGB bit
1625
        debugUnit->writeSpr (SPR_DCR0+off,0);
1626
        debugUnit->writeSpr (SPR_DVR0+off,0);
1627
        debugUnit->writeSpr (SPR_DMR2,debugUnit->readSpr (SPR_DMR2) & ~((1<<off)<<SPR_DMR2_WGB_SHIFT));
1628
        pkt->packStr ("OK");
1629
        rsp->putPkt (pkt);
1630
        return;
1631
      }
1632
 
1633
    case WP_ACCESS:
1634
      {
1635
        int off;
1636
        for (off=0;off<8;off++)
1637
          {
1638
            //printf("WP_ACCESS remove check off=%d DCR=0x%.8x DVR=0x%.8x\n",
1639
            //off,debugUnit->readSpr (SPR_DCR0+off),debugUnit->readSpr (SPR_DVR0+off));
1640
            if ((debugUnit->readSpr (SPR_DCR0+off) == (0xc3)) &&
1641
                (debugUnit->readSpr (SPR_DVR0+off) == addr))
1642
              break;
1643
          }
1644
        if (off > 7)
1645
          {
1646
            //printf("rspRemoveWatchpoint: WP_ACCESS remove ERROR, regpair %d for 0x%.8x\n",off, addr);
1647
            pkt->packStr ("E02"); // Failed ot find breakpoint
1648
            rsp->putPkt (pkt);
1649
          return;
1650
          }
1651
        //printf("rspRemoveWatchpoint: WP_ACCESS remove, regpair %d for 0x%.8x\n",off, addr);
1652
 
1653
        // Clear DCR's CT and DVR, WGB bit
1654
        debugUnit->writeSpr (SPR_DCR0+off,0);
1655
        debugUnit->writeSpr (SPR_DVR0+off,0);
1656
        debugUnit->writeSpr (SPR_DMR2,debugUnit->readSpr (SPR_DMR2) & ~((1<<off)<<SPR_DMR2_WGB_SHIFT));
1657
        pkt->packStr ("OK");
1658
        rsp->putPkt (pkt);
1659
        return;
1660
      }
1661
    default:
1662
      cerr << "Warning: RSP matchpoint type " << type
1663
           << " not recognized: ignored" << endl;
1664
      pkt->packStr ("E01");
1665
      rsp->putPkt (pkt);
1666
      return;
1667
    }
1668
}       // rspRemoveMatchpoint ()
1669
 
1670
 
1671
//---------------------------------------------------------------------------*/
1672
//! Handle a RSP insert breakpoint or matchpoint request
1673
 
1674
//! For now only memory breakpoints are implemented, which are implemented by
1675
//! substituting a breakpoint at the specified address. The implementation must
1676
//! cope with the possibility of duplicate packets.
1677
 
1678
//! @todo This doesn't work with icache/immu yet
1679
//---------------------------------------------------------------------------*/
1680
void
1681
GdbServerSC::rspInsertMatchpoint ()
1682
{
1683
  MpType    type;                       // What sort of matchpoint
1684
  uint32_t  addr;                       // Address specified
1685
  int       len;                        // Matchpoint length (not used)
1686
 
1687
  // Break out the instruction
1688
  if (3 != sscanf (pkt->data, "Z%1d,%lx,%1d", (int *)&type, &addr, &len))
1689
    {
1690
      cerr << "Warning: RSP matchpoint insertion request not "
1691
           << "recognized: ignored" << endl;
1692
      pkt->packStr ("E01");
1693
      rsp->putPkt (pkt);
1694
      return;
1695
    }
1696
 
1697
  // Sanity check that the length is 4
1698
  if (4 != len)
1699
    {
1700
      cerr << "Warning: RSP matchpoint insertion length " << len
1701
           << "not valid: 4 assumed" << endl;
1702
      len = 4;
1703
    }
1704
 
1705
  // Sort out the type of matchpoint
1706
  switch (type)
1707
    {
1708
    case BP_MEMORY:
1709
      // Memory breakpoint - substitute a TRAP instruction
1710
      mpHash->add (type, addr, debugUnit->readMem32 (addr));
1711
      debugUnit->writeMem32 (addr, OR1K_TRAP_INSTR);
1712
      pkt->packStr ("OK");
1713
      rsp->putPkt (pkt);
1714
      return;
1715
 
1716
    case BP_HARDWARE:
1717
      {
1718
        int off;
1719
        for (off=0;off<8;off++)
1720
          if (!(debugUnit->readSpr (SPR_DCR0+off) & SPR_DCR_CT_MASK))
1721
            break;
1722
        if (off > 7)
1723
          {
1724
            pkt->packStr ("");          // No room
1725
            rsp->putPkt (pkt);
1726
            return;
1727
          }
1728
        // CC = equal, CT = Instruction fetch EA, set WGB bit
1729
        debugUnit->writeSpr (SPR_DCR0+off,0x22);
1730
        debugUnit->writeSpr (SPR_DVR0+off,addr);
1731
        debugUnit->writeSpr (SPR_DMR2,debugUnit->readSpr (SPR_DMR2)|((1<<off)<<SPR_DMR2_WGB_SHIFT));
1732
        pkt->packStr ("OK");
1733
        rsp->putPkt (pkt);
1734
        return;
1735
      }
1736
 
1737
    case WP_WRITE:
1738
      {
1739
        int off;
1740
        for (off=0;off<8;off++)
1741
          if (!(debugUnit->readSpr (SPR_DCR0+off) & SPR_DCR_CT_MASK))
1742
            break;
1743
        //printf("rspInsertWatchpoint: WP_WRITE, regpair %d for 0x%.8x\n",off, addr);
1744
        if (off > 7)
1745
          {
1746
            pkt->packStr ("");          // No room
1747
            rsp->putPkt (pkt);
1748
            return;
1749
          }
1750
        // CC = equal, CT = Store EA, set WGB bit
1751
        debugUnit->writeSpr (SPR_DCR0+off,0x62);
1752
        debugUnit->writeSpr (SPR_DVR0+off,addr);
1753
        debugUnit->writeSpr (SPR_DMR2,debugUnit->readSpr (SPR_DMR2)|((1<<off)<<SPR_DMR2_WGB_SHIFT));
1754
        pkt->packStr ("OK");
1755
        rsp->putPkt (pkt);
1756
        return;
1757
      }
1758
 
1759
    case WP_READ:
1760
      {
1761
        int off;
1762
        for (off=0;off<8;off++)
1763
          if (!(debugUnit->readSpr (SPR_DCR0+off) & SPR_DCR_CT_MASK))
1764
            break;
1765
        //printf("rspInsertWatchpoint: WP_WRITE, regpair %d for 0x%.8x\n",off, addr);
1766
        if (off > 7)
1767
          {
1768
            pkt->packStr ("");          // No room
1769
            rsp->putPkt (pkt);
1770
            return;
1771
          }
1772
        // CC = equal, CT = Load EA, set WGB bit
1773
        debugUnit->writeSpr (SPR_DCR0+off,0x42);
1774
        debugUnit->writeSpr (SPR_DVR0+off,addr);
1775
        debugUnit->writeSpr (SPR_DMR2,debugUnit->readSpr (SPR_DMR2)|((1<<off)<<SPR_DMR2_WGB_SHIFT));
1776
        pkt->packStr ("OK");
1777
        rsp->putPkt (pkt);
1778
        return;
1779
      }
1780
 
1781
      pkt->packStr ("");                // Not supported
1782
      rsp->putPkt (pkt);
1783
      return;
1784
 
1785
    case WP_ACCESS:
1786
      {
1787
        int off;
1788
        for (off=0;off<8;off++)
1789
          if (!(debugUnit->readSpr (SPR_DCR0+off) & SPR_DCR_CT_MASK))
1790
            break;
1791
        //printf("rspInsertWatchpoint: WP_ACCESS, regpair %d for 0x%.8x\n",off, addr);
1792
        if (off > 7)
1793
          {
1794
            pkt->packStr ("");          // No room
1795
            rsp->putPkt (pkt);
1796
            return;
1797
          }
1798
        // CC = equal, CT = Load/Store EA, set WGB bit
1799
        debugUnit->writeSpr (SPR_DCR0+off,0xc2);
1800
        debugUnit->writeSpr (SPR_DVR0+off,addr);
1801
        debugUnit->writeSpr (SPR_DMR2,debugUnit->readSpr (SPR_DMR2)|((1<<off)<<SPR_DMR2_WGB_SHIFT));
1802
        pkt->packStr ("OK");
1803
        rsp->putPkt (pkt);
1804
        return;
1805
      }
1806
 
1807
    default:
1808
      cerr << "Warning: RSP matchpoint type " << type
1809
           << "not recognized: ignored"<< endl;
1810
      pkt->packStr ("E01");
1811
      rsp->putPkt (pkt);
1812
      return;
1813
    }
1814
}       // rspInsertMatchpoint ()
1815
 
1816
 
1817
//-----------------------------------------------------------------------------
1818
//! Read the value of the Next Program Counter (a SPR)
1819
 
1820
//! A convenience routine.
1821
 
1822
//! Setting the NPC flushes the pipeline, so subsequent reads will return
1823
//! zero until the processor has refilled the pipeline. This will not be
1824
//! happening if the processor is stalled (as it is when GDB had control).
1825
 
1826
//! However for debugging we always want to know what the effective value of
1827
//! the NPC will be (i.e. the value that will be used once the pipeline has
1828
//! refilled). Fortunately SPR cacheing in the debug unit silently solves this
1829
//! for us.
1830
 
1831
//! @return  The value of the NPC
1832
//-----------------------------------------------------------------------------
1833
uint32_t
1834
GdbServerSC::readNpc ()
1835
{
1836
  return debugUnit->readSpr (SPR_NPC);
1837
 
1838
}       // readNpc ()
1839
 
1840
 
1841
//-----------------------------------------------------------------------------
1842
//! Write the value of the Next Program Counter (a SPR)
1843
 
1844
//! A convenience function.
1845
 
1846
//! Setting the NPC flushes the pipeline, so subsequent reads will return
1847
//! zero until the processor has refilled the pipeline. This will not be
1848
//! happening if the processor is stalled (as it is when GDB had control).
1849
 
1850
//! However for debugging we always want to know what the effective value of
1851
//! the NPC will be (i.e. the value that will be used once the pipeline has
1852
//! refilled). Fortunately SPR cacheing in the debug unit silently solves this
1853
//! for us.
1854
 
1855
//! There is one other caveat for the NPC. We do not wish to write it (whether
1856
//! or not it is cached) if it has not changed. So unlike all other SPRs we
1857
//! always read it first before writing.
1858
 
1859
//! @param[in]  The address to write into the NPC
1860
//-----------------------------------------------------------------------------
1861
void
1862
GdbServerSC::writeNpc (uint32_t  addr)
1863
{
1864
  if (addr != readNpc())
1865
    {
1866
      debugUnit->writeSpr (SPR_NPC,  addr);
1867
    }
1868
}       // writeNpc ()
1869
 
1870
 
1871
//-----------------------------------------------------------------------------
1872
//! Read the value of an OpenRISC 1000 General Purpose Register
1873
 
1874
//! A convenience function. This is just a wrapper for reading a SPR, since
1875
//! the GPR's are mapped into SPR space
1876
 
1877
//! @param[in]  regNum  The GPR to read
1878
 
1879
//! @return  The value of the GPR
1880
//-----------------------------------------------------------------------------
1881
uint32_t
1882
GdbServerSC::readGpr (int  regNum)
1883
{
1884
  return  debugUnit->readSpr (SPR_GPR0 + regNum);
1885
 
1886
}       // readGpr ()
1887
 
1888
 
1889
//-----------------------------------------------------------------------------
1890
//! Write the value of an OpenRISC 1000 General Purpose Register
1891
 
1892
//! A convenience function. This is just a wrapper for writing a SPR, since
1893
//! the GPR's are mapped into SPR space
1894
 
1895
//! @param[in]  regNum  The GPR to read
1896
 
1897
//! @return  The value of the GPR
1898
//-----------------------------------------------------------------------------
1899
void
1900
GdbServerSC::writeGpr (int       regNum,
1901
                       uint32_t  value)
1902
{
1903
  debugUnit->writeSpr (SPR_GPR0 + regNum, value);
1904
 
1905
}       // writeGpr ()
1906
 
1907
//-----------------------------------------------------------------------------
1908
//! Check if we received anything via the pipe from the or1200 monitor
1909
 
1910
//! We stall the processor, and behave in a manner similar to if an interrupt
1911
//! had been received. Perhaps the sigval should be set differently/more
1912
//! more appropriately.
1913
//! Read from the pipe should be NON-blocking.
1914
 
1915
//! @return  false if nothing received, else true
1916
//-----------------------------------------------------------------------------
1917
bool
1918
GdbServerSC::checkMonitorPipe ()
1919
{
1920
  char readChar;
1921
  int n = read(monitor_to_gdb_pipe[0][0], &readChar, sizeof(char));
1922
  if (!( ((n < 0) && (errno == EAGAIN)) || (n==0) ) && !targetStopped)
1923
    {
1924
      debugUnit->stall ();
1925
      // Send a stop reply response, manually set rsp.sigval to TARGET_SIGNAL_NONE
1926
      rsp_sigval = TARGET_SIGNAL_NONE;
1927
      rspReportException();
1928
      targetStopped = true;             // Processor now not running
1929
      write(monitor_to_gdb_pipe[1][1],&readChar,sizeof(char));
1930
      return true;
1931
    }
1932
 
1933
  return false;
1934
 
1935
}       // checkMonitorPipe ()

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.