summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPixel <>2001-04-16 20:40:13 +0000
committerPixel <>2001-04-16 20:40:13 +0000
commit85155ff54ba94f8ac40e267f83435284e88b866c (patch)
tree26e8ba119f6e5af7cbdf40cf8382becbc1affefd
parent4b6921b966481ff28c919ca0e0fb345e601a9a74 (diff)
Prout
-rw-r--r--include/Makefile.am2
-rw-r--r--include/simulator.h9
-rw-r--r--include/terminal.h12
-rw-r--r--lib/Makefile.am2
-rw-r--r--lib/memoire.c7
-rw-r--r--lib/simulator.c48
-rw-r--r--lib/terminal.c34
-rw-r--r--po/POTFILES.in1
-rw-r--r--src/simul.c11
9 files changed, 94 insertions, 32 deletions
diff --git a/include/Makefile.am b/include/Makefile.am
index da89ffc..579a87a 100644
--- a/include/Makefile.am
+++ b/include/Makefile.am
@@ -1 +1 @@
-include_HEADERS = alu.h simulator.h assembler.h exceptions.h fpu.h hash.h interne.h memoire.h meta.h numbers.h parser.h registre.h types.h linker.h
+include_HEADERS = alu.h simulator.h assembler.h exceptions.h fpu.h hash.h interne.h memoire.h meta.h numbers.h parser.h registre.h types.h linker.h terminal.h
diff --git a/include/simulator.h b/include/simulator.h
index fee37cc..ba8c7d1 100644
--- a/include/simulator.h
+++ b/include/simulator.h
@@ -15,14 +15,9 @@
extern Uint32 memoire_principale[TAILLE_MEMOIRE];
extern Uint32 registre[NB_REGISTRES_PHYSIQUES]; /* Registres classiques */
-Uint32 LireInstruction(void);
-void IncrementeCompteurOrdinal(void);
-Uint32 Adresse(Uint32 u, Uint32 instruction);
+extern int debug;
+
void Initialisation(void);
-void DecodeExec(Uint32 instruction, Uint32 entrypoint);
-void Traitement(Uint32 entrypoint);
-void AfficheReg(void);
-void Debogueur(void);
void ChargeBinaire(char * filename);
#endif \ No newline at end of file
diff --git a/include/terminal.h b/include/terminal.h
new file mode 100644
index 0000000..ed65f71
--- /dev/null
+++ b/include/terminal.h
@@ -0,0 +1,12 @@
+#ifndef __TERMINAL_H__
+#define __TERMINAL_H__
+#include <stdio.h>
+
+extern FILE * input;
+extern struct termios initial_settings, new_settings;
+
+openterm();
+clearterm();
+initterm();
+
+#endif \ No newline at end of file
diff --git a/lib/Makefile.am b/lib/Makefile.am
index 352f089..dedd82d 100644
--- a/lib/Makefile.am
+++ b/lib/Makefile.am
@@ -5,7 +5,7 @@ INCLUDES = -I. -I.. -I$(includedir) -I../include
lib_LTLIBRARIES = libCompilo.la libSimul.la libLinker.la
libCompilo_la_SOURCES = assembler.c parser.c meta.c numbers.c hash.c exceptions.c
-libSimul_la_SOURCES = alu.c simulator.c exceptions.c fpu.c interne.c memoire.c registre.c
+libSimul_la_SOURCES = alu.c simulator.c exceptions.c fpu.c interne.c memoire.c registre.c terminal.c
libLinker_la_SOURCES = linker.c exceptions.c hash.c
libCompilo_la_LDFLAGS = -version-info $(ProjetArchi_VERSION_INFO)
diff --git a/lib/memoire.c b/lib/memoire.c
index ee99983..48daf0e 100644
--- a/lib/memoire.c
+++ b/lib/memoire.c
@@ -2,6 +2,7 @@
#include "interne.h"
#include "simulator.h"
#include "exceptions.h"
+#include "terminal.h"
#ifdef HAVE_CONFIG_H
#include "config.h"
#else
@@ -10,6 +11,8 @@
char temp[BUFSIZ];
+Uint32 * memoire_principale;
+
/*****************************************/
/** **/
@@ -28,7 +31,9 @@ Uint32 LD(Uint32 offset)
case 0xffffff01:
return (fgetc(stdin));
case 0xffffff05:
- fscanf(stdin, "%i", &i);
+ clearterm();
+ fscanf(input, "%i", &i);
+ initterm();
return i;
default:
if (offset >= TAILLE_MEMOIRE) {
diff --git a/lib/simulator.c b/lib/simulator.c
index 247a8c4..d542a07 100644
--- a/lib/simulator.c
+++ b/lib/simulator.c
@@ -14,19 +14,12 @@
#include "fpu.h"
#include "exceptions.h"
#include "linker.h"
+#include "terminal.h"
-/*
- initialisation de la MP avec un malloc
- fermeture du prog et free
- catch du ctrl-c
- */
-
-
-int HasToRun = 1, HasToReset;
+int HasToRun = 1, HasToReset = 0, debug = 0;
Uint32 base_addr = 0;
-
Uint32 LireInstruction(void)
{
return (LD(LireRegistrePC()));
@@ -373,22 +366,45 @@ void AfficheReg(void) // affiche reg
for (i = 0; i <= 3; i++) {
for (j = 1; j <= 8; j++) {
- printf(" R%02d ", (i * 8 + j));
+ fprintf(stderr, " R%02d ", (i * 8 + j));
}
- printf("\n");
+ fprintf(stderr, "\n");
for (j = 1; j <= 8; j++) {
- printf("%08lX ", (registre[i * 8 + j - 1]));
+ fprintf(stderr, "%08lX ", (registre[i * 8 + j - 1]));
}
- printf("\n");
+ fprintf(stderr, "\n");
}
- printf("Rg: %08lX | Rd: %08lX | Flag: %08lX | PC: %08lX\n", LireRegistreRG(), LireRegistreRD(),
+ fprintf(stderr, "Rg: %08lX | Rd: %08lX | Flag: %08lX | PC: %08lX\n\n", LireRegistreRG(), LireRegistreRD(),
LireRegistreFLAG(), registre[REG_PC]);
- printf("\n");
}
void Debogueur(void)
{
- AfficheReg();
+ int out = 0;
+
+ while (!out) {
+ AfficheReg();
+ printf("%08lX:%08lX > ", LireRegistrePC(), LD(LireRegistrePC()));
+
+ switch (fgetc(input)) {
+ case 'G':
+ case 'g':
+ fprintf(stderr, "Go\n")
+ debug = 0;
+ out = 1;
+ break;
+ case 'p':
+ case 'P':
+ fprintf(stderr, "Proceed\n");
+ out = 1;
+ break;
+ case 'R':
+ case 'r':
+ break;
+ default:
+ fprintf(stderr, _("Help:\nG: go\nP: Proceed\nR: display registers\n\n");
+ }
+ }
}
void ChargeBinaire(char *filename)
diff --git a/lib/terminal.c b/lib/terminal.c
new file mode 100644
index 0000000..df3e61d
--- /dev/null
+++ b/lib/terminal.c
@@ -0,0 +1,34 @@
+#include <stdio.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include <termios.h>
+#include <string.h>
+#include "config.h"
+
+FILE *input;
+struct termios initial_settings, new_settings;
+
+void initterm() {
+ tcgetattr(fileno(input), &initial_settings);
+ new_settings = initial_settings;
+ new_settings.c_lflag &= ~ICANON;
+ new_settings.c_lflag &= ~ECHO;
+ new_settings.c_cc[VMIN] = 1;
+ new_settings.c_cc[VTIME] = 0;
+ new_settings.c_lflag &= ~ISIG;
+
+ if (tcsetattr(fileno(input), TCSANOW, &new_settings) != 0) {
+ exception(1, _("could not set terminal attributes"));
+ }
+
+}
+
+void clearterm() {
+ tcsetattr(fileno(input), TCSANOW, &initial_settings);
+}
+
+void openterm() {
+ if (!(input = fopen("/dev/tty", "r"))) {
+ exception(1, _("could not open terminal"));
+ }
+}
diff --git a/po/POTFILES.in b/po/POTFILES.in
index 0244510..cb56ef9 100644
--- a/po/POTFILES.in
+++ b/po/POTFILES.in
@@ -11,6 +11,7 @@ lib/memoire.c
lib/registre.c
lib/linker.c
lib/simulator.c
+lib/terminal.c
src/compilo.c
src/simul.c
src/linker.c
diff --git a/src/simul.c b/src/simul.c
index 11dd9d8..44a1e1f 100644
--- a/src/simul.c
+++ b/src/simul.c
@@ -6,15 +6,14 @@
#define _(x) x
#endif
+#include "simulator.h"
#include "alu.h"
-#include "registre.h"
-#include "memoire.h"
-#include "fpu.h"
int main(void)
{
- Debogueur();
- // Initialisation();
- // Traitement();
+ Rapide = 1;
+ Initialisation();
+ ChargerBinaire("progtest");
return (0);
}
+