Browse Source

Initial commit

Faure Paul 2 years ago
commit
fa13faf667

+ 5
- 0
.gitignore View File

@@ -0,0 +1,5 @@
1
+gradlew
2
+gradlew.bat
3
+gradle/*
4
+build/*
5
+.gradle/*

+ 3
- 0
.idea/.gitignore View File

@@ -0,0 +1,3 @@
1
+# Default ignored files
2
+/shelf/
3
+/workspace.xml

+ 6
- 0
.idea/compiler.xml View File

@@ -0,0 +1,6 @@
1
+<?xml version="1.0" encoding="UTF-8"?>
2
+<project version="4">
3
+  <component name="CompilerConfiguration">
4
+    <bytecodeTargetLevel target="11" />
5
+  </component>
6
+</project>

+ 18
- 0
.idea/gradle.xml View File

@@ -0,0 +1,18 @@
1
+<?xml version="1.0" encoding="UTF-8"?>
2
+<project version="4">
3
+  <component name="GradleMigrationSettings" migrationVersion="1" />
4
+  <component name="GradleSettings">
5
+    <option name="linkedExternalProjectsSettings">
6
+      <GradleProjectSettings>
7
+        <option name="distributionType" value="DEFAULT_WRAPPED" />
8
+        <option name="externalProjectPath" value="$PROJECT_DIR$" />
9
+        <option name="modules">
10
+          <set>
11
+            <option value="$PROJECT_DIR$" />
12
+          </set>
13
+        </option>
14
+        <option name="useQualifiedModuleNames" value="true" />
15
+      </GradleProjectSettings>
16
+    </option>
17
+  </component>
18
+</project>

+ 20
- 0
.idea/jarRepositories.xml View File

@@ -0,0 +1,20 @@
1
+<?xml version="1.0" encoding="UTF-8"?>
2
+<project version="4">
3
+  <component name="RemoteRepositoriesConfiguration">
4
+    <remote-repository>
5
+      <option name="id" value="central" />
6
+      <option name="name" value="Maven Central repository" />
7
+      <option name="url" value="https://repo1.maven.org/maven2" />
8
+    </remote-repository>
9
+    <remote-repository>
10
+      <option name="id" value="jboss.community" />
11
+      <option name="name" value="JBoss Community repository" />
12
+      <option name="url" value="https://repository.jboss.org/nexus/content/repositories/public/" />
13
+    </remote-repository>
14
+    <remote-repository>
15
+      <option name="id" value="MavenRepo" />
16
+      <option name="name" value="MavenRepo" />
17
+      <option name="url" value="https://repo.maven.apache.org/maven2/" />
18
+    </remote-repository>
19
+  </component>
20
+</project>

+ 7
- 0
.idea/misc.xml View File

@@ -0,0 +1,7 @@
1
+<?xml version="1.0" encoding="UTF-8"?>
2
+<project version="4">
3
+  <component name="ExternalStorageConfigurationManager" enabled="true" />
4
+  <component name="ProjectRootManager" version="2" languageLevel="JDK_11" default="true" project-jdk-name="11" project-jdk-type="JavaSDK">
5
+    <output url="file://$PROJECT_DIR$/out" />
6
+  </component>
7
+</project>

+ 6
- 0
.idea/vcs.xml View File

@@ -0,0 +1,6 @@
1
+<?xml version="1.0" encoding="UTF-8"?>
2
+<project version="4">
3
+  <component name="VcsDirectoryMappings">
4
+    <mapping directory="$PROJECT_DIR$" vcs="Git" />
5
+  </component>
6
+</project>

+ 235
- 0
System.vhd View File

@@ -0,0 +1,235 @@
1
+----------------------------------------------------------------------------------
2
+-- Company:  INSA-Toulouse
3
+-- Engineer: Paul Faure
4
+-- 
5
+-- Create Date: 13.04.2021 10:19:15
6
+-- Module Name: System - Behavioral
7
+-- Project Name: Processeur sécurisé
8
+-- Target Devices: Basys 3 ARTIX7
9
+-- Tool Versions: Vivado 2016.4
10
+-- Description: Environnement du processeur, mapping entre le processeur et les periphériques, affectation des ports la carte
11
+-- 
12
+-- Dependencies: 
13
+--    - Clock_Divider
14
+--    - Pipeline
15
+--    - Pipeline_NS
16
+--    - PeripheriqueEcran
17
+--    - PeripheriqueClavier
18
+----------------------------------------------------------------------------------
19
+
20
+
21
+library IEEE;
22
+use IEEE.STD_LOGIC_1164.ALL;
23
+
24
+-- Lien avec le fichier de contraintes 
25
+--   Récupération du VGA
26
+--   Récupération du PS2
27
+--   Récupération d'un bouton pour RST
28
+--   Récupération de la clock
29
+entity System is
30
+    Port ( vgaRed   : out STD_LOGIC_VECTOR (3 downto 0);
31
+           vgaBlue  : out STD_LOGIC_VECTOR (3 downto 0);
32
+           vgaGreen : out STD_LOGIC_VECTOR (3 downto 0);
33
+           Hsync    : out STD_LOGIC;
34
+           Vsync    : out STD_LOGIC;
35
+           PS2Clk : in STD_LOGIC;
36
+           PS2Data : in STD_LOGIC;
37
+           btnC : in STD_LOGIC;
38
+           CLK : in STD_LOGIC);
39
+end System;
40
+
41
+architecture Structural of System is
42
+
43
+    component Pipeline is
44
+    Generic (Nb_bits : Natural := 8;
45
+             Instruction_En_Memoire_Size : Natural := 29;
46
+             Addr_Memoire_Instruction_Size : Natural := 3;
47
+             Memoire_Instruction_Size : Natural := 8;
48
+             Instruction_Bus_Size : Natural := 5;
49
+             Nb_Instructions : Natural := 32;
50
+             Nb_Registres : Natural := 16;
51
+             Addr_registres_size : Natural := 4;
52
+             Memoire_Size : Natural := 32;
53
+             Adresse_mem_size : Natural := 5;
54
+             Memoire_Adresses_Retour_Size : Natural := 16;
55
+             Adresse_Memoire_Adresses_Retour_Size : Natural := 4);
56
+    Port (CLK : in STD_LOGIC;
57
+          RST : in STD_LOGIC;
58
+          STD_IN          : in STD_LOGIC_VECTOR (Nb_bits - 1 downto 0); 
59
+          STD_IN_Av       : in STD_LOGIC;
60
+          STD_IN_Request  : out STD_LOGIC;
61
+          STD_OUT         : out STD_LOGIC_VECTOR (Nb_bits - 1 downto 0); 
62
+          STD_OUT_Av      : out STD_LOGIC;
63
+          STD_OUT_Int     : out STD_LOGIC);
64
+    end component;
65
+
66
+    component Pipeline_NS is
67
+    Generic (Nb_bits : Natural := 8;
68
+             Instruction_En_Memoire_Size : Natural := 29;
69
+             Addr_Memoire_Instruction_Size : Natural := 3;
70
+             Memoire_Instruction_Size : Natural := 8;
71
+             Instruction_Bus_Size : Natural := 5;
72
+             Nb_Instructions : Natural := 32;
73
+             Nb_Registres : Natural := 16;
74
+             Addr_registres_size : Natural := 4;
75
+             Memoire_Size : Natural := 32;
76
+             Adresse_mem_size : Natural := 5);
77
+    Port (CLK : STD_LOGIC;
78
+          RST : STD_LOGIC;
79
+          STD_IN      : in STD_LOGIC_VECTOR (Nb_bits - 1 downto 0); 
80
+          STD_IN_Av   : in STD_LOGIC;
81
+          STD_IN_Request  : out STD_LOGIC;
82
+          STD_OUT     : out STD_LOGIC_VECTOR (Nb_bits - 1 downto 0); 
83
+          STD_OUT_Av  : out STD_LOGIC;
84
+          STD_OUT_Int : out STD_LOGIC);
85
+    end component;
86
+    
87
+    component PeripheriqueEcran 
88
+    Generic ( Nb_Bits : Natural);
89
+    Port ( CLK : in STD_LOGIC;
90
+           CLK_VGA : in STD_LOGIC;
91
+           RST : in STD_LOGIC;
92
+           
93
+           vgaRed   : out STD_LOGIC_VECTOR (3 downto 0);
94
+           vgaBlue  : out STD_LOGIC_VECTOR (3 downto 0);
95
+           vgaGreen : out STD_LOGIC_VECTOR (3 downto 0);
96
+           Hsync    : out STD_LOGIC;
97
+           Vsync    : out STD_LOGIC;
98
+                     
99
+           STD_OUT : in STD_LOGIC_VECTOR (Nb_Bits - 1 downto 0);
100
+           STD_OUT_Av : in STD_LOGIC;
101
+           STD_OUT_Int : in STD_LOGIC);
102
+    end component;
103
+    
104
+    component PeripheriqueClavier 
105
+    Generic (Nb_Bits : Natural);
106
+    Port ( CLK : in STD_LOGIC;
107
+           RST : in STD_LOGIC;
108
+           PS2Clk : in STD_LOGIC;
109
+           PS2Data : in STD_LOGIC;
110
+           STD_IN : out STD_LOGIC_VECTOR (Nb_Bits - 1 downto 0);
111
+           STD_IN_Av : out STD_LOGIC;
112
+           STD_IN_Request : in STD_LOGIC;
113
+           STD_OUT : out STD_LOGIC_VECTOR (Nb_Bits - 1 downto 0);
114
+           STD_OUT_Av : out STD_LOGIC);
115
+    end component;
116
+    
117
+    component Clock_Divider is
118
+        Port ( CLK_IN : in STD_LOGIC;
119
+               CLK_OUT : out STD_LOGIC);
120
+    end component;
121
+    
122
+    -- signaux auxiliaires
123
+    signal my_RST : STD_LOGIC; -- Signal de RST (inversion par rapport au btnC)
124
+    signal my_CLK : STD_LOGIC; -- Signal de clock (divisée par rapport CLK)
125
+    -- signaux de gestion de l'entrée
126
+    signal STD_IN      : STD_LOGIC_VECTOR (15 downto 0) := (others => '0');  -- Entrée
127
+    signal STD_IN_Av   : STD_LOGIC := '0';                                   -- Entrée disponible en lecture sur le clavier
128
+    signal STD_IN_Request  : STD_LOGIC := '0';                               -- Demande d'une entrée au clavier
129
+    -- signaux de gestion de la sortie
130
+    signal STD_OUT     : STD_LOGIC_VECTOR (15 downto 0) := (others => '0');               -- Sortie vers l'écran                                  
131
+    signal STD_OUT_Av  : STD_LOGIC := '0';                                                -- Sortie disponible pour l'écran
132
+    signal STD_OUT_Int : STD_LOGIC := '0';                                                -- Type de la sortie (entier ou ASCII) pour l'écran          
133
+    signal pipeline_STD_OUT     : STD_LOGIC_VECTOR (15 downto 0) := (others => '0');      -- Sortie depuis le Pipeline                                    
134
+    signal pipeline_STD_OUT_Av  : STD_LOGIC := '0';                                       -- Sortie disponible depuis le Pipeline
135
+    signal pipeline_STD_OUT_Int : STD_LOGIC := '0';                                       -- Type de la sortie (entier ou ASCII) depuis le pipeline          
136
+    signal clavier_STD_OUT     : STD_LOGIC_VECTOR (15 downto 0) := (others => '0');       -- Sortie depuis le Clavier                              
137
+    signal clavier_STD_OUT_Av  : STD_LOGIC := '0';                                        -- Sortie disponible depuis le Clavier                   
138
+    signal clavier_STD_OUT_Int : STD_LOGIC := '0';                                        -- Type de la sortie (entier ou ASCII) depuis le Clavier 
139
+    
140
+    constant SECURISED : boolean := false;  -- Booléen de sélection entre la version sécurisée et non sécurisée
141
+        
142
+begin    
143
+           
144
+    -- Diviseur de clock
145
+    clk_div : Clock_Divider
146
+    port map (CLK_IN => CLK,
147
+              CLK_OUT => my_CLK);
148
+              
149
+              
150
+    -- Generation du pipeline en fonction de la condition sécurisé ou non       
151
+    instance: if (SECURISED) generate
152
+        instance_securisee : entity work.Pipeline
153
+            generic map (Nb_bits => 16,
154
+                         Instruction_En_Memoire_Size => 53,
155
+                         Addr_Memoire_Instruction_Size => 9,
156
+                         Memoire_Instruction_Size => 512,
157
+                         Instruction_Bus_Size => 5,
158
+                         Nb_Instructions => 32,
159
+                         Nb_Registres => 16,
160
+                         Addr_registres_size => 4,
161
+                         Memoire_Size => 64,
162
+                         Adresse_mem_size => 6,
163
+                         Memoire_Adresses_Retour_Size => 4,
164
+                         Adresse_Memoire_Adresses_Retour_Size => 2)
165
+            port map (CLK => my_CLK,
166
+                      RST => my_RST,
167
+                      STD_IN      => STD_IN,
168
+                      STD_IN_Av   => STD_IN_Av,
169
+                      STD_IN_Request => STD_IN_Request,
170
+                      STD_OUT     => pipeline_STD_OUT,
171
+                      STD_OUT_Av  => pipeline_STD_OUT_Av,
172
+                      STD_OUT_Int => pipeline_STD_OUT_Int);
173
+    else generate
174
+        instance_non_securisee : entity work.Pipeline_NS
175
+            generic map (Nb_bits => 16,
176
+                         Instruction_En_Memoire_Size => 53,
177
+                         Addr_Memoire_Instruction_Size => 9,
178
+                         Memoire_Instruction_Size => 512,
179
+                         Instruction_Bus_Size => 5,
180
+                         Nb_Instructions => 32,
181
+                         Nb_Registres => 16,
182
+                         Addr_registres_size => 4,
183
+                         Memoire_Size => 64,
184
+                         Adresse_mem_size => 6)
185
+            port map (CLK => my_CLK,
186
+                      RST => my_RST,
187
+                      STD_IN      => STD_IN,
188
+                      STD_IN_Av   => STD_IN_Av,
189
+                      STD_IN_Request => STD_IN_Request,
190
+                      STD_OUT     => pipeline_STD_OUT,
191
+                      STD_OUT_Av  => pipeline_STD_OUT_Av,
192
+                      STD_OUT_Int => pipeline_STD_OUT_Int);
193
+    end generate;  
194
+    
195
+    instance_perif_ecran : PeripheriqueEcran 
196
+    generic map ( Nb_Bits => 16)
197
+    port map ( CLK => my_CLK,
198
+               CLK_VGA => CLK,
199
+               RST => my_RST,
200
+               
201
+               vgaRed   => vgaRed,
202
+               vgaBlue  => vgaBlue,
203
+               vgaGreen => vgaGreen,
204
+               Hsync    => Hsync,
205
+               Vsync    => Vsync,
206
+                         
207
+               STD_OUT =>     STD_OUT,
208
+               STD_OUT_Av =>  STD_OUT_Av,
209
+               STD_OUT_Int => STD_OUT_Int);
210
+               
211
+    instance_perif_clavier : PeripheriqueClavier 
212
+    generic map (Nb_Bits => 16)
213
+    port map ( CLK => my_CLK,
214
+               RST => my_RST,
215
+               PS2Clk => PS2Clk,
216
+               PS2Data => PS2Data,
217
+               STD_IN => STD_IN,
218
+               STD_IN_Av => STD_IN_Av,
219
+               STD_IN_Request => STD_IN_Request,
220
+               STD_OUT =>    clavier_STD_OUT,
221
+               STD_OUT_Av => clavier_STD_OUT_Av);
222
+          
223
+              
224
+    -- Gestion du RST (inversion d'état)
225
+    my_RST <= '1' when btnC = '0' else
226
+              '0';
227
+              
228
+    
229
+    -- Gestion de l'affichage sur l'écran lors d'une demande d'entrée le clavier affiche sur l'écran
230
+    STD_OUT <= clavier_STD_OUT when STD_IN_Request = '1' else pipeline_STD_OUT;
231
+    STD_OUT_Av <= clavier_STD_OUT_Av when STD_IN_Request = '1' else pipeline_STD_OUT_Av;
232
+    STD_OUT_Int <= clavier_STD_OUT_Int when STD_IN_Request = '1' else pipeline_STD_OUT_Int;
233
+    
234
+end Structural;
235
+

+ 14
- 0
build.gradle View File

@@ -0,0 +1,14 @@
1
+plugins {
2
+    id 'java'
3
+}
4
+
5
+group 'org.example'
6
+version '1.0-SNAPSHOT'
7
+
8
+repositories {
9
+    mavenCentral()
10
+}
11
+
12
+dependencies {
13
+    testCompile group: 'junit', name: 'junit', version: '4.12'
14
+}

+ 2
- 0
settings.gradle View File

@@ -0,0 +1,2 @@
1
+rootProject.name = 'ParserVHDL'
2
+

+ 17
- 0
src/main/java/Affectation.java View File

@@ -0,0 +1,17 @@
1
+public class Affectation {
2
+    private Signal signal1;
3
+    private Signal signal2;
4
+
5
+    public Affectation(Signal signal1, Signal signal2) {
6
+        this.signal1 = signal1;
7
+        this.signal2 = signal2;
8
+    }
9
+
10
+    public Signal getSignal1() {
11
+        return signal1;
12
+    }
13
+
14
+    public Signal getSignal2() {
15
+        return signal2;
16
+    }
17
+}

+ 16
- 0
src/main/java/Component.java View File

@@ -0,0 +1,16 @@
1
+import java.util.ArrayList;
2
+
3
+public class Component {
4
+    private Entity entity;
5
+    private ArrayList<Affectation> affectations;
6
+    private Entity entity2;
7
+    private ArrayList<Affectation> affectations2;
8
+    private Signal condition;
9
+    private boolean conditionnelle;
10
+
11
+    public Component(String entity, String affectations) {
12
+        this.entity = Entities.getEntity(entity);
13
+        // TODO Créer les affectations
14
+        this.conditionnelle = false;
15
+    }
16
+}

+ 14
- 0
src/main/java/Entities.java View File

@@ -0,0 +1,14 @@
1
+import java.util.ArrayList;
2
+
3
+public class Entities {
4
+    private static ArrayList<Entity> entities = new ArrayList<>();
5
+    private static ArrayList<String> entitiesNames = new ArrayList<>();
6
+
7
+    public static Entity getEntity(String name) {
8
+        if (! entitiesNames.contains(name)) {
9
+            entities.add(new Entity(name));
10
+            entitiesNames.add(name);
11
+        }
12
+        return entities.get(entitiesNames.indexOf(name));
13
+    }
14
+}

+ 92
- 0
src/main/java/Entity.java View File

@@ -0,0 +1,92 @@
1
+import java.io.File;
2
+import java.io.IOException;
3
+import java.util.ArrayList;
4
+import java.util.Arrays;
5
+import java.util.stream.Collectors;
6
+
7
+public class Entity {
8
+    private String name;
9
+    private ArrayList<Signal> portsIn;
10
+    private ArrayList<Signal> portsOut;
11
+    private ArrayList<Component> components;
12
+    private ArrayList<Signal> signaux;
13
+    private ArrayList<String> processes;
14
+
15
+    public Entity(String name) {
16
+        this.name = name;
17
+        this.portsIn = new ArrayList<>();
18
+        this.portsOut = new ArrayList<>();
19
+        this.components = new ArrayList<>();
20
+        this.signaux = new ArrayList<>();
21
+        this.processes = new ArrayList<>();
22
+
23
+
24
+        File f = new File(name + ".vhd");
25
+        String text = new String();
26
+        try {
27
+            text = IO.loadFile(f);
28
+        } catch (IOException e) {
29
+            System.out.println("Impossible de charger l'entité " + name);
30
+            System.exit(1);
31
+        }
32
+        // Nettoyage du texte
33
+        text = text.replaceAll("(--|library|use)[^\n]*", "");
34
+        text = text.replaceAll(" +", " ");
35
+        text = text.replaceAll(" ;", ";");
36
+        text = text.replaceAll("\n ", "\n");
37
+        text = text.replaceAll("(\t|\n)+", "\n");
38
+        text = text.replaceAll("\\( ", "(");
39
+        text = text.replaceAll("\nentity", "entity");
40
+
41
+        // Récupération de la definition de l'entité
42
+        String[] tab = text.split("end " + name + ";");
43
+        String entity = tab[0];
44
+        text = tab[1];
45
+        entity = entity.replaceFirst("entity " + name + " is\nPort \\(", "");
46
+        ArrayList<String> ports = new ArrayList<>();
47
+        ports.addAll(Arrays.asList(entity.split("\n")));
48
+        ports.forEach(port ->
49
+            { if (port.contains("in")) {
50
+                this.portsIn.add(new Signal(port.split(" ")[0]));
51
+              } else if (port.contains("out")) {
52
+                this.portsOut.add(new Signal(port.split(" ")[0]));
53
+              } else {
54
+                System.out.println("WARNING : Port illisible");
55
+              }
56
+            });
57
+
58
+        // Récupération des composants -> inutile, on travaille sur les instances
59
+        text = text.replaceFirst("[^\n]*\n", "");
60
+        text = text.replaceFirst("[^\n]*\n", "");
61
+        tab = text.split("end component;\n");
62
+        text = tab[tab.length - 1];
63
+
64
+        // Récupération des signaux
65
+
66
+        System.out.println(text);
67
+    }
68
+
69
+    public ArrayList<Signal> getPortsIn() {
70
+        return portsIn;
71
+    }
72
+
73
+    public ArrayList<Signal> getPortsOut() {
74
+        return portsOut;
75
+    }
76
+
77
+    @Override
78
+    public String toString() {
79
+        return "Entity{" +
80
+                "name='" + name + '\'' +
81
+                ", portsIn=" + portsIn +
82
+                ", portsOut=" + portsOut +
83
+                ", components=" + components +
84
+                ", signaux=" + signaux +
85
+                ", processes=" + processes +
86
+                '}';
87
+    }
88
+
89
+    public void writeScheme() {
90
+        //TODO
91
+    }
92
+}

+ 28
- 0
src/main/java/IO.java View File

@@ -0,0 +1,28 @@
1
+import java.io.*;
2
+
3
+public class IO {
4
+    public static String loadFile(File f) throws IOException {
5
+        BufferedInputStream in = new BufferedInputStream(new FileInputStream(f));
6
+        StringWriter out = new StringWriter();
7
+        int b;
8
+        while ((b=in.read()) != -1)
9
+            out.write(b);
10
+        out.flush();
11
+        out.close();
12
+        in.close();
13
+        return out.toString();
14
+    }
15
+
16
+    public static void writeFile(String string, String name) throws IOException {
17
+        File f = new File(name);
18
+        BufferedOutputStream out = new BufferedOutputStream(new FileOutputStream(f));
19
+        StringReader in = new StringReader(string);
20
+        int b;
21
+        while ((b=in.read()) != -1)
22
+            out.write(b);
23
+        out.flush();
24
+        out.close();
25
+        in.close();
26
+        f.createNewFile();
27
+    }
28
+}

+ 5
- 0
src/main/java/Main.java View File

@@ -0,0 +1,5 @@
1
+public class Main {
2
+    public static void main(String[] args) {
3
+        Entities.getEntity("System");
4
+    }
5
+}

+ 18
- 0
src/main/java/Signal.java View File

@@ -0,0 +1,18 @@
1
+public class Signal {
2
+    private String name;
3
+
4
+    public Signal(String name) {
5
+        this.name = name;
6
+    }
7
+
8
+    public String getName() {
9
+        return name;
10
+    }
11
+
12
+    @Override
13
+    public String toString() {
14
+        return "Signal{" +
15
+                "name='" + name + '\'' +
16
+                '}';
17
+    }
18
+}

Loading…
Cancel
Save