Compare commits
8 commits
Interprete
...
master
Author | SHA1 | Date | |
---|---|---|---|
|
1b805fca00 | ||
|
25efac091c | ||
|
b6f5abf852 | ||
|
a035a534e9 | ||
9b91ac0036 | |||
3efa8d5ef2 | |||
725e012507 | |||
c9c60001de |
6 changed files with 52 additions and 59 deletions
|
@ -33,6 +33,7 @@ yyerror (char const *s)
|
|||
|
||||
"GET" { return tGET; }
|
||||
"PRI" { return tPRI; }
|
||||
"PRIC" { return tPRIC; }
|
||||
|
||||
"CALL" { return tCALL; }
|
||||
"RET" { return tRET; }
|
||||
|
|
|
@ -11,7 +11,7 @@
|
|||
%token tAFC tCPY tAFCA
|
||||
%token tREAD tWR
|
||||
%token tJMP tJMF
|
||||
%token tGET tPRI
|
||||
%token tGET tPRI tPRIC
|
||||
%token tCALL tRET
|
||||
%token tSTOP
|
||||
%token<nombre> tNB
|
||||
|
@ -55,6 +55,8 @@ Instruction : tWR tNB tNB {add_instruction(WRITE, $2, $3, 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);};
|
||||
|
|
4
Makefile
4
Makefile
|
@ -9,7 +9,7 @@ default :
|
|||
clean_all : clean clean_Inputs clean_Outputs
|
||||
|
||||
clean: clean_Lex_Yacc clean_Tables
|
||||
@rm -f rondoudou_interpreter
|
||||
@rm -f interpreter
|
||||
|
||||
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
|
||||
gcc Lex_Yacc/as.tab.o Lex_Yacc/lex.yy.o Tables/tables.o -o interpreter
|
||||
|
||||
build_Tables: clean_Tables
|
||||
gcc -c Tables/tables.c -o Tables/tables.o
|
||||
|
|
45
ReadMe.md
45
ReadMe.md
|
@ -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.
|
||||
|
||||
|
||||
|
||||
|
|
@ -4,6 +4,9 @@
|
|||
|
||||
#define TAILLE_BUFFER_INSTRUCTIONS (1024)
|
||||
#define TAILLE_MEMOIRE (64)
|
||||
#define TAILLE_PILE_APPELS (16)
|
||||
|
||||
#define SECURED (1)
|
||||
|
||||
|
||||
/**************************************************/
|
||||
|
@ -32,6 +35,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;
|
||||
|
||||
|
||||
|
||||
|
||||
|
@ -57,6 +66,15 @@ int check_adresse(int 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
|
||||
int check_eip(int eip) {
|
||||
if (eip >= TAILLE_BUFFER_INSTRUCTIONS) {
|
||||
|
@ -169,22 +187,39 @@ void execute() {
|
|||
}
|
||||
|
||||
} else if (programme[eip].instruction == GET) {
|
||||
printf("Veuillez saisir un nombre : \n");
|
||||
scanf("%d", &(mem[check_adresse(ebp + programme[eip].param1)]));
|
||||
} else if (programme[eip].instruction == PRI) {
|
||||
printf("%d@%d\n", mem[check_adresse(ebp + programme[eip].param1)], ebp + programme[eip].param1);
|
||||
printf("%d", mem[check_adresse(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) {
|
||||
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) {
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
|
||||
|
||||
// Enum of the instruction
|
||||
enum instruction_t {ADD, MUL, SUB, DIV, INF, SUP, EQU, CPY, AFC, AFCA, READ, WRITE, JMP, JMF, PRI, GET, CALL, RET, STOP};
|
||||
enum instruction_t {ADD, MUL, SUB, DIV, INF, SUP, EQU, CPY, AFC, AFCA, READ, WRITE, JMP, JMF, PRI, PRIC, GET, CALL, RET, STOP};
|
||||
|
||||
// Add a new instruction
|
||||
void add_instruction(enum instruction_t inst, int param1, int param2, int param3);
|
||||
|
|
Loading…
Reference in a new issue