Skip to content

Commit c65507c

Browse files
committed
Basic fuctionalities in Debug environment
1 parent 6fd6809 commit c65507c

File tree

2 files changed

+55
-68
lines changed

2 files changed

+55
-68
lines changed

data.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,8 @@
4040
#define T3 27
4141

4242
#define BP_REG 28
43-
#define IP_REG 29
44-
#define SP_REG 30
43+
#define SP_REG 29
44+
#define IP_REG 30
4545
#define PTBR_REG 31
4646
#define PTLR_REG 32
4747
#define EFR_REG 33

debug.c

+53-66
Original file line numberDiff line numberDiff line change
@@ -36,35 +36,19 @@ int runCommand(char command[])
3636
{
3737
char *name = strtok(command, " ");
3838
char *arg1, *arg2, *arg3;
39-
int arg1value, arg2value;
40-
41-
39+
int arg1value, arg2value;
4240
if(strcmp(name,"help")==0) //"help" to display all commands
4341
{
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");
6450
printf("help\n");
65-
}
66-
67-
51+
}
6852
else if (strcmp(name,"step") == 0 || strcmp(name,"s") == 0) //Single Stepping
6953
{
7054
step_flag = ENABLE;
@@ -75,7 +59,7 @@ int runCommand(char command[])
7559
step_flag = DISABLE;
7660
return 1;
7761
}
78-
else if (strcmp(name,"reg")==0) //Prints the registers.
62+
else if (strcmp(name,"reg")==0 || strcmp(name,"r")==0) //Prints the registers.
7963
{
8064
arg1 = strtok(NULL, " ");
8165
arg2 = strtok(NULL, " ");
@@ -85,7 +69,7 @@ int runCommand(char command[])
8569
{
8670
arg1value = getRegArg(arg1);
8771
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);
8973
else
9074
printRegisters(arg1value);
9175
}
@@ -94,7 +78,7 @@ int runCommand(char command[])
9478
arg1value = getRegArg(arg1);
9579
arg2value = getRegArg(arg2);
9680
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);
9882
else
9983
{
10084
if(arg1value > arg2value) //swap them
@@ -110,53 +94,44 @@ int runCommand(char command[])
11094
}
11195
}
11296
}
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);*/
14197
}
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
14399
{
144100
arg1 = strtok(NULL, " ");
145101
arg2 = strtok(NULL, " ");
146102
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);
148104
else if(arg2 == NULL)
149105
{
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);
151111
}
152112
else
153113
{
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);
157132
}
158133
}
159-
else if (strcmp(name,"exit")==0) //Exits the interface
134+
else if (strcmp(name,"exit")==0 || strcmp(name,"e")==0) //Exits the interface
160135
exit(0);
161136
else
162137
printf("Unknown command \"%s\". See \"help\" for more information",name);
@@ -171,10 +146,10 @@ int getRegArg(char *arg)
171146
int argvalue;
172147
if(strcmp(arg,"BP") == 0 || strcmp(arg,"bp") == 0)
173148
return(BP_REG);
174-
else if(strcmp(arg,"IP") == 0 || strcmp(arg,"ip") == 0)
175-
return(IP_REG);
176149
else if(strcmp(arg,"SP") == 0 || strcmp(arg,"sp") == 0)
177150
return(SP_REG);
151+
else if(strcmp(arg,"IP") == 0 || strcmp(arg,"ip") == 0)
152+
return(IP_REG);
178153
else if(strcmp(arg,"PTBR") == 0 || strcmp(arg,"ptbr") == 0)
179154
return(PTBR_REG);
180155
else if(strcmp(arg,"PTLR") == 0 || strcmp(arg,"ptlr") == 0)
@@ -246,3 +221,15 @@ void printRegisters(int flag)
246221
}while(i<NUM_REGS && flag == -1);
247222
printf("\n");
248223
}
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

Comments
 (0)