Fix almost all bugs and change the scheduler implementation
Co-authored-by: Ezequiel Bellver <ebellver@itba.edu.ar> Co-authored-by: Juan Barmasch <jbarmasch@itba.edu.ar>
This commit is contained in:
parent
953f608b4b
commit
9af7505421
|
@ -28,7 +28,7 @@ EXTERN nextProcess
|
||||||
GLOBAL switchContext
|
GLOBAL switchContext
|
||||||
GLOBAL loadProcess
|
GLOBAL loadProcess
|
||||||
GLOBAL _initialize_stack_frame
|
GLOBAL _initialize_stack_frame
|
||||||
GLOBAL _switchContext, forceTimerAux
|
;GLOBAL _switchContext, forceTimerAux
|
||||||
|
|
||||||
EXTERN getFPUaddress, getSSEaddress
|
EXTERN getFPUaddress, getSSEaddress
|
||||||
EXTERN checkSleeping
|
EXTERN checkSleeping
|
||||||
|
@ -173,110 +173,46 @@ picSlaveMask:
|
||||||
pop rbp
|
pop rbp
|
||||||
retn
|
retn
|
||||||
|
|
||||||
; getFPUaddress:
|
|
||||||
; push rcx
|
|
||||||
; mov ecx, [auxi]
|
|
||||||
; mov ecx, 1
|
|
||||||
; xor ecx, [auxi]
|
|
||||||
; cmp ecx, 0
|
|
||||||
; jne .getSecond
|
|
||||||
; mov rax, bytesForFPU1
|
|
||||||
; jmp .finish
|
|
||||||
; .getSecond:
|
|
||||||
; mov rax, bytesForFPU2
|
|
||||||
; .finish:
|
|
||||||
; mov dword [auxi], ecx
|
|
||||||
; pop rcx
|
|
||||||
; ret
|
|
||||||
|
|
||||||
; getSSEaddress:
|
|
||||||
; push rcx
|
|
||||||
; mov ecx, [auxi]
|
|
||||||
; cmp ecx, 0
|
|
||||||
; jne .getSecond
|
|
||||||
; mov rax, bytesForSSEAligned1
|
|
||||||
; jmp .finish
|
|
||||||
; .getSecond:
|
|
||||||
; mov rax, bytesForSSEAligned2
|
|
||||||
; .finish:
|
|
||||||
; pop rcx
|
|
||||||
; ret
|
|
||||||
|
|
||||||
forceTimerAux:
|
|
||||||
pushStateNoRax
|
|
||||||
|
|
||||||
; call checkSleeping
|
|
||||||
|
|
||||||
call nextProcess
|
|
||||||
mov rsp, rax
|
|
||||||
|
|
||||||
popStateNoRax
|
|
||||||
iretq
|
|
||||||
|
|
||||||
;8254 Timer (Timer Tick)
|
;8254 Timer (Timer Tick)
|
||||||
_irq00Handler:
|
_irq00Handler:
|
||||||
pushState
|
pushState
|
||||||
|
|
||||||
; mov rsi, rsp
|
mov rsi, rsp
|
||||||
; and rsp, -16
|
and rsp, -16
|
||||||
; sub rsp, 108
|
sub rsp, 108
|
||||||
; fsave [rsp]
|
fsave [rsp]
|
||||||
; and rsp, -16
|
and rsp, -16
|
||||||
; sub rsp, 512
|
sub rsp, 512
|
||||||
; fxsave [rsp]
|
fxsave [rsp]
|
||||||
; push rsi
|
push rsi
|
||||||
|
|
||||||
; push rax
|
|
||||||
; call getFPUaddress
|
|
||||||
; fsave [rax]
|
|
||||||
; call getSSEaddress
|
|
||||||
; fxsave [rax]
|
|
||||||
; pop rax
|
|
||||||
; fsave [bytesForFPU]
|
|
||||||
; fxsave [bytesForSSEAligned]
|
|
||||||
|
|
||||||
call checkSleeping
|
call checkSleeping
|
||||||
|
|
||||||
mov rdi, rsp
|
; mov rdi, rsp
|
||||||
call updateRSP
|
; call updateRSP
|
||||||
mov r10, rax
|
|
||||||
|
|
||||||
mov rdi, 0
|
mov rdi, 0
|
||||||
call irqDispatcher
|
call irqDispatcher
|
||||||
|
|
||||||
|
mov rdi, rsp
|
||||||
call nextProcess
|
call nextProcess
|
||||||
mov rsp, rax
|
mov rsp, rax
|
||||||
|
|
||||||
mov al, 20h
|
mov al, 20h
|
||||||
out 20h, al
|
out 20h, al
|
||||||
|
|
||||||
; fxrstor [bytesForSSEAligned]
|
pop rsp
|
||||||
; frstor [bytesForFPU]
|
mov rax, rsp
|
||||||
; push rax
|
and rsp, -16
|
||||||
; call getFPUaddress
|
sub rsp, 108
|
||||||
; frstor [rax]
|
frstor [rsp]
|
||||||
; call getSSEaddress
|
and rsp, -16
|
||||||
; fxrstor [rax]
|
sub rsp, 512
|
||||||
; pop rax
|
fxrstor [rsp]
|
||||||
|
mov rsp, rax
|
||||||
; cmp r10, 0
|
|
||||||
; je .end
|
|
||||||
|
|
||||||
; pop rsp
|
|
||||||
; mov rax, rsp
|
|
||||||
; and rsp, -16
|
|
||||||
; sub rsp, 108
|
|
||||||
; frstor [rsp]
|
|
||||||
; and rsp, -16
|
|
||||||
; sub rsp, 512
|
|
||||||
; fxrstor [rsp]
|
|
||||||
; mov rsp, rax
|
|
||||||
|
|
||||||
popState
|
popState
|
||||||
iretq
|
iretq
|
||||||
; .end:
|
|
||||||
; popStateNoRax
|
|
||||||
; iretq
|
|
||||||
|
|
||||||
;Keyboard
|
;Keyboard
|
||||||
_irq01Handler:
|
_irq01Handler:
|
||||||
|
@ -312,7 +248,6 @@ haltcpu:
|
||||||
cli
|
cli
|
||||||
ret
|
ret
|
||||||
|
|
||||||
|
|
||||||
_initialize_stack_frame:
|
_initialize_stack_frame:
|
||||||
mov r10, rsp
|
mov r10, rsp
|
||||||
mov rsp, rsi
|
mov rsp, rsi
|
||||||
|
@ -328,28 +263,15 @@ _initialize_stack_frame:
|
||||||
|
|
||||||
pushState
|
pushState
|
||||||
|
|
||||||
; mov rsi, rsp
|
mov rsi, rsp
|
||||||
; and rsp, -16
|
and rsp, -16
|
||||||
; sub rsp, 108
|
sub rsp, 108
|
||||||
; fsave [rsp]
|
fsave [rsp]
|
||||||
; and rsp, -16
|
and rsp, -16
|
||||||
; sub rsp, 512
|
sub rsp, 512
|
||||||
; fxsave [rsp]
|
fxsave [rsp]
|
||||||
; push rsi
|
push rsi
|
||||||
; mov rax, rsp
|
mov rax, rsp
|
||||||
|
|
||||||
; fsave [bytesForFPU]
|
|
||||||
; fxsave [bytesForSSEAligned]
|
|
||||||
|
|
||||||
; push rax
|
|
||||||
; call getFPUaddress
|
|
||||||
; fsave [rax]
|
|
||||||
; call getSSEaddress
|
|
||||||
; fxsave [rax]
|
|
||||||
; pop rax
|
|
||||||
|
|
||||||
; fsave [r8]
|
|
||||||
; fxsave [r9]
|
|
||||||
|
|
||||||
mov rsp, r10
|
mov rsp, r10
|
||||||
ret
|
ret
|
||||||
|
@ -359,36 +281,34 @@ _systemCallsHandler:
|
||||||
pushStateNoRax
|
pushStateNoRax
|
||||||
; fsave [bytesForFPU]
|
; fsave [bytesForFPU]
|
||||||
; fxsave [bytesForSSEAligned]
|
; fxsave [bytesForSSEAligned]
|
||||||
; mov [auxRSI], rsi
|
|
||||||
; mov rsi, rsp
|
|
||||||
; and rsp, -16
|
|
||||||
; sub rsp, 108
|
|
||||||
; fsave [rsp]
|
|
||||||
; and rsp, -16
|
|
||||||
; sub rsp, 512
|
|
||||||
; fxsave [rsp]
|
|
||||||
; push rsi
|
|
||||||
|
|
||||||
; mov [auxRDI], rdi
|
mov [auxRSI], rsi
|
||||||
; mov rdi, rsp
|
mov rsi, rsp
|
||||||
; call updateRSP
|
and rsp, -16
|
||||||
|
sub rsp, 108
|
||||||
|
fsave [rsp]
|
||||||
|
and rsp, -16
|
||||||
|
sub rsp, 512
|
||||||
|
fxsave [rsp]
|
||||||
|
push rsi
|
||||||
|
mov rsi, [auxRSI]
|
||||||
|
|
||||||
; mov rsi, [auxRSI]
|
|
||||||
; mov rdi, [auxRDI]
|
|
||||||
call systemCallsDispatcher
|
call systemCallsDispatcher
|
||||||
|
|
||||||
; fxrstor [bytesForSSEAligned]
|
; fxrstor [bytesForSSEAligned]
|
||||||
; frstor [bytesForFPU]
|
; frstor [bytesForFPU]
|
||||||
|
|
||||||
; pop rsp
|
pop rsp
|
||||||
; mov rax, rsp
|
mov [auxRAX], rax
|
||||||
; and rsp, -16
|
mov rax, rsp
|
||||||
; sub rsp, 108
|
and rsp, -16
|
||||||
; frstor [rsp]
|
sub rsp, 108
|
||||||
; and rsp, -16
|
frstor [rsp]
|
||||||
; sub rsp, 512
|
and rsp, -16
|
||||||
; fxrstor [rsp]
|
sub rsp, 512
|
||||||
; mov rsp, rax
|
fxrstor [rsp]
|
||||||
|
mov rsp, rax
|
||||||
|
mov rax, [auxRAX]
|
||||||
|
|
||||||
popStateNoRax
|
popStateNoRax
|
||||||
iretq
|
iretq
|
||||||
|
@ -396,18 +316,13 @@ _systemCallsHandler:
|
||||||
SECTION .data
|
SECTION .data
|
||||||
align 16
|
align 16
|
||||||
bytesForSSEAligned times 512 db 0
|
bytesForSSEAligned times 512 db 0
|
||||||
; bytesForSSEAligned1 times 512 db 0
|
|
||||||
; bytesForSSEAligned2 times 512 db 0
|
|
||||||
; counter dd 1
|
|
||||||
|
|
||||||
SECTION .bss
|
SECTION .bss
|
||||||
aux resq 1
|
aux resq 1
|
||||||
bytesForSSE resb 512
|
bytesForSSE resb 512
|
||||||
bytesForFPU resb 108
|
bytesForFPU resb 108
|
||||||
; bytesForFPU1 resb 108
|
|
||||||
; bytesForFPU2 resb 108
|
|
||||||
insPointer resb 8
|
insPointer resb 8
|
||||||
rspPointer resb 8
|
rspPointer resb 8
|
||||||
auxRSI resb 8
|
auxRSI resb 8
|
||||||
auxRDI resb 8
|
auxRDI resb 8
|
||||||
; auxi resb 4
|
auxRAX resb 8
|
|
@ -181,7 +181,7 @@ int main() {
|
||||||
clear();
|
clear();
|
||||||
// haltcpu();
|
// haltcpu();
|
||||||
_sti();
|
_sti();
|
||||||
// forceTimer();
|
forceTimer();
|
||||||
|
|
||||||
// printBottlerAndWait();
|
// printBottlerAndWait();
|
||||||
return EXIT_SUCCESS;
|
return EXIT_SUCCESS;
|
||||||
|
|
|
@ -7,7 +7,7 @@ loader:
|
||||||
mov rsp, rax ; Set up the stack with the returned address
|
mov rsp, rax ; Set up the stack with the returned address
|
||||||
call main
|
call main
|
||||||
|
|
||||||
; hang:
|
hang:
|
||||||
; cli
|
cli
|
||||||
; hlt ; halt machine should kernel return
|
hlt ; halt machine should kernel return
|
||||||
; jmp hang
|
jmp hang
|
||||||
|
|
|
@ -5,19 +5,7 @@
|
||||||
// void _initialize_stack_frame(void *, void *, int, char**, void *, void *);
|
// void _initialize_stack_frame(void *, void *, int, char**, void *, void *);
|
||||||
uint64_t * _initialize_stack_frame(void *, void *, int, char**);
|
uint64_t * _initialize_stack_frame(void *, void *, int, char**);
|
||||||
|
|
||||||
enum states {READY = 0, BLOCKED};
|
enum states {READY = 0, DEAD, BLOCKED};
|
||||||
|
|
||||||
// typedef long Align;
|
|
||||||
|
|
||||||
// union header {
|
|
||||||
// struct {
|
|
||||||
// void * fpuBytes;
|
|
||||||
// void * sseBytes;
|
|
||||||
// } s;
|
|
||||||
// Align x;
|
|
||||||
// };
|
|
||||||
|
|
||||||
// typedef union header Header;
|
|
||||||
|
|
||||||
typedef struct processCDT {
|
typedef struct processCDT {
|
||||||
struct processCDT * next;
|
struct processCDT * next;
|
||||||
|
@ -31,10 +19,6 @@ typedef struct processCDT {
|
||||||
char foreground;
|
char foreground;
|
||||||
enum states state;
|
enum states state;
|
||||||
int * fd;
|
int * fd;
|
||||||
// Header * bytes;
|
|
||||||
// Header * sse;
|
|
||||||
// void * sseBytes;
|
|
||||||
// void * fpuBytes;
|
|
||||||
} processCDT;
|
} processCDT;
|
||||||
|
|
||||||
typedef struct sleepCDT {
|
typedef struct sleepCDT {
|
||||||
|
@ -44,29 +28,12 @@ typedef struct sleepCDT {
|
||||||
struct sleepCDT * next;
|
struct sleepCDT * next;
|
||||||
} sleepCDT;
|
} sleepCDT;
|
||||||
|
|
||||||
// typedef union processCDT {
|
processCDT * firstBlockedIteration = NULL;
|
||||||
// struct {
|
|
||||||
// struct p * next;
|
|
||||||
// char * name;
|
|
||||||
// int pid;
|
|
||||||
// int ppid;
|
|
||||||
// uint64_t rsp;
|
|
||||||
// uint64_t rbp;
|
|
||||||
// char priority;
|
|
||||||
// char executions;
|
|
||||||
// char foreground;
|
|
||||||
// enum states state;
|
|
||||||
// int * fd;
|
|
||||||
// void * sseBytes;
|
|
||||||
// void * fpuBytes;
|
|
||||||
// } p;
|
|
||||||
// Align x;
|
|
||||||
// } processCDT;
|
|
||||||
|
|
||||||
processCDT * firstReady = NULL;
|
processCDT * firstProcess = NULL;
|
||||||
processCDT * lastReady = NULL;
|
processCDT * lastProcess = NULL;
|
||||||
processCDT * firstBlocked = NULL;
|
// processCDT * firstBlocked = NULL;
|
||||||
processCDT * lastBlocked = NULL;
|
// processCDT * lastBlocked = NULL;
|
||||||
sleepCDT * firstSleep = NULL;
|
sleepCDT * firstSleep = NULL;
|
||||||
|
|
||||||
static processCDT * currentProcess = NULL;
|
static processCDT * currentProcess = NULL;
|
||||||
|
@ -74,17 +41,103 @@ static int pids = IDLE_PID;
|
||||||
static char update = 1;
|
static char update = 1;
|
||||||
static char idleFlag = 2;
|
static char idleFlag = 2;
|
||||||
|
|
||||||
uint64_t nextProcess() {
|
void debug() {
|
||||||
update = 1;
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
void removeProcess(processCDT * del, processCDT * prev, processCDT ** first, processCDT ** last) {
|
||||||
|
if (prev == NULL) {
|
||||||
|
*first = del->next;
|
||||||
|
if (*last == del)
|
||||||
|
*last = NULL;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
prev->next = del->next;
|
||||||
|
if (*last == del)
|
||||||
|
*last = prev;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
uint64_t nextProcess(uint64_t currentRSP) {
|
||||||
|
if (currentProcess != NULL /*&& currentProcess->state != BLOCKED*/)
|
||||||
|
currentProcess->rsp = currentRSP;
|
||||||
|
processCDT * prev = currentProcess;
|
||||||
|
if (currentProcess != NULL)
|
||||||
|
currentProcess = currentProcess->next;
|
||||||
|
while (currentProcess == NULL || currentProcess->state == BLOCKED || currentProcess->state == DEAD) {
|
||||||
if (currentProcess == NULL) {
|
if (currentProcess == NULL) {
|
||||||
if (firstReady == NULL) {
|
currentProcess = firstProcess;
|
||||||
|
}
|
||||||
|
else if (currentProcess == firstBlockedIteration) {
|
||||||
|
idleFlag = 2;
|
||||||
|
unblock(IDLE_PID);
|
||||||
|
prev = currentProcess;
|
||||||
|
currentProcess = currentProcess->next;
|
||||||
|
}
|
||||||
|
else if (currentProcess->state == DEAD) {
|
||||||
|
debug();
|
||||||
|
processCDT * del = currentProcess;
|
||||||
|
currentProcess = currentProcess->next;
|
||||||
|
removeProcess(del, prev, &firstProcess, &lastProcess);
|
||||||
|
vPortFree((void *) del);
|
||||||
|
}
|
||||||
|
else if (currentProcess->state == BLOCKED) {
|
||||||
|
if (firstBlockedIteration == NULL)
|
||||||
|
firstBlockedIteration = currentProcess;
|
||||||
|
prev = currentProcess;
|
||||||
|
currentProcess = currentProcess->next;
|
||||||
|
}
|
||||||
|
else if (currentProcess->state == READY && currentProcess->executions == MAX_PRIORITY - currentProcess->priority + 1) {
|
||||||
|
currentProcess->executions = 0;
|
||||||
|
prev = currentProcess;
|
||||||
|
currentProcess = currentProcess->next;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (currentProcess->pid != IDLE_PID)
|
||||||
|
block(IDLE_PID);
|
||||||
|
firstBlockedIteration = NULL;
|
||||||
|
currentProcess->executions++;
|
||||||
|
return currentProcess->rsp;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
uint64_t nextProcess(uint64_t currentRSP) {
|
||||||
|
if (currentProcess == firstBlockedIteration) {
|
||||||
idleFlag = 2;
|
idleFlag = 2;
|
||||||
unblock(IDLE_PID);
|
unblock(IDLE_PID);
|
||||||
}
|
}
|
||||||
|
update = 1;
|
||||||
currentProcess = firstReady;
|
if (currentProcess == NULL) {
|
||||||
return firstReady->rsp;
|
currentProcess = firstProcess;
|
||||||
|
return currentProcess->rsp;
|
||||||
}
|
}
|
||||||
|
else if (currentProcess->state == DEAD) {
|
||||||
|
processCDT * del = currentProcess;
|
||||||
|
if (currentProcess->next != NULL) {
|
||||||
|
currentProcess = currentProcess->next;
|
||||||
|
}
|
||||||
|
else currentProcess = firstProcess;
|
||||||
|
processCDT * prev = NULL;
|
||||||
|
removeProcess(del, prev, &firstProcess, &lastProcess);
|
||||||
|
vPortFree((void *) del);
|
||||||
|
return currentProcess->rsp;
|
||||||
|
}
|
||||||
|
currentProcess->rsp = currentRSP;
|
||||||
|
if (currentProcess->state == BLOCKED) {
|
||||||
|
if (firstBlockedIteration == NULL)
|
||||||
|
firstBlockedIteration = currentProcess;
|
||||||
|
processCDT * del = currentProcess;
|
||||||
|
if (currentProcess->next != NULL) {
|
||||||
|
currentProcess = currentProcess->next;
|
||||||
|
}
|
||||||
|
else if (firstProcess == NULL) {
|
||||||
|
idleFlag = 2;
|
||||||
|
unblock(IDLE_PID);
|
||||||
|
}
|
||||||
|
else currentProcess = firstProcess;
|
||||||
|
return currentProcess->rsp;
|
||||||
|
}
|
||||||
|
firstBlockedIteration = NULL;
|
||||||
if (currentProcess->executions < MAX_PRIORITY - currentProcess->priority + 1) {
|
if (currentProcess->executions < MAX_PRIORITY - currentProcess->priority + 1) {
|
||||||
currentProcess->executions++;
|
currentProcess->executions++;
|
||||||
return currentProcess->rsp;
|
return currentProcess->rsp;
|
||||||
|
@ -93,10 +146,11 @@ uint64_t nextProcess() {
|
||||||
if (currentProcess->next != NULL)
|
if (currentProcess->next != NULL)
|
||||||
currentProcess = currentProcess->next;
|
currentProcess = currentProcess->next;
|
||||||
else {
|
else {
|
||||||
currentProcess = firstReady;
|
currentProcess = firstProcess;
|
||||||
}
|
}
|
||||||
return currentProcess->rsp;
|
return currentProcess->rsp;
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
void idle() {
|
void idle() {
|
||||||
while (1) {
|
while (1) {
|
||||||
|
@ -106,15 +160,9 @@ void idle() {
|
||||||
|
|
||||||
void initScheduler() {
|
void initScheduler() {
|
||||||
char * argv[] = {"idle"};
|
char * argv[] = {"idle"};
|
||||||
enqueueProcess(idle, 0, 1, argv, NULL);
|
nice(enqueueProcess(idle, 0, 1, argv, NULL), 19);
|
||||||
}
|
}
|
||||||
|
|
||||||
// void setFn(void (*fn) (int, char **), int argc, char *argv[]) {
|
|
||||||
// currentProcess->rsp = (currentProcess->rbp) - 20;
|
|
||||||
// _initialize_stack_frame(fn, currentProcess->rbp, argc, argv);
|
|
||||||
// }
|
|
||||||
|
|
||||||
// void enqueueProcess(void (*fn) (int, char **), char foreground, int argc, char *argv[]) {
|
|
||||||
int enqueueProcess(void (*fn) (int, char **), char foreground, int argc, char *argv[], int * fd) {
|
int enqueueProcess(void (*fn) (int, char **), char foreground, int argc, char *argv[], int * fd) {
|
||||||
if (fd == NULL) {
|
if (fd == NULL) {
|
||||||
int * aux = pvPortMalloc(2 * sizeof(int));
|
int * aux = pvPortMalloc(2 * sizeof(int));
|
||||||
|
@ -122,7 +170,7 @@ int enqueueProcess(void (*fn) (int, char **), char foreground, int argc, char *a
|
||||||
aux[1] = 1;
|
aux[1] = 1;
|
||||||
fd = aux;
|
fd = aux;
|
||||||
}
|
}
|
||||||
if (firstReady != NULL && firstReady->pid == IDLE_PID)
|
if (!idleFlag)
|
||||||
block(IDLE_PID);
|
block(IDLE_PID);
|
||||||
|
|
||||||
processADT process = pvPortMalloc(sizeof(processCDT));
|
processADT process = pvPortMalloc(sizeof(processCDT));
|
||||||
|
@ -151,39 +199,19 @@ int enqueueProcess(void (*fn) (int, char **), char foreground, int argc, char *a
|
||||||
process->state = READY;
|
process->state = READY;
|
||||||
process->fd = fd;
|
process->fd = fd;
|
||||||
process->next = NULL;
|
process->next = NULL;
|
||||||
// process->bytes->s.fpuBytes = pvPortMalloc(108);
|
|
||||||
// process->bytes->s.sseBytes = pvPortMalloc(512);
|
|
||||||
// process->sseBytes = pvPortMalloc(64);
|
|
||||||
// process->fpuBytes = pvPortMalloc(14);
|
|
||||||
|
|
||||||
// _initialize_stack_frame(fn, rbp, argc, argv, &(process->fpuBytes), &(process->sseBytes));
|
process->rsp = _initialize_stack_frame(fn, rbp, argc, argv);
|
||||||
// _initialize_stack_frame(fn, rbp, argc, argv, &(process->bytes->s.sseBytes), &(process->bytes->s.fpuBytes));
|
// _initialize_stack_frame(fn, rbp, argc, argv);
|
||||||
// _initialize_stack_frame(fn, rbp, argc, argv, process->bytes->s.sseBytes, process->bytes->s.fpuBytes);
|
|
||||||
// process->rsp = _initialize_stack_frame(fn, rbp, argc, argv);
|
|
||||||
_initialize_stack_frame(fn, rbp, argc, argv);
|
|
||||||
|
|
||||||
if (firstReady == NULL)
|
if (firstProcess == NULL)
|
||||||
firstReady = process;
|
firstProcess = process;
|
||||||
else
|
else
|
||||||
lastReady->next = process;
|
lastProcess->next = process;
|
||||||
lastReady = process;
|
lastProcess = process;
|
||||||
|
|
||||||
return process->pid;
|
return process->pid;
|
||||||
}
|
}
|
||||||
|
|
||||||
void removeProcess(processCDT * del, processCDT * prev, processCDT ** first, processCDT ** last) {
|
|
||||||
if (prev == NULL) {
|
|
||||||
*first = del->next;
|
|
||||||
if (*last == del)
|
|
||||||
*last = NULL;
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
prev->next = del->next;
|
|
||||||
if (*last == del)
|
|
||||||
*last = prev;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void sleep(int secs) {
|
void sleep(int secs) {
|
||||||
if (currentProcess == NULL)
|
if (currentProcess == NULL)
|
||||||
return;
|
return;
|
||||||
|
@ -204,7 +232,7 @@ void wakeUp(sleepCDT * wake, sleepCDT * prev) {
|
||||||
else {
|
else {
|
||||||
prev->next = wake->next;
|
prev->next = wake->next;
|
||||||
}
|
}
|
||||||
unblockFirst(wake->pid);
|
unblock(wake->pid);
|
||||||
vPortFree(wake);
|
vPortFree(wake);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -255,11 +283,13 @@ processADT searchProcess(processADT * previous, int pid, processADT first) {
|
||||||
|
|
||||||
char block(int pid) {
|
char block(int pid) {
|
||||||
processADT prev = NULL;
|
processADT prev = NULL;
|
||||||
processADT del = searchProcess(&prev, pid, firstReady);
|
processADT del = searchProcess(&prev, pid, firstProcess);
|
||||||
if (del == NULL)
|
if (del == NULL)
|
||||||
return EXIT_FAILURE;
|
return EXIT_FAILURE;
|
||||||
else {
|
else {
|
||||||
removeProcess(del, prev, &firstReady, &lastReady);
|
// removeProcess(del, prev, &firstReady, &lastReady);
|
||||||
|
del->state = BLOCKED;
|
||||||
|
//blockProcess(del, prev);
|
||||||
// if (prev != NULL) {
|
// if (prev != NULL) {
|
||||||
// prev->next = del->next;
|
// prev->next = del->next;
|
||||||
// if (lastReady == del)
|
// if (lastReady == del)
|
||||||
|
@ -272,31 +302,45 @@ char block(int pid) {
|
||||||
// }
|
// }
|
||||||
}
|
}
|
||||||
|
|
||||||
processCDT * next = del->next;
|
// processCDT * next = del->next;
|
||||||
del->next = NULL;
|
// del->next = NULL;
|
||||||
|
|
||||||
if (lastBlocked != NULL)
|
// del->state = BLOCKED;
|
||||||
lastBlocked->next = del;
|
// if (lastBlocked != NULL)
|
||||||
else
|
// lastBlocked->next = del;
|
||||||
firstBlocked = del;
|
// else
|
||||||
lastBlocked = del;
|
// firstBlocked = del;
|
||||||
|
// lastBlocked = del;
|
||||||
|
|
||||||
|
// processCDT * auxCurr = pvPortMalloc(sizeof(processCDT));
|
||||||
|
// auxCurr->next = next;
|
||||||
|
// auxCurr->pid = pid;
|
||||||
|
// currentProcess->state = BLOCKED;
|
||||||
|
|
||||||
if (pid == currentProcess->pid) {
|
if (pid == currentProcess->pid) {
|
||||||
update = 0;
|
// update = 0;
|
||||||
currentProcess = next;
|
// currentProcess = next;
|
||||||
|
|
||||||
forceTimer();
|
forceTimer();
|
||||||
}
|
}
|
||||||
|
|
||||||
return EXIT_SUCCESS;
|
return EXIT_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// void debug() {
|
||||||
|
// return;
|
||||||
|
// }
|
||||||
|
|
||||||
char unblock(int pid) {
|
char unblock(int pid) {
|
||||||
processADT prev = NULL;
|
processADT prev = NULL;
|
||||||
processADT del = searchProcess(&prev, pid, firstBlocked);
|
processADT del = searchProcess(&prev, pid, firstProcess);
|
||||||
if (del == NULL)
|
if (del == NULL) {
|
||||||
|
// debug();
|
||||||
return EXIT_FAILURE;
|
return EXIT_FAILURE;
|
||||||
|
}
|
||||||
else {
|
else {
|
||||||
removeProcess(del, prev, &firstBlocked, &lastBlocked);
|
// removeProcess(del, prev, &firstBlocked, &lastBlocked);
|
||||||
|
del->state = READY;
|
||||||
// if (prev != NULL) {
|
// if (prev != NULL) {
|
||||||
// prev->next = del->next;
|
// prev->next = del->next;
|
||||||
// if (del == lastBlocked)
|
// if (del == lastBlocked)
|
||||||
|
@ -309,13 +353,14 @@ char unblock(int pid) {
|
||||||
// }
|
// }
|
||||||
}
|
}
|
||||||
|
|
||||||
del->next = NULL;
|
// del->next = NULL;
|
||||||
if (lastReady != NULL)
|
// if (lastReady != NULL)
|
||||||
lastReady->next = del;
|
// lastReady->next = del;
|
||||||
else
|
// else
|
||||||
firstReady = del;
|
// firstReady = del;
|
||||||
lastReady = del;
|
// lastReady = del;
|
||||||
|
//
|
||||||
|
// del->state = READY;
|
||||||
// if (firstReady != NULL && firstReady->pid == IDLE_PID && lastReady->pid != IDLE_PID)
|
// if (firstReady != NULL && firstReady->pid == IDLE_PID && lastReady->pid != IDLE_PID)
|
||||||
if (idleFlag && !(--idleFlag))
|
if (idleFlag && !(--idleFlag))
|
||||||
block(IDLE_PID);
|
block(IDLE_PID);
|
||||||
|
@ -323,13 +368,15 @@ char unblock(int pid) {
|
||||||
return EXIT_SUCCESS;
|
return EXIT_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
char unblockFirst(int pid) {
|
char unblockFirst(int pid) {
|
||||||
processADT prev = NULL;
|
processADT prev = NULL;
|
||||||
processADT del = searchProcess(&prev, pid, firstBlocked);
|
processADT del = searchProcess(&prev, pid, firstBlocked);
|
||||||
if (del == NULL)
|
if (del == NULL)
|
||||||
return EXIT_FAILURE;
|
return EXIT_FAILURE;
|
||||||
else {
|
else {
|
||||||
removeProcess(del, prev, &firstBlocked, &lastBlocked);
|
// removeProcess(del, prev, &firstBlocked, &lastBlocked);
|
||||||
|
|
||||||
// if (prev != NULL) {
|
// if (prev != NULL) {
|
||||||
// prev->next = del->next;
|
// prev->next = del->next;
|
||||||
// if (lastBlocked == del)
|
// if (lastBlocked == del)
|
||||||
|
@ -357,33 +404,36 @@ char unblockFirst(int pid) {
|
||||||
lastReady = del;
|
lastReady = del;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
del->state = READY;
|
||||||
|
|
||||||
// if (firstReady != NULL && lastReady->pid == IDLE_PID && firstReady->pid != IDLE_PID)
|
// if (firstReady != NULL && lastReady->pid == IDLE_PID && firstReady->pid != IDLE_PID)
|
||||||
if (idleFlag && !(--idleFlag))
|
if (idleFlag && !(--idleFlag))
|
||||||
block(IDLE_PID);
|
block(IDLE_PID);
|
||||||
|
|
||||||
return EXIT_SUCCESS;
|
return EXIT_SUCCESS;
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
char kill(int pid) {
|
char kill(int pid) {
|
||||||
processADT prev = NULL;
|
processADT prev = NULL;
|
||||||
processADT del = searchProcess(&prev, pid, firstReady);
|
processADT del = searchProcess(&prev, pid, firstProcess);
|
||||||
if (del == NULL) {
|
if (del == NULL) {
|
||||||
del = searchProcess(&prev, pid, firstBlocked);
|
// del = searchProcess(&prev, pid, firstBlocked);
|
||||||
if (del == NULL)
|
// if (del == NULL)
|
||||||
return EXIT_FAILURE;
|
return EXIT_FAILURE;
|
||||||
else {
|
// else {
|
||||||
removeProcess(del, prev, &firstBlocked, &lastBlocked);
|
// removeProcess(del, prev, &firstBlocked, &lastBlocked);
|
||||||
// if (prev != NULL) {
|
// // if (prev != NULL) {
|
||||||
// prev->next = del->next;
|
// // prev->next = del->next;
|
||||||
// if (del == lastBlocked)
|
// // if (del == lastBlocked)
|
||||||
// lastBlocked = prev;
|
// // lastBlocked = prev;
|
||||||
|
// // }
|
||||||
|
// // else
|
||||||
|
// // firstBlocked = del->next;
|
||||||
// }
|
// }
|
||||||
// else
|
|
||||||
// firstBlocked = del->next;
|
|
||||||
}
|
}
|
||||||
}
|
// else {
|
||||||
else {
|
// removeProcess(del, prev, &firstReady, &lastReady);
|
||||||
removeProcess(del, prev, &firstReady, &lastReady);
|
|
||||||
// if (prev != NULL) {
|
// if (prev != NULL) {
|
||||||
// prev->next = del->next;
|
// prev->next = del->next;
|
||||||
// if (del == lastReady)
|
// if (del == lastReady)
|
||||||
|
@ -391,17 +441,19 @@ char kill(int pid) {
|
||||||
// }
|
// }
|
||||||
// else
|
// else
|
||||||
// firstReady = del->next;
|
// firstReady = del->next;
|
||||||
}
|
// }
|
||||||
|
|
||||||
processCDT * next = del->next;
|
// processCDT * next = del->next;
|
||||||
|
|
||||||
vPortFree(del->fd);
|
vPortFree(del->fd);
|
||||||
vPortFree((void *) del->rbp - STACK_SIZE);
|
vPortFree((void *) del->rbp - STACK_SIZE);
|
||||||
vPortFree((void *) del);
|
currentProcess->state = DEAD;
|
||||||
|
|
||||||
if (pid == currentProcess->pid) {
|
if (pid == currentProcess->pid) {
|
||||||
update = 0;
|
// if (pid < 9)
|
||||||
currentProcess = next;
|
// update = 0;
|
||||||
|
// currentProcess = next;
|
||||||
|
|
||||||
forceTimer();
|
forceTimer();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -429,13 +481,13 @@ char nice(int pid, char offset) {
|
||||||
return EXIT_FAILURE;
|
return EXIT_FAILURE;
|
||||||
|
|
||||||
processADT prev = NULL;
|
processADT prev = NULL;
|
||||||
processADT del = searchProcess(&prev, pid, firstReady);
|
processADT del = searchProcess(&prev, pid, firstProcess);
|
||||||
if (del == NULL) {
|
if (del == NULL) {
|
||||||
del = searchProcess(&prev, pid, firstBlocked);
|
// del = searchProcess(&prev, pid, firstBlocked);
|
||||||
if (del == NULL)
|
// if (del == NULL)
|
||||||
return EXIT_FAILURE;
|
return EXIT_FAILURE;
|
||||||
else
|
// else
|
||||||
del->priority = offset + 20;
|
// del->priority = offset + 20;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
del->priority = offset + 20;
|
del->priority = offset + 20;
|
||||||
|
@ -503,7 +555,8 @@ char getProcessData(char * out, processCDT * proc) {
|
||||||
getGenProcessData(&out, &written, MAX_ATTR_SIZE, itoa(proc->priority, buffer, 10, 2), 0);
|
getGenProcessData(&out, &written, MAX_ATTR_SIZE, itoa(proc->priority, buffer, 10, 2), 0);
|
||||||
getGenProcessData(&out, &written, MAX_NAME_SIZE, itoa(proc->rsp, buffer, 16, 10), 0);
|
getGenProcessData(&out, &written, MAX_NAME_SIZE, itoa(proc->rsp, buffer, 16, 10), 0);
|
||||||
getGenProcessData(&out, &written, MAX_NAME_SIZE, itoa(proc->rbp, buffer, 16, 10), 0);
|
getGenProcessData(&out, &written, MAX_NAME_SIZE, itoa(proc->rbp, buffer, 16, 10), 0);
|
||||||
getGenProcessData(&out, &written, MAX_ATTR_SIZE, (proc->foreground == 1) ? "F" : "B", 1);
|
getGenProcessData(&out, &written, MAX_ATTR_SIZE, (proc->foreground == 1) ? "F" : "B", 0);
|
||||||
|
getGenProcessData(&out, &written, MAX_ATTR_SIZE, proc->state == BLOCKED ? "Block" : proc->state == DEAD ? "Killed" : "Ready", 1);
|
||||||
|
|
||||||
return written;
|
return written;
|
||||||
}
|
}
|
||||||
|
@ -512,23 +565,17 @@ char * processes(){
|
||||||
char * ans = pvPortMalloc(pids * PROCESS_DATA_MAX_SIZE);
|
char * ans = pvPortMalloc(pids * PROCESS_DATA_MAX_SIZE);
|
||||||
char * ret = ans;
|
char * ret = ans;
|
||||||
|
|
||||||
char * info = "name pid prio rsp rbp fore\n";
|
char * info = "name pid prio rsp rbp fore state\n";
|
||||||
ans += strcpy(ans, info);
|
ans += strcpy(ans, info);
|
||||||
// ans += 56;
|
// ans += 56;
|
||||||
|
|
||||||
processCDT * aux = firstReady;
|
processCDT * aux = firstProcess;
|
||||||
while (aux != NULL) {
|
while (aux != NULL) {
|
||||||
char writtenChars = getProcessData(ans, aux);
|
char writtenChars = getProcessData(ans, aux);
|
||||||
if (writtenChars == EXIT_FAILURE)
|
if (writtenChars == EXIT_FAILURE)
|
||||||
return NULL;
|
return NULL;
|
||||||
ans += writtenChars - 1;
|
ans += writtenChars - 1;
|
||||||
*ans++ = '\n';
|
*ans++ = '\n';
|
||||||
|
|
||||||
if (aux == lastBlocked)
|
|
||||||
aux = NULL;
|
|
||||||
else if (aux == lastReady)
|
|
||||||
aux = firstBlocked;
|
|
||||||
else
|
|
||||||
aux = aux->next;
|
aux = aux->next;
|
||||||
}
|
}
|
||||||
*--ans = 0;
|
*--ans = 0;
|
||||||
|
|
|
@ -106,10 +106,12 @@ void semPost(sem_t * sem) {
|
||||||
|
|
||||||
sem->value++;
|
sem->value++;
|
||||||
|
|
||||||
|
if (sem->entering != NULL) {
|
||||||
pid_t * aux = sem->entering;
|
pid_t * aux = sem->entering;
|
||||||
sem->entering = sem->entering->next;
|
sem->entering = sem->entering->next;
|
||||||
unblock(sem->entering->pid);
|
unblock(sem->entering->pid);
|
||||||
vPortFree(aux);
|
vPortFree(aux);
|
||||||
|
}
|
||||||
|
|
||||||
leave_region(&semLock);
|
leave_region(&semLock);
|
||||||
}
|
}
|
||||||
|
|
|
@ -14,6 +14,7 @@ int main(int argc, char *argv[]) {
|
||||||
char * argv1[] = {"bottler"};
|
char * argv1[] = {"bottler"};
|
||||||
sys_loadProcess(bottler, 1, 1, argv1, NULL);
|
sys_loadProcess(bottler, 1, 1, argv1, NULL);
|
||||||
// sys_sleep(4);
|
// sys_sleep(4);
|
||||||
|
// winClear();
|
||||||
|
|
||||||
char * argv2[] = {"shell"};
|
char * argv2[] = {"shell"};
|
||||||
sys_loadProcess(shell, 1, 1, argv2, NULL);
|
sys_loadProcess(shell, 1, 1, argv2, NULL);
|
||||||
|
|
|
@ -2,12 +2,17 @@
|
||||||
#define PUAN -1
|
#define PUAN -1
|
||||||
|
|
||||||
void loop(int argc, char *argv[]) {
|
void loop(int argc, char *argv[]) {
|
||||||
int pid = sys_getPid(), secs = atoi(argv[1], PUAN);
|
// int pid = sys_getPid(), secs = atoi(argv[1], PUAN);
|
||||||
char * str = "Hola, soy el proceso ";
|
// char * str = "Hola, soy el proceso ";
|
||||||
char buffer[MAX_LEN];
|
// char buffer[MAX_LEN];
|
||||||
str = strcat(str, itoa(pid, buffer, 10));
|
// str = strcat(str, itoa(pid, buffer, 10));
|
||||||
while (1) {
|
// while (1) {
|
||||||
printString(str);
|
// printString(str);
|
||||||
sys_sleep(secs);
|
// sys_sleep(secs);
|
||||||
}
|
// }
|
||||||
|
|
||||||
|
int pid = sys_getPid();
|
||||||
|
sys_block(pid);
|
||||||
|
sys_unblock(pid);
|
||||||
|
sys_exit();
|
||||||
}
|
}
|
|
@ -201,8 +201,8 @@ void phylo(int argc, char ** argv) {
|
||||||
phil = phil->right;
|
phil = phil->right;
|
||||||
} while (phil != firstPhil);
|
} while (phil != firstPhil);
|
||||||
|
|
||||||
// char c;
|
//char c;
|
||||||
// while (1) {
|
//while (1) {
|
||||||
// while ((c = getChar()) != 0 && c != -1) {
|
// while ((c = getChar()) != 0 && c != -1) {
|
||||||
// if (c == 'a') {
|
// if (c == 'a') {
|
||||||
// addPhilo();
|
// addPhilo();
|
||||||
|
@ -214,18 +214,17 @@ void phylo(int argc, char ** argv) {
|
||||||
// break;
|
// break;
|
||||||
// }
|
// }
|
||||||
// }
|
// }
|
||||||
// }
|
//}
|
||||||
|
|
||||||
// phil = firstPhil;
|
//phil = firstPhil;
|
||||||
// do {
|
//do {
|
||||||
// sys_semClose(phil);
|
// sys_semClose(phil);
|
||||||
// sys_free(phil);
|
// sys_free(phil);
|
||||||
// sys_free(phil);
|
// sys_free(phil);
|
||||||
// sys_free(phil);
|
// sys_free(phil);
|
||||||
|
|
||||||
// sys_kill(phil->pid);
|
// sys_kill(phil->pid);
|
||||||
// phil = phil->right;
|
// phil = phil->right;
|
||||||
// } while (phil != firstPhil); // PROBLEMA
|
//} while (phil != firstPhil); // PROBLEMA
|
||||||
|
|
||||||
sys_exit();
|
sys_exit();
|
||||||
}
|
}
|
||||||
|
|
|
@ -20,6 +20,7 @@
|
||||||
#include "kill.h"
|
#include "kill.h"
|
||||||
#include "block.h"
|
#include "block.h"
|
||||||
#include "unblock.h"
|
#include "unblock.h"
|
||||||
|
#include "loop.h"
|
||||||
#define EXIT_FAILURE 1
|
#define EXIT_FAILURE 1
|
||||||
#define EXIT_SUCCESS 0
|
#define EXIT_SUCCESS 0
|
||||||
|
|
||||||
|
@ -55,6 +56,7 @@ cmd_t commands[] = {
|
||||||
{ "printmem", printmem, 0 },
|
{ "printmem", printmem, 0 },
|
||||||
{ "phylo", phylo, 0 },
|
{ "phylo", phylo, 0 },
|
||||||
{ "wc", wc, 0 },
|
{ "wc", wc, 0 },
|
||||||
|
{ "loop", loop, 0 },
|
||||||
{ NULL, NULL, 0}
|
{ NULL, NULL, 0}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue