Skip to content

Commit 12ac248

Browse files
committed
Ej 5 V2 mas varios cambios
1 parent a6669e9 commit 12ac248

13 files changed

+367
-230
lines changed

V2/Clock.c

+2-7
Original file line numberDiff line numberDiff line change
@@ -5,17 +5,12 @@
55
#include "OperatingSystem.h"
66

77
int tics=0;
8-
int numberOfClockInterrupts = 0; //V2 Ej 4
8+
99

1010
void Clock_Update() {
1111
tics++;
1212
if (tics>=intervalBetweenInterrupts && tics%intervalBetweenInterrupts==0){
13-
numberOfClockInterrupts++;
14-
//V2 Ej4
15-
OperatingSystem_ShowTime(INTERRUPT);
16-
ComputerSystem_DebugMessage(120,INTERRUPT,numberOfClockInterrupts);
17-
18-
OperatingSystem_InterruptLogic(CLOCKINT_BIT); //V2 Ej 2
13+
Processor_RaiseInterrupt(CLOCKINT_BIT); //V2 Ej 2
1914
}
2015
}
2116

V2/OperatingSystem.c

+30-1
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ void OperatingSystem_HandleSystemCall();
2828
void OperatingSystem_PrintReadyToRunQueue();
2929
void OperatingSystem_GiveControl();
3030
void OperatingSystem_HandleClockInterrupt();
31+
void OperatingSystem_MoveToTheBLOCKEDState();
3132

3233
// The process table
3334
PCB processTable[PROCESSTABLEMAXSIZE];
@@ -38,6 +39,9 @@ int OS_address_base = PROCESSTABLEMAXSIZE * MAINMEMORYSECTIONSIZE;
3839
// Identifier of the current executing process
3940
int executingProcessID=NOPROCESS;
4041

42+
// Variable containing the number of interruption clocks (V2 Ej 4)
43+
int numberOfClockInterrupts = 0;
44+
4145
// Identifier of the System Idle Process
4246
int sipID;
4347

@@ -60,6 +64,10 @@ heapItem readyToRunQueue [NUMBEROFQUEUES][PROCESSTABLEMAXSIZE];
6064
int numberOfReadyToRunProcesses[NUMBEROFQUEUES]={0,0};
6165
char * queueNames [NUMBEROFQUEUES]={"USER","DAEMONS"};
6266

67+
// Exercise 5-b of V2
68+
// Heap with blocked processes sort by when to wakeup
69+
heapItem sleepingProcessesQueue[PROCESSTABLEMAXSIZE];
70+
int numberOfSleepingProcesses=0;
6371

6472
// Initial set of tasks of the OS
6573
void OperatingSystem_Initialize(int daemonsIndex) {
@@ -447,9 +455,14 @@ void OperatingSystem_HandleSystemCall() {
447455
break;
448456

449457
//V1 Ej 12
450-
case SYSCALL_YIELD: ;
458+
case SYSCALL_YIELD:
451459
OperatingSystem_GiveControl();
452460
break;
461+
462+
//V2 Ej 5
463+
case SYSCALL_SLEEP:
464+
OperatingSystem_MoveToTheBLOCKEDState();
465+
break;
453466
}
454467
}
455468

@@ -506,5 +519,21 @@ void OperatingSystem_GiveControl() {
506519

507520
// Exercise 2-b of V2
508521
void OperatingSystem_HandleClockInterrupt() {
522+
numberOfClockInterrupts++;
523+
524+
//V2 Ej4
525+
OperatingSystem_ShowTime(INTERRUPT);
526+
ComputerSystem_DebugMessage(120,INTERRUPT,numberOfClockInterrupts);
527+
509528
return;
529+
}
530+
531+
// V2 Ej5
532+
void OperatingSystem_MoveToTheBLOCKEDState() {
533+
processTable[executingProcessID].whenToWakeUp=abs(processTable[executingProcessID].copyOfAccumulator) + numberOfClockInterrupts + 1;
534+
if (Heap_add(executingProcessID, sleepingProcessesQueue, QUEUE_WAKEUP, numberOfSleepingProcesses, PROCESSTABLEMAXSIZE)>=0){
535+
processTable[executingProcessID].state=BLOCKED;
536+
OperatingSystem_SaveContext(PID);
537+
OperatingSystem_PrintStatus();
538+
}
510539
}

V2/OperatingSystem.h

+4
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,9 @@
1919

2020
#define NOPROCESS -1
2121

22+
// V2 Ej 5c
23+
#define SLEEPINGQUEUE
24+
2225
// Contains the possible type of programs
2326
enum ProgramTypes { USERPROGRAM, DAEMONPROGRAM };
2427

@@ -46,6 +49,7 @@ typedef struct {
4649
unsigned int copyOfPSWRegister;
4750
int programListIndex;
4851
int queueID;
52+
int whenToWakeUp; // Exercise 5-a of V2
4953
} PCB;
5054

5155
// These "extern" declaration enables other source code files to gain access

V2/OperatingSystemCode

+2-1
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,5 @@ OS 2 // SysCall Interrupt
66
IRET
77
OS 6 // Exception Interrupt
88
IRET
9-
9+
OS 9 // Clock interrupt
10+
IRET

V2/Processor.c

+6-3
Original file line numberDiff line numberDiff line change
@@ -250,8 +250,9 @@ void Processor_DecodeAndExecuteInstruction() {
250250

251251
// Hardware interrupt processing
252252
void Processor_ManageInterrupts() {
253-
254-
int i;
253+
254+
if(!Processor_PSW_BitState(INTERRUPT_MASKED_BIT)){
255+
int i;
255256

256257
for (i=0;i<INTERRUPTTYPES;i++)
257258
// If an 'i'-type interrupt is pending
@@ -260,14 +261,16 @@ void Processor_ManageInterrupts() {
260261
Processor_ACKInterrupt(i);
261262
// Copy PC and PSW registers in the system stack
262263
Processor_CopyInSystemStack(MAINMEMORYSIZE-1, registerPC_CPU);
263-
Processor_CopyInSystemStack(MAINMEMORYSIZE-2, registerPSW_CPU);
264+
Processor_CopyInSystemStack(MAINMEMORYSIZE-2, registerPSW_CPU);
265+
Processor_CopyInSystemStack(MAINMEMORYSIZE-3, registerAccumulator_CPU);
264266
// Activate protected excution mode
265267
Processor_ActivatePSW_Bit(EXECUTION_MODE_BIT);
266268
Processor_ActivatePSW_Bit(INTERRUPT_MASKED_BIT); //V2 Ej 3
267269
// Call the appropriate OS interrupt-handling routine setting PC register
268270
registerPC_CPU=interruptVectorTable[i];
269271
break; // Don't process another interrupt
270272
}
273+
}
271274
}
272275

273276
char * Processor_ShowPSW(){

V2/Processor.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ enum PSW_BITS {POWEROFF_BIT=0, ZERO_BIT=1, NEGATIVE_BIT=2, OVERFLOW_BIT=3, EXECU
1414

1515
// Enumerated type that connects bit positions in the interruptLines with
1616
// interrupt types
17-
enum INT_BITS {SYSCALL_BIT=2, EXCEPTION_BIT=6, CLOCKINT_BIT=9}; //CLOCKINT_BIT=9 V2 Ej 2a
17+
enum INT_BITS {SYSCALL_BIT=2, EXCEPTION_BIT=6, SYSCALL_SLEEP=7, CLOCKINT_BIT=9}; //CLOCKINT_BIT=9 V2 Ej 2a - SYSCALL_SLEEP=7 V2 Ej 5
1818

1919
// Functions prototypes
2020
void Processor_InitializeInterruptVectorTable();

V2/V1-1-output.log

-26
This file was deleted.

V2/V1-2-output.log

-33
This file was deleted.

V2/V1-3-output.log

-157
This file was deleted.

0 commit comments

Comments
 (0)