Skip to content

Commit

Permalink
Esqueleto Syscalls
Browse files Browse the repository at this point in the history
Vinculo Userland-Kernel listo, funcionalidades en proceso.
  • Loading branch information
pdomins committed Apr 26, 2021
1 parent 92e0472 commit 361d43f
Show file tree
Hide file tree
Showing 9 changed files with 127 additions and 26 deletions.
8 changes: 5 additions & 3 deletions Kernel/include/scheduler.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,16 @@

void initScheduler();

uint64_t * createProcess(uint64_t * entryPoint); //antes retornaba void
unsigned int createProcess(uint64_t * entryPoint); //antes retornaba void

unsigned int switchProcesses(uint64_t * rsp);
uint64_t * switchProcesses(uint64_t * rsp);

void switchStates(unsigned int pid);

void endProcess(unsigned int processID);
void endProcess(unsigned int pid);

void printProcesses();

void changePriorities(unsigned int pid, unsigned int newPriority);

#endif //SO_TP2_SCHEDULER_H
51 changes: 51 additions & 0 deletions Kernel/interruptions/syscallDispatcher.c
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#include <library.h>
#include <time.h>
#include <syscallDispatcher.h>
#include <scheduler.h>

#define READ_SYSCALL 0
#define WRITE_SYSCALL 1
Expand All @@ -16,6 +17,11 @@
#define SET_ALARM 11
#define SCREEN_HEIGHT 12
#define SCREEN_WIDTH 13
#define PS_SYSCALL 14
#define LOOP_SYSCALL 15
#define KILL_SYSCALL 16
#define NICE_SYSCALL 17
#define BLOCK_SYSCALL 18

#define MEM_BYTES 32

Expand All @@ -37,6 +43,16 @@ int screenHeightHandler();

int screenWidthHandler();

void psHandler();

void loopHandler();

void killHandler(unsigned int pid);

void niceHandler(unsigned int pid, int priority);

void blockHandler(unsigned int pid);


int syscallDispatcher(uint64_t call, uint64_t firstP, uint64_t secondP, uint64_t thirdP, uint64_t fourthP,
uint64_t fifthP) {
Expand Down Expand Up @@ -66,6 +82,21 @@ int syscallDispatcher(uint64_t call, uint64_t firstP, uint64_t secondP, uint64_t
return screenHeightHandler();
case SCREEN_WIDTH:
return screenWidthHandler();
case PS_SYSCALL:
psHandler();
return 0;
case LOOP_SYSCALL:
loopHandler();
return 0;
case KILL_SYSCALL:
killHandler((unsigned int) firstP);
return 0;
case NICE_SYSCALL:
niceHandler((unsigned int) firstP, (int) secondP);
return 0;
case BLOCK_SYSCALL:
blockHandler((unsigned int) firstP);
return 0;
default:
return -1;
}
Expand Down Expand Up @@ -109,4 +140,24 @@ int screenHeightHandler() {

int screenWidthHandler() {
return screenWidth();
}

void psHandler(){
printProcesses();
}

void loopHandler(){
//ID con saludo
}

void killHandler(unsigned int pid){
endProcess(pid);
}

void niceHandler(unsigned int pid, int priority){
changePriorities(pid,priority);
}

void blockHandler(unsigned int pid){
switchStates(pid);
}
2 changes: 1 addition & 1 deletion Kernel/utilities/circularQueue.c
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ PCB * deleteNode(QueueADT queue, unsigned int pid) {
}

static Node * deleteNodeRec(Node * first, unsigned int pid, PCB * pcb) {
if(first) == NULL) {
if(first == NULL) {
return first;
}

Expand Down
10 changes: 5 additions & 5 deletions Kernel/utilities/scheduler.c
Original file line number Diff line number Diff line change
Expand Up @@ -59,16 +59,16 @@ uint64_t * switchProcesses(uint64_t * rsp){
return currentProcess->rsp;
}

void switchStates(unsigned int processID){
void switchStates(unsigned int pid){
PCB *aux;
if ((aux = findPCB(processes, processID) ) != NULL){
if ((aux = findPCB(processes, pid) ) != NULL){
aux->state = aux->state == BLOCKED? READY:BLOCKED;
}
}

void endProcess(unsigned int processID){
void endProcess(unsigned int pid){
PCB *deleted;
if((deleted = deleteNode(proccesses, processID))!= NULL){
if((deleted = deleteNode(processes, pid))!= NULL){
mmFree(deleted->rbp - STACK_SIZE);
mmFree(deleted);
}
Expand All @@ -81,7 +81,7 @@ void printProcesses(){
}
}

void changePriorities(unsigned int processID, unsigned int newPriority){
void changePriorities(unsigned int pid, unsigned int newPriority){

}

Expand Down
11 changes: 10 additions & 1 deletion Userland/SampleCodeModule/include/apps.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

#include <stdint.h>

#define PROGRAMS 9
#define PROGRAMS 14

typedef struct {
char name[12];
Expand Down Expand Up @@ -33,5 +33,14 @@ void throwInvOpCode();

void about();

void ps();

void loop();

void kill(int args, char argv[][25]);

void nice(int args, char argv[][25]);

void block(int args, char argv[][25]);

#endif
10 changes: 10 additions & 0 deletions Userland/SampleCodeModule/include/syscalls.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,14 @@ int getHeight();

int getWidth();

void getProcessesList();

void generateIDGreet();

void killProcess(unsigned int pid);

void changeProcessPriority(unsigned int pid, int priority);

void changeProcessState(unsigned int pid);

#endif
27 changes: 27 additions & 0 deletions Userland/SampleCodeModule/libraries/syscalls.c
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,11 @@
#define SET_ALARM 11
#define SCREEN_HEIGHT 12
#define SCREEN_WIDTH 13
#define PS_SYSCALL 14
#define LOOP_SYSCALL 15
#define KILL_SYSCALL 16
#define NICE_SYSCALL 17
#define BLOCK_SYSCALL 18

int read(char *buffer, int length) {
return _syscall(READ_SYSCALL, length, buffer);
Expand Down Expand Up @@ -54,3 +59,25 @@ int getHeight() {
int getWidth() {
return _syscall(SCREEN_WIDTH);
}

void getProcessesList(){
return _syscall(PS_SYSCALL);
}

void generateIDGreet(){
return _syscall(LOOP_SYSCALL);
}

void killProcess(unsigned int pid){
return _syscall(KILL_SYSCALL, pid);

}

void changeProcessPriority(unsigned int pid, int priority){
return _syscall(NICE_SYSCALL, pid, priority);
}

void changeProcessState(unsigned int pid){
return _syscall(BLOCK_SYSCALL, pid);

} /*killProcess y changeProcessState podrian llamar a la misma syscall con un parametro que identifique si quiere matar o cambiar de estado*/
1 change: 0 additions & 1 deletion Userland/SampleCodeModule/sampleCodeModule.c
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
char * v = (char*)0xB8000 + 79 * 2;

int main() {
println("-----AAAAA-----");
initShell();
return 0;
}
33 changes: 18 additions & 15 deletions Userland/SampleCodeModule/utilities/apps.c
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,11 @@ programs commands[] = {{"about", about, " Information about
{"printmem", printMem, " Prints on screen the first 32 bytes from a given position."},
{"chess", chess, " Starts a PVP chess match. Try chess help for aditional info."},
{"clear", clear, " Clears the current screen."},
//{"ps", ps, " Displays a list of all the running processes with relevant data."},
//{"loop", loop, " Prints a process ID given a determined number of seconds."},
//{"kill", kill, " Kills a process given its ID."},
//{"nice", nice, " Changes the given process priority."},
//{"block", block, " Changes the process state given its ID."},
{"ps", ps, " Displays a list of all the running processes with relevant data."},
{"loop", loop, " Prints a process ID given a determined number of seconds."},
{"kill", kill, " Kills a process given its ID."},
{"nice", nice, " Changes the given process priority."},
{"block", block, " Changes the process state given its ID."},
{"exceptionZ", throwDivZero, " Throws a divide by zero exception"},
{"exceptionOP", throwInvOpCode, "Throws an invalid Operation Code Exception"}
};
Expand Down Expand Up @@ -132,23 +132,26 @@ int checkArgs(int args, int expected) {
}
return 1;
}
/*
void ps(){

void ps(){
getProcessesList();
}

void loop(){
generateIDGreet();
}

void kill(){
void kill(int args, char argv[][25]){
if (!checkArgs(args, 1)) return;
killProcess(0);
}

void nice(){
void nice(int args, char argv[][25]){
if (!checkArgs(args, 2)) return;
changeProcessPriority(0,0);
}

void block(){
}*/
void block(int args, char argv[][25]){
if (!checkArgs(args, 1)) return;
changeProcessState(0);
}

0 comments on commit 361d43f

Please sign in to comment.