Skip to content

Commit 81fcfca

Browse files
committed
Ejs 12 y 13
1 parent 80678e8 commit 81fcfca

9 files changed

+77
-7
lines changed

V1/.vscode/launch.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
"type": "cppdbg",
1111
"request": "launch",
1212
"program": "${workspaceFolder}/Simulator",
13-
"args": ["programVerySimple"],
13+
"args": ["prog-V1-E12"],
1414
"stopAtEntry": false,
1515
"cwd": "${workspaceFolder}",
1616
"environment": [],

V1/OperatingSystem.c

+24-2
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ int OperatingSystem_ExtractFromReadyToRun();
2525
void OperatingSystem_HandleException();
2626
void OperatingSystem_HandleSystemCall();
2727
void OperatingSystem_PrintReadyToRunQueue();
28+
void OperatingSystem_GiveControl();
2829

2930
// The process table
3031
PCB processTable[PROCESSTABLEMAXSIZE];
@@ -415,6 +416,15 @@ void OperatingSystem_HandleSystemCall() {
415416
ComputerSystem_DebugMessage(73,SYSPROC,executingProcessID,programList[processTable[executingProcessID].programListIndex]->executableName);
416417
OperatingSystem_TerminateProcess();
417418
break;
419+
420+
case SYSCALL_YIELD: ;
421+
int previousPID, currentPID;
422+
previousPID=executingProcessID;
423+
OperatingSystem_GiveControl();
424+
currentPID=executingProcessID;
425+
if (previousPID!=currentPID)
426+
ComputerSystem_DebugMessage(115, SHORTTERMSCHEDULE, previousPID, programList[processTable[previousPID].programListIndex]->executableName, currentPID, programList[processTable[currentPID].programListIndex]->executableName);
427+
break;
418428
}
419429
}
420430

@@ -437,11 +447,11 @@ void OperatingSystem_PrintReadyToRunQueue() {
437447
ComputerSystem_DebugMessage(112,SHORTTERMSCHEDULE);
438448
for(i=0;i<2;i++){
439449
if(i==0 && numberOfReadyToRunProcesses[i]>0)
440-
ComputerSystem_DebugMessage(113,SHORTTERMSCHEDULE,"");
450+
ComputerSystem_DebugMessage(114,SHORTTERMSCHEDULE,"");
441451
else if(i==1 && numberOfReadyToRunProcesses[i]>0)
442452
ComputerSystem_DebugMessage(114,SHORTTERMSCHEDULE,"");
443453
else if(i==0)
444-
ComputerSystem_DebugMessage(113,SHORTTERMSCHEDULE,"\n");
454+
ComputerSystem_DebugMessage(114,SHORTTERMSCHEDULE,"\n");
445455
else
446456
ComputerSystem_DebugMessage(114,SHORTTERMSCHEDULE,"\n");
447457

@@ -461,3 +471,15 @@ void OperatingSystem_PrintReadyToRunQueue() {
461471
}
462472
}
463473

474+
void OperatingSystem_GiveControl() {
475+
int i,j,PID;
476+
for(i=0;i<2;i++){
477+
for(j=0;j<numberOfReadyToRunProcesses[i];j++){
478+
PID=readyToRunQueue[i][j].info;
479+
if (processTable[PID].priority==processTable[executingProcessID].priority){
480+
OperatingSystem_PreemptRunningProcess();
481+
return;
482+
}
483+
}
484+
}
485+
}

V1/OperatingSystem.h

+2-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,8 @@ enum ProgramTypes { USERPROGRAM, DAEMONPROGRAM };
2626
enum ProcessStates { NEW, READY, EXECUTING, BLOCKED, EXIT};
2727

2828
// Enumerated type containing the list of system calls and their numeric identifiers
29-
enum SystemCallIdentifiers { SYSCALL_END=3, SYSCALL_PRINTEXECPID=5};
29+
//V1 Ej 12: adding SYSCALL_YIELD
30+
enum SystemCallIdentifiers { SYSCALL_END=3, SYSCALL_YIELD=4, SYSCALL_PRINTEXECPID=5};
3031

3132
// Data structures for multiple queuing
3233
// V1 Ej 11

V1/Simulator

304 Bytes
Binary file not shown.

V1/V1-2-output.log

+33
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
29 messages loaded from file messagesTCH.txt
2+
13 messages loaded from file messagesSTD.txt
3+
0 Asserts Loaded
4+
User program list:
5+
Program[prog-V1-E6] with arrival time [0]
6+
 Program[prog-V1-E7] with arrival time [0]
7+
 Program[programMEMADD] with arrival time [0]
8+
New process [3 - SystemIdleProcess] moving to the [NEW] state
9+
Process [3] created from program [SystemIdleProcess]
10+
Process [3 - SystemIdleProcess] moving from the [NEW] state to the [READY] state
11+
Ready-to-run_processes_queues:
12+
USERS:
13+
DAEMONS: [3,100]
14+
ERROR: Program [prog-V1-E6] is too big
15+
ERROR: Program [prog-V1-E7] is too big
16+
ERROR: Program [programMEMADD] is not valid [--- invalid priority or size ---]
17+
Process [3 - SystemIdleProcess] moving from the [READY] state to the [EXECUTING] state
18+
New Tick (1)
19+
{0D 000 000} IRET 0 0 (PC: 183, Accumulator: 0, PSW: 0082 [--------X-----Z-])
20+
New Tick (2)
21+
{04 003 000} TRAP 3 0 (PC: 184, Accumulator: 0, PSW: 0082 [--------X-----Z-])
22+
New Tick (3)
23+
{0C 002 000} OS 2 0 (PC: 242, Accumulator: 0, PSW: 0082 [--------X-----Z-])
24+
New Tick (4)
25+
Process [3 - SystemIdleProcess] has requested to terminate
26+
Process [3 - SystemIdleProcess] moving from the [EXECUTING] state to the [EXIT] state
27+
The system will shut down now...
28+
New Tick (5)
29+
{0D 000 000} IRET 0 0 (PC: 241, Accumulator: 0, PSW: 0082 [--------X-----Z-])
30+
New Tick (6)
31+
{0B 000 000} HALT 0 0 (PC: 241, Accumulator: 0, PSW: 0083 [--------X-----ZS])
32+
END of the simulation
33+


V1/messagesSTD.txt

+2-1
Original file line numberDiff line numberDiff line change
@@ -15,4 +15,5 @@
1515
111,Process [@G%d - %s@@] moving from the [@G%s@@] state to the [@G%s@@] state\n
1616
112,Ready-to-run_processes_queues:\n
1717
113,USERS:%s
18-
114,DAEMONS:%s
18+
114,DAEMONS:%s
19+
115,Process [@G%d - %s@@] will transfer the control of the processor to process [@G%d - %s@@]\n

V1/prog-V1-E12

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
55
2+
5
3+
MEMADD 3 20
4+
WRITE 20
5+
DIV 20 20
6+
TRAP 4
7+
HALT

V1/programVerySimple

-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
30
22
5
33
NOP
4-
TRAP 5
54
ADD 10 -13
65
WRITE 15
76
HALT

V1/readme.txt

+8-1
Original file line numberDiff line numberDiff line change
@@ -19,4 +19,11 @@ Ejercicio 6: Se ha modificado OperatingSystem_CreateProcess para que devuelva TO
1919
Ejercicio 7: Se ha cambiado la funcion OperatingSystem_CreateProcess para que, en la llamada a OperatingSystem_LoadProgram retorne TOOBIDPROCESS si el tamaño del programa es menor que el programa en si
2020
Ejercicio 8: Modificado el initialPID a PROCESSTABLEMAXSIZE-1 que es el tamaño de la tabla de procesos. Por lo que el PID de los siguientes programas empezara en 0. Pero esto no afecta a la opcion de ejecucion --initialPID
2121
Ejercicio 9: Creada la funcion OperatingSystem_PrintReadyToRunQueue que imprime la lista de procesos en estado LISTO. Además se le ha llamado en OperatingSystem_MoveToTheREADYState
22-
Ejercicio 10: Creada la estructura de datos con los nombres de los estados de los procesos (char * statesNames). Ahora se imprime un mensaje cada vez que se cambia de estado a un proceso
22+
Ejercicio 10: Creada la estructura de datos con los nombres de los estados de los procesos (char * statesNames). Ahora se imprime un mensaje cada vez que se cambia de estado a un proceso
23+
Ejercicio 11: Modificados todos los metodos necewsarios y funciona bien, pero error en la impresion de la cola de programas de usuario
24+
Ejercicio 12: Creada la funcion OperatingSystem_GiveControl para dar control al siguiente proceso que tenga su la misma prioridad. Añadido en el enum corresponiente SYSCALL_YIELD y su case para el tratamiento de la llamada, la cual se ejecuta con la orden TRAP 4
25+
Ejercicio 13:
26+
a. Se deben guardar los estados de esos registros para que, después de una interrupción, el proceso vuela al estado en el que estaba.
27+
b. También se deberia guardar el registro de acumulador
28+
c. Habría que añadir el guardado del registro acumulador en la función
29+
d. Afectaria al PCB

0 commit comments

Comments
 (0)