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

Subversion Repositories or1k

[/] [or1k/] [trunk/] [gdb-5.0/] [sim/] [w65/] [run.c] - Blame information for rev 1765

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 106 markom
/* run front end support for W65
2
   Copyright (C) 1995 Free Software Foundation, Inc.
3
 
4
This file is part of W65 SIM
5
 
6
GNU CC is free software; you can redistribute it and/or modify
7
it under the terms of the GNU General Public License as published by
8
the Free Software Foundation; either version 2, or (at your option)
9
any later version.
10
 
11
GNU CC is distributed in the hope that it will be useful,
12
but WITHOUT ANY WARRANTY; without even the implied warranty of
13
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
GNU General Public License for more details.
15
 
16
You should have received a copy of the GNU General Public License
17
along with this program; if not, write to the Free Software
18
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.  */
19
 
20
 
21
/* Steve Chamberlain
22
   sac@cygnus.com */
23
 
24
#include "config.h"
25
 
26
#include <stdio.h>
27
#ifdef HAVE_STDLIB_H
28
#include <stdlib.h>
29
#endif
30
#include "getopt.h"
31
#include "bfd.h"
32
 
33
#ifdef NEED_DECLARATION_PRINTF
34
extern int printf ();
35
#endif
36
 
37
void usage();
38
extern int optind;
39
 
40
int
41
main (ac, av)
42
     int ac;
43
     char **av;
44
{
45
  bfd *abfd;
46
  bfd_vma start_address;
47
  asection *s;
48
  int i;
49
  int verbose = 0;
50
  int trace = 0;
51
  char *name = "";
52
 
53
  while ((i = getopt (ac, av, "tv")) != EOF)
54
    switch (i)
55
      {
56
      case 't':
57
        trace = 1;
58
        break;
59
      case 'v':
60
        verbose = 1;
61
        break;
62
      default:
63
        usage();
64
      }
65
  ac -= optind;
66
  av += optind;
67
 
68
  if (ac != 1)
69
    usage();
70
 
71
  name = *av;
72
 
73
  if (verbose)
74
    {
75
      printf ("run %s\n", name);
76
    }
77
  abfd = bfd_openr (name, "coff-w65");
78
  if (abfd)
79
    {
80
 
81
      if (bfd_check_format (abfd, bfd_object))
82
        {
83
 
84
          for (s = abfd->sections; s; s = s->next)
85
            {
86
              unsigned char *buffer = malloc (bfd_section_size (abfd, s));
87
              bfd_get_section_contents (abfd,
88
                                        s,
89
                                        buffer,
90
                                        0,
91
                                        bfd_section_size (abfd, s));
92
              sim_write (s->vma, buffer, bfd_section_size (abfd, s));
93
              free (buffer);
94
            }
95
 
96
          start_address = bfd_get_start_address (abfd);
97
          sim_set_pc (start_address);
98
          if (trace)
99
            {
100
              int done = 0;
101
              while (!done)
102
                {
103
                  done = sim_trace ();
104
                }
105
            }
106
          else
107
            {
108
              sim_resume (0, 0);
109
            }
110
          if (verbose)
111
            sim_info (printf, 0);
112
 
113
          /* Find out what was in r0 and return that */
114
          {
115
            unsigned char b[4];
116
            sim_fetch_register(0, b, 4);
117
            return b[3];
118
          }
119
 
120
        }
121
    }
122
 
123
  return 1;
124
}
125
 
126
void
127
usage()
128
{
129
  fprintf (stderr, "usage: run [-tv] program\n");
130
  exit (1);
131
}

powered by: WebSVN 2.1.0

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