Browse code

Add source code of the assembler compiler

Pawel Jablonski authored on 14/12/2022 19:04:16
Showing 1 changed files
1 1
new file mode 100644
... ...
@@ -0,0 +1,58 @@
1
+/*
2
+ * Author: Pawel Jablonski
3
+ * E-mail: pj@xirx.net
4
+ * WWW: xirx.net
5
+ * GIT: git.xirx.net
6
+ *
7
+ * License: You can use this code however you like
8
+ * but leave information about the original author.
9
+ * Code is free for non-commercial and commercial use.
10
+ */
11
+
12
+#ifndef LINKER_H
13
+#define LINKER_H
14
+
15
+#include <QString>
16
+#include <QTextStream>
17
+#include <QVector>
18
+#include <QHash>
19
+#include <QRegularExpression>
20
+#include <QFile>
21
+#include <QIODevice>
22
+
23
+#include "codeitem.h"
24
+#include "codesection.h"
25
+#include "ramitem.h"
26
+#include "flashitem.h"
27
+#include "data.h"
28
+#include "datalist.h"
29
+
30
+//! This class glues all binary parts from the compilation part and set correct memory addresses
31
+class Linker
32
+{
33
+	public:
34
+		static const int ROM_RAM_SIZE = 3840; //!< Size of RAM reserved for the kernel
35
+		static const int ROM_FLASH_SIZE = 32768; //!< Size of Flash reserved for the kernel
36
+		static const int ROM_RAM_OFFSET = 0; //!< Start of RAM reserved for the kernel
37
+		static const int ROM_FLASH_OFFSET = 0; //!< Start of Flash reserved for the kernel
38
+
39
+		static const int APP_RAM_SIZE = 28672; //!<  Size of RAM reserved for a user application
40
+		static const int APP_FLASH_SIZE = 32768; //!< Size of Flash reserved for a user application
41
+		static const int APP_RAM_OFFSET = 4096; //!< Start of RAM reserved for a user application
42
+		static const int APP_FLASH_OFFSET = 32768; //!< Start of Flash reserved for a user application
43
+
44
+		Linker(DataList &dataList);
45
+
46
+		bool link();
47
+		bool saveFile(const QString &path, const QString &pathMap);
48
+
49
+	private:
50
+		DataList &dataList; //!< List of data for each source file
51
+		QVector<unsigned char> flashVector; //!< Buffer with a compiled, parsed and linked binary code
52
+
53
+		bool findAddress(Data &data, const QString &label, unsigned int &address);
54
+		bool findCodeAddress(Data &data, const QString &name, unsigned int &address);
55
+		bool findMemoryAddress(Data &data, const QString &name, unsigned int &address);
56
+};
57
+
58
+#endif