Answer To: Operating Systems COMP 310 – ECSE 427 McGill University Vybihal Assignment #2 Page 1 of 6 Assignment...
Pratik answered on Feb 25 2021
Kernel/kernel.h
#include
//#include "pcb.h"
void addToReady(struct PCB *p);
void myinit(FILE *p);
void scheduler();
void initKernel();
void init();
Kernel/mykernel
Kernel/README.md
#KERNEL
The folder contains all the files required for a kernel.
To build the kernel use the command -
gcc -o mykernel shell.c interpreter.c shellmemory.c kernel.c cpu.c pcb.c ram.c
##Run the program
Usage - ./mykernel
The folder also contains TESTFILE.txt, it can be used as
./mykernel < TESTFILE.txt
##Learning Programming
Please refer to the main() function in the kernel.c file
Kernel/prog2.txt
set a 100
print b
set b 250
print b
Kernel/ram.h
#include
void initRAM();
void addToRAM(FILE *p);
void removeMemory(FILE *p);
Kernel/interpreter.c
#include
#include
#include
#include "shellmemory.h"
#include "shell.h"
#include "kernel.h"
int run(char *filename) {
FILE *ptr;
char buffer[1000], buf0[100], buf1[100], buf2[100];
int result = 0;
ptr = fopen(filename,"rt");
if (ptr == NULL) return 4; // file not found
fgets(buffer,999,ptr);
while(!feof(ptr)) {
if (strlen(buffer)>1) result = prompt(buffer);
if (result == 99) break;
fgets(buffer,999,ptr);
}
fclose(ptr);
if (result == 99) return 99;
return 0;
}
int exec(char buf1[],char buf2[],char buf3[])
{
FILE *ptr1,*ptr2,*ptr3;
ptr1=ptr2=ptr3=NULL;
if(strcmp(buf1,buf2)==0)
{
printf("Error : Script %s already loaded\n",buf1);
buf2="\0";
}
else if(strcmp(buf1,buf3)==0)
{
printf("Error : Script %s already loaded\n",buf1);
buf3="\0";
}
else if((strlen(buf2)>0)&&(strcmp(buf2,buf3)==0))
{
printf("Error : Script %s already loaded\n",buf2);
buf3="\0";
}
ptr1 = fopen(buf1,"rt");
if(strlen(buf2)>1)
ptr2 = fopen(buf2,"rt");
if(strlen(buf3)>1)
ptr3 = fopen(buf3,"rt");
if(ptr1==NULL) return 4;
myinit(ptr1);
if(ptr2!=NULL)
myinit(ptr2);
if(ptr3!=NULL)
myinit(ptr3);
scheduler();
return 0;
}
int interpreter(char buf0[], char buf1[], char buf2[],char buf3[]) {
int result = 0; // no errors
if (strcmp(buf0,"help")==0) {
printf("Legal commands:\n");
printf("help display this help\n");
printf("quit exits the shell\n");
printf("set VAR STRING assign STRING to VAR\n");
printf("print VAR display contents of VAR\n");
printf("run SCRIPT.TXT interpret SCRIPT.TXT\n");
printf("exec prog1.txt [prog2.txt] [prog3.txt]\n");
result = 0;
}
else if (strcmp(buf0,"quit")==0) {
result = 99; // exit shell code
}
else if (strcmp(buf0,"set")==0) {
if (strlen(buf1)<1 || strlen(buf2)<1) return 1; // set error
add(strdup(buf1), strdup(buf2));
}
else if (strcmp(buf0,"print")==0) {
if (strlen(buf1)<1) return 2; // print error
printf("%s\n", get(buf1));
}
else if (strcmp(buf0,"run")==0) {
if (strlen(buf1)<1) return 3; // run error
result = run(buf1);
}
else if(strcmp(buf0,"exec")==0){
if (strlen(buf1)<1) return 5; // exec error
result = exec(buf1,buf2,buf3);
}
else {
result = 98; // command does not exist
}
return result;
}
Kernel/shell.c
#include
#include
#include...