~ubuntu-branches/ubuntu/jaunty/spim/jaunty

« back to all changes in this revision

Viewing changes to buttons.c

  • Committer: Bazaar Package Importer
  • Author(s): Fernando Sanchez
  • Date: 2001-01-24 14:05:34 UTC
  • Revision ID: james.westby@ubuntu.com-20010124140534-3le9wmofforjjcd8
Tags: upstream-6.3
ImportĀ upstreamĀ versionĀ 6.3

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* SPIM S20 MIPS simulator.
 
2
   X interface to SPIM
 
3
   (Derived from an earlier work by Alan Siow.)
 
4
 
 
5
   Copyright (C) 1990-2000 by James Larus (larus@cs.wisc.edu).
 
6
   ALL RIGHTS RESERVED.
 
7
 
 
8
   SPIM is distributed under the following conditions:
 
9
 
 
10
     You may make copies of SPIM for your own use and modify those copies.
 
11
 
 
12
     All copies of SPIM must retain my name and copyright notice.
 
13
 
 
14
     You may not sell SPIM or distributed SPIM in conjunction with a
 
15
     commerical product or service without the expressed written consent of
 
16
     James Larus.
 
17
 
 
18
   THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
 
19
   IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
 
20
   WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
 
21
   PURPOSE. */
 
22
 
 
23
 
 
24
/* $Header: /Software/SPIM/src/buttons.c 5     12/24/00 1:37p Larus $
 
25
 */
 
26
 
 
27
#include <X11/Intrinsic.h>
 
28
#include <X11/StringDefs.h>
 
29
#include <X11/Shell.h>
 
30
#include <X11/Xaw/Form.h>
 
31
#include <X11/Xaw/AsciiText.h>
 
32
#include <X11/Xaw/Command.h>
 
33
#include <X11/Xaw/Dialog.h>
 
34
#include <X11/Xaw/Label.h>
 
35
#include <X11/Xaw/MenuButton.h>
 
36
#include <X11/Xaw/SimpleMenu.h>
 
37
#include <X11/Xaw/Sme.h>
 
38
#include <X11/Xaw/SmeBSB.h>
 
39
#include <X11/Xaw/Cardinals.h>
 
40
 
 
41
#include <stdio.h>
 
42
#include <setjmp.h>
 
43
#include <ctype.h>
 
44
 
 
45
#include "spim.h"
 
46
#include "spim-utils.h"
 
47
#include "xspim.h"
 
48
#include "inst.h"
 
49
#include "mem.h"
 
50
#include "reg.h"
 
51
#include "scanner.h"
 
52
#include "sym-tbl.h"
 
53
#include "buttons.h"
 
54
 
 
55
 
 
56
/* Local functions: */
 
57
 
 
58
#ifdef __STDC__
 
59
static void add_breakpoint_action (Widget w, XtPointer client_data,
 
60
                                   XtPointer call_data);
 
61
static void add_clear_button (Widget parent);
 
62
static void add_mode_button (Widget parent);
 
63
static void add_reload_button (Widget parent);
 
64
static void add_print_button (Widget parent);
 
65
static void add_terminal_button (Widget parent);
 
66
static void breakpoint_prompt (Widget button, XtPointer client_data,
 
67
                               XtPointer call_data);
 
68
static void breakpoint_prompt_destroyed (Widget w, XtPointer client_data,
 
69
                                         XtPointer call_data);
 
70
static void clear_program_state_action (Widget w, XtPointer client_data,
 
71
                                        XtPointer call_data);
 
72
static void continue_action (Widget w, XtPointer client_data,
 
73
                             XtPointer call_data);
 
74
static void continue_prompt_destroyed (Widget w, XtPointer client_data,
 
75
                                       XtPointer call_data);
 
76
static void delete_breakpoint_action (Widget w, XtPointer client_data,
 
77
                                      XtPointer call_data);
 
78
static void destroy_popup_prompt (Widget w, XtPointer client_data,
 
79
                                  XtPointer call_data);
 
80
static void help_action (Widget w, XtPointer ignore, XtPointer ignored);
 
81
static void init_stack (char *args);
 
82
static void load_prompt (Widget button, XtPointer client_data,
 
83
                         XtPointer call_data);
 
84
static void load_prompt_destroyed (Widget w, XtPointer client_data,
 
85
                                   XtPointer call_data);
 
86
static void list_breakpoint_action (Widget w, XtPointer client_data,
 
87
                                    XtPointer call_data);
 
88
static void noop (void);
 
89
static void parse_print_value (Widget w, XtPointer client_data,
 
90
                               XtPointer call_data);
 
91
static void parse_set_value (Widget w, XtPointer client_data,
 
92
                             XtPointer call_data);
 
93
static Widget popup_two_field_dialog (Widget button, String name,
 
94
                                      String field1_label, String field1_value,
 
95
                                      String field2_label, String field2_value,
 
96
                                      String action_name,
 
97
                                      void (*action) (/* ??? */),
 
98
                                      String action2_name,
 
99
                                      void (*action2) (/* ??? */),
 
100
                                      Widget *field1_text,
 
101
                                      Widget *field2_text);
 
102
static void print_mem_prompt (Widget button, XtPointer client_data,
 
103
                              XtPointer call_data);
 
104
static void print_prompt_destroyed (Widget w, XtPointer client_data,
 
105
                                    XtPointer call_data);
 
106
static void print_symbol_action (Widget w, XtPointer client_data,
 
107
                                 XtPointer call_data);
 
108
static void quit_action (Widget w, XtPointer client_data,XtPointer call_data);
 
109
static void quit_prompt (Widget button, XtPointer client_data,
 
110
                         XtPointer call_data);
 
111
static void quit_prompt_destroyed (Widget w, XtPointer client_data,
 
112
                                   XtPointer call_data);
 
113
static void read_assm_file_action (Widget w, XtPointer client_data,
 
114
                                   XtPointer call_data);
 
115
static void reload_action (Widget w, XtPointer client_data,
 
116
                           XtPointer call_data);
 
117
static void run_program_action (Widget w, XtPointer client_data,
 
118
                                XtPointer call_data);
 
119
static void run_prompt (Widget button, XtPointer client_data,
 
120
                        XtPointer call_data);
 
121
static void run_prompt_destroyed (Widget w, XtPointer client_data,
 
122
                                  XtPointer call_data);
 
123
static void select_mode_action (Widget w, XtPointer client_data,
 
124
                                XtPointer call_data);
 
125
static void set_value_action (char *location_str,char *value_str);
 
126
static void set_value_prompt (Widget button, XtPointer client_data,
 
127
                              XtPointer call_data);
 
128
static void set_value_destroyed (Widget w, XtPointer client_data,
 
129
                                 XtPointer call_data);
 
130
static void step_continue_action (Widget w, XtPointer client_data,
 
131
                                  XtPointer call_data);
 
132
static void step_program_action (Widget w, XtPointer client_data,
 
133
                                 XtPointer call_data);
 
134
static void step_prompt (Widget button, XtPointer client_data,
 
135
                         XtPointer call_data);
 
136
static void step_prompt_destroyed (Widget w, XtPointer client_data,
 
137
                                   XtPointer call_data);
 
138
static void warp_to_second_dialog (Widget widget, XEvent *event,
 
139
                                   String *params, Cardinal *num_params);
 
140
 
 
141
#else
 
142
 
 
143
static void add_breakpoint_action ();
 
144
static void add_clear_button ();
 
145
static void add_mode_button ();
 
146
static void add_print_button ();
 
147
static void add_reload_button ();
 
148
static void add_terminal_button ();
 
149
static void breakpoint_prompt ();
 
150
static void breakpoint_prompt_destroyed ();
 
151
static void clear_program_state_action ();
 
152
static void continue_action ();
 
153
static void continue_prompt_destroyed ();
 
154
static void delete_breakpoint_action ();
 
155
static void destroy_popup_prompt ();
 
156
static void help_action ();
 
157
static void init_stack ();
 
158
static void load_prompt ();
 
159
static void load_prompt_destroyed ();
 
160
static void list_breakpoint_action ();
 
161
static void noop ();
 
162
static void parse_print_value ();
 
163
static void parse_set_value ();
 
164
static Widget popup_two_field_dialog ();
 
165
static void print_mem_prompt ();
 
166
static void print_prompt_destroyed ();
 
167
static void print_symbol_action ();
 
168
static void quit_action ();
 
169
static void quit_prompt ();
 
170
static void quit_prompt_destroyed ();
 
171
static void read_assm_file_action ();
 
172
static void reload_action ();
 
173
static void run_program_action ();
 
174
static void run_prompt ();
 
175
static void run_prompt_destroyed ();
 
176
static void select_mode_action ();
 
177
static void set_value_action ();
 
178
static void set_value_prompt ();
 
179
static void set_value_destroyed ();
 
180
static void step_continue_action ();
 
181
static void step_program_action ();
 
182
static void step_prompt ();
 
183
static void step_prompt_destroyed ();
 
184
static void warp_to_second_dialog ();
 
185
 
 
186
#endif
 
187
 
 
188
/* Local variables: */
 
189
 
 
190
static Widget breakpointButton;
 
191
static void (*confirmAction) () = noop;
 
192
static int stack_initialized = 0;
 
193
char *xspim_file_name = NULL;   /* Retain last file's name. */
 
194
 
 
195
 
 
196
 
 
197
#ifdef __STDC__
 
198
void
 
199
record_file_name_for_prompt (char *name)
 
200
#else
 
201
void
 
202
record_file_name_for_prompt (name)
 
203
     char *name;
 
204
#endif
 
205
{
 
206
  xspim_file_name = str_copy (name);
 
207
}
 
208
 
 
209
 
 
210
#ifdef __STDC__
 
211
void
 
212
create_buttons (Widget parent)
 
213
#else
 
214
void
 
215
create_buttons (parent)
 
216
     Widget parent;
 
217
#endif
 
218
{
 
219
  Widget button;
 
220
  Widget command;
 
221
  Arg args[10];
 
222
 
 
223
 
 
224
  XtSetArg (args[0], XtNlabel, "quit");
 
225
  XtSetArg (args[1], XtNwidth, button_width);
 
226
  button = XtCreateManagedWidget ("quitbutton", commandWidgetClass, parent,
 
227
                                  args, TWO);
 
228
  XtAddCallback (button, XtNcallback, quit_prompt, NULL);
 
229
 
 
230
 
 
231
  XtSetArg (args[0], XtNlabel, "load");
 
232
  XtSetArg (args[1], XtNwidth, button_width);
 
233
  command = XtCreateManagedWidget ("loadbutton", commandWidgetClass, parent,
 
234
                                   args, TWO);
 
235
  XtAddCallback (command, XtNcallback, load_prompt, NULL);
 
236
 
 
237
 
 
238
  add_reload_button (parent);
 
239
 
 
240
 
 
241
  XtSetArg (args[0], XtNlabel, "run");
 
242
  XtSetArg (args[1], XtNwidth, button_width);
 
243
  button = XtCreateManagedWidget ("runbutton", commandWidgetClass, parent,
 
244
                                  args, TWO);
 
245
  XtAddCallback (button, XtNcallback, run_prompt, NULL);
 
246
 
 
247
 
 
248
  XtSetArg (args[0], XtNlabel, "step");
 
249
  XtSetArg (args[1], XtNwidth, button_width);
 
250
  button = XtCreateManagedWidget ("stepbutton", commandWidgetClass, parent,
 
251
                                  args, TWO);
 
252
  XtAddCallback (button, XtNcallback, step_prompt, NULL);
 
253
 
 
254
 
 
255
  add_clear_button (parent);
 
256
 
 
257
 
 
258
  XtSetArg (args[0], XtNlabel, "set value");
 
259
  XtSetArg (args[1], XtNwidth, button_width);
 
260
  button = XtCreateManagedWidget ("setvaluebutton", commandWidgetClass, parent,
 
261
                                  args, TWO);
 
262
  XtAddCallback (button, XtNcallback, set_value_prompt, NULL);
 
263
 
 
264
 
 
265
  add_print_button (parent);
 
266
 
 
267
 
 
268
  XtSetArg (args[0], XtNlabel, "breakpoints");
 
269
  XtSetArg (args[1], XtNwidth, button_width);
 
270
  button = XtCreateManagedWidget ("bkptbutton", commandWidgetClass, parent,
 
271
                                  args, TWO);
 
272
  breakpointButton = button;
 
273
  XtAddCallback (button, XtNcallback, breakpoint_prompt, NULL);
 
274
 
 
275
 
 
276
  XtSetArg (args[0], XtNlabel, "help");
 
277
  XtSetArg (args[1], XtNwidth, button_width);
 
278
  button = XtCreateManagedWidget ("helpbutton", commandWidgetClass, parent,
 
279
                                  args, TWO);
 
280
  XtAddCallback (button, XtNcallback, help_action, NULL);
 
281
 
 
282
 
 
283
  add_terminal_button (parent);
 
284
 
 
285
 
 
286
  add_mode_button (parent);
 
287
}
 
288
 
 
289
 
 
290
 
 
291
/* *** Quit *** */
 
292
 
 
293
static Widget quit_popup = NULL;
 
294
 
 
295
#ifdef __STDC__
 
296
static void
 
297
quit_prompt (Widget button, XtPointer client_data, XtPointer call_data)
 
298
#else
 
299
static void
 
300
quit_prompt (button, client_data, call_data)
 
301
     Widget button;
 
302
     XtPointer client_data, call_data;
 
303
#endif
 
304
{
 
305
  Widget parent, dialog;
 
306
  Arg args[10];
 
307
  Position x, y;
 
308
 
 
309
  if (quit_popup == NULL)
 
310
    {
 
311
      parent = XtParent (button);
 
312
 
 
313
      XtTranslateCoords (button, (Position) 0, (Position) 0, &x, &y);
 
314
      XtSetArg (args[0], XtNx, x);
 
315
      XtSetArg (args[1], XtNy, y);
 
316
      quit_popup = XtCreatePopupShell ("prompt", transientShellWidgetClass,
 
317
                                       parent, args, TWO);
 
318
      XtAddCallback (quit_popup, XtNdestroyCallback, quit_prompt_destroyed,
 
319
                     (XtPointer) 0);
 
320
 
 
321
      XtSetArg (args[0], XtNlabel, "quit?");
 
322
      dialog = XtCreateManagedWidget ("quit", dialogWidgetClass, quit_popup,
 
323
                                      args, ONE);
 
324
 
 
325
      XawDialogAddButton (dialog, "quit", quit_action, (XtPointer) dialog);
 
326
      XawDialogAddButton (dialog, "abort command", destroy_popup_prompt,
 
327
                          (XtPointer) dialog);
 
328
 
 
329
    }
 
330
  confirmAction = quit_action;
 
331
  XtPopup (quit_popup, XtGrabNone);
 
332
}
 
333
 
 
334
 
 
335
#ifdef __STDC__
 
336
static void
 
337
quit_action (Widget w, XtPointer client_data, XtPointer call_data)
 
338
#else
 
339
static void
 
340
quit_action (w, client_data, call_data)
 
341
     Widget w;
 
342
     XtPointer client_data, call_data;
 
343
#endif
 
344
{
 
345
  Widget dialog = (Widget) client_data;
 
346
 
 
347
  destroy_popup_prompt (NULL, (XtPointer) dialog, (XtPointer) NULL);
 
348
  XtDestroyApplicationContext (XtWidgetToApplicationContext (w));
 
349
  exit (0);
 
350
}
 
351
 
 
352
 
 
353
#ifdef __STDC__
 
354
static void
 
355
quit_prompt_destroyed (Widget w, XtPointer client_data, XtPointer call_data)
 
356
#else
 
357
static void
 
358
quit_prompt_destroyed (w, client_data, call_data)
 
359
     Widget w;
 
360
     XtPointer client_data, call_data;
 
361
#endif
 
362
{
 
363
  quit_popup = NULL;
 
364
}
 
365
 
 
366
 
 
367
/* *** Load *** */
 
368
 
 
369
static Widget load_popup = NULL;
 
370
 
 
371
#ifdef __STDC__
 
372
static void
 
373
load_prompt (Widget button, XtPointer client_data, XtPointer call_data)
 
374
#else
 
375
static void
 
376
load_prompt (button, client_data, call_data)
 
377
     Widget button;
 
378
     XtPointer client_data, call_data;
 
379
#endif
 
380
{
 
381
  Widget parent, dialog;
 
382
  Arg args[10];
 
383
  Position x, y;
 
384
 
 
385
  if (load_popup == NULL)
 
386
    {
 
387
      parent = XtParent (button);
 
388
 
 
389
      XtTranslateCoords (button, (Position) 0, (Position) 0, &x, &y);
 
390
      XtSetArg (args[0], XtNx, x);
 
391
      XtSetArg (args[1], XtNy, y);
 
392
      load_popup = XtCreatePopupShell ("popup", transientShellWidgetClass,
 
393
                                      parent, args, TWO);
 
394
      XtAddCallback (load_popup, XtNdestroyCallback, load_prompt_destroyed,
 
395
                     (XtPointer) 0);
 
396
 
 
397
      if (xspim_file_name == NULL)
 
398
        xspim_file_name = str_copy ("");
 
399
      XtSetArg (args[0], XtNlabel, "input filename:");
 
400
      XtSetArg (args[1], XtNvalue, xspim_file_name);
 
401
      dialog = XtCreateManagedWidget ("dialog", dialogWidgetClass, load_popup,
 
402
                                      args, TWO);
 
403
 
 
404
      XawDialogAddButton (dialog, "assembly file", read_assm_file_action,
 
405
                          (XtPointer) dialog);
 
406
      XawDialogAddButton (dialog, "abort command", destroy_popup_prompt,
 
407
                          (XtPointer) dialog);
 
408
    }
 
409
 
 
410
  confirmAction =  read_assm_file_action;
 
411
  XtPopup (load_popup, XtGrabNone);
 
412
}
 
413
 
 
414
 
 
415
#ifdef __STDC__
 
416
static void
 
417
read_assm_file_action (Widget w, XtPointer client_data, XtPointer call_data)
 
418
#else
 
419
static void
 
420
read_assm_file_action (w, client_data, call_data)
 
421
     Widget w;
 
422
     XtPointer client_data, call_data;
 
423
#endif
 
424
{
 
425
  Widget dialog = (Widget) client_data;
 
426
  String value = XawDialogGetValueString (dialog);
 
427
 
 
428
  free (xspim_file_name);
 
429
  xspim_file_name = str_copy (value);
 
430
  read_file (value, 1);
 
431
 
 
432
  destroy_popup_prompt (NULL, (XtPointer) dialog, (XtPointer) NULL);
 
433
}
 
434
 
 
435
 
 
436
#ifdef __STDC__
 
437
static void
 
438
load_prompt_destroyed (Widget w, XtPointer client_data, XtPointer call_data)
 
439
#else
 
440
static void
 
441
load_prompt_destroyed (w, client_data, call_data)
 
442
     Widget w;
 
443
     XtPointer client_data, call_data;
 
444
#endif
 
445
{
 
446
  load_popup = NULL;
 
447
}
 
448
 
 
449
 
 
450
/* *** Run *** */
 
451
 
 
452
static Widget run_popup = NULL;
 
453
static Widget run_field1_text, run_field2_text;
 
454
 
 
455
#ifdef __STDC__
 
456
static void
 
457
run_prompt (Widget button, XtPointer client_data, XtPointer call_data)
 
458
#else
 
459
static void
 
460
run_prompt (button, client_data, call_data)
 
461
     Widget button;
 
462
     XtPointer client_data, call_data;
 
463
#endif
 
464
{
 
465
  char sa[20];
 
466
 
 
467
  if (run_popup == NULL)
 
468
    {
 
469
      sprintf (sa, "0x%08x", starting_address ());
 
470
      run_popup = popup_two_field_dialog (button, "run program",
 
471
                                         "starting address:", sa,
 
472
                                         "args:", xspim_file_name,
 
473
                                         "ok", run_program_action,
 
474
                                         NULL, NULL,
 
475
                                         &run_field1_text, &run_field2_text);
 
476
      XtAddCallback (run_popup, XtNdestroyCallback, run_prompt_destroyed,
 
477
                     (XtPointer) 0);
 
478
    }
 
479
  confirmAction =  run_program_action;
 
480
  XtPopup (run_popup, XtGrabNone);
 
481
}
 
482
 
 
483
 
 
484
#ifdef __STDC__
 
485
static void
 
486
run_program_action (Widget w, XtPointer client_data, XtPointer call_data)
 
487
#else
 
488
static void
 
489
run_program_action (w, client_data, call_data)
 
490
     Widget w;
 
491
     XtPointer client_data, call_data;
 
492
#endif
 
493
{
 
494
  Arg args[10];
 
495
  String value1, value2;
 
496
  Widget form = XtParent (w);
 
497
  mem_addr addr;
 
498
 
 
499
  XtSetArg (args[0], XtNstring, &value1);
 
500
  XtGetValues (run_field1_text, args, ONE);
 
501
 
 
502
  XtSetArg (args[0], XtNstring, &value2);
 
503
  XtGetValues (run_field2_text, args, ONE);
 
504
 
 
505
  destroy_popup_prompt (NULL, (XtPointer) form, NULL);
 
506
 
 
507
  init_stack (value2);
 
508
  addr = strtoul (value1, NULL, 0);
 
509
  if (addr > 0)
 
510
    start_program (addr);
 
511
}
 
512
 
 
513
 
 
514
#ifdef __STDC__
 
515
static void
 
516
init_stack (char *args)
 
517
#else
 
518
static void
 
519
init_stack (args)
 
520
     char *args;
 
521
#endif
 
522
{
 
523
  int argc = 0;
 
524
  char *argv[10000];
 
525
  char *a;
 
526
 
 
527
  if (stack_initialized)
 
528
    return;
 
529
  while (*args != '\0')
 
530
    {
 
531
      /* Skip leading blanks */
 
532
      while (*args == ' ' || *args == '\t') args++;
 
533
      /* First non-blank char */
 
534
      a = args;
 
535
      /* Last non-blank, non-null char */
 
536
      while (*args != ' ' && *args != '\t' && *args != '\0') args++;
 
537
      /* Terminate word */
 
538
      if (a != args)
 
539
        {
 
540
          if (*args != '\0')
 
541
            *args++ = '\0';     /* Null terminate */
 
542
          argv [argc++] = a;
 
543
        }
 
544
    }
 
545
  initialize_run_stack (argc, argv);
 
546
  stack_initialized = 1;
 
547
}
 
548
 
 
549
 
 
550
#ifdef __STDC__
 
551
static void
 
552
run_prompt_destroyed (Widget w, XtPointer client_data, XtPointer call_data)
 
553
#else
 
554
static void
 
555
run_prompt_destroyed (w, client_data, call_data)
 
556
     Widget w;
 
557
     XtPointer client_data, call_data;
 
558
#endif
 
559
{
 
560
  run_popup = NULL;
 
561
}
 
562
 
 
563
 
 
564
/* *** Step *** */
 
565
 
 
566
static char *step_size = NULL;  /* Retain step size */
 
567
 
 
568
static Widget step_popup = NULL;
 
569
static Widget step_field1_text, step_field2_text;
 
570
 
 
571
#ifdef __STDC__
 
572
static void
 
573
step_prompt (Widget button, XtPointer client_data, XtPointer call_data)
 
574
#else
 
575
static void
 
576
step_prompt (button, client_data, call_data)
 
577
     Widget button;
 
578
     XtPointer client_data, call_data;
 
579
#endif
 
580
{
 
581
  if (step_popup == NULL)
 
582
    {
 
583
      if (step_size == NULL)
 
584
        step_size = str_copy ("1");
 
585
      step_popup = popup_two_field_dialog (button, "step program",
 
586
                                          "number of steps:", step_size,
 
587
                                          "args:", xspim_file_name,
 
588
                                          "step", step_program_action,
 
589
                                          "continue", step_continue_action,
 
590
                                          &step_field1_text,
 
591
                                          &step_field2_text);
 
592
      XtAddCallback (step_popup, XtNdestroyCallback, step_prompt_destroyed,
 
593
                     (XtPointer) 0);
 
594
    }
 
595
  confirmAction =  step_program_action;
 
596
  XtPopup (step_popup, XtGrabNone);
 
597
}
 
598
 
 
599
 
 
600
#ifdef __STDC__
 
601
static void
 
602
step_program_action (Widget w, XtPointer client_data, XtPointer call_data)
 
603
#else
 
604
static void
 
605
step_program_action (w, client_data, call_data)
 
606
     Widget w;
 
607
     XtPointer client_data, call_data;
 
608
#endif
 
609
{
 
610
  Arg args[10];
 
611
  String value1, value2;
 
612
  mem_addr addr;
 
613
  int steps;
 
614
 
 
615
  XtSetArg (args[0], XtNstring, &value1);
 
616
  XtGetValues (step_field1_text, args, ONE);
 
617
 
 
618
  XtSetArg (args[0], XtNstring, &value2);
 
619
  XtGetValues (step_field2_text, args, ONE);
 
620
 
 
621
  steps = atoi (value1);
 
622
  free (step_size);
 
623
  step_size = str_copy (value1);
 
624
  addr = starting_address ();
 
625
  init_stack (value2);
 
626
  if (steps > 0 && addr > 0)
 
627
    execute_program (addr, steps, 1, 1);
 
628
  else
 
629
    error ("Cannot step %d steps from 0x%x\n", steps, addr);
 
630
}
 
631
 
 
632
 
 
633
#ifdef __STDC__
 
634
static void
 
635
step_continue_action (Widget w, XtPointer client_data, XtPointer call_data)
 
636
#else
 
637
static void
 
638
step_continue_action (w, client_data, call_data)
 
639
     Widget w;
 
640
     XtPointer client_data, call_data;
 
641
#endif
 
642
{
 
643
  Widget dialog = (Widget) client_data;
 
644
 
 
645
  XtPopdown (XtParent (dialog));
 
646
  destroy_popup_prompt (NULL, (XtPointer) dialog, (XtPointer) NULL);
 
647
  step_popup = NULL;
 
648
  execute_program (PC, DEFAULT_RUN_STEPS, 0, 0);
 
649
}
 
650
 
 
651
 
 
652
#ifdef __STDC__
 
653
static void
 
654
step_prompt_destroyed (Widget w, XtPointer client_data, XtPointer call_data)
 
655
#else
 
656
static void
 
657
step_prompt_destroyed (w, client_data, call_data)
 
658
     Widget w;
 
659
     XtPointer client_data, call_data;
 
660
#endif
 
661
{
 
662
  step_popup = NULL;
 
663
}
 
664
 
 
665
 
 
666
/* *** Reload *** */
 
667
 
 
668
#ifdef __STDC__
 
669
static void
 
670
add_reload_button (Widget parent)
 
671
#else
 
672
static void
 
673
add_reload_button (parent)
 
674
     Widget parent;
 
675
#endif
 
676
{
 
677
  Widget command, menu, entry;
 
678
  Arg args[2];
 
679
 
 
680
  XtSetArg (args[0], XtNwidth, button_width);
 
681
  command = XtCreateManagedWidget ("reload", menuButtonWidgetClass,
 
682
                                   parent, args, ONE);
 
683
  menu = XtCreatePopupShell ("menu", simpleMenuWidgetClass, command,
 
684
                             NULL, ZERO);
 
685
 
 
686
  entry = XtCreateManagedWidget ("assembly file", smeBSBObjectClass, menu,
 
687
                                 args, ONE);
 
688
  XtAddCallback (entry, XtNcallback, reload_action,
 
689
                 (XtPointer) 1);
 
690
}
 
691
 
 
692
 
 
693
#ifdef __STDC__
 
694
static void
 
695
reload_action (Widget w, XtPointer client_data, XtPointer call_data)
 
696
#else
 
697
static void
 
698
reload_action (w, client_data, call_data)
 
699
     Widget w;
 
700
     XtPointer client_data, call_data;
 
701
#endif
 
702
{
 
703
  int assem_or_exec = (int) client_data;
 
704
 
 
705
  if (xspim_file_name == NULL)
 
706
    return;
 
707
 
 
708
  write_output (message_out, "Memory and registers cleared\n\n");
 
709
  initialize_world (load_trap_handler ? trap_file : NULL);
 
710
  write_startup_message ();
 
711
  stack_initialized = 0;
 
712
  read_file (xspim_file_name, assem_or_exec);
 
713
}
 
714
 
 
715
 
 
716
 
 
717
/* *** Clear *** */
 
718
 
 
719
#define CLEAR_REGS 1
 
720
#define CLEAR_MEM_REGS 2
 
721
 
 
722
#ifdef __STDC__
 
723
static void
 
724
add_clear_button (Widget parent)
 
725
#else
 
726
static void
 
727
add_clear_button (parent)
 
728
     Widget parent;
 
729
#endif
 
730
{
 
731
  Widget command, menu, entry;
 
732
  Arg args[2];
 
733
 
 
734
  XtSetArg (args[0], XtNwidth, button_width);
 
735
  command = XtCreateManagedWidget ("clear", menuButtonWidgetClass,
 
736
                                   parent, args, ONE);
 
737
  menu = XtCreatePopupShell ("menu", simpleMenuWidgetClass, command,
 
738
                             NULL, ZERO);
 
739
 
 
740
  entry = XtCreateManagedWidget ("registers", smeBSBObjectClass, menu,
 
741
                                 args, ONE);
 
742
  XtAddCallback (entry, XtNcallback, clear_program_state_action,
 
743
                 (XtPointer) CLEAR_REGS);
 
744
 
 
745
  entry = XtCreateManagedWidget ("memory & registers", smeBSBObjectClass, menu,
 
746
                                 args, ONE);
 
747
  XtAddCallback (entry, XtNcallback, clear_program_state_action,
 
748
                 (XtPointer) CLEAR_MEM_REGS);
 
749
}
 
750
 
 
751
 
 
752
#ifdef __STDC__
 
753
static void
 
754
clear_program_state_action (Widget w, XtPointer client_data,
 
755
                            XtPointer call_data)
 
756
#else
 
757
static void
 
758
clear_program_state_action (w, client_data, call_data)
 
759
     Widget w;
 
760
     XtPointer client_data, call_data;
 
761
#endif
 
762
{
 
763
  int clear_op = (int) client_data;
 
764
 
 
765
  switch (clear_op)
 
766
    {
 
767
    case CLEAR_REGS:
 
768
      write_output (message_out, "Registers cleared\n\n");
 
769
      initialize_registers ();
 
770
      break;
 
771
 
 
772
    case CLEAR_MEM_REGS:
 
773
      write_output (message_out, "Memory and registers cleared\n\n");
 
774
      initialize_world (load_trap_handler ? trap_file : NULL);
 
775
      write_startup_message ();
 
776
      stack_initialized = 0;
 
777
      break;
 
778
 
 
779
    default:
 
780
      fatal_error("Unknown action: %d\n", clear_op);
 
781
    }
 
782
 
 
783
  redisplay_text ();
 
784
  redisplay_data ();
 
785
}
 
786
 
 
787
 
 
788
/* *** Set Value *** */
 
789
 
 
790
static Widget set_value_popup = NULL;
 
791
static Widget set_field1_text, set_field2_text;
 
792
 
 
793
#ifdef __STDC__
 
794
static void
 
795
set_value_prompt (Widget button, XtPointer client_data, XtPointer call_data)
 
796
#else
 
797
static void
 
798
set_value_prompt (button, client_data, call_data)
 
799
     Widget button;
 
800
     XtPointer client_data, call_data;
 
801
#endif
 
802
{
 
803
  if (set_value_popup == NULL)
 
804
    {
 
805
      set_value_popup = popup_two_field_dialog (button, "set value",
 
806
                                           "register/location:", "",
 
807
                                           "value:", "",
 
808
                                           "set", parse_set_value,
 
809
                                           NULL, NULL,
 
810
                                           &set_field1_text, &set_field2_text);
 
811
      XtAddCallback (set_value_popup, XtNdestroyCallback,
 
812
                     set_value_destroyed, (XtPointer) 0);
 
813
    }
 
814
  confirmAction = parse_set_value;
 
815
  XtPopup (set_value_popup, XtGrabNone);
 
816
}
 
817
 
 
818
 
 
819
#ifdef __STDC__
 
820
static void
 
821
parse_set_value (Widget w, XtPointer client_data, XtPointer call_data)
 
822
#else
 
823
static void
 
824
parse_set_value (w, client_data, call_data)
 
825
     Widget w;
 
826
     XtPointer client_data, call_data;
 
827
#endif
 
828
{
 
829
  Arg args[10];
 
830
  String value1, value2;
 
831
  Widget form = XtParent (w);
 
832
 
 
833
  XtSetArg (args[0], XtNstring, &value1);
 
834
  XtGetValues (set_field1_text, args, ONE);
 
835
 
 
836
  XtSetArg (args[0], XtNstring, &value2);
 
837
  XtGetValues (set_field2_text, args, ONE);
 
838
 
 
839
  destroy_popup_prompt (NULL, (XtPointer) form, NULL);
 
840
 
 
841
  set_value_action (value1, value2);
 
842
}
 
843
 
 
844
 
 
845
#ifdef __STDC__
 
846
static void
 
847
set_value_action (char *location_str, char *value_str)
 
848
#else
 
849
static void
 
850
set_value_action (location_str, value_str)
 
851
     char *location_str, *value_str;
 
852
#endif
 
853
{
 
854
  unsigned long value;
 
855
  int reg_no;
 
856
 
 
857
  value = strtol (value_str, NULL, 0);
 
858
  reg_no = register_name_to_number (location_str);
 
859
 
 
860
  if (reg_no < 0)
 
861
    if (*location_str == '$' || *location_str == 'r' || *location_str == 'R')
 
862
      reg_no = register_name_to_number (location_str + 1);
 
863
 
 
864
  if (reg_no == 0)
 
865
    error ("Cannot modify register 0\n");
 
866
  else if (reg_no > 0)
 
867
    R[reg_no] = (reg_word)value;
 
868
  else if (streq (location_str, "Status") || streq (location_str, "status"))
 
869
    Status_Reg = (reg_word)value;
 
870
  else if (streq (location_str, "PC") || streq (location_str, "pc"))
 
871
    PC = (reg_word)value;
 
872
  else if (streq (location_str, "EPC") | streq (location_str, "epc"))
 
873
    EPC = (reg_word)value;
 
874
  else
 
875
    {
 
876
      char *eptr;
 
877
      mem_addr addr;
 
878
 
 
879
      /* Try to parse string as a number */
 
880
      addr = strtol (location_str, &eptr, 0);
 
881
      if (eptr == location_str)
 
882
        error ("Unknown register selected: %s\n", location_str);
 
883
      else
 
884
        SET_MEM_WORD (addr, value);
 
885
    }
 
886
  redisplay_data ();
 
887
}
 
888
 
 
889
 
 
890
#ifdef __STDC__
 
891
static void
 
892
set_value_destroyed (Widget w, XtPointer client_data, XtPointer call_data)
 
893
#else
 
894
static void
 
895
set_value_destroyed (w, client_data, call_data)
 
896
     Widget w;
 
897
     XtPointer client_data, call_data;
 
898
#endif
 
899
{
 
900
  set_value_popup = NULL;
 
901
}
 
902
 
 
903
 
 
904
/* *** Print *** */
 
905
 
 
906
#ifdef __STDC__
 
907
static void
 
908
add_print_button (Widget parent)
 
909
#else
 
910
static void
 
911
add_print_button (parent)
 
912
     Widget parent;
 
913
#endif
 
914
{
 
915
  Widget command, menu, entry;
 
916
  Arg args[2];
 
917
 
 
918
  XtSetArg (args[0], XtNwidth, button_width);
 
919
  command = XtCreateManagedWidget ("print", menuButtonWidgetClass,
 
920
                                   parent, args, ONE);
 
921
  menu = XtCreatePopupShell ("menu", simpleMenuWidgetClass, command,
 
922
                             NULL, ZERO);
 
923
 
 
924
  entry = XtCreateManagedWidget ("memory location(s)", smeBSBObjectClass, menu,
 
925
                                 args, ONE);
 
926
  XtAddCallback (entry, XtNcallback, print_mem_prompt, NULL);
 
927
 
 
928
  entry = XtCreateManagedWidget ("global symbols", smeBSBObjectClass, menu,
 
929
                                 args, ONE);
 
930
  XtAddCallback (entry, XtNcallback, print_symbol_action, NULL);
 
931
}
 
932
 
 
933
 
 
934
static Widget print_popup = NULL;
 
935
static Widget print_field1_text, print_field2_text;
 
936
 
 
937
#ifdef __STDC__
 
938
static void
 
939
print_mem_prompt (Widget button, XtPointer client_data, XtPointer call_data)
 
940
#else
 
941
static void
 
942
print_mem_prompt (button, client_data, call_data)
 
943
     Widget button;
 
944
     XtPointer client_data, call_data;
 
945
#endif
 
946
{
 
947
  if (print_popup == NULL)
 
948
    {
 
949
      print_popup = popup_two_field_dialog (XtParent (button), "print memory",
 
950
                                        "from", "",
 
951
                                        "to", "",
 
952
                                        "print", parse_print_value,
 
953
                                        NULL, NULL,
 
954
                                        &print_field1_text,
 
955
                                        &print_field2_text);
 
956
      XtAddCallback (print_popup, XtNdestroyCallback, print_prompt_destroyed,
 
957
                     (XtPointer) 0);
 
958
    }
 
959
  confirmAction = parse_print_value;
 
960
  XtPopup (print_popup, XtGrabNone);
 
961
}
 
962
 
 
963
 
 
964
#ifdef __STDC__
 
965
static void
 
966
parse_print_value (Widget w, XtPointer client_data, XtPointer call_data)
 
967
#else
 
968
static void
 
969
parse_print_value (w, client_data, call_data)
 
970
     Widget w;
 
971
     XtPointer client_data, call_data;
 
972
#endif
 
973
{
 
974
  Arg args[10];
 
975
  String value1, value2;
 
976
  Widget form = XtParent (w);
 
977
 
 
978
  XtSetArg (args[0], XtNstring, &value1);
 
979
  XtGetValues (print_field1_text, args, ONE);
 
980
 
 
981
  XtSetArg (args[0], XtNstring, &value2);
 
982
  XtGetValues (print_field2_text, args, ONE);
 
983
 
 
984
  XtPopdown (XtParent (form));
 
985
  destroy_popup_prompt (NULL, (XtPointer) form, NULL);
 
986
 
 
987
  if (!streq (value1, ""))
 
988
    {
 
989
      mem_addr from, to;
 
990
 
 
991
      from = strtoul (value1, NULL, 0);
 
992
      to = strtoul (value2, NULL, 0);
 
993
      if (streq (value2, ""))
 
994
        print_mem (from);
 
995
      else
 
996
        for ( ; from <= to; from+= BYTES_PER_WORD)
 
997
          print_mem (from);
 
998
    }
 
999
}
 
1000
 
 
1001
 
 
1002
#ifdef __STDC__
 
1003
static void
 
1004
print_symbol_action (Widget w, XtPointer client_data, XtPointer call_data)
 
1005
#else
 
1006
static void
 
1007
print_symbol_action (w, client_data, call_data)
 
1008
     Widget w;
 
1009
     XtPointer client_data, call_data;
 
1010
#endif
 
1011
{
 
1012
  print_symbols ();
 
1013
}
 
1014
 
 
1015
 
 
1016
#ifdef __STDC__
 
1017
static void
 
1018
print_prompt_destroyed (Widget w, XtPointer client_data, XtPointer call_data)
 
1019
#else
 
1020
static void
 
1021
print_prompt_destroyed (w, client_data, call_data)
 
1022
     Widget w;
 
1023
     XtPointer client_data, call_data;
 
1024
#endif
 
1025
{
 
1026
  print_popup = NULL;
 
1027
}
 
1028
 
 
1029
 
 
1030
/* *** Breakpoints **** */
 
1031
 
 
1032
static char *breakpoint_addr = NULL; /* Retain last breakpoint address */
 
1033
 
 
1034
static Widget bkpt_popup = NULL;
 
1035
 
 
1036
#ifdef __STDC__
 
1037
static void
 
1038
breakpoint_prompt (Widget button, XtPointer client_data, XtPointer call_data)
 
1039
#else
 
1040
static void
 
1041
breakpoint_prompt (button, client_data, call_data)
 
1042
     Widget button;
 
1043
     XtPointer client_data, call_data;
 
1044
#endif
 
1045
{
 
1046
  Widget parent, dialog;
 
1047
  Arg args[10];
 
1048
  Position x, y;
 
1049
 
 
1050
  if (bkpt_popup == NULL)
 
1051
    {
 
1052
      parent = XtParent (button);
 
1053
 
 
1054
      XtTranslateCoords (button, (Position) 0, (Position) 0, &x, &y);
 
1055
      XtSetArg (args[0], XtNx, x);
 
1056
      XtSetArg (args[1], XtNy, y);
 
1057
      bkpt_popup = XtCreatePopupShell ("popup", transientShellWidgetClass,
 
1058
                                      parent, args, TWO);
 
1059
 
 
1060
      if (breakpoint_addr == NULL)
 
1061
        breakpoint_addr = str_copy ("");
 
1062
      XtSetArg (args[0], XtNlabel, "address:");
 
1063
      XtSetArg (args[1], XtNvalue, breakpoint_addr);
 
1064
      dialog = XtCreateManagedWidget ("dialog", dialogWidgetClass,
 
1065
                                      bkpt_popup,
 
1066
                                      args, TWO);
 
1067
      XtAddCallback (bkpt_popup, XtNdestroyCallback,
 
1068
                     breakpoint_prompt_destroyed, (XtPointer) 0);
 
1069
 
 
1070
      XawDialogAddButton (dialog, "add",
 
1071
                          add_breakpoint_action, (XtPointer) dialog);
 
1072
      XawDialogAddButton (dialog, "delete",
 
1073
                          delete_breakpoint_action, (XtPointer) dialog);
 
1074
      XawDialogAddButton (dialog, "list",
 
1075
                          list_breakpoint_action, (XtPointer) dialog);
 
1076
      XawDialogAddButton (dialog, "abort command", destroy_popup_prompt,
 
1077
                          (XtPointer) dialog);
 
1078
    }
 
1079
 
 
1080
  confirmAction = add_breakpoint_action;
 
1081
  XtPopup (bkpt_popup, XtGrabNone);
 
1082
}
 
1083
 
 
1084
 
 
1085
#ifdef __STDC__
 
1086
static void
 
1087
add_breakpoint_action (Widget w, XtPointer client_data, XtPointer call_data)
 
1088
#else
 
1089
static void
 
1090
add_breakpoint_action (w, client_data, call_data)
 
1091
     Widget w;
 
1092
     XtPointer client_data, call_data;
 
1093
#endif
 
1094
{
 
1095
  Widget dialog = (Widget) client_data;
 
1096
  String value = XawDialogGetValueString (dialog);
 
1097
  mem_addr addr;
 
1098
 
 
1099
  free (breakpoint_addr);
 
1100
  breakpoint_addr = str_copy (value);
 
1101
 
 
1102
  while (*breakpoint_addr == ' ') breakpoint_addr++;
 
1103
  if (isdigit (*breakpoint_addr))
 
1104
    addr = strtoul (value, NULL, 0);
 
1105
  else
 
1106
    addr = find_symbol_address (breakpoint_addr);
 
1107
 
 
1108
  add_breakpoint (addr);
 
1109
 
 
1110
  destroy_popup_prompt (NULL, (XtPointer) dialog, (XtPointer) NULL);
 
1111
}
 
1112
 
 
1113
 
 
1114
#ifdef __STDC__
 
1115
static void
 
1116
delete_breakpoint_action (Widget w, XtPointer client_data, XtPointer call_data)
 
1117
#else
 
1118
static void
 
1119
delete_breakpoint_action (w, client_data, call_data)
 
1120
     Widget w;
 
1121
     XtPointer client_data, call_data;
 
1122
#endif
 
1123
{
 
1124
  Widget dialog = (Widget) client_data;
 
1125
  String value = XawDialogGetValueString (dialog);
 
1126
  mem_addr addr;
 
1127
 
 
1128
  free (breakpoint_addr);
 
1129
  breakpoint_addr = str_copy (value);
 
1130
  addr = strtoul (value, NULL, 0);
 
1131
 
 
1132
  delete_breakpoint (addr);
 
1133
 
 
1134
  destroy_popup_prompt (NULL, (XtPointer) dialog, (XtPointer) NULL);
 
1135
}
 
1136
 
 
1137
 
 
1138
#ifdef __STDC__
 
1139
static void
 
1140
list_breakpoint_action (Widget w, XtPointer client_data, XtPointer call_data)
 
1141
#else
 
1142
static void
 
1143
list_breakpoint_action (w, client_data, call_data)
 
1144
     Widget w;
 
1145
     XtPointer client_data, call_data;
 
1146
#endif
 
1147
{
 
1148
  list_breakpoints ();
 
1149
}
 
1150
 
 
1151
 
 
1152
#ifdef __STDC__
 
1153
static void
 
1154
breakpoint_prompt_destroyed (Widget w, XtPointer client_data,
 
1155
                             XtPointer call_data)
 
1156
#else
 
1157
static void
 
1158
breakpoint_prompt_destroyed (w, client_data, call_data)
 
1159
     Widget w;
 
1160
     XtPointer client_data, call_data;
 
1161
#endif
 
1162
{
 
1163
  bkpt_popup = NULL;
 
1164
}
 
1165
 
 
1166
 
 
1167
/* *** Help *** */
 
1168
 
 
1169
#ifdef __STDC__
 
1170
static void
 
1171
help_action (Widget w, XtPointer ignore, XtPointer ignored)
 
1172
#else
 
1173
static void
 
1174
help_action (w, ignore, ignored)
 
1175
     Widget w;
 
1176
     XtPointer ignore;
 
1177
     XtPointer ignored;
 
1178
#endif
 
1179
{
 
1180
  static char * msg = "\nSPIM is a MIPS R2000 simulator.\n\
 
1181
Copyright (C) 1990-2000 by James R. Larus, larus@cs.wisc.edu\n\n\
 
1182
quit  -- Exit from the simulator\n\
 
1183
load -- Read a file into memory\n\
 
1184
run -- Execute a program\n\
 
1185
step -- Single-step through a program\n\
 
1186
clear -- Reinitialize registers or memory\n\
 
1187
set value -- Set the value in register or memory\n\
 
1188
print -- Print the value in register or memory\n\
 
1189
breakpoint -- Set or delete a breakpoint\n\
 
1190
help -- This message\n\
 
1191
terminal -- Raise or hide console window\n\
 
1192
mode -- Set SPIM operating modes\n";
 
1193
 
 
1194
  write_output (message_out, msg);
 
1195
}
 
1196
 
 
1197
 
 
1198
/* *** Terminal *** */
 
1199
 
 
1200
#ifdef __STDC__
 
1201
static void
 
1202
add_terminal_button (Widget parent)
 
1203
#else
 
1204
static void
 
1205
add_terminal_button (parent)
 
1206
     Widget parent;
 
1207
#endif
 
1208
{
 
1209
  Widget command, menu, entry;
 
1210
  Arg args[2];
 
1211
 
 
1212
  XtSetArg (args[0], XtNwidth, button_width);
 
1213
  command = XtCreateManagedWidget ("terminal", menuButtonWidgetClass,
 
1214
                                   parent, args, ONE);
 
1215
  menu = XtCreatePopupShell ("menu", simpleMenuWidgetClass, command,
 
1216
                             NULL, ZERO);
 
1217
 
 
1218
  entry = XtCreateManagedWidget ("popup console", smeBSBObjectClass, menu,
 
1219
                                 args, ONE);
 
1220
  XtAddCallback (entry, XtNcallback, popup_console, NULL);
 
1221
}
 
1222
 
 
1223
 
 
1224
/* *** Mode *** */
 
1225
 
 
1226
static Widget modeCommand;
 
1227
 
 
1228
#ifdef __STDC__
 
1229
static void
 
1230
add_mode_button (Widget parent)
 
1231
#else
 
1232
static void
 
1233
add_mode_button (parent)
 
1234
     Widget parent;
 
1235
#endif
 
1236
{
 
1237
  Widget menu, entry;
 
1238
  Arg args[2];
 
1239
 
 
1240
  XtSetArg (args[0], XtNwidth, button_width);
 
1241
  modeCommand = XtCreateManagedWidget ("mode", menuButtonWidgetClass,
 
1242
                                       parent, args, ONE);
 
1243
  menu = XtCreatePopupShell ("menu", simpleMenuWidgetClass, modeCommand,
 
1244
                             NULL, ZERO);
 
1245
 
 
1246
  XtSetArg (args[0], XtNleftMargin, 20);
 
1247
  entry = XtCreateManagedWidget ("bare", smeBSBObjectClass, menu, args, ONE);
 
1248
  XtAddCallback (entry, XtNcallback, select_mode_action, NULL);
 
1249
  if (bare_machine)
 
1250
    {
 
1251
      XtSetArg (args[0], XtNleftBitmap, mark);
 
1252
      XtSetValues (entry, args, ONE);
 
1253
    }
 
1254
 
 
1255
  XtSetArg (args[0], XtNleftMargin, 20);
 
1256
  entry = XtCreateManagedWidget ("quiet", smeBSBObjectClass, menu, args, ONE);
 
1257
  XtAddCallback (entry, XtNcallback, select_mode_action, NULL);
 
1258
  if (quiet)
 
1259
    {
 
1260
      XtSetArg (args[0], XtNleftBitmap, mark);
 
1261
      XtSetValues (entry, args, ONE);
 
1262
    }
 
1263
}
 
1264
 
 
1265
 
 
1266
#ifdef __STDC__
 
1267
static void
 
1268
select_mode_action (Widget w, XtPointer client_data, XtPointer call_data)
 
1269
#else
 
1270
static void
 
1271
select_mode_action (w, client_data, call_data)
 
1272
     Widget w;
 
1273
     XtPointer client_data, call_data;
 
1274
#endif
 
1275
{
 
1276
  Arg args[10];
 
1277
  String name = XtName (w);
 
1278
 
 
1279
  if (streq (name, "bare"))
 
1280
    {
 
1281
      bare_machine = !bare_machine;
 
1282
      if (bare_machine)
 
1283
        XtSetArg (args[0], XtNleftBitmap, mark);
 
1284
      else
 
1285
        XtSetArg (args[0], XtNleftBitmap, None);
 
1286
      XtSetValues (w, args, ONE);
 
1287
    }
 
1288
  else if (streq (name, "quiet"))
 
1289
    {
 
1290
      quiet = !quiet;
 
1291
      if (quiet)
 
1292
        XtSetArg (args[0], XtNleftBitmap, mark);
 
1293
      else
 
1294
        XtSetArg (args[0], XtNleftBitmap, None);
 
1295
      XtSetValues (w, args, ONE);
 
1296
    }
 
1297
}
 
1298
 
 
1299
 
 
1300
/* *** Continue *** */
 
1301
 
 
1302
static Widget continue_popup = NULL;
 
1303
 
 
1304
#ifdef __STDC__
 
1305
void
 
1306
continue_prompt (int interrupt_seen)
 
1307
#else
 
1308
void
 
1309
continue_prompt (interrupt_seen)
 
1310
     int interrupt_seen;
 
1311
#endif
 
1312
{
 
1313
  Widget dialog;
 
1314
  Arg args[10];
 
1315
  Position x, y;
 
1316
  char msg[256];
 
1317
 
 
1318
  if (continue_popup != NULL)
 
1319
    XtDestroyWidget (continue_popup);
 
1320
  XtTranslateCoords (breakpointButton, (Position) 0, (Position) 0, &x, &y);
 
1321
  XtSetArg (args[0], XtNx, x);
 
1322
  XtSetArg (args[1], XtNy, y);
 
1323
  continue_popup = XtCreatePopupShell ("prompt", transientShellWidgetClass,
 
1324
                                      breakpointButton, args, TWO);
 
1325
  XtAddCallback (continue_popup, XtNdestroyCallback,
 
1326
                 continue_prompt_destroyed, (XtPointer) 0);
 
1327
 
 
1328
  if (interrupt_seen)
 
1329
    sprintf (msg, "execution interrupt at 0x%08x", PC);
 
1330
  else
 
1331
    sprintf (msg, "breakpoint encountered at 0x%08x", PC);
 
1332
  XtSetArg (args[0], XtNlabel, msg);
 
1333
  dialog = XtCreateManagedWidget ("continue", dialogWidgetClass,
 
1334
                                  continue_popup, args, ONE);
 
1335
 
 
1336
  XawDialogAddButton (dialog, "continue", continue_action,
 
1337
                      (XtPointer) dialog);
 
1338
  XawDialogAddButton (dialog, "abort command", destroy_popup_prompt,
 
1339
                      (XtPointer) dialog);
 
1340
 
 
1341
  confirmAction = continue_action;
 
1342
  XtPopup (continue_popup, XtGrabNone);
 
1343
}
 
1344
 
 
1345
 
 
1346
#ifdef __STDC__
 
1347
static void
 
1348
continue_action (Widget w, XtPointer client_data, XtPointer call_data)
 
1349
#else
 
1350
static void
 
1351
continue_action (w, client_data, call_data)
 
1352
     Widget w;
 
1353
     XtPointer client_data, call_data;
 
1354
#endif
 
1355
{
 
1356
  Widget dialog = (Widget) client_data;
 
1357
 
 
1358
  XtPopdown (XtParent (dialog));
 
1359
  destroy_popup_prompt (NULL, (XtPointer) dialog, (XtPointer) NULL);
 
1360
  continue_popup = NULL;
 
1361
  execute_program (PC, 1, 0, 1); /* Step over breakpoint */
 
1362
  execute_program (PC, DEFAULT_RUN_STEPS - 1, 0, 0);
 
1363
}
 
1364
 
 
1365
 
 
1366
#ifdef __STDC__
 
1367
static void
 
1368
continue_prompt_destroyed (Widget w, XtPointer client_data,
 
1369
                           XtPointer call_data)
 
1370
#else
 
1371
static void
 
1372
continue_prompt_destroyed (w, client_data, call_data)
 
1373
     Widget w;
 
1374
     XtPointer client_data, call_data;
 
1375
#endif
 
1376
{
 
1377
  continue_popup = NULL;
 
1378
}
 
1379
 
 
1380
 
 
1381
 
 
1382
 
 
1383
#ifdef __STDC__
 
1384
void
 
1385
confirm (Widget widget, XEvent *event, String *params, Cardinal *num_params)
 
1386
#else
 
1387
void
 
1388
confirm (widget, event, params, num_params)
 
1389
     Widget widget;
 
1390
     XEvent *event;
 
1391
     String *params;
 
1392
     Cardinal *num_params;
 
1393
#endif
 
1394
{
 
1395
  Widget dialog = XtParent (widget);
 
1396
  (*confirmAction) (widget, (XtPointer) dialog, (XtPointer) NULL);
 
1397
}
 
1398
 
 
1399
 
 
1400
#ifdef __STDC__
 
1401
static void
 
1402
destroy_popup_prompt (Widget w, XtPointer client_data, XtPointer call_data)
 
1403
#else
 
1404
static void
 
1405
destroy_popup_prompt (w, client_data, call_data)
 
1406
     Widget w;
 
1407
     XtPointer client_data, call_data;
 
1408
#endif
 
1409
{
 
1410
  Widget popup = XtParent ((Widget) client_data);
 
1411
 
 
1412
  confirmAction = noop;
 
1413
  XtDestroyWidget (popup);
 
1414
}
 
1415
 
 
1416
 
 
1417
#ifdef __STDC__
 
1418
static void
 
1419
noop (void)
 
1420
#else
 
1421
static void
 
1422
noop ()
 
1423
#endif
 
1424
{
 
1425
}
 
1426
 
 
1427
 
 
1428
#ifdef __STDC__
 
1429
static Widget
 
1430
popup_two_field_dialog (Widget button, String name, String field1_label,
 
1431
                        String field1_value, String field2_label,
 
1432
                        String field2_value, String action_name,
 
1433
                        void (*action) (/* ??? */), String action2_name,
 
1434
                        void (*action2) (/* ??? */), Widget *field1_text,
 
1435
                        Widget *field2_text)
 
1436
#else
 
1437
static Widget
 
1438
popup_two_field_dialog (button, name, field1_label, field1_value,
 
1439
                     field2_label, field2_value, action_name, action,
 
1440
                     action2_name, action2, field1_text, field2_text)
 
1441
     Widget button;
 
1442
     String name, field1_label, field1_value, field2_label, field2_value,
 
1443
       action_name, action2_name;
 
1444
     void (*action) (), (*action2) ();
 
1445
     Widget *field1_text, *field2_text;
 
1446
#endif
 
1447
{
 
1448
  Widget popup, form;
 
1449
  Widget labelx, field1, field2;
 
1450
  Widget button1, button2, cancelbutton;
 
1451
  Widget parent = XtParent (button);
 
1452
  Arg args[10];
 
1453
  Position x, y;
 
1454
  static XtActionsRec action_table []
 
1455
    = {{"warp_to_second_dialog", warp_to_second_dialog},};
 
1456
 
 
1457
  XtTranslateCoords (button, (Position) 0, (Position) 0, &x, &y);
 
1458
 
 
1459
  XtSetArg (args[0], XtNx, x);
 
1460
  XtSetArg (args[1], XtNy, y);
 
1461
  popup = XtCreatePopupShell ("prompt", transientShellWidgetClass, parent,
 
1462
                              args, TWO);
 
1463
 
 
1464
  form = XtCreateManagedWidget ("form", formWidgetClass, popup, NULL, ZERO);
 
1465
 
 
1466
  XtSetArg (args[0], XtNlabel, name);
 
1467
  XtSetArg (args[1], XtNborderWidth, 0);
 
1468
  labelx = XtCreateManagedWidget ("label", labelWidgetClass, form, args, TWO);
 
1469
 
 
1470
  XtSetArg (args[0], XtNfromVert, labelx);
 
1471
  XtSetArg (args[1], XtNborderWidth, 0);
 
1472
  XtSetArg (args[2], XtNlabel, field1_label);
 
1473
  field1 = XtCreateManagedWidget ("field1", labelWidgetClass, form, args,
 
1474
                                  THREE);
 
1475
 
 
1476
  XtSetArg (args[0], XtNfromHoriz, field1);
 
1477
  XtSetArg (args[1], XtNfromVert, labelx);
 
1478
  XtSetArg (args[2], XtNeditType, "edit");
 
1479
  XtSetArg (args[3], XtNstring, field1_value);
 
1480
  XtSetArg (args[4], XtNtype, XawAsciiString);
 
1481
  *field1_text = XtCreateManagedWidget ("field1_text", asciiTextWidgetClass,
 
1482
                                        form, args, FIVE);
 
1483
  XtOverrideTranslations (*field1_text,
 
1484
                          XtParseTranslationTable
 
1485
                          ("#override \n <Key>Return:warp_to_second_dialog()"));
 
1486
  XtAppAddActions (app_context, action_table, XtNumber (action_table));
 
1487
 
 
1488
  XtSetArg (args[0], XtNfromVert, *field1_text);
 
1489
  XtSetArg (args[1], XtNborderWidth, 0);
 
1490
  XtSetArg (args[2], XtNlabel, field2_label);
 
1491
  field2 = XtCreateManagedWidget ("field2", labelWidgetClass, form, args,
 
1492
                                  THREE);
 
1493
 
 
1494
  XtSetArg (args[0], XtNfromHoriz, field1);
 
1495
  XtSetArg (args[1], XtNfromVert, *field1_text);
 
1496
  XtSetArg (args[2], XtNeditType, "edit");
 
1497
  XtSetArg (args[3], XtNstring, field2_value);
 
1498
  XtSetArg (args[4], XtNtype, XawAsciiString);
 
1499
  *field2_text = XtCreateManagedWidget ("field2_text", asciiTextWidgetClass,
 
1500
                                        form, args, FIVE);
 
1501
  XtOverrideTranslations (*field2_text,
 
1502
                          XtParseTranslationTable
 
1503
                          ("#override \n <Key>Return: confirm()"));
 
1504
 
 
1505
  XtSetArg (args[0], XtNfromVert, *field2_text);
 
1506
  button1 = XtCreateManagedWidget (action_name, commandWidgetClass, form,
 
1507
                                   args, ONE);
 
1508
  XtAddCallback (button1, XtNcallback, action, (XtPointer) form);
 
1509
 
 
1510
  if (action2 != NULL)
 
1511
    {
 
1512
      XtSetArg (args[0], XtNfromHoriz, button1);
 
1513
      XtSetArg (args[1], XtNfromVert, *field2_text);
 
1514
      button2 = XtCreateManagedWidget (action2_name, commandWidgetClass, form,
 
1515
                                       args, TWO);
 
1516
      XtAddCallback (button2, XtNcallback, action2, (XtPointer) form);
 
1517
    }
 
1518
 
 
1519
  XtSetArg (args[0], XtNfromHoriz, action2 == NULL ? button1 : button2);
 
1520
  XtSetArg (args[1], XtNfromVert, *field2_text);
 
1521
  cancelbutton = XtCreateManagedWidget ("abort command", commandWidgetClass,
 
1522
                                        form, args, TWO);
 
1523
  XtAddCallback (cancelbutton, XtNcallback, destroy_popup_prompt,
 
1524
                 (XtPointer) form);
 
1525
 
 
1526
  return (popup);
 
1527
}
 
1528
 
 
1529
 
 
1530
#ifdef __STDC__
 
1531
static void
 
1532
warp_to_second_dialog (Widget widget, XEvent *event, String *params,
 
1533
                       Cardinal *num_params)
 
1534
#else
 
1535
static void
 
1536
warp_to_second_dialog (widget, event, params, num_params)
 
1537
     Widget widget;
 
1538
     XEvent *event;
 
1539
     String *params;
 
1540
     Cardinal *num_params;
 
1541
#endif
 
1542
{
 
1543
  Widget form = XtParent (widget);
 
1544
  Widget second_dialog;
 
1545
 
 
1546
  second_dialog = XtNameToWidget (form, "field2_text");
 
1547
  if (second_dialog)
 
1548
    XWarpPointer (XtDisplay (second_dialog), None, XtWindow (second_dialog),
 
1549
                  0, 0, 0, 0, 0, 10);
 
1550
}