mirror of
https://github.com/wichtounet/thor-os.git
synced 2025-09-08 20:10:04 -04:00
Use a namespace for the tlib
This commit is contained in:
parent
e966ca9120
commit
d1f01df46c
@ -12,7 +12,7 @@
|
||||
|
||||
namespace rtc {
|
||||
|
||||
datetime all_data();
|
||||
tlib::datetime all_data();
|
||||
|
||||
} //end of rtc namespace
|
||||
|
||||
|
@ -35,7 +35,7 @@ public:
|
||||
devfs_file_system(path mount_point);
|
||||
~devfs_file_system();
|
||||
|
||||
size_t statfs(statfs_info& file);
|
||||
size_t statfs(tlib::statfs_info& file);
|
||||
size_t read(const path& file_path, char* buffer, size_t count, size_t offset, size_t& read);
|
||||
size_t write(const path& file_path, const char* buffer, size_t count, size_t offset, size_t& written);
|
||||
size_t clear(const path& file_path, size_t count, size_t offset, size_t& written);
|
||||
|
@ -36,7 +36,7 @@ public:
|
||||
|
||||
void init();
|
||||
|
||||
size_t statfs(statfs_info& file);
|
||||
size_t statfs(tlib::statfs_info& file);
|
||||
size_t read(const path& file_path, char* buffer, size_t count, size_t offset, size_t& read);
|
||||
size_t write(const path& file_path, const char* buffer, size_t count, size_t offset, size_t& written);
|
||||
size_t clear(const path& file_path, size_t count, size_t offset, size_t& written);
|
||||
|
@ -26,7 +26,7 @@ public:
|
||||
procfs_file_system(path mount_point);
|
||||
~procfs_file_system();
|
||||
|
||||
size_t statfs(statfs_info& file);
|
||||
size_t statfs(tlib::statfs_info& file);
|
||||
size_t read(const path& file_path, char* buffer, size_t count, size_t offset, size_t& read);
|
||||
size_t write(const path& file_path, const char* buffer, size_t count, size_t offset, size_t& written);
|
||||
size_t clear(const path& file_path, size_t count, size_t offset, size_t& written);
|
||||
|
@ -24,7 +24,7 @@ public:
|
||||
sysfs_file_system(path mount_point);
|
||||
~sysfs_file_system();
|
||||
|
||||
size_t statfs(statfs_info& file);
|
||||
size_t statfs(tlib::statfs_info& file);
|
||||
size_t read(const path& file_path, char* buffer, size_t count, size_t offset, size_t& read);
|
||||
size_t write(const path& file_path, const char* buffer, size_t count, size_t offset, size_t& written);
|
||||
size_t clear(const path& file_path, size_t count, size_t offset, size_t& written);
|
||||
|
@ -21,9 +21,9 @@ struct file {
|
||||
bool hidden;
|
||||
bool system;
|
||||
uint64_t size;
|
||||
datetime created;
|
||||
datetime modified;
|
||||
datetime accessed;
|
||||
tlib::datetime created;
|
||||
tlib::datetime modified;
|
||||
tlib::datetime accessed;
|
||||
|
||||
//File system specific
|
||||
size_t location;
|
||||
|
@ -23,7 +23,7 @@ struct file_system {
|
||||
|
||||
virtual void init(){}
|
||||
|
||||
virtual size_t statfs(statfs_info& file) = 0;
|
||||
virtual size_t statfs(tlib::statfs_info& file) = 0;
|
||||
virtual size_t read(const path& file_path, char* buffer, size_t count, size_t offset, size_t& read) = 0;
|
||||
virtual size_t write(const path& file_path, const char* buffer, size_t count, size_t offset, size_t& written) = 0;
|
||||
virtual size_t clear(const path& file_path, size_t count, size_t offset, size_t& written) = 0;
|
||||
|
@ -50,7 +50,7 @@ void close(size_t fd);
|
||||
* \param info The info to fill
|
||||
* \return a status code
|
||||
*/
|
||||
int64_t stat(size_t fd, stat_info& info);
|
||||
int64_t stat(size_t fd, tlib::stat_info& info);
|
||||
|
||||
/*!
|
||||
* \brief Returns information about the file system
|
||||
@ -58,7 +58,7 @@ int64_t stat(size_t fd, stat_info& info);
|
||||
* \param info The info to fill
|
||||
* \return a status code
|
||||
*/
|
||||
int64_t statfs(const char* mount_point, statfs_info& info);
|
||||
int64_t statfs(const char* mount_point, tlib::statfs_info& info);
|
||||
|
||||
/*!
|
||||
* \brief Create a new directory
|
||||
|
@ -29,7 +29,7 @@ uint8_t get_RTC_register(int reg){
|
||||
|
||||
} //end of anonymous namespace
|
||||
|
||||
datetime rtc::all_data(){
|
||||
tlib::datetime rtc::all_data(){
|
||||
uint8_t second;
|
||||
uint8_t minute;
|
||||
uint8_t hour;
|
||||
|
@ -194,7 +194,7 @@ size_t devfs::devfs_file_system::rm(const path& ){
|
||||
return std::ERROR_PERMISSION_DENIED;
|
||||
}
|
||||
|
||||
size_t devfs::devfs_file_system::statfs(statfs_info& file){
|
||||
size_t devfs::devfs_file_system::statfs(tlib::statfs_info& file){
|
||||
file.total_size = 0;
|
||||
file.free_size = 0;
|
||||
|
||||
|
@ -703,7 +703,7 @@ size_t fat32::fat32_file_system::rm(const path& file_path){
|
||||
}
|
||||
}
|
||||
|
||||
size_t fat32::fat32_file_system::statfs(statfs_info& file){
|
||||
size_t fat32::fat32_file_system::statfs(tlib::statfs_info& file){
|
||||
file.total_size = fat_bs->total_sectors_long * 512;
|
||||
file.free_size = fat_is->free_clusters * fat_bs->sectors_per_cluster * 512;
|
||||
|
||||
|
@ -193,7 +193,7 @@ size_t procfs::procfs_file_system::ls(const path& file_path, std::vector<vfs::fi
|
||||
return std::ERROR_NOT_EXISTS;
|
||||
}
|
||||
|
||||
size_t procfs::procfs_file_system::statfs(statfs_info& file){
|
||||
size_t procfs::procfs_file_system::statfs(tlib::statfs_info& file){
|
||||
file.total_size = 0;
|
||||
file.free_size = 0;
|
||||
|
||||
|
@ -320,7 +320,7 @@ size_t sysfs::sysfs_file_system::rm(const path& ){
|
||||
return std::ERROR_PERMISSION_DENIED;
|
||||
}
|
||||
|
||||
size_t sysfs::sysfs_file_system::statfs(statfs_info& file){
|
||||
size_t sysfs::sysfs_file_system::statfs(tlib::statfs_info& file){
|
||||
file.total_size = 0;
|
||||
file.free_size = 0;
|
||||
|
||||
|
@ -44,7 +44,7 @@ void append_to_file(const char* s, size_t length){
|
||||
auto fd = vfs::open("/messages", std::OPEN_CREATE);
|
||||
|
||||
if(fd >= 0){
|
||||
stat_info info;
|
||||
tlib::stat_info info;
|
||||
if(vfs::stat(fd, info) == 0){
|
||||
if(vfs::truncate(fd, info.size + length + 1) == 0){
|
||||
std::string buffer = s;
|
||||
|
@ -170,14 +170,14 @@ void sc_close(interrupt::syscall_regs* regs){
|
||||
|
||||
void sc_stat(interrupt::syscall_regs* regs){
|
||||
auto fd = regs->rbx;
|
||||
auto info = reinterpret_cast<stat_info*>(regs->rcx);
|
||||
auto info = reinterpret_cast<tlib::stat_info*>(regs->rcx);
|
||||
|
||||
regs->rax = vfs::stat(fd, *info);
|
||||
}
|
||||
|
||||
void sc_statfs(interrupt::syscall_regs* regs){
|
||||
auto mount_point = reinterpret_cast<char*>(regs->rbx);
|
||||
auto info = reinterpret_cast<statfs_info*>(regs->rcx);
|
||||
auto info = reinterpret_cast<tlib::statfs_info*>(regs->rcx);
|
||||
|
||||
regs->rax = vfs::statfs(mount_point, *info);
|
||||
}
|
||||
@ -269,7 +269,7 @@ void sc_rm(interrupt::syscall_regs* regs){
|
||||
}
|
||||
|
||||
void sc_datetime(interrupt::syscall_regs* regs){
|
||||
auto date = reinterpret_cast<datetime*>(regs->rbx);
|
||||
auto date = reinterpret_cast<tlib::datetime*>(regs->rbx);
|
||||
|
||||
*date = rtc::all_data();
|
||||
}
|
||||
|
@ -216,7 +216,7 @@ int64_t vfs::mount(partition_type type, const char* mount_point, const char* dev
|
||||
return 0;
|
||||
}
|
||||
|
||||
int64_t vfs::statfs(const char* mount_point, statfs_info& info){
|
||||
int64_t vfs::statfs(const char* mount_point, tlib::statfs_info& info){
|
||||
auto base_path = get_path(mount_point);
|
||||
|
||||
if(!base_path.is_valid()){
|
||||
@ -307,7 +307,7 @@ int64_t vfs::rm(const char* file_path){
|
||||
return fs.file_system->rm(fs_path);
|
||||
}
|
||||
|
||||
int64_t vfs::stat(size_t fd, stat_info& info){
|
||||
int64_t vfs::stat(size_t fd, tlib::stat_info& info){
|
||||
if(!scheduler::has_handle(fd)){
|
||||
return -std::ERROR_INVALID_FILE_DESCRIPTOR;
|
||||
}
|
||||
@ -320,7 +320,7 @@ int64_t vfs::stat(size_t fd, stat_info& info){
|
||||
if(fs_path.is_root()){
|
||||
//TODO Add file system support for stat of the root directory
|
||||
info.size = 4096;
|
||||
info.flags = STAT_FLAG_DIRECTORY;
|
||||
info.flags = tlib::STAT_FLAG_DIRECTORY;
|
||||
|
||||
return 0;
|
||||
}
|
||||
@ -336,20 +336,20 @@ int64_t vfs::stat(size_t fd, stat_info& info){
|
||||
info.flags = 0;
|
||||
|
||||
if(f.directory){
|
||||
info.flags |= STAT_FLAG_DIRECTORY;
|
||||
info.flags |= tlib::STAT_FLAG_DIRECTORY;
|
||||
}
|
||||
|
||||
if(f.system){
|
||||
info.flags |= STAT_FLAG_SYSTEM;
|
||||
info.flags |= tlib::STAT_FLAG_SYSTEM;
|
||||
}
|
||||
|
||||
if(f.hidden){
|
||||
info.flags |= STAT_FLAG_HIDDEN;
|
||||
info.flags |= tlib::STAT_FLAG_HIDDEN;
|
||||
}
|
||||
|
||||
// All files starting with a .dot are hidden by default
|
||||
if(fs_path.base_name()[0] == '.'){
|
||||
info.flags |= STAT_FLAG_HIDDEN;
|
||||
info.flags |= tlib::STAT_FLAG_HIDDEN;
|
||||
}
|
||||
|
||||
info.created = f.created;
|
||||
@ -522,7 +522,7 @@ int64_t vfs::entries(size_t fd, char* buffer, size_t size){
|
||||
size_t total_size = 0;
|
||||
|
||||
for(auto& f : files){
|
||||
total_size += sizeof(directory_entry) + f.file_name.size();
|
||||
total_size += sizeof(tlib::directory_entry) + f.file_name.size();
|
||||
}
|
||||
|
||||
if(size < total_size){
|
||||
@ -534,7 +534,7 @@ int64_t vfs::entries(size_t fd, char* buffer, size_t size){
|
||||
for(size_t i = 0; i < files.size(); ++i){
|
||||
auto& file = files[i];
|
||||
|
||||
auto entry = reinterpret_cast<directory_entry*>(buffer + position);
|
||||
auto entry = reinterpret_cast<tlib::directory_entry*>(buffer + position);
|
||||
|
||||
entry->type = 0; //TODO Fill that
|
||||
entry->length = file.file_name.size();
|
||||
@ -572,7 +572,7 @@ int64_t vfs::mounts(char* buffer, size_t size){
|
||||
for(size_t i = 0; i < mount_point_list.size(); ++i){
|
||||
auto& mp = mount_point_list[i];
|
||||
|
||||
auto entry = reinterpret_cast<mount_point*>(buffer + position);
|
||||
auto entry = reinterpret_cast<tlib::mount_point*>(buffer + position);
|
||||
|
||||
auto fs_type = partition_type_to_string(mp.fs_type);
|
||||
|
||||
|
@ -8,7 +8,7 @@
|
||||
#include <tlib/system.hpp>
|
||||
|
||||
int main(int, char*[]){
|
||||
alpha();
|
||||
tlib::alpha();
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
@ -9,7 +9,7 @@
|
||||
|
||||
int main(int argc, char* argv[]){
|
||||
for(size_t i = 0; i < size_t(argc); ++i){
|
||||
print_line(argv[i]);
|
||||
tlib::print_line(argv[i]);
|
||||
}
|
||||
|
||||
return 0;
|
||||
|
@ -17,18 +17,18 @@ size_t repeat = 1;
|
||||
bool display_result(const char* name, uint64_t duration){
|
||||
if(!duration){
|
||||
repeat *= 2;
|
||||
printf("%s was too fast (duration=0) increasing repeat to %u\n", name, repeat);
|
||||
tlib::printf("%s was too fast (duration=0) increasing repeat to %u\n", name, repeat);
|
||||
return false;
|
||||
}
|
||||
|
||||
uint64_t throughput = 1000 * ((repeat * PAGES * 4096) / duration);
|
||||
|
||||
if(throughput > (1024 * 1024)){
|
||||
printf("%s: %ums bandwith: %uMiB/s\n", name, duration, throughput / (1024 * 1024));
|
||||
tlib::printf("%s: %ums bandwith: %uMiB/s\n", name, duration, throughput / (1024 * 1024));
|
||||
} else if(throughput > 1024){
|
||||
printf("%s: %ums bandwith: %uKiB/s\n", name, duration, throughput / 1024);
|
||||
tlib::printf("%s: %ums bandwith: %uKiB/s\n", name, duration, throughput / 1024);
|
||||
} else {
|
||||
printf("%s: %ums bandwith: %uB/s\n", name, duration, throughput);
|
||||
tlib::printf("%s: %ums bandwith: %uB/s\n", name, duration, throughput);
|
||||
}
|
||||
|
||||
return true;
|
||||
@ -40,18 +40,18 @@ int main(){
|
||||
char* buffer_one = new char[PAGES * 4096];
|
||||
char* buffer_two = new char[PAGES * 4096];
|
||||
|
||||
printf("Start benchmark...\n");
|
||||
tlib::printf("Start benchmark...\n");
|
||||
|
||||
uint64_t start = 0, end = 0;
|
||||
|
||||
while(repeat < 100){
|
||||
start = ms_time();
|
||||
start = tlib::ms_time();
|
||||
|
||||
for(size_t i = 0; i < repeat; ++i){
|
||||
std::copy_n(buffer_two, PAGES * 4096, buffer_one);
|
||||
}
|
||||
|
||||
end = ms_time();
|
||||
end = tlib::ms_time();
|
||||
|
||||
if(display_result("copy", end - start)){
|
||||
break;
|
||||
@ -61,13 +61,13 @@ int main(){
|
||||
repeat = 1;
|
||||
|
||||
while(repeat < 100){
|
||||
start = ms_time();
|
||||
start = tlib::ms_time();
|
||||
|
||||
for(size_t i = 0; i < repeat; ++i){
|
||||
std::fill_n(buffer_two, PAGES * 4096, 'Z');
|
||||
}
|
||||
|
||||
end = ms_time();
|
||||
end = tlib::ms_time();
|
||||
|
||||
if(display_result("fill", end - start)){
|
||||
break;
|
||||
@ -77,13 +77,13 @@ int main(){
|
||||
repeat = 1;
|
||||
|
||||
while(repeat < 100){
|
||||
start = ms_time();
|
||||
start = tlib::ms_time();
|
||||
|
||||
for(size_t i = 0; i < repeat; ++i){
|
||||
std::fill_n(buffer_two, PAGES * 4096, 0);
|
||||
}
|
||||
|
||||
end = ms_time();
|
||||
end = tlib::ms_time();
|
||||
|
||||
if(display_result("clear", end - start)){
|
||||
break;
|
||||
|
@ -12,46 +12,46 @@
|
||||
|
||||
int main(int argc, char* argv[]){
|
||||
if(argc == 1){
|
||||
print_line("Usage: cat file_path");
|
||||
tlib::print_line("Usage: cat file_path");
|
||||
return 1;
|
||||
}
|
||||
|
||||
auto fd = open(argv[1]);
|
||||
auto fd = tlib::open(argv[1]);
|
||||
|
||||
if(fd.valid()){
|
||||
auto info = stat(*fd);
|
||||
auto info = tlib::stat(*fd);
|
||||
|
||||
if(info.valid()){
|
||||
if(info->flags & STAT_FLAG_DIRECTORY){
|
||||
print_line("cat: error: Is a directory");
|
||||
if(info->flags & tlib::STAT_FLAG_DIRECTORY){
|
||||
tlib::print_line("cat: error: Is a directory");
|
||||
} else {
|
||||
auto size = info->size;
|
||||
|
||||
auto buffer = new char[size];
|
||||
|
||||
auto content_result = read(*fd, buffer, size);
|
||||
auto content_result = tlib::read(*fd, buffer, size);
|
||||
|
||||
if(content_result.valid()){
|
||||
if(*content_result != size){
|
||||
//TODO Read more
|
||||
} else {
|
||||
for(size_t i = 0; i < size; ++i){
|
||||
print(buffer[i]);
|
||||
tlib::print(buffer[i]);
|
||||
}
|
||||
|
||||
print_line();
|
||||
tlib::print_line();
|
||||
}
|
||||
} else {
|
||||
printf("cat: error: %s\n", std::error_message(content_result.error()));
|
||||
tlib::printf("cat: error: %s\n", std::error_message(content_result.error()));
|
||||
}
|
||||
}
|
||||
} else {
|
||||
printf("cat: error: %s\n", std::error_message(info.error()));
|
||||
tlib::printf("cat: error: %s\n", std::error_message(info.error()));
|
||||
}
|
||||
|
||||
close(*fd);
|
||||
tlib::close(*fd);
|
||||
} else {
|
||||
printf("cat: error: %s\n", std::error_message(fd.error()));
|
||||
tlib::printf("cat: error: %s\n", std::error_message(fd.error()));
|
||||
}
|
||||
|
||||
return 0;
|
||||
|
@ -29,12 +29,12 @@ void get_base_info(){
|
||||
|
||||
native_cpuid(1, eax, ebx, ecx, edx);
|
||||
|
||||
printf("Stepping: %u\n", eax & 0xF);
|
||||
printf("Model: %u\n", (eax >> 4) & 0xF);
|
||||
printf("Family: %u\n", (eax >> 8) & 0xF);
|
||||
printf("Processor Type: %u\n", (eax >> 12) & 0x3);
|
||||
printf("Extended Model: %u\n", (eax >> 16) & 0xF);
|
||||
printf("Extended Family: %u\n", (eax >> 20) & 0xFF);
|
||||
tlib::printf("Stepping: %u\n", eax & 0xF);
|
||||
tlib::printf("Model: %u\n", (eax >> 4) & 0xF);
|
||||
tlib::printf("Family: %u\n", (eax >> 8) & 0xF);
|
||||
tlib::printf("Processor Type: %u\n", (eax >> 12) & 0x3);
|
||||
tlib::printf("Extended Model: %u\n", (eax >> 16) & 0xF);
|
||||
tlib::printf("Extended Family: %u\n", (eax >> 20) & 0xFF);
|
||||
}
|
||||
|
||||
void get_vendor_id(){
|
||||
@ -46,7 +46,7 @@ void get_vendor_id(){
|
||||
vendor_id[1] = edx;
|
||||
vendor_id[2] = ecx;
|
||||
|
||||
printf("Vendor ID: %s\n", reinterpret_cast<const char*>(vendor_id));
|
||||
tlib::printf("Vendor ID: %s\n", reinterpret_cast<const char*>(vendor_id));
|
||||
}
|
||||
|
||||
void get_brand_string(){
|
||||
@ -72,7 +72,7 @@ void get_brand_string(){
|
||||
brand_string[10] = ecx;
|
||||
brand_string[11] = edx;
|
||||
|
||||
printf("Brand String: %s\n", reinterpret_cast<const char*>(brand_string));
|
||||
tlib::printf("Brand String: %s\n", reinterpret_cast<const char*>(brand_string));
|
||||
}
|
||||
|
||||
// EDX Features
|
||||
@ -91,8 +91,8 @@ const int AVX = 1 << 28;
|
||||
|
||||
void test_feature(uint32_t reg, int mask, const char* s){
|
||||
if(reg & mask){
|
||||
print(' ');
|
||||
print(s);
|
||||
tlib::print(' ');
|
||||
tlib::print(s);
|
||||
}
|
||||
}
|
||||
|
||||
@ -101,7 +101,7 @@ void get_features(){
|
||||
|
||||
native_cpuid(1, eax, ebx, ecx, edx);
|
||||
|
||||
print("Features:");
|
||||
tlib::print("Features:");
|
||||
|
||||
test_feature(edx, FPU, "fpu");
|
||||
test_feature(edx, MMX, "mmx");
|
||||
@ -115,7 +115,7 @@ void get_features(){
|
||||
test_feature(ecx, AES, "aes");
|
||||
test_feature(ecx, AVX, "avx");
|
||||
|
||||
print_line();
|
||||
tlib::print_line();
|
||||
}
|
||||
|
||||
void decode_bytes (int data, int descriptor[16], int *next){
|
||||
@ -138,12 +138,12 @@ void get_cache_info() {
|
||||
|
||||
uint32_t eax = 0, ebx = 0, ecx = 0, edx = 0;
|
||||
|
||||
print_line("Cache and TLB:");
|
||||
tlib::print_line("Cache and TLB:");
|
||||
|
||||
native_cpuid(0, eax, ebx, ecx, edx);
|
||||
|
||||
if (eax < 2){
|
||||
print_line(" CPUID(2) not supported");
|
||||
tlib::print_line(" CPUID(2) not supported");
|
||||
return;
|
||||
}
|
||||
|
||||
@ -174,179 +174,179 @@ void get_cache_info() {
|
||||
}
|
||||
|
||||
if ( descriptor[i] == 0x01){
|
||||
print_line(" Instruction TLB ... 4 kb pages, 4-way associative, 32 entries");
|
||||
tlib::print_line(" Instruction TLB ... 4 kb pages, 4-way associative, 32 entries");
|
||||
}
|
||||
if ( descriptor[i] == 0x02){
|
||||
print_line(" Instruction TLB ... 4 Mb pages, 4-way associative, 2 entries");
|
||||
tlib::print_line(" Instruction TLB ... 4 Mb pages, 4-way associative, 2 entries");
|
||||
}
|
||||
if ( descriptor[i] == 0x03){
|
||||
print_line(" Data TLB .......... 4 kb pages, 4-way associative, 64 entries");
|
||||
tlib::print_line(" Data TLB .......... 4 kb pages, 4-way associative, 64 entries");
|
||||
}
|
||||
if ( descriptor[i] == 0x04){
|
||||
print_line(" Data TLB .......... 4 Mb pages, 4-way associative, 8 entries");
|
||||
tlib::print_line(" Data TLB .......... 4 Mb pages, 4-way associative, 8 entries");
|
||||
}
|
||||
if ( descriptor[i] == 0x06){
|
||||
print_line(" L1 instruction cache 8 kb, 4-way associative, 32 byte line size");
|
||||
tlib::print_line(" L1 instruction cache 8 kb, 4-way associative, 32 byte line size");
|
||||
}
|
||||
if ( descriptor[i] == 0x08){
|
||||
print_line(" L1 instruction cache 16 kb, 4-way associative, 32 byte line size");
|
||||
tlib::print_line(" L1 instruction cache 16 kb, 4-way associative, 32 byte line size");
|
||||
}
|
||||
if ( descriptor[i] == 0x0A){
|
||||
print_line(" L1 data cache ..... 8 kb, 2-way associative, 32 byte line size");
|
||||
tlib::print_line(" L1 data cache ..... 8 kb, 2-way associative, 32 byte line size");
|
||||
}
|
||||
if ( descriptor[i] == 0x0B){
|
||||
print_line(" Instruction TLB ... 4 Mb pages, 4-way associative, 4 entries");
|
||||
tlib::print_line(" Instruction TLB ... 4 Mb pages, 4-way associative, 4 entries");
|
||||
}
|
||||
if ( descriptor[i] == 0x0C){
|
||||
print_line(" L1 data cache ..... 16 kb, 4-way associative, 32 byte line size");
|
||||
tlib::print_line(" L1 data cache ..... 16 kb, 4-way associative, 32 byte line size");
|
||||
}
|
||||
if ( descriptor[i] == 0x22){
|
||||
print_line(" L3 cache: 512K Bytes, 4-way associative, 64 byte line size, ");
|
||||
print_line(" 128 byte sector size" );
|
||||
tlib::print_line(" L3 cache: 512K Bytes, 4-way associative, 64 byte line size, ");
|
||||
tlib::print_line(" 128 byte sector size" );
|
||||
}
|
||||
if ( descriptor[i] == 0x23){
|
||||
print_line(" L3 cache: 1M Bytes, 8-way associative, 64 byte line size, ");
|
||||
print_line(" 128 byte sector size" );
|
||||
tlib::print_line(" L3 cache: 1M Bytes, 8-way associative, 64 byte line size, ");
|
||||
tlib::print_line(" 128 byte sector size" );
|
||||
}
|
||||
if ( descriptor[i] == 0x25){
|
||||
print_line(" L3 cache: 2M Bytes, 8-way associative, 64 byte line size, ");
|
||||
print_line(" 128 byte sector size" );
|
||||
tlib::print_line(" L3 cache: 2M Bytes, 8-way associative, 64 byte line size, ");
|
||||
tlib::print_line(" 128 byte sector size" );
|
||||
}
|
||||
if ( descriptor[i] == 0x29){
|
||||
print_line(" L3 cache: 4M Bytes, 8-way associative, 64 byte line size, ");
|
||||
print_line(" 128 byte sector size" );
|
||||
tlib::print_line(" L3 cache: 4M Bytes, 8-way associative, 64 byte line size, ");
|
||||
tlib::print_line(" 128 byte sector size" );
|
||||
}
|
||||
if ( descriptor[i] == 0x2C){
|
||||
print_line(" 1st-level D-cache: 32K Bytes, 8-way associative, 64 byte line size");
|
||||
tlib::print_line(" 1st-level D-cache: 32K Bytes, 8-way associative, 64 byte line size");
|
||||
}
|
||||
if ( descriptor[i] == 0x30){
|
||||
print_line(" 1st-level I-cache: 32K Bytes, 8-way associative, 64 byte line size");
|
||||
tlib::print_line(" 1st-level I-cache: 32K Bytes, 8-way associative, 64 byte line size");
|
||||
}
|
||||
if ( descriptor[i] == 0x40){
|
||||
print_line(" No L2 cache OR if there is an L2 cache, then no L3 cache");
|
||||
tlib::print_line(" No L2 cache OR if there is an L2 cache, then no L3 cache");
|
||||
}
|
||||
if ( descriptor[i] == 0x41){
|
||||
print_line(" L2 cache .......... 128 kb, 4-way associative, 32 byte line size");
|
||||
tlib::print_line(" L2 cache .......... 128 kb, 4-way associative, 32 byte line size");
|
||||
}
|
||||
if ( descriptor[i] == 0x42){
|
||||
print_line(" L2 cache .......... 256 kb, 4-way associative, 32 byte line size");
|
||||
tlib::print_line(" L2 cache .......... 256 kb, 4-way associative, 32 byte line size");
|
||||
}
|
||||
if ( descriptor[i] == 0x43){
|
||||
print_line(" L2 cache .......... 512 kb, 4-way associative, 32 byte line size");
|
||||
tlib::print_line(" L2 cache .......... 512 kb, 4-way associative, 32 byte line size");
|
||||
}
|
||||
if ( descriptor[i] == 0x44){
|
||||
print_line(" L2 cache .......... 1 Mb, 4-way associative, 32 byte line size");
|
||||
tlib::print_line(" L2 cache .......... 1 Mb, 4-way associative, 32 byte line size");
|
||||
}
|
||||
if ( descriptor[i] == 0x45){
|
||||
print_line(" L2 cache .......... 2 Mb, 4-way associative, 32 byte line size");
|
||||
tlib::print_line(" L2 cache .......... 2 Mb, 4-way associative, 32 byte line size");
|
||||
}
|
||||
if ( descriptor[i] == 0x46){
|
||||
print_line(" L3 cache .......... 4 Mb, 4-way associative, 64 byte line size");
|
||||
tlib::print_line(" L3 cache .......... 4 Mb, 4-way associative, 64 byte line size");
|
||||
}
|
||||
if ( descriptor[i] == 0x47){
|
||||
print_line(" L3 cache .......... 8 Mb, 8-way associative, 64 byte line size");
|
||||
tlib::print_line(" L3 cache .......... 8 Mb, 8-way associative, 64 byte line size");
|
||||
}
|
||||
if ( descriptor[i] == 0x49){
|
||||
print_line(" L2 cache .......... 4 Mb, 16-way associative, 64 byte line size");
|
||||
tlib::print_line(" L2 cache .......... 4 Mb, 16-way associative, 64 byte line size");
|
||||
}
|
||||
if ( descriptor[i] == 0x50){
|
||||
print_line(" Instruction TLB ... 4 kb and 2 Mb or 4 Mb pages, 64 entries");
|
||||
tlib::print_line(" Instruction TLB ... 4 kb and 2 Mb or 4 Mb pages, 64 entries");
|
||||
}
|
||||
if ( descriptor[i] == 0x51){
|
||||
print_line(" Instruction TLB ... 4 kb and 2 Mb or 4 Mb pages, 128 entries");
|
||||
tlib::print_line(" Instruction TLB ... 4 kb and 2 Mb or 4 Mb pages, 128 entries");
|
||||
}
|
||||
if ( descriptor[i] == 0x52){
|
||||
print_line(" Instruction TLB ... 4 kb and 2 Mb or 4 Mb pages, 256 entries");
|
||||
tlib::print_line(" Instruction TLB ... 4 kb and 2 Mb or 4 Mb pages, 256 entries");
|
||||
}
|
||||
if ( descriptor[i] == 0x56){
|
||||
print_line(" Data TLB .......... 4 Mb pages, 4-way associative, 16 entries");
|
||||
tlib::print_line(" Data TLB .......... 4 Mb pages, 4-way associative, 16 entries");
|
||||
}
|
||||
if ( descriptor[i] == 0x57){
|
||||
print_line(" Data TLB .......... 4 Kb pages, 4-way associative, 16 entries");
|
||||
tlib::print_line(" Data TLB .......... 4 Kb pages, 4-way associative, 16 entries");
|
||||
}
|
||||
if ( descriptor[i] == 0x5B){
|
||||
print_line(" Data TLB .......... 4 kb and 4 Mb pages, 64 entries");
|
||||
tlib::print_line(" Data TLB .......... 4 kb and 4 Mb pages, 64 entries");
|
||||
}
|
||||
if ( descriptor[i] == 0x5C){
|
||||
print_line(" Data TLB .......... 4 kb and 4 Mb pages, 128 entries");
|
||||
tlib::print_line(" Data TLB .......... 4 kb and 4 Mb pages, 128 entries");
|
||||
}
|
||||
if ( descriptor[i] == 0x5D){
|
||||
print_line(" Data TLB .......... 4 kb and 4 Mb pages, 256 entries");
|
||||
tlib::print_line(" Data TLB .......... 4 kb and 4 Mb pages, 256 entries");
|
||||
}
|
||||
if ( descriptor[i] == 0x60){
|
||||
print_line(" L1 data cache ..... 16 kb, 8-way associative, 64 byte line size");
|
||||
tlib::print_line(" L1 data cache ..... 16 kb, 8-way associative, 64 byte line size");
|
||||
}
|
||||
if ( descriptor[i] == 0x66){
|
||||
print_line(" L1 data cache ..... 8 kb, 4-way associative, 64 byte line size");
|
||||
tlib::print_line(" L1 data cache ..... 8 kb, 4-way associative, 64 byte line size");
|
||||
}
|
||||
if ( descriptor[i] == 0x67){
|
||||
print_line(" L1 data cache ..... 16 kb, 4-way associative, 64 byte line size");
|
||||
tlib::print_line(" L1 data cache ..... 16 kb, 4-way associative, 64 byte line size");
|
||||
}
|
||||
if ( descriptor[i] == 0x68){
|
||||
print_line(" L1 data cache ..... 32 kb, 4-way associative, 64 byte line size");
|
||||
tlib::print_line(" L1 data cache ..... 32 kb, 4-way associative, 64 byte line size");
|
||||
}
|
||||
if ( descriptor[i] == 0x70){
|
||||
print_line(" Trace cache ...... 12k uop, 8-way associative");
|
||||
tlib::print_line(" Trace cache ...... 12k uop, 8-way associative");
|
||||
}
|
||||
if ( descriptor[i] == 0x71){
|
||||
print_line(" Trace cache ...... 16k uop, 8-way associative");
|
||||
tlib::print_line(" Trace cache ...... 16k uop, 8-way associative");
|
||||
}
|
||||
if ( descriptor[i] == 0x72){
|
||||
print_line(" Trace cache ...... 32k uop, 8-way associative");
|
||||
tlib::print_line(" Trace cache ...... 32k uop, 8-way associative");
|
||||
}
|
||||
if ( descriptor[i] == 0x78){
|
||||
print_line(" L2 cache .......... 1 MB , 8-way associative, 64byte line size");
|
||||
tlib::print_line(" L2 cache .......... 1 MB , 8-way associative, 64byte line size");
|
||||
}
|
||||
if ( descriptor[i] == 0x79){
|
||||
print_line(" L2 cache .......... 128 kb, 8-way associative, sectored, 64 byte line size");
|
||||
tlib::print_line(" L2 cache .......... 128 kb, 8-way associative, sectored, 64 byte line size");
|
||||
}
|
||||
if ( descriptor[i] == 0x7A){
|
||||
print_line(" L2 cache .......... 256 kb, 8-way associative, sectored, 64 byte line size");
|
||||
tlib::print_line(" L2 cache .......... 256 kb, 8-way associative, sectored, 64 byte line size");
|
||||
}
|
||||
if ( descriptor[i] == 0x7B){
|
||||
print_line(" L2 cache .......... 512 kb, 8-way associative, sectored, 64 byte line size");
|
||||
tlib::print_line(" L2 cache .......... 512 kb, 8-way associative, sectored, 64 byte line size");
|
||||
}
|
||||
if ( descriptor[i] == 0x7C){
|
||||
print_line(" L2 cache .......... 1M Byte, 8-way associative, sectored, 64 byte line size");
|
||||
tlib::print_line(" L2 cache .......... 1M Byte, 8-way associative, sectored, 64 byte line size");
|
||||
}
|
||||
if ( descriptor[i] == 0x7D){
|
||||
print_line(" L2 cache .......... 2M Byte, 8-way associative, 64 byte line size");
|
||||
tlib::print_line(" L2 cache .......... 2M Byte, 8-way associative, 64 byte line size");
|
||||
}
|
||||
if ( descriptor[i] == 0x7F){
|
||||
print_line(" L2 cache .........512K Byte, 2-way associative, 64 byte line size");
|
||||
tlib::print_line(" L2 cache .........512K Byte, 2-way associative, 64 byte line size");
|
||||
}
|
||||
if ( descriptor[i] == 0x82){
|
||||
print_line(" L2 cache .......... 256 kb, 8-way associative, 32 byte line size");
|
||||
tlib::print_line(" L2 cache .......... 256 kb, 8-way associative, 32 byte line size");
|
||||
}
|
||||
if ( descriptor[i] == 0x83){
|
||||
print_line(" L2 cache .......... 512K Byte, 8-way associative, 32 byte line size");
|
||||
tlib::print_line(" L2 cache .......... 512K Byte, 8-way associative, 32 byte line size");
|
||||
}
|
||||
if ( descriptor[i] == 0x84){
|
||||
print_line(" L2 cache .......... 1 Mb, 8-way associative, 32 byte line size");
|
||||
tlib::print_line(" L2 cache .......... 1 Mb, 8-way associative, 32 byte line size");
|
||||
}
|
||||
if ( descriptor[i] == 0x85){
|
||||
print_line(" L2 cache .......... 2 Mb, 8-way associative, 32 byte line size");
|
||||
tlib::print_line(" L2 cache .......... 2 Mb, 8-way associative, 32 byte line size");
|
||||
}
|
||||
if ( descriptor[i] == 0x86){
|
||||
print_line(" L2 cache .......... 512K Byte, 4-way associative, 64 byte line size");
|
||||
tlib::print_line(" L2 cache .......... 512K Byte, 4-way associative, 64 byte line size");
|
||||
}
|
||||
if ( descriptor[i] == 0x87){
|
||||
print_line(" L2 cache .......... 1M Byte, 8-way associative, 64 byte line size");
|
||||
tlib::print_line(" L2 cache .......... 1M Byte, 8-way associative, 64 byte line size");
|
||||
}
|
||||
if ( descriptor[i] == 0xB0){
|
||||
print_line(" Instruction TLB 4K-Byte Pages, 4-way associative, 128 entries");
|
||||
tlib::print_line(" Instruction TLB 4K-Byte Pages, 4-way associative, 128 entries");
|
||||
}
|
||||
if ( descriptor[i] == 0xB3){
|
||||
print_line(" Data TLB 4K-Byte Pages, 4-way associative, 128 entries");
|
||||
tlib::print_line(" Data TLB 4K-Byte Pages, 4-way associative, 128 entries");
|
||||
}
|
||||
if ( descriptor[i] == 0xB4){
|
||||
print_line(" Data TLB 4K-Byte Pages, 4-way associative, 256 entries");
|
||||
tlib::print_line(" Data TLB 4K-Byte Pages, 4-way associative, 256 entries");
|
||||
}
|
||||
if ( descriptor[i] == 0xF0){
|
||||
print_line(" 64-byte prefetching");
|
||||
tlib::print_line(" 64-byte prefetching");
|
||||
}
|
||||
if ( descriptor[i] == 0xF1){
|
||||
print_line(" 128-byte prefetching");
|
||||
tlib::print_line(" 128-byte prefetching");
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -372,23 +372,23 @@ void get_deterministic_cache_parameters(){
|
||||
}
|
||||
|
||||
if ((eax & 0x1F) == 1){
|
||||
print("Data Cache: ");
|
||||
tlib::print("Data Cache: ");
|
||||
}
|
||||
|
||||
if ((eax & 0x1F) == 2){
|
||||
print("Instruction Cache: ");
|
||||
tlib::print("Instruction Cache: ");
|
||||
}
|
||||
|
||||
if ((eax & 0x1F) == 3){
|
||||
print("Unified Cache: ");
|
||||
tlib::print("Unified Cache: ");
|
||||
}
|
||||
|
||||
printf( "Level %u: ", static_cast<size_t>((eax & 0xE0)/32));
|
||||
printf( "Max Threads %u: ", static_cast<size_t>(((eax & 0x03FFC000)/(8192))+1));
|
||||
printf( "Max Procs. %u: " , static_cast<size_t>(((eax & 0xFC000000)/(4*256*65536))+1));
|
||||
printf( "Line Size = %u: ", static_cast<size_t>((ebx & 0xFFF ) + 1));
|
||||
printf( "Associativity = %u: ", (static_cast<size_t>((ebx & 0xFFC00000)/4*16*65536) + 1));
|
||||
printf( "Sets = %u:\n", static_cast<size_t>(ecx + 1));
|
||||
tlib::printf( "Level %u: ", static_cast<size_t>((eax & 0xE0)/32));
|
||||
tlib::printf( "Max Threads %u: ", static_cast<size_t>(((eax & 0x03FFC000)/(8192))+1));
|
||||
tlib::printf( "Max Procs. %u: " , static_cast<size_t>(((eax & 0xFC000000)/(4*256*65536))+1));
|
||||
tlib::printf( "Line Size = %u: ", static_cast<size_t>((ebx & 0xFFF ) + 1));
|
||||
tlib::printf( "Associativity = %u: ", (static_cast<size_t>((ebx & 0xFFC00000)/4*16*65536) + 1));
|
||||
tlib::printf( "Sets = %u:\n", static_cast<size_t>(ecx + 1));
|
||||
|
||||
++caches;
|
||||
}
|
||||
|
@ -9,19 +9,19 @@
|
||||
#include <tlib/system.hpp>
|
||||
|
||||
int main(int, char*[]){
|
||||
auto date = local_date();
|
||||
auto date = tlib::local_date();
|
||||
|
||||
print(date.day);
|
||||
print('.');
|
||||
print(date.month);
|
||||
print('.');
|
||||
print(date.year);
|
||||
print(' ');
|
||||
tlib::print(date.day);
|
||||
tlib::print('.');
|
||||
tlib::print(date.month);
|
||||
tlib::print('.');
|
||||
tlib::print(date.year);
|
||||
tlib::print(' ');
|
||||
|
||||
print(date.hour);
|
||||
print(':');
|
||||
print(date.minutes);
|
||||
print_line();
|
||||
tlib::print(date.hour);
|
||||
tlib::print(':');
|
||||
tlib::print(date.minutes);
|
||||
tlib::print_line();
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
@ -12,11 +12,11 @@ namespace {
|
||||
|
||||
struct A {
|
||||
A(){
|
||||
print_line("dctor: Constructor called");
|
||||
tlib::print_line("dctor: Constructor called");
|
||||
}
|
||||
|
||||
~A(){
|
||||
print_line("dctor: Destructor called");
|
||||
tlib::print_line("dctor: Destructor called");
|
||||
}
|
||||
};
|
||||
|
||||
@ -25,7 +25,7 @@ A a;
|
||||
} // end of anonymous namespace
|
||||
|
||||
int main(int, char*[]){
|
||||
print_line("dctor: main function called");
|
||||
tlib::print_line("dctor: main function called");
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
@ -27,30 +27,30 @@ int main(int argc, char* argv[]){
|
||||
|
||||
auto buffer = new char[BUFFER_SIZE];
|
||||
|
||||
auto mp_result = mounts(buffer, BUFFER_SIZE);
|
||||
auto mp_result = tlib::mounts(buffer, BUFFER_SIZE);
|
||||
|
||||
if(mp_result.valid()){
|
||||
size_t position = 0;
|
||||
|
||||
print_line("File system Size Used Available");
|
||||
tlib::print_line("File system Size Used Available");
|
||||
|
||||
while(true){
|
||||
auto entry = reinterpret_cast<mount_point*>(buffer + position);
|
||||
auto entry = reinterpret_cast<tlib::mount_point*>(buffer + position);
|
||||
|
||||
auto mount_point = &entry->name;
|
||||
|
||||
auto statfs_result = statfs(mount_point);
|
||||
auto statfs_result = tlib::statfs(mount_point);
|
||||
|
||||
if(statfs_result.valid()){
|
||||
auto& statfs = *statfs_result;
|
||||
|
||||
if(human){
|
||||
printf("%s %m %m %m\n", mount_point, statfs.total_size, statfs.total_size - statfs.free_size, statfs.free_size);
|
||||
tlib::printf("%s %m %m %m\n", mount_point, statfs.total_size, statfs.total_size - statfs.free_size, statfs.free_size);
|
||||
} else {
|
||||
printf("%s %u %u %u\n", mount_point, statfs.total_size, statfs.total_size - statfs.free_size, statfs.free_size);
|
||||
tlib::printf("%s %u %u %u\n", mount_point, statfs.total_size, statfs.total_size - statfs.free_size, statfs.free_size);
|
||||
}
|
||||
} else {
|
||||
printf("df: error: %s\n", std::error_message(statfs_result.error()));
|
||||
tlib::printf("df: error: %s\n", std::error_message(statfs_result.error()));
|
||||
}
|
||||
|
||||
if(!entry->offset_next){
|
||||
@ -60,7 +60,7 @@ int main(int argc, char* argv[]){
|
||||
position += entry->offset_next;
|
||||
}
|
||||
} else {
|
||||
printf("df: error: %s\n", std::error_message(mp_result.error()));
|
||||
tlib::printf("df: error: %s\n", std::error_message(mp_result.error()));
|
||||
}
|
||||
|
||||
delete[] buffer;
|
||||
|
@ -12,20 +12,20 @@ const char* source = "Hello world";
|
||||
int main(){
|
||||
char buffer[16];
|
||||
|
||||
printf("Read 1 string (max 15)\n");
|
||||
tlib::printf("Read 1 string (max 15)\n");
|
||||
|
||||
auto c = read_input(buffer, 15);
|
||||
auto c = tlib::read_input(buffer, 15);
|
||||
buffer[c] = '\0';
|
||||
print(buffer);
|
||||
tlib::print(buffer);
|
||||
|
||||
printf("Read 1 string (max 15) with timeout 5\n");
|
||||
c = read_input(buffer, 15, 5000);
|
||||
tlib::printf("Read 1 string (max 15) with timeout 5\n");
|
||||
c = tlib::read_input(buffer, 15, 5000);
|
||||
|
||||
if(c){
|
||||
buffer[c] = '\0';
|
||||
print(buffer);
|
||||
tlib::print(buffer);
|
||||
} else {
|
||||
printf("Timeout reached\n");
|
||||
tlib::printf("Timeout reached\n");
|
||||
}
|
||||
|
||||
return 0;
|
||||
|
@ -20,14 +20,14 @@ uint64_t fibonacci_slow(uint64_t s){
|
||||
int main(){
|
||||
uint64_t i = 0;
|
||||
|
||||
print_line("START");
|
||||
tlib::print_line("START");
|
||||
|
||||
while(i < 10){
|
||||
print_line(fibonacci_slow(current));
|
||||
tlib::print_line(fibonacci_slow(current));
|
||||
++i;
|
||||
}
|
||||
|
||||
print_line("END");
|
||||
tlib::print_line("END");
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
@ -22,7 +22,7 @@ auto message = "I'm one";
|
||||
int main(){
|
||||
while(true){
|
||||
fibonacci_slow(current);
|
||||
print_line(message);
|
||||
tlib::print_line(message);
|
||||
}
|
||||
|
||||
return 0;
|
||||
|
@ -22,7 +22,7 @@ auto message = "I'm two";
|
||||
int main(){
|
||||
while(true){
|
||||
fibonacci_slow(current);
|
||||
print_line(message);
|
||||
tlib::print_line(message);
|
||||
}
|
||||
|
||||
return 0;
|
||||
|
@ -21,55 +21,55 @@ struct config {
|
||||
};
|
||||
|
||||
void ls_files(const config& conf, const char* file_path){
|
||||
auto fd = open(file_path);
|
||||
auto fd = tlib::open(file_path);
|
||||
|
||||
if(fd.valid()){
|
||||
auto info = stat(*fd);
|
||||
auto info = tlib::stat(*fd);
|
||||
|
||||
if(info.valid()){
|
||||
if(!(info->flags & STAT_FLAG_DIRECTORY)){
|
||||
print_line("ls: error: Is not a directory");
|
||||
if(!(info->flags & tlib::STAT_FLAG_DIRECTORY)){
|
||||
tlib::print_line("ls: error: Is not a directory");
|
||||
} else {
|
||||
auto buffer = new char[BUFFER_SIZE];
|
||||
|
||||
auto entries_result = entries(*fd, buffer, BUFFER_SIZE);
|
||||
auto entries_result = tlib::entries(*fd, buffer, BUFFER_SIZE);
|
||||
|
||||
if(entries_result.valid()){
|
||||
if(*entries_result){
|
||||
size_t position = 0;
|
||||
|
||||
while(true){
|
||||
auto entry = reinterpret_cast<directory_entry*>(buffer + position);
|
||||
auto entry = reinterpret_cast<tlib::directory_entry*>(buffer + position);
|
||||
|
||||
bool show = true;
|
||||
if(!conf.hidden){
|
||||
auto path = std::string(file_path) + "/" + &entry->name;
|
||||
|
||||
auto file_fd = open(path.c_str());
|
||||
auto file_fd = tlib::open(path.c_str());
|
||||
|
||||
if(file_fd.valid()){
|
||||
auto file_info = stat(*file_fd);
|
||||
auto file_info = tlib::stat(*file_fd);
|
||||
|
||||
if(file_info.valid()){
|
||||
if(file_info->flags & STAT_FLAG_HIDDEN){
|
||||
if(file_info->flags & tlib::STAT_FLAG_HIDDEN){
|
||||
show = false;
|
||||
}
|
||||
} else {
|
||||
printf("ls: stat error: %s\n", std::error_message(file_info.error()));
|
||||
tlib::printf("ls: stat error: %s\n", std::error_message(file_info.error()));
|
||||
}
|
||||
} else {
|
||||
printf("ls: open error: %s\n", std::error_message(file_fd.error()));
|
||||
tlib::printf("ls: open error: %s\n", std::error_message(file_fd.error()));
|
||||
}
|
||||
|
||||
close(*file_fd);
|
||||
tlib::close(*file_fd);
|
||||
}
|
||||
|
||||
if(show){
|
||||
if(conf.list){
|
||||
print_line(&entry->name);
|
||||
tlib::print_line(&entry->name);
|
||||
} else {
|
||||
print(&entry->name);
|
||||
print(" ");
|
||||
tlib::print(&entry->name);
|
||||
tlib::print(" ");
|
||||
}
|
||||
}
|
||||
|
||||
@ -81,22 +81,22 @@ void ls_files(const config& conf, const char* file_path){
|
||||
}
|
||||
|
||||
if(!conf.list){
|
||||
print_line();
|
||||
tlib::print_line();
|
||||
}
|
||||
}
|
||||
} else {
|
||||
printf("ls: entries error: %s\n", std::error_message(entries_result.error()));
|
||||
tlib::printf("ls: entries error: %s\n", std::error_message(entries_result.error()));
|
||||
}
|
||||
|
||||
delete[] buffer;
|
||||
}
|
||||
} else {
|
||||
printf("ls: stat error: %s\n", std::error_message(info.error()));
|
||||
tlib::printf("ls: stat error: %s\n", std::error_message(info.error()));
|
||||
}
|
||||
|
||||
close(*fd);
|
||||
tlib::close(*fd);
|
||||
} else {
|
||||
printf("ls: open error: %s\n", std::error_message(fd.error()));
|
||||
tlib::printf("ls: open error: %s\n", std::error_message(fd.error()));
|
||||
}
|
||||
}
|
||||
|
||||
@ -118,7 +118,7 @@ int main(int argc, char* argv[]){
|
||||
} else if(c == 'a'){
|
||||
conf.hidden = true;
|
||||
} else {
|
||||
print_line("ls: invalid argument");
|
||||
tlib::print_line("ls: invalid argument");
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
@ -128,7 +128,7 @@ int main(int argc, char* argv[]){
|
||||
}
|
||||
|
||||
if(i == argc){
|
||||
auto cwd = current_working_directory();
|
||||
auto cwd = tlib::current_working_directory();
|
||||
ls_files(conf, cwd.c_str());
|
||||
} else {
|
||||
ls_files(conf, argv[argc -1]);
|
||||
|
@ -14,57 +14,57 @@
|
||||
static constexpr const size_t BUFFER_SIZE = 4096;
|
||||
|
||||
std::string read_file(const std::string& path){
|
||||
auto fd = open(path.c_str());
|
||||
auto fd = tlib::open(path.c_str());
|
||||
|
||||
if(fd.valid()){
|
||||
auto info = stat(*fd);
|
||||
auto info = tlib::stat(*fd);
|
||||
|
||||
if(info.valid()){
|
||||
auto size = info->size;
|
||||
|
||||
auto buffer = new char[size+1];
|
||||
|
||||
auto content_result = read(*fd, buffer, size);
|
||||
auto content_result = tlib::read(*fd, buffer, size);
|
||||
|
||||
if(content_result.valid()){
|
||||
if(*content_result != size){
|
||||
//TODO Read more
|
||||
} else {
|
||||
buffer[size] = '\0';
|
||||
close(*fd);
|
||||
tlib::close(*fd);
|
||||
return buffer;
|
||||
}
|
||||
} else {
|
||||
printf("cat: error: %s\n", std::error_message(content_result.error()));
|
||||
tlib::printf("cat: error: %s\n", std::error_message(content_result.error()));
|
||||
}
|
||||
} else {
|
||||
printf("cat: error: %s\n", std::error_message(info.error()));
|
||||
tlib::printf("cat: error: %s\n", std::error_message(info.error()));
|
||||
}
|
||||
|
||||
close(*fd);
|
||||
tlib::close(*fd);
|
||||
} else {
|
||||
printf("cat: error: %s\n", std::error_message(fd.error()));
|
||||
tlib::printf("cat: error: %s\n", std::error_message(fd.error()));
|
||||
}
|
||||
|
||||
return "";
|
||||
}
|
||||
|
||||
int main(int /*argc*/, char* /*argv*/[]){
|
||||
auto fd = open("/sys/memory/e820/");
|
||||
auto fd = tlib::open("/sys/memory/e820/");
|
||||
|
||||
if(fd.valid()){
|
||||
auto info = stat(*fd);
|
||||
auto info = tlib::stat(*fd);
|
||||
|
||||
if(info.valid()){
|
||||
auto entries_buffer = new char[BUFFER_SIZE];
|
||||
|
||||
auto entries_result = entries(*fd, entries_buffer, BUFFER_SIZE);
|
||||
auto entries_result = tlib::entries(*fd, entries_buffer, BUFFER_SIZE);
|
||||
|
||||
if(entries_result.valid()){
|
||||
size_t position = 0;
|
||||
|
||||
while(true){
|
||||
auto entry = reinterpret_cast<directory_entry*>(entries_buffer + position);
|
||||
auto entry = reinterpret_cast<tlib::directory_entry*>(entries_buffer + position);
|
||||
|
||||
std::string base_path = "/sys/memory/e820/";
|
||||
std::string entry_name = &entry->name;
|
||||
@ -74,7 +74,7 @@ int main(int /*argc*/, char* /*argv*/[]){
|
||||
auto size = parse(read_file(base_path + entry_name + "/size"));
|
||||
auto type = read_file(base_path + entry_name + "/type");
|
||||
|
||||
printf("%s: %s (%hB) %h -> %h\n", &entry->name, type.c_str(), size, base, base + size);
|
||||
tlib::printf("%s: %s (%hB) %h -> %h\n", &entry->name, type.c_str(), size, base, base + size);
|
||||
}
|
||||
|
||||
if(!entry->offset_next){
|
||||
@ -84,17 +84,17 @@ int main(int /*argc*/, char* /*argv*/[]){
|
||||
position += entry->offset_next;
|
||||
}
|
||||
} else {
|
||||
printf("lse820: entries error: %s\n", std::error_message(entries_result.error()));
|
||||
tlib::printf("lse820: entries error: %s\n", std::error_message(entries_result.error()));
|
||||
}
|
||||
|
||||
delete[] entries_buffer;
|
||||
} else {
|
||||
printf("lse820: stat error: %s\n", std::error_message(info.error()));
|
||||
tlib::printf("lse820: stat error: %s\n", std::error_message(info.error()));
|
||||
}
|
||||
|
||||
close(*fd);
|
||||
tlib::close(*fd);
|
||||
} else {
|
||||
printf("lse820: open error: %s\n", std::error_message(fd.error()));
|
||||
tlib::printf("lse820: open error: %s\n", std::error_message(fd.error()));
|
||||
}
|
||||
|
||||
return 0;
|
||||
|
@ -14,36 +14,36 @@
|
||||
static constexpr const size_t BUFFER_SIZE = 4096;
|
||||
|
||||
std::string read_file(const std::string& path){
|
||||
auto fd = open(path.c_str());
|
||||
auto fd = tlib::open(path.c_str());
|
||||
|
||||
if(fd.valid()){
|
||||
auto info = stat(*fd);
|
||||
auto info = tlib::stat(*fd);
|
||||
|
||||
if(info.valid()){
|
||||
auto size = info->size;
|
||||
|
||||
auto buffer = new char[size+1];
|
||||
|
||||
auto content_result = read(*fd, buffer, size);
|
||||
auto content_result = tlib::read(*fd, buffer, size);
|
||||
|
||||
if(content_result.valid()){
|
||||
if(*content_result != size){
|
||||
//TODO Read more
|
||||
} else {
|
||||
buffer[size] = '\0';
|
||||
close(*fd);
|
||||
tlib::close(*fd);
|
||||
return buffer;
|
||||
}
|
||||
} else {
|
||||
printf("cat: error: %s\n", std::error_message(content_result.error()));
|
||||
tlib::printf("cat: error: %s\n", std::error_message(content_result.error()));
|
||||
}
|
||||
} else {
|
||||
printf("cat: error: %s\n", std::error_message(info.error()));
|
||||
tlib::printf("cat: error: %s\n", std::error_message(info.error()));
|
||||
}
|
||||
|
||||
close(*fd);
|
||||
tlib::close(*fd);
|
||||
} else {
|
||||
printf("cat: error: %s\n", std::error_message(fd.error()));
|
||||
tlib::printf("cat: error: %s\n", std::error_message(fd.error()));
|
||||
}
|
||||
|
||||
return "";
|
||||
@ -90,21 +90,21 @@ const char* device_type_str(const std::string& class_code){
|
||||
}
|
||||
|
||||
int main(int /*argc*/, char* /*argv*/[]){
|
||||
auto fd = open("/sys/pci/");
|
||||
auto fd = tlib::open("/sys/pci/");
|
||||
|
||||
if(fd.valid()){
|
||||
auto info = stat(*fd);
|
||||
auto info = tlib::stat(*fd);
|
||||
|
||||
if(info.valid()){
|
||||
auto entries_buffer = new char[BUFFER_SIZE];
|
||||
|
||||
auto entries_result = entries(*fd, entries_buffer, BUFFER_SIZE);
|
||||
auto entries_result = tlib::entries(*fd, entries_buffer, BUFFER_SIZE);
|
||||
|
||||
if(entries_result.valid()){
|
||||
size_t position = 0;
|
||||
|
||||
while(true){
|
||||
auto entry = reinterpret_cast<directory_entry*>(entries_buffer + position);
|
||||
auto entry = reinterpret_cast<tlib::directory_entry*>(entries_buffer + position);
|
||||
|
||||
std::string base_path = "/sys/pci/";
|
||||
std::string entry_name = &entry->name;
|
||||
@ -115,7 +115,7 @@ int main(int /*argc*/, char* /*argv*/[]){
|
||||
auto subclass = read_file(base_path + entry_name + "/subclass");
|
||||
auto device_type = device_type_str(class_code);
|
||||
|
||||
printf("%s: %s %s:%s (%s:%s)\n", device_type, &entry->name, vendor.c_str(), device.c_str(), class_code.c_str(), subclass.c_str());
|
||||
tlib::printf("%s: %s %s:%s (%s:%s)\n", device_type, &entry->name, vendor.c_str(), device.c_str(), class_code.c_str(), subclass.c_str());
|
||||
|
||||
if(!entry->offset_next){
|
||||
break;
|
||||
@ -124,17 +124,17 @@ int main(int /*argc*/, char* /*argv*/[]){
|
||||
position += entry->offset_next;
|
||||
}
|
||||
} else {
|
||||
printf("ls: error: %s\n", std::error_message(entries_result.error()));
|
||||
tlib::printf("ls: error: %s\n", std::error_message(entries_result.error()));
|
||||
}
|
||||
|
||||
delete[] entries_buffer;
|
||||
} else {
|
||||
printf("ls: error: %s\n", std::error_message(info.error()));
|
||||
tlib::printf("ls: error: %s\n", std::error_message(info.error()));
|
||||
}
|
||||
|
||||
close(*fd);
|
||||
tlib::close(*fd);
|
||||
} else {
|
||||
printf("ls: error: %s\n", std::error_message(fd.error()));
|
||||
tlib::printf("ls: error: %s\n", std::error_message(fd.error()));
|
||||
}
|
||||
|
||||
return 0;
|
||||
|
@ -13,14 +13,14 @@
|
||||
|
||||
int main(int argc, char* argv[]){
|
||||
if(argc == 1){
|
||||
print_line("Usage: mkdir file_path");
|
||||
tlib::print_line("Usage: mkdir file_path");
|
||||
return 1;
|
||||
}
|
||||
|
||||
auto result = mkdir(argv[1]);
|
||||
auto result = tlib::mkdir(argv[1]);
|
||||
|
||||
if(result < 0){
|
||||
printf("mkdir: error: %s\n", std::error_message(-result));
|
||||
tlib::printf("mkdir: error: %s\n", std::error_message(-result));
|
||||
}
|
||||
|
||||
return 0;
|
||||
|
@ -20,7 +20,7 @@ static constexpr const size_t BUFFER_SIZE = 4096;
|
||||
|
||||
int main(int argc, char* argv[]){
|
||||
if(argc < 3){
|
||||
printf("usage: mkfs fs device \n");
|
||||
tlib::printf("usage: mkfs fs device \n");
|
||||
|
||||
return 1;
|
||||
}
|
||||
@ -32,27 +32,27 @@ int main(int argc, char* argv[]){
|
||||
|
||||
if(fs == "fat32"){
|
||||
// Open the device file
|
||||
auto fd = open(device_str);
|
||||
auto fd = tlib::open(device_str);
|
||||
|
||||
if(!fd.valid()){
|
||||
printf("mkfs: open error: %s\n", std::error_message(fd.error()));
|
||||
tlib::printf("mkfs: open error: %s\n", std::error_message(fd.error()));
|
||||
return 1;
|
||||
}
|
||||
|
||||
// Get the size of the device
|
||||
|
||||
uint64_t size = 0;
|
||||
auto code = ioctl(*fd, ioctl_request::GET_BLK_SIZE, &size);
|
||||
auto code = tlib::ioctl(*fd, ioctl_request::GET_BLK_SIZE, &size);
|
||||
|
||||
if(code){
|
||||
printf("mkfs: ioctl error: %s\n", std::error_message(code));
|
||||
tlib::printf("mkfs: ioctl error: %s\n", std::error_message(code));
|
||||
return 1;
|
||||
}
|
||||
|
||||
// Start computing and writing the FAT32 values
|
||||
|
||||
printf("mkfs: Creating Fat32 filesystem on %s\n", device_str);
|
||||
printf("mkfs: Device size: %m\n", size);
|
||||
tlib::printf("mkfs: Creating Fat32 filesystem on %s\n", device_str);
|
||||
tlib::printf("mkfs: Device size: %m\n", size);
|
||||
|
||||
uint64_t sector_size = 512;
|
||||
uint64_t sectors_per_cluster = 8;
|
||||
@ -67,15 +67,15 @@ int main(int argc, char* argv[]){
|
||||
uint64_t fat_size_clusters = std::ceil_divide(fat_size_sectors, sectors_per_cluster);
|
||||
fat_size_sectors = fat_size_clusters * sectors_per_cluster;
|
||||
|
||||
printf("mkfs: Device sectors : %u\n", sectors);
|
||||
printf("mkfs: Available sectors : %u\n", available_sectors);
|
||||
printf("mkfs: FAT sectors : %u\n", fat_size_sectors);
|
||||
tlib::printf("mkfs: Device sectors : %u\n", sectors);
|
||||
tlib::printf("mkfs: Available sectors : %u\n", available_sectors);
|
||||
tlib::printf("mkfs: FAT sectors : %u\n", fat_size_sectors);
|
||||
|
||||
uint64_t free_clusters = available_clusters - fat_size_clusters - 1;
|
||||
uint64_t free_sectors = free_clusters * sectors_per_cluster;
|
||||
|
||||
printf("mkfs: Free sectors : %u\n", free_sectors);
|
||||
printf("mkfs: Free clusters : %u\n", free_clusters);
|
||||
tlib::printf("mkfs: Free sectors : %u\n", free_sectors);
|
||||
tlib::printf("mkfs: Free clusters : %u\n", free_clusters);
|
||||
|
||||
auto fat_bs = std::make_unique<fat32::fat_bs_t>();
|
||||
|
||||
@ -94,10 +94,10 @@ int main(int argc, char* argv[]){
|
||||
fat_bs->signature = 0xAA55;
|
||||
|
||||
// Write the FAT BS
|
||||
auto status = write(*fd, reinterpret_cast<const char*>(fat_bs.get()), sector_size, 0);
|
||||
auto status = tlib::write(*fd, reinterpret_cast<const char*>(fat_bs.get()), sector_size, 0);
|
||||
|
||||
if(!status.valid()){
|
||||
printf("mkfs: write error: %s\n", std::error_message(status.error()));
|
||||
tlib::printf("mkfs: write error: %s\n", std::error_message(status.error()));
|
||||
return 1;
|
||||
}
|
||||
|
||||
@ -110,29 +110,29 @@ int main(int argc, char* argv[]){
|
||||
fat_is->signature_end = 0x000055AA;
|
||||
|
||||
// Write the FAT IS
|
||||
status = write(*fd, reinterpret_cast<const char*>(fat_is.get()), sector_size, sector_size);
|
||||
status = tlib::write(*fd, reinterpret_cast<const char*>(fat_is.get()), sector_size, sector_size);
|
||||
|
||||
if(!status.valid()){
|
||||
printf("mkfs: write error: %s\n", std::error_message(status.error()));
|
||||
tlib::printf("mkfs: write error: %s\n", std::error_message(status.error()));
|
||||
return 1;
|
||||
}
|
||||
|
||||
// Clear the FAT
|
||||
|
||||
auto fat_begin = fat_bs->reserved_sectors;
|
||||
status = clear(*fd, fat_begin * sector_size, fat_size_sectors * sector_size);
|
||||
status = tlib::clear(*fd, fat_begin * sector_size, fat_size_sectors * sector_size);
|
||||
|
||||
if(!status.valid()){
|
||||
printf("mkfs: clear error: %s\n", std::error_message(status.error()));
|
||||
tlib::printf("mkfs: clear error: %s\n", std::error_message(status.error()));
|
||||
return 1;
|
||||
}
|
||||
|
||||
// Write end of chain for cluster 2 (root)
|
||||
uint32_t end_of_cluster_chain = 0x0FFFFFF8;
|
||||
status = write(*fd, reinterpret_cast<char*>(&end_of_cluster_chain), 4, fat_begin * sector_size + 2 * 4);
|
||||
status = tlib::write(*fd, reinterpret_cast<char*>(&end_of_cluster_chain), 4, fat_begin * sector_size + 2 * 4);
|
||||
|
||||
if(!status.valid()){
|
||||
printf("mkfs: write error: %s\n", std::error_message(status.error()));
|
||||
tlib::printf("mkfs: write error: %s\n", std::error_message(status.error()));
|
||||
return 1;
|
||||
}
|
||||
|
||||
@ -150,14 +150,14 @@ int main(int argc, char* argv[]){
|
||||
|
||||
//Write the directory entries to the disk
|
||||
auto root_sector = fat_begin + (fat_bs->number_of_fat * fat_bs->sectors_per_fat_long);
|
||||
if(!write(*fd, reinterpret_cast<char*>(root_cluster_entries.get()), sector_size * fat_bs->sectors_per_cluster, root_sector * sector_size)){
|
||||
if(!tlib::write(*fd, reinterpret_cast<char*>(root_cluster_entries.get()), sector_size * fat_bs->sectors_per_cluster, root_sector * sector_size)){
|
||||
return std::ERROR_FAILED;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
printf("mkfs: Unsupported filesystem %s\n", fs_str);
|
||||
tlib::printf("mkfs: Unsupported filesystem %s\n", fs_str);
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
@ -17,19 +17,19 @@ int main(int argc, char* argv[]){
|
||||
if(argc == 1){
|
||||
auto buffer = new char[BUFFER_SIZE];
|
||||
|
||||
auto mp_result = mounts(buffer, BUFFER_SIZE);
|
||||
auto mp_result = tlib::mounts(buffer, BUFFER_SIZE);
|
||||
|
||||
if(mp_result.valid()){
|
||||
size_t position = 0;
|
||||
|
||||
while(true){
|
||||
auto entry = reinterpret_cast<mount_point*>(buffer + position);
|
||||
auto entry = reinterpret_cast<tlib::mount_point*>(buffer + position);
|
||||
|
||||
auto mount_point = &entry->name;
|
||||
auto device = mount_point + entry->length_mp + 1;
|
||||
auto type = device + entry->length_dev + 1;
|
||||
|
||||
printf("%s %s %s\n", mount_point, device, type);
|
||||
tlib::printf("%s %s %s\n", mount_point, device, type);
|
||||
|
||||
if(!entry->offset_next){
|
||||
break;
|
||||
@ -38,7 +38,7 @@ int main(int argc, char* argv[]){
|
||||
position += entry->offset_next;
|
||||
}
|
||||
} else {
|
||||
printf("mount: error: %s\n", std::error_message(mp_result.error()));
|
||||
tlib::printf("mount: error: %s\n", std::error_message(mp_result.error()));
|
||||
}
|
||||
|
||||
delete[] buffer;
|
||||
@ -47,7 +47,7 @@ int main(int argc, char* argv[]){
|
||||
}
|
||||
|
||||
if(argc < 4){
|
||||
printf("usage: mount fs device mountpoint\n");
|
||||
tlib::printf("usage: mount fs device mountpoint\n");
|
||||
|
||||
return 1;
|
||||
}
|
||||
@ -59,29 +59,29 @@ int main(int argc, char* argv[]){
|
||||
std::string fs(fs_str);
|
||||
|
||||
if(fs == "fat32"){
|
||||
printf("mkfs: Mounting %s fat32 filesystem on %s\n", device_str, mount_point_str);
|
||||
tlib::printf("mkfs: Mounting %s fat32 filesystem on %s\n", device_str, mount_point_str);
|
||||
|
||||
auto device_fd = open(device_str);
|
||||
auto device_fd = tlib::open(device_str);
|
||||
|
||||
if(!device_fd.valid()){
|
||||
printf("mount: open error: %s\n", std::error_message(device_fd.error()));
|
||||
tlib::printf("mount: open error: %s\n", std::error_message(device_fd.error()));
|
||||
return 1;
|
||||
}
|
||||
|
||||
auto mp_fd = open(mount_point_str);
|
||||
auto mp_fd = tlib::open(mount_point_str);
|
||||
|
||||
if(!mp_fd.valid()){ printf("mount: open error: %s\n", std::error_message(mp_fd.error()));
|
||||
if(!mp_fd.valid()){ tlib::printf("mount: open error: %s\n", std::error_message(mp_fd.error()));
|
||||
return 1;
|
||||
}
|
||||
|
||||
auto mount_result = mount(1, *device_fd, *mp_fd);
|
||||
auto mount_result = tlib::mount(1, *device_fd, *mp_fd);
|
||||
|
||||
if(!mount_result.valid()){
|
||||
printf("mount: mount error: %s\n", std::error_message(mount_result.error()));
|
||||
tlib::printf("mount: mount error: %s\n", std::error_message(mount_result.error()));
|
||||
return 1;
|
||||
}
|
||||
} else {
|
||||
printf("mkfs: Unsupported filesystem %s\n", fs_str);
|
||||
tlib::printf("mkfs: Unsupported filesystem %s\n", fs_str);
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
@ -97,8 +97,8 @@ void draw_string(size_t x, size_t y, const char* s, uint32_t color){
|
||||
}
|
||||
|
||||
void paint_cursor(){
|
||||
auto x = graphics::mouse_x();
|
||||
auto y = graphics::mouse_y();
|
||||
auto x = tlib::graphics::mouse_x();
|
||||
auto y = tlib::graphics::mouse_y();
|
||||
|
||||
auto color = make_color(20, 20, 20);
|
||||
|
||||
@ -118,9 +118,9 @@ void paint_top_bar(){
|
||||
draw_rect(0, 0, width, 18, make_color(51, 51, 51));
|
||||
draw_rect(0, 18, width, 2, make_color(25, 25, 25));
|
||||
|
||||
auto date = local_date();
|
||||
auto date = tlib::local_date();
|
||||
|
||||
auto date_str = sprintf("%u.%u.%u %u:%u", size_t(date.day), size_t(date.month), size_t(date.year), size_t(date.hour), size_t(date.minutes));
|
||||
auto date_str = tlib::sprintf("%u.%u.%u %u:%u", size_t(date.day), size_t(date.month), size_t(date.year), size_t(date.hour), size_t(date.minutes));
|
||||
|
||||
draw_char(2, 2, 'T', make_color(30, 30, 30));
|
||||
draw_string(width - 128, 2, date_str.c_str(), make_color(200, 200, 200));
|
||||
@ -159,8 +159,8 @@ public:
|
||||
|
||||
void update(){
|
||||
if(drag){
|
||||
auto mouse_x = graphics::mouse_x();
|
||||
auto mouse_y = graphics::mouse_y();
|
||||
auto mouse_x = tlib::graphics::mouse_x();
|
||||
auto mouse_y = tlib::graphics::mouse_y();
|
||||
|
||||
auto delta_x = int64_t(mouse_x) - drag_start_x;
|
||||
auto delta_y = int64_t(mouse_y) - drag_start_y;
|
||||
@ -203,8 +203,8 @@ public:
|
||||
}
|
||||
|
||||
bool mouse_in_title(){
|
||||
auto mouse_x = graphics::mouse_x();
|
||||
auto mouse_y = graphics::mouse_y();
|
||||
auto mouse_x = tlib::graphics::mouse_x();
|
||||
auto mouse_y = tlib::graphics::mouse_y();
|
||||
|
||||
return mouse_x >= x && mouse_x <= x + width && mouse_y >= y + 2 && mouse_y <= mouse_y + 18;
|
||||
}
|
||||
@ -212,8 +212,8 @@ public:
|
||||
void start_drag(){
|
||||
if(!drag){
|
||||
drag = true;
|
||||
drag_start_x = graphics::mouse_x();
|
||||
drag_start_y = graphics::mouse_y();
|
||||
drag_start_x = tlib::graphics::mouse_x();
|
||||
drag_start_y = tlib::graphics::mouse_y();
|
||||
}
|
||||
}
|
||||
|
||||
@ -227,14 +227,14 @@ std::vector<window> windows;
|
||||
} // end of anonnymous namespace
|
||||
|
||||
int main(int /*argc*/, char* /*argv*/[]){
|
||||
width = graphics::get_width();
|
||||
height = graphics::get_height();
|
||||
x_shift = graphics::get_x_shift();
|
||||
y_shift = graphics::get_y_shift();
|
||||
bytes_per_scan_line = graphics::get_bytes_per_scan_line();
|
||||
red_shift = graphics::get_red_shift();
|
||||
green_shift = graphics::get_green_shift();
|
||||
blue_shift = graphics::get_blue_shift();
|
||||
width = tlib::graphics::get_width();
|
||||
height = tlib::graphics::get_height();
|
||||
x_shift = tlib::graphics::get_x_shift();
|
||||
y_shift = tlib::graphics::get_y_shift();
|
||||
bytes_per_scan_line = tlib::graphics::get_bytes_per_scan_line();
|
||||
red_shift = tlib::graphics::get_red_shift();
|
||||
green_shift = tlib::graphics::get_green_shift();
|
||||
blue_shift = tlib::graphics::get_blue_shift();
|
||||
|
||||
size_t total_size = height * bytes_per_scan_line;
|
||||
|
||||
@ -244,8 +244,8 @@ int main(int /*argc*/, char* /*argv*/[]){
|
||||
|
||||
auto background = make_color(128, 128, 128);
|
||||
|
||||
set_canonical(false);
|
||||
set_mouse(true);
|
||||
tlib::set_canonical(false);
|
||||
tlib::set_mouse(true);
|
||||
|
||||
static constexpr const size_t sleep_timeout = 50;
|
||||
|
||||
@ -267,18 +267,18 @@ int main(int /*argc*/, char* /*argv*/[]){
|
||||
|
||||
paint_cursor();
|
||||
|
||||
graphics::redraw(buffer);
|
||||
tlib::graphics::redraw(buffer);
|
||||
|
||||
auto before = ms_time();
|
||||
auto code = read_input_raw(sleep_timeout);
|
||||
auto after = ms_time();
|
||||
auto before = tlib::ms_time();
|
||||
auto code = tlib::read_input_raw(sleep_timeout);
|
||||
auto after = tlib::ms_time();
|
||||
|
||||
if(code != keycode::TIMEOUT){
|
||||
// TODO Handle event at this point
|
||||
|
||||
switch(code){
|
||||
case keycode::MOUSE_LEFT_PRESS:
|
||||
user_logf("odin: left press");
|
||||
tlib::user_logf("odin: left press");
|
||||
|
||||
for(auto& window: windows){
|
||||
if(window.mouse_in_title()){
|
||||
@ -289,7 +289,7 @@ int main(int /*argc*/, char* /*argv*/[]){
|
||||
break;
|
||||
|
||||
case keycode::MOUSE_LEFT_RELEASE:
|
||||
user_logf("odin: left release");
|
||||
tlib::user_logf("odin: left release");
|
||||
|
||||
for(auto& window: windows){
|
||||
window.stop_drag();
|
||||
@ -298,27 +298,27 @@ int main(int /*argc*/, char* /*argv*/[]){
|
||||
break;
|
||||
|
||||
case keycode::MOUSE_RIGHT_PRESS:
|
||||
user_logf("odin: right press");
|
||||
tlib::user_logf("odin: right press");
|
||||
break;
|
||||
|
||||
case keycode::MOUSE_RIGHT_RELEASE:
|
||||
user_logf("odin: right release");
|
||||
tlib::user_logf("odin: right release");
|
||||
break;
|
||||
|
||||
default:
|
||||
user_logf("odin: %u ", static_cast<size_t>(code));
|
||||
tlib::user_logf("odin: %u ", static_cast<size_t>(code));
|
||||
}
|
||||
|
||||
auto duration = after - before;
|
||||
|
||||
if(duration < sleep_timeout){
|
||||
sleep_ms(sleep_timeout - duration);
|
||||
tlib::sleep_ms(sleep_timeout - duration);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
set_canonical(true);
|
||||
set_mouse(false);
|
||||
tlib::set_canonical(true);
|
||||
tlib::set_mouse(false);
|
||||
|
||||
delete[] buffer;
|
||||
|
||||
|
@ -16,20 +16,20 @@ namespace {
|
||||
|
||||
int main(int argc, char* argv[]){
|
||||
if(argc != 2){
|
||||
print_line("usage: ping address_ip");
|
||||
tlib::print_line("usage: ping address_ip");
|
||||
return 1;
|
||||
}
|
||||
|
||||
std::string ip(argv[0]);
|
||||
|
||||
auto socket = socket_open(network::socket_domain::AF_INET, network::socket_type::RAW, network::socket_protocol::ICMP);
|
||||
auto socket = tlib::socket_open(network::socket_domain::AF_INET, network::socket_type::RAW, network::socket_protocol::ICMP);
|
||||
|
||||
if(!socket){
|
||||
printf("ls: socket_open error: %s\n", std::error_message(socket.error()));
|
||||
tlib::printf("ls: socket_open error: %s\n", std::error_message(socket.error()));
|
||||
return 1;
|
||||
}
|
||||
|
||||
socket_close(*socket);
|
||||
tlib::socket_close(*socket);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
@ -16,36 +16,36 @@ namespace {
|
||||
static constexpr const size_t BUFFER_SIZE = 4096;
|
||||
|
||||
std::string read_file(const std::string& path){
|
||||
auto fd = open(path.c_str());
|
||||
auto fd = tlib::open(path.c_str());
|
||||
|
||||
if(fd.valid()){
|
||||
auto info = stat(*fd);
|
||||
auto info = tlib::stat(*fd);
|
||||
|
||||
if(info.valid()){
|
||||
auto size = info->size;
|
||||
|
||||
auto buffer = new char[size+1];
|
||||
|
||||
auto content_result = read(*fd, buffer, size);
|
||||
auto content_result = tlib::read(*fd, buffer, size);
|
||||
|
||||
if(content_result.valid()){
|
||||
if(*content_result != size){
|
||||
//TODO Read more
|
||||
} else {
|
||||
buffer[size] = '\0';
|
||||
close(*fd);
|
||||
tlib::close(*fd);
|
||||
return buffer;
|
||||
}
|
||||
} else {
|
||||
printf("ps: error: %s\n", std::error_message(content_result.error()));
|
||||
tlib::printf("ps: error: %s\n", std::error_message(content_result.error()));
|
||||
}
|
||||
} else {
|
||||
printf("ps: error: %s\n", std::error_message(info.error()));
|
||||
tlib::printf("ps: error: %s\n", std::error_message(info.error()));
|
||||
}
|
||||
|
||||
close(*fd);
|
||||
tlib::close(*fd);
|
||||
} else {
|
||||
printf("ps: error: %s\n", std::error_message(fd.error()));
|
||||
tlib::printf("ps: error: %s\n", std::error_message(fd.error()));
|
||||
}
|
||||
|
||||
return "";
|
||||
@ -77,23 +77,23 @@ const char* state_str(uint64_t state){
|
||||
} // end of anonymous space
|
||||
|
||||
int main(int /*argc*/, char* /*argv*/[]){
|
||||
auto fd = open("/proc/");
|
||||
auto fd = tlib::open("/proc/");
|
||||
|
||||
printf("PID PPID Pri State Memory Name\n");
|
||||
tlib::printf("PID PPID Pri State Memory Name\n");
|
||||
|
||||
if(fd.valid()){
|
||||
auto info = stat(*fd);
|
||||
auto info = tlib::stat(*fd);
|
||||
|
||||
if(info.valid()){
|
||||
auto entries_buffer = new char[BUFFER_SIZE];
|
||||
|
||||
auto entries_result = entries(*fd, entries_buffer, BUFFER_SIZE);
|
||||
auto entries_result = tlib::entries(*fd, entries_buffer, BUFFER_SIZE);
|
||||
|
||||
if(entries_result.valid()){
|
||||
size_t position = 0;
|
||||
|
||||
while(true){
|
||||
auto entry = reinterpret_cast<directory_entry*>(entries_buffer + position);
|
||||
auto entry = reinterpret_cast<tlib::directory_entry*>(entries_buffer + position);
|
||||
|
||||
std::string base_path = "/proc/";
|
||||
std::string entry_name = &entry->name;
|
||||
@ -107,9 +107,9 @@ int main(int /*argc*/, char* /*argv*/[]){
|
||||
auto memory = parse(read_file(base_path + entry_name + "/memory"));
|
||||
|
||||
if(system){
|
||||
printf("%3u %4u %3u %10s %6m %s [kernel]\n", pid, ppid, priority, state_str(state), memory, name.c_str());
|
||||
tlib::printf("%3u %4u %3u %10s %6m %s [kernel]\n", pid, ppid, priority, state_str(state), memory, name.c_str());
|
||||
} else {
|
||||
printf("%3u %4u %3u %10s %6m %s \n", pid, ppid, priority, state_str(state), memory, name.c_str());
|
||||
tlib::printf("%3u %4u %3u %10s %6m %s \n", pid, ppid, priority, state_str(state), memory, name.c_str());
|
||||
}
|
||||
|
||||
if(!entry->offset_next){
|
||||
@ -119,17 +119,17 @@ int main(int /*argc*/, char* /*argv*/[]){
|
||||
position += entry->offset_next;
|
||||
}
|
||||
} else {
|
||||
printf("ps: error: %s\n", std::error_message(entries_result.error()));
|
||||
tlib::printf("ps: error: %s\n", std::error_message(entries_result.error()));
|
||||
}
|
||||
|
||||
delete[] entries_buffer;
|
||||
} else {
|
||||
printf("ps: error: %s\n", std::error_message(info.error()));
|
||||
tlib::printf("ps: error: %s\n", std::error_message(info.error()));
|
||||
}
|
||||
|
||||
close(*fd);
|
||||
tlib::close(*fd);
|
||||
} else {
|
||||
printf("ps: error: %s\n", std::error_message(fd.error()));
|
||||
tlib::printf("ps: error: %s\n", std::error_message(fd.error()));
|
||||
}
|
||||
|
||||
return 0;
|
||||
|
@ -15,17 +15,17 @@ namespace {
|
||||
|
||||
void readelf(char* buffer){
|
||||
if(!elf::is_valid(buffer)){
|
||||
print_line("readelf: This file is not an ELF file or not in ELF64 format");
|
||||
tlib::print_line("readelf: This file is not an ELF file or not in ELF64 format");
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
auto header = reinterpret_cast<elf::elf_header*>(buffer);
|
||||
|
||||
printf("%h\n", reinterpret_cast<size_t>(buffer));
|
||||
tlib::printf("%h\n", reinterpret_cast<size_t>(buffer));
|
||||
|
||||
printf("Number of Program Headers: %u\n", static_cast<uint64_t>(header->e_phnum));
|
||||
printf("Number of Section Headers: %u\n", static_cast<uint64_t>(header->e_shnum));
|
||||
tlib::printf("Number of Program Headers: %u\n", static_cast<uint64_t>(header->e_phnum));
|
||||
tlib::printf("Number of Section Headers: %u\n", static_cast<uint64_t>(header->e_shnum));
|
||||
|
||||
auto program_header_table = reinterpret_cast<elf::program_header*>(buffer + header->e_phoff);
|
||||
auto section_header_table = reinterpret_cast<elf::section_header*>(buffer + header->e_shoff);
|
||||
@ -36,38 +36,38 @@ void readelf(char* buffer){
|
||||
for(size_t p = 0; p < header->e_phnum; ++p){
|
||||
auto& p_header = program_header_table[p];
|
||||
|
||||
printf("Program header %u\n", p);
|
||||
printf("\tVirtual Address: %h\n", p_header.p_paddr);
|
||||
printf("\tMSize: %u\t", p_header.p_memsz);
|
||||
printf("\tFSize: %u\t Offset: %u \n", p_header.p_filesize, p_header.p_offset);
|
||||
tlib::printf("Program header %u\n", p);
|
||||
tlib::printf("\tVirtual Address: %h\n", p_header.p_paddr);
|
||||
tlib::printf("\tMSize: %u\t", p_header.p_memsz);
|
||||
tlib::printf("\tFSize: %u\t Offset: %u \n", p_header.p_filesize, p_header.p_offset);
|
||||
}
|
||||
|
||||
for(size_t s = 0; s < header->e_shnum; ++s){
|
||||
auto& s_header = section_header_table[s];
|
||||
|
||||
printf("Section \"%s\" (", &string_table[s_header.sh_name]);
|
||||
tlib::printf("Section \"%s\" (", &string_table[s_header.sh_name]);
|
||||
|
||||
if(s_header.sh_flags & 0x1){
|
||||
print(" W");
|
||||
tlib::print(" W");
|
||||
}
|
||||
|
||||
if(s_header.sh_flags & 0x2){
|
||||
print(" A");
|
||||
tlib::print(" A");
|
||||
}
|
||||
|
||||
if(s_header.sh_flags & 0x4){
|
||||
print(" X");
|
||||
tlib::print(" X");
|
||||
}
|
||||
|
||||
if(s_header.sh_flags & 0x0F000000){
|
||||
print(" OS");
|
||||
tlib::print(" OS");
|
||||
}
|
||||
|
||||
if(s_header.sh_flags & 0xF0000000){
|
||||
print(" CPU");
|
||||
tlib::print(" CPU");
|
||||
}
|
||||
print_line(")");
|
||||
printf("\tAddress: %h Size: %u Offset: %u\n", s_header.sh_addr, s_header.sh_size, s_header.sh_offset);
|
||||
tlib::print_line(")");
|
||||
tlib::printf("\tAddress: %h Size: %u Offset: %u\n", s_header.sh_addr, s_header.sh_size, s_header.sh_offset);
|
||||
}
|
||||
}
|
||||
|
||||
@ -75,27 +75,27 @@ void readelf(char* buffer){
|
||||
|
||||
int main(int argc, char* argv[]){
|
||||
if(argc == 1){
|
||||
print_line("Usage: readelf file_path");
|
||||
tlib::print_line("Usage: readelf file_path");
|
||||
return 1;
|
||||
}
|
||||
|
||||
auto fd = open(argv[1]);
|
||||
auto fd = tlib::open(argv[1]);
|
||||
|
||||
if(fd.valid()){
|
||||
auto info = stat(*fd);
|
||||
auto info = tlib::stat(*fd);
|
||||
|
||||
if(info.valid()){
|
||||
if(info->flags & STAT_FLAG_DIRECTORY){
|
||||
print_line("readelf: error: Is a directory");
|
||||
if(info->flags & tlib::STAT_FLAG_DIRECTORY){
|
||||
tlib::print_line("readelf: error: Is a directory");
|
||||
} else {
|
||||
auto size = info->size;
|
||||
|
||||
if(size == 0){
|
||||
print_line("readelf: error: The file is empty");
|
||||
tlib::print_line("readelf: error: The file is empty");
|
||||
} else {
|
||||
auto buffer = new char[size];
|
||||
|
||||
auto content_result = read(*fd, buffer, size);
|
||||
auto content_result = tlib::read(*fd, buffer, size);
|
||||
|
||||
if(content_result.valid()){
|
||||
if(*content_result != size){
|
||||
@ -104,19 +104,19 @@ int main(int argc, char* argv[]){
|
||||
readelf(buffer);
|
||||
}
|
||||
} else {
|
||||
printf("readelf: error: %s\n", std::error_message(content_result.error()));
|
||||
tlib::printf("readelf: error: %s\n", std::error_message(content_result.error()));
|
||||
}
|
||||
|
||||
delete[] buffer;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
printf("readelf: error: %s\n", std::error_message(info.error()));
|
||||
tlib::printf("readelf: error: %s\n", std::error_message(info.error()));
|
||||
}
|
||||
|
||||
close(*fd);
|
||||
tlib::close(*fd);
|
||||
} else {
|
||||
printf("readelf: error: %s\n", std::error_message(fd.error()));
|
||||
tlib::printf("readelf: error: %s\n", std::error_message(fd.error()));
|
||||
}
|
||||
|
||||
return 0;
|
||||
|
@ -8,6 +8,6 @@
|
||||
#include <tlib/system.hpp>
|
||||
|
||||
int main(){
|
||||
reboot();
|
||||
tlib::reboot();
|
||||
return 0;
|
||||
}
|
||||
|
@ -13,22 +13,22 @@
|
||||
|
||||
int main(int argc, char* argv[]){
|
||||
if(argc == 1){
|
||||
print_line("Usage: rm file_path");
|
||||
tlib::print_line("Usage: rm file_path");
|
||||
return 1;
|
||||
}
|
||||
|
||||
auto fd = open(argv[1]);
|
||||
auto fd = tlib::open(argv[1]);
|
||||
|
||||
if(fd.valid()){
|
||||
auto result = rm(argv[1]);
|
||||
auto result = tlib::rm(argv[1]);
|
||||
|
||||
if(result < 0){
|
||||
printf("rm: error: %s\n", std::error_message(-result));
|
||||
tlib::printf("rm: error: %s\n", std::error_message(-result));
|
||||
}
|
||||
|
||||
close(*fd);
|
||||
tlib::close(*fd);
|
||||
} else {
|
||||
printf("rm: error: %s\n", std::error_message(fd.error()));
|
||||
tlib::printf("rm: error: %s\n", std::error_message(fd.error()));
|
||||
}
|
||||
|
||||
return 0;
|
||||
|
@ -8,6 +8,6 @@
|
||||
#include <tlib/system.hpp>
|
||||
|
||||
int main(){
|
||||
shutdown();
|
||||
tlib::shutdown();
|
||||
return 0;
|
||||
}
|
||||
|
@ -12,85 +12,85 @@
|
||||
|
||||
int main(int argc, char* argv[]){
|
||||
if(argc == 1){
|
||||
print_line("Usage: stat file_path");
|
||||
tlib::print_line("Usage: stat file_path");
|
||||
return 1;
|
||||
}
|
||||
|
||||
auto fd = open(argv[1]);
|
||||
auto fd = tlib::open(argv[1]);
|
||||
|
||||
if(fd.valid()){
|
||||
auto info = stat(*fd);
|
||||
auto info = tlib::stat(*fd);
|
||||
|
||||
if(info.valid()){
|
||||
if(info->flags & STAT_FLAG_DIRECTORY){
|
||||
print("Directory ");
|
||||
if(info->flags & tlib::STAT_FLAG_DIRECTORY){
|
||||
tlib::print("Directory ");
|
||||
} else {
|
||||
print("File ");
|
||||
tlib::print("File ");
|
||||
}
|
||||
|
||||
print_line(argv[1]);
|
||||
tlib::print_line(argv[1]);
|
||||
|
||||
printf("Size: %m\n", info->size);
|
||||
print("Flags: ");
|
||||
tlib::printf("Size: %m\n", info->size);
|
||||
tlib::print("Flags: ");
|
||||
|
||||
if(info->flags & STAT_FLAG_HIDDEN){
|
||||
print("Hidden ");
|
||||
if(info->flags & tlib::STAT_FLAG_HIDDEN){
|
||||
tlib::print("Hidden ");
|
||||
}
|
||||
|
||||
if(info->flags & STAT_FLAG_SYSTEM){
|
||||
print("System ");
|
||||
if(info->flags & tlib::STAT_FLAG_SYSTEM){
|
||||
tlib::print("System ");
|
||||
}
|
||||
|
||||
print_line();
|
||||
tlib::print_line();
|
||||
|
||||
print("Created: ");
|
||||
tlib::print("Created: ");
|
||||
|
||||
print(info->created.day);
|
||||
print('.');
|
||||
print(info->created.month);
|
||||
print('.');
|
||||
print(info->created.year);
|
||||
print(' ');
|
||||
tlib::print(info->created.day);
|
||||
tlib::print('.');
|
||||
tlib::print(info->created.month);
|
||||
tlib::print('.');
|
||||
tlib::print(info->created.year);
|
||||
tlib::print(' ');
|
||||
|
||||
print(info->created.hour);
|
||||
print(':');
|
||||
print(info->created.minutes);
|
||||
print_line();
|
||||
tlib::print(info->created.hour);
|
||||
tlib::print(':');
|
||||
tlib::print(info->created.minutes);
|
||||
tlib::print_line();
|
||||
|
||||
print("Modified: ");
|
||||
tlib::print("Modified: ");
|
||||
|
||||
print(info->modified.day);
|
||||
print('.');
|
||||
print(info->modified.month);
|
||||
print('.');
|
||||
print(info->modified.year);
|
||||
print(' ');
|
||||
tlib::print(info->modified.day);
|
||||
tlib::print('.');
|
||||
tlib::print(info->modified.month);
|
||||
tlib::print('.');
|
||||
tlib::print(info->modified.year);
|
||||
tlib::print(' ');
|
||||
|
||||
print(info->modified.hour);
|
||||
print(':');
|
||||
print(info->modified.minutes);
|
||||
print_line();
|
||||
tlib::print(info->modified.hour);
|
||||
tlib::print(':');
|
||||
tlib::print(info->modified.minutes);
|
||||
tlib::print_line();
|
||||
|
||||
print("Accessed: ");
|
||||
tlib::print("Accessed: ");
|
||||
|
||||
print(info->accessed.day);
|
||||
print('.');
|
||||
print(info->accessed.month);
|
||||
print('.');
|
||||
print(info->accessed.year);
|
||||
print(' ');
|
||||
tlib::print(info->accessed.day);
|
||||
tlib::print('.');
|
||||
tlib::print(info->accessed.month);
|
||||
tlib::print('.');
|
||||
tlib::print(info->accessed.year);
|
||||
tlib::print(' ');
|
||||
|
||||
print(info->accessed.hour);
|
||||
print(':');
|
||||
print(info->accessed.minutes);
|
||||
print_line();
|
||||
tlib::print(info->accessed.hour);
|
||||
tlib::print(':');
|
||||
tlib::print(info->accessed.minutes);
|
||||
tlib::print_line();
|
||||
} else {
|
||||
printf("stat: error: %s\n", std::error_message(info.error()));
|
||||
tlib::printf("stat: error: %s\n", std::error_message(info.error()));
|
||||
}
|
||||
|
||||
close(*fd);
|
||||
tlib::close(*fd);
|
||||
} else {
|
||||
printf("stat: error: %s\n", std::error_message(fd.error()));
|
||||
tlib::printf("stat: error: %s\n", std::error_message(fd.error()));
|
||||
}
|
||||
|
||||
return 0;
|
||||
|
@ -12,16 +12,16 @@
|
||||
|
||||
int main(int argc, char* argv[]){
|
||||
if(argc == 1){
|
||||
print_line("Usage: touch file_path");
|
||||
tlib::print_line("Usage: touch file_path");
|
||||
return 1;
|
||||
}
|
||||
|
||||
auto fd = open(argv[1], std::OPEN_CREATE);
|
||||
auto fd = tlib::open(argv[1], std::OPEN_CREATE);
|
||||
|
||||
if(fd.valid()){
|
||||
close(*fd);
|
||||
tlib::close(*fd);
|
||||
} else {
|
||||
printf("touch: error: %s\n", std::error_message(fd.error()));
|
||||
tlib::printf("touch: error: %s\n", std::error_message(fd.error()));
|
||||
}
|
||||
|
||||
return 0;
|
||||
|
@ -19,8 +19,8 @@ size_t columns = 0;
|
||||
size_t rows = 0;
|
||||
|
||||
void get_console_information(){
|
||||
columns = get_columns();
|
||||
rows = get_rows();
|
||||
columns = tlib::get_columns();
|
||||
rows = tlib::get_rows();
|
||||
}
|
||||
|
||||
void exit_command(const std::vector<std::string>& params);
|
||||
@ -45,68 +45,68 @@ command_definition commands[6] = {
|
||||
};
|
||||
|
||||
void exit_command(const std::vector<std::string>&){
|
||||
exit(0);
|
||||
tlib::exit(0);
|
||||
}
|
||||
|
||||
void echo_command(const std::vector<std::string>& params){
|
||||
for(uint64_t i = 1; i < params.size(); ++i){
|
||||
print(params[i]);
|
||||
print(' ');
|
||||
tlib::print(params[i]);
|
||||
tlib::print(' ');
|
||||
}
|
||||
print_line();
|
||||
tlib::print_line();
|
||||
}
|
||||
|
||||
void sleep_command(const std::vector<std::string>& params){
|
||||
if(params.size() == 1){
|
||||
print_line("sleep: missing operand");
|
||||
tlib::print_line("sleep: missing operand");
|
||||
} else {
|
||||
size_t time = std::parse(params[1]);
|
||||
sleep_ms(time * 1000);
|
||||
tlib::sleep_ms(time * 1000);
|
||||
}
|
||||
}
|
||||
|
||||
void clear_command(const std::vector<std::string>&){
|
||||
clear();
|
||||
tlib::clear();
|
||||
}
|
||||
|
||||
void cd_command(const std::vector<std::string>& params){
|
||||
if(params.size() == 1){
|
||||
print_line("Usage: cd file_path");
|
||||
tlib::print_line("Usage: cd file_path");
|
||||
return;
|
||||
}
|
||||
|
||||
auto& path = params[1];
|
||||
|
||||
auto fd = open(path.c_str());
|
||||
auto fd = tlib::open(path.c_str());
|
||||
|
||||
if(fd.valid()){
|
||||
auto info = stat(*fd);
|
||||
auto info = tlib::stat(*fd);
|
||||
|
||||
if(info.valid()){
|
||||
if(!(info->flags & STAT_FLAG_DIRECTORY)){
|
||||
print_line("cat: error: Is not a directory");
|
||||
if(!(info->flags & tlib::STAT_FLAG_DIRECTORY)){
|
||||
tlib::print_line("cat: error: Is not a directory");
|
||||
} else {
|
||||
if(path[0] == '/'){
|
||||
set_current_working_directory(path);
|
||||
tlib::set_current_working_directory(path);
|
||||
} else {
|
||||
auto cwd = current_working_directory();
|
||||
auto cwd = tlib::current_working_directory();
|
||||
|
||||
set_current_working_directory(cwd + "/" + path);
|
||||
tlib::set_current_working_directory(cwd + "/" + path);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
printf("cd: error: %s\n", std::error_message(info.error()));
|
||||
tlib::printf("cd: error: %s\n", std::error_message(info.error()));
|
||||
}
|
||||
|
||||
close(*fd);
|
||||
tlib::close(*fd);
|
||||
} else {
|
||||
printf("cd: error: %s\n", std::error_message(fd.error()));
|
||||
tlib::printf("cd: error: %s\n", std::error_message(fd.error()));
|
||||
}
|
||||
}
|
||||
|
||||
void pwd_command(const std::vector<std::string>&){
|
||||
auto cwd = current_working_directory();
|
||||
print_line(cwd);
|
||||
auto cwd = tlib::current_working_directory();
|
||||
tlib::print_line(cwd);
|
||||
}
|
||||
|
||||
} //end of anonymous namespace
|
||||
@ -117,10 +117,10 @@ int main(){
|
||||
char input_buffer[256];
|
||||
std::string current_input;
|
||||
|
||||
print("thor> ");
|
||||
tlib::print("thor> ");
|
||||
|
||||
while(true){
|
||||
auto c = read_input(input_buffer, 255 );
|
||||
auto c = tlib::read_input(input_buffer, 255 );
|
||||
|
||||
if(input_buffer[c-1] == '\n'){
|
||||
if(c > 1){
|
||||
@ -156,21 +156,21 @@ int main(){
|
||||
executable = "/bin/" + executable;
|
||||
}
|
||||
|
||||
auto result = exec_and_wait(executable.c_str(), args);
|
||||
auto result = tlib::exec_and_wait(executable.c_str(), args);
|
||||
|
||||
if(!result.valid()){
|
||||
print("error: ");
|
||||
print_line(std::error_message(result.error()));
|
||||
print("command: \"");
|
||||
print(current_input);
|
||||
print_line("\"");
|
||||
tlib::print("error: ");
|
||||
tlib::print_line(std::error_message(result.error()));
|
||||
tlib::print("command: \"");
|
||||
tlib::print(current_input);
|
||||
tlib::print_line("\"");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
current_input.clear();
|
||||
|
||||
print("thor> ");
|
||||
tlib::print("thor> ");
|
||||
} else {
|
||||
input_buffer[c] = '\0';
|
||||
|
||||
|
@ -11,12 +11,12 @@
|
||||
#include <tlib/print.hpp>
|
||||
|
||||
int main(int, char*[]){
|
||||
auto fd = open("/sys/uptime");
|
||||
auto fd = tlib::open("/sys/uptime");
|
||||
|
||||
if(fd.valid()){
|
||||
auto buffer = new char[64];
|
||||
|
||||
auto content_result = read(*fd, buffer, 64);
|
||||
auto content_result = tlib::read(*fd, buffer, 64);
|
||||
|
||||
if(content_result.valid()){
|
||||
auto chars = *content_result;
|
||||
@ -30,16 +30,16 @@ int main(int, char*[]){
|
||||
|
||||
auto value = std::parse(value_str);
|
||||
|
||||
printf("Uptime: %u:%u:%u\n", value / 3600, (value % 3600) / 60, value % 60);
|
||||
tlib::printf("Uptime: %u:%u:%u\n", value / 3600, (value % 3600) / 60, value % 60);
|
||||
} else {
|
||||
printf("uptime: error: %s\n", std::error_message(content_result.error()));
|
||||
tlib::printf("uptime: error: %s\n", std::error_message(content_result.error()));
|
||||
}
|
||||
|
||||
delete[] buffer;
|
||||
|
||||
close(*fd);
|
||||
tlib::close(*fd);
|
||||
} else {
|
||||
printf("uptime: error: %s\n", std::error_message(fd.error()));
|
||||
tlib::printf("uptime: error: %s\n", std::error_message(fd.error()));
|
||||
}
|
||||
|
||||
return 0;
|
||||
|
@ -12,7 +12,7 @@
|
||||
|
||||
int main(int argc, char* argv[]){
|
||||
if(argc == 1){
|
||||
print_line("Usage: which executable_path");
|
||||
tlib::print_line("Usage: which executable_path");
|
||||
return 1;
|
||||
}
|
||||
|
||||
@ -22,17 +22,17 @@ int main(int argc, char* argv[]){
|
||||
path = "/bin/" + path;
|
||||
}
|
||||
|
||||
auto fd = open(path.c_str());
|
||||
auto fd = tlib::open(path.c_str());
|
||||
|
||||
if(fd.valid()){
|
||||
print_line(path);
|
||||
tlib::print_line(path);
|
||||
|
||||
close(*fd);
|
||||
tlib::close(*fd);
|
||||
} else {
|
||||
if(fd.has_error(std::ERROR_NOT_EXISTS)){
|
||||
printf("%s not found\n", argv[1]);
|
||||
tlib::printf("%s not found\n", argv[1]);
|
||||
} else {
|
||||
printf("which: error: %s\n", std::error_message(fd.error()));
|
||||
tlib::printf("which: error: %s\n", std::error_message(fd.error()));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -13,32 +13,32 @@
|
||||
|
||||
int main(int argc, char* argv[]){
|
||||
if(argc == 1){
|
||||
print_line("Usage: writer file_path");
|
||||
tlib::print_line("Usage: writer file_path");
|
||||
return 1;
|
||||
}
|
||||
|
||||
auto fd = open(argv[1], std::OPEN_CREATE);
|
||||
auto fd = tlib::open(argv[1], std::OPEN_CREATE);
|
||||
|
||||
if(fd.valid()){
|
||||
auto truncate_result = truncate(*fd, 12);
|
||||
auto truncate_result = tlib::truncate(*fd, 12);
|
||||
|
||||
if(truncate_result.valid()){
|
||||
auto s = "0123456789AB";
|
||||
|
||||
auto write_result = write(*fd, s, 12, 0);
|
||||
auto write_result = tlib::write(*fd, s, 12, 0);
|
||||
|
||||
if(write_result.valid()){
|
||||
//TODO
|
||||
} else {
|
||||
printf("writer: error: %s\n", std::error_message(write_result.error()));
|
||||
tlib::printf("writer: error: %s\n", std::error_message(write_result.error()));
|
||||
}
|
||||
} else {
|
||||
printf("writer: error: %s\n", std::error_message(truncate_result.error()));
|
||||
tlib::printf("writer: error: %s\n", std::error_message(truncate_result.error()));
|
||||
}
|
||||
|
||||
close(*fd);
|
||||
tlib::close(*fd);
|
||||
} else {
|
||||
printf("writer: error: %s\n", std::error_message(fd.error()));
|
||||
tlib::printf("writer: error: %s\n", std::error_message(fd.error()));
|
||||
}
|
||||
|
||||
return 0;
|
||||
|
@ -10,6 +10,8 @@
|
||||
|
||||
#include <types.hpp>
|
||||
|
||||
namespace tlib {
|
||||
|
||||
struct datetime {
|
||||
uint16_t year;
|
||||
uint8_t month;
|
||||
@ -21,4 +23,6 @@ struct datetime {
|
||||
uint64_t precise;
|
||||
} __attribute__((packed)) ;
|
||||
|
||||
} // end of namespace tlib
|
||||
|
||||
#endif
|
||||
|
@ -10,6 +10,8 @@
|
||||
|
||||
#include <types.hpp>
|
||||
|
||||
namespace tlib {
|
||||
|
||||
struct directory_entry {
|
||||
size_t type;
|
||||
size_t offset_next;
|
||||
@ -17,4 +19,6 @@ struct directory_entry {
|
||||
char name; //First char
|
||||
};
|
||||
|
||||
} // end of namespace tlib
|
||||
|
||||
#endif
|
||||
|
@ -87,6 +87,6 @@ inline const char* error_message(size_t error){
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
} // end of namespace std
|
||||
|
||||
#endif
|
||||
|
@ -15,6 +15,8 @@
|
||||
#include "tlib/stat_info.hpp"
|
||||
#include "tlib/statfs_info.hpp"
|
||||
|
||||
namespace tlib {
|
||||
|
||||
std::expected<size_t> open(const char* file, size_t flags = 0);
|
||||
int64_t mkdir(const char* file);
|
||||
int64_t rm(const char* file);
|
||||
@ -32,4 +34,6 @@ std::expected<void> mount(size_t type, size_t dev_fd, size_t mp_fd);
|
||||
std::string current_working_directory();
|
||||
void set_current_working_directory(const std::string& directory);
|
||||
|
||||
} // end of namespace tlib
|
||||
|
||||
#endif
|
||||
|
@ -10,6 +10,8 @@
|
||||
|
||||
#include <types.hpp>
|
||||
|
||||
namespace tlib {
|
||||
|
||||
namespace graphics {
|
||||
|
||||
uint64_t get_width();
|
||||
@ -31,4 +33,6 @@ void redraw(char* buffer);
|
||||
|
||||
} // end of namespace graphics
|
||||
|
||||
} // end of namespace tlib
|
||||
|
||||
#endif
|
||||
|
@ -13,6 +13,10 @@
|
||||
|
||||
#include "tlib/ioctl_codes.hpp"
|
||||
|
||||
namespace tlib {
|
||||
|
||||
int64_t ioctl(size_t device, ioctl_request request, void* data);
|
||||
|
||||
} //end of namespace tlib
|
||||
|
||||
#endif
|
||||
|
@ -16,6 +16,8 @@ void operator delete(void* p);
|
||||
void* operator new[](uint64_t size);
|
||||
void operator delete[](void* p);
|
||||
|
||||
namespace tlib {
|
||||
|
||||
void* malloc(size_t size);
|
||||
void free(void* pointer);
|
||||
|
||||
@ -23,4 +25,6 @@ size_t brk_start();
|
||||
size_t brk_end();
|
||||
size_t sbrk(size_t inc);
|
||||
|
||||
} // end of tlib namespace
|
||||
|
||||
#endif
|
||||
|
@ -10,6 +10,8 @@
|
||||
|
||||
#include <types.hpp>
|
||||
|
||||
namespace tlib {
|
||||
|
||||
struct mount_point {
|
||||
size_t offset_next;
|
||||
size_t length_mp;
|
||||
@ -18,4 +20,6 @@ struct mount_point {
|
||||
char name; //First char
|
||||
};
|
||||
|
||||
} // end of namespace tlib
|
||||
|
||||
#endif
|
||||
|
@ -12,7 +12,11 @@
|
||||
|
||||
#include "net_constants.hpp"
|
||||
|
||||
namespace tlib {
|
||||
|
||||
std::expected<size_t> socket_open(network::socket_domain domain, network::socket_type type, network::socket_protocol protocol);
|
||||
void socket_close(size_t fd);
|
||||
|
||||
} // end of namespace tlib
|
||||
|
||||
#endif
|
||||
|
@ -17,6 +17,8 @@
|
||||
|
||||
#include <tlib/keycode.hpp>
|
||||
|
||||
namespace tlib {
|
||||
|
||||
void print(char c);
|
||||
void print(const char* s);
|
||||
void print(const std::string& s);
|
||||
@ -54,4 +56,6 @@ size_t get_rows();
|
||||
|
||||
void user_logf(const char* s, ...);
|
||||
|
||||
} //end of namespace tlib
|
||||
|
||||
#endif
|
||||
|
@ -12,6 +12,8 @@
|
||||
|
||||
#include "tlib/datetime.hpp"
|
||||
|
||||
namespace tlib {
|
||||
|
||||
constexpr const size_t STAT_FLAG_DIRECTORY = 1 << 0;
|
||||
constexpr const size_t STAT_FLAG_HIDDEN = 1 << 1;
|
||||
constexpr const size_t STAT_FLAG_SYSTEM = 1 << 2;
|
||||
@ -24,4 +26,6 @@ struct stat_info {
|
||||
datetime accessed;
|
||||
};
|
||||
|
||||
} // end of namespace tlib
|
||||
|
||||
#endif
|
||||
|
@ -10,9 +10,13 @@
|
||||
|
||||
#include <types.hpp>
|
||||
|
||||
namespace tlib {
|
||||
|
||||
struct statfs_info {
|
||||
size_t total_size;
|
||||
size_t free_size;
|
||||
};
|
||||
|
||||
} // end of namespace tlib
|
||||
|
||||
#endif
|
||||
|
@ -15,6 +15,8 @@
|
||||
|
||||
#include "tlib/datetime.hpp"
|
||||
|
||||
namespace tlib {
|
||||
|
||||
void exit(size_t return_code) __attribute__((noreturn));
|
||||
|
||||
std::expected<size_t> exec(const char* executable, const std::vector<std::string>& params = {});
|
||||
@ -34,4 +36,6 @@ uint64_t ms_time();
|
||||
|
||||
void alpha();
|
||||
|
||||
} // end of tlib namespace
|
||||
|
||||
#endif
|
||||
|
@ -7,7 +7,7 @@
|
||||
|
||||
#include "tlib/file.hpp"
|
||||
|
||||
std::expected<size_t> open(const char* file, size_t flags){
|
||||
std::expected<size_t> tlib::open(const char* file, size_t flags){
|
||||
int64_t fd;
|
||||
asm volatile("mov rax, 300; mov rbx, %[path]; mov rcx, %[flags]; int 50; mov %[fd], rax"
|
||||
: [fd] "=m" (fd)
|
||||
@ -21,7 +21,7 @@ std::expected<size_t> open(const char* file, size_t flags){
|
||||
}
|
||||
}
|
||||
|
||||
int64_t mkdir(const char* file){
|
||||
int64_t tlib::mkdir(const char* file){
|
||||
int64_t result;
|
||||
asm volatile("mov rax, 306; mov rbx, %[path]; int 50; mov %[result], rax"
|
||||
: [result] "=m" (result)
|
||||
@ -30,7 +30,7 @@ int64_t mkdir(const char* file){
|
||||
return result;
|
||||
}
|
||||
|
||||
int64_t rm(const char* file){
|
||||
int64_t tlib::rm(const char* file){
|
||||
int64_t result;
|
||||
asm volatile("mov rax, 307; mov rbx, %[path]; int 50; mov %[result], rax"
|
||||
: [result] "=m" (result)
|
||||
@ -39,15 +39,15 @@ int64_t rm(const char* file){
|
||||
return result;
|
||||
}
|
||||
|
||||
void close(size_t fd){
|
||||
void tlib::close(size_t fd){
|
||||
asm volatile("mov rax, 302; mov rbx, %[fd]; int 50;"
|
||||
: /* No outputs */
|
||||
: [fd] "g" (fd)
|
||||
: "rax", "rbx");
|
||||
}
|
||||
|
||||
std::expected<stat_info> stat(size_t fd){
|
||||
stat_info info;
|
||||
std::expected<tlib::stat_info> tlib::stat(size_t fd){
|
||||
tlib::stat_info info;
|
||||
|
||||
int64_t code;
|
||||
asm volatile("mov rax, 301; mov rbx, %[fd]; mov rcx, %[buffer]; int 50; mov %[code], rax"
|
||||
@ -56,14 +56,14 @@ std::expected<stat_info> stat(size_t fd){
|
||||
: "rax", "rbx", "rcx");
|
||||
|
||||
if(code < 0){
|
||||
return std::make_expected_from_error<stat_info, size_t>(-code);
|
||||
return std::make_expected_from_error<tlib::stat_info, size_t>(-code);
|
||||
} else {
|
||||
return std::make_expected<stat_info>(info);
|
||||
return std::make_expected<tlib::stat_info>(info);
|
||||
}
|
||||
}
|
||||
|
||||
std::expected<statfs_info> statfs(const char* file){
|
||||
statfs_info info;
|
||||
std::expected<tlib::statfs_info> tlib::statfs(const char* file){
|
||||
tlib::statfs_info info;
|
||||
|
||||
int64_t code;
|
||||
asm volatile("mov rax, 310; mov rbx, %[path]; mov rcx, %[buffer]; int 50; mov %[code], rax"
|
||||
@ -72,13 +72,13 @@ std::expected<statfs_info> statfs(const char* file){
|
||||
: "rax", "rbx", "rcx");
|
||||
|
||||
if(code < 0){
|
||||
return std::make_expected_from_error<statfs_info, size_t>(-code);
|
||||
return std::make_expected_from_error<tlib::statfs_info, size_t>(-code);
|
||||
} else {
|
||||
return std::make_expected<statfs_info>(info);
|
||||
return std::make_expected<tlib::statfs_info>(info);
|
||||
}
|
||||
}
|
||||
|
||||
std::expected<size_t> read(size_t fd, char* buffer, size_t max, size_t offset){
|
||||
std::expected<size_t> tlib::read(size_t fd, char* buffer, size_t max, size_t offset){
|
||||
int64_t code;
|
||||
asm volatile("mov rax, 303; mov rbx, %[fd]; mov rcx, %[buffer]; mov rdx, %[max]; mov rsi, %[offset]; int 50; mov %[code], rax"
|
||||
: [code] "=m" (code)
|
||||
@ -92,7 +92,7 @@ std::expected<size_t> read(size_t fd, char* buffer, size_t max, size_t offset){
|
||||
}
|
||||
}
|
||||
|
||||
std::expected<size_t> write(size_t fd, const char* buffer, size_t max, size_t offset){
|
||||
std::expected<size_t> tlib::write(size_t fd, const char* buffer, size_t max, size_t offset){
|
||||
int64_t code;
|
||||
asm volatile("mov rax, 311; mov rbx, %[fd]; mov rcx, %[buffer]; mov rdx, %[max]; mov rsi, %[offset]; int 50; mov %[code], rax"
|
||||
: [code] "=m" (code)
|
||||
@ -106,7 +106,7 @@ std::expected<size_t> write(size_t fd, const char* buffer, size_t max, size_t of
|
||||
}
|
||||
}
|
||||
|
||||
std::expected<size_t> clear(size_t fd, size_t max, size_t offset){
|
||||
std::expected<size_t> tlib::clear(size_t fd, size_t max, size_t offset){
|
||||
int64_t code;
|
||||
asm volatile("mov rax, 313; mov rbx, %[fd]; mov rcx, %[max]; mov rdx, %[offset]; int 50; mov %[code], rax"
|
||||
: [code] "=m" (code)
|
||||
@ -120,7 +120,7 @@ std::expected<size_t> clear(size_t fd, size_t max, size_t offset){
|
||||
}
|
||||
}
|
||||
|
||||
std::expected<size_t> truncate(size_t fd, size_t size){
|
||||
std::expected<size_t> tlib::truncate(size_t fd, size_t size){
|
||||
int64_t code;
|
||||
asm volatile("mov rax, 312; mov rbx, %[fd]; mov rcx, %[size]; int 50; mov %[code], rax"
|
||||
: [code] "=m" (code)
|
||||
@ -134,7 +134,7 @@ std::expected<size_t> truncate(size_t fd, size_t size){
|
||||
}
|
||||
}
|
||||
|
||||
std::expected<size_t> entries(size_t fd, char* buffer, size_t max){
|
||||
std::expected<size_t> tlib::entries(size_t fd, char* buffer, size_t max){
|
||||
int64_t code;
|
||||
asm volatile("mov rax, 308; mov rbx, %[fd]; mov rcx, %[buffer]; mov rdx, %[max]; int 50; mov %[code], rax"
|
||||
: [code] "=m" (code)
|
||||
@ -148,7 +148,7 @@ std::expected<size_t> entries(size_t fd, char* buffer, size_t max){
|
||||
}
|
||||
}
|
||||
|
||||
std::expected<size_t> mounts(char* buffer, size_t max){
|
||||
std::expected<size_t> tlib::mounts(char* buffer, size_t max){
|
||||
int64_t code;
|
||||
asm volatile("mov rax, 309; mov rbx, %[buffer]; mov rcx, %[max]; int 50; mov %[code], rax"
|
||||
: [code] "=m" (code)
|
||||
@ -162,7 +162,7 @@ std::expected<size_t> mounts(char* buffer, size_t max){
|
||||
}
|
||||
}
|
||||
|
||||
std::expected<void> mount(size_t type, size_t dev_fd, size_t mp_fd){
|
||||
std::expected<void> tlib::mount(size_t type, size_t dev_fd, size_t mp_fd){
|
||||
int64_t code;
|
||||
asm volatile("mov rax, 314; mov rbx, %[type]; mov rcx, %[mp]; mov rdx, %[dev]; int 50; mov %[code], rax"
|
||||
: [code] "=m" (code)
|
||||
@ -176,7 +176,7 @@ std::expected<void> mount(size_t type, size_t dev_fd, size_t mp_fd){
|
||||
}
|
||||
}
|
||||
|
||||
std::string current_working_directory(){
|
||||
std::string tlib::current_working_directory(){
|
||||
char buffer[128];
|
||||
buffer[0] = '\0';
|
||||
|
||||
@ -188,7 +188,7 @@ std::string current_working_directory(){
|
||||
return {buffer};
|
||||
}
|
||||
|
||||
void set_current_working_directory(const std::string& directory){
|
||||
void tlib::set_current_working_directory(const std::string& directory){
|
||||
asm volatile("mov rax, 305; mov rbx, %[buffer]; int 50;"
|
||||
: /* No outputs */
|
||||
: [buffer] "g" (reinterpret_cast<size_t>(directory.c_str()))
|
||||
|
@ -20,49 +20,49 @@ uint64_t syscall_get(uint64_t call){
|
||||
|
||||
} // end of anonymous namespace
|
||||
|
||||
uint64_t graphics::get_width(){
|
||||
uint64_t tlib::graphics::get_width(){
|
||||
return syscall_get(0x1000);
|
||||
}
|
||||
|
||||
uint64_t graphics::get_height(){
|
||||
uint64_t tlib::graphics::get_height(){
|
||||
return syscall_get(0x1001);
|
||||
}
|
||||
|
||||
uint64_t graphics::get_x_shift(){
|
||||
uint64_t tlib::graphics::get_x_shift(){
|
||||
return syscall_get(0x1002);
|
||||
}
|
||||
|
||||
uint64_t graphics::get_y_shift(){
|
||||
uint64_t tlib::graphics::get_y_shift(){
|
||||
return syscall_get(0x1003);
|
||||
}
|
||||
|
||||
uint64_t graphics::get_bytes_per_scan_line(){
|
||||
uint64_t tlib::graphics::get_bytes_per_scan_line(){
|
||||
return syscall_get(0x1004);
|
||||
}
|
||||
|
||||
uint64_t graphics::get_red_shift(){
|
||||
uint64_t tlib::graphics::get_red_shift(){
|
||||
return syscall_get(0x1005);
|
||||
}
|
||||
|
||||
uint64_t graphics::get_green_shift(){
|
||||
uint64_t tlib::graphics::get_green_shift(){
|
||||
return syscall_get(0x1006);
|
||||
}
|
||||
|
||||
uint64_t graphics::get_blue_shift(){
|
||||
uint64_t tlib::graphics::get_blue_shift(){
|
||||
return syscall_get(0x1007);
|
||||
}
|
||||
|
||||
void graphics::redraw(char* buffer){
|
||||
void tlib::graphics::redraw(char* buffer){
|
||||
asm volatile("mov rax, 0x1008; mov rbx, %[buffer]; int 50;"
|
||||
:
|
||||
: [buffer] "g" (buffer)
|
||||
: "rax", "rbx");
|
||||
}
|
||||
|
||||
uint64_t graphics::mouse_x(){
|
||||
uint64_t tlib::graphics::mouse_x(){
|
||||
return syscall_get(0x1100);
|
||||
}
|
||||
|
||||
uint64_t graphics::mouse_y(){
|
||||
uint64_t tlib::graphics::mouse_y(){
|
||||
return syscall_get(0x1101);
|
||||
}
|
||||
|
@ -7,7 +7,7 @@
|
||||
|
||||
#include "tlib/io.hpp"
|
||||
|
||||
int64_t ioctl(size_t device, ioctl_request request, void* data){
|
||||
int64_t tlib::ioctl(size_t device, ioctl_request request, void* data){
|
||||
int64_t code;
|
||||
asm volatile("mov rax, 0x2000; mov rbx, %[device]; mov rcx, %[request]; mov rdx, %[data]; int 50; mov %[code], rax"
|
||||
: [code] "=m" (code)
|
||||
|
@ -84,8 +84,8 @@ bool expand_heap(malloc_header_chunk* current, size_t bytes = 0){
|
||||
}
|
||||
|
||||
//Allocate a new block of memory
|
||||
auto old_end = brk_end();
|
||||
auto brk_end = sbrk(blocks * BLOCK_SIZE);
|
||||
auto old_end = tlib::brk_end();
|
||||
auto brk_end = tlib::sbrk(blocks * BLOCK_SIZE);
|
||||
|
||||
if(brk_end == old_end){
|
||||
return false;
|
||||
@ -123,7 +123,7 @@ void init_head(){
|
||||
|
||||
} //end of anonymous namespace
|
||||
|
||||
void* malloc(size_t bytes){
|
||||
void* tlib::malloc(size_t bytes){
|
||||
if(unlikely(!init)){
|
||||
init_head();
|
||||
}
|
||||
@ -191,7 +191,7 @@ void* malloc(size_t bytes){
|
||||
return reinterpret_cast<void*>(block_start);
|
||||
}
|
||||
|
||||
void free(void* block){
|
||||
void tlib::free(void* block){
|
||||
auto free_header = reinterpret_cast<malloc_header_chunk*>(
|
||||
reinterpret_cast<uintptr_t>(block) - sizeof(malloc_header_chunk));
|
||||
|
||||
@ -202,7 +202,7 @@ void free(void* block){
|
||||
insert_after(malloc_head, free_header);
|
||||
}
|
||||
|
||||
size_t brk_start(){
|
||||
size_t tlib::brk_start(){
|
||||
size_t value;
|
||||
asm volatile("mov rax, 7; int 50; mov %[brk_start], rax"
|
||||
: [brk_start] "=m" (value)
|
||||
@ -211,7 +211,7 @@ size_t brk_start(){
|
||||
return value;
|
||||
}
|
||||
|
||||
size_t brk_end(){
|
||||
size_t tlib::brk_end(){
|
||||
size_t value;
|
||||
asm volatile("mov rax, 8; int 50; mov %[brk_end], rax"
|
||||
: [brk_end] "=m" (value)
|
||||
@ -220,7 +220,7 @@ size_t brk_end(){
|
||||
return value;
|
||||
}
|
||||
|
||||
size_t sbrk(size_t inc){
|
||||
size_t tlib::sbrk(size_t inc){
|
||||
size_t value;
|
||||
asm volatile("mov rax, 9; mov rbx, %[brk_inc]; int 50; mov %[brk_end], rax"
|
||||
: [brk_end] "=m" (value)
|
||||
@ -230,17 +230,17 @@ size_t sbrk(size_t inc){
|
||||
}
|
||||
|
||||
void* operator new(uint64_t size){
|
||||
return malloc(size);
|
||||
return tlib::malloc(size);
|
||||
}
|
||||
|
||||
void operator delete(void* p){
|
||||
free(p);
|
||||
tlib::free(p);
|
||||
}
|
||||
|
||||
void* operator new[](uint64_t size){
|
||||
return malloc(size);
|
||||
return tlib::malloc(size);
|
||||
}
|
||||
|
||||
void operator delete[](void* p){
|
||||
return free(p);
|
||||
return tlib::free(p);
|
||||
}
|
||||
|
@ -7,7 +7,7 @@
|
||||
|
||||
#include "tlib/net.hpp"
|
||||
|
||||
std::expected<size_t> socket_open(network::socket_domain domain, network::socket_type type, network::socket_protocol protocol){
|
||||
std::expected<size_t> tlib::socket_open(network::socket_domain domain, network::socket_type type, network::socket_protocol protocol){
|
||||
int64_t fd;
|
||||
asm volatile("mov rax, 0x3000; mov rbx, %[type]; mov rcx, %[type]; mov rdx, %[protocol]; int 50; mov %[fd], rax"
|
||||
: [fd] "=m" (fd)
|
||||
@ -21,7 +21,7 @@ std::expected<size_t> socket_open(network::socket_domain domain, network::socket
|
||||
}
|
||||
}
|
||||
|
||||
void socket_close(size_t fd){
|
||||
void tlib::socket_close(size_t fd){
|
||||
asm volatile("mov rax, 0x3001; mov rbx, %[fd]; int 50;"
|
||||
: /* No outputs */
|
||||
: [fd] "g" (fd)
|
||||
|
@ -9,14 +9,14 @@
|
||||
|
||||
#include "tlib/print.hpp"
|
||||
|
||||
void print(char c){
|
||||
void tlib::print(char c){
|
||||
asm volatile("mov rax, 0; mov rbx, %[c]; int 50"
|
||||
: //No outputs
|
||||
: [c] "g" (static_cast<size_t>(c))
|
||||
: "rax", "rbx");
|
||||
}
|
||||
|
||||
void print(const char* s){
|
||||
void tlib::print(const char* s){
|
||||
asm volatile("mov rax, 1; mov rbx, %[s]; int 50"
|
||||
: //No outputs
|
||||
: [s] "g" (reinterpret_cast<size_t>(s))
|
||||
@ -30,39 +30,39 @@ void log(const char* s){
|
||||
: "rax", "rbx");
|
||||
}
|
||||
|
||||
void print(uint8_t v){
|
||||
void tlib::print(uint8_t v){
|
||||
print(std::to_string(v));
|
||||
}
|
||||
|
||||
void print(uint16_t v){
|
||||
void tlib::print(uint16_t v){
|
||||
print(std::to_string(v));
|
||||
}
|
||||
|
||||
void print(uint32_t v){
|
||||
void tlib::print(uint32_t v){
|
||||
print(std::to_string(v));
|
||||
}
|
||||
|
||||
void print(uint64_t v){
|
||||
void tlib::print(uint64_t v){
|
||||
print(std::to_string(v));
|
||||
}
|
||||
|
||||
void print(int8_t v){
|
||||
void tlib::print(int8_t v){
|
||||
print(std::to_string(v));
|
||||
}
|
||||
|
||||
void print(int16_t v){
|
||||
void tlib::print(int16_t v){
|
||||
print(std::to_string(v));
|
||||
}
|
||||
|
||||
void print(int32_t v){
|
||||
void tlib::print(int32_t v){
|
||||
print(std::to_string(v));
|
||||
}
|
||||
|
||||
void print(int64_t v){
|
||||
void tlib::print(int64_t v){
|
||||
print(std::to_string(v));
|
||||
}
|
||||
|
||||
void set_canonical(bool can){
|
||||
void tlib::set_canonical(bool can){
|
||||
size_t value = can;
|
||||
asm volatile("mov rax, 0x20; mov rbx, %[value]; int 50;"
|
||||
:
|
||||
@ -70,7 +70,7 @@ void set_canonical(bool can){
|
||||
: "rax", "rbx");
|
||||
}
|
||||
|
||||
void set_mouse(bool m){
|
||||
void tlib::set_mouse(bool m){
|
||||
size_t value = m;
|
||||
asm volatile("mov rax, 0x21; mov rbx, %[value]; int 50;"
|
||||
:
|
||||
@ -78,7 +78,7 @@ void set_mouse(bool m){
|
||||
: "rax", "rbx");
|
||||
}
|
||||
|
||||
size_t read_input(char* buffer, size_t max){
|
||||
size_t tlib::read_input(char* buffer, size_t max){
|
||||
size_t value;
|
||||
asm volatile("mov rax, 0x10; mov rbx, %[buffer]; mov rcx, %[max]; int 50; mov %[read], rax"
|
||||
: [read] "=m" (value)
|
||||
@ -87,7 +87,7 @@ size_t read_input(char* buffer, size_t max){
|
||||
return value;
|
||||
}
|
||||
|
||||
size_t read_input(char* buffer, size_t max, size_t ms){
|
||||
size_t tlib::read_input(char* buffer, size_t max, size_t ms){
|
||||
size_t value;
|
||||
asm volatile("mov rax, 0x11; mov rbx, %[buffer]; mov rcx, %[max]; mov rdx, %[ms]; int 50; mov %[read], rax"
|
||||
: [read] "=m" (value)
|
||||
@ -96,7 +96,7 @@ size_t read_input(char* buffer, size_t max, size_t ms){
|
||||
return value;
|
||||
}
|
||||
|
||||
keycode read_input_raw(){
|
||||
keycode tlib::read_input_raw(){
|
||||
size_t value;
|
||||
asm volatile("mov rax, 0x12; int 50; mov %[input], rax"
|
||||
: [input] "=m" (value)
|
||||
@ -105,7 +105,7 @@ keycode read_input_raw(){
|
||||
return static_cast<keycode>(value);
|
||||
}
|
||||
|
||||
keycode read_input_raw(size_t ms){
|
||||
keycode tlib::read_input_raw(size_t ms){
|
||||
size_t value;
|
||||
asm volatile("mov rax, 0x13; mov rbx, %[ms]; int 50; mov %[input], rax"
|
||||
: [input] "=m" (value)
|
||||
@ -114,14 +114,14 @@ keycode read_input_raw(size_t ms){
|
||||
return static_cast<keycode>(value);
|
||||
}
|
||||
|
||||
void clear(){
|
||||
void tlib::clear(){
|
||||
asm volatile("mov rax, 100; int 50;"
|
||||
: //No outputs
|
||||
: //No inputs
|
||||
: "rax");
|
||||
}
|
||||
|
||||
size_t get_columns(){
|
||||
size_t tlib::get_columns(){
|
||||
size_t value;
|
||||
asm volatile("mov rax, 101; int 50; mov %[columns], rax"
|
||||
: [columns] "=m" (value)
|
||||
@ -130,7 +130,7 @@ size_t get_columns(){
|
||||
return value;
|
||||
}
|
||||
|
||||
size_t get_rows(){
|
||||
size_t tlib::get_rows(){
|
||||
size_t value;
|
||||
asm volatile("mov rax, 102; int 50; mov %[rows], rax"
|
||||
: [rows] "=m" (value)
|
||||
@ -139,29 +139,42 @@ size_t get_rows(){
|
||||
return value;
|
||||
}
|
||||
|
||||
void print(const std::string& s){
|
||||
void tlib::print(const std::string& s){
|
||||
return print(s.c_str());
|
||||
}
|
||||
|
||||
void print_line(){
|
||||
void tlib::print_line(){
|
||||
print('\n');
|
||||
}
|
||||
|
||||
void print_line(const char* s){
|
||||
void tlib::print_line(const char* s){
|
||||
print(s);
|
||||
print_line();
|
||||
}
|
||||
|
||||
void print_line(size_t v){
|
||||
void tlib::print_line(size_t v){
|
||||
print(v);
|
||||
print_line();
|
||||
}
|
||||
|
||||
void print_line(const std::string& s){
|
||||
void tlib::print_line(const std::string& s){
|
||||
print(s);
|
||||
print_line();
|
||||
}
|
||||
|
||||
void tlib::user_logf(const char* s, ...){
|
||||
va_list va;
|
||||
va_start(va, s);
|
||||
|
||||
char buffer[512];
|
||||
vsprintf_raw(buffer, 512, s, va);
|
||||
log(buffer);
|
||||
|
||||
va_end(va);
|
||||
}
|
||||
|
||||
namespace tlib {
|
||||
|
||||
#include "printf_def.hpp"
|
||||
|
||||
void __printf(const std::string& formatted){
|
||||
@ -172,13 +185,4 @@ void __printf_raw(const char* formatted){
|
||||
print(formatted);
|
||||
}
|
||||
|
||||
void user_logf(const char* s, ...){
|
||||
va_list va;
|
||||
va_start(va, s);
|
||||
|
||||
char buffer[512];
|
||||
vsprintf_raw(buffer, 512, s, va);
|
||||
log(buffer);
|
||||
|
||||
va_end(va);
|
||||
}
|
||||
} // end of namespace tlib
|
||||
|
@ -15,9 +15,9 @@ extern "C" {
|
||||
uintptr_t __stack_chk_guard = STACK_CHK_GUARD;
|
||||
|
||||
__attribute__((noreturn)) void __stack_chk_fail(){
|
||||
printf("Stack smashing detected \n");
|
||||
tlib::printf("Stack smashing detected \n");
|
||||
//TODO printf("pid=%u\n", scheduler::get_pid());
|
||||
exit(1);
|
||||
tlib::exit(1);
|
||||
}
|
||||
|
||||
}
|
||||
} // end of extern "C"
|
||||
|
@ -32,7 +32,7 @@ void _start(int argc, char* argv[]){
|
||||
__cxa_finalize(nullptr);
|
||||
|
||||
// Kill the process with the correct exit code
|
||||
exit(code);
|
||||
tlib::exit(code);
|
||||
}
|
||||
|
||||
#define ATEXIT_MAX_FUNCS 32
|
||||
|
@ -20,7 +20,7 @@ uint64_t syscall_get(uint64_t call){
|
||||
|
||||
} // end of anonymous namespace
|
||||
|
||||
void exit(size_t return_code) {
|
||||
void tlib::exit(size_t return_code) {
|
||||
asm volatile("mov rax, 0x666; mov rbx, %[ret]; int 50"
|
||||
: //No outputs
|
||||
: [ret] "g" (return_code)
|
||||
@ -29,7 +29,7 @@ void exit(size_t return_code) {
|
||||
__builtin_unreachable();
|
||||
}
|
||||
|
||||
std::expected<size_t> exec(const char* executable, const std::vector<std::string>& params){
|
||||
std::expected<size_t> tlib::exec(const char* executable, const std::vector<std::string>& params){
|
||||
const char** args = nullptr;
|
||||
if(!params.empty()){
|
||||
args = new const char*[params.size()];
|
||||
@ -56,22 +56,22 @@ std::expected<size_t> exec(const char* executable, const std::vector<std::string
|
||||
}
|
||||
}
|
||||
|
||||
void await_termination(size_t pid) {
|
||||
void tlib::await_termination(size_t pid) {
|
||||
asm volatile("mov rax, 6; mov rbx, %[pid]; int 50;"
|
||||
: //No outputs
|
||||
: [pid] "g" (pid)
|
||||
: "rax", "rbx");
|
||||
}
|
||||
|
||||
void sleep_ms(size_t ms){
|
||||
void tlib::sleep_ms(size_t ms){
|
||||
asm volatile("mov rax, 4; mov rbx, %[ms]; int 50"
|
||||
: //No outputs
|
||||
: [ms] "g" (ms)
|
||||
: "rax", "rbx");
|
||||
}
|
||||
|
||||
datetime local_date(){
|
||||
datetime date_s;
|
||||
tlib::datetime tlib::local_date(){
|
||||
tlib::datetime date_s;
|
||||
|
||||
asm volatile("mov rax, 0x400; mov rbx, %[buffer]; int 50; "
|
||||
: /* No outputs */
|
||||
@ -81,15 +81,15 @@ datetime local_date(){
|
||||
return date_s;
|
||||
}
|
||||
|
||||
uint64_t s_time(){
|
||||
uint64_t tlib::s_time(){
|
||||
return syscall_get(0x401);
|
||||
}
|
||||
|
||||
uint64_t ms_time(){
|
||||
uint64_t tlib::ms_time(){
|
||||
return syscall_get(0x402);
|
||||
}
|
||||
|
||||
std::expected<size_t> exec_and_wait(const char* executable, const std::vector<std::string>& params){
|
||||
std::expected<size_t> tlib::exec_and_wait(const char* executable, const std::vector<std::string>& params){
|
||||
auto result = exec(executable, params);
|
||||
|
||||
if(result.valid()){
|
||||
@ -99,7 +99,7 @@ std::expected<size_t> exec_and_wait(const char* executable, const std::vector<st
|
||||
return std::move(result);
|
||||
}
|
||||
|
||||
void reboot(){
|
||||
void tlib::reboot(){
|
||||
asm volatile("mov rax, 201; int 50"
|
||||
: //No outputs
|
||||
: //No inputs
|
||||
@ -108,7 +108,7 @@ void reboot(){
|
||||
__builtin_unreachable();
|
||||
}
|
||||
|
||||
void shutdown(){
|
||||
void tlib::shutdown(){
|
||||
asm volatile("mov rax, 202; int 50"
|
||||
: //No outputs
|
||||
: //No inputs
|
||||
@ -117,7 +117,7 @@ void shutdown(){
|
||||
__builtin_unreachable();
|
||||
}
|
||||
|
||||
void alpha(){
|
||||
void tlib::alpha(){
|
||||
asm volatile("mov rax, 0x6666; int 50"
|
||||
: //No outputs
|
||||
: //No inputs
|
||||
|
Loading…
x
Reference in New Issue
Block a user