Replace xmalloc/xfree with vector in jit.c
[deliverable/binutils-gdb.git] / sim / erc32 / func.c
index 265d42f5f162cdd18534250f8c2ba8668c0de49a..a0c85a091394b040d4245dac4a3a86cfb706b1ab 100644 (file)
@@ -1,23 +1,20 @@
-/*
- * func.c, misc simulator functions. This file is part of SIS.
- * 
- * SIS, SPARC instruction simulator V1.8 Copyright (C) 1995 Jiri Gaisler,
- * European Space Agency
- * 
- * This program is free software; you can redistribute it and/or modify it under
- * the terms of the GNU General Public License as published by the Free
- * Software Foundation; either version 3 of the License, or (at your option)
- * any later version.
- * 
- * This program is distributed in the hope that it will be useful, but WITHOUT
- * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
- * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
- * more details.
- * 
- * You should have received a copy of the GNU General Public License along with
- * this program; if not, see <http://www.gnu.org/licenses/>.
- * 
- */
+/* This file is part of SIS (SPARC instruction simulator)
+
+   Copyright (C) 1995-2019 Free Software Foundation, Inc.
+   Contributed by Jiri Gaisler, European Space Agency
+
+   This program is free software; you can redistribute it and/or modify
+   it under the terms of the GNU General Public License as published by
+   the Free Software Foundation; either version 3 of the License, or
+   (at your option) any later version.
+
+   This program is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
+
+   You should have received a copy of the GNU General Public License
+   along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
 
 #include "config.h"
 #include <signal.h>
 #include "sim-config.h"
 #include <inttypes.h>
 
-
 #define        VAL(x)  strtoul(x,(char **)NULL,0)
 
-extern int     current_target_byte_order;
 struct disassemble_info dinfo;
 struct pstate   sregs;
 extern struct estate ebase;
@@ -86,7 +81,7 @@ batch(sregs, fname)
 
     if ((fp = fopen(fname, "r")) == NULL) {
        fprintf(stderr, "couldn't open batch file %s\n", fname);
-       return (0);
+       return 0;
     }
     while (getline(&lbuf, &len, fp) > -1) {
        slen = strlen(lbuf);
@@ -98,7 +93,7 @@ batch(sregs, fname)
     }
     free(lbuf);
     fclose(fp);
-    return (1);
+    return 1;
 }
 
 void
@@ -184,18 +179,10 @@ get_regi(struct pstate * sregs, int32 reg, char *buf)
     default:break;
        }
     }
-    if (current_target_byte_order == BIG_ENDIAN) {
-       buf[0] = (rval >> 24) & 0x0ff;
-       buf[1] = (rval >> 16) & 0x0ff;
-       buf[2] = (rval >> 8) & 0x0ff;
-       buf[3] = rval & 0x0ff;
-    }
-    else {
-       buf[3] = (rval >> 24) & 0x0ff;
-       buf[2] = (rval >> 16) & 0x0ff;
-       buf[1] = (rval >> 8) & 0x0ff;
-       buf[0] = rval & 0x0ff;
-    }
+    buf[0] = (rval >> 24) & 0x0ff;
+    buf[1] = (rval >> 16) & 0x0ff;
+    buf[2] = (rval >> 8) & 0x0ff;
+    buf[3] = rval & 0x0ff;
 }
 
 
@@ -375,23 +362,22 @@ limcalc (freq)
             lim = -1;
         }
     }
-    return (lim);
+    return lim;
 }
-    
+
 int
-exec_cmd(sregs, cmd)
-    char           *cmd;
-    struct pstate  *sregs;
+exec_cmd(struct pstate *sregs, const char *cmd)
 {
     char           *cmd1, *cmd2;
     int32           stat;
     uint32          len, i, clen, j;
     static uint32   daddr = 0;
-    char           *cmdsave;
+    char           *cmdsave, *cmdsave2 = NULL;
 
     stat = OK;
     cmdsave = strdup(cmd);
-    if ((cmd1 = strtok(cmd, " \t")) != NULL) {
+    cmdsave2 = strdup (cmd);
+    if ((cmd1 = strtok (cmdsave2, " \t")) != NULL) {
        clen = strlen(cmd1);
        if (strncmp(cmd1, "bp", clen) == 0) {
            for (i = 0; i < sregs->bptnum; i++) {
@@ -608,9 +594,11 @@ exec_cmd(sregs, cmd)
        } else
            printf("syntax error\n");
     }
+    if (cmdsave2 != NULL)
+       free(cmdsave2);
     if (cmdsave != NULL)
        free(cmdsave);
-    return (stat);
+    return stat;
 }
 
 
@@ -749,7 +737,7 @@ disp_fpu(sregs)
            printf("\n");
     }
     printf("\n");
-    return (OK);
+    return OK;
 }
 
 static void
@@ -786,15 +774,15 @@ disp_ctrl(sregs)
     struct pstate  *sregs;
 {
 
-    unsigned char           i[4];
+    uint32           i;
 
     printf("\n psr: %08X   wim: %08X   tbr: %08X   y: %08X\n",
           sregs->psr, sregs->wim, sregs->tbr, sregs->y);
-    sis_memory_read(sregs->pc, i, 4);
-    printf("\n  pc: %08X = %02X%02X%02X%02X    ", sregs->pc,i[0],i[1],i[2],i[3]);
+    sis_memory_read (sregs->pc, (char *) &i, 4);
+    printf ("\n  pc: %08X = %08X    ", sregs->pc, i);
     print_insn_sparc_sis(sregs->pc, &dinfo);
-    sis_memory_read(sregs->npc, i, 4);
-    printf("\n npc: %08X = %02X%02X%02X%02X    ",sregs->npc,i[0],i[1],i[2],i[3]);
+    sis_memory_read (sregs->npc, (char *) &i, 4);
+    printf ("\n npc: %08X = %08X    ", sregs->npc, i);
     print_insn_sparc_sis(sregs->npc, &dinfo);
     if (sregs->err_mode)
        printf("\n IU in error mode");
@@ -808,22 +796,25 @@ disp_mem(addr, len)
 {
 
     uint32          i;
-    unsigned char   data[4];
+    union {
+           unsigned char u8[4];
+           uint32 u32;
+    } data;
     uint32          mem[4], j;
     char           *p;
 
     for (i = addr & ~3; i < ((addr + len) & ~3); i += 16) {
        printf("\n %8X  ", i);
        for (j = 0; j < 4; j++) {
-           sis_memory_read((i + (j * 4)), data, 4);
-           printf("%02x%02x%02x%02x  ", data[0],data[1],data[2],data[3]);
-           mem[j] = *((int *) &data);
+           sis_memory_read ((i + (j * 4)), data.u8, 4);
+           printf ("%08x  ", data.u32);
+           mem[j] = data.u32;
        }
        printf("  ");
        p = (char *) mem;
        for (j = 0; j < 16; j++) {
-           if (isprint(p[j]))
-               putchar(p[j]);
+           if (isprint (p[j ^ EBT]))
+               putchar (p[j ^ EBT]);
            else
                putchar('.');
        }
@@ -838,11 +829,14 @@ dis_mem(addr, len, info)
     struct disassemble_info *info;
 {
     uint32          i;
-    unsigned char   data[4];
+    union {
+           unsigned char u8[4];
+           uint32 u32;
+    } data;
 
     for (i = addr & -3; i < ((addr & -3) + (len << 2)); i += 4) {
-       sis_memory_read(i, data, 4);
-       printf(" %08x  %02x%02x%02x%02x  ", i, data[0],data[1],data[2],data[3]);
+       sis_memory_read (i, data.u8, 4);
+       printf (" %08x  %08x  ", i, data.u32);
        print_insn_sparc_sis(i, info);
         if (i >= 0xfffffffc) break;
        printf("\n");
@@ -950,7 +944,7 @@ advance_time(sregs)
 uint32
 now()
 {
-    return(ebase.simtime);
+    return ebase.simtime;
 }
 
 
@@ -982,7 +976,7 @@ wait_for_irq()
        }
     }
     sregs.pwdtime += ebase.simtime - endtime;
-    return (ebase.simtime - endtime);
+    return ebase.simtime - endtime;
 }
 
 int
@@ -992,12 +986,12 @@ check_bpt(sregs)
     int32           i;
 
     if ((sregs->bphit) || (sregs->annul))
-       return (0);
+       return 0;
     for (i = 0; i < (int32) sregs->bptnum; i++) {
        if (sregs->pc == sregs->bpts[i])
-           return (BPT_HIT);
+           return BPT_HIT;
     }
-    return (0);
+    return 0;
 }
 
 void
@@ -1035,44 +1029,36 @@ sys_halt()
 #define LOAD_ADDRESS 0
 
 int
-bfd_load(fname)
-    char           *fname;
+bfd_load (const char *fname)
 {
     asection       *section;
     bfd            *pbfd;
     const bfd_arch_info_type *arch;
+    int            i;
 
     pbfd = bfd_openr(fname, 0);
 
     if (pbfd == NULL) {
        printf("open of %s failed\n", fname);
-       return (-1);
+       return -1;
     }
     if (!bfd_check_format(pbfd, bfd_object)) {
        printf("file %s  doesn't seem to be an object file\n", fname);
-       return (-1);
+       return -1;
     }
 
     arch = bfd_get_arch_info (pbfd);
-    if (bfd_little_endian (pbfd) || arch->mach == bfd_mach_sparc_sparclite_le)
-        current_target_byte_order = LITTLE_ENDIAN;
-    else
-       current_target_byte_order = BIG_ENDIAN;
-    if (sis_verbose)
-       printf("file %s is %s-endian.\n", fname,
-              current_target_byte_order == BIG_ENDIAN ? "big" : "little");
-
     if (sis_verbose)
        printf("loading %s:", fname);
     for (section = pbfd->sections; section; section = section->next) {
-       if (bfd_get_section_flags(pbfd, section) & SEC_ALLOC) {
+       if (bfd_section_flags (section) & SEC_ALLOC) {
            bfd_vma         section_address;
            unsigned long   section_size;
            const char     *section_name;
 
-           section_name = bfd_get_section_name(pbfd, section);
+           section_name = bfd_section_name (section);
 
-           section_address = bfd_get_section_vma(pbfd, section);
+           section_address = bfd_section_vma (section);
            /*
             * Adjust sections from a.out files, since they don't carry their
             * addresses with.
@@ -1093,22 +1079,19 @@ bfd_load(fname)
                                              sizeof (marker));
                    if (strncmp (marker.signature, "DaTa", 4) == 0)
                      {
-                       if (current_target_byte_order == BIG_ENDIAN)
-                         section_address = bfd_getb32 (marker.sdata);
-                       else
-                         section_address = bfd_getl32 (marker.sdata);
+                       section_address = bfd_getb32 (marker.sdata);
                      }
                }
            }
 
-           section_size = bfd_section_size(pbfd, section);
+           section_size = bfd_section_size (section);
 
            if (sis_verbose)
                printf("\nsection %s at 0x%08lx (0x%lx bytes)",
                       section_name, section_address, section_size);
 
            /* Text, data or lit */
-           if (bfd_get_section_flags(pbfd, section) & SEC_LOAD) {
+           if (bfd_section_flags (section) & SEC_LOAD) {
                file_ptr        fptr;
 
                fptr = 0;
@@ -1121,7 +1104,8 @@ bfd_load(fname)
 
                    bfd_get_section_contents(pbfd, section, buffer, fptr, count);
 
-                   sis_memory_write(section_address, buffer, count);
+                   for (i = 0; i < count; i++)
+                       sis_memory_write ((section_address + i) ^ EBT, &buffer[i], 1);
 
                    section_address += count;
                    fptr += count;
@@ -1135,7 +1119,7 @@ bfd_load(fname)
     if (sis_verbose)
        printf("\n");
 
-    return(bfd_get_start_address (pbfd));
+    return bfd_get_start_address (pbfd);
 }
 
 double get_time (void)
@@ -1146,5 +1130,5 @@ double get_time (void)
 
     gettimeofday (&tm, NULL);
     usec = ((double) tm.tv_sec) * 1E6 + ((double) tm.tv_usec);
-    return (usec / 1E6);
+    return usec / 1E6;
 }
This page took 0.029699 seconds and 4 git commands to generate.