Compare commits

..

No commits in common. "master" and "Interpreteur_Non_Securise" have entirely different histories.

6 changed files with 59 additions and 52 deletions

View file

@ -33,7 +33,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; }

View file

@ -11,7 +11,7 @@
%token tAFC tCPY tAFCA %token tAFC tCPY tAFCA
%token tREAD tWR %token tREAD tWR
%token tJMP tJMF %token tJMP tJMF
%token tGET tPRI tPRIC %token tGET tPRI
%token tCALL tRET %token tCALL tRET
%token tSTOP %token tSTOP
%token<nombre> tNB %token<nombre> tNB
@ -55,8 +55,6 @@ Instruction : tWR tNB tNB {add_instruction(WRITE, $2, $3, 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);};

View file

@ -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 @rm -f rondoudou_interpreter
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 gcc Lex_Yacc/as.tab.o Lex_Yacc/lex.yy.o Tables/tables.o -ll -o rondoudou_interpreter
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
View 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.

View file

@ -4,9 +4,6 @@
#define TAILLE_BUFFER_INSTRUCTIONS (1024) #define TAILLE_BUFFER_INSTRUCTIONS (1024)
#define TAILLE_MEMOIRE (64) #define TAILLE_MEMOIRE (64)
#define TAILLE_PILE_APPELS (16)
#define SECURED (1)
/**************************************************/ /**************************************************/
@ -35,12 +32,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;
@ -66,15 +57,6 @@ int check_adresse(int adresse) {
return adresse; return adresse;
} }
// 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) {
@ -187,39 +169,22 @@ void execute() {
} }
} else if (programme[eip].instruction == GET) { } else if (programme[eip].instruction == GET) {
printf("Veuillez saisir un nombre : \n");
scanf("%d", &(mem[check_adresse(ebp + programme[eip].param1)])); scanf("%d", &(mem[check_adresse(ebp + programme[eip].param1)]));
} else if (programme[eip].instruction == PRI) { } else if (programme[eip].instruction == PRI) {
printf("%d", mem[check_adresse(ebp + programme[eip].param1)]); printf("%d@%d\n", mem[check_adresse(ebp + programme[eip].param1)], ebp + programme[eip].param1);
} else if (programme[eip].instruction == PRIC) {
printf("%c", mem[check_adresse(ebp + programme[eip].param1)]);
} else if (programme[eip].instruction == CALL) { } else if (programme[eip].instruction == CALL) {
if (SECURED) {
pile[check_adresse_pile(esp)] = ebp;
esp++;
pile[check_adresse_pile(esp)] = eip + 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)] = ebp;
mem[check_adresse(ebp + programme[eip].param2 + 1)] = eip + 1; mem[check_adresse(ebp + programme[eip].param2 + 1)] = eip + 1;
ebp = ebp + programme[eip].param2 + 2; ebp = ebp + programme[eip].param2 + 2;
eip = programme[eip].param1 - 1; eip = programme[eip].param1 - 1;
}
} else if (programme[eip].instruction == RET) { } else if (programme[eip].instruction == RET) {
if (SECURED) {
esp--;
eip = pile[check_adresse_pile(esp)] - 1;
esp--;
ebp = pile[check_adresse_pile(esp)];
} else {
int lastebp = ebp; int lastebp = ebp;
eip = mem[check_adresse(ebp - 1)] - 1; eip = mem[check_adresse(ebp - 1)] - 1;
ebp = mem[check_adresse(ebp - 2)]; ebp = mem[check_adresse(ebp - 2)];
mem[check_adresse(lastebp - 2)] = mem[check_adresse(lastebp)]; 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) {

View file

@ -3,7 +3,7 @@
// Enum of the instruction // Enum of the instruction
enum instruction_t {ADD, MUL, SUB, DIV, INF, SUP, EQU, CPY, AFC, AFCA, READ, WRITE, JMP, JMF, PRI, PRIC, GET, CALL, RET, STOP}; enum instruction_t {ADD, MUL, SUB, DIV, INF, SUP, EQU, CPY, AFC, AFCA, READ, WRITE, JMP, JMF, 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);