@@ -36,35 +36,19 @@ int runCommand(char command[])
36
36
{
37
37
char * name = strtok (command , " " );
38
38
char * arg1 , * arg2 , * arg3 ;
39
- int arg1value , arg2value ;
40
-
41
-
39
+ int arg1value , arg2value ;
42
40
if (strcmp (name ,"help" )== 0 ) //"help" to display all commands
43
41
{
44
- /*printf("\n fdisk \n\t Format the disk with XFS filesystem\n\n");
45
- printf(" load --exec <pathname> \n\t Loads an executable file to XFS disk \n\n");
46
- printf(" load --init <pathname> \n\t Loads INIT code to XFS disk \n\n");
47
- printf(" load --data <pathname> \n\t Loads a data file to XFS disk \n\n");
48
- printf(" load --os <pathname> \n\t Loads OS startup code to XFS disk \n\n");
49
- printf(" load --int=timer <pathname>\n\t Loads Timer Interrupt routine to XFS disk \n\n");
50
- printf(" load --int=[1-7] <pathname>\n\t Loads the specified Interrupt routine to XFS disk \n\n");
51
- printf(" load --exhandler <pathname> \n\t Loads exception handler routine to XFS disk \n\n");
52
- printf(" rm --exec <xfs_filename>\n\t Removes an executable file from XFS disk \n\n");
53
- printf(" rm --init <xfs_filename> \n\t Removes INIT code from XFS disk \n\n");
54
- printf(" rm --data <xfs_filename>\n\t Removes a data file from XFS disk \n\n");
55
- printf(" rm --os \n\t Removes OS startup code from XFS disk \n\n");
56
- printf(" rm --int=timer \n\t Removes the Timer Interrupt routine from XFS disk \n\n");
57
- printf(" rm --int=[1-7] \n\t Removes the specified Interrupt routine from XFS disk \n\n");
58
- printf(" rm --exhandler\n\t Removes the exception handler routine from XFS disk \n\n");
59
- printf(" ls \n\t List all files\n\n");
60
- printf(" df \n\t Display free list and free space\n\n");
61
- printf(" cat <xfs_filename> \n\t to display contents of a file\n\n");
62
- printf(" copy <start_blocks> <end_block> <unix_filename>\n\t Copies contents of specified range of blocks to a UNIX file.\n\n");
63
- printf(" exit \n\t Exit the interface\n");*/
42
+ printf ("\n step / s\n\t Single step the exection\n\n" );
43
+ printf (" continue / c\n\t Continue to next breakpoint \n\n" );
44
+ printf (" reg / r \n\t Prints the value of all registers \n\n" );
45
+ printf (" reg / r <register_name> \n\t Prints the value of a particular register \n\n" );
46
+ printf (" reg / r <register_name1> <register_name2> \n\t Prints the value of all registers from <register_name1> to <register_name2> \n\n" );
47
+ printf (" mem / m <page_num> \n\t Displays contents of a memory page \n\n" );
48
+ printf (" mem / m <page_num1> <page_num2> \n\t Displays contents of memory pages from <page_num1> to <page_num2>\n\n" );
49
+ printf (" exit \n\t Exit the interface and Halt the machine\n" );
64
50
printf ("help\n" );
65
- }
66
-
67
-
51
+ }
68
52
else if (strcmp (name ,"step" ) == 0 || strcmp (name ,"s" ) == 0 ) //Single Stepping
69
53
{
70
54
step_flag = ENABLE ;
@@ -75,7 +59,7 @@ int runCommand(char command[])
75
59
step_flag = DISABLE ;
76
60
return 1 ;
77
61
}
78
- else if (strcmp (name ,"reg" )== 0 ) //Prints the registers.
62
+ else if (strcmp (name ,"reg" )== 0 || strcmp ( name , "r" ) == 0 ) //Prints the registers.
79
63
{
80
64
arg1 = strtok (NULL , " " );
81
65
arg2 = strtok (NULL , " " );
@@ -85,7 +69,7 @@ int runCommand(char command[])
85
69
{
86
70
arg1value = getRegArg (arg1 );
87
71
if (arg1value == -1 )
88
- printf ("Illegal argument for reg . See \"help\" for more information" );
72
+ printf ("Illegal argument for \"%s\" . See \"help\" for more information" , name );
89
73
else
90
74
printRegisters (arg1value );
91
75
}
@@ -94,7 +78,7 @@ int runCommand(char command[])
94
78
arg1value = getRegArg (arg1 );
95
79
arg2value = getRegArg (arg2 );
96
80
if (arg1value == -1 || arg2value == -1 )
97
- printf ("Illegal argument for reg . See \"help\" for more information" );
81
+ printf ("Illegal argument for \"%s\" . See \"help\" for more information" , name );
98
82
else
99
83
{
100
84
if (arg1value > arg2value ) //swap them
@@ -110,53 +94,44 @@ int runCommand(char command[])
110
94
}
111
95
}
112
96
}
113
- return 0 ;
114
- /*char *int_command = strtok(arg1, "=");
115
- char *intType = strtok(NULL, "=");
116
- char *fileName = arg2;;
117
-
118
- if(fileName!=NULL)
119
- fileName[50] = '\0';
120
- else
121
- {
122
- printf("Missing <pathname> for load. See \"help\" for more information");
123
- return;
124
- }
125
- if (strcmp(arg1,"--exec")==0)
126
-
127
- else if (strcmp(arg1,"--init")==0)
128
-
129
- else if (strcmp(arg1,"--data")==0)
130
- {
131
- }
132
- else if (strcmp(arg1,"--os")==0)
133
-
134
- else if (strcmp(arg1,"--int")==0)
135
- {
136
- }
137
- else if (strcmp(arg1,"--exhandler")==0)
138
-
139
- else
140
- printf("Invalid argument \"%s\" for load. See \"help\" for more information",arg1);*/
141
97
}
142
- else if (strcmp (name ,"mem" )== 0 ) //displays pages in memory
98
+ else if (strcmp (name ,"mem" )== 0 || strcmp ( name , "m" ) == 0 ) //displays pages in memory
143
99
{
144
100
arg1 = strtok (NULL , " " );
145
101
arg2 = strtok (NULL , " " );
146
102
if (arg1 == NULL )
147
- printf ("Insufficient argument for \"mem \". See \"help\" for more information" );
103
+ printf ("Insufficient argument for \"%s \". See \"help\" for more information" , name );
148
104
else if (arg2 == NULL )
149
105
{
150
- printf ("mem" );
106
+ arg1value = atoi (arg1 );
107
+ if (arg1value > 0 && arg1value < NUM_PAGES )
108
+ printMemory (arg1value );
109
+ else
110
+ printf ("Illegal argument for \"%s\". See \"help\" for more information" ,name );
151
111
}
152
112
else
153
113
{
154
- int startPage = atoi (arg1 );
155
- int endPage = atoi (arg2 );
156
- //copyBlocksToFile (startBlock,endBlock,fileName);
114
+ arg1value = atoi (arg1 );
115
+ arg2value = atoi (arg2 );
116
+ if (arg1value > arg2value ) //swap them
117
+ {
118
+ arg1value = arg1value + arg2value ;
119
+ arg2value = arg1value - arg2value ;
120
+ arg1value = arg1value - arg2value ;
121
+ }
122
+ if (arg1value > 0 && arg2value < NUM_PAGES )
123
+ {
124
+ while (arg1value <= arg2value )
125
+ {
126
+ printMemory (arg1value );
127
+ arg1value ++ ;
128
+ }
129
+ }
130
+ else
131
+ printf ("Illegal argument for \"%s\". See \"help\" for more information" ,name );
157
132
}
158
133
}
159
- else if (strcmp (name ,"exit" )== 0 ) //Exits the interface
134
+ else if (strcmp (name ,"exit" )== 0 || strcmp ( name , "e" ) == 0 ) //Exits the interface
160
135
exit (0 );
161
136
else
162
137
printf ("Unknown command \"%s\". See \"help\" for more information" ,name );
@@ -171,10 +146,10 @@ int getRegArg(char *arg)
171
146
int argvalue ;
172
147
if (strcmp (arg ,"BP" ) == 0 || strcmp (arg ,"bp" ) == 0 )
173
148
return (BP_REG );
174
- else if (strcmp (arg ,"IP" ) == 0 || strcmp (arg ,"ip" ) == 0 )
175
- return (IP_REG );
176
149
else if (strcmp (arg ,"SP" ) == 0 || strcmp (arg ,"sp" ) == 0 )
177
150
return (SP_REG );
151
+ else if (strcmp (arg ,"IP" ) == 0 || strcmp (arg ,"ip" ) == 0 )
152
+ return (IP_REG );
178
153
else if (strcmp (arg ,"PTBR" ) == 0 || strcmp (arg ,"ptbr" ) == 0 )
179
154
return (PTBR_REG );
180
155
else if (strcmp (arg ,"PTLR" ) == 0 || strcmp (arg ,"ptlr" ) == 0 )
@@ -246,3 +221,15 @@ void printRegisters(int flag)
246
221
}while (i < NUM_REGS && flag == -1 );
247
222
printf ("\n" );
248
223
}
224
+
225
+ /*
226
+ * This fuction prints the memory page passed as argument.
227
+ */
228
+ void printMemory (int page_no )
229
+ {
230
+ int word_no ;
231
+ printf ("Page No : %d\n" ,page_no );
232
+ for (word_no = 0 ; word_no < PAGE_SIZE ; word_no ++ )
233
+ printf ("%d: %s \t\t" , word_no , page [page_no ].word [word_no ]);
234
+ printf ("\n\n" );
235
+ }
0 commit comments