Skip to content

Commit b868a23

Browse files
committed
sim: nltvals: localize TARGET_<open> defines
Code should not be using these directly, instead they should be resolving these dynamically via the open_map. Rework the common callback code that was using the defines to use symbolic names instead, and localize some of the defines in the ARM code (since it's a bit unclear how many different APIs it supports currently), then remove the defines out of the header so no new code can rely on them.
1 parent 88c8370 commit b868a23

File tree

3 files changed

+40
-25
lines changed

3 files changed

+40
-25
lines changed

sim/arm/armos.c

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,6 @@
3131
#include <errno.h>
3232
#include <limits.h>
3333
#include <string.h>
34-
#include "targ-vals.h"
35-
36-
#ifndef TARGET_O_BINARY
37-
#define TARGET_O_BINARY 0
38-
#endif
3934

4035
#ifdef HAVE_UNISTD_H
4136
#include <unistd.h> /* For SEEK_SET etc. */
@@ -188,7 +183,17 @@ ARMul_OSInit (ARMul_State * state)
188183
return TRUE;
189184
}
190185

191-
static int translate_open_mode[] =
186+
/* These are libgloss defines, but seem to be common across all supported ARM
187+
targets at the moment. These should get moved to the callback open_map. */
188+
#define TARGET_O_BINARY 0
189+
#define TARGET_O_APPEND 0x8
190+
#define TARGET_O_CREAT 0x200
191+
#define TARGET_O_RDONLY 0x0
192+
#define TARGET_O_RDWR 0x2
193+
#define TARGET_O_TRUNC 0x400
194+
#define TARGET_O_WRONLY 0x1
195+
196+
static const int translate_open_mode[] =
192197
{
193198
TARGET_O_RDONLY, /* "r" */
194199
TARGET_O_RDONLY + TARGET_O_BINARY, /* "rb" */

sim/common/callback.c

Lines changed: 28 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@
3737
#include <sys/types.h>
3838
#include <sys/stat.h>
3939
#include "sim/callback.h"
40-
#include "targ-vals.h"
4140
/* For xmalloc. */
4241
#include "libiberty.h"
4342

@@ -886,29 +885,44 @@ cb_target_to_host_open (host_callback *cb, int target_val)
886885
{
887886
int host_val = 0;
888887
CB_TARGET_DEFS_MAP *m;
888+
int o_rdonly = 0;
889+
int o_wronly = 0;
890+
int o_rdwr = 0;
891+
int o_binary = 0;
892+
int o_rdwrmask;
889893

894+
/* O_RDONLY can be (and usually is) 0 which needs to be treated specially. */
890895
for (m = &cb->open_map[0]; m->host_val != -1; ++m)
891896
{
892-
switch (m->target_val)
897+
if (!strcmp (m->name, "O_RDONLY"))
898+
o_rdonly = m->target_val;
899+
else if (!strcmp (m->name, "O_WRONLY"))
900+
o_wronly = m->target_val;
901+
else if (!strcmp (m->name, "O_RDWR"))
902+
o_rdwr = m->target_val;
903+
else if (!strcmp (m->name, "O_BINARY"))
904+
o_binary = m->target_val;
905+
}
906+
o_rdwrmask = o_rdonly | o_wronly | o_rdwr;
907+
908+
for (m = &cb->open_map[0]; m->host_val != -1; ++m)
909+
{
910+
if (m->target_val == o_rdonly || m->target_val == o_wronly
911+
|| m->target_val == o_rdwr)
893912
{
894-
/* O_RDONLY can be (and usually is) 0 which needs to be treated
895-
specially. */
896-
case TARGET_O_RDONLY :
897-
case TARGET_O_WRONLY :
898-
case TARGET_O_RDWR :
899-
if ((target_val & (TARGET_O_RDONLY | TARGET_O_WRONLY | TARGET_O_RDWR))
900-
== m->target_val)
913+
if ((target_val & o_rdwrmask) == m->target_val)
901914
host_val |= m->host_val;
902915
/* Handle the host/target differentiating between binary and
903916
text mode. Only one case is of importance */
904-
#if ! defined (TARGET_O_BINARY) && defined (O_BINARY)
905-
host_val |= O_BINARY;
917+
#ifdef O_BINARY
918+
if (o_binary == 0)
919+
host_val |= O_BINARY;
906920
#endif
907-
break;
908-
default :
921+
}
922+
else
923+
{
909924
if ((m->target_val & target_val) == m->target_val)
910925
host_val |= m->host_val;
911-
break;
912926
}
913927
}
914928

sim/common/gentmap.c

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -39,11 +39,6 @@ gen_targ_vals_h (void)
3939
printf ("#define TARGET_%s %d\n", t->symbol, t->value);
4040
printf ("\n");
4141

42-
printf ("/* open flag values */\n");
43-
for (t = &open_tdefs[0]; t->symbol; ++t)
44-
printf ("#define TARGET_%s 0x%x\n", t->symbol, t->value);
45-
printf ("\n");
46-
4742
printf ("#endif /* TARG_VALS_H */\n");
4843
}
4944

@@ -78,6 +73,7 @@ gen_targ_map_c (void)
7873
printf ("CB_TARGET_DEFS_MAP cb_init_open_map[] = {\n");
7974
for (t = &open_tdefs[0]; t->symbol; ++t)
8075
{
76+
printf ("#define TARGET_%s 0x%x\n", t->symbol, t->value);
8177
printf ("#ifdef %s\n", t->symbol);
8278
printf (" { \"%s\", %s, TARGET_%s },\n", t->symbol, t->symbol, t->symbol);
8379
printf ("#endif\n");

0 commit comments

Comments
 (0)