Fix some errors
Co-authored-by: Ezequiel Bellver <ebellver@itba.edu.ar> Co-authored-by: Juan Barmasch <jbarmasch@itba.edu.ar>
This commit is contained in:
parent
750006abbf
commit
f5eda8639a
|
@ -139,8 +139,8 @@ picSlaveMask:
|
|||
;8254 Timer (Timer Tick)
|
||||
_irq00Handler:
|
||||
pushState
|
||||
fsave [bytesForFPU]
|
||||
fxsave [bytesForSSEAligned]
|
||||
; fsave [bytesForFPU]
|
||||
; fxsave [bytesForSSEAligned]
|
||||
|
||||
mov rdi, 0
|
||||
call irqDispatcher
|
||||
|
@ -154,9 +154,11 @@ _irq00Handler:
|
|||
mov al, 20h
|
||||
out 20h, al
|
||||
|
||||
fxrstor [bytesForSSEAligned]
|
||||
frstor [bytesForFPU]
|
||||
; fxrstor [bytesForSSEAligned]
|
||||
; frstor [bytesForFPU]
|
||||
popState
|
||||
; pop rsi ; argv
|
||||
; pop rdi ; argc 6004d8
|
||||
iretq
|
||||
|
||||
;Keyboard
|
||||
|
@ -229,15 +231,15 @@ haltcpu:
|
|||
|
||||
_initialize_stack_frame:
|
||||
mov r10, rsp
|
||||
; mov rsp, rsi
|
||||
mov rsp, rsi
|
||||
|
||||
push 0x0 ; ss
|
||||
push rsi ; sp
|
||||
push 0x202 ; rflags
|
||||
push 0x08 ; cs -- offset de la GDT
|
||||
push rdi ; IP
|
||||
push rdx ; argc
|
||||
push rcx ; argv
|
||||
; push rdx ; argc
|
||||
; push rcx ; argv
|
||||
|
||||
pushState
|
||||
; mov rdi, rsp
|
||||
|
|
|
@ -11,7 +11,8 @@ int ticks_elapsed() {
|
|||
}
|
||||
|
||||
int seconds_elapsed() {
|
||||
return ticks / 18;
|
||||
// return ticks / 18;
|
||||
return ticks;
|
||||
}
|
||||
|
||||
int getTime(char option) {
|
||||
|
|
|
@ -1,6 +1,8 @@
|
|||
#include <stdint.h>
|
||||
#include "systemCalls.h"
|
||||
|
||||
void exitProcess();
|
||||
|
||||
uint64_t systemCallsDispatcher(uint64_t rdi, uint64_t rsi, uint64_t rdx, uint64_t rcx, uint64_t r8) {
|
||||
switch (rdi) {
|
||||
case 0:
|
||||
|
@ -13,6 +15,9 @@ uint64_t systemCallsDispatcher(uint64_t rdi, uint64_t rsi, uint64_t rdx, uint64_
|
|||
// createProcess(rsi);
|
||||
enqueueProcess(rsi, rdx, rcx, r8);
|
||||
break;
|
||||
case 4:
|
||||
exitProcess();
|
||||
break;
|
||||
default:
|
||||
return -1;
|
||||
}
|
||||
|
|
|
@ -147,6 +147,7 @@ void initScheduler();
|
|||
void _cli();
|
||||
void _sti();
|
||||
void haltcpu();
|
||||
void forceTimer();
|
||||
|
||||
int main() {
|
||||
// _cli();
|
||||
|
@ -179,8 +180,9 @@ int main() {
|
|||
enqueueProcess(sampleCodeModuleAddress, 1, 1, argv);
|
||||
// haltcpu();
|
||||
_sti();
|
||||
// forceTimer();
|
||||
|
||||
printBottlerAndWait();
|
||||
// printBottlerAndWait();
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
|
|
|
@ -22,7 +22,7 @@ typedef unsigned long UBaseType_t;
|
|||
|
||||
#define configSUPPORT_STATIC_ALLOCATION 1
|
||||
#define configSUPPORT_DYNAMIC_ALLOCATION 1
|
||||
#define configTOTAL_HEAP_SIZE 1024
|
||||
#define configTOTAL_HEAP_SIZE 1024 * 1024
|
||||
#define configAPPLICATION_ALLOCATED_HEAP 0
|
||||
#define portBYTE_ALIGNMENT 8
|
||||
#define portBYTE_ALIGNMENT_MASK ( 0x0007 ) // 8
|
||||
|
|
|
@ -24,16 +24,32 @@ processCDT * lastBlocked = NULL;
|
|||
int readyLen = 0;
|
||||
int blockedLen = 0;
|
||||
|
||||
processCDT * currentProcess = NULL;
|
||||
static processCDT * currentProcess = NULL;
|
||||
int pids = 0;
|
||||
|
||||
#include "naiveConsole.h"
|
||||
#include "time.h"
|
||||
uint64_t nextProcess() {
|
||||
if (currentProcess == NULL)
|
||||
if (currentProcess == NULL) {
|
||||
ncClear();
|
||||
ncPrint("Una cubana para el socio biza");
|
||||
ncPrint(firstReady->name);
|
||||
// ncPrintDec(firstReady->pid);
|
||||
ncPrintHex(firstReady->rsp);
|
||||
ncPrintHex(firstReady->rbp);
|
||||
// wait(4);
|
||||
currentProcess = firstReady;
|
||||
return firstReady->rsp;
|
||||
}
|
||||
if (currentProcess->executions < MAX_PRIORITY - currentProcess->priority + 1) {
|
||||
currentProcess->executions++;
|
||||
ncClear();
|
||||
ncPrint("Hola");
|
||||
// ncPrintDec(firstReady->pid);
|
||||
// wait(4);
|
||||
return currentProcess->rsp;
|
||||
}
|
||||
ncPrint("Chau");
|
||||
currentProcess->executions = 0;
|
||||
currentProcess = currentProcess->next;
|
||||
return currentProcess->rsp;
|
||||
|
@ -51,29 +67,58 @@ void initScheduler() {
|
|||
}
|
||||
|
||||
void enqueueProcess(void (*fn) (int, char **), char foreground, int argc, char *argv[]) {
|
||||
processADT proc = pvPortMalloc(sizeof(processCDT));
|
||||
uint64_t * rbp = pvPortMalloc(STACK_SIZE);
|
||||
uint64_t * rsp = rbp;
|
||||
processADT process = pvPortMalloc(sizeof(processCDT));
|
||||
uint64_t * rbp = STACK_SIZE + pvPortMalloc(STACK_SIZE);
|
||||
uint64_t * rsp = rbp - 20; //22
|
||||
|
||||
char priority = (foreground == 1) ? DEF_PRIORITY : MAX_PRIORITY/2;
|
||||
|
||||
newProcess(proc, argv[0], priority, foreground, (uint64_t)rsp, (uint64_t)rbp);
|
||||
// newProcess(process, argv[0], priority, foreground, (uint64_t) rsp, (uint64_t) rbp);
|
||||
// char aux[MAX_NAME_SIZE];
|
||||
char * aux = pvPortMalloc(10);
|
||||
int j;
|
||||
for (j = 0; j < MAX_NAME_SIZE - 1 && argv[0][j] != 0; j++) {
|
||||
aux[j] = argv[0][j];
|
||||
}
|
||||
aux[j] = '\0';
|
||||
|
||||
process->name = aux;
|
||||
process->pid = pids++;
|
||||
process->ppid = currentProcess->pid;
|
||||
process->priority = priority;
|
||||
process->rsp = (uint64_t) rsp;
|
||||
process->rbp = (uint64_t) rbp;
|
||||
process->executions = 0;
|
||||
process->foreground = foreground;
|
||||
process->state = READY;
|
||||
|
||||
_initialize_stack_frame(fn, rbp, argc, argv);
|
||||
|
||||
if (firstReady == NULL)
|
||||
firstReady = proc;
|
||||
if (firstReady == NULL) {
|
||||
firstReady = process;
|
||||
lastReady = firstReady;
|
||||
}
|
||||
else
|
||||
lastReady->next = proc;
|
||||
lastReady->next = process;
|
||||
|
||||
ncClear();
|
||||
ncPrint(argv[0]);
|
||||
// proc->name = argv[0];
|
||||
ncPrint(process->name);
|
||||
ncPrintDec(process->pid);
|
||||
ncPrintHex(process->rsp);
|
||||
ncPrintHex(process->rbp);
|
||||
// wait(3);
|
||||
return;
|
||||
}
|
||||
|
||||
void newProcess(processADT process, char * name, char priority, char foreground, uint64_t rsp, uint64_t rbp) {
|
||||
char aux[MAX_NAME_SIZE];
|
||||
for (int j = 0; j < MAX_NAME_SIZE && name[j] != 0; j++) {
|
||||
int j;
|
||||
for (j = 0; j < MAX_NAME_SIZE - 1 && name[j] != 0; j++) {
|
||||
aux[j] = name[j];
|
||||
}
|
||||
aux[j] = '\0';
|
||||
|
||||
process->name = aux;
|
||||
process->pid = pids++;
|
||||
|
@ -91,8 +136,8 @@ void newProcess(processADT process, char * name, char priority, char foreground,
|
|||
// exit();
|
||||
// }
|
||||
|
||||
processCDT * search(processCDT ** previous, int pid, processCDT * first) {
|
||||
processCDT * curr = first;
|
||||
processADT search(processADT * previous, int pid, processADT first) {
|
||||
processADT curr = first;
|
||||
* previous = NULL;
|
||||
while (curr != NULL) {
|
||||
if (curr->pid == pid) {
|
||||
|
@ -113,8 +158,8 @@ processCDT * search(processCDT ** previous, int pid, processCDT * first) {
|
|||
}
|
||||
|
||||
char block(int pid) {
|
||||
processCDT * prev = NULL;
|
||||
processCDT * del = search(&prev, pid, firstReady);
|
||||
processADT prev = NULL;
|
||||
processADT del = search(&prev, pid, firstReady);
|
||||
if (del == NULL)
|
||||
return EXIT_FAILURE;
|
||||
else {
|
||||
|
@ -134,8 +179,8 @@ char block(int pid) {
|
|||
}
|
||||
|
||||
char unblock(int pid) {
|
||||
processCDT * prev = NULL;
|
||||
processCDT * del = search(&prev, pid, firstBlocked);
|
||||
processADT prev = NULL;
|
||||
processADT del = search(&prev, pid, firstBlocked);
|
||||
if (del == NULL)
|
||||
return EXIT_FAILURE;
|
||||
else {
|
||||
|
@ -152,8 +197,8 @@ char unblock(int pid) {
|
|||
}
|
||||
|
||||
char kill(int pid) {
|
||||
processCDT * prev = NULL;
|
||||
processCDT * del = search(&prev, pid, firstReady);
|
||||
processADT prev = NULL;
|
||||
processADT del = search(&prev, pid, firstReady);
|
||||
if (del == NULL) {
|
||||
del = search(&prev, pid, firstBlocked);
|
||||
if (del == NULL)
|
||||
|
@ -193,8 +238,12 @@ char nice(char offset) {
|
|||
}
|
||||
|
||||
void updateRSP(uint64_t newRsp) {
|
||||
if (currentProcess == NULL)
|
||||
if (currentProcess == NULL) {
|
||||
ncClear();
|
||||
ncPrint("ES NULL");
|
||||
// wait(4);
|
||||
return;
|
||||
}
|
||||
currentProcess->rsp = newRsp;
|
||||
}
|
||||
|
||||
|
|
|
@ -3,6 +3,7 @@ GLOBAL _getMem, sys_loadProcess
|
|||
GLOBAL raiseOpcodeExc
|
||||
GLOBAL _getRegs, sys_switchContext
|
||||
GLOBAL cpu_id, cpu_id_support
|
||||
GLOBAL sys_exit
|
||||
|
||||
section .text
|
||||
|
||||
|
@ -54,6 +55,21 @@ sys_read:
|
|||
pop rbp
|
||||
ret
|
||||
|
||||
sys_exit:
|
||||
push rbp
|
||||
mov rbp, rsp
|
||||
|
||||
push rdi
|
||||
|
||||
mov rdi, 4
|
||||
int 80h
|
||||
|
||||
pop rdi
|
||||
|
||||
mov rsp, rbp
|
||||
pop rbp
|
||||
ret
|
||||
|
||||
_getMem:
|
||||
push rbp
|
||||
mov rbp, rsp
|
||||
|
|
|
@ -3,16 +3,17 @@
|
|||
#include "shell/include/shell.h"
|
||||
|
||||
void sys_loadProcess(void (*fn) (int, char **), char foreground, int argc, char *argv[]);
|
||||
void sys_exit();
|
||||
// void sys_switchContext();
|
||||
|
||||
int main() {
|
||||
int main(int argc, char *argv[]) {
|
||||
winClear();
|
||||
|
||||
char * argv[] = {"BottlerSh"};
|
||||
sys_loadProcess(shell, 1, 1, argv);
|
||||
char * argv2[] = {"BottlerSh"};
|
||||
sys_loadProcess(shell, 1, 1, argv2);
|
||||
// sys_loadProcess(shell);
|
||||
|
||||
// sys_switchContext();
|
||||
|
||||
sys_exit();
|
||||
return 1;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue