1
0
Fork 0
mirror of https://gitlab.com/niansa/minituxi.git synced 2025-03-06 20:49:18 +01:00

Initial commit

This commit is contained in:
niansa 2021-03-20 23:46:12 +01:00
commit a69319e942
7 changed files with 122 additions and 0 deletions

10
Makefile Normal file
View file

@ -0,0 +1,10 @@
all: genimg
compile:
utils/compile.sh
genimg: compile
utils/genimg.sh
test:
qemu-system-x86_64 -hda /dev/null -m 64 -kernel bzImage -initrd initramfs.cpio.gz -append 'quiet rdinit=/main'

0
bin/.gitkeep Normal file
View file

3
include/defs.h Normal file
View file

@ -0,0 +1,3 @@
#define PRODUCT_NAME "Minituxi"
#define PRODUCT_VERSION "0.1-dev"
#define PRODUCT_CONTACT "nilsansa@gmail.com"

66
include/system.hpp Normal file
View file

@ -0,0 +1,66 @@
#include <fstream>
#include <filesystem>
#include <termios.h>
#include <sys/sysinfo.h>
#include <sys/mount.h>
namespace get_mem {
size_t total() {
// Get sysinfo
struct sysinfo i;
sysinfo(&i);
// Get total ram
return i.totalram;
}
size_t free() {
// Get sysinfo
struct sysinfo i;
sysinfo(&i);
// Get available ram
return i.freeram;
}
size_t used() {
// Get sysinfo
struct sysinfo i;
sysinfo(&i);
// Get used ram
return i.totalram - i.freeram;
}
}
class Mounts {
public:
Mounts() {
std::filesystem::create_directory("/dev");
mount("devtmpfs", "/dev", "devtmpfs", 0, 0);
}
~Mounts() {
umount("/dev");
}
};
class Console {
termios termbak;
public:
Console(tcflag_t antiflags) {
termios thisterm;
tcgetattr(0, &thisterm);
termbak = thisterm;
thisterm.c_lflag &= ~antiflags;
tcsetattr(0, TCSANOW, &thisterm);
}
~Console() {
tcsetattr(0, TCSANOW, &termbak);
}
};

21
src/main.cpp Normal file
View file

@ -0,0 +1,21 @@
#include <iostream>
#include <string>
#include <filesystem>
#include "system.hpp"
using namespace std;
int main() {
{
// Initialisations
Mounts mounts;
// Print memory usage
cout << "Total: " << get_mem::total() / 1000000 << " MB" << endl
<< "Used: " << get_mem::used() / 1000000 << " MB" << endl
<< "Free: " << get_mem::free() / 1000000 << " MB" << endl;
}
while (1);
}

17
utils/compile.sh Executable file
View file

@ -0,0 +1,17 @@
#! /bin/sh
# Config
C="c++"
CFLAGS="-std=c++17 -static -O3 -I../include"
# Init env
cd src
# Clean up old executables
rm -f ../bin/*
# Compile executables
cd ../src
outfile="../bin/main"
"$C" $CFLAGS *.cpp -o "$outfile" || exit

5
utils/genimg.sh Executable file
View file

@ -0,0 +1,5 @@
#! /bin/sh
cd bin
ls ./* | cpio -ov -H newc -R 0 --no-absolute-filenames > ../initramfs.cpio || exit
cd ..
gzip -f initramfs.cpio