Esempio n. 1
0
void handleTimerInterrupt(int segment, int stackPointer){
    struct PCB *pcb ;
    struct PCB *head;
    
    setKernelDataSegment();
    pcb = getFreePCB();
    
    if(pcb->state != DEFUNCT){
        
    }
    pcb->stackPointer = stackPointer;
    pcb->state = READY;
    addToReady(pcb);
    
    head = removeFromReady();
    restoreDataSegment();
    
    setKernelDataSegment();
    if(head == NULL){
        head = idleProc;
    }
    
    head->state = RUNNING;
    restoreDataSegment();

    setKernelDataSegment();
    running = head;
    restoreDataSegment();
    //printString("tic");
    returnFromTimer(head->segment, head->stackPointer);
}
Esempio n. 2
0
void printProcTable() {
  char errorMessage[10];
  char number[10];
  char newline[3];
  char programBuffer[13312];
  ProcEntry te[PROC_ENTRY_NUM];
  int i, t, current, curProcUser;

  /* ------------ print proc table out */
  for (i = 0; i < PROC_ENTRY_NUM; i++) {
    setKernelDataSegment();
    t = procTable[i].active;
    restoreDataSegment(); 
    te[i].active = t ;
    setKernelDataSegment(); 
    t = procTable[i].sp;
    restoreDataSegment();
    te[i].sp = t;
  }

  setKernelDataSegment(); 
  t = currentProcess;
  restoreDataSegment();
  curProcUser = t;

  errorMessage[0] = ' ';
  errorMessage[1] = ':';
  errorMessage[2] = ' ';
  errorMessage[3] = '\0';
  newline[0] = '\r';
  newline[1] = '\n';
  newline[2] = '\0';
  for (i = 0; i < PROC_ENTRY_NUM; i++) {
    convertIntToString(number, i );
    printString(number);
    printString(errorMessage);
    convertIntToString(number, te[i].active );
    printString(number);
    printString(errorMessage);
    convertIntToString(number, te[i].sp/0x100);
    printString(number);
    printString(errorMessage);
    printString(newline);
  }

  errorMessage[0] = 'C';
  errorMessage[1] = 'u';
  errorMessage[2] = 'r';
  errorMessage[3] = 'r';
  errorMessage[4] = 'e';
  errorMessage[5] = 'n';
  errorMessage[6] = 't';
  errorMessage[7] = ':';
  errorMessage[8] = ' ';
  errorMessage[9] = '\0';
  printString(errorMessage);
  convertIntToString(number, curProcUser);
  printString(number);
  printString(newline);
}
Esempio n. 3
0
void terminate(){
	// resetSegments();
	setKernelDataSegment();
	releasePCB(running);
	restoreDataSegment();
	setKernelDataSegment();
	releaseMemorySegment((*running).segment);
	restoreDataSegment();
	while(1 == 1){}
}
Esempio n. 4
0
int executeProgram(char* name){
	char buffer[13312];
	int i;
	int freeSegment;
	int segment;
	struct PCB *pcb;

	setKernelDataSegment();
	freeSegment = getFreeMemorySegment();
	restoreDataSegment();

	if(freeSegment == -1){
		print("No Memory Available\0");
		return -2;
	}

	// if(freeSegment == 0x0000 || freeSegment == 0x1000){
	// 	print("Invalid Segment\0");
	// 	return -1; 
	// }

	interrupt(0x21, 0x03, name, buffer, 0);

	if(buffer[0] == 0x00){
		print("File not found\0");
		return -1;
	}

	segment = 0x1000*(freeSegment+2);

	for(i = 0;i<13312;i++){
		putInMemory(segment, i, buffer[i]);
	}

	setKernelDataSegment();
	pcb = getFreePCB();
	restoreDataSegment();

	if(pcb == NULL){
		return -2;
	}

	kStrCopy(name,(*pcb).name, 6);

	setKernelDataSegment();
	(*pcb).segment = segment;
	(*pcb).stackPointer = 0xFF00;
	addToReady(pcb);
	restoreDataSegment();
	
	initializeProgram(segment);

	return 1;
}
Esempio n. 5
0
void executeProgram(char* name, int toWaitOn){
  char buffer[MAXFILESIZE];
  int curLoadChar;
  int q, found, process, charTemp;
  int segment = 0;

  found = readFile(name, buffer);
  if(found != 1){
    return;
  }

  setKernelDataSegment();
  for(q=0; q<NUMBEROFPROCESSENTRIES; q++){
    if(processTable[q].active == 0){
      segment = findProcessTableSegment(q);
      break;
    }
  }
  restoreDataSegment();
  process = q;

  if(segment == 0){
    printString("Too many processes");
    return;
  }

  for(curLoadChar=0; curLoadChar<MAXFILESIZE; curLoadChar++){
    putInMemory(segment, curLoadChar, buffer[curLoadChar]);
  }

  initializeProgram(segment);

  for(q=0; q<NAMELENGTH; q++){
    charTemp = name[q];
    setKernelDataSegment();
    processTable[process].name[q] = charTemp;
    restoreDataSegment();
  }
  setKernelDataSegment();
  processTable[process].name[q] = '\0';

  if(toWaitOn != NOONE){
    processTable[toWaitOn].waitingOn = process;
  }
  processTable[process].active = 1;
  processTable[process].stackPointer = INTITALSTACKLOCATION;
  restoreDataSegment();
  return;
}
Esempio n. 6
0
void main2() {
	int i;
	char buffer[13312];
	char shell[6];
  	shell[0]='s';
 	shell[1]='h';
  	shell[2]='e';
  	shell[3]='l';
  	shell[4]='l';
  	shell[5]=0;
	setKernelDataSegment() ;
	for(i=0;i<8;i++);
	{
		p[i].active=0;
		p[i].sp=0x11;
	}
	if(p[0].sp==0x11)
		printString("sp==0xff00");
	currentProcess=0;
	restoreDataSegment();
	makeInterrupt21();
//	makeTimerInterrupt() ;
	interrupt(0x21, 9,shell,0, 0);
	while (1); 
}
Esempio n. 7
0
void kill(int process)
{
	setKernelDataSegment();
	p[process].active=0;
	printInteger(p[process].active);
	restoreDataSegment();
}
Esempio n. 8
0
void executeProgram(char* name) 
{
	char buffer[13312];
	int i=0,process,seg;
	setKernelDataSegment() ;
	readFile(name,buffer);	
	process=0;
	while(process<8)
	{
		if(p[process].active==0)
		{
			p[process].active=1;
			seg=process+2;
			seg=seg * 4096;
			currentProcess=process;
			break;
		}
		process++;
	}
	  
	while(i < 13312)
	{
		putInMemory(seg,i,buffer[i]);
		i++;
	}
	printString("hi");
	initializeProgram(seg);
	printString("process initialised");
	restoreDataSegment();
}
Esempio n. 9
0
void handleTimerInterrupt(int segment, int sp) {
  int curProcUser, curProcSegUser, curProcSpUser, count, wait, parentWait;

  setKernelDataSegment();
  curProcSegUser = segment;
  curProcSpUser = sp;
  curProcUser = div(curProcSegUser, 0x1000) - 2;

  if (curProcUser >= 0) {
    procTable[curProcUser].sp = sp;
  }

  for (count = 0; count <= PROC_ENTRY_NUM; count++) {
    curProcUser = (curProcUser + 1) % PROC_ENTRY_NUM;

    /* TODO: Not very efficient, wait to be changed */
    wait = procTable[curProcUser].waiting;
    if (wait != -1) { /* Current process is waiting for `wait` */
      parentWait = procTable[wait].waiting;
      if (!procTable[wait].active && parentWait == -1) {
        procTable[curProcUser].waiting = -1;
        procTable[curProcUser].active = 1;
      }
    }
    if (procTable[curProcUser].active == 1) {
      currentProcess = curProcUser;
      curProcSegUser = currentProcess * 0x1000 + 0x2000;
      curProcSpUser = procTable[currentProcess].sp;
      break;
    }
  }
  restoreDataSegment();
  returnFromTimer(curProcSegUser, curProcSpUser);
}
Esempio n. 10
0
void terminate(){
    struct PCB *pcb;
    
    setKernelDataSegment();
    pcb = running;
    restoreDataSegment();
    
    setKernelDataSegment();
    releaseMemorySegment(pcb->segment);
    releasePCB(pcb);
    restoreDataSegment();

//    resetSegments();
//    printString("I'm back!");
    interrupt(0x21, 0x04, "shell\0", 0x2000, 0);
}
Esempio n. 11
0
void handleTimerInterrupt(int segment, int stackPointer){
	struct PCB *pcb;

	setKernelDataSegment();

	(*running).stackPointer = stackPointer;
	(*running).segment = segment;

	if((*running).state != DEFUNCT && (*running).name != "idle\0"){
		(*running).state = READY;
		addToReady(running);
	}
	
	pcb = removeFromReady();

	if(pcb == NULL){
		running = &idleProc;
	}else{
		(*pcb).state = RUNNING;
		running = pcb;
	}

	returnFromTimer((*running).segment,(*running).stackPointer);
	restoreDataSegment();
}
Esempio n. 12
0
int executeProgram(char* name){
    int i = 0;
    int offset = 0x0000;
    char buffer[512];
    int sectors;
    int segment;
    struct PCB *pcb;
    
    setKernelDataSegment();
    pcb = getFreePCB();
    restoreDataSegment();

    setKernelDataSegment();
    segment = getFreeMemorySegment()
    restoreDataSegment();

    if(segment == -1){
        return -2;
    }
    
    sectors = readfile(name, buffer);
    if(sectors == -1){
        return -1;
    }
    
    for (i; i < sectors*512 ; i++) {
        putInMemory(segment,offset,buffer[i]);
        offset++;
    }
//    pcb->name[0] = name[0];
//    pcb->name[1] = name[1];
//    pcb->name[2] = name[2];
//    pcb->name[3] = name[3];
//    pcb->name[4] = name[4];
//    pcb->name[5] = name[5];
    kStrCopy(name, pcb->name, 6);
    
    setKernelDataSegment();
    pcb->state = STARTING;
    pcb->segment = segment;
    pcb->stackPointer = 0xFF00;
    restoreDataSegment();

    initializeProgram(segment);
    return 1;
    
}
Esempio n. 13
0
void terminate()
{
	setKernelDataSegment() ;
	p[currentProcess].active=0;
	p[currentProcess].sp=0xff00;
	restoreDataSegment();
	while(1);        
}
Esempio n. 14
0
void terminate(){
  int cur;
  setKernelDataSegment();
  cur = currentProcess;
  restoreDataSegment();
  killProcess(cur);
  while(1);
  return;
}
Esempio n. 15
0
void handleInterrupt21(int ax, int bx, int cx, int dx){
  int cur;
  switch(ax){
    case 0x0: /*Print String*/
      printString(bx);
      break;
    case 0x1: /*Read String*/
      readString(bx);
      break;
    case 0x2: /*Read Sector*/
      readSector(bx, cx);
      break;
    case 0x3: /*Read File*/
      readFile(bx, cx);
      break;
    case 0x4: /*Execute Program*/
      executeProgram(bx, NOONE);
      break;
    case 0x5: /*Terminate Program*/
      terminate();
      break;
    case 0x6: /*Write Sector*/
      writeSector(bx, cx);
      break;
    case 0x7: /*Delete File*/
      deleteFile(bx);
      break;
    case 0x8: /*Write File*/
      writeFile(bx, cx, dx);
      break;
    case 0x9: /*Kill Process*/
      killProcess(bx);
      break;
    case 0xa: /*Execute Program in Blocking Fashion*/
      setKernelDataSegment();
      cur = currentProcess;
      restoreDataSegment();
      executeProgram(bx, cur);
      break;
    case 0xb:
      listProcesses();
      break;
    case 0xc:
      editString(bx);
      break;
    default:
      printString("Interrupt21 got undefined ax.");
      break;
  }

  return;
}
Esempio n. 16
0
void listProcesses(){
  int q;
  char mess[20];
  char proc[5];
  proc[0] = ' ';
  proc[1] = '#';
  proc[2] = '\r';
  proc[3] = '\n';
  proc[4] = '\0';
  mess[0] = 'P';
  mess[1] = 'r';
  mess[2] = 'o';
  mess[3] = 'c';
  mess[4] = 'e';
  mess[5] = 's';
  mess[6] = 's';
  mess[7] = 'e';
  mess[8] = 's';
  mess[9] = ':';
  mess[10] = '\r';
  mess[11] = '\n';
  mess[12] = '\0';
  printString(mess);

  setKernelDataSegment();
  for(q=0; q<NUMBEROFPROCESSENTRIES; q++){
    if(processTable[q].active == 1){
      printString(processTable[q].name);

      restoreDataSegment();
      proc[1] = '0'+q;
      printString(proc);
      setKernelDataSegment();
    }
  }
  restoreDataSegment();

  return;
}
Esempio n. 17
0
void yield(){
	struct PCB *pcb;
	char name[7];

	setKernelDataSegment();
	// kStrCopy((*running).name, name, 7);
	// pcb = running;
	// releasePCB(running);
	// (*pcb).state = READY;
	// kStrCopy(name, (*running).name, 7);
	// addToReady(pcb);
	addToReady(running);
	restoreDataSegment();
}
Esempio n. 18
0
int runProgram(char* name, int dirID) {
  char errorMessage[10];
  char number[10];
  char newline[3];
  char programBuffer[13312];
  int i, t, current, curProcUser;
  int segment2;

  readFile(name, programBuffer, ROOT_SECTOR);

  setKernelDataSegment();

  for (i = 0; i < PROC_ENTRY_NUM; i++) {
    if (procTable[i].active == 0 && procTable[i].waiting == -1) {
      procTable[i].sp = 0xFF00;
      t = i;
      break;
    }
  }

  restoreDataSegment();

  /* convertIntToString(number, t); */
  /* number[1] = ' '; */
  /* number[2] = '\0'; */
  /* printString(number); */

  segment2 = (t + 2) * 0x1000;
  for (i = 0; i <= 13312; i++) {
    putInMemory(segment2, i, programBuffer[i]);
  }
  initializeProgram(segment2);
  setKernelDataSegment();
  procTable[t].active = 1;
  restoreDataSegment();
  return t;
}
Esempio n. 19
0
void killProcess(int id){
  int q;

  setKernelDataSegment();
  processTable[id].stackPointer = INTITALSTACKLOCATION;
  processTable[id].waitingOn = NOONE;

  for(q=0; q<NUMBEROFPROCESSENTRIES; q++){
    if(processTable[q].waitingOn == id){
      processTable[q].waitingOn = NOONE;
    }
  }

  processTable[id].active = 0;
  restoreDataSegment();
  return;
}
Esempio n. 20
0
void writeSector(char* buffer, int sector){ 


	int ah = 3; 
	int al = 1; 
	int ax = ah * 256 + al; 
	int bx = buffer;  
	int ch = div(sector,36); 
	int cl = mod(sector,18)+1;  
	int cx = ch * 256 + cl;
	int dh = mod(div(sector,18),2); 
	int dl = 0; 
	int dx = dh * 256 + dl; 
	setKernelDataSegment() ;
	interrupt(0x13, ax, bx, cx, dx);
	restoreDataSegment();
}
Esempio n. 21
0
void showProcesses(){
    int i = 0;
    setKernelDataSegment();
    struct PCB *pcb;
    for(i; i < 8; i++){
        if(pcb->state == RUNNING){
            pcb->name = memoryMap[i]->name;
            pcb->segment = memoryMap[i]->segment;
            segment = (pcb->segment - 0x2000)/0x1000;
            printString(pcb->name);
            printString(", ");
            printString(segment);
            printString("\n");
        }
        
    }
    restoreDataSegment();
}
Esempio n. 22
0
void terminate() {
  /* int i; */
  /* char shell[6]; */
  /* shell[0] = 't'; */
  /* shell[1] = 'e'; */
  /* shell[2] = 'r'; */
  /* shell[3] = '\n'; */
  /* shell[4] = '\r'; */
  /* shell[5] = '\0'; */
  /* printString(shell); */
  setKernelDataSegment();
  procTable[currentProcess].active = 0;
  restoreDataSegment();
  while(1);
  /* for (i = 0 ; i < -1; i++); */
  /* runProgram(shell); */
  /* interrupt(0x21, 4, shell, 0x2000, 0); */
}
Esempio n. 23
0
void yield(){
    setKernelDataSegment();
    running->state = READY;
    restoreDataSegment();
}
Esempio n. 24
0
void killProcess(int id) {
  setKernelDataSegment();
  procTable[id].active = 0;
  restoreDataSegment();
}
Esempio n. 25
0
void handleTimerInterrupt(int segment, int sp)
{
	
	int i,process,count=1;
	setKernelDataSegment();
	if(segment==0x1000)
	{	printString("segment=1000");
		currentProcess=-1;
	}
	else
	{
		p[currentProcess].sp=sp;
	}
	process=currentProcess+1;
		
	if (segment == 0x1000)
	{
	 	putInMemory(0xB000, 0x8162, 'K');
	 	putInMemory(0xB000, 0x8163, 0x7);
	}
	else if (segment == 0x2000)
	 {
		putInMemory(0xB000, 0x8164, '0');
		putInMemory(0xB000, 0x8165, 0x7);
	 }
	else if (segment == 0x3000)
	 {
		putInMemory(0xB000, 0x8166, '1');
	 	putInMemory(0xB000, 0x8167, 0x7);
	 }
	else
	 {
		putInMemory(0xB000, 0x8160, 'X');
		putInMemory(0xB000, 0x8161, 0x7); 
       	 }
	
	while(process<8)
	{
		
		if(p[process].active==1)
		{
			printString("process active");
			currentProcess=process;
			segment=process+2;
			segment=segment*0x1000;
			if( p[process].sp == 0xff00 )
				printString("segment=0x2000");
			restoreDataSegment();
			returnFromTimer(segment,p[process].sp);
		}	
		if(count==8)
		{
			printString("breaking");
			break;
		}	
		if(process==7)
		{
			printString("process==7");
			process=0;
		}
		else
		{
			process++;
		}
			count++;
			
	}

//	printString("Tic");
	restoreDataSegment();
        returnFromTimer(segment,sp);
}
Esempio n. 26
0
void shellWait(int process) {
   setKernelDataSegment();
   procTable[0].waiting = process;
   procTable[0].active = 0;
   restoreDataSegment();
}