10 #include "../procsr3.h" 18 case 01:
case 3:
case 5:
case 7:
case 8:
case 10:
case 12:
21 case 4:
case 6:
case 9:
case 11:
37 if((!
strcmp(parameters[0],
"")) || (!
strcmp(parameters[0],
"\0"))) {
50 if(!
strcmp(parameters[0],
"") || !
strcmp(parameters[0],
"\0")) {
52 }
else if(
strcmp(parameters[0],
"shutdown")==0) {
54 }
else if(
strcmp(parameters[0],
"version")==0) {
56 }
else if(
strcmp(parameters[0],
"time")==0) {
58 }
else if(
strcmp(parameters[0],
"date")==0) {
60 }
else if(
strcmp(parameters[0],
"pcb")==0) {
62 }
else if(
strcmp(parameters[0],
"loadr3")==0) {
64 }
else if(
strcmp(parameters[0],
"mcb")==0) {
105 else if(!
strcmp(parameters[0],
"--showfree")) {
107 }
else if(!
strcmp(parameters[0],
"--showallocated")) {
110 serial_println(
"Invalid parameter, run 'help mcb' to see the valid parameters.");
120 serial_println(
"______________ | _________________________________");
124 serial_println(
"Type 'help [command]' to see what the command does and arguments it requires.");
129 serial_println(
"Allocate memory for MPX. Size of the heap in bytes.");
137 serial_println(
"Allocate memory from heap. Amount of bytes to be allocated from the heap.");
145 serial_println(
"Free a particular block of memory that was previously allocated. Takes in the pointer to an address in memory");
153 serial_println(
"Returns true or false based on whether the heap is empty.");
160 serial_println(
"Show the address and size of the blocks in the free list.");
167 serial_println(
"Show the address and size of the blocks in the allocated list.");
184 printf(
"%sThere are no arguments required.\r\n",
"");
185 printf(
"%sThis will return R1, R2,... showing the current module.\r\n",
"");
218 serial_println(
"ex. 'set time --set[14:20.00]' to set the system time to 2:20.00 PM");
227 serial_println(
"You will be prompted to confirm that you want to shutdown.");
240 if(!
strlen(parameters[0]))
244 serial_println(
"\033[38;2;255;255;0mArguments available: \033[38;2;255;0;0m--set, --get\033[0m");
245 serial_println(
"Enter the command 'help date --get' or 'help date --set'");
247 else if(!
strcmp(parameters[0],
"--set"))
251 serial_println(
"Usage: \033[38;2;255;255;0m 'date --set' \"DD/MM/YYYY\" \033[0m");
253 else if(!
strcmp(parameters[0],
"--get"))
257 serial_println(
"Usage: \033[38;2;255;255;0m 'date --get' \033[0m");
263 if(!
strlen(parameters[0]))
267 serial_println(
"\033[38;2;255;255;0mArguments available: \033[38;2;255;0;0m--set, --get\033[0m");
268 serial_println(
"Enter the command 'help time --get' or 'help time --set'");
270 else if(!
strcmp(parameters[0],
"--set"))
274 serial_println(
"Usage: \033[38;2;255;255;0m 'time --set' \"HH:MM.SS\" \033[0m");
276 else if(!
strcmp(parameters[0],
"--get"))
280 serial_println(
"Usage: \033[38;2;255;255;0m 'time --get' \033[0m");
287 }
else if(!
strcmp(parameters[0],
"--block")) {
289 }
else if(!
strcmp(parameters[0],
"--create")) {
291 }
else if(!
strcmp(parameters[0],
"--delete")) {
293 }
else if(!
strcmp(parameters[0],
"--resume")) {
295 }
else if(!
strcmp(parameters[0],
"--setpriority")) {
297 }
else if(!
strcmp(parameters[0],
"--show")) {
299 }
else if(!
strcmp(parameters[0],
"--showall")) {
301 }
else if(!
strcmp(parameters[0],
"--showblocked")) {
303 }
else if(!
strcmp(parameters[0],
"--showready")) {
305 }
else if(!
strcmp(parameters[0],
"--suspend")) {
307 }
else if(!
strcmp(parameters[0],
"--unblock")) {
310 serial_println(
"Invalid parameter, run 'help pcb' to see the valid parameters.");
318 serial_println(
"____________ | _________________________________");
320 serial_println(
"--create | Creates a new PCB and allocates memory");
321 serial_println(
"--delete | Delete specified PCB and frees memory");
323 serial_println(
"--setpriority | Set/change the priority of the specified PCB");
326 serial_println(
"--showblocked | Show the PCBs in the blocked queue");
329 serial_println(
"--unblock | Moves the specified PCB from the blocked state to ready queue");
331 serial_println(
"Type 'help [command]' to see what the command does and arguments it requires.");
344 serial_println(
"Resume the specified PCB. Removes PCB from suspended queue and places it into the appropriate queue.");
355 serial_println(
"-n/--name 'name of PCB'\n-p/--priority 'priority from 0-9'");
376 serial_println(
"Show all of the processes that are in the ready queue.");
384 serial_println(
"Show all of the processes that are in the blocked queue.");
395 serial_println(
"-n/--name 'the name of the PCB'\n-p/--priority 'priority from 0-9 of pcb'\n-c/--class 'System or User_app'");
400 serial_println(
"Delete the specified PCB and frees memory. Removes the PCB from any queues it is currently in.");
408 serial_println(
"Removes the PCB from current queue and places it into the blocked queue.");
416 serial_println(
"Removes the PCB from the blocked queue and places it into the ready queue.");
437 if(!
strcmp(parameters[0],
"--get")) {
439 }
else if(!
strcmp(parameters[0],
"--set")) {
442 serial_println(
"Check your input, there are only 12 months in a year.");
448 int month=0, day=0, year=0;
450 printf(
"The current date is %d/%d/20%d UTC\r\n", day, month, year);
455 if(!
strlen(parameters[2]) || !
atoi(parameters[0]) || !
atoi(parameters[1]) || !
atoi(parameters[2]))
463 if((
atoi(parameters[0]) > 0) && (daysInMonth >=
atoi(parameters[0]))){
467 printf(
"\033[38;2;255;0;255mTotal days in your selected month are: %d UTC\r\n\033[38;2;255;255;255m", daysInMonth);
480 if(!
strcmp(parameters[0],
"--get")) {
482 }
else if(!
strcmp(parameters[0],
"--set")) {
491 int hour=0, minutes=0, seconds=0;
492 get_time(&hour, &minutes, &seconds);
495 sprintf(buf, 500,
"\033[38;2;255;0;255mThe current time is %d:%d.%d UTC\r\n\033[38;2;255;255;255m", hour, minutes, seconds);
\ 501 if(!
strlen(parameters[2]) || !
atoi(parameters[0]) || !
atoi(parameters[1]) || !
atoi(parameters[2]))
508 if(
atoi(parameters[0]) < 0 ||
atoi(parameters[0]) > 24 ||
atoi(parameters[1]) < 0 ||
atoi(parameters[1]) > 59 ||
atoi(parameters[2]) < 0 ||
atoi(parameters[2]) > 59) {
526 sprintf(buf, 500,
"\033[38;2;255;0;255mShutdown called\r\n\033[38;2;255;255;255m");
\ 530 if(
strcmp(parameters[1],
"")==0) {
538 if(
strcmp(in_string,
"y")==0)
544 else if (
strcmp(in_string,
"n")==0)
559 if(!
strcmp(parameters[0],
"--suspend")) {
564 (!
strcmp(parameters[1],
"-n") || !
strcmp(parameters[1],
"--name"))) {
573 }
else if(!
strcmp(parameters[0],
"--resume")) {
578 (!
strcmp(parameters[1],
"-n") || !
strcmp(parameters[1],
"--name"))) {
587 }
else if(!
strcmp(parameters[0],
"--setpriority")) {
591 if((!
strcmp(parameters[1],
"--name") || !
strcmp(parameters[1],
"-n")) && (!
strcmp(parameters[3],
"--priority") || !
strcmp(parameters[3],
"-p"))) {
593 }
else if((!
strcmp(parameters[3],
"--name") || !
strcmp(parameters[3],
"-n")) && (!
strcmp(parameters[1],
"--priority") || !
strcmp(parameters[1],
"-p"))) {
596 printf(
"%sProper command: 'pcb --setpriority -n \"pcb name\" -p \"pcb priority\"",
"");
599 }
else if(!
strcmp(parameters[0],
"--show")) {
601 printf(
"Missing name of pcb to show%s.\n",
"");
603 if(!
strcmp(parameters[1],
"-n") || !
strcmp(parameters[1],
"--name")) {
606 printf(
"Type 'help pcb --show' to see the arguments required.%s\n",
"");
609 }
else if(!
strcmp(parameters[0],
"--showall")) {
614 printf(
"No arguments required%s\n",
"");
617 }
else if(!
strcmp(parameters[0],
"--showready")) {
622 printf(
"No arguments required%s\n",
"");
625 }
else if(!
strcmp(parameters[0],
"--showblocked")) {
630 printf(
"No arguments required%s\n",
"");
633 }
else if(!
strcmp(parameters[0],
"--create")) {
635 printf(
"Missing parameters of pcb to create%s.\n",
"");
637 char *
procName;
char * procPrio;
char * procClass;
639 for(;!
isEmpty(¶meters[i]); i++) {
640 if(!
strcmp(parameters[i],
"--name") || !
strcmp(parameters[i],
"-n")) {
642 procName = parameters[i];
643 }
else if(!
strcmp(parameters[i],
"--priority") || !
strcmp(parameters[i],
"-p")) {
645 procPrio = parameters[i];
646 }
else if(!
strcmp(parameters[i],
"--class") || !
strcmp(parameters[i],
"-c")) {
648 procClass = parameters[i];
652 createPCB(procName, procPrio, procClass);
654 }
else if(!
strcmp(parameters[0],
"--delete")) {
656 printf(
"Missing name of pcb to create%s.\n",
"");
658 if(!
strcmp(parameters[1],
"-n") || !
strcmp(parameters[1],
"--name")) {
661 printf(
"Type 'help pcb --delete' to see the arguments required.%s\n",
"");
664 }
else if(!
strcmp(parameters[0],
"--block")) {
666 printf(
"Missing name of pcb to create%s.\n",
"");
668 if(!
strcmp(parameters[1],
"-n") || !
strcmp(parameters[1],
"--name")) {
671 printf(
"Type 'help pcb --block' to see the arguments required.%s\n",
"");
674 }
else if(!
strcmp(parameters[0],
"--unblock")) {
676 printf(
"Missing name of pcb to create%s.\n",
"");
678 if(!
strcmp(parameters[1],
"-n") || !
strcmp(parameters[1],
"--name")) {
681 printf(
"Type 'help pcb --unblock' to see the arguments required.%s\n",
"");
748 printf(
"\n\nReady Queue:%s",
"\r\n");
750 printf(
"\n\nBlocked Queue:%s",
"\r\n");
752 printf(
"\n\nSuspended-Ready Queue:%s",
"\r\n");
754 printf(
"\n\nSuspended-Blocked Queue:%s",
"\r\n");
761 printf(
"%s",
"\n\nReady Queue:\n");
768 printf(
"%s",
"\n\nBlocked Queue:\n");
773 int createPCB(
const char* pcbName,
const char* pcbPriority,
const char* pcbClass) {
821 asm volatile(
"int $60");
837 cp->
ebp = (
u32int )( newPCB->stackBase );
838 cp->
esp = (
u32int )( newPCB->stackTop );
850 cp->
ebp = (
u32int )( newPCB->stackBase );
851 cp->
esp = (
u32int )( newPCB->stackTop );
864 cp->
ebp = (
u32int )( newPCB->stackBase );
865 cp->
esp = (
u32int )( newPCB->stackTop );
877 cp->
ebp = (
u32int )( newPCB->stackBase );
878 cp->
esp = (
u32int )( newPCB->stackTop );
890 cp->
ebp = (
u32int )( newPCB->stackBase );
891 cp->
esp = (
u32int )( newPCB->stackTop );
931 if(!
strcmp(parameters[0],
"--showfree")) {
932 printf(
"%s",
"free list\r\n")
934 }
else if(!
strcmp(parameters[0],
"--showallocated")) {
935 printf(
"%s",
"Alloc list\r\n")
937 }
else if(!
strcmp(parameters[0],
"--showall")) {
938 printf(
"%s",
"Free list\r\n")
940 printf(
"%s",
"Alloc list\r\n")
942 }
else if(!
strcmp(parameters[0],
"--testheap")) {
e_PCB_ERROR_CODE_t prevPCBError
void set_time(int hours, int minutes, int seconds)
set_time sets the RTC time. Military time
linkedList_t mcbAllocList
int deletePCB(char parameters[][MAX_LENGTH])
deletePCB deletes the PCB requested by the user.
void helpMcbPrint()
Prints the help menu for all mcb functions.
void helpMCB(char parameters[][MAX_LENGTH])
The command handler for mcb's checking for valid input.
void printPCBFunc(void *pcb)
printPCBFunc prints the status of a process
const char * errorToString(e_PCB_ERROR_CODE_t error)
errorToString creates a string form of the error passed in
int getNumDaysInMonth(int month, int year)
getNumDaysInMonth is a helper function to allow the easy retrieval of days in a month based on the mo...
void helpResumePCB()
helpResumePCB prints out the parameters and usage of the resume pcb command.
void helpSuspendPCB()
helpSuspendPCB prints the help instructions for the suspendPCB command.
void getDate()
getDate Get the current date from the system.
void set_date(int day, int month, int year)
set_date sets the RTC Date
int createPCB(const char *pcbName, const char *pcbPriority, const char *pcbClass)
createPCB creates a new PCB and allocates memory for the PCB.
The s_processContext struct defines the context that each process stores .
void helpGetTime()
helpGetTime prints the help instructions for get time. Tells the user what the commands and arguments...
int blockPCB(char parameters[][MAX_LENGTH])
blockPCB blocks the specified PCB
void helpSetDate()
helpSetDate prints the help instructions for set date. Tells the user what the command and arguments ...
#define printf(format,...)
printf is simply a wrapper macro around sprintf with built in terminal print builtin needs to be a ma...
pcb_t * findPCB(const char *processName)
findPCB will search all queues for the PCB with the input name
int time(char parameters[][MAX_LENGTH])
int serial_print(const char *msg)
void helpUnblockPCB()
helpUnblockPCB prints out the parameters and usage for unblocking a PCB.
void helpBlockPCB()
helpBlockPCB prints out the parameters and usage for blocking a PCB.
void helpMCBAllocate()
Prints the details for Allocating an mcb.
void helpMCBIsEmpty()
Prints details for IsEmpty func.
int showPCB(char parameters[][MAX_LENGTH])
showPCB shows the process information for the process requested by the user
e_PCB_ERROR_CODE_t changeProcessPriority(const char *procName, processPriority_t newPriority)
changeProcessPriority
void helpTime(char parameters[][MAX_LENGTH])
helpTime prints out the help information for time, for time –set and time –get
void helpSetPriority()
helpSetPriority prints out to console the parameters and usage for –setpriority. ...
int date(char parameters[][MAX_LENGTH])
void helpShowReadyProcesses()
helpShowReadyProcesses shows the parameters and usage for showing ready PCBs.
int isEmpty(char parameters[][MAX_LENGTH])
void help()
help prints out a list of all possible commands and a brief description of what they do...
linkedList_t blockedQueue
int mcbFunc(char parameters[][MAX_LENGTH])
takes in whatever you are looking for and checks to see if it can be done for mcb ...
e_PCB_ERROR_CODE_t freePCB(pcb_t *pcbToFree)
freePCB free all associated memory with the PCB, including the stack and other pointers ...
int suspendPCB(char parameters[][MAX_LENGTH])
suspendPCB suspends the pcb passed in by the user
char in_string[MAX_LENGTH]
void helpMCBShowAllocated()
Prints details for showing all the allocated memory blocks in the heap.
void printList(linkedList_t *list)
test function to show list functionality. uses const char* as test data
void helpLoadR3()
helpLoadR3 prints out the help commands for helpLoadR3 Loads all of the processes from procsr3 ...
void helpGetDate()
helpGetDate prints the help instructions for get date. Tells the user what the command and arguments ...
void helpCreatePCB()
helpCreatePCB prints out the parameters and usage for createPCB.
int resumePCB(char parameters[][MAX_LENGTH])
resumePCB resumes the PCB passed in by the user
void getTime()
getTime this function has the side-effect of printing the current time to the terminal.
int yield()
stops the exection of commhand and executes each process in the ready queue
int version(char parameters[][MAX_LENGTH])
version prints out the current version of the operating system. It will print out R1...
void helpPcbPrint()
helpPcbPrint prints out the commands for PCBs.
int shutdownFunc(char parameters[][MAX_LENGTH])
shutdownFunc shuts down the OS.
linkedList_t suspendedBlockedQueue
int loadr3(char parameters[][MAX_LENGTH])
loads all processes into memory in a suspended ready state at any priority of the users choosing ...
void helpMCBInitHeap()
prints the all details about the initheap func
void setDate(char parameters[][MAX_LENGTH])
setDate sets the system date using the input from the user.
void get_date(int *day, int *month, int *year)
get_date this function will retrieve the system date and place in three pointers
int pcbFunc(char parameters[][MAX_LENGTH])
takes in parameters and makes sure its valid then runs what you want to.
int serial_println(const char *msg)
void helpShowAllProcesses()
helpShowAllProcesses shows all processes in the system. Takes in no parameters and prints out to the ...
void helpPcb(char parameters[][MAX_LENGTH])
helpPcb takes in the command to print the help information for. Calls the proper function to print th...
int strlen(const char *s)
strlen returns the length of a string
void helpDeletePCB()
helpDeletePCB prints out the parameters and usage for deleting a PCB.
int showReadyProcesses(char parameters[][MAX_LENGTH])
showReadyProcesses shows all processes that are ready, in the ready queue (linked list)...
e_PROCESS_CLASS_t stringToClass(const char *stringifiedClass)
stringToClass returns the enum representation of a string
int atoi(const char *s)
atoi converts and ASCII string to an integer
void helpShutdown()
helpShutdown prints the help instructions for set date. Tells the user what the command and arguments...
int showBlockedProcesses(char parameters[][MAX_LENGTH])
showBlockedProcesses shows all processes that are blocked.
pcb_t * setupPCB(const char *processName, e_PROCESS_CLASS_t processClass, processPriority_t processPriority)
setupPCB calls allocatePCB, initializes the PCB with the arguments and sets it state to ready ...
e_PCB_ERROR_CODE_t changeProcessSuspensionState(const char *processName, e_PROCESS_SUSPENSION_STATE_t suspensionState)
changeProcessSuspensionState
void helpDate(char parameters[][MAX_LENGTH])
helpDate prints out the help information for date, for date –set and date –get
void helpSetTime()
helpSetTime prints the help instructions for set time. Tells the user what the command and arguments ...
e_PCB_ERROR_CODE_t
The e_PCB_ERROR_CODE_t enum defines the return status of functions working with PCBs.
e_PCB_ERROR_CODE_t changeProcessState(const char *processName, e_PROCESS_STATE_t state)
changeProcessState changes the state of the process being called
void heapTest()
heapTest test function to create sample mcbs.
int showAllProcesses(char parameters[][MAX_LENGTH])
showAllProcesses shows all processes in the system.
char * serial_poll(char in_string[MAX_LENGTH])
int unblockPCB(char parameters[][MAX_LENGTH])
unblockPCB unblocks the specified PCB.
void get_time(int *hours, int *minutes, int *seconds)
get_time this function will retrieve the system time and place it in three pointers. Military time
linkedList_t suspendedReadyQueue
int sprintf(char *str, int bufLength, const char *format,...) __attribute__((format(printf
sprintf print with format to specified string buffer
int helpGetVersion()
helpGetVersion prints the help instructions for version. Tells the user what the command and argument...
int setPriority(char *procName, char *procPrio)
setPriority sets the priority of a particular process
int strcmp(const char *s1, const char *s2)
strcmp compares two strings.
void helpMCBShowFree()
Prints details for showing all the free memory blocks in the heap.
void * memset(void *s, int c, size_t n)
memset Set a region of memory.
void helpMCBFreeMem()
Prints the details for freeing an mcb.
void setTime(char parameters[][MAX_LENGTH])
setTime sets the current system time from the users input.
void helpVersion()
helpVersion prints the help instructions for using the version command. No arguments are required...
void helpShowBlockedProcesses()
helpShowBlockedProcesses shows the parameters and usage for showing the blocked PCBs.
int helpFunc(char parameters[][MAX_LENGTH])
helpFunc calls the other help functions