# Term Project: Ripes
## Build
```git clone ...``` Fork ripes and clone it.
>Recommend suffix ```--recurse-submodules``` or you might need to make up submodule after cloning.
<!--
### Docker
Under docker directory
```docker build --rm --tag ripes -f ripes.dockerfile .``` Build docker.
```docker run --rm -it --net=host -e DISPLAY=$DISPLAY -v /tmp/.X11-unix:/tmp/.X11-unix ripes:latest``` Test if it works.
-->
### Cmake
<!-- Below may be outdated.
```
$ sudo apt-get install cmake
$ sudo apt-get install qttools5-dev
$ sudo apt-get install qttools5-dev-tools
$ sudo apt-get install qtmultimedia5-dev
$ sudo apt-get install libqt5svg5-dev
$ sudo apt-get install libqt5webkit5-dev
$ sudo apt-get install libqt5charts5-dev
```
-->
:::danger
CMake Error at CMakeLists.txt:55 (find_package):
By not providing "FindQt6.cmake" in CMAKE_MODULE_PATH this project has
asked CMake to find a package configuration file provided by "Qt6", but
CMake did not find one.
Could not find a package configuration file provided by "Qt6" with any of
the following names:
Qt6Config.cmake
qt6-config.cmake
Add the installation prefix of "Qt6" to CMAKE_PREFIX_PATH or set "Qt6_DIR"
to a directory containing one of the above files. If "Qt6" provides a
separate development package or SDK, be sure it has been installed.
:::
#### By not providing "FindQt6.cmake"
Install Qt6
```sudo apt install qt6-base-dev```
However, there exists another problem.
:::danger
CMake Error at CMakeLists.txt:55 (find_package):
Found package configuration file:
/usr/lib/x86_64-linux-gnu/cmake/Qt6/Qt6Config.cmake
but it set Qt6_FOUND to FALSE so package "Qt6" is considered to be NOT
FOUND. Reason given by package:
Failed to find Qt component "Svg".
Expected Config file at
"/usr/lib/x86_64-linux-gnu/cmake/Qt6Svg/Qt6SvgConfig.cmake" does NOT exist
Failed to find Qt component "Charts".
Expected Config file at
"/usr/lib/x86_64-linux-gnu/cmake/Qt6Charts/Qt6ChartsConfig.cmake" does NOT
exist
:::
#### Expected Config file at ... does NOT exist
Install **libqt6svg6-dev** instead of qt5.
```
sudo apt-get install qt6-tools-dev
sudo apt-get install qt6-tools-dev-tools
sudo apt-get install libqt6charts6-dev
```
Another problem shows up,
:::danger
statusQT_HOST_PATH =
CMake Error at external/CMakeLists.txt:11 (add_subdirectory):
The source directory
/home/tinhanho/Ripes/external/VSRTL
does not contain a CMakeLists.txt file.
CMake Error at external/CMakeLists.txt:15 (add_subdirectory):
The source directory
/home/tinhanho/Ripes/external/libelfin
does not contain a CMakeLists.txt file.
:::
Submodule is not initialize.
Conduct ```git submodule update --init --recursive```
```
statusQT_HOST_PATH =
-- Found PythonInterp: /usr/bin/python3 (found suitable version "3.10.12", minimum required is "3")
-- Configuring done
```
All problems are solved.
Under ripes directory
```
cmake -B build \
-Wno-dev \
-DRIPES_BUILD_TESTS=ON \
-DVSRTL_BUILD_TESTS=ON \
-DCMAKE_BUILD_TYPE=Release \
-DCMAKE_PREFIX_PATH=$(pwd)/6.5.0/gcc_64/
```
Go to build/test ```cd build/test && make```
Under build directory ```sudo make install```
Execute ```./Ripes``` and it works!
## The "write integers" ecall(66) will write wrong numbers when the integer is negative numbers. #313
:::info
lixintong911 commented on Oct 6
for example, when I write a=-1, the number in the file will be 2147483647.
:::
### Test Open System Call

#### Flags Meaning
See [systemio.h](https://github.com/mortbopet/Ripes/blob/bb2988e76bd0e8ed85e268fb200163b98d17562d/src/syscall/systemio.h).
```c
enum Flags : unsigned {
O_RDONLY = 0x00000000,
O_WRONLY = 0x00000001,
O_RDWR = 0x00000002,
O_ACCMODE = 0x00000003,
O_CREAT = 0x00000100,
O_EXCL = 0x00000200,
O_TRUNC = 0x00001000,
O_APPEND = 0x00002000
};
```
```c
.data
filename: .string "test.txt"
.text
## Open a file
la a0 filename
li a1 0x00000002 # O_RDWR
li a7 1024
ecall
```
Create a blank .txt file and execute the code. The register a0 shall return file descriptor.
```c
.data
filename: .string "test_non_exist.txt"
.text
## Open a file
la a0 filename
li a1 0x00000000 # O_RDONLY
li a7 1024
ecall
```
Above code shall return -1 because the .txt file does not exist.
### Test Write System Call

#### File Descriptor
See [systemio.h](https://github.com/mortbopet/Ripes/blob/bb2988e76bd0e8ed85e268fb200163b98d17562d/src/syscall/systemio.h).
```c
// Standard I/O Channels
enum STDIO {
STDIN = 0,
STDOUT = 1,
STDERR = 2,
STDIO_END
};
```
### Test Read System call

```c
.data
filename: .string "test.txt"
str: .string "hello worlds"
buffer: .string ""
.text
## Open a file
la a0 filename
li a1 0x00000002 # O_RDWR
li a7 1024
ecall
## Read
la a1 buffer
li a2 12 # reqLength
li a7 63 # Read
ecall
## print read file string
add a0 a1 x0
li a7 4
ecall
```
### Test Close System Call
```
static void close(int fd) {
// Can't close STDIN, STDOUT, STDERR, or invalid fd
if (fd < STDIO_END || fd >= SYSCALL_MAXFILES)
return;
fileFlags[fd] = O_ACCMODE; // set flag to invalid read/write mode
files[fd].close();
streams.erase(fd);
files.erase(fd);
fileNames.erase(fd);
}
```
Set fild descriptor to STDIO_END to close the file.
#### Combine All Together
```c
.data
filename: .string "test.txt"
str: .string "Hello Worlds"
buffer: .string ""
.text
## Open a file
la a0 filename
li a1 0x00000002 # O_RDWR
li a7 1024
ecall
## Write
la a1 str
li a2 12
li a7 64
ecall
## Close
li a0 3
li a7 57
ecall
## Open again
la a0 filename
li a1 0x00000002 # O_RDWR
li a7 1024
ecall
## Read
la a1 buffer
li a2 12 # reqLength
li a7 63 # Read
ecall
## print read file string
add a0 a1 x0
li a7 4
ecall
```
But there is no write integers ecall(66). So sad.
## Improve UI colors by using system-provided palette
[issue #300](https://github.com/mortbopet/Ripes/issues/300)
:::info
mortbopet commented on Sep 22
Currently, Ripes doesn't really use the system palette as made available through QApplication. A result of this is that colors throughout the application may look outdated/non-matching with respect to the system theme that the user is using on their system.
This can be improved by identifying places in Ripes where hardcoded colors are used, and replacing these in favor of using the system palette's provided colors (see the available colors in QPalette).
Also relevant for: #61
Note: this issue isn't restricted to Ripes, and mostly pertains to VSRTL, since that's where most of the drawing in Ripes is done.
More discussion on this topic: #61
:::
**Also relevant for: #61**
Check Issuse #61. The main problem is that when the system is in the dark mode, the processor UI area is hard to be read. It seems to be solve by changing it into processor dark mode.

However, there is inconsistent use of Qt's palette system. Parts of the colors are specified and other parts use the system-defaults.
We can test it in linux to understand more of the problem.


Furthermore, in dark mode the code section is a little bit hard to be read because the color seems to be hardcoded.
This can be improved by **identifying places in Ripes where hardcoded colors are used.**
### Create a new Groupbox
Under [settingsdialog.cpp](https://github.com/mortbopet/Ripes/blob/master/src/settingsdialog.cpp), add new GroupBox.
```c
auto *InstruColorGroupBox = new QGroupBox("UserDefinedColor");
auto *InstruColorLayout = new QGridLayout();
InstruColorGroupBox->setLayout(InstruColorLayout);
appendToLayout(createSettingsWidgets<QPushButton, QColorDialog>(
RIPES_SETTING_INSTRUCOLOR, "Console font color:"),
InstruColorLayout);
appendToLayout(InstruColorGroupBox, pageLayout);
```
Modify [ripessettings.cpp]() and [ripessettings.h]()
```c
{RIPES_SETTING_INSTRUCOLOR,
QVariant() /* Let Console define its own default font */},
```
```c
#define RIPES_SETTING_INSTRUCOLOR ("instru_color")
```
However, not sure how to deal with hardcoded part in editor source code. We can update the color initially but not dynamic. It seems to be a big work to redo it.
## Add Replacement Mechanism
### FIFO
Add one more condition in [cachesim.cpp](https://github.com/tinhanho/Ripes/blob/master/src/cachesim/cachesim.cpp), FIFO policy is relatively simple. What we do is adding a counter and it shall circularly evict cache slots because of the First In First Out rule.
```c
else if (m_replPolicy == ReplPolicy::FIFO){
ew.first = CacheSim::counter;
ew.second = &cacheLine[ew.first];
CacheSim::counter += 1;
CacheSim::counter %= getWays();
}
```
In [cachesim.h](https://github.com/tinhanho/Ripes/blob/master/src/cachesim/cachesim.h),
add counter in CacheSim class and append one more rule.
```c
enum ReplPolicy { Random, LRU, FIFO};
...
class CacheSim : public CacheInterface {
Q_OBJECT
public:
static constexpr unsigned s_invalidIndex = static_cast<unsigned>(-1);
int counter = 0;
...
const static std::map<ReplPolicy, QString> s_cacheReplPolicyStrings{
{ReplPolicy::Random, "Random"}, {ReplPolicy::LRU, "LRU"}, {ReplPolicy::FIFO, "FIFO"}};
```
We test it with the assembly code below,
```c
li a1 5
lw a1 0(x0)
addi a1 a1 5
lw a1 512(x0)
lw a1 0(x0)
lw a1 1024(x0)
```
LRU

FIFO

It works as our expectation.