mirror of
https://github.com/wichtounet/thor-os.git
synced 2025-09-17 16:51:33 -04:00
Review print
This commit is contained in:
parent
c275c37abd
commit
af76d47f50
@ -34,33 +34,4 @@ void wipeout();
|
|||||||
|
|
||||||
} // end of namespace console
|
} // end of namespace console
|
||||||
|
|
||||||
void k_print(char key);
|
|
||||||
void k_print(const char* string);
|
|
||||||
void k_print(const char* string, uint64_t end);
|
|
||||||
|
|
||||||
void k_print(const std::string& s);
|
|
||||||
|
|
||||||
void k_print(uint8_t number);
|
|
||||||
void k_print(uint16_t number);
|
|
||||||
void k_print(uint32_t number);
|
|
||||||
void k_print(uint64_t number);
|
|
||||||
|
|
||||||
void k_print(int8_t number);
|
|
||||||
void k_print(int16_t number);
|
|
||||||
void k_print(int32_t number);
|
|
||||||
void k_print(int64_t number);
|
|
||||||
|
|
||||||
template<typename... Arguments>
|
|
||||||
typename std::enable_if_t<(sizeof...(Arguments) == 0)> k_print_line(const Arguments&... args){
|
|
||||||
k_print('\n');
|
|
||||||
}
|
|
||||||
|
|
||||||
template<typename... Arguments>
|
|
||||||
typename std::enable_if_t<(sizeof...(Arguments) > 0)> k_print_line(const Arguments&... args){
|
|
||||||
k_print(args...);
|
|
||||||
k_print('\n');
|
|
||||||
}
|
|
||||||
|
|
||||||
#include "printf_dec.hpp"
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
46
kernel/include/print.hpp
Normal file
46
kernel/include/print.hpp
Normal file
@ -0,0 +1,46 @@
|
|||||||
|
//=======================================================================
|
||||||
|
// Copyright Baptiste Wicht 2013-2016.
|
||||||
|
// Distributed under the terms of the MIT License.
|
||||||
|
// (See accompanying file LICENSE or copy at
|
||||||
|
// http://www.opensource.org/licenses/MIT)
|
||||||
|
//=======================================================================
|
||||||
|
|
||||||
|
#ifndef PRINT_H
|
||||||
|
#define PRINT_H
|
||||||
|
|
||||||
|
#include <stdarg.h>
|
||||||
|
|
||||||
|
#include <types.hpp>
|
||||||
|
#include <enable_if.hpp>
|
||||||
|
#include <string.hpp>
|
||||||
|
|
||||||
|
void k_print(char key);
|
||||||
|
void k_print(const char* string);
|
||||||
|
void k_print(const char* string, uint64_t end);
|
||||||
|
|
||||||
|
void k_print(const std::string& s);
|
||||||
|
|
||||||
|
void k_print(uint8_t number);
|
||||||
|
void k_print(uint16_t number);
|
||||||
|
void k_print(uint32_t number);
|
||||||
|
void k_print(uint64_t number);
|
||||||
|
|
||||||
|
void k_print(int8_t number);
|
||||||
|
void k_print(int16_t number);
|
||||||
|
void k_print(int32_t number);
|
||||||
|
void k_print(int64_t number);
|
||||||
|
|
||||||
|
template<typename... Arguments>
|
||||||
|
typename std::enable_if_t<(sizeof...(Arguments) == 0)> k_print_line(const Arguments&... args){
|
||||||
|
k_print('\n');
|
||||||
|
}
|
||||||
|
|
||||||
|
template<typename... Arguments>
|
||||||
|
typename std::enable_if_t<(sizeof...(Arguments) > 0)> k_print_line(const Arguments&... args){
|
||||||
|
k_print(args...);
|
||||||
|
k_print('\n');
|
||||||
|
}
|
||||||
|
|
||||||
|
#include "printf_dec.hpp"
|
||||||
|
|
||||||
|
#endif
|
@ -10,7 +10,7 @@
|
|||||||
#include "kernel_utils.hpp"
|
#include "kernel_utils.hpp"
|
||||||
#include "timer.hpp"
|
#include "timer.hpp"
|
||||||
#include "paging.hpp"
|
#include "paging.hpp"
|
||||||
#include "console.hpp"
|
#include "print.hpp"
|
||||||
#include "logging.hpp"
|
#include "logging.hpp"
|
||||||
#include "scheduler.hpp"
|
#include "scheduler.hpp"
|
||||||
#include "arch.hpp"
|
#include "arch.hpp"
|
||||||
|
@ -6,7 +6,7 @@
|
|||||||
//=======================================================================
|
//=======================================================================
|
||||||
|
|
||||||
#include "assert.hpp"
|
#include "assert.hpp"
|
||||||
#include "console.hpp"
|
#include "print.hpp"
|
||||||
#include "kernel.hpp"
|
#include "kernel.hpp"
|
||||||
#include "logging.hpp"
|
#include "logging.hpp"
|
||||||
|
|
||||||
|
@ -50,38 +50,6 @@ void print_char(size_t line, size_t column, char c){
|
|||||||
volatile size_t current_line = 0;
|
volatile size_t current_line = 0;
|
||||||
volatile size_t current_column = 0;
|
volatile size_t current_column = 0;
|
||||||
|
|
||||||
template<int B, typename D>
|
|
||||||
void print_unsigned(D number){
|
|
||||||
if(number == 0){
|
|
||||||
k_print('0');
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
char buffer[B];
|
|
||||||
int i = 0;
|
|
||||||
|
|
||||||
while(number != 0){
|
|
||||||
buffer[i++] = '0' + number % 10;
|
|
||||||
number /= 10;
|
|
||||||
}
|
|
||||||
|
|
||||||
--i;
|
|
||||||
|
|
||||||
for(; i >= 0; --i){
|
|
||||||
k_print(buffer[i]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
template<int B, typename U, typename D>
|
|
||||||
void print_signed(D number){
|
|
||||||
if(number < 0){
|
|
||||||
k_print('-');
|
|
||||||
print_unsigned<B>(static_cast<U>(-1 * number));
|
|
||||||
} else {
|
|
||||||
print_unsigned<B>(static_cast<U>(number));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void next_line(){
|
void next_line(){
|
||||||
++current_line;
|
++current_line;
|
||||||
|
|
||||||
@ -178,84 +146,24 @@ void console::wipeout(){
|
|||||||
current_column = 0;
|
current_column = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
void k_print(uint8_t number){
|
//void k_print(char key){
|
||||||
print_unsigned<3>(number);
|
//if(key == '\n'){
|
||||||
}
|
//next_line();
|
||||||
|
//} else if(key == '\r'){
|
||||||
|
//// Ignore \r for now
|
||||||
|
//} else if(key == '\b'){
|
||||||
|
//--current_column;
|
||||||
|
//k_print(' ');
|
||||||
|
//--current_column;
|
||||||
|
//} else if(key == '\t'){
|
||||||
|
//k_print(" ");
|
||||||
|
//} else {
|
||||||
|
//print_char(current_line, current_column, key);
|
||||||
|
|
||||||
void k_print(uint16_t number){
|
//++current_column;
|
||||||
print_unsigned<5>(number);
|
|
||||||
}
|
|
||||||
|
|
||||||
void k_print(uint32_t number){
|
//if(current_column == console::get_columns()){
|
||||||
print_unsigned<10>(number);
|
//next_line();
|
||||||
}
|
//}
|
||||||
|
//}
|
||||||
void k_print(uint64_t number){
|
//}
|
||||||
print_unsigned<20>(number);
|
|
||||||
}
|
|
||||||
|
|
||||||
void k_print(int8_t number){
|
|
||||||
print_signed<3,uint8_t>(number);
|
|
||||||
}
|
|
||||||
|
|
||||||
void k_print(int16_t number){
|
|
||||||
print_signed<5,uint16_t>(number);
|
|
||||||
}
|
|
||||||
|
|
||||||
void k_print(int32_t number){
|
|
||||||
print_signed<10,uint32_t>(number);
|
|
||||||
}
|
|
||||||
|
|
||||||
void k_print(int64_t number){
|
|
||||||
print_signed<20,uint64_t,int64_t>(number);
|
|
||||||
}
|
|
||||||
|
|
||||||
void k_print(char key){
|
|
||||||
if(key == '\n'){
|
|
||||||
next_line();
|
|
||||||
} else if(key == '\r'){
|
|
||||||
// Ignore \r for now
|
|
||||||
} else if(key == '\b'){
|
|
||||||
--current_column;
|
|
||||||
k_print(' ');
|
|
||||||
--current_column;
|
|
||||||
} else if(key == '\t'){
|
|
||||||
k_print(" ");
|
|
||||||
} else {
|
|
||||||
print_char(current_line, current_column, key);
|
|
||||||
|
|
||||||
++current_column;
|
|
||||||
|
|
||||||
if(current_column == console::get_columns()){
|
|
||||||
next_line();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void k_print(const char* str){
|
|
||||||
for(uint64_t i = 0; str[i] != 0; ++i){
|
|
||||||
k_print(str[i]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void k_print(const std::string& s){
|
|
||||||
for(auto c : s){
|
|
||||||
k_print(c);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void k_print(const char* str, uint64_t end){
|
|
||||||
for(uint64_t i = 0; i < end && str[i] != 0; ++i){
|
|
||||||
k_print(str[i]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#include "printf_def.hpp"
|
|
||||||
|
|
||||||
void __printf(const std::string& str){
|
|
||||||
k_print(str);
|
|
||||||
}
|
|
||||||
|
|
||||||
void __printf_raw(const char* str){
|
|
||||||
k_print(str);
|
|
||||||
}
|
|
||||||
|
@ -11,7 +11,7 @@
|
|||||||
|
|
||||||
#include "disks.hpp"
|
#include "disks.hpp"
|
||||||
#include "thor.hpp"
|
#include "thor.hpp"
|
||||||
#include "console.hpp"
|
#include "print.hpp"
|
||||||
#include "logging.hpp"
|
#include "logging.hpp"
|
||||||
|
|
||||||
// The disks implementation
|
// The disks implementation
|
||||||
|
@ -8,7 +8,7 @@
|
|||||||
#include <types.hpp>
|
#include <types.hpp>
|
||||||
|
|
||||||
#include "interrupts.hpp"
|
#include "interrupts.hpp"
|
||||||
#include "console.hpp"
|
#include "print.hpp"
|
||||||
#include "kernel_utils.hpp"
|
#include "kernel_utils.hpp"
|
||||||
#include "gdt.hpp"
|
#include "gdt.hpp"
|
||||||
#include "scheduler.hpp"
|
#include "scheduler.hpp"
|
||||||
|
@ -6,7 +6,7 @@
|
|||||||
//=======================================================================
|
//=======================================================================
|
||||||
|
|
||||||
#include "kalloc.hpp"
|
#include "kalloc.hpp"
|
||||||
#include "console.hpp"
|
#include "print.hpp"
|
||||||
#include "physical_allocator.hpp"
|
#include "physical_allocator.hpp"
|
||||||
#include "paging.hpp"
|
#include "paging.hpp"
|
||||||
#include "e820.hpp"
|
#include "e820.hpp"
|
||||||
|
@ -22,6 +22,7 @@
|
|||||||
#include "arch.hpp"
|
#include "arch.hpp"
|
||||||
#include "vesa.hpp"
|
#include "vesa.hpp"
|
||||||
#include "console.hpp"
|
#include "console.hpp"
|
||||||
|
#include "print.hpp"
|
||||||
#include "gdt.hpp"
|
#include "gdt.hpp"
|
||||||
#include "stdio.hpp"
|
#include "stdio.hpp"
|
||||||
#include "scheduler.hpp"
|
#include "scheduler.hpp"
|
||||||
|
@ -6,7 +6,7 @@
|
|||||||
//=======================================================================
|
//=======================================================================
|
||||||
|
|
||||||
#include "kernel_utils.hpp"
|
#include "kernel_utils.hpp"
|
||||||
#include "console.hpp"
|
#include "print.hpp"
|
||||||
|
|
||||||
void print_stack(const char* s, size_t check){
|
void print_stack(const char* s, size_t check){
|
||||||
printf("%s stack: %u (16B-a:%u) \n", s, check, static_cast<size_t>(check % 16));
|
printf("%s stack: %u (16B-a:%u) \n", s, check, static_cast<size_t>(check % 16));
|
||||||
|
@ -11,7 +11,7 @@
|
|||||||
|
|
||||||
#include "logging.hpp"
|
#include "logging.hpp"
|
||||||
#include "assert.hpp"
|
#include "assert.hpp"
|
||||||
#include "console.hpp"
|
#include "print.hpp"
|
||||||
#include "virtual_debug.hpp"
|
#include "virtual_debug.hpp"
|
||||||
#include "early_memory.hpp"
|
#include "early_memory.hpp"
|
||||||
#include "vfs/vfs.hpp"
|
#include "vfs/vfs.hpp"
|
||||||
|
@ -12,7 +12,7 @@
|
|||||||
#include "paging.hpp"
|
#include "paging.hpp"
|
||||||
#include "kernel.hpp"
|
#include "kernel.hpp"
|
||||||
#include "physical_allocator.hpp"
|
#include "physical_allocator.hpp"
|
||||||
#include "console.hpp"
|
#include "print.hpp"
|
||||||
#include "assert.hpp"
|
#include "assert.hpp"
|
||||||
#include "process.hpp"
|
#include "process.hpp"
|
||||||
#include "physical_pointer.hpp"
|
#include "physical_pointer.hpp"
|
||||||
|
@ -17,7 +17,7 @@
|
|||||||
|
|
||||||
//For problems during boot
|
//For problems during boot
|
||||||
#include "kernel.hpp"
|
#include "kernel.hpp"
|
||||||
#include "console.hpp"
|
#include "print.hpp"
|
||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
|
|
||||||
|
114
kernel/src/print.cpp
Normal file
114
kernel/src/print.cpp
Normal file
@ -0,0 +1,114 @@
|
|||||||
|
//=======================================================================
|
||||||
|
// Copyright Baptiste Wicht 2013-2016.
|
||||||
|
// Distributed under the terms of the MIT License.
|
||||||
|
// (See accompanying file LICENSE or copy at
|
||||||
|
// http://www.opensource.org/licenses/MIT)
|
||||||
|
//=======================================================================
|
||||||
|
|
||||||
|
#include <stdarg.h>
|
||||||
|
|
||||||
|
#include <types.hpp>
|
||||||
|
#include <string.hpp>
|
||||||
|
|
||||||
|
#include "print.hpp"
|
||||||
|
#include "stdio.hpp"
|
||||||
|
|
||||||
|
namespace {
|
||||||
|
|
||||||
|
template<int B, typename D>
|
||||||
|
void print_unsigned(D number){
|
||||||
|
if(number == 0){
|
||||||
|
k_print('0');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
char buffer[B];
|
||||||
|
int i = 0;
|
||||||
|
|
||||||
|
while(number != 0){
|
||||||
|
buffer[i++] = '0' + number % 10;
|
||||||
|
number /= 10;
|
||||||
|
}
|
||||||
|
|
||||||
|
--i;
|
||||||
|
|
||||||
|
for(; i >= 0; --i){
|
||||||
|
k_print(buffer[i]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
template<int B, typename U, typename D>
|
||||||
|
void print_signed(D number){
|
||||||
|
if(number < 0){
|
||||||
|
k_print('-');
|
||||||
|
print_unsigned<B>(static_cast<U>(-1 * number));
|
||||||
|
} else {
|
||||||
|
print_unsigned<B>(static_cast<U>(number));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
} // end of anonymous namespace
|
||||||
|
|
||||||
|
void k_print(uint8_t number){
|
||||||
|
print_unsigned<3>(number);
|
||||||
|
}
|
||||||
|
|
||||||
|
void k_print(uint16_t number){
|
||||||
|
print_unsigned<5>(number);
|
||||||
|
}
|
||||||
|
|
||||||
|
void k_print(uint32_t number){
|
||||||
|
print_unsigned<10>(number);
|
||||||
|
}
|
||||||
|
|
||||||
|
void k_print(uint64_t number){
|
||||||
|
print_unsigned<20>(number);
|
||||||
|
}
|
||||||
|
|
||||||
|
void k_print(int8_t number){
|
||||||
|
print_signed<3,uint8_t>(number);
|
||||||
|
}
|
||||||
|
|
||||||
|
void k_print(int16_t number){
|
||||||
|
print_signed<5,uint16_t>(number);
|
||||||
|
}
|
||||||
|
|
||||||
|
void k_print(int32_t number){
|
||||||
|
print_signed<10,uint32_t>(number);
|
||||||
|
}
|
||||||
|
|
||||||
|
void k_print(int64_t number){
|
||||||
|
print_signed<20,uint64_t,int64_t>(number);
|
||||||
|
}
|
||||||
|
|
||||||
|
void k_print(char key){
|
||||||
|
stdio::get_active_terminal().print(key);
|
||||||
|
}
|
||||||
|
|
||||||
|
void k_print(const char* str){
|
||||||
|
for(uint64_t i = 0; str[i] != 0; ++i){
|
||||||
|
k_print(str[i]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void k_print(const std::string& s){
|
||||||
|
for(auto c : s){
|
||||||
|
k_print(c);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void k_print(const char* str, uint64_t end){
|
||||||
|
for(uint64_t i = 0; i < end && str[i] != 0; ++i){
|
||||||
|
k_print(str[i]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#include "printf_def.hpp"
|
||||||
|
|
||||||
|
void __printf(const std::string& str){
|
||||||
|
k_print(str);
|
||||||
|
}
|
||||||
|
|
||||||
|
void __printf_raw(const char* str){
|
||||||
|
k_print(str);
|
||||||
|
}
|
@ -22,7 +22,7 @@
|
|||||||
#include "gdt.hpp"
|
#include "gdt.hpp"
|
||||||
#include "stdio.hpp"
|
#include "stdio.hpp"
|
||||||
#include "disks.hpp"
|
#include "disks.hpp"
|
||||||
#include "console.hpp"
|
#include "print.hpp"
|
||||||
#include "physical_allocator.hpp"
|
#include "physical_allocator.hpp"
|
||||||
#include "virtual_allocator.hpp"
|
#include "virtual_allocator.hpp"
|
||||||
#include "physical_pointer.hpp"
|
#include "physical_pointer.hpp"
|
||||||
|
@ -7,6 +7,7 @@
|
|||||||
|
|
||||||
#include "system_calls.hpp"
|
#include "system_calls.hpp"
|
||||||
#include "console.hpp"
|
#include "console.hpp"
|
||||||
|
#include "print.hpp"
|
||||||
#include "scheduler.hpp"
|
#include "scheduler.hpp"
|
||||||
#include "timer.hpp"
|
#include "timer.hpp"
|
||||||
#include "drivers/keyboard.hpp"
|
#include "drivers/keyboard.hpp"
|
||||||
|
@ -15,6 +15,8 @@
|
|||||||
#include "logging.hpp"
|
#include "logging.hpp"
|
||||||
#include "scheduler.hpp"
|
#include "scheduler.hpp"
|
||||||
|
|
||||||
|
#include "print.hpp"
|
||||||
|
|
||||||
void stdio::virtual_terminal::print(char key){
|
void stdio::virtual_terminal::print(char key){
|
||||||
//TODO If it is not the active terminal, buffer it
|
//TODO If it is not the active terminal, buffer it
|
||||||
k_print(key);
|
k_print(key);
|
||||||
|
@ -9,7 +9,7 @@
|
|||||||
#include "kalloc.hpp"
|
#include "kalloc.hpp"
|
||||||
#include "scheduler.hpp"
|
#include "scheduler.hpp"
|
||||||
#include "logging.hpp"
|
#include "logging.hpp"
|
||||||
#include "console.hpp"
|
#include "print.hpp"
|
||||||
|
|
||||||
void* operator new(uint64_t size){
|
void* operator new(uint64_t size){
|
||||||
return kalloc::k_malloc(size);
|
return kalloc::k_malloc(size);
|
||||||
|
@ -16,7 +16,7 @@
|
|||||||
#include "acpica.hpp"
|
#include "acpica.hpp"
|
||||||
|
|
||||||
#include "kalloc.hpp"
|
#include "kalloc.hpp"
|
||||||
#include "console.hpp"
|
#include "print.hpp"
|
||||||
#include "scheduler.hpp"
|
#include "scheduler.hpp"
|
||||||
#include "virtual_allocator.hpp"
|
#include "virtual_allocator.hpp"
|
||||||
#include "paging.hpp"
|
#include "paging.hpp"
|
||||||
|
Loading…
x
Reference in New Issue
Block a user