/[gxemul]/upstream/0.4.4/src/symbol.c
This is repository of my old source code which isn't updated any more. Go to git.rot13.org for current projects!
ViewVC logotype

Diff of /upstream/0.4.4/src/symbol.c

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 10 by dpavlin, Mon Oct 8 16:18:27 2007 UTC revision 22 by dpavlin, Mon Oct 8 16:19:37 2007 UTC
# Line 1  Line 1 
1  /*  /*
2   *  Copyright (C) 2003-2005  Anders Gavare.  All rights reserved.   *  Copyright (C) 2003-2006  Anders Gavare.  All rights reserved.
3   *   *
4   *  Redistribution and use in source and binary forms, with or without   *  Redistribution and use in source and binary forms, with or without
5   *  modification, are permitted provided that the following conditions are met:   *  modification, are permitted provided that the following conditions are met:
# Line 25  Line 25 
25   *  SUCH DAMAGE.   *  SUCH DAMAGE.
26   *   *
27   *   *
28   *  $Id: symbol.c,v 1.26 2005/06/21 16:22:52 debug Exp $   *  $Id: symbol.c,v 1.34 2006/01/14 12:51:59 debug Exp $
29   *   *
30   *  Address to symbol translation routines.   *  Address to symbol translation routines.
31   *   *
32   *  This module is (probably) independant from the rest of the emulator.   *  This module is (probably) independent from the rest of the emulator.
33   *  symbol_init() must be called before any other function in this   *  symbol_init() must be called before any other function in this file is used.
  *  file is used.  
34   */   */
35    
36  #include <stdio.h>  #include <stdio.h>
# Line 94  int get_symbol_addr(struct symbol_contex Line 93  int get_symbol_addr(struct symbol_contex
93    
94    
95  /*  /*
96   *  get_symbol_name():   *  get_symbol_name_and_n_args():
97   *   *
98   *  Translate an address into a symbol name.  The return value is a pointer   *  Translate an address into a symbol name.  The return value is a pointer
99   *  to a static char array, containing the symbol name.  (In other words,   *  to a static char array, containing the symbol name.  (In other words,
# Line 107  int get_symbol_addr(struct symbol_contex Line 106  int get_symbol_addr(struct symbol_contex
106   *  0x1008, the symbol's name will be found in the static char array, and   *  0x1008, the symbol's name will be found in the static char array, and
107   *  *offset will be set to 0x8.   *  *offset will be set to 0x8.
108   *   *
109     *  If n_argsp is non-NULL, *n_argsp is set to the symbol's n_args value.
110     *
111   *  If no symbol was found, NULL is returned instead.   *  If no symbol was found, NULL is returned instead.
112   */   */
113  static char symbol_buf[SYMBOLBUF_MAX+1];  static char symbol_buf[SYMBOLBUF_MAX+1];
114  char *get_symbol_name(struct symbol_context *sc, uint64_t addr,  char *get_symbol_name_and_n_args(struct symbol_context *sc, uint64_t addr,
115          uint64_t *offset)          uint64_t *offset, int *n_argsp)
116  {  {
117          struct symbol *s;          struct symbol *s;
118          int stepsize, ofs;          int stepsize, ofs;
# Line 141  char *get_symbol_name(struct symbol_cont Line 142  char *get_symbol_name(struct symbol_cont
142                                              (addr - s->addr));                                              (addr - s->addr));
143                                  if (offset != NULL)                                  if (offset != NULL)
144                                          *offset = addr - s->addr;                                          *offset = addr - s->addr;
145                                    if (n_argsp != NULL)
146                                            *n_argsp = s->n_args;
147                                  return symbol_buf;                                  return symbol_buf;
148                          }                          }
149                          s = s->next;                          s = s->next;
# Line 163  char *get_symbol_name(struct symbol_cont Line 166  char *get_symbol_name(struct symbol_cont
166                                              (addr - s->addr));                                              (addr - s->addr));
167                                  if (offset != NULL)                                  if (offset != NULL)
168                                          *offset = addr - s->addr;                                          *offset = addr - s->addr;
169                                    if (n_argsp != NULL)
170                                            *n_argsp = s->n_args;
171                                  return symbol_buf;                                  return symbol_buf;
172                          }                          }
173    
# Line 190  char *get_symbol_name(struct symbol_cont Line 195  char *get_symbol_name(struct symbol_cont
195    
196    
197  /*  /*
198     *  get_symbol_name():
199     *
200     *  See get_symbol_name_and_n_args().
201     */
202    char *get_symbol_name(struct symbol_context *sc, uint64_t addr, uint64_t *offs)
203    {
204            return get_symbol_name_and_n_args(sc, addr, offs, NULL);
205    }
206    
207    
208    /*
209   *  add_symbol_name():   *  add_symbol_name():
210   *   *
211   *  Add a symbol to the symbol list.   *  Add a symbol to the symbol list.
212   */   */
213  void add_symbol_name(struct symbol_context *sc,  void add_symbol_name(struct symbol_context *sc,
214          uint64_t addr, uint64_t len, char *name, int type)          uint64_t addr, uint64_t len, char *name, int type, int n_args)
215  {  {
216          struct symbol *s;          struct symbol *s;
217    
# Line 214  void add_symbol_name(struct symbol_conte Line 230  void add_symbol_name(struct symbol_conte
230                  return;                  return;
231    
232          /*  TODO: Maybe this should be optional?  */          /*  TODO: Maybe this should be optional?  */
233          if (name[0] == '$')          if (name[0] == '.' || name[0] == '$')
234                  return;                  return;
235    
236            /*  Quick test-hack:  */
237            if (n_args < 0) {
238                    if (strcmp(name, "strlen") == 0)
239                            n_args = 1;
240                    if (strcmp(name, "strcmp") == 0)
241                            n_args = 2;
242                    if (strcmp(name, "strcpy") == 0)
243                            n_args = 2;
244                    if (strcmp(name, "strncpy") == 0)
245                            n_args = 3;
246                    if (strcmp(name, "strlcpy") == 0)
247                            n_args = 3;
248                    if (strcmp(name, "strlcat") == 0)
249                            n_args = 3;
250                    if (strcmp(name, "strncmp") == 0)
251                            n_args = 3;
252                    if (strcmp(name, "memset") == 0)
253                            n_args = 3;
254                    if (strcmp(name, "memcpy") == 0)
255                            n_args = 3;
256                    if (strcmp(name, "bzero") == 0)
257                            n_args = 2;
258                    if (strcmp(name, "bcopy") == 0)
259                            n_args = 3;
260            }
261    
262          if ((addr >> 32) == 0 && (addr & 0x80000000ULL))          if ((addr >> 32) == 0 && (addr & 0x80000000ULL))
263                  addr |= 0xffffffff00000000ULL;                  addr |= 0xffffffff00000000ULL;
264    
# Line 231  void add_symbol_name(struct symbol_conte Line 273  void add_symbol_name(struct symbol_conte
273                  fprintf(stderr, "out of memory\n");                  fprintf(stderr, "out of memory\n");
274                  exit(1);                  exit(1);
275          }          }
276          s->addr = addr;          s->addr   = addr;
277          s->len  = len;          s->len    = len;
278          s->type = type;          s->type   = type;
279            s->n_args = n_args;
280    
281          sc->n_symbols ++;          sc->n_symbols ++;
282    
# Line 292  void symbol_readfile(struct symbol_conte Line 335  void symbol_readfile(struct symbol_conte
335                  if (type == 't' || type == 'r' || type == 'g')                  if (type == 't' || type == 'r' || type == 'g')
336                          continue;                          continue;
337    
338                  add_symbol_name(sc, addr, len, b4, type);                  add_symbol_name(sc, addr, len, b4, type, -1);
339          }          }
340    
341          fclose(f);          fclose(f);

Legend:
Removed from v.10  
changed lines
  Added in v.22

  ViewVC Help
Powered by ViewVC 1.1.26