-
Notifications
You must be signed in to change notification settings - Fork 0
/
debug.c
1352 lines (1074 loc) · 32.6 KB
/
debug.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
/*
The XSM debugger.
*/
#include "debug.h"
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
static debug_status _db_status;
const char *_db_commands_lh[] = {
"step",
"continue",
"reg",
"mem",
"pcb",
"pagetable",
"diskmaptable",
"resourcetable",
"filetable",
"semtable",
"memfreelist",
"filestatus",
"diskstatus",
"systemstatus",
"terminalstatus",
"accesslocktable",
"buffertable",
"inodetable",
"usertable",
"diskfreelist",
"rootfile",
"location",
"val",
"watch",
"watchclear",
"list",
"page",
"exit",
"help"};
const char *_db_commands_sh[] = {
"s",
"c",
"r",
"m",
"p",
"pt",
"dmt",
"rt",
"ft",
"st",
"mf",
"fst",
"dst",
"sst",
"tst",
"alt",
"bt",
"it",
"ut",
"df",
"rf",
"loc",
"v",
"w",
"wc",
"l",
"pg",
"e",
"h"};
/* Initialise debugger */
int debug_init()
{
_db_status.state = OFF;
_db_status.ip = -1;
_db_status.prev_mode[PRIMARY_CORE] = PRIVILEGE_KERNEL;
_db_status.prev_mode[SECONDARY_CORE] = PRIVILEGE_KERNEL;
_db_status.skip = 0;
strcpy(_db_status.command, "help");
debug_watch_clear();
return TRUE;
}
/* Activate the debugger */
void debug_activate()
{
_db_status.state = ON;
}
/* Deactivate debugger */
void debug_deactivate()
{
_db_status.state = OFF;
}
/* Called from machine for debugger */
int debug_next_step(int curr_ip)
{
int mem_left, mem_right;
int wp = DEBUG_ERROR;
if (machine_get_core_state() == ACTIVE_MODE)
{
if (machine_get_core() == PRIMARY_CORE)
_db_status.prev_ip[SECONDARY_CORE] = _db_status.ip;
else if (machine_get_core() == SECONDARY_CORE)
_db_status.prev_ip[PRIMARY_CORE] = _db_status.ip;
}
else
{
_db_status.prev_ip[PRIMARY_CORE] = _db_status.ip;
_db_status.prev_ip[SECONDARY_CORE] = -1;
}
_db_status.ip = curr_ip;
machine_get_mem_access(&mem_left, &mem_right);
if (mem_left > 0)
wp = debug_watch_test(mem_left, mem_right);
if (wp >= 0)
{
printf("Watchpoint at %d has been triggered.\n", _db_status.wp[wp]);
_db_status.state = ON;
}
if (_db_status.state == ON)
debug_show_interface();
_db_status.prev_mode[machine_get_core()] = machine_get_mode();
return TRUE;
}
/* Display debugger interface */
int debug_show_interface()
{
int done = FALSE, addr;
char command[DEBUG_COMMAND_LEN], prev_instr[XSM_NUM_CORES][DEBUG_STRING_LEN], next_instr[DEBUG_STRING_LEN];
if (_db_status.skip > 0)
{
_db_status.skip--;
if (_db_status.skip_command == DEBUG_CONTINUE)
debug_deactivate();
return TRUE;
}
// Get previous instruction for PRIMARY_CORE
addr = machine_translate_address(_db_status.prev_ip[PRIMARY_CORE], FALSE, DEBUG_FETCH, PRIMARY_CORE, _db_status.prev_mode[PRIMARY_CORE]);
if (addr >= 0)
memory_retrieve_raw_instr(prev_instr[PRIMARY_CORE], addr);
else
prev_instr[PRIMARY_CORE][0] = '\0';
// Get previous instruction for SECONDARY_CORE
addr = machine_translate_address(_db_status.prev_ip[SECONDARY_CORE], FALSE, DEBUG_FETCH, SECONDARY_CORE, _db_status.prev_mode[SECONDARY_CORE]);
if (addr >= 0)
memory_retrieve_raw_instr(prev_instr[SECONDARY_CORE], addr);
else
prev_instr[SECONDARY_CORE][0] = '\0';
// Get the next instruction
addr = machine_translate_address(_db_status.ip, FALSE, DEBUG_FETCH, machine_get_core(), machine_get_mode());
if (addr >= 0)
memory_retrieve_raw_instr(next_instr, addr);
else
next_instr[0] = '\0';
// Print the info
printf("Previous instruction at IP (PRIMARY_CORE) = %d: %s\n", _db_status.prev_ip[PRIMARY_CORE], prev_instr[PRIMARY_CORE]);
if (machine_get_core_state() == ACTIVE_MODE)
printf("Previous instruction at IP (SECONDARY_CORE) = %d: %s\n", _db_status.prev_ip[SECONDARY_CORE], prev_instr[SECONDARY_CORE]);
printf("Mode: %s \t Core: %s \t PID: %d\n", (machine_get_mode() == PRIVILEGE_KERNEL) ? "KERNEL" : "USER", (machine_get_core() == PRIMARY_CORE) ? "PRIMARY" : "SECONDARY", debug_active_process(machine_get_core()));
printf("Next instruction at IP = %d, Page No. = %d: %s\n", _db_status.ip, _db_status.ip / XSM_PAGE_SIZE, next_instr);
while (!done)
{
printf("debug> ");
fgets(command, DEBUG_COMMAND_LEN, stdin);
// Remove the dangling \n from fgets
strtok(command, "\n");
if (!strcmp(command, "\n"))
strncpy(command, _db_status.command, DEBUG_COMMAND_LEN);
else if (!strcmp(command, "exit") || !strcmp(command, "e"))
{
debug_deactivate();
printf("Killing the machine\n");
exit(0);
return FALSE;
}
else
strncpy(_db_status.command, command, DEBUG_COMMAND_LEN);
done = debug_command(command);
}
return TRUE;
}
/* Call the function based on the given command */
int debug_command(char *command)
{
int code;
char *arg1, *cmd, *arg2;
const char *delim = " \t";
cmd = strtok(command, delim);
code = debug_command_code(cmd);
switch (code)
{
case DEBUG_STEP:
arg1 = strtok(NULL, delim);
if (arg1)
debug_skip_n(atoi(arg1), DEBUG_STEP);
return TRUE;
case DEBUG_CONTINUE:
arg1 = strtok(NULL, delim);
if (arg1)
debug_skip_n(atoi(arg1), DEBUG_CONTINUE);
debug_deactivate();
return TRUE;
case DEBUG_REG:
arg1 = strtok(NULL, delim);
if (!arg1)
debug_display_all_registers();
else
{
arg2 = strtok(NULL, delim);
if (!arg2)
debug_display_register(arg1);
else
debug_display_range_reg(arg1, arg2);
}
break;
case DEBUG_MEM:
arg1 = strtok(NULL, delim);
if (!arg1)
debug_invalid_cmd(command);
else
{
arg2 = strtok(NULL, delim);
if (!arg2)
debug_display_mem_range(atoi(arg1), atoi(arg1));
else
debug_display_mem_range(atoi(arg1), atoi(arg2));
}
break;
case DEBUG_PCB:
arg1 = strtok(NULL, delim);
if (!arg1)
debug_display_pcb();
else
debug_display_pcb_pid(atoi(arg1));
break;
case DEBUG_PAGETABLE:
arg1 = strtok(NULL, delim);
if (!arg1)
debug_display_pt_ptbr();
else
debug_display_pt_pid(atoi(arg1));
break;
case DEBUG_FILETABLE:
debug_display_ft();
break;
case DEBUG_SEMTABLE:
debug_display_st();
break;
case DEBUG_FILESTATUS:
debug_display_fst();
break;
case DEBUG_DISKSTATUS:
debug_display_dst();
break;
case DEBUG_SYSTEMSTATUS:
debug_display_sst();
break;
case DEBUG_TERMINALSTATUS:
debug_display_tst();
break;
case DEBUG_ACCESSLOCK:
debug_display_alt();
break;
case DEBUG_BUFFERTABLE:
debug_display_bt();
break;
case DEBUG_DISKMAPTABLE:
arg1 = strtok(NULL, delim);
if (!arg1)
debug_display_dmt();
else
debug_dmt_pid(atoi(arg1));
break;
case DEBUG_ROOTFILE:
debug_display_rf();
break;
case DEBUG_RESOURCETABLE:
arg1 = strtok(NULL, delim);
if (!arg1)
debug_display_rt();
else
debug_rt_pid(atoi(arg1));
break;
case DEBUG_MEMFREELIST:
debug_display_memlist();
break;
case DEBUG_DISKFREELIST:
debug_display_dfl();
break;
case DEBUG_INODETABLE:
debug_display_inodetable();
break;
case DEBUG_USERTABLE:
debug_display_usertable();
break;
case DEBUG_LOCATION:
arg1 = strtok(NULL, delim);
if (!arg1)
debug_invalid_cmd(command);
else
debug_display_location(atoi(arg1));
break;
case DEBUG_VAL:
arg1 = strtok(NULL, delim);
if (!arg1)
debug_invalid_cmd(command);
else
debug_display_val(arg1);
break;
case DEBUG_WATCH:
arg1 = strtok(NULL, delim);
if (!arg1)
debug_invalid_cmd(command);
else
{
debug_watch_add(atoi(arg1));
printf("Watch point added at %d.\n", atoi(arg1));
}
break;
case DEBUG_WATCHCLEAR:
debug_watch_clear();
printf("Watch points cleared.\n");
break;
case DEBUG_LIST:
debug_display_list();
break;
case DEBUG_PAGE:
arg1 = strtok(NULL, delim);
if (!arg1)
debug_invalid_cmd(command);
else
debug_display_page(atoi(arg1));
break;
case DEBUG_HELP:
debug_display_help();
break;
default:
debug_invalid_cmd(command);
}
return FALSE;
}
void debug_invalid_cmd(const char *cmd)
{
printf("Unknown command \"%s\". See \"help\" for more information.\n", cmd);
}
/* Retrieve the debug command index */
int debug_command_code(const char *cmd)
{
int i;
for (i = 0; i < DEBUG_COUNT; ++i)
if (!strcmp(cmd, _db_commands_lh[i]))
return i;
for (i = 0; i < DEBUG_COUNT; ++i)
if (!strcmp(cmd, _db_commands_sh[i]))
return i;
return DEBUG_ERROR;
}
/* Retrieve RUNNING process */
int debug_active_process(int core)
{
int ptbr, pid;
ptbr = registers_get_integer("PTBR", core);
pid = (ptbr - DEBUG_PT_BASE) / 20;
if (pid < 0 || pid >= MAX_PROC_NUM)
pid = -1;
return pid;
}
/* Debug step/continue command */
int debug_skip_n(int num, int debug_command)
{
num--;
if (num > 0)
{
_db_status.skip = num;
_db_status.skip_command = debug_command;
}
return TRUE;
}
/* Debug reg command */
int debug_display_all_registers()
{
int num_regs, i;
char *content;
const char **reg_names;
reg_names = registers_names();
num_regs = registers_len();
printf("PRIMARY_CORE:\n");
for (i = 0; i < num_regs; ++i)
{
content = registers_get_string(reg_names[i], PRIMARY_CORE);
printf("%s: %s\t", reg_names[i], content);
if ((i < 20 && i % 5 == 4) || i == 23 || i == 28)
printf("\n");
}
printf("\n\n");
printf("SECONDARY_CORE:\n");
for (i = 0; i < num_regs; ++i)
{
content = registers_get_string(reg_names[i], SECONDARY_CORE);
printf("%s: %s\t", reg_names[i], content);
if ((i < 20 && i % 5 == 4) || i == 23 || i == 28)
printf("\n");
}
printf("\n");
return TRUE;
}
/* Debug reg regname command */
int debug_display_register(const char *regname)
{
char *content;
content = registers_get_string(regname, PRIMARY_CORE);
if (!content)
{
printf("No such register.\n");
return FALSE;
}
printf("PRIMARY_CORE: %s: %s\n", regname, content);
content = registers_get_string(regname, SECONDARY_CORE);
printf("SECONDARY_CORE: %s: %s\n", regname, content);
return TRUE;
}
/* Debug reg reg_b_name reg_e_name command */
int debug_display_range_reg(const char *reg_b_name, const char *reg_e_name)
{
int num_regs, i, start;
char *content;
const char **reg_names;
reg_names = registers_names();
num_regs = registers_len();
for (i = 0; i < num_regs; ++i)
if (!strcmp(reg_b_name, reg_names[i]))
break;
start = i;
printf("PRIMARY_CORE:\n");
for (; i < num_regs; ++i)
{
content = registers_get_string(reg_names[i], PRIMARY_CORE);
printf("%s: %s\n", reg_names[i], content);
if (!strcmp(reg_e_name, reg_names[i]))
break;
}
printf("SECONDARY_CORE:\n");
for (i = start; i < num_regs; ++i)
{
content = registers_get_string(reg_names[i], SECONDARY_CORE);
printf("%s: %s\n", reg_names[i], content);
if (!strcmp(reg_e_name, reg_names[i]))
break;
}
return TRUE;
}
/* Debug mem page_l page_r command */
int debug_display_mem_range(int page_l, int page_h)
{
int i,j;
int ptr;
char *content;
xsm_word *word;
FILE *fp;
fp = fopen("mem", "w");
for (i = page_l; i <= page_h; ++i)
{
printf("Page: %d\n", i);
word = memory_get_page(i);
if (!word)
{
printf("No such page.\n");
return FALSE;
}
ptr = i * XSM_PAGE_SIZE;
fprintf(fp, "Page: %d\n", i);
// Write to file mem
for (j = 0; j < XSM_PAGE_SIZE; j++)
{
word = memory_get_word(ptr);
content = word_get_string(word);
fprintf(fp, "%d: %s\n", j, content);
ptr++;
}
}
printf("Written to file mem\n");
fclose(fp);
return TRUE;
}
int debug_display_fields(int baseptr, const char **fields, const int *fields_len, int n_fields)
{
int i, ptr, num;
xsm_word *word;
const char *state[] = {"READY", "RUNNING", "CREATED", "TERMINATED", "WAIT_DISK", "WAIT_FILE", "WAIT_BUFFER", "WAIT_TERMINAL", "WAIT_PROCESS", "WAIT_SEMAPHORE", "WAIT_MEM", "ALLOCATED"};
const char *mode[] = {"Create", "Open", "Close", "Delete", "Write", "Seek", "Read", "Fork", "Exec", "Exit", "Getpid", "Getppid", "Wait", "Signal", "15", "16", "Semget", "Semrelease", "SemLock", "SemUnLock", "Shutdown", "Newusr", "Remusr", "Setpwd", "Getuname", "Getuid", "Login", "Logout"};
const char *test[] = {"Test0", "Test1", "Test2", "Test3"};
ptr = baseptr;
for (i = 0; i < n_fields; ++i)
{
printf("%s: \t\t", fields[i]);
/* Convert STATE to CONSTANT */
if (!strcmp(fields[i], "State"))
{
word = memory_get_word(ptr);
num = word_get_integer(word);
if (num >= 1 && num <= 12)
printf("(%s, ", state[num - 1]);
else
printf("(%s, ", word_get_string(word));
ptr = ptr + 1;
word = memory_get_word(ptr);
printf("%s)\n", word_get_string(word));
ptr = ptr + 1;
continue;
}
/* Convert MODE to CONSTANT */
if (!strcmp(fields[i], "Mode Flag"))
{
word = memory_get_word(ptr);
num = word_get_integer(word);
if (num >= 1 && num <= 28)
printf("%s", mode[num - 1]);
else if (num >= 96 && num <= 99)
printf("%s", test[num - 96]);
else
printf("%s", word_get_string(word));
ptr = ptr + 1;
printf("\n");
continue;
}
/* Display the corresponding number of words. */
int j;
for (j = 0; j < fields_len[i]; ++j)
{
word = memory_get_word(ptr);
printf("%s ", word_get_string(word));
ptr = ptr + 1;
}
printf("\n");
}
return TRUE;
}
/* Debug pcb pid command */
int debug_display_pcb_pid(int pid)
{
const char *fields[] = {"Tick", "PID", "PPID", "UserID", "State", "Swap Flag", "Inode Index",
"Input Buffer", "Mode Flag", "User Area Swap Status", "User Area Page Number",
"Kernel Stack Pointer", "User Stack Pointer", "PTBR", "PTLR", "Unused"};
const int fields_len[] = {1, 1, 1, 1, 2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1};
const int n_fields = 15;
int ptr;
ptr = DEBUG_LOC_PT + pid * PT_ENTRY_SIZE;
return debug_display_fields(ptr, fields, fields_len, n_fields);
}
/* Debug pcb command */
int debug_display_pcb()
{
int pid;
printf("PRIMARY_CORE: \n");
pid = debug_active_process(PRIMARY_CORE);
if (pid < 0)
printf("No active processes.\n");
else
debug_display_pcb_pid(pid);
printf("SECONDARY_CORE: \n");
pid = debug_active_process(SECONDARY_CORE);
if (pid < 0)
printf("No active processes.\n");
else
debug_display_pcb_pid(pid);
return TRUE;
}
/* Debug pagetable command */
int debug_display_pt_ptbr()
{
int addr;
printf("PRIMARY_CORE: \n");
addr = registers_get_integer("PTBR", PRIMARY_CORE);
debug_display_pt_at(addr);
printf("SECONDARY_CORE: \n");
addr = registers_get_integer("PTBR", SECONDARY_CORE);
debug_display_pt_at(addr);
return TRUE;
}
/* Display Page Table at given addr */
int debug_display_pt_at(int addr)
{
int i, ptr;
xsm_word *word;
ptr = addr;
for (i = 0; i < MAX_NUM_PAGES; i++)
{
printf("VIRT: %d\t\t", i);
word = memory_get_word(ptr);
printf("PHY: %s\t\t", word_get_string(word));
ptr = ptr + 1;
word = memory_get_word(ptr);
printf("AUX: %s\t\n", word_get_string(word));
ptr = ptr + 1;
}
return TRUE;
}
/* Debug pagetable pid command */
int debug_display_pt_pid(int pid)
{
int ptbr_addr = DEBUG_PT_BASE + pid * MAX_NUM_PAGES * 2;
return debug_display_pt_at(ptbr_addr);
}
/* Debug diskmaptable command */
int debug_display_dmt()
{
int pid;
printf("PRIMARY_CORE:\n");
pid = debug_active_process(PRIMARY_CORE);
if (pid < 0)
printf("No active processes.\n");
else
debug_dmt_pid(pid);
printf("SECONDARY_CORE:\n");
pid = debug_active_process(SECONDARY_CORE);
if (pid < 0)
printf("No active processes.\n");
else
debug_dmt_pid(pid);
return TRUE;
}
/* Debug diskmaptable pid command */
int debug_dmt_pid(int pid)
{
int ptr;
xsm_word *word;
ptr = DEBUG_LOC_DISKMAPTABLE + pid * MAX_NUM_PAGES + 2;
word = memory_get_word(ptr++);
printf("Heap 1 in Disk: %s\t", word_get_string(word));
word = memory_get_word(ptr++);
printf("Heap 2 in Disk: %s\n", word_get_string(word));
word = memory_get_word(ptr++);
printf("Code 1 in Disk: %s\t", word_get_string(word));
word = memory_get_word(ptr++);
printf("Code 2 in Disk: %s\n", word_get_string(word));
word = memory_get_word(ptr++);
printf("Code 3 in Disk: %s\t", word_get_string(word));
word = memory_get_word(ptr++);
printf("Code 4 in Disk: %s\n", word_get_string(word));
word = memory_get_word(ptr++);
printf("Stack 1 in Disk: %s\t", word_get_string(word));
word = memory_get_word(ptr++);
printf("Stack 2 in Disk: %s\n", word_get_string(word));
return TRUE;
}
/* Debug resourcetable command */
int debug_display_rt()
{
int pid;
printf("PRIMARY_CORE:\n");
pid = debug_active_process(PRIMARY_CORE);
if (pid < 0)
printf("No active processes.\n");
else
debug_rt_pid(pid);
printf("SECONDARY_CORE:\n");
pid = debug_active_process(SECONDARY_CORE);
if (pid < 0)
printf("No active processes.\n");
else
debug_rt_pid(pid);
return TRUE;
}
/* Debug resourcetable pid command */
int debug_rt_pid(int pid)
{
int ptr, page, rid, i;
xsm_word *word;
page = DEBUG_LOC_PT + pid * PT_ENTRY_SIZE + 11;
word = memory_get_word(page);
page = word_get_integer(word);
if (page < 0 || page >= XSM_MEMORY_NUMPAGES)
{
printf("Invalid User Area Page Number");
return FALSE;
}
ptr = page * XSM_PAGE_SIZE + RESOURCE_OFFSET;
for (i = 0; i < MAX_RESOURCE; ++i)
{
printf("%d. ", i);
word = memory_get_word(ptr++);
rid = word_get_integer(word);
printf("Resource Identifier: ");
switch (rid)
{
case 0:
printf("FILE\t\t");
break;
case 1:
printf("SEMAPHORE\t");
break;
default:
printf("%s\t\t", word_get_string(word));
break;
}
word = memory_get_word(ptr++);
printf("Index of Table Entry: %s\n", word_get_string(word));
}
return TRUE;
}
/* Debug filetable command */
int debug_display_ft()
{
int ptr, i;
xsm_word *word;
ptr = DEBUG_LOC_FILETABLE;
for (i = 0; i < MAX_OPENFILE_NUM; ++i)
{
printf("%d. ", i);
word = memory_get_word(ptr++);
printf("Inode Index: %s\t", word_get_string(word));
word = memory_get_word(ptr++);
printf("Open Instance Count: %s\t", word_get_string(word));
word = memory_get_word(ptr++);
printf("Lseek: %s\n", word_get_string(word));
ptr++; /* Unused field. */
}
return TRUE;
}
/* Debug semtable command */
int debug_display_st()
{
int ptr, i;
xsm_word *word;
ptr = DEBUG_LOC_SEMTABLE;
for (i = 0; i < MAX_SEM_COUNT; ++i)
{
printf("%d. ", i);
word = memory_get_word(ptr++);
printf("Locking PID: %s\t", word_get_string(word));
word = memory_get_word(ptr++);
printf("Process Count: %s\n", word_get_string(word));
ptr += 2; /* Unused field. */
}
return TRUE;
}
/* Debug memfreelist command */
int debug_display_memlist()
{
int i, ptr;
xsm_word *word;
ptr = DEBUG_LOC_MFL;
for (i = 0; i < MAX_MEM_PAGE;)
{
word = memory_get_word(ptr++);
printf("%d\t%s\t\t", i, word_get_string(word));
word = memory_get_word(ptr++);
printf("%d\t%s\t\t", i + 1, word_get_string(word));
word = memory_get_word(ptr++);
printf("%d\t%s\t\t", i + 2, word_get_string(word));
word = memory_get_word(ptr++);
printf("%d\t%s\n", i + 3, word_get_string(word));
i = i + 4;
}
return TRUE;
}
/* Debug filestatus command */
int debug_display_fst()
{
int ptr, i;
xsm_word *word;
ptr = DEBUG_LOC_FILESTATUS;
for (i = 0; i < MAX_FILE_NUM; ++i)
{
printf("%d. ", i);
word = memory_get_word(ptr++);
printf("Locking PID: %s\t", word_get_string(word));
word = memory_get_word(ptr++);
printf("File Open Count: %s\n", word_get_string(word));
ptr += 2; /* Unused field. */
}
return TRUE;
}
/* Debug diskstatus command */
int debug_display_dst()
{
int ptr, i;
xsm_word *word;
ptr = DEBUG_LOC_DISKSTATUS;
word = memory_get_word(ptr++);
printf("Status: %s\n", word_get_string(word));
word = memory_get_word(ptr++);
printf("Load/Store Bit: %s\n", word_get_string(word));
word = memory_get_word(ptr++);
printf("Page Number: %s\n", word_get_string(word));
word = memory_get_word(ptr++);
printf("Block Number: %s\n", word_get_string(word));
word = memory_get_word(ptr++);
printf("PID: %s\n", word_get_string(word));
ptr += 3; /* Unused field. */
return TRUE;
}
/* Debug systemstatus command */
int debug_display_sst()
{
int ptr, i;
xsm_word *word;
ptr = DEBUG_LOC_SYSTEMSTATUS;
word = memory_get_word(ptr++);