mirror of
https://github.com/wichtounet/thor-os.git
synced 2025-09-18 09:04:49 -04:00
Add new printf mode: memory operand
This commit is contained in:
parent
28492e7bb4
commit
2cfcfc4799
@ -169,6 +169,7 @@ void k_printf(const char* fmt, ...){
|
|||||||
|
|
||||||
auto prev = current_column;
|
auto prev = current_column;
|
||||||
|
|
||||||
|
//Decimal
|
||||||
if(ch == 'd'){
|
if(ch == 'd'){
|
||||||
auto arg = va_arg(va, std::size_t);
|
auto arg = va_arg(va, std::size_t);
|
||||||
|
|
||||||
@ -186,7 +187,9 @@ void k_printf(const char* fmt, ...){
|
|||||||
}
|
}
|
||||||
|
|
||||||
k_print(arg);
|
k_print(arg);
|
||||||
} else if(ch == 'h'){
|
}
|
||||||
|
//Hexadecimal
|
||||||
|
else if(ch == 'h'){
|
||||||
k_print("0x");
|
k_print("0x");
|
||||||
|
|
||||||
uint8_t buffer[20];
|
uint8_t buffer[20];
|
||||||
@ -239,7 +242,27 @@ void k_printf(const char* fmt, ...){
|
|||||||
|
|
||||||
--i;
|
--i;
|
||||||
}
|
}
|
||||||
} else if(ch == 's'){
|
}
|
||||||
|
//Memory
|
||||||
|
else if(ch == 'm'){
|
||||||
|
auto memory= va_arg(va, std::size_t);
|
||||||
|
|
||||||
|
if(memory > 1024 * 1024 * 1024){
|
||||||
|
k_print(memory / (1024 * 1024 * 1024));
|
||||||
|
k_print("GiB");
|
||||||
|
} else if(memory > 1024 * 1024){
|
||||||
|
k_print(memory / (1024 * 1024));
|
||||||
|
k_print("MiB");
|
||||||
|
} else if(memory > 1024){
|
||||||
|
k_print(memory / 1024);
|
||||||
|
k_print("KiB");
|
||||||
|
} else {
|
||||||
|
k_print(memory);
|
||||||
|
k_print("B");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
//String
|
||||||
|
else if(ch == 's'){
|
||||||
auto arg = va_arg(va, const char*);
|
auto arg = va_arg(va, const char*);
|
||||||
k_print(arg);
|
k_print(arg);
|
||||||
}
|
}
|
||||||
|
@ -245,31 +245,19 @@ void mmap_command(const char*){
|
|||||||
for(std::size_t i = 0; i < mmap_entry_count(); ++i){
|
for(std::size_t i = 0; i < mmap_entry_count(); ++i){
|
||||||
auto& entry = mmap_entry(i);
|
auto& entry = mmap_entry(i);
|
||||||
|
|
||||||
k_printf("%.10h %.10h %.10h %.10d %s\n",
|
k_printf("%.10h %.10h %.10h %8m %s\n",
|
||||||
entry.base, entry.base + entry.size, entry.size, entry.size, str_e820_type(entry.type));
|
entry.base, entry.base + entry.size, entry.size, entry.size, str_e820_type(entry.type));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void print_memory(const char* format, std::size_t memory){
|
|
||||||
if(memory > 1024 * 1024 * 1024){
|
|
||||||
k_printf(format, memory / (1024 * 1024 * 1024), "GiB");
|
|
||||||
} else if(memory > 1024 * 1024){
|
|
||||||
k_printf(format, memory / (1024 * 1024), "MiB");
|
|
||||||
} else if(memory > 1024){
|
|
||||||
k_printf(format, memory / 1024, "KiB");
|
|
||||||
} else {
|
|
||||||
k_printf(format, memory, "B");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void memory_command(const char*){
|
void memory_command(const char*){
|
||||||
if(mmap_failed()){
|
if(mmap_failed()){
|
||||||
k_print_line("The mmap was not correctly loaded from e820");
|
k_print_line("The mmap was not correctly loaded from e820");
|
||||||
} else {
|
} else {
|
||||||
print_memory("Total available memory: %d%s\n", available_memory());
|
k_printf("Total available memory: %m\n", available_memory());
|
||||||
print_memory("Total used memory: %d%s\n", used_memory());
|
k_printf("Total used memory: %m\n", used_memory());
|
||||||
print_memory("Total free memory: %d%s\n", free_memory());
|
k_printf("Total free memory: %m\n", free_memory());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user