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

Commit

Permalink
Fix Syscall 2, 7, 9 #19
Browse files Browse the repository at this point in the history
( Syscall 2 e 8 non faceva i controlli corretti sui puntatori forniti )
( Syscall 7 re-implementata con relativa gestione per processo )
Fix inversione subdevice in eventNotify #20
  • Loading branch information
jjak0b committed May 14, 2020
1 parent d08ca47 commit be839b5
Show file tree
Hide file tree
Showing 5 changed files with 79 additions and 112 deletions.
46 changes: 13 additions & 33 deletions include/handler/shared.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,42 +5,12 @@

#define SYSNO2INDEX( n )( (n)-1 )

#define SYS_SPECPASSUP_AREA_OLD 0
#define SYS_SPECPASSUP_AREA_NEW 1
#define SYS_SPECPASSUP_TYPE_SYSBK 0
#define SYS_SPECPASSUP_TYPE_TLB 1
#define SYS_SPECPASSUP_TYPE_PGMTRAP 2


void SpecPassup_init();

/**
* @brief Indica se è stato definito un handler superiore del tipo fornito
*
* @param type
* @return int boooleano
*/
int IsSetSpecPassup( int type );

/**
* @brief Imposta l'area fornita come handler superiore del tipo fornito
*
* @param type
* @param area
* @return int
* - 0 se è l'area stata impostata correttamente
* - -1 se il tipo fornito non è gestito, area == NULL, oppure se è già stata assegnata un'area all'handler del tipo specifiato
*/
int SetSpecPassup( int type, state_t *area );

/**
* @brief Restituisce il puntatore dello stato dell'handler superiore, associato al tipo specificato
*
* @param type
* @return state_t*
* - NULL se IsSetSpecPassup avrebbe restituito TRUE
* - l'area altrimenti
*/
state_t *GetSpecPassup( int type );

/**
* @brief Chiamante di system call che dati dei parametri forniti, chiama la specifica system call con i parametri dati
* @PostCondition valgono tutte le PostCondition delle system call
Expand Down Expand Up @@ -100,9 +70,19 @@ int Sys7_SpecPassup( state_t* currState, int type, state_t *old_area, state_t *n
* @brief assegna pid il puntatore al processo corrente, a ppid il puntatore al processo genitore
* @param pid
* @param ppid
*/
void Sys8_GetPID( pcb_t **pid, pcb_t **ppid );

/**
* @brief Carica sul processore lo stato associato alla specPassup del type fornito, memorizzando nella sua old area, lo stato request
*
* @param request
* @param type
* @return int
* -1 se il type fornito non è valido, oppure se non è stato associato un handler superiore al tipo fornito
* Altrimenti non dovrebbe ritornare perchè il controllo dell'esecuzione cambia con quello dell handler associata
*/
int Sys8_GetPID( pcb_t **pid, pcb_t **ppid );
int handle_specPassUp( state_t *request, int type );

// Interrupt Handler functions and define
//-------------------------------------------------------
Expand Down
6 changes: 6 additions & 0 deletions include/system/types_bikaya.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,12 @@ typedef struct pcb_t {
/* chrono start tod = tod of the last chronometer activation */
unsigned int first_activation_tod, chrono_start_tod;
unsigned int kmode_timelapse, umode_timelapse;

/*
stati del processore dedicati a handler di livello superiore specifici
nelle righe sono specificati i puntatori alle zone di memoria della old e new area rispettivamente
*/
state_t *specPassup[3][2];
} pcb_t;


Expand Down
133 changes: 56 additions & 77 deletions src/handler/shared.c
Original file line number Diff line number Diff line change
Expand Up @@ -28,35 +28,6 @@
#include <shared/device/terminal.h>
#include <system/shared/registers.h>

HIDDEN state_t specPassup[3]; /* stati del processore dedicati a handler di livello superiore specifici */
HIDDEN byte bitmap_specPassup; /* bitmap con i flag settati sulle i-esime posizioni se la specPassup[ i ] è assegnata */

void SpecPassup_init() {
bitmap_specPassup = 0;
}

int IsSetSpecPassup( int type ) {
byte mask_specPassup_type = 1 << type;
return (bitmap_specPassup & mask_specPassup_type) == mask_specPassup_type;
}

int SetSpecPassup( int type, state_t *area ) {
if( area != NULL && ( type >= 0 && type <= 2 ) && !IsSetSpecPassup( type ) ) {
/* copia la area corrispondente e imposta l'i-esmi bit della bitmap relativo al tipo fornito*/
moveState(area, &specPassup[ type ]);
bitmap_specPassup |= (1 << type);
return TRUE;
}
return FALSE;
}

state_t *GetSpecPassup( int type ) {
if( IsSetSpecPassup( type ) ) {
return &specPassup[ type ];
}
return NULL;
}

word Syscaller( state_t *state, word sysNo, word param1, word param2, word param3, word *returnValue ) {
int b_hasReturnValue = FALSE;
switch( sysNo ) {
Expand Down Expand Up @@ -85,17 +56,12 @@ word Syscaller( state_t *state, word sysNo, word param1, word param2, word param
*returnValue = (int) Sys7_SpecPassup( state, (int)param1, (state_t*)param2, (state_t*)param3 );
break;
case GETPID:
b_hasReturnValue = TRUE;
*returnValue = (int) Sys8_GetPID( (pcb_t**)param1, (pcb_t**)param2 );
Sys8_GetPID( (pcb_t**)param1, (pcb_t**)param2 );
break;
default: {
state_t *area = GetSpecPassup( SYS_SPECPASSUP_TYPE_SYSBK );
if( area != NULL ) {
LDST( area );
}
else {
b_hasReturnValue = TRUE;
if( handle_specPassUp( state, SYS_SPECPASSUP_TYPE_SYSBK ) ){
*returnValue = -1;
b_hasReturnValue = TRUE;
scheduler_StateToTerminate( NULL, FALSE );
}
break;
Expand Down Expand Up @@ -124,22 +90,21 @@ int Sys1_GetCPUTime( unsigned int *user, unsigned int *kernel, unsigned int *wal

int Sys2_CreateProcess( state_t *child_state, int child_priority, pcb_t **child_pid ) {
/* prima di eseguire viene controllata la validità dei puntatori forniti */
if ( child_state && child_pid ) {
*child_pid = allocPcb(); /* il puntatore sarà nullo in caso non vi siano PCB disponibili */
if ( child_state != NULL ) {
pcb_t *child = allocPcb(); /* il puntatore sarà nullo in caso non vi siano PCB disponibili */
if ( child != NULL ) {
moveState( child_state, &child->p_s );
child->priority = child_priority;
child->original_priority = child_priority;
insertChild( scheduler_GetRunningProcess(), child );
scheduler_AddProcess( child );
if( child_pid != NULL )
*child_pid = child;

if ( *child_pid ) {
moveState( child_state, &(*child_pid)->p_s );
(*child_pid)->priority = child_priority;
(*child_pid)->original_priority = child_priority;
insertChild( scheduler_GetRunningProcess(), *child_pid );
scheduler_AddProcess( *child_pid );
return 0;
}
else
return (-1);
}
}
else
return (-1);
return -1;
}

int Sys3_TerminateProcess( pcb_t *pid ) {
Expand Down Expand Up @@ -191,29 +156,43 @@ void Sys6_DoIO( word command, word *devregAddr, int subdevice ) {
}

int Sys7_SpecPassup( state_t* currState, int type, state_t *old_area, state_t *new_area ) {
if( !SetSpecPassup( type, new_area ) ) {
moveState( currState, old_area );
return 0;
pcb_t* p = scheduler_GetRunningProcess();
if( p != NULL && (0 <= type && type < 3) ) {
if( p->specPassup[ type ][ SYS_SPECPASSUP_AREA_NEW ] == NULL ) {
p->specPassup[ type ][ SYS_SPECPASSUP_AREA_NEW ] = new_area;
p->specPassup[ type ][ SYS_SPECPASSUP_AREA_OLD ] = old_area;
return 0;
}
else {
scheduler_StateToTerminate( p, TRUE );
}
}

scheduler_StateToTerminate( NULL, FALSE );
return -1;
}

int Sys8_GetPID( pcb_t **pid, pcb_t **ppid ) {
void Sys8_GetPID( pcb_t **pid, pcb_t **ppid ) {
/* la procedura ritorna errore in caso di puntatori non validi */
if ( pid && ppid ) {
*pid = scheduler_GetRunningProcess();
pcb_t *p = scheduler_GetRunningProcess();
if ( pid != NULL )
*pid = p;

if ( *pid )
*ppid = (*pid)->p_parent;
else
return (-1);

return 0;
}
if ( p != NULL && ppid != NULL )
*ppid = p->p_parent;
}

return (-1);
int handle_specPassUp( state_t *request, int type ) {
if( (0 <= type && type < 3) ) {
pcb_t *p = scheduler_GetRunningProcess();
state_t *new_area = p->specPassup[ type ][ SYS_SPECPASSUP_AREA_NEW ];
state_t *old_area = p->specPassup[ type ][ SYS_SPECPASSUP_AREA_OLD ];
if( p != NULL && new_area != NULL ) {
if( old_area != NULL ) {
moveState( request, old_area );
}
LDST( new_area );
}
}
return -1;
}

// Interrupt Handler
Expand Down Expand Up @@ -303,7 +282,7 @@ void notifyEvent(unsigned int line, unsigned int dev, unsigned int subdev_trasm,
word new_command = p->p_s.reg_param_1;
switch(line){
case IL_TERMINAL:
(subdev_trasm) ? (dev_reg->term.transm_command = new_command) : (dev_reg->term.recv_command = new_command);
(!subdev_trasm) ? (dev_reg->term.transm_command = new_command) : (dev_reg->term.recv_command = new_command);
break;
default:
dev_reg->dtp.command = new_command;
Expand All @@ -312,24 +291,24 @@ void notifyEvent(unsigned int line, unsigned int dev, unsigned int subdev_trasm,
//----------------------------------------------------------------

void Handle_Trap(void){
state_t *area = GetSpecPassup( SYS_SPECPASSUP_TYPE_PGMTRAP );
if( area != NULL ) {
LDST( area );
state_t *request = (state_t *) PGMTRAP_OLDAREA;
if( handle_specPassUp( request, SYS_SPECPASSUP_TYPE_PGMTRAP ) ){
scheduler_StateToTerminate( NULL, FALSE );
scheduler_schedule( TRUE );
}
PANIC();
}

void Handle_TLB(void){
state_t *area = GetSpecPassup( SYS_SPECPASSUP_TYPE_TLB );
if( area != NULL ) {
LDST( area );
state_t *request = (state_t *) TLB_OLDAREA;
if( handle_specPassUp( request, SYS_SPECPASSUP_TYPE_TLB ) ){
scheduler_StateToTerminate( NULL, FALSE );
scheduler_schedule( TRUE );
}
PANIC();
}

void Handle_breakpoint() {
state_t *area = GetSpecPassup( SYS_SPECPASSUP_TYPE_SYSBK );
if( area != NULL ) {
LDST( area );
}
state_t *request = (state_t *) SYSBK_OLDAREA;
handle_specPassUp( request, SYS_SPECPASSUP_TYPE_SYSBK );
}
1 change: 0 additions & 1 deletion src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@
int main(){
//---------------------Inizialializzazione del sistema
initAreas();
SpecPassup_init();
initPcbs();
initASL();
device_init();
Expand Down
5 changes: 4 additions & 1 deletion src/pcb/pcb.c
Original file line number Diff line number Diff line change
Expand Up @@ -123,14 +123,17 @@ void pcb_init( pcb_t *new ){
new->chrono_start_tod = 0;
new->kmode_timelapse = 0;
new->umode_timelapse = 0;
int i, j;
for( i = 0; i < 3; i++ )
for( j = 0; j < 2; j++ )
new->specPassup[ i ][ j ] = NULL;
#ifdef TARGET_UMPS
new->p_s.entry_hi = 0;
new->p_s.cause = 0;
new->p_s.status = 0;
new->p_s.pc_epc = 0;
new->p_s.hi = 0;
new->p_s.lo = 0;
int i;
for( i = 0; i < STATE_GPR_LEN; i++ ){
new->p_s.gpr[ i ] = 0;
}
Expand Down

0 comments on commit be839b5

Please sign in to comment.