Skip to content

Commit 8a858c1

Browse files
committedJan 29, 2020
SCP: Clean up WEAK definition and rework deprecated references to sim_vm_init
As discussed in simh#794
1 parent ca4b733 commit 8a858c1

32 files changed

+59
-51
lines changed
 

‎AltairZ80/altairz80_cpu.c

+4-3
Original file line numberDiff line numberDiff line change
@@ -6159,7 +6159,10 @@ static t_stat sim_instr_mmu (void) {
61596159

61606160
static t_stat cpu_reset(DEVICE *dptr) {
61616161
int32 i;
6162-
sim_vm_is_subroutine_call = cpu_is_pc_a_subroutine_call;
6162+
if (sim_vm_is_subroutine_call == NULL) { /* First time reset? */
6163+
sim_vm_is_subroutine_call = cpu_is_pc_a_subroutine_call;
6164+
altairz80_init();
6165+
}
61636166
AF_S = AF1_S = 0;
61646167
BC_S = DE_S = HL_S = 0;
61656168
BC1_S = DE1_S = HL1_S = 0;
@@ -6802,8 +6805,6 @@ void altairz80_init(void) {
68026805
/* altairz80_print_tables(); */
68036806
}
68046807

6805-
WEAK void (*sim_vm_init) (void) = &altairz80_init;
6806-
68076808
/* This is the binary loader. The input file is considered to be a string of
68086809
literal bytes with no special format. The load starts at the current value
68096810
of the PC if no start address is given. If the input string ends with ROM

‎HP2100/hp2100_sys.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -1874,7 +1874,7 @@ char sim_name [] = "HP 2100"; /* the simulator name */
18741874

18751875
int32 sim_emax = MAX_INSTR_LENGTH; /* the maximum number of words in any instruction */
18761876

1877-
void (*sim_vm_init) (void) = &one_time_init; /* a pointer to the one-time initializer */
1877+
WEAK void (*sim_vm_init) (void) = &one_time_init; /* a pointer to the one-time initializer */
18781878

18791879
DEVICE *sim_devices [] = { /* an array of pointers to the simulated devices */
18801880
&cpu_dev, /* CPU (must be first) */

‎HP3000/hp3000_sys.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -1072,7 +1072,7 @@ char sim_name [] = "HP 3000"; /* the simulator name */
10721072

10731073
int32 sim_emax = 2; /* the maximum number of words in any instruction */
10741074

1075-
void (*sim_vm_init) (void) = &one_time_init; /* a pointer to the one-time initializer */
1075+
WEAK void (*sim_vm_init) (void) = &one_time_init; /* a pointer to the one-time initializer */
10761076

10771077
DEVICE *sim_devices [] = { /* an array of pointers to the simulated devices */
10781078
&cpu_dev, /* CPU (must be first) */

‎I650/i650_defs.h

+1
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ extern int IAS_TimingRing;
5757
extern int WriteAddr(int AR, t_int64 d, int NegZero);
5858
extern int ReadAddr(int AR, t_int64 * d, int * NegZero);
5959
extern CONST char * DecodeOpcode(t_int64 d, int * opcode, int * DA, int * IA);
60+
extern void vm_init(void);
6061

6162

6263
/* digits contants */

‎I650/i650_sys.c

+5-2
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,11 @@ uint16 ascii_to_hol[128] = {
177177
void
178178
vm_init(void) {
179179
int i;
180+
static int initialized = 0;
181+
182+
if (initialized)
183+
return;
184+
initialized = 1;
180185
// Initialize vm memory to all plus zero
181186
for(i = 0; i < MAXDRUMSIZE; i++) DRUM[i] = DRUM_NegativeZeroFlag[i] = 0;
182187
for(i = 0; i < 60; i++) IAS[i] = IAS_NegativeZeroFlag[i] = 0;
@@ -186,8 +191,6 @@ vm_init(void) {
186191
}
187192

188193

189-
void (*sim_vm_init) (void) = &vm_init;
190-
191194
/* Load a card image file into memory. */
192195

193196
t_stat

‎I7000/i701_cpu.c

+3
Original file line numberDiff line numberDiff line change
@@ -764,6 +764,9 @@ sim_instr(void)
764764
t_stat
765765
cpu_reset(DEVICE * dptr)
766766
{
767+
extern void sys_init(void);
768+
769+
sys_init();
767770
AC = 0;
768771
MQ = 0;
769772
dualcore = 0;

‎I7000/i701_sys.c

-2
Original file line numberDiff line numberDiff line change
@@ -301,8 +301,6 @@ void sys_init(void) {
301301
sim_vm_parse_addr = &parse_addr;
302302
}
303303

304-
void (*sim_vm_init) (void) = &sys_init;
305-
306304
/* Symbolic decode
307305
308306
Inputs:

‎I7000/i7070_cpu.c

+6-1
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,6 @@ int cycle_time = 20; /* Cycle time of 12us */
132132
int32 hst_p = 0; /* History pointer */
133133
int32 hst_lnt = 0; /* History length */
134134
struct InstHistory *hst = NULL; /* History stack */
135-
void (*sim_vm_init) (void) = &mem_init;
136135

137136

138137
/* CPU data structures
@@ -2775,6 +2774,12 @@ mem_init() {
27752774
t_stat
27762775
cpu_reset(DEVICE * dptr)
27772776
{
2777+
static int initialized = 0;
2778+
2779+
if (initialized == 0) {
2780+
initialized = 1;
2781+
mem_init();
2782+
}
27782783

27792784
AC[1] = PSIGN;
27802785
AC[2] = PSIGN;

‎I7000/i7080_cpu.c

+6-1
Original file line numberDiff line numberDiff line change
@@ -231,7 +231,6 @@ int32 hst_lnt = 0; /* History length */
231231
struct InstHistory *hst = NULL; /* History stack */
232232
extern uint32 drum_addr;
233233
extern UNIT chan_unit[];
234-
void (*sim_vm_init) (void) = &mem_init;
235234

236235

237236
/* CPU data structures
@@ -3174,6 +3173,12 @@ cpu_reset(DEVICE * dptr)
31743173
{
31753174
int i;
31763175
int n,p,h;
3176+
static int initialized;
3177+
3178+
if (initialized == 0) {
3179+
initialized = 1;
3180+
mem_init();
3181+
}
31773182

31783183
/* Set next and previous address arrays based on CPU type */
31793184
if (CPU_MODEL == CPU_702) {

‎Ibm1130/ibm1130_cpu.c

+1-3
Original file line numberDiff line numberDiff line change
@@ -162,9 +162,6 @@ static void cgi_start(void);
162162
static void cgi_stop(t_stat reason);
163163
static int simh_status_to_stopcode (int status);
164164

165-
/* hook pointers from scp.c */
166-
void (*sim_vm_init) (void) = &sim_init;
167-
168165
/* space to store extra simulator-specific commands */
169166
#define MAX_EXTRA_COMMANDS 10
170167
CTAB x_cmds[MAX_EXTRA_COMMANDS];
@@ -1317,6 +1314,7 @@ void break_simulation (t_stat stopreason)
13171314

13181315
t_stat cpu_reset (DEVICE *dptr)
13191316
{
1317+
sim_init();
13201318
wait_state = 0; /* cancel wait */
13211319
wait_lamp = TRUE; /* but keep the wait lamp lit on the GUI */
13221320

‎PDQ-3/pdq3_cpu.c

+3-1
Original file line numberDiff line numberDiff line change
@@ -343,7 +343,9 @@ void cpu_finishAutoload() {
343343

344344
/* CPU reset */
345345
t_stat cpu_reset (DEVICE *dptr) {
346-
// sim_printf("CPU RESET\n");
346+
extern void pdq3_vm_init (void);
347+
pdq3_vm_init();
348+
// sim_printf("CPU RESET\n");
347349
sim_brk_types = SWMASK('E')|SWMASK('R')|SWMASK('W');
348350
sim_brk_dflt = SWMASK('E');
349351

‎PDQ-3/pdq3_sys.c

-3
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@
3434
#include <ctype.h>
3535

3636
t_stat parse_sym_m (char *cptr, t_value *val, int32 sw);
37-
void pdq3_vm_init (void);
3837
static t_stat pdq3_cmd_exstack(int32 arg, CONST char *buf);
3938
static t_stat pdq3_cmd_exmscw(int32 arg, CONST char *buf);
4039
static t_stat pdq3_cmd_extib(int32 arg, CONST char *buf);
@@ -94,8 +93,6 @@ CTAB pdq3_cmds[] = {
9493
{ NULL, NULL, 0, NULL }
9594
};
9695

97-
WEAK void (*sim_vm_init)(void) = &pdq3_vm_init;
98-
9996
/* Loader proper */
10097
t_stat sim_load (FILE *fi, CONST char *cptr, CONST char *fnam, int flag)
10198
{

‎SAGE/m68k_scp.c

+1-4
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@
3131
#include <ctype.h>
3232

3333
static t_bool symtrace = TRUE;
34-
static void m68k_sim_init(void);
3534
static t_stat hdump_cmd(int32 arg, CONST char* buf);
3635
static t_stat symset_cmd(int32 arg, CONST char* buf);
3736
static t_stat symclr_cmd(int32 arg, CONST char* buf);
@@ -56,8 +55,6 @@ static CTAB m68k_sim_cmds[] = {
5655
{0,0,0,0}
5756
};
5857

59-
WEAK void (*sim_vm_init)(void) = &m68k_sim_init;
60-
6158
typedef struct _symhash {
6259
struct _symhash* nnext;
6360
struct _symhash* vnext;
@@ -87,7 +84,7 @@ static void sym_clearall(void)
8784
return;
8885
}
8986

90-
static void m68k_sim_init(void)
87+
void m68k_sim_init(void)
9188
{
9289
int i;
9390
sim_vm_cmd = m68k_sim_cmds;

‎SAGE/sage_cpu.c

+4
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,10 @@ static void sage_trapcallback(DEVICE* dptr,int trapnum)
130130
static t_stat sagecpu_reset(DEVICE* dptr)
131131
{
132132
t_stat rc;
133+
extern void m68k_sim_init(void);
134+
135+
136+
m68k_sim_init();
133137

134138
/* set CPU pointers */
135139
m68kcpu_dev = &sagecpu_dev;

‎VAX/is1000_syslist.c

-2
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,6 @@ void vax_init(void)
3434
sim_savename = "InfoServer 1000";
3535
}
3636

37-
WEAK void (*sim_vm_init) (void) = &vax_init;
38-
3937
extern DEVICE cpu_dev;
4038
extern DEVICE tlb_dev;
4139
extern DEVICE rom_dev;

‎VAX/vax410_syslist.c

-2
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,6 @@ void vax_init(void)
3434
sim_savename = "MicroVAX 2000 (KA410)";
3535
}
3636

37-
WEAK void (*sim_vm_init) (void) = &vax_init;
38-
3937
extern DEVICE cpu_dev;
4038
extern DEVICE tlb_dev;
4139
extern DEVICE rom_dev;

‎VAX/vax420_syslist.c

-2
Original file line numberDiff line numberDiff line change
@@ -58,8 +58,6 @@ sim_savename = "VAXstation 3100 M38 (KA42-B)";
5858
#endif
5959
}
6060

61-
WEAK void (*sim_vm_init) (void) = &vax_init;
62-
6361
extern DEVICE cpu_dev;
6462
extern DEVICE tlb_dev;
6563
extern DEVICE rom_dev;

‎VAX/vax43_syslist.c

-2
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,6 @@ void vax_init(void)
3434
sim_savename = "VAXstation 3100 M76 (KA43-A)";
3535
}
3636

37-
WEAK void (*sim_vm_init) (void) = &vax_init;
38-
3937
extern DEVICE cpu_dev;
4038
extern DEVICE tlb_dev;
4139
extern DEVICE rom_dev;

‎VAX/vax440_syslist.c

-2
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,6 @@ sim_savename = "VAXstation 4000-VLC (KA48)";
4646
#endif
4747
}
4848

49-
WEAK void (*sim_vm_init) (void) = &vax_init;
50-
5149
extern DEVICE cpu_dev;
5250
extern DEVICE tlb_dev;
5351
extern DEVICE rom_dev;

‎VAX/vax610_syslist.c

-2
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,6 @@ void vax_init(void)
3636
sim_savename = "MicroVAX I (KA610)";
3737
}
3838

39-
WEAK void (*sim_vm_init) (void) = &vax_init;
40-
4139
extern DEVICE cpu_dev;
4240
extern DEVICE mctl_dev;
4341
extern DEVICE tlb_dev;

‎VAX/vax630_syslist.c

-2
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,6 @@ sim_savename = "MicroVAX II (KA630)";
4545
}
4646
#endif
4747

48-
WEAK void (*sim_vm_init) (void) = &vax_init;
49-
5048
extern DEVICE cpu_dev;
5149
extern DEVICE tlb_dev;
5250
extern DEVICE rom_dev;

‎VAX/vax730_syslist.c

+5
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,11 @@
3131

3232
char sim_name[] = "VAX 11/730";
3333

34+
void vax_init(void)
35+
{
36+
sim_savename = "VAX730";
37+
}
38+
3439
extern DEVICE cpu_dev;
3540
extern DEVICE tlb_dev;
3641
extern DEVICE sysb_dev;

‎VAX/vax750_syslist.c

+5
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,11 @@
3131

3232
char sim_name[] = "VAX 11/750";
3333

34+
void vax_init(void)
35+
{
36+
sim_savename = "VAX750";
37+
}
38+
3439
extern DEVICE cpu_dev;
3540
extern DEVICE tlb_dev;
3641
extern DEVICE cmi_dev;

‎VAX/vax780_syslist.c

-2
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,6 @@ void vax_init(void)
3636
sim_savename = "VAX780";
3737
}
3838

39-
WEAK void (*sim_vm_init) (void) = &vax_init;
40-
4139
extern DEVICE cpu_dev;
4240
extern DEVICE tlb_dev;
4341
extern DEVICE sbi_dev;

‎VAX/vax820_syslist.c

-2
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,6 @@ void vax_init(void)
3434
sim_savename = "VAX820";
3535
}
3636

37-
WEAK void (*sim_vm_init) (void) = &vax_init;
38-
3937
extern DEVICE cpu_dev;
4038
extern DEVICE tlb_dev;
4139
extern DEVICE bi_dev;

‎VAX/vax860_syslist.c

-2
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,6 @@ void vax_init(void)
3636
sim_savename = "VAX 8600";
3737
}
3838

39-
WEAK void (*sim_vm_init) (void) = &vax_init;
40-
4139
extern DEVICE cpu_dev;
4240
extern DEVICE tlb_dev;
4341
extern DEVICE abus_dev;

‎VAX/vax_cpu.c

+1
Original file line numberDiff line numberDiff line change
@@ -3315,6 +3315,7 @@ ASTLVL = 4;
33153315
mapen = 0;
33163316
FLUSH_ISTR; /* init I-stream */
33173317
if (M == NULL) { /* first time init? */
3318+
vax_init();
33183319
sim_brk_types = sim_brk_dflt = SWMASK ('E');
33193320
sim_vm_is_subroutine_call = cpu_is_pc_a_subroutine_call;
33203321
sim_clock_precalibrate_commands = vax_clock_precalibrate_commands;

‎VAX/vax_defs.h

+1
Original file line numberDiff line numberDiff line change
@@ -1035,6 +1035,7 @@ extern t_stat cpu_show_instruction_set (FILE *st, UNIT *uptr, int32 val, CONST v
10351035
extern t_stat cpu_set_instruction_set (UNIT *uptr, int32 val, CONST char *cptr, void *desc);
10361036
extern t_stat cpu_help (FILE *st, DEVICE *dptr, UNIT *uptr, int32 flag, const char *cptr);
10371037
extern t_stat cpu_model_help (FILE *st, DEVICE *dptr, UNIT *uptr, int32 flag, const char *cptr);
1038+
extern void vax_init();
10381039
extern const uint32 byte_mask[33];
10391040
extern int32 autcon_enb; /* autoconfig enable */
10401041
extern int32 int_req[IPL_HLVL]; /* intr, IPL 14-17 */

‎VAX/vax_syslist.c

-2
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,6 @@ void vax_init(void)
3737
sim_savename = "VAX";
3838
}
3939

40-
WEAK void (*sim_vm_init) (void) = &vax_init;
41-
4240
extern DEVICE cpu_dev;
4341
extern DEVICE tlb_dev;
4442
extern DEVICE rom_dev;

‎doc/simh.doc

512 Bytes
Binary file not shown.

‎scp.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -417,7 +417,7 @@ extern t_stat parse_sym (CONST char *cptr, t_addr addr, UNIT *uptr, t_value *val
417417
/* The per-simulator init routine is a weak global that defaults to NULL
418418
The other per-simulator pointers can be overrriden by the init routine */
419419

420-
WEAK extern void (*sim_vm_init) (void);
420+
extern void (*sim_vm_init) (void);
421421
extern char *(*sim_vm_read) (char *ptr, int32 size, FILE *stream);
422422
extern void (*sim_vm_post) (t_bool from_scp);
423423
extern CTAB *sim_vm_cmd;

‎sim_defs.h

+10-6
Original file line numberDiff line numberDiff line change
@@ -322,12 +322,16 @@ typedef uint32 t_addr;
322322
#define WEAK __attribute__((weak))
323323
#elif defined(_MSC_VER)
324324
#define WEAK __declspec(selectany)
325-
#else
326-
#define WEAK extern
327-
#endif
328-
#else
329-
#define WEAK
330-
#endif
325+
#else /* !defined(__GNUC__) && !defined(_MSC_VER) */
326+
#define WEAK
327+
#endif /* __GNUC__ */
328+
#else /* !defined(__cplusplus) */
329+
#if defined(__GNUC__)
330+
#define WEAK __attribute__((common))
331+
#else /* !defined(__GNUC__) */
332+
#define WEAK
333+
#endif /* defined(__GNUC__) */
334+
#endif /* defined(__cplusplus) */
331335

332336
/* System independent definitions */
333337

0 commit comments

Comments
 (0)
Please sign in to comment.