-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathagc_debugger.c
1458 lines (1299 loc) · 38.2 KB
/
agc_debugger.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
Copyright 2008 Onno Hommes:1
This file is part of yaAGC.
yaAGC 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 2 of the License, or
(at your option) any later version.
yaAGC 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 yaAGC; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
In addition, as a special exception, permission is granted to
link the code of this program with the Orbiter SDK library (or with
modified versions of the Orbiter SDK library that use the same license as
the Orbiter SDK library), and distribute linked combinations including
the two. You must obey the GNU General Public License in all respects for
all of the code used other than the Orbiter SDK library. If you modify
this file, you may extend this exception to your version of the file,
but you are not obligated to do so. If you do not wish to do so, delete
this exception statement from your version.
Filename: agc_debugger.c
Purpose: This is module implements the debugger behavior.
Compiler: GNU gcc.
Contact: Onno Hommes
Reference: http://virtualagc.googlecode.com
Mods: 12/05/08 OH Began work.
07/01/09 OH Allow Address request using symbol
*/
#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
#include <string.h>
#include <signal.h>
#include "agc_cli.h"
#include "agc_help.h"
#include "agc_engine.h"
#include "agc_symtab.h"
#include "agc_debug.h"
#include "agc_debugger.h"
#include "agc_disassembler.h"
#include "agc_gdbmi.h"
#include "agc_simulator.h"
extern int SymbolTableSize;
extern Symbol_t *SymbolTable;
extern char *SourcePathName; /* Owned by agc_symtab */
static Debugger_t Debugger;
static Frame_t *Frames;
int LogCount = 0;
static int LogLast = -1;
// JMS: Variables pertaining to the symbol table loaded
int HaveSymbols = 0; // 1 if we have a symbol table
char *SymbolFile; // The name of the symbol table file
/* These globals will be deprecated when debugger is mature */
//int DebugMode;
FILE *FromFiles[MAX_FROMFILES];
FILE *LogFile = NULL;
int NumFromFiles = 1;
#define INT_MAIN 0
#define INT_TIMER6 1
#define INT_TIMER5 2
#define INT_TIMER3 3
#define INT_TIMER4 4
#define INT_KEYBD1 5
#define INT_KEYBD2 6
#define INT_UPLINK 7
#define INT_DNLINK 8
#define INT_RADAR 9
#define INT_JOYSTK 10
static char s1[129], s2[129], s3[129], s4[129], s5[129];
static int BreakPending = 0;
/* Prompt String
* Allow the prompt to be changed in gdb/mi mode
*/
char agcPrompt[16] = "(agc) ";
char s[129], sraw[129], slast[129];
Breakpoint_t Breakpoints[MAX_BREAKPOINTS];
int NumBreakpoints = 0;
/*
* My substitute for fgets, for use when stdin is unblocked.
*/
static void
rfgets (agc_t * State, char *Buffer, int MaxSize, FILE * fp)
{
int c, Count = 0;
char *s;
MaxSize--;
while (1)
{
/* While waiting for character input, continue to look for client connects
* and disconnects.
*/
while ((fp != stdin && EOF == (c = fgetc (fp))) ||
(fp == stdin && Buffer != (s = nbfgets (Buffer, MaxSize))))
{
/* If we have redirected console input, and the file of source data is
* exhausted, then reattach the console.
*/
if (NumFromFiles > 1 && fp == FromFiles[NumFromFiles - 1])
{
NumFromFiles--;
//printf ("Keystroke source-file closed.\n");
if (NumFromFiles == 1)
{
// printf ("The keyboard has been reattached.\n> ");
}
fclose (fp);
fp = FromFiles[NumFromFiles - 1];
}
else
{
#ifdef WIN32
Sleep (10);
#else
struct timespec req, rem;
req.tv_sec = 0;
req.tv_nsec = 10000000;
nanosleep (&req, &rem);
#endif // WIN32
}
ChannelRoutine (State);
}
if (fp == stdin && s != NULL)
return;
Buffer[Count] = c;
if (c == '\n' || Count >= MaxSize)
{
Buffer[Count] = 0;
return;
}
Count++;
}
}
/**
* Put the Debugger into the Run state.
*/
void
DbgSetRunState (void)
{
Debugger.RunState = 1;
}
void
DbgDisplayVersion (void)
{
printf ("Apollo Guidance Computer simulation, ver. " NVER ", built "
__DATE__ " " __TIME__ "\n"
"Copyright (C) 2003-2009 Ronald S. Burkey, Onno Hommes.\n"
"yaAGC is free software, covered by the GNU General Public License, and you are\n"
"welcome to change it and/or distribute copies of it under certain conditions.\n");
printf
("Refer to http://www.ibiblio.org/apollo/index.html for additional information.\n");
}
int
DbgHasBreakEvent ()
{
int BreakFlag;
if (Debugger.State->PendFlag)
BreakFlag = 0;
else
{
if (SingleStepCounter == 0)
{
// if(Debugger.RunState) printf ("Stepped.\n");
BreakFlag = 1;
}
else
{
int Value;
Value = DbgGetFromZ (Debugger.State);
/* Detect certain types of impending infinite loops. */
if (!(Value & 0177777) && !Debugger.State->Erasable[0][0])
{
/* Infinite Loop break on next instruction */
BreakFlag = DebugMode = 1;
}
else
{
if (SingleStepCounter > 0)
SingleStepCounter--;
if (DebugMode)
BreakFlag = DbgMonitorBreakpoints ();
}
}
}
if (BreakPending)
{
BreakPending = 0;
BreakFlag = 1;
}
return BreakFlag;
}
/**
* Delete a breakpoint from the debugger based on the BreapointId
* \param The breakpoint identifier
*/
void
DbgDeleteBreakpoint(int bp)
{
int i,j;
for (i = 0; i < NumBreakpoints; i++)
if (Breakpoints[i].Id == bp)
{
NumBreakpoints--;
for (j = i; j < NumBreakpoints; j++)
{
Breakpoints[j] = Breakpoints[j + 1];
}
break;
}
}
void
DbgHitBreakpoint(Breakpoint_t* bp)
{
bp->Hits++;
if (bp->Disposition == BP_DELETE)
{
DbgDeleteBreakpoint(bp->Id);
}
}
/* Normalize data in s and return sraw pointer */
char *
DbgNormalizeCmdString (char *s)
{
int i;
char *ss;
/* Normalize the strings by getting rid of leading, trailing
or duplicated spaces. */
i = sscanf (s, "%s%s%s%s%s", s1, s2, s3, s4, s5);
if (i == 1)
strcpy (s, s1);
else if (i == 2)
sprintf (s, "%s %s", s1, s2);
else if (i == 3)
sprintf (s, "%s %s %s", s1, s2, s3);
else if (i == 4)
sprintf (s, "%s %s %s %s", s1, s2, s3, s4);
else if (i == 5)
sprintf (s, "%s %s %s %s %s", s1, s2, s3, s4, s5);
else
s[0] = 0;
strcpy (sraw, s);
for (ss = s; *ss; *ss = toupper (*ss), ss++);
return sraw;
}
/*
* Get the value stored at an address, as specified by a Breakpoint_t.
*/
unsigned short
DbgGetWatch (agc_t * State, Breakpoint_t * bp)
{
int Address12, vRegBB;
Address12 = (bp->Address12 & 07777);
vRegBB = (bp->vRegBB & 07777);
int16_t Value = 0;
/* First check if it is fixed erasable */
if (Address12 <= 01377)
{
Value = (State->Erasable[Address12 / 0400][Address12 & 0377]);
}
/* Check if it is Switched erasable */
else if (Address12 <= 01777)
{
Value = (State->Erasable[vRegBB & 07][Address12 & 0377]);
}
/* Return value of address or default 0 */
return (Value);
}
/*
* Gets the value at the instruction pointer. The INDEX is automatically added,
* and the Extracode bit is used as the 16th bit.
*/
int
DbgGetFromZ (agc_t * State)
{
int CurrentZ, Bank, Value;
CurrentZ = (State->Erasable[0][RegZ] & 07777);
// Print the address.
if (CurrentZ < 01400)
{
Bank = CurrentZ / 0400;
Value = State->Erasable[Bank][CurrentZ & 0377];
}
else if (CurrentZ >= 04000)
{
Bank = 2 + (CurrentZ - 04000) / 02000;
Value = State->Fixed[Bank][CurrentZ & 01777];
}
else if (CurrentZ < 02000)
{
Bank = (7 & State->Erasable[0][RegBB]);
Value = State->Erasable[Bank][CurrentZ & 0377];
}
else
{
Bank = (31 & (State->Erasable[0][RegBB] >> 10));
if (0x18 == (Bank & 0x18) && (State->OutputChannel7 & 0100))
{
Bank += 0x08;
}
Value = State->Fixed[Bank][CurrentZ & 01777];
}
Value = OverflowCorrected (AddSP16
(SignExtend (Value),
SignExtend (State->IndexValue)));
Value = (Value & 077777);
/* Extracode? */
if (State->ExtraCode)
Value |= 0100000;
/* Indexed? */
if (State->IndexValue)
Value |= 0200000;
/* Positive overflow? */
if (0040000 == (0140000 & State->Erasable[0][RegA]))
Value |= 0400000;
/* Negative overflow? */
if (0100000 == (0140000 & State->Erasable[0][RegA]))
Value |= 01000000;
/* Sign of Accumulator */
if (0 != (0100000 & State->Erasable[0][RegA]))
Value |= 02000000;
/* Signs of Accumulator and L disagree. */
if (0 != (0100000 & (State->Erasable[0][RegL] ^ State->Erasable[0][RegA])))
{
Value |= 04000000;
}
/* Inside of an ISR? */
if (State->InIsr)
Value |= 010000000;
return (Value);
}
/**
* The Frames array is used to cache and look up the Frame Labels
* when trying to display the frame trace or current location
*/
static Frame_t *
DbgInitFrameData (void)
{
int i;
unsigned LinearAddr;
if (Debugger.HaveSymbols)
{
char *FrameName = NULL;
Symbol_t *Symbol;
Frames = (Frame_t *) malloc (38912 * sizeof (Frame_t));
if (Frames)
{
/* First Clean Frames */
for (i = 0; i < 38912; i++)
Frames[i].Name = NULL;
/* Vecter Table Frames */
Frames[0].Name = "MAIN";
Frames[4].Name = "TIMER6";
Frames[8].Name = "TIMER5";
Frames[12].Name = "TIMER3";
Frames[16].Name = "TIMER4";
Frames[20].Name = "KEYBD1";
Frames[24].Name = "KEYBD2";
Frames[28].Name = "UPLINK";
Frames[32].Name = "DNLINK";
Frames[36].Name = "RADAR";
Frames[40].Name = "JOYSTK";
/* First find all the Labels and Populate Frames */
for (i = 0; i < SymbolTableSize; i++)
{
Symbol = &SymbolTable[i];
if (Symbol->Type == SYMBOL_LABEL)
{
LinearAddr = DbgLinearFixedAddr (Symbol->Value.SReg,
Symbol->Value.FB,
Symbol->Value.Super);
Frames[LinearAddr - 2048].Name = Symbol->Name;
}
}
/* Next Fill all the remaining Empty Frames */
for (i = 0; i < 38912; i++)
{
if (Frames[i].Name != NULL)
FrameName = Frames[i].Name;
else
Frames[i].Name = FrameName;
}
}
}
return (Frames);
}
char *
DbgGetFrameNameByAddr (unsigned LinearAddr)
{
char *FrameName = NULL;
if (LinearAddr >= 2048 && LinearAddr < 40960)
FrameName = Frames[LinearAddr - 2048].Name;
return (FrameName);
}
/**
* Return the symbol line of the head of the current stack
*/
SymbolLine_t *
DbgResolveCurrentLine(void)
{
int CurrentZ = Debugger.State->Erasable[0][RegZ] & 07777;
int FB = 037 & (Debugger.State->Erasable[0][RegBB] >> 10);
int SBB = (Debugger.State->OutputChannel7 & 0100) ? 1 : 0;
return (ResolveLineAGC(CurrentZ, FB, SBB));
}
/**
* This function returns the frame name offset which is the offset in words
* from the start of the function. In the case of the AGC assembly this
* means the offset counted in words since the last label definition. Since
* The label is used as the frame name this allows the disassembly command
* to build the <FrameName+Offset> string. Examples
* <DOFSTART+00> The frame is at the same address as the label definition.
* <GOPROG+12> The frame is 12 words passed the address of GOPROG
*
* The Offset can only be calculated if the symbols were loaded. In all other
* cases the Offset will be 0.
*
* \param[in] LinearAddr A Pseudo linear address
* \retval The offset of the frame name.
*/
int
DbgGetFrameNameOffsetByAddr(unsigned LinearAddr)
{
int Offset =0;
char *FrameName;
/* Get the Frame Name for the current address */
FrameName = DbgGetFrameNameByAddr(LinearAddr);
/* Start counting until the Frame Name changes which gives the offset */
while (FrameName == DbgGetFrameNameByAddr(--LinearAddr)) ++Offset;
/* Do the obvious and return the calculated offset */
return (Offset);
}
/**
* This function returns the current value of the program counter which is the
* address of next instruction to be executed.
*
* /retval The current program counter (PC)
*/
unsigned
DbgGetCurrentProgramCounter(void)
{
int CurrentZ = Debugger.State->Erasable[0][RegZ] & 07777;
int FB = 037 & (Debugger.State->Erasable[0][RegBB] >> 10);
int SBB = (Debugger.State->OutputChannel7 & 0100) ? 1 : 0;
return (DbgLinearFixedAddr(CurrentZ,FB,SBB));
}
/**
* Catch the SIGINT Signal to stop running and return to debug mode
*/
static void
DbgCatchSignal (int sig)
{
BreakPending = 1; /* Make sure Break only happens when we want it */
nbfgets_ready (agcPrompt);
signal (sig, DbgCatchSignal);
}
int
DbgInitialize (Options_t * Options, agc_t * State)
{
Debugger.Options = Options;
Debugger.RunState = 0;
Debugger.State = State;
/* Will remove these variables when debugger is mature */
SingleStepCounter = 0;
DebugMode = 1;
/* if the symbolfile is provided load the symbol table */
if (Options->symtab)
{
/* Set the old global vars */
SymbolFile = Options->symtab;
HaveSymbols = 1;
/* Reset and attempt to load the symbol table */
ResetSymbolTable ();
if (ReadSymbolTable (Options->symtab))
HaveSymbols = 0; /* Default is 0 */
/* In the future Have Symbols will only be used by the Debugger */
Debugger.HaveSymbols = HaveSymbols;
DbgInitFrameData ();
}
/* setvbuf (stdout, OutBuf, _IOLBF, sizeof (OutBuf)); */
FromFiles[0] = stdin;
/* Allow a command file to be used with initial debugger commands */
if (Options->fromfile > 0)
{
if (NumFromFiles < MAX_FROMFILES)
{
FromFiles[NumFromFiles] = fopen (Options->fromfile, "r");
if (FromFiles[NumFromFiles] != NULL)
NumFromFiles++;
}
}
/* If a new source path is given then apply this to prevent the
* default source path from the symbol table to be used.
*/
if (Options->directory > 0)
SourcePathName = Options->directory;
/* Add the AGC starting point */
BacktraceAdd (State, 0);
/* Register the SIGINT to be handled by AGC Debugger */
signal (SIGINT, DbgCatchSignal);
return 0;
}
int
DbgMonitorBreakpoints (void)
{
int Break;
int CurrentZ;
int CurrentBB;
int i;
int Value;
SymbolLine_t *Line;
Value = DbgGetFromZ (Debugger.State);
CurrentZ = Debugger.State->Erasable[0][RegZ];
CurrentBB = (Debugger.State->Erasable[0][RegBB] & 076007) |
(Debugger.State->InputChannel[7] & 0100);
for (Break = i = 0; i < NumBreakpoints; i++)
{
Line = Breakpoints[i].Line;
if (Breakpoints[i].WatchBreak == 2 &&
DbgCheckBreakpoint (&Breakpoints[i]))
{
// Pattern!
if (Breakpoints[i].Address12 == (Value & Breakpoints[i].vRegBB))
{
printf ("Hit pattern, Value=" PAT " Mask=" PAT
".\n", Breakpoints[i].Address12, Breakpoints[i].vRegBB);
DbgHitBreakpoint (&Breakpoints[i]);
Break = 1;
break;
}
}
else if (Breakpoints[i].WatchBreak == 0 &&
DbgCheckBreakpoint (&Breakpoints[i]))
{
int Address12, vRegBB;
int CurrentFB, vCurrentFB;
Address12 = Breakpoints[i].Address12;
if (Address12 != CurrentZ)
continue;
if (Address12 < 01400)
{
GdbmiDisplayBreakpointForLine (Line, i + 1);
DbgHitBreakpoint (&Breakpoints[i]);
Break = 1;
break;
}
if (Address12 >= 04000)
{
GdbmiDisplayBreakpointForLine (Line, i + 1);
DbgHitBreakpoint (&Breakpoints[i]);
Break = 1;
break;
}
vRegBB = Breakpoints[i].vRegBB;
if (Address12 >= 01400 && Address12 < 02000 &&
(vRegBB & 7) == (CurrentBB & 7))
{
// JMS: I'm not convinced yet that we can have a
// breakpoint in erasable memory that has a symbol
if (Breakpoints[i].Symbol != NULL)
printf ("Hit breakpoint %s at E%o,%05o.\n",
Breakpoints[i].Symbol->Name, CurrentBB & 7,
Address12);
else
printf ("Hit breakpoint at E%o,%05o.\n", CurrentBB & 7,
Address12);
DbgHitBreakpoint (&Breakpoints[i]);
Break = 1;
break;
}
CurrentFB = (CurrentBB >> 10) & 037;
if (CurrentFB >= 030 && (CurrentBB & 0100))
CurrentFB += 010;
vCurrentFB = (vRegBB >> 10) & 037;
if (vCurrentFB >= 030 && (vRegBB & 0100))
vCurrentFB += 010;
if (Address12 >= 02000 && Address12 < 04000 &&
CurrentFB == vCurrentFB)
{
int Bank;
Bank = (CurrentBB >> 10) & 037;
if (0 != (CurrentBB & 0100) && Bank >= 030)
Bank += 010;
// if (Breakpoints[i].Symbol != NULL)
// printf ("Hit breakpoint %s at %02o,%05o.\n",
// Breakpoints[i].Symbol->Name, Bank, Address12);
// else
// printf ("Hit breakpoint ot %02o,%05o.\n", Bank, Address12);
GdbmiDisplayBreakpointForLine (Line, i + 1);
DbgHitBreakpoint (&Breakpoints[i]);
Break = 1;
break;
}
}
else if ((Breakpoints[i].WatchBreak == 1 &&
DbgCheckBreakpoint (&Breakpoints[i]) &&
Breakpoints[i].WatchValue != DbgGetWatch (Debugger.State,
&Breakpoints[i]))
|| (Breakpoints[i].WatchBreak == 3
&& Breakpoints[i].WatchValue ==
DbgGetWatch (Debugger.State, &Breakpoints[i])))
{
int Address12, vRegBB, Before, After;
Address12 = Breakpoints[i].Address12;
Before = (Breakpoints[i].WatchValue & 077777);
After = (DbgGetWatch (Debugger.State, &Breakpoints[i]) & 077777);
if (Address12 < 01400)
{
if (Breakpoints[i].Symbol != NULL)
printf ("Hit watchpoint %s at %05o, %06o -> %06o.\n",
Breakpoints[i].Symbol->Name, Address12, Before,
After);
else
printf ("Hit watchpoint at %05o, %06o -> %06o.\n",
Address12, Before, After);
if (Breakpoints[i].WatchBreak == 1)
Breakpoints[i].WatchValue =
DbgGetWatch (Debugger.State, &Breakpoints[i]);
DbgHitBreakpoint (&Breakpoints[i]);
Break = 1;
break;
}
vRegBB = Breakpoints[i].vRegBB;
if (Address12 >= 01400 && Address12 < 02000 &&
(vRegBB & 7) == (CurrentBB & 7))
{
if (Breakpoints[i].Symbol == NULL)
printf
("Hit watchpoint at E%o,%05o, %06o -> %06o.\n",
CurrentBB & 7, Address12, Before, After);
else
printf
("Hit watchpoint %s at E%o,%05o, %06o -> %06o.\n",
Breakpoints[i].Symbol->Name, CurrentBB & 7,
Address12, Before, After);
if (Breakpoints[i].WatchBreak == 1)
Breakpoints[i].WatchValue =
DbgGetWatch (Debugger.State, &Breakpoints[i]);
DbgHitBreakpoint (&Breakpoints[i]);
Break = 1;
break;
}
}
else if ((Breakpoints[i].WatchBreak == 4 &&
DbgCheckBreakpoint (&Breakpoints[i]) &&
Breakpoints[i].WatchValue != DbgGetWatch (Debugger.State,
&Breakpoints[i])))
{
int Address12, vRegBB, Before, After;
Address12 = Breakpoints[i].Address12;
Before = (Breakpoints[i].WatchValue & 077777);
After = (DbgGetWatch (Debugger.State, &Breakpoints[i]) & 077777);
if (Address12 < 01400)
{
if (Breakpoints[i].Symbol != NULL)
printf ("%s=%06o\n", Breakpoints[i].Symbol->Name, After);
else
printf ("(%05o)=%06o\n", Address12, After);
Breakpoints[i].WatchValue =
DbgGetWatch (Debugger.State, &Breakpoints[i]);
}
else
{
vRegBB = Breakpoints[i].vRegBB;
if (Address12 >= 01400 && Address12 < 02000 &&
(vRegBB & 7) == (CurrentBB & 7))
{
if (Breakpoints[i].Symbol == NULL)
printf ("(E%o,%05o)=%06o\n", CurrentBB & 7, Address12,
After);
else
printf ("%s=%06o\n", Breakpoints[i].Symbol->Name, After);
Breakpoints[i].WatchValue =
DbgGetWatch (Debugger.State, &Breakpoints[i]);
}
}
}
}
return (Break);
}
int DbgCheckBreakpoint(Breakpoint_t* bp)
{
return (bp->Enable == 'y');
}
void
DbgDisplayInnerFrame (void)
{
// If we have the symbol table, then print out the actual source,
// rather than just a disassembly
if (Debugger.Options->symtab && Debugger.HaveSymbols)
{
// Resolve the current program counter into an entry into
// the program line table. We pass in the current value of
// the Z register, but also need the BB register and the
// super-bank bit to resolve addresses.
int CurrentZ = Debugger.State->Erasable[0][RegZ] & 07777;
int FB = 037 & (Debugger.State->Erasable[0][RegBB] >> 10);
int SBB = (Debugger.State->OutputChannel7 & 0100) ? 1 : 0;
/* Get the SymbolLine for the InnerFrame */
SymbolLine_t *Line = ResolveLineAGC (CurrentZ, FB, SBB);
// There are several ways this can fail, and if either does we
// just want to disasemble: if we didn't find the line in the
// table or if ListSource() fails.
if (Line)
{
/* Load the actual Source Line */
LoadSourceLine (Line->FileName, Line->LineNumber);
if (Debugger.RunState)
{
if (Debugger.Options->fullname)
GdbmiPrintFullNameFrame (Line);
else
GdbmiPrintSourceFrame (Line);
}
}
}
else
Disassemble (Debugger.State);
}
Address_t
DbgNativeAddr (unsigned linear_addr)
{
Address_t agc_addr;
if (linear_addr > 0117777)
{
agc_addr.Invalid = 1;
agc_addr.Address = 0;
}
else if (linear_addr > 07777) /* Must be Common Fixed */
{
agc_addr.Banked = 1;
agc_addr.Unbanked = 0;
agc_addr.Address = 1;
agc_addr.Invalid = 0;
agc_addr.Fixed = 1;
agc_addr.Erasable = 0;
agc_addr.FB = (linear_addr - 010000) / 02000;
agc_addr.SReg = (linear_addr - agc_addr.FB * 02000) - 06000;
if (agc_addr.FB > 037) /* Do we need to set the Extension Bit */
{
agc_addr.FB = agc_addr.FB - 010;
agc_addr.Super = 01;
}
else
agc_addr.Super = 0;
}
else if (linear_addr > 03777) /* Must be Fixed Fixed */
{
agc_addr.Banked = 0;
agc_addr.Unbanked = 1;
agc_addr.Address = 1;
agc_addr.Invalid = 0;
agc_addr.Fixed = 1;
agc_addr.Erasable = 0;
agc_addr.FB = linear_addr / 02000; /* Allows for faster Value access later */
agc_addr.Super = 0;
agc_addr.SReg = linear_addr;
}
else /* Map to Eraseable memory */
{
agc_addr.Banked = 1;
agc_addr.Unbanked = 0;
agc_addr.Address = 1;
agc_addr.Invalid = 0;
agc_addr.Fixed = 0;
agc_addr.Erasable = 1;
agc_addr.EB = linear_addr / 0400; /* Allows for faster Value access later */
agc_addr.SReg = linear_addr - agc_addr.EB * 0400 + 01400;
}
return agc_addr;
}
/**
* Return the Virtual Linear Pseudo address. According to
* AGC Memo #9 page 5. with the exception of Fixed banked
* 02 and 03; I kept linear address 014000-017777 this
* way you can still notice you were dealing with a banked
* address. However the value for address 04000 and 14000
* will give you the same result.
*/
unsigned
DbgLinearAddr (Address_t * agc_addr)
{
unsigned LinearAddress = ~0; /* Default invalid Address */
if (agc_addr->SReg < 01400) /* Must be Unbanked Eraseable */
{
LinearAddress = agc_addr->SReg;
}
else if (agc_addr->SReg < 02000) /* Must be Banked Eraseable */
{
LinearAddress = agc_addr->EB * 0400 + agc_addr->SReg - 01400;
}
else if (agc_addr->SReg < 04000) /* Must be Banked fixed memory */
{
if (agc_addr->FB < 030)
LinearAddress = 06000 + agc_addr->FB * 02000 + agc_addr->SReg;
else
LinearAddress =
06000 + (agc_addr->FB + agc_addr->Super * 010) * 02000 +
agc_addr->SReg;
}
else if (agc_addr->SReg < 07777) /* Must be fixed fixed */
{
LinearAddress = agc_addr->SReg;
}
return LinearAddress;
}
unsigned
DbgLinearFixedAddr (unsigned agc_sreg, unsigned agc_fb, unsigned agc_super)
{
Address_t agc_addr;
agc_addr.Fixed = 1;
agc_addr.Banked = 1;
agc_addr.SReg = agc_sreg;
agc_addr.FB = agc_fb;
agc_addr.Super = agc_super;
return DbgLinearAddr (&agc_addr);
}
unsigned
DbgLinearEraseableAddr (unsigned agc_sreg, unsigned agc_eb)
{
Address_t agc_addr;
agc_addr.Erasable = 1;
agc_addr.Banked = 1;
agc_addr.SReg = agc_sreg;
agc_addr.EB = agc_eb;
return DbgLinearAddr (&agc_addr);
}
unsigned short
DbgGetValueByAddress (unsigned gdbmi_addr)
{
Address_t agc_addr;
unsigned short Value = 0;
/* if in Eraseable use Eraseable value */
agc_addr = DbgNativeAddr (gdbmi_addr);
if (agc_addr.Erasable == 1)
{
Value = Debugger.State->Erasable[agc_addr.EB][agc_addr.SReg - 01400];
}
else /* Must be fixed memory */
{
if (agc_addr.Unbanked == 1) /* Check for Fixed Fixed */
{
/* remember the FB should already be fine (see gdbmiNativeAddr */
Value = Debugger.State->Fixed[agc_addr.FB][agc_addr.SReg - 04000];
}
else /* This is Common Fixed */
{
Value =
Debugger.State->Fixed[agc_addr.FB +
agc_addr.Super * 010][agc_addr.SReg -
02000];
}
}
return Value;
}
/**
* This function returns the linear pseudo address based on an address string
* The address string could be the string representation of a linear address
* or be the original AGC see bank address string.
*
* Examples:
* 0x800 is a hex linear address
* 04000 is an octal linear address
* 2048 is a decimal linear address
* 12,2345 is a banked fixed address
* E4,1456 is a banked switched address
*
* Notice that for the original AGC addressing you can't use the notation for
* unswitched or common fixed memory. However these locations are also
* accessible in the switched region. The term pseudo address from from
* the original AGC memo.
*/
unsigned