Userspace logging

This commit is contained in:
Baptiste Wicht 2016-08-18 21:17:47 +02:00
parent 12d02aa47f
commit 2cd81f7652
4 changed files with 31 additions and 0 deletions

View File

@ -31,6 +31,11 @@ void sc_print_string(interrupt::syscall_regs* regs){
k_print(reinterpret_cast<const char*>(regs->rbx));
}
void sc_log_string(interrupt::syscall_regs* regs){
auto m = reinterpret_cast<const char*>(regs->rbx);
logging::logf(logging::log_level::USER, "%s\n", m);
}
void sc_get_input(interrupt::syscall_regs* regs){
auto ttyid = scheduler::get_process(scheduler::get_pid()).tty;
auto& tty = stdio::get_terminal(ttyid);
@ -336,6 +341,10 @@ void system_call_entry(interrupt::syscall_regs* regs){
sc_print_string(regs);
break;
case 2:
sc_log_string(regs);
break;
case 4:
sc_sleep_ms(regs);
break;

View File

@ -80,6 +80,8 @@ void stdio::virtual_terminal::send_input(char key){
if(!input_queue.empty()){
input_queue.wake_up();
}
thor_assert(!raw_buffer.full(), "raw buffer is full!");
}
}

View File

@ -50,4 +50,6 @@ size_t get_rows();
#include "printf_dec.hpp"
void user_logf(const char* s, ...);
#endif

View File

@ -23,6 +23,13 @@ void print(const char* s){
: "rax", "rbx");
}
void log(const char* s){
asm volatile("mov rax, 2; mov rbx, %[s]; int 50"
: //No outputs
: [s] "g" (reinterpret_cast<size_t>(s))
: "rax", "rbx");
}
void print(uint8_t v){
print(std::to_string(v));
}
@ -156,3 +163,14 @@ void __printf(const std::string& formatted){
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);
}