Skip to content
This repository has been archived by the owner on Sep 19, 2022. It is now read-only.

Commit

Permalink
Merge pull request #32 from specialfish9/phase3/gabriele
Browse files Browse the repository at this point in the history
Phase3/gabriele
  • Loading branch information
specialfish9 authored Jul 16, 2022
2 parents 6ccc3e4 + 4ff34e7 commit cb09f79
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 25 deletions.
57 changes: 33 additions & 24 deletions src/sys_support.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,10 @@
#include <umps3/umps/const.h>
#include <umps3/umps/libumps.h>
#include <umps3/umps/cp0.h>

#include "pandos_const.h"

#define PRINTCHR 2

void support_syscall_handler(support_t* act_proc_sup);
/*
unsigned int retValue = SYSCALL (GETTOD, 0, 0, 0);
GETTOD=1
Expand Down Expand Up @@ -42,13 +41,8 @@ SYSCALL (TERMINATE, 0, 0, 0);
TERMINATE=2
*/
inline void terminate(void){
/*
TODO usare la funzione di terminate della fase 2 al posto di kill_parent_and_progeny
*/

//spara al processo utente che l'ha chiamato
SYSCALL(TERMPROCESS, act_proc->p_pid, 0, 0);
//return is_alive(act_proc) ? RENQUEUE : NOTHING;
}

/*
Expand All @@ -67,7 +61,7 @@ inline int write_to_printer(unsigned int virtAddr, int len, unsigned int asid){
int i;
for(i=0; i<len; i++){
dev_reg->data0 = virtAddr+i; //carico il carattere da trasmettere sul campoi data0, data1 non viene usato
if((char)(virtAddr+i) == '\0'){
if(*((char*)(virtAddr+i)) == '\0'){
break;
}
SYSCALL(DOIO, (int)&dev_reg->command, PRINTCHR, 0);
Expand All @@ -91,16 +85,15 @@ int retValue = SYSCALL (WRITETERMINAL, char *virtAddr, int len, 0);
WRITETERMINAL=4
*/
inline int write_to_terminal(unsigned int virtAddr, int len, unsigned int asid){ //cresta
//TODO
termreg_t * dev_reg = (termreg_t*)DEV_REG_ADDR(IL_TERMINAL,asid-1); //sup_asid è l'id del processo, associazione 1:1 tra processi e devices
int i;
for(i=0; i<len; i++){
dev_reg->transm_command = virtAddr+i; //carico il carattere da trasmettere sul campo data0, data1 non viene usato
if((char)(virtAddr+i) == '\0'){
if(*((char*)(virtAddr+i)) == '\0'){
break;
}
SYSCALL(DOIO, (int)&dev_reg->transm_command, TRANSMITCHAR, 0);
if(dev_reg->transm_status != 5) //TODO CERCARE LA COSTANTE AL POSTO DI 5
if(dev_reg->transm_status != OKCHARTRANS)
return -dev_reg->transm_status;
}
return i;
Expand Down Expand Up @@ -151,19 +144,30 @@ inline int read_from_terminal(unsigned int virtAddr, unsigned int asid){ //


void support_handler(void){
support_t* act_proc_sup = (support_t*)SYSCALL(GETSUPPORTPTR,0,0,0);
unsigned int cause = CAUSE_GET_EXCCODE(act_proc_sup->sup_exceptState[GENERALEXCEPT].cause);
if(cause == EXC_SYS){
support_syscall_handler(act_proc_sup);
}else{ //TODO verificare che questo sia sempre una trap
support_trap_handler();
}





//se exc è syscall > 0
//support_syscall_handler() / se è = 0 ci entra lo stesso probabilmente e va nel caso default
//support_syscall_handler(act_proc_sup) / se è = 0 ci entra lo stesso probabilmente e va nel caso default
//altrimenti se exc è trap
//support_trap_handler()
}



void support_syscall_handler(void){
void support_syscall_handler(support_t* act_proc_sup){
unsigned int arg1, arg2, arg3;

support_t* act_proc_sup = (support_t*)SYSCALL(GETSUPPORTPTR,0,0,0);
if(act_proc_sup == NULL){
if(act_proc_sup == NULL){ //TODO forse questo controllo va tolto / va messo nel support_handler() perchè viene già fatto a priori dalla passup or die quindi è ridondante
//LOG("Error on get support");
return; //TODO gestire l'errore meglio
}
Expand All @@ -174,7 +178,7 @@ void support_syscall_handler(void){
arg3 = act_proc_sup->sup_exceptState[1].reg_a3;


int ret=0;
int ret=-2147483648; //uso MININT per evitare conflitti con i valori di ritorno che possono essere numeri negativi, 0 e positivi
switch(number){
case GETTOD:{
ret=get_TOD();
Expand All @@ -197,18 +201,23 @@ void support_syscall_handler(void){
}
}

if(ret != 0)
act_proc->p_s.reg_v0 = ret;
/*
TODO:
-after successful completion of syscall place any return status in v0 of U-proc and return control to calling process
-increment PC by 4
*/
//dopo il completamento con successo della syscall inserisco il valore di ritorno nel registro v0 del processo chiamante
if(ret != -2147483648) //uso MININT per evitare conflitti con i valori di ritorno che possono essere numeri negativi, 0 e positivi
act_proc_sup->sup_exceptState[1].reg_v0 = ret;

act_proc_sup->sup_exceptState[1].pc_epc = act_proc_sup->sup_exceptState[1].reg_t9 = act_proc_sup->sup_exceptState[1].pc_epc + WORDLEN; //incremento PC di 4


//TODO after successful completion of syscall place any return status in v0 (fatto) of U-proc and return control to calling process
enqueue_proc(act_proc, act_proc->p_prio);
scheduler_next();
}

void support_trap_handler(void){
void support_trap_handler(support_t* act_proc_sup){

if(act_proc_sup.)
//se il processo tiene mutua esclusione su un semaforo mutex del livello supporto (es. swap pool sem)
//rilascia la risorsa (NSYS4 / verhogen?)
//ammazza il processo (SYS2)
terminate();
}
1 change: 1 addition & 0 deletions src/sys_support.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ extern unsigned int get_TOD(void);
extern void terminate(void);
extern int write_to_printer(unsigned int virtAddr, int len, unsigned int asid);
extern int write_to_terminal(unsigned int virtAddr, int len, unsigned int asid);
extern void support_trap_handler(support_t* act_proc_sup);
extern int read_from_terminal(unsigned int virtAddr, unsigned int asid);


Expand Down
1 change: 0 additions & 1 deletion src/vm_support.c
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ typedef struct {
pteEntry_t *pg_tbl_entry;
} swppl_entry_t;

static int swp_pl_sem = 1;
static swppl_entry_t swppl_tbl[SWAP_POOL_SIZE];

/*
Expand Down
2 changes: 2 additions & 0 deletions src/vm_support.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
#ifndef VM_SUPPORT
#define VM_SUPPORT

extern int swp_pl_sem = 1;

extern void init_supp_structures(void);

extern void tlb_exc_handler(void);
Expand Down

0 comments on commit cb09f79

Please sign in to comment.