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