Compare commits
No commits in common. "master" and "InterpreteurRegistres_Non_Securise" have entirely different histories.
master
...
Interprete
6 changed files with 63 additions and 56 deletions
|
@ -34,7 +34,6 @@ yyerror (char const *s)
|
||||||
|
|
||||||
"GET" { return tGET; }
|
"GET" { return tGET; }
|
||||||
"PRI" { return tPRI; }
|
"PRI" { return tPRI; }
|
||||||
"PRIC" { return tPRIC; }
|
|
||||||
|
|
||||||
"CALL" { return tCALL; }
|
"CALL" { return tCALL; }
|
||||||
"RET" { return tRET; }
|
"RET" { return tRET; }
|
||||||
|
|
|
@ -11,7 +11,7 @@
|
||||||
%token tAFC tCPY
|
%token tAFC tCPY
|
||||||
%token tLOAD tSTORE tLOADI tSTOREI tSTOREA
|
%token tLOAD tSTORE tLOADI tSTOREI tSTOREA
|
||||||
%token tJMP tJMZ
|
%token tJMP tJMZ
|
||||||
%token tGET tPRI tPRIC
|
%token tGET tPRI
|
||||||
%token tCALL tRET
|
%token tCALL tRET
|
||||||
%token tSTOP
|
%token tSTOP
|
||||||
%token<nombre> tNB
|
%token<nombre> tNB
|
||||||
|
@ -48,7 +48,7 @@ Instruction : tLOADI tNB tNB {add_instruction(LOADI, $2, $3, 0);};
|
||||||
// STOREI R R
|
// STOREI R R
|
||||||
Instruction : tSTOREI tNB tNB {add_instruction(STOREI, $2, $3, 0);};
|
Instruction : tSTOREI tNB tNB {add_instruction(STOREI, $2, $3, 0);};
|
||||||
// STOREA @ R
|
// STOREA @ R
|
||||||
Instruction : tSTOREA tNB tNB {add_instruction(STOREA, $2, $3, 0);};
|
Instruction : tSTOREA tNB tNB {add_instruction(STORE, $2, $3, 0);};
|
||||||
|
|
||||||
// JMP Ins
|
// JMP Ins
|
||||||
Instruction : tJMP tNB {add_instruction(JMP, $2, 0, 0);};
|
Instruction : tJMP tNB {add_instruction(JMP, $2, 0, 0);};
|
||||||
|
@ -59,8 +59,6 @@ Instruction : tJMZ tNB {add_instruction(JMZ, $2, 0, 0);};
|
||||||
Instruction : tGET tNB {add_instruction(GET, $2, 0, 0);};
|
Instruction : tGET tNB {add_instruction(GET, $2, 0, 0);};
|
||||||
// PRI @
|
// PRI @
|
||||||
Instruction : tPRI tNB {add_instruction(PRI, $2, 0, 0);};
|
Instruction : tPRI tNB {add_instruction(PRI, $2, 0, 0);};
|
||||||
// PRIC @
|
|
||||||
Instruction : tPRIC tNB {add_instruction(PRIC, $2, 0, 0);};
|
|
||||||
|
|
||||||
// CALL Ins Val
|
// CALL Ins Val
|
||||||
Instruction : tCALL tNB tNB {add_instruction(CALL, $2, $3, 0);};
|
Instruction : tCALL tNB tNB {add_instruction(CALL, $2, $3, 0);};
|
||||||
|
|
4
Makefile
4
Makefile
|
@ -9,7 +9,7 @@ default :
|
||||||
clean_all : clean clean_Inputs clean_Outputs
|
clean_all : clean clean_Inputs clean_Outputs
|
||||||
|
|
||||||
clean: clean_Lex_Yacc clean_Tables
|
clean: clean_Lex_Yacc clean_Tables
|
||||||
@rm -f interpreter_registers
|
@rm -f rondoudou_interpreter_registres
|
||||||
|
|
||||||
clean_Tables:
|
clean_Tables:
|
||||||
@rm -f Tables/*.o
|
@rm -f Tables/*.o
|
||||||
|
@ -29,7 +29,7 @@ clean_Outputs:
|
||||||
### COMPILATION ###
|
### COMPILATION ###
|
||||||
###########################
|
###########################
|
||||||
build : clean build_Tables build_Lex_Yacc
|
build : clean build_Tables build_Lex_Yacc
|
||||||
gcc Lex_Yacc/as.tab.o Lex_Yacc/lex.yy.o Tables/tables.o -o interpreter_registers
|
gcc Lex_Yacc/as.tab.o Lex_Yacc/lex.yy.o Tables/tables.o -ll -o rondoudou_interpreter_registres
|
||||||
|
|
||||||
build_Tables: clean_Tables
|
build_Tables: clean_Tables
|
||||||
gcc -c Tables/tables.c -o Tables/tables.o
|
gcc -c Tables/tables.c -o Tables/tables.o
|
||||||
|
|
45
ReadMe.md
Normal file
45
ReadMe.md
Normal file
|
@ -0,0 +1,45 @@
|
||||||
|
# Processeur sécurisé - Interpreteur
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
Afin de pouvoir tester le code que nous avons compilé depuis le C avec notre compilateur, nous avons crée un interpreteur pour simuler l'execution du code assembleur
|
||||||
|
|
||||||
|
# Utilisation du cross assembleur
|
||||||
|
|
||||||
|
Un Makefile a été inclus au sous module Interpreteur afin de simplifier son utilisation. Ainsi, afin de compiler tout l'Interpreteur, il suffit de de rentrer la commande.
|
||||||
|
``` bash
|
||||||
|
make build
|
||||||
|
```
|
||||||
|
Pour lancer l'Interpretation du code qui aura été préalablement généré avec notre compilateur, il suffit de lancer la commande
|
||||||
|
``` bash
|
||||||
|
cat FicherASM | ./rondoudou_interpreter
|
||||||
|
```
|
||||||
|
Les prints et gets du programme auront lieu dans le terminal.
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
NB : Il est possible de rester au niveau du projet général. Un Makefile est aussi présent. Pour compiler l'Interpreteur uniquement :
|
||||||
|
``` bash
|
||||||
|
make compile QUOI="interpreteur"
|
||||||
|
```
|
||||||
|
Pour compiler le projet en entier :
|
||||||
|
``` bash
|
||||||
|
make compile QUOI="all"
|
||||||
|
```
|
||||||
|
|
||||||
|
Pour interpreter le fichier ***file_name.memasm*** :
|
||||||
|
``` bash
|
||||||
|
make exec SOURCE="file_name" QUOI="interprete"
|
||||||
|
```
|
||||||
|
Pour compiler, cross assembler et interpreter le fichier ***file_name.c*** et générer les fichiers ***file_name.memasm***, ***file_name.regasm***, ***file_name.bin***, et, copier le code binaire dans le fichier ***../Processeur/Processeur.srcs/sources1/new/MemoireInstructions.vhd*** :
|
||||||
|
``` bash
|
||||||
|
make exec SOURCE="file_name" QUOI="all"
|
||||||
|
```
|
||||||
|
|
||||||
|
# Implémentation
|
||||||
|
|
||||||
|
L'implémentation a été réalisée grâce à Lex/Yacc. Le parseur charge le programme dans un buffer, puis une méthode d'execution est lancée.
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -3,12 +3,9 @@
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
|
||||||
#define TAILLE_BUFFER_INSTRUCTIONS (1024)
|
#define TAILLE_BUFFER_INSTRUCTIONS (1024)
|
||||||
#define TAILLE_MEMOIRE (64)
|
#define TAILLE_MEMOIRE (32)
|
||||||
#define TAILLE_PILE_APPELS (4)
|
|
||||||
#define TAILLE_BANC_REGISTRES (16)
|
#define TAILLE_BANC_REGISTRES (16)
|
||||||
|
|
||||||
#define SECURED (1)
|
|
||||||
|
|
||||||
|
|
||||||
/**************************************************/
|
/**************************************************/
|
||||||
/**************************************************/
|
/**************************************************/
|
||||||
|
@ -39,12 +36,6 @@ int mem[TAILLE_MEMOIRE];
|
||||||
// Pointeur de base dans la mémoire
|
// Pointeur de base dans la mémoire
|
||||||
int ebp = 0;
|
int ebp = 0;
|
||||||
|
|
||||||
// Memoire du programme
|
|
||||||
int pile[TAILLE_PILE_APPELS];
|
|
||||||
|
|
||||||
// Pointeur de sommet dans la pile d'appel
|
|
||||||
int esp = 0;
|
|
||||||
|
|
||||||
// Flag Z
|
// Flag Z
|
||||||
int Z = 0;
|
int Z = 0;
|
||||||
|
|
||||||
|
@ -70,8 +61,6 @@ int Z = 0;
|
||||||
int check_adresse(int adresse) {
|
int check_adresse(int adresse) {
|
||||||
if (adresse >= TAILLE_MEMOIRE || adresse < 0) {
|
if (adresse >= TAILLE_MEMOIRE || adresse < 0) {
|
||||||
printf("\033[31;01m ERROR : \033[00m Segmentation fault de %d avec eip = %d et ebp = %d\n", adresse, eip, ebp);
|
printf("\033[31;01m ERROR : \033[00m Segmentation fault de %d avec eip = %d et ebp = %d\n", adresse, eip, ebp);
|
||||||
print();
|
|
||||||
print_reg();
|
|
||||||
exit(2);
|
exit(2);
|
||||||
}
|
}
|
||||||
return adresse;
|
return adresse;
|
||||||
|
@ -86,15 +75,6 @@ int check_registre(int registre) {
|
||||||
return registre;
|
return registre;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Verifie que les limites de la mémoire d'appels ne sont pas franchies
|
|
||||||
int check_adresse_pile(int adresse) {
|
|
||||||
if (adresse >= TAILLE_PILE_APPELS || adresse < 0) {
|
|
||||||
printf("\033[31;01m ERROR : \033[00m Stack error\n");
|
|
||||||
exit(2);
|
|
||||||
}
|
|
||||||
return adresse;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Verifie que eip ne depasse pas la taille du buffer
|
// Verifie que eip ne depasse pas la taille du buffer
|
||||||
int check_eip(int eip) {
|
int check_eip(int eip) {
|
||||||
if (eip >= TAILLE_BUFFER_INSTRUCTIONS) {
|
if (eip >= TAILLE_BUFFER_INSTRUCTIONS) {
|
||||||
|
@ -220,43 +200,28 @@ void execute() {
|
||||||
}
|
}
|
||||||
|
|
||||||
} else if (programme[eip].instruction == GET) {
|
} else if (programme[eip].instruction == GET) {
|
||||||
|
printf("Veuillez saisir un nombre : \n");
|
||||||
scanf("%d", &(registres[check_registre(programme[eip].param1)]));
|
scanf("%d", &(registres[check_registre(programme[eip].param1)]));
|
||||||
} else if (programme[eip].instruction == PRI) {
|
} else if (programme[eip].instruction == PRI) {
|
||||||
printf("%d", registres[check_registre(programme[eip].param1)]);
|
printf("%d@%d\n", registres[check_registre(programme[eip].param1)], programme[eip].param1);
|
||||||
} else if (programme[eip].instruction == PRIC) {
|
|
||||||
printf("%c", registres[check_registre(programme[eip].param1)]);
|
|
||||||
|
|
||||||
} else if (programme[eip].instruction == CALL) {
|
} else if (programme[eip].instruction == CALL) {
|
||||||
if (SECURED) {
|
mem[check_adresse(ebp + programme[eip].param2)] = ebp;
|
||||||
pile[check_adresse_pile(esp)] = ebp;
|
mem[check_adresse(ebp + programme[eip].param2 + 1)] = eip + 1;
|
||||||
esp++;
|
ebp = ebp + programme[eip].param2 + 2;
|
||||||
pile[check_adresse_pile(esp)] = eip + 1;
|
eip = programme[eip].param1 - 1;
|
||||||
esp++;
|
|
||||||
ebp = ebp + programme[eip].param2;
|
|
||||||
eip = programme[eip].param1 - 1;
|
|
||||||
} else {
|
|
||||||
mem[check_adresse(ebp + programme[eip].param2)] = ebp;
|
|
||||||
mem[check_adresse(ebp + programme[eip].param2 + 1)] = eip + 1;
|
|
||||||
ebp = ebp + programme[eip].param2 + 2;
|
|
||||||
eip = programme[eip].param1 - 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
} else if (programme[eip].instruction == RET) {
|
} else if (programme[eip].instruction == RET) {
|
||||||
if (SECURED) {
|
int lastebp = ebp;
|
||||||
esp--;
|
eip = mem[check_adresse(ebp - 1)] - 1;
|
||||||
eip = pile[check_adresse_pile(esp)] - 1;
|
ebp = mem[check_adresse(ebp - 2)];
|
||||||
esp--;
|
mem[check_adresse(lastebp - 2)] = mem[check_adresse(lastebp)];
|
||||||
ebp = pile[check_adresse_pile(esp)];
|
|
||||||
} else {
|
|
||||||
int lastebp = ebp;
|
|
||||||
eip = mem[check_adresse(ebp - 1)] - 1;
|
|
||||||
ebp = mem[check_adresse(ebp - 2)];
|
|
||||||
mem[check_adresse(lastebp - 2)] = mem[check_adresse(lastebp)];
|
|
||||||
}
|
|
||||||
|
|
||||||
} else if (programme[eip].instruction == STOP) {
|
} else if (programme[eip].instruction == STOP) {
|
||||||
if (programme[eip].param1 == 0) {
|
if (programme[eip].param1 == 0) {
|
||||||
continuer = 0;
|
continuer = 0;
|
||||||
|
print();
|
||||||
|
print_reg();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
eip = (eip + 1) % TAILLE_BUFFER_INSTRUCTIONS;
|
eip = (eip + 1) % TAILLE_BUFFER_INSTRUCTIONS;
|
||||||
|
|
|
@ -3,7 +3,7 @@
|
||||||
|
|
||||||
|
|
||||||
// Enum of the instruction
|
// Enum of the instruction
|
||||||
enum instruction_t {ADD, MUL, SUB, DIV, INF, SUP, EQU, CPY, AFC, LOAD, STORE, LOADI, STOREI, STOREA, JMP, JMZ, PRI, PRIC, GET, CALL, RET, STOP};
|
enum instruction_t {ADD, MUL, SUB, DIV, INF, SUP, EQU, CPY, AFC, LOAD, STORE, LOADI, STOREI, STOREA, JMP, JMZ, PRI, GET, CALL, RET, STOP};
|
||||||
|
|
||||||
// Add a new instruction
|
// Add a new instruction
|
||||||
void add_instruction(enum instruction_t inst, int param1, int param2, int param3);
|
void add_instruction(enum instruction_t inst, int param1, int param2, int param3);
|
||||||
|
|
Loading…
Reference in a new issue