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

Subversion Repositories openrisc_me

[/] [openrisc/] [trunk/] [gnu-src/] [gdb-7.1/] [sim/] [or32/] [wrapper.c] - Blame information for rev 311

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

Line No. Rev Author Line
1 227 jeremybenn
/* GDB Simulator wrapper for Or1ksim, the OpenRISC architectural simulator
2
 
3
   Copyright 1988-2008, Free Software Foundation, Inc.
4
   Copyright (C) 2010 Embecosm Limited
5
 
6
   Contributor Jeremy Bennett <jeremy.bennett@embecosm.com>
7
 
8
   This file is part of GDB.
9
 
10
   This program is free software; you can redistribute it and/or modify it
11
   under the terms of the GNU General Public License as published by the Free
12
   Software Foundation; either version 3 of the License, or (at your option)
13
   any later version.
14
 
15
   This program is distributed in the hope that it will be useful, but WITHOUT
16
   ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
17
   FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
18
   more details.
19
 
20
   You should have received a copy of the GNU General Public License along
21
   with this program.  If not, see <http://www.gnu.org/licenses/>.  */
22
 
23
/*---------------------------------------------------------------------------*/
24
/* This is a wrapper for Or1ksim, suitable for use as a GDB simulator.
25
 
26
   The code tries to follow the GDB coding style.
27
 
28
   Commenting is Doxygen compatible.                                         */
29
/*---------------------------------------------------------------------------*/
30
 
31
#include <errno.h>
32
#include <stdlib.h>
33
#include <stdio.h>
34
#include <signal.h>
35
#include <string.h>
36
#include <sys/socket.h>
37
#include <sys/types.h>
38
#include <sys/un.h>
39
#include <unistd.h>
40
 
41
#include "ansidecl.h"
42
#include "gdb/callback.h"
43
#include "gdb/remote-sim.h"
44
#include "sim-utils.h"
45
#include "targ-vals.h"
46
 
47
#include "or1ksim.h"
48
#include "or32sim.h"
49
 
50 244 jeremybenn
/* Define this to turn on debug messages */
51
/* #define OR32_SIM_DEBUG */
52 227 jeremybenn
 
53 244 jeremybenn
 
54 227 jeremybenn
/* ------------------------------------------------------------------------- */
55
/*!Create a fully initialized simulator instance.
56
 
57
   This function is called when the simulator is selected from the gdb command
58
   line.
59
 
60
   While the simulator configuration can be parameterized by (in decreasing
61
   precedence) argv's SIM-OPTION, argv's TARGET-PROGRAM and the abfd argument,
62
   the successful creation of the simulator shall not dependent on the
63
   presence of any of these arguments/options.
64
 
65
   For a hardware simulator the created simulator shall be sufficiently
66
   initialized to handle, without restrictions any client requests (including
67
   memory reads/writes, register fetch/stores and a resume).
68
 
69
   For a process simulator, the process is not created until a call to
70
   sim_create_inferior.
71
 
72
   We do the following on a first call.
73
   - parse the options
74
   -
75
   @todo Eventually we should use the option parser built into the GDB
76
         simulator (see common/sim-options.h). However since this is minimally
77
         documented, and we have only the one option, for now we do it
78
         ourselves.
79
 
80
   @note We seem to capable of being called twice. We use the static
81
         "global_sd" variable to keep track of this. Second and subsequent
82
         calls do nothing, but return the previously opened simulator
83
         description.
84
 
85
   @param[in] kind  Specifies how the simulator shall be used.  Currently
86
                    there are only two kinds: stand-alone and debug.
87
 
88
   @param[in] callback  Specifies a standard host callback (defined in
89
                        callback.h).
90
 
91
   @param[in] abfd      When non NULL, designates a target program.  The
92
                        program is not loaded.
93
 
94
   @param[in] argv      A standard ARGV pointer such as that passed from the
95
                        command line.  The syntax of the argument list is is
96
                        assumed to be ``SIM-PROG { SIM-OPTION } [
97
                        TARGET-PROGRAM { TARGET-OPTION } ]''.
98
 
99
                        The trailing TARGET-PROGRAM and args are only valid
100
                        for a stand-alone simulator.
101
 
102
                        The argument list is null terminated!
103
 
104
   @return On success, the result is a non NULL descriptor that shall be
105
           passed to the other sim_foo functions.                            */
106
/* ------------------------------------------------------------------------- */
107
SIM_DESC
108
sim_open (SIM_OPEN_KIND                kind,
109
          struct host_callback_struct *callback,
110
          struct bfd                  *abfd,
111
          char                        *argv[])
112
{
113
  /*!A global record of the simulator description */
114
  static SIM_DESC  static_sd = NULL;
115
 
116 244 jeremybenn
#ifdef OR32_SIM_DEBUG
117
  printf ("sim_open called\n");
118
#endif
119
 
120 227 jeremybenn
  /* If static_sd is not yet allocated, we allocate it and mark the simulator
121 232 jeremybenn
     as not yet open. This is the only time we can process any custom
122
     arguments and only time we initialize the simulator. */
123 227 jeremybenn
  if (NULL == static_sd)
124
    {
125 232 jeremybenn
      int    local_argc;                /* Our local argv with extra args */
126
      char **local_argv;
127 227 jeremybenn
 
128
      int    argc;                      /* How many args originally */
129
      int    i;                         /* For local argv */
130
      int    mem_defined_p = 0;          /* Have we requested a memory size? */
131
 
132 232 jeremybenn
      int    res;                       /* Result of initialization */
133
 
134
      static_sd = (SIM_DESC) malloc (sizeof (*static_sd));
135
      static_sd->sim_open = 0;
136
 
137 227 jeremybenn
      /* Count the number of arguments and see if we have specified either a
138
         config file or a memory size. */
139
      for (argc = 1; NULL != argv[argc]; argc++)
140
        {
141 244 jeremybenn
#ifdef OR32_SIM_DEBUG
142
          printf ("argv[%d] = %s\n", argc, argv[argc]);
143
#endif
144 227 jeremybenn
          if ((0 == strcmp (argv[argc], "-f"))    ||
145
              (0 == strcmp (argv[argc], "-file")) ||
146
              (0 == strcmp (argv[argc], "-m"))    ||
147
              (0 == strcmp (argv[argc], "-memory")))
148
            {
149
              mem_defined_p = 1;
150
            }
151
        }
152
 
153
      /* If we have no memory defined, we give it a default 8MB. We also always
154
         run quiet. So we must define our own argument vector */
155
      local_argc = mem_defined_p ? argc + 1 : argc + 3;
156
      local_argv = malloc ((local_argc + 1) * sizeof (char *));
157
 
158
      for (i = 0 ; i < argc; i++)
159
        {
160
          local_argv[i] = argv[i];
161
        }
162
 
163
      local_argv[i++] = "--quiet";
164
 
165
      if (!mem_defined_p)
166
        {
167
          local_argv[i++] = "--memory";
168
          local_argv[i++] = "8M";
169
        }
170
 
171
      local_argv[i] = NULL;
172 232 jeremybenn
 
173
      /* Try to initialize, then we can free the local argument vector. If we
174
         fail to initialize return NULL to indicate that failure. */
175 244 jeremybenn
      res = or1ksim_init (local_argc, local_argv, NULL, NULL, NULL);
176 232 jeremybenn
      free (local_argv);
177
 
178
      if (res)
179
        {
180
          return  NULL;                 /* Failure */
181
        }
182 227 jeremybenn
    }
183
 
184 232 jeremybenn
  /* We have either initialized a new simulator, or already have an intialized
185
     simulator. Populate the descriptor and stall the processor, the return
186
     the descriptor. */
187
  static_sd->callback    = callback;
188
  static_sd->is_debug    = (kind == SIM_OPEN_DEBUG);
189
  static_sd->myname      = (char *)xstrdup (argv[0]);
190
  static_sd->sim_open    = 1;
191
  static_sd->last_reason = sim_running;
192
  static_sd->last_rc     = TARGET_SIGNAL_NONE;
193
  static_sd->entry_point = OR32_RESET_EXCEPTION;
194
  static_sd->resume_npc  = OR32_RESET_EXCEPTION;
195 227 jeremybenn
 
196 232 jeremybenn
  or1ksim_set_stall_state (0);
197 227 jeremybenn
 
198 232 jeremybenn
  return  static_sd;
199
 
200 227 jeremybenn
}       /* sim_open () */
201
 
202
 
203
/* ------------------------------------------------------------------------- */
204
/*!Destroy a simulator instance.
205
 
206 232 jeremybenn
   We never actually close the simulator, because we have no way to
207
   reinitialize it. Instead we just stall the processor and mark it closed.
208 227 jeremybenn
 
209
   @param[in] sd        Simulation descriptor from sim_open ().
210
   @param[in] quitting  Non-zero if we cannot hang on errors.                */
211
/* ------------------------------------------------------------------------- */
212
void
213
sim_close (SIM_DESC  sd,
214
           int       quitting)
215
{
216 244 jeremybenn
#ifdef OR32_SIM_DEBUG
217
  printf ("sim_close called\n");
218
#endif
219
 
220 227 jeremybenn
  if (NULL == sd)
221
    {
222
      fprintf (stderr,
223
               "Warning: Attempt to close non-open simulation: ignored.\n");
224
    }
225
  else
226
    {
227
      free (sd->myname);
228
      sd->sim_open = 0;
229 232 jeremybenn
      or1ksim_set_stall_state (0);
230 227 jeremybenn
    }
231
}       /* sim_close () */
232
 
233
 
234
/* ------------------------------------------------------------------------- */
235
/*!Load program PROG into the simulators memory.
236
 
237
   Hardware simulator: Normally, each program section is written into
238
   memory according to that sections LMA using physical (direct)
239
   addressing.  The exception being systems, such as PPC/CHRP, which
240
   support more complicated program loaders.  A call to this function
241
   should not effect the state of the processor registers.  Multiple
242
   calls to this function are permitted and have an accumulative
243
   effect.
244
 
245
   Process simulator: Calls to this function may be ignored.
246
 
247
   @todo Most hardware simulators load the image at the VMA using
248
         virtual addressing.
249
 
250
   @todo For some hardware targets, before a loaded program can be executed,
251
         it requires the manipulation of VM registers and tables.  Such
252
         manipulation should probably (?) occure in sim_create_inferior ().
253
 
254
   @param[in] sd        Simulation descriptor from sim_open ().
255
   @param[in] prog      The name of the program
256
   @param[in] abfd      If non-NULL, the BFD for the file has already been
257
                        opened.
258
   @param[in] from_tty  Not sure what this does. Probably indicates this is a
259
                        command line load? Anyway we don't use it.
260
 
261
   @return  A return code indicating success.                                */
262
/* ------------------------------------------------------------------------- */
263
SIM_RC
264
sim_load (SIM_DESC    sd,
265
          char       *prog,
266
          struct bfd *abfd,
267
          int         from_tty)
268
{
269
  bfd *prog_bfd;
270
 
271 244 jeremybenn
#ifdef OR32_SIM_DEBUG
272
  printf ("sim_load called\n");
273
#endif
274
 
275 227 jeremybenn
  /* Use the built in loader, which will in turn use our write function. */
276
  prog_bfd = sim_load_file (sd, sd->myname, sd->callback, prog, abfd,
277
                            sd->is_debug, 0, sim_write);
278
 
279
  if (NULL == prog_bfd)
280
    {
281
      return SIM_RC_FAIL;
282
    }
283
 
284
  /* If the BFD was not already open, then close the loaded program. */
285
  if (NULL == abfd)
286
    {
287
      bfd_close (prog_bfd);
288
    }
289
 
290
  return  SIM_RC_OK;
291
 
292
}       /* sim_load () */
293
 
294
 
295
/* ------------------------------------------------------------------------- */
296
/*!Prepare to run the simulated program.
297
 
298
   Hardware simulator: This function shall initialize the processor
299
   registers to a known value.  The program counter and possibly stack
300
   pointer shall be set using information obtained from ABFD (or
301
   hardware reset defaults).  ARGV and ENV, dependant on the target
302
   ABI, may be written to memory.
303
 
304
   Process simulator: After a call to this function, a new process
305
   instance shall exist. The TEXT, DATA, BSS and stack regions shall
306
   all be initialized, ARGV and ENV shall be written to process
307
   address space (according to the applicable ABI) and the program
308
   counter and stack pointer set accordingly.
309
 
310
   ABFD, if not NULL, provides initial processor state information.
311
   ARGV and ENV, if non NULL, are NULL terminated lists of pointers.
312
 
313
   We perform the following steps:
314
   - stall the processor
315
   - set the entry point to the entry point in the BFD, or the reset
316
     vector if the BFD is not available.
317
   - set the resumption NPC to the reset vector. We always do this, to ensure
318
     the library is initialized.
319
 
320
   @param[in] sd    Simulation descriptor from sim_open ().
321
   @param[in] abfd  If non-NULL provides initial processor state information.
322
   @param[in] argv  Vector of arguments to the program. We don't use this
323
   @param[in] env   Vector of environment data. We don't use this.
324
 
325
   @return  A return code indicating success.                                */
326
/* ------------------------------------------------------------------------- */
327
SIM_RC
328
sim_create_inferior (SIM_DESC     sd,
329
                     struct bfd  *abfd,
330
                     char       **argv  ATTRIBUTE_UNUSED,
331
                     char       **env   ATTRIBUTE_UNUSED)
332
{
333 244 jeremybenn
#ifdef OR32_SIM_DEBUG
334
  printf ("sim_create_inferior called\n");
335
#endif
336
 
337 227 jeremybenn
  or1ksim_set_stall_state (1);
338
  sd->entry_point = (NULL == abfd) ? OR32_RESET_EXCEPTION :
339
                                    bfd_get_start_address (abfd);
340
  sd->resume_npc  = OR32_RESET_EXCEPTION;
341
 
342
  return  SIM_RC_OK;
343
 
344
}       /* sim_create_inferior () */
345
 
346
 
347
/* ------------------------------------------------------------------------- */
348
/*!Fetch bytes from the simulated program's memory.
349
 
350
   @param[in]  sd   Simulation descriptor from sim_open (). We don't use
351
                    this.
352
   @param[in]  mem  The address in memory to fetch from.
353
   @param[out] buf  Where to put the read data
354
   @param[in]  len  Number of bytes to fetch
355
 
356
   @return  Number of bytes read, or zero if error.                          */
357
/* ------------------------------------------------------------------------- */
358
int
359
sim_read (SIM_DESC       sd  ATTRIBUTE_UNUSED,
360
          SIM_ADDR       mem,
361
          unsigned char *buf,
362
          int            len)
363
{
364
  int res = or1ksim_read_mem (mem, buf, len);
365
 
366 244 jeremybenn
#ifdef OR32_SIM_DEBUG
367
  printf ("Reading %d bytes from 0x%08p\n", len, mem);
368
#endif
369 227 jeremybenn
 
370
  return  res;
371
 
372
}      /* sim_read () */
373
 
374
 
375
/* ------------------------------------------------------------------------- */
376
/*!Store bytes to the simulated program's memory.
377
 
378
   @param[in] sd   Simulation descriptor from sim_open (). We don't use
379
                   this.
380
   @param[in] mem  The address in memory to write to.
381
   @param[in] buf  The data to write
382
   @param[in] len  Number of bytes to write
383
 
384
   @return  Number of byte written, or zero if error.                        */
385
/* ------------------------------------------------------------------------- */
386
int
387
sim_write (SIM_DESC       sd  ATTRIBUTE_UNUSED,
388
           SIM_ADDR       mem,
389
           unsigned char *buf,
390
           int            len)
391
{
392 244 jeremybenn
#ifdef OR32_SIM_DEBUG
393
  printf ("Writing %d bytes to 0x%08p\n", len, mem);
394
#endif
395 227 jeremybenn
 
396
  return  or1ksim_write_mem ((unsigned int) mem, buf, len);
397
 
398
}       /* sim_write () */
399
 
400
 
401
/* ------------------------------------------------------------------------- */
402
/*!Fetch a register from the simulation
403
 
404
   We get the register back as a 32-bit value. However we must convert it to a
405
   character array <em>in target endian order</em>.
406
 
407
   The exception is if the register is the NPC, which is only written just
408
   before resumption, to avoid pipeline confusion. It is fetched from the SD.
409
 
410
   @param[in]  sd     Simulation descriptor from sim_open (). We don't use
411
                      this.
412
   @param[in]  regno  The register to fetch
413
   @param[out] buf    Buffer of length bytes to store the result. Data is
414
                      only transferred if length matches the register length
415
                      (the actual register size is still returned).
416
   @param[in]  len    Size of buf, which should match the size of the
417
                      register.
418
 
419
   @return  The actual size of the register, or zero if regno is not
420
            applicable. Legacy implementations return -1.
421
/* ------------------------------------------------------------------------- */
422
int
423
sim_fetch_register (SIM_DESC       sd,
424
                    int            regno,
425
                    unsigned char *buf,
426
                    int            len)
427
{
428 232 jeremybenn
  unsigned long int  regval;
429
  int                res;
430 227 jeremybenn
 
431 244 jeremybenn
#ifdef OR32_SIM_DEBUG
432
  printf ("sim_fetch_register (regno=%d\n) called\n", regno);
433
#endif
434 227 jeremybenn
  if (4 != len)
435
    {
436
      fprintf (stderr, "Invalid register length %d\n");
437
      return  0;
438
    }
439
 
440
  if (OR32_NPC_REGNUM == regno)
441
    {
442
      regval = sd->resume_npc;
443
      res    = 4;
444
    }
445
  else
446
    {
447
      int res = or1ksim_read_reg (regno, &regval) ? 4 : 0;
448
    }
449
 
450
  /* Convert to target (big) endian */
451
  if (res)
452
    {
453
      buf[0] = (regval >> 24) & 0xff;
454
      buf[1] = (regval >> 16) & 0xff;
455
      buf[2] = (regval >>  8) & 0xff;
456
      buf[3] =  regval        & 0xff;
457 244 jeremybenn
 
458
      return  4;                        /* Success */
459 227 jeremybenn
    }
460 244 jeremybenn
  else
461
    {
462
      return  0;                 /* Failure */
463
    }
464 227 jeremybenn
}       /* sim_fetch_register () */
465
 
466
 
467
/* ------------------------------------------------------------------------- */
468
/*!Store a register to the simulation
469
 
470
   We write the register back as a 32-bit value. However we must convert it from
471
   a character array <em>in target endian order</em>.
472
 
473
   The exception is if the register is the NPC, which is only written just
474
   before resumption, to avoid pipeline confusion. It is saved in the SD.
475
 
476
   @param[in] sd     Simulation descriptor from sim_open (). We don't use
477
                     this.
478
   @param[in] regno  The register to store
479
   @param[in] buf    Buffer of length bytes with the data to store. Data is
480
                     only transferred if length matches the register length
481
                     (the actual register size is still returned).
482
   @param[in] len    Size of buf, which should match the size of the
483
                     register.
484
 
485
   @return  The actual size of the register, or zero if regno is not
486
            applicable. Legacy implementations return -1.
487
/* ------------------------------------------------------------------------- */
488
int
489
sim_store_register (SIM_DESC       sd,
490
                    int            regno,
491
                    unsigned char *buf,
492
                    int            len)
493
{
494
  unsigned int  regval;
495
 
496 244 jeremybenn
#ifdef OR32_SIM_DEBUG
497
  printf ("sim_store_register (regno=%d\n) called\n", regno);
498
#endif
499
 
500 227 jeremybenn
  if (4 != len)
501
    {
502
      fprintf (stderr, "Invalid register length %d\n");
503
      return  0;
504
    }
505
 
506
  /* Convert from target (big) endian */
507
  regval = (((unsigned int) buf[0]) << 24) |
508
           (((unsigned int) buf[1]) << 16) |
509
           (((unsigned int) buf[2]) <<  8) |
510
           (((unsigned int) buf[3])      );
511
 
512 244 jeremybenn
#ifdef OR32_SIM_DEBUG
513
  printf ("Writing register 0x%02x, value 0x%08x\n", regno, regval);
514
#endif
515 227 jeremybenn
 
516
  if (OR32_NPC_REGNUM == regno)
517
    {
518
      sd->resume_npc = regval;
519
      return  4;                        /* Reg length in bytes */
520
    }
521
  else
522
    {
523
      return  or1ksim_write_reg (regno, regval) ? 4 : 0;
524
    }
525
}       /* sim_store_register () */
526
 
527
 
528
/* ------------------------------------------------------------------------- */
529
/* Print whatever statistics the simulator has collected.
530
 
531
   @param[in] sd       Simulation descriptor from sim_open (). We don't use
532
                       this.
533
   @param[in] verbose  Currently unused, and should always be zero.          */
534
/* ------------------------------------------------------------------------- */
535
void
536
sim_info (SIM_DESC  sd       ATTRIBUTE_UNUSED,
537
          int       verbose  ATTRIBUTE_UNUSED)
538
{
539
}       /* sim_info () */
540
 
541
 
542
/* ------------------------------------------------------------------------- */
543
/*!Run (or resume) the simulated program.
544
 
545
   Hardware simulator: If the SIGRC value returned by
546
   sim_stop_reason() is passed back to the simulator via siggnal then
547
   the hardware simulator shall correctly deliver the hardware event
548
   indicated by that signal.  If a value of zero is passed in then the
549
   simulation will continue as if there were no outstanding signal.
550
   The effect of any other siggnal value is is implementation
551
   dependant.
552
 
553
   Process simulator: If SIGRC is non-zero then the corresponding
554
   signal is delivered to the simulated program and execution is then
555
   continued.  A zero SIGRC value indicates that the program should
556
   continue as normal.
557
 
558
   We carry out the following
559
   - Clear the debug reason register
560
   - Clear watchpoing break generation in debug mode register 2
561
   - Set the debug unit to handle TRAP exceptions
562
   - If stepping, set the single step trigger in debug mode register 1
563
   - Write the resume_npc if it differs from the actual NPC.
564
   - Unstall the processor
565
   - Run the processor.
566
 
567
   On execution completion, we determine the reason for the halt. If it is a
568
   breakpoint, we mark the resumption NPC to be the PPC (so we redo the NPC
569
   location).
570
 
571
   @param[in] sd       Simulation descriptor from sim_open ().
572
   @param[in] step     When non-zero indicates that only a single simulator
573
                       cycle should be emulated.
574
   @param[in] siggnal  If non-zero is a (HOST) SIGRC value indicating the type
575
                       of event (hardware interrupt, signal) to be delivered
576
                       to the simulated program.                             */
577
/* ------------------------------------------------------------------------- */
578
void
579
sim_resume (SIM_DESC  sd,
580
            int       step,
581
            int       siggnal)
582
{
583 232 jeremybenn
  unsigned long int  npc;               /* Next Program Counter */
584
  unsigned long int  drr;               /* Debug Reason Register */
585
  unsigned long int  dsr;               /* Debug Stop Register */
586
  unsigned long int  dmr1;              /* Debug Mode Register 1*/
587
  unsigned long int  dmr2;              /* Debug Mode Register 2*/
588 227 jeremybenn
 
589 232 jeremybenn
  unsigned long int  retval;            /* Return value on Or1ksim exit */
590
 
591 227 jeremybenn
  int                res;               /* Result of a run. */
592
 
593 244 jeremybenn
#ifdef OR32_SIM_DEBUG
594
  printf ("sim_resume called\n");
595
#endif
596
 
597 227 jeremybenn
  /* Clear Debug Reason Register and watchpoint break generation in Debug Mode
598
     Register 2 */
599
  (void) or1ksim_write_spr (OR32_SPR_DRR, 0);
600
 
601
  (void) or1ksim_read_spr (OR32_SPR_DMR2, &dmr2);
602
  dmr2 &= ~OR32_SPR_DMR2_WGB;
603
  (void) or1ksim_write_spr (OR32_SPR_DMR2, dmr2);
604
 
605
  /* Set debug unit to handle TRAP exceptions */
606
  (void) or1ksim_read_spr (OR32_SPR_DSR, &dsr);
607
  dsr |= OR32_SPR_DSR_TE;
608
  (void) or1ksim_write_spr (OR32_SPR_DSR, dsr);
609
 
610 237 jeremybenn
  /* Set the single step trigger in Debug Mode Register 1 if we are
611
     stepping. Otherwise clear it! */
612 227 jeremybenn
  if (step)
613
    {
614
      (void) or1ksim_read_spr (OR32_SPR_DMR1, &dmr1);
615
      dmr1 |= OR32_SPR_DMR1_ST;
616
      (void) or1ksim_write_spr (OR32_SPR_DMR1, dmr1);
617
    }
618 237 jeremybenn
  else
619
    {
620
      (void) or1ksim_read_spr (OR32_SPR_DMR1, &dmr1);
621
      dmr1 &= ~OR32_SPR_DMR1_ST;
622
      (void) or1ksim_write_spr (OR32_SPR_DMR1, dmr1);
623
    }
624 227 jeremybenn
 
625
  /* Set the NPC if it has changed */
626
  (void) or1ksim_read_reg (OR32_NPC_REGNUM, &npc);
627
 
628 244 jeremybenn
#ifdef OR32_SIM_DEBUG
629
  printf ("  npc = 0x%08lx, resume_npc = 0x%08lx\n", npc, sd->resume_npc);
630
#endif
631
 
632 227 jeremybenn
  if (npc != sd->resume_npc)
633
    {
634
      (void) or1ksim_write_reg (OR32_NPC_REGNUM, sd->resume_npc);
635
    }
636
 
637
  /* Unstall and run */
638
  or1ksim_set_stall_state (0);
639
  res = or1ksim_run (-1.0);
640
 
641
  /* Determine the reason for stopping. If we hit a breakpoint, then the
642
     resumption NPC must be set to the PPC to allow re-execution of the
643
     trapped instruction. */
644
  switch (res)
645
    {
646
    case OR1KSIM_RC_HALTED:
647
      sd->last_reason = sim_exited;
648 232 jeremybenn
      (void) or1ksim_read_reg (OR32_FIRST_ARG_REGNUM, &retval);
649
      sd->last_rc     = (unsigned int) retval;
650 227 jeremybenn
      sd->resume_npc  = OR32_RESET_EXCEPTION;
651
      break;
652
 
653
    case OR1KSIM_RC_BRKPT:
654
      sd->last_reason = sim_stopped;
655
      sd->last_rc     = TARGET_SIGNAL_TRAP;
656 237 jeremybenn
 
657
      /* This could have been a breakpoint or single step. */
658
      if (step)
659
        {
660
          (void) or1ksim_read_reg (OR32_NPC_REGNUM, &(sd->resume_npc));
661
        }
662
      else
663
        {
664
          (void) or1ksim_read_reg (OR32_PPC_REGNUM, &(sd->resume_npc));
665
        }
666
 
667 227 jeremybenn
      break;
668
 
669
    case OR1KSIM_RC_OK:
670
      /* Should not happen */
671
      fprintf (stderr, "Ooops. Didn't expect OK return from Or1ksim.\n");
672
 
673
      sd->last_reason = sim_running;            /* Should trigger an error! */
674
      sd->last_rc     = TARGET_SIGNAL_NONE;
675
      (void) or1ksim_read_reg (OR32_NPC_REGNUM, &(sd->resume_npc));
676
      break;
677
    }
678
}       /* sim_resume () */
679
 
680
 
681
/* ------------------------------------------------------------------------- */
682
/*!Asynchronous request to stop the simulation.
683
 
684
   @param[in] sd  Simulation descriptor from sim_open (). We don't use this.
685
 
686
   @return  Non-zero indicates that the simulator is able to handle the
687
            request.                                                         */
688
/* ------------------------------------------------------------------------- */
689
int sim_stop (SIM_DESC  sd  ATTRIBUTE_UNUSED)
690
{
691 244 jeremybenn
#ifdef OR32_SIM_DEBUG
692
  printf ("sim_stop called\n");
693
#endif
694
 
695 227 jeremybenn
  return  0;                     /* We don't support this */
696
 
697
}       /* sim_stop () */
698
 
699
 
700
/* ------------------------------------------------------------------------- */
701
/*!Fetch the REASON why the program stopped.
702
 
703
   The reason enumeration indicates why:
704
 
705
   - sim_exited:    The program has terminated. sigrc indicates the target
706
                    dependant exit status.
707
 
708
   - sim_stopped:   The program has stopped.  sigrc uses the host's signal
709
                    numbering as a way of identifying the reaon: program
710
                    interrupted by user via a sim_stop request (SIGINT); a
711
                    breakpoint instruction (SIGTRAP); a completed single step
712
                    (SIGTRAP); an internal error condition (SIGABRT); an
713
                    illegal instruction (SIGILL); Access to an undefined
714
                    memory region (SIGSEGV); Mis-aligned memory access
715
                    (SIGBUS).
716
 
717
                    For some signals information in addition to the signal
718
                    number may be retained by the simulator (e.g. offending
719
                    address), that information is not directly accessable via
720
                    this interface.
721
 
722
   - sim_signalled: The program has been terminated by a signal. The
723
                    simulator has encountered target code that causes the the
724
                    program to exit with signal sigrc.
725
 
726
   - sim_running:
727
   - sim_polling:   The return of one of these values indicates a problem
728
                    internal to the simulator.
729
 
730
   @param[in]  sd      Simulation descriptor from sim_open ().
731
   @param[out] reason  The reason for stopping
732
   @param[out] sigrc   Supplementary information for some values of reason.  */
733
/* ------------------------------------------------------------------------- */
734
void
735
sim_stop_reason (SIM_DESC       sd,
736
                 enum sim_stop *reason,
737
                 int           *sigrc)
738
 {
739
   *reason = sd->last_reason;
740
   *sigrc  = sd->last_rc;
741
 
742
}       /* sim_stop_reason () */
743
 
744
 
745
/* ------------------------------------------------------------------------- */
746
/* Passthru for other commands that the simulator might support.
747
 
748
   Simulators should be prepared to deal with any combination of NULL
749
   or empty command.
750
 
751
   This implementation currently does nothing.
752
 
753
   @param[in] sd  Simulation descriptor from sim_open (). We don't use this.
754
   @param[in] cmd The command to pass through.                               */
755
/* ------------------------------------------------------------------------- */
756
void
757
sim_do_command (SIM_DESC  sd   ATTRIBUTE_UNUSED,
758
                char     *cmd  ATTRIBUTE_UNUSED)
759
{
760
}       /* sim_do_command () */
761
 
762
 
763
/* ------------------------------------------------------------------------- */
764
/* Set the default host_callback_struct
765
 
766
   @note Deprecated, but implemented, since it is still required for linking.
767
 
768
   This implementation currently does nothing.
769
 
770
   @param[in] ptr  The host_callback_struct pointer. Unused here.            */
771
/* ------------------------------------------------------------------------- */
772
void
773
sim_set_callbacks (struct host_callback_struct *ptr ATTRIBUTE_UNUSED)
774
{
775
}       /* sim_set_callbacks () */
776
 
777
 
778
/* ------------------------------------------------------------------------- */
779
/* Set the size of the simulator memory array.
780
 
781
   @note Deprecated, but implemented, since it is still required for linking.
782
 
783
   This implementation currently does nothing.
784
 
785
   @param[in] size  The memory size to use. Unused here.                     */
786
/* ------------------------------------------------------------------------- */
787
void
788
sim_size (int  size  ATTRIBUTE_UNUSED)
789
{
790
}       /* sim_size () */
791
 
792
 
793
/* ------------------------------------------------------------------------- */
794
/* Single step the simulator with tracing enabled.
795
 
796
   @note Deprecated, but implemented, since it is still required for linking.
797
 
798
   This implementation currently does nothing.
799
 
800
   @param[in] sd  The simulator description struct. Unused here.             */
801
/* ------------------------------------------------------------------------- */
802
void
803
sim_trace (SIM_DESC  sd  ATTRIBUTE_UNUSED)
804
{
805
}       /* sim_trace () */

powered by: WebSVN 2.1.0

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