Compare commits

..

7 commits

Author SHA1 Message Date
Faure Paul
20a372f29a Clean 2022-06-29 19:38:50 +02:00
Faure Paul
510d9c2d6c Clean 2022-06-27 21:46:01 +02:00
Faure Paul
084df49373 Ajout du PRIC 2021-07-16 16:04:28 +02:00
Faure Paul
9e9dd66c3a Basculement sur les PCs INSA => option ly au lieu de ll 2021-07-13 17:25:11 +02:00
bc036e3c94 Correctif merge 2021-06-24 15:19:58 +02:00
36996ae17f Merge branch 'InterpreteurRegistres_Non_Securise' 2021-06-24 14:53:55 +02:00
cf119a9a25 Fix bug STOREA 2021-06-24 09:43:08 +02:00
6 changed files with 56 additions and 63 deletions

View file

@ -34,6 +34,7 @@ yyerror (char const *s)
"GET" { return tGET; }
"PRI" { return tPRI; }
"PRIC" { return tPRIC; }
"CALL" { return tCALL; }
"RET" { return tRET; }

View file

@ -11,7 +11,7 @@
%token tAFC tCPY
%token tLOAD tSTORE tLOADI tSTOREI tSTOREA
%token tJMP tJMZ
%token tGET tPRI
%token tGET tPRI tPRIC
%token tCALL tRET
%token tSTOP
%token<nombre> tNB
@ -48,7 +48,7 @@ Instruction : tLOADI tNB tNB {add_instruction(LOADI, $2, $3, 0);};
// STOREI R R
Instruction : tSTOREI tNB tNB {add_instruction(STOREI, $2, $3, 0);};
// STOREA @ R
Instruction : tSTOREA tNB tNB {add_instruction(STORE, $2, $3, 0);};
Instruction : tSTOREA tNB tNB {add_instruction(STOREA, $2, $3, 0);};
// JMP Ins
Instruction : tJMP tNB {add_instruction(JMP, $2, 0, 0);};
@ -59,6 +59,8 @@ Instruction : tJMZ tNB {add_instruction(JMZ, $2, 0, 0);};
Instruction : tGET tNB {add_instruction(GET, $2, 0, 0);};
// PRI @
Instruction : tPRI tNB {add_instruction(PRI, $2, 0, 0);};
// PRIC @
Instruction : tPRIC tNB {add_instruction(PRIC, $2, 0, 0);};
// CALL Ins Val
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: clean_Lex_Yacc clean_Tables
@rm -f rondoudou_interpreter_registres
@rm -f interpreter_registers
clean_Tables:
@rm -f Tables/*.o
@ -29,7 +29,7 @@ clean_Outputs:
### COMPILATION ###
###########################
build : clean build_Tables build_Lex_Yacc
gcc Lex_Yacc/as.tab.o Lex_Yacc/lex.yy.o Tables/tables.o -ll -o rondoudou_interpreter_registres
gcc Lex_Yacc/as.tab.o Lex_Yacc/lex.yy.o Tables/tables.o -o interpreter_registers
build_Tables: clean_Tables
gcc -c Tables/tables.c -o Tables/tables.o

View file

@ -1,45 +0,0 @@
# 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

@ -3,9 +3,12 @@
#include <stdlib.h>
#define TAILLE_BUFFER_INSTRUCTIONS (1024)
#define TAILLE_MEMOIRE (32)
#define TAILLE_MEMOIRE (64)
#define TAILLE_PILE_APPELS (4)
#define TAILLE_BANC_REGISTRES (16)
#define SECURED (1)
/**************************************************/
/**************************************************/
@ -36,6 +39,12 @@ int mem[TAILLE_MEMOIRE];
// Pointeur de base dans la mémoire
int ebp = 0;
// Memoire du programme
int pile[TAILLE_PILE_APPELS];
// Pointeur de sommet dans la pile d'appel
int esp = 0;
// Flag Z
int Z = 0;
@ -61,6 +70,8 @@ int Z = 0;
int check_adresse(int adresse) {
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);
print();
print_reg();
exit(2);
}
return adresse;
@ -75,6 +86,15 @@ int check_registre(int 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
int check_eip(int eip) {
if (eip >= TAILLE_BUFFER_INSTRUCTIONS) {
@ -200,28 +220,43 @@ void execute() {
}
} else if (programme[eip].instruction == GET) {
printf("Veuillez saisir un nombre : \n");
scanf("%d", &(registres[check_registre(programme[eip].param1)]));
} else if (programme[eip].instruction == PRI) {
printf("%d@%d\n", registres[check_registre(programme[eip].param1)], programme[eip].param1);
printf("%d", registres[check_registre(programme[eip].param1)]);
} else if (programme[eip].instruction == PRIC) {
printf("%c", registres[check_registre(programme[eip].param1)]);
} else if (programme[eip].instruction == CALL) {
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;
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 + 1)] = eip + 1;
ebp = ebp + programme[eip].param2 + 2;
eip = programme[eip].param1 - 1;
}
} else if (programme[eip].instruction == RET) {
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)];
if (SECURED) {
esp--;
eip = pile[check_adresse_pile(esp)] - 1;
esp--;
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) {
if (programme[eip].param1 == 0) {
continuer = 0;
print();
print_reg();
}
}
eip = (eip + 1) % TAILLE_BUFFER_INSTRUCTIONS;

View file

@ -3,7 +3,7 @@
// Enum of the instruction
enum instruction_t {ADD, MUL, SUB, DIV, INF, SUP, EQU, CPY, AFC, LOAD, STORE, LOADI, STOREI, STOREA, JMP, JMZ, PRI, GET, CALL, RET, STOP};
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};
// Add a new instruction
void add_instruction(enum instruction_t inst, int param1, int param2, int param3);