jsos

college code for operating system fundamentals in js

git clone https://9o.is/git/jsos.git

pcb.js

(1635B)


      1 /*
      2  * Process Control Block
      3  */
      4 function pcb(pid, state, base, limit, pc, priority) {
      5   this.PID = pid;
      6   this.state = state;
      7   this.base = base;
      8   this.limit = limit;
      9   this.PC = pc;
     10   this.ACC = 0;
     11   this.X = 0;
     12   this.Y = 0;
     13   this.Z = 0;
     14   this.priority = priority;
     15   this.tsb = undefined;
     16   this.arrival = undefined;
     17   this.end = undefined;
     18   this.bursts = 0;
     19     
     20   /*
     21    * Updates process control block values.
     22    */
     23   this.update = function(state, base, limit, pc, acc, x, y, z) {
     24     this.state = state;
     25     this.base = base;
     26     this.limit = limit;
     27     this.PC = this.assureValidPC(pc);
     28     this.ACC = acc;
     29     this.X = x;
     30     this.Y = y;
     31     this.Z = z;
     32     _KernelMemoryManager.output();
     33   }
     34 
     35   /*
     36    * Updates the PCB with a new state.
     37    */
     38   this.setState = function(newState) {
     39     this.update(
     40       newState, 
     41       this.base, 
     42       this.limit, 
     43       this.PC, 
     44       this.ACC, 
     45       this.X, 
     46       this.Y, 
     47       this.Z);
     48 
     49     if(newState == PCB_STATE_TERMINATED)
     50       this.end = _OSclock;
     51 
     52     if(this.arrival == undefined && 
     53            newState == PCB_STATE_READY) 
     54       this.arrival = _OSclock;
     55   }
     56 
     57   /*
     58    * Updates the registers and Zflag.
     59    */
     60   this.updateRegisters = function(pc, acc, x, y, z) {
     61     this.update(
     62       this.state, 
     63       this.base, 
     64       this.limit, 
     65       pc, acc, x, y, z);
     66   }
     67 
     68   /*
     69    * Enforce the memory boundaries all the time. If it 
     70    * crosses its boundaries, it will terminate.
     71    */
     72   this.assureValidPC = function(pc) {
     73     if(pc >= this.base && pc <= this.limit)
     74       return pc;
     75     else {
     76       this.state = PCB_STATE_TERMINATED;
     77       return this.base;
     78     }
     79   }
     80 }