@@ -8,6 +8,7 @@ void initialize_debug()
8
8
{
9
9
db_mode = DISABLE ;
10
10
step_flag = DISABLE ;
11
+ watch_flag = DISABLE ;
11
12
bzero (command ,COMMAND_LENGTH );
12
13
bzero ( prev_command , COMMAND_LENGTH );
13
14
}
@@ -58,6 +59,7 @@ int runCommand(char command[])
58
59
char * name = strtok (command , " " );
59
60
char * arg1 , * arg2 , * arg3 ;
60
61
int arg1value , arg2value ;
62
+ struct address translatedAddr ;
61
63
if (strcmp (name ,"help" )== 0 || strcmp (name ,"h" )== 0 ) //"help" to display all commands
62
64
{
63
65
printf ("\n step / s\n\t Single step the exection\n\n" );
@@ -75,7 +77,7 @@ int runCommand(char command[])
75
77
printf (" memfreelist / mf \n \t Displays the Memory Free List\n\n" );
76
78
printf (" diskfreelist / df \n \t Displays the Memory copy of Disk Free List\n\n" );
77
79
printf (" fat \n \t Displays the Memory Copy of File Allocation Table\n\n" );
78
- printf (" word / w <register/ address> \n \t Displays the Memory Copy of File Allocation Table \n\n" );
80
+ printf (" location / l < address> \n \t Displays the content at memory address (Translation takes place in USER mode) \n\n" );
79
81
printf (" exit / e \n\t Exit the interface and Halt the machine\n" );
80
82
printf (" help / h\n" );
81
83
}
@@ -236,8 +238,22 @@ int runCommand(char command[])
236
238
printDiskFreeList ();
237
239
else if (strcmp (name ,"fat" )== 0 ) //displays File Allocation Table
238
240
printFAT ();
239
- else if (strcmp (name ,"word" )== 0 || strcmp (name ,"w" )== 0 ) //displays a word
240
- printFAT ();
241
+ else if (strcmp (name ,"location" )== 0 || strcmp (name ,"l" )== 0 ) //displays a content of a memory location
242
+ {
243
+ arg1 = strtok (NULL , " " );
244
+ if (arg1 == NULL )
245
+ {
246
+ printf ("Insufficient argument for \"%s\". See \"help\" for more information" ,name );
247
+ return -1 ;
248
+ }
249
+ translatedAddr = translate_debug (atoi (arg1 ));
250
+ if (getType (arg1 ) == TYPE_STR || (translatedAddr .page_no == -1 && translatedAddr .word_no == -1 ) )
251
+ {
252
+ printf ("Illegal argument for \"%s\". See \"help\" for more information" ,name );
253
+ return -1 ;
254
+ }
255
+ printLocation (translatedAddr );
256
+ }
241
257
else if (strcmp (name ,"exit" )== 0 || strcmp (name ,"e" )== 0 ) //Exits the interface
242
258
exit (0 );
243
259
else
@@ -469,3 +485,45 @@ void printPageTable(int ptbr)
469
485
counter ++ ;
470
486
}
471
487
}
488
+
489
+ /*
490
+ * This function translates an address without
491
+ * invoking execution on errors.
492
+ * returns page_no and word_no as -1 on failure
493
+ */
494
+ struct address translate_debug (int virtual_addr ) {
495
+ struct address resultant_addr ;
496
+ resultant_addr .page_no = -1 ;
497
+ resultant_addr .word_no = -1 ;
498
+ if (mode == USER_MODE )
499
+ {
500
+ int page_entry ;
501
+ if (getType (reg [PTBR_REG ]) == TYPE_STR || getType (reg [PTLR_REG ]) == TYPE_STR || virtual_addr < 0
502
+ || virtual_addr >= getInteger (reg [PTLR_REG ]) * PAGE_SIZE )
503
+ return resultant_addr ;
504
+ page_entry = getInteger (reg [PTBR_REG ]) + (virtual_addr / PAGE_SIZE ) * 2 ;
505
+ if (page [(page_entry + 1 ) / PAGE_SIZE ].word [(page_entry + 1 ) % PAGE_SIZE ][1 ] == VALID )
506
+ {
507
+ resultant_addr .page_no = getInteger (page [page_entry / PAGE_SIZE ].word [page_entry % PAGE_SIZE ] );
508
+ resultant_addr .word_no = virtual_addr % PAGE_SIZE ;
509
+ page [(page_entry + 1 ) / PAGE_SIZE ].word [(page_entry + 1 ) % PAGE_SIZE ][0 ] = REFERENCED ;
510
+ }
511
+ return resultant_addr ;
512
+ }
513
+ else
514
+ {
515
+ if ( virtual_addr < 0 || virtual_addr >= SIZE_OF_MEM )
516
+ return resultant_addr ;
517
+ resultant_addr .page_no = virtual_addr / PAGE_SIZE ;
518
+ resultant_addr .word_no = virtual_addr % PAGE_SIZE ;
519
+ return resultant_addr ;
520
+ }
521
+ }
522
+
523
+ /*
524
+ * This function prints the memory location
525
+ */
526
+ void printLocation (struct address translatedAddr )
527
+ {
528
+ printf ("%s\n" , page [translatedAddr .page_no ].word [translatedAddr .word_no ]);
529
+ }
0 commit comments