diff --git a/arch/x86_64/addr_space.cpp b/arch/x86_64/addr_space.cpp index aed518d..a66754e 100644 --- a/arch/x86_64/addr_space.cpp +++ b/arch/x86_64/addr_space.cpp @@ -52,8 +52,10 @@ AddrSpace::AddrSpace() /* Create a new address space by allocating * a fresh Page Map Level 4 */ m_pml4 = PageMap::get().alloc(); - updateKernelMappings(); + + debug(VSPACE) << "allocated new virtual address space (PML4 @ " + << PPN_TO_PTR(m_pml4) << ")\n"; } AddrSpace* AddrSpace::clone() @@ -89,6 +91,9 @@ AddrSpace* AddrSpace::clone() pageMap.addRef(pml4_old[i].ppn); } + debug(VSPACE) << "cloned address space with cow-semantics (PML4 @ " + << PPN_TO_PTR(m_pml4) << ")\n"; + /* it's important that the TLB will be flushed after setting all * the tables readonly by calling apply(). */ this->apply(); @@ -100,26 +105,24 @@ void AddrSpace::setup() assert(sizeof(GenericPagingTable) == 8); /* Create a new virtual address space for the kernel */ - debug() << "allocating kernel virtual address space\n"; auto kernelSpace = new (&s_kernelAddrSpace) AddrSpace(); /* map the whole physical memory to the upper half */ - debug() << "mapping physical memory to the upper half..."; + debug(VSPACE) << "mapping physical memory to the upper half...\n"; const size_t totalPages = PageMap::get().getTotalPageCount(); const size_t ident_page_offset = IDENT_OFFSET >> PAGE_SHIFT; for (size_t page = 0; page < totalPages; page++) kernelSpace->map(page + ident_page_offset, page, MAP_WRITE); - debug() << " done\n"; /* Enable support for NX pages */ s_nxEnabled = enable_nx(); - debug() << "trying to enable NX: " + debug(VSPACE) << "trying to enable NX: " << (s_nxEnabled ? "ok\n" : "not available\n"); /* Switch to the newly created address space. */ kernelSpace->apply(); s_initialized = true; - debug() << "successfully written %cr3\n"; + debug(VSPACE) << "successfully written %cr3\n"; } AddrSpace &AddrSpace::kernel() @@ -212,6 +215,9 @@ void AddrSpace::map(size_t virt, size_t phys, int flags) currentTablePPN = currentLevelTableEntry.ppn; } + + //debug(VSPACE) << PPN_TO_PTR(virt) << " -> " PPN_TO_PTR(phys) + // << " (PML4 @ " << PPN_TO_PTR(m_pml4) << ")\n"; } void AddrSpace::unmap(size_t virt) @@ -260,9 +266,6 @@ bool AddrSpace::triggerCow(size_t virt) indices[1] = (virt >> 9) & 0x1ff; indices[0] = (virt) & 0x1ff; - debug() << "COW triggered for addr " - << (void*)(virt << PAGE_SHIFT) << "\n"; - size_t currentTablePpn = m_pml4; for (int level = 3; level >= 0; level--) { @@ -303,6 +306,7 @@ bool AddrSpace::triggerCow(size_t virt) * actual table. That means we must not set any bits * but just copy the page */ memcpy(new_table_ptr, old_table_ptr, PAGE_SIZE); + debug(VSPACE) << "cow: copying page: " << PPN_TO_PTR(virt) << "\n"; } else { @@ -444,7 +448,8 @@ AddrSpace::~AddrSpace() } pageMap.free(m_pml4); - m_pml4 = (size_t)-1; - debug() << "address space deleted\n"; + debug(VSPACE) << "deleted address space (had PML4 @ " + << PPN_TO_PTR(m_pml4) << ")\n"; + m_pml4 = (size_t)-1; } diff --git a/arch/x86_64/context.cpp b/arch/x86_64/context.cpp index d5902d0..2963759 100644 --- a/arch/x86_64/context.cpp +++ b/arch/x86_64/context.cpp @@ -44,14 +44,15 @@ void IrqContext::newKernelCtx() void IrqContext::print() { - debug() << "--- Register dump (x86) ---\n" - << DEBUG_HEX << " rip=" << rip - << ", rsp=" << rsp - << ", err=" << error_id << "\n" - << DEBUG_HEX << " rax=" << rax - << ", rbx=" << rbx - << ", rcx=" << rcx << "\n" - << DEBUG_HEX << " rdx=" << rdx - << ", rdi=" << rdi - << ", rsi=" << rsi << "\n"; + debug(EXCEPT) + << "--- REGISTER DUMP (x86_64) ---\n" + << DEBUG_HEX << " rip=" << rip + << ", rsp=" << rsp + << ", err=" << error_id << "\n" + << DEBUG_HEX << " rax=" << rax + << ", rbx=" << rbx + << ", rcx=" << rcx << "\n" + << DEBUG_HEX << " rdx=" << rdx + << ", rdi=" << rdi + << ", rsi=" << rsi << "\n"; } diff --git a/arch/x86_64/idt.cpp b/arch/x86_64/idt.cpp index c0f0286..28c0fe0 100644 --- a/arch/x86_64/idt.cpp +++ b/arch/x86_64/idt.cpp @@ -33,7 +33,7 @@ static IrqDescriptor g_idt[256]; static void setup_pic() { - debug() << "reconfigure PIC\n"; + debug(BOOT) << "reconfigure PIC\n"; outb(0x20, 0x11); // init PIC1 outb(0xA0, 0x11); // init PIC2 @@ -84,8 +84,6 @@ extern "C" { static void setup_idt() { - debug() << "Setting up interrupt descriptor table\n"; - install_descriptor(0, &irq0, IDT_PRESENT | IDT_SUPV | IDT_GATE, 0); install_descriptor(1, &irq1, IDT_PRESENT | IDT_SUPV | IDT_GATE, 0); install_descriptor(2, &irq2, IDT_PRESENT | IDT_SUPV | IDT_GATE, 0); diff --git a/arch/x86_64/syscall.cpp b/arch/x86_64/syscall.cpp index c1cb96f..29cd78a 100644 --- a/arch/x86_64/syscall.cpp +++ b/arch/x86_64/syscall.cpp @@ -5,15 +5,24 @@ #include #include #include +#include #include "../../kernel/syscall_list.h" +static void invalidSyscall(IrqContext* ctx) +{ + debug(SYSCALL) << "PID " << sched::currentPid() + << ": invalid system call: #" + << ctx->returnValue() << "\n"; +} + void do_syscall(IrqContext* ctx) { /* check for an invalid system call number */ if (ctx->rax >= sizeof(syscalls) / sizeof(void*)) { ctx->rax = -ENOSYS; + invalidSyscall(ctx); return; } @@ -22,6 +31,7 @@ void do_syscall(IrqContext* ctx) if (syscall_addr == nullptr) { ctx->rax = -ENOSYS; + invalidSyscall(ctx); return; } diff --git a/arch/x86_common/interrupt.cpp b/arch/x86_common/interrupt.cpp index 8d8cf54..d56ea07 100644 --- a/arch/x86_common/interrupt.cpp +++ b/arch/x86_common/interrupt.cpp @@ -59,19 +59,20 @@ extern "C" IrqContext* x86_irq_handler(IrqContext* ctx) void* addr = getPageFaultAddr(); sti(); - debug() << "fault: " << addr - << ", present=" << (ctx->error() & PF_PRESENT ? "y" : "n") - << ", user=" << (ctx->error() & PF_USER ? "y" : "n") - << ", write=" << (ctx->error() & PF_WRITE ? "y" : "n") - << ", reserved=" << (ctx->error() & PF_RESERVED ? "y" : "n") - << ", data=" << (ctx->error() & PF_CODE ? "n" : "y") << "\n"; - if (handlePageFault((size_t)addr, (FaultFlags)ctx->error())) { return ctx; } + + debug(PAGEFAULT) + << "fault @ " << addr << ": " + << (ctx->error() & PF_PRESENT ? "protection, " : "non-present, ") + << (ctx->error() & PF_USER ? "user, " : "kernel,") + << (ctx->error() & PF_WRITE ? "write, " : "read, ") + << (ctx->error() & PF_RESERVED ? "reserved, " : "") + << (ctx->error() & PF_CODE ? "code" : "data") << "\n"; } - debug() << "(!!) exception #" << ctx->irq() + debug(EXCEPT) << "(!!) exception #" << ctx->irq() << " (" << strexcept(ctx->irq()) << ")\n"; ctx->print(); diff --git a/arch/x86_common/pagemap.cpp b/arch/x86_common/pagemap.cpp index 98049b0..baf2f2b 100644 --- a/arch/x86_common/pagemap.cpp +++ b/arch/x86_common/pagemap.cpp @@ -71,28 +71,29 @@ static const char* get_mmap_type_str(uint32_t type) static void print_mmap_entry(stivale_mmap_entry& entry) { - debug() << " " << DEBUG_HEX - << entry.base << " - " << (entry.base + entry.length - 1) - << ": " << get_mmap_type_str(entry.type) << "\n"; + debug(MEMORY) + << " " << DEBUG_HEX + << entry.base << " - " << (entry.base + entry.length - 1) + << ": " << get_mmap_type_str(entry.type) << "\n"; } void create_page_bitmap() { /* Compute total RAM size */ const auto total_pages = getSystemPageCount(); - debug() << "Total RAM size: " << (total_pages >> 8) << "MB (" + debug(MEMORY) << "Total RAM size: " << (total_pages >> 8) << "MB (" << total_pages << " page frames)\n"; /* Compute the amount of pages needed to store the page refcounter */ size_t pagemap_pages = total_pages >> PAGE_SHIFT; if (total_pages % PAGE_SIZE != 0) pagemap_pages++; - debug() << "PageMap: ref counter size: ~" << (total_pages >> 10) << "KB\n"; + debug(MEMORY) << "PageMap: ref counter size: ~" << (total_pages >> 10) << "KB\n"; /* Get a memory location to store the page bitmap */ const size_t pagemap_start_page = getFirstNFreePages(pagemap_pages); const auto pagemap = (uint8_t*)PPN_TO_VIRT(pagemap_start_page); - debug() << "PageMap: stored at " << (void*)pagemap << "\n"; + debug(MEMORY) << "PageMap: stored at " << (void*)pagemap << "\n"; /* Set initial refcount for all pages to 0xff (max) */ memset(pagemap, 0xff, total_pages); @@ -128,6 +129,6 @@ void create_page_bitmap() /* Initialize the PageManager class */ new (&s_pagemap) PageMap(total_pages, free_pages, usable_pages, pagemap); - debug() << "Usable RAM: " << (free_pages >> 8) + debug(MEMORY) << "Usable RAM: " << (free_pages >> 8) << "/" << (total_pages >> 8) << " MB\n"; } diff --git a/arch/x86_common/start.cpp b/arch/x86_common/start.cpp index 13a97d2..02272d5 100644 --- a/arch/x86_common/start.cpp +++ b/arch/x86_common/start.cpp @@ -58,18 +58,18 @@ extern "C" void _NORETURN _start(struct stivale_struct *stivale) debug_init(); s_stivale = stivale; - debug() << "Hello, world!\n"; + debug(BOOT) << "Hello, world!\n"; /* Load our own Global Descriptor Table */ - debug() << "Setting up Global Descriptor Table ..."; + debug(BOOT) << "Setup: Global Descriptor Table\n"; setup_gdt(); - debug() << " done\n"; /* Create a map of free pages from the stivale * memory map. */ create_page_bitmap(); /* Load an interrupt descriptor table */ + debug(BOOT) << "Setup: Interrupt Descriptor Table\n"; x86_irq_init(); /* Create the kernel virtual memory address space and @@ -79,7 +79,7 @@ extern "C" void _NORETURN _start(struct stivale_struct *stivale) /* enable SSE and AVX if available */ s_sseEnabled = sse_enable(); - debug() << "trying to enable SSE: " + debug(BOOT) << "trying to enable SSE: " << (s_sseEnabled ? "ok\n" : "not available\n"); s_sseEnabled = sse_enable(); diff --git a/kernel/boot.cpp b/kernel/boot.cpp index 0c0c38e..ae05f1d 100644 --- a/kernel/boot.cpp +++ b/kernel/boot.cpp @@ -14,11 +14,11 @@ static void printIssue() { - debug() << "Koerix OS kernel\n" + debug(BOOT) << "Koerix OS kernel\n" "Copyright (C) 2017-2021 Alexander Ulmer\n"; auto& pagemap = PageMap::get(); - debug() << "Memory: " << (pagemap.getUsedMemory() >> 20) << "/" + debug(BOOT) << "Memory: " << (pagemap.getUsedMemory() >> 20) << "/" << (pagemap.getUsableMemory() >> 20) << " MB used" " of total " << (pagemap.getTotalMemory() >> 20) << " MB\n\n"; } @@ -44,7 +44,7 @@ void kernel_init(const char* cmdline) int error; auto fd = fs::open(valueBuffer, error); if (!fd.valid()) { - debug() << "warning: " << valueBuffer << ": " + debug(BOOT) << "warning: " << valueBuffer << ": " << strerror(error) << "\n"; } else { mainTerm = ktl::shared_ptr(new Terminal(fd)); diff --git a/kernel/debug.cpp b/kernel/debug.cpp index 894e3d2..1d94323 100644 --- a/kernel/debug.cpp +++ b/kernel/debug.cpp @@ -9,7 +9,7 @@ #include #include -using namespace debugging; +using namespace dbg; static Spinlock s_debugLock; static bool s_initialized = false; @@ -18,7 +18,7 @@ static pc::SerialPort s_serial; void panic(const char* message) { cli(); - debug() << "**** kernel panic: " << message << "\n\n\n"; + debug(KERNEL) << "**** kernel panic: " << message << "\n\n\n"; for (;;) { hlt(); } } @@ -37,6 +37,9 @@ DebugStream::~DebugStream() if (!s_initialized) return; + if ((m_loglevel & OUTPUT_ENABLE) == 0) + return; + size_t len = strlen(m_buffer); s_debugLock.lock(); #ifdef DEBUG diff --git a/kernel/debug_stream.cpp b/kernel/debug_stream.cpp index 35d7e7d..a04571e 100644 --- a/kernel/debug_stream.cpp +++ b/kernel/debug_stream.cpp @@ -4,13 +4,14 @@ #include #include -using namespace debugging; +using namespace dbg; -DebugStream::DebugStream() +DebugStream::DebugStream(int loglevel) : m_currentMode(DEC) + , m_loglevel(loglevel) { - m_buffer[0] = 0; - m_destPtr = m_buffer; + m_buffer[0] = 0; + m_destPtr = m_buffer; } DebugStream& DebugStream::operator<<(Modifier modif) diff --git a/kernel/devices.cpp b/kernel/devices.cpp index 5355064..faef10b 100644 --- a/kernel/devices.cpp +++ b/kernel/devices.cpp @@ -34,6 +34,7 @@ namespace dev { void registerDevice(const char* name, DeviceFile* dev) { + debug(DEVICES) << "registered device '" << name << "'\n"; DeviceFs* devfs = (DeviceFs*)s_devfs.get(); devfs->registerDevice(name, ktl::shared_ptr(dev)); } diff --git a/kernel/include/debug.h b/kernel/include/debug.h index 538c767..08c6085 100644 --- a/kernel/include/debug.h +++ b/kernel/include/debug.h @@ -9,7 +9,7 @@ void _NORETURN panic(const char* msg); #ifdef DEBUG #define assert(x) if (!(x)) { \ - debug() << "****\n" \ + debug(KERNEL) << "****\n" \ "**** in " << __FILE__ << ": " \ << __func__ << "(), line " << __LINE__ << "\n"; \ panic("assertion failed"); \ @@ -20,21 +20,36 @@ void _NORETURN panic(const char* msg); #define assert_verify(x) (x) #endif -#define DEBUG_HEX debugging::DebugStream::HEX -#define DEBUG_DEC debugging::DebugStream::HEX +#define DEBUG_HEX dbg::DebugStream::HEX +#define DEBUG_DEC dbg::DebugStream::HEX -namespace debugging { +#define OUTPUT_ENABLE BIT(10) +#define PAGEFAULT 1 | OUTPUT_ENABLE +#define SYSCALL 2 | OUTPUT_ENABLE +#define PROCESS 3 | OUTPUT_ENABLE +#define TASK 4 | OUTPUT_ENABLE +#define VSPACE 5 | OUTPUT_ENABLE +#define FPU 6 | OUTPUT_ENABLE +#define KERNEL 7 | OUTPUT_ENABLE +#define BOOT 8 | OUTPUT_ENABLE +#define EXCEPT 9 | OUTPUT_ENABLE +#define MEMORY 10 | OUTPUT_ENABLE +#define LOADER 11 | OUTPUT_ENABLE +#define TIMER 12 | OUTPUT_ENABLE +#define DEVICES 13 | OUTPUT_ENABLE + +namespace dbg { class DebugStream { public: enum Modifier { - HEX, - DEC + HEX, + DEC }; - DebugStream(); + DebugStream(int loglevel); ~DebugStream(); DebugStream& operator<<(char c); @@ -58,11 +73,13 @@ namespace debugging { char *m_destPtr; Modifier m_currentMode; char m_buffer[BUFFER_SIZE]; + + int m_loglevel; }; } -static inline debugging::DebugStream debug() +static inline dbg::DebugStream debug(int loglevel) { - return debugging::DebugStream(); + return dbg::DebugStream(loglevel); } diff --git a/kernel/include/scheduler.h b/kernel/include/scheduler.h index c6129d3..ab32201 100644 --- a/kernel/include/scheduler.h +++ b/kernel/include/scheduler.h @@ -15,6 +15,7 @@ namespace sched { bool isEnabled(); Task* currentTask(); + size_t currentPid(); UserTask* currentUserTask(); size_t taskCount(); diff --git a/kernel/kernel_task.cpp b/kernel/kernel_task.cpp index d244033..6a996af 100644 --- a/kernel/kernel_task.cpp +++ b/kernel/kernel_task.cpp @@ -8,7 +8,7 @@ static void ktask_runtime(KernelTask* task, void(*func)(void*)) { - debug() << "kernel task #" << task->tid() << " started executing\n"; + debug(TASK) << "kernel task #" << task->tid() << " started executing\n"; func(task->arg()); task->exit(); } @@ -23,5 +23,5 @@ KernelTask::KernelTask(void(*entry)(void* arg), void* arg) context()->arg1() = (size_t)this; context()->arg2() = (size_t)entry; - debug() << "created new kernel task with TID " << tid() << "\n"; + debug(TASK) << "created new kernel task with TID " << tid() << "\n"; } diff --git a/kernel/loader.cpp b/kernel/loader.cpp index 56ce68b..1f201b5 100644 --- a/kernel/loader.cpp +++ b/kernel/loader.cpp @@ -33,12 +33,12 @@ bool Loader::isValidBinary() const if ((phtEntry.p_vaddr & 0xfff) != 0) { - debug() << "loader warning: trying to load ELF " + debug(LOADER) << "loader warning: trying to load ELF " "with unaligned LOAD program headers\n"; return false; } - //debug() << "load: addr=" << (void*)phtEntry.p_vaddr + //debug(LOADER) << "load: addr=" << (void*)phtEntry.p_vaddr // << ", size=" << DEBUG_HEX << phtEntry.p_memsz << "\n"; } diff --git a/kernel/mm/heap.cpp b/kernel/mm/heap.cpp index 94c4606..dfeb2c7 100644 --- a/kernel/mm/heap.cpp +++ b/kernel/mm/heap.cpp @@ -46,7 +46,7 @@ void kheap_print() { s_heapMutex.lock(); - debug() << "--- HEAP DUMP ---\n"; + debug(MEMORY) << "--- HEAP DUMP ---\n"; HeapBlock *entry; for (HeapBlock* entry = heap_start; entry != nullptr; @@ -58,15 +58,15 @@ void kheap_print() if (entry->available) { - debug() << " @ " << (entry + 1) << ": " << entry->size << "B [free]\n"; + debug(MEMORY) << " @ " << (entry + 1) << ": " << entry->size << "B [free]\n"; } else { #ifdef DEBUG - debug() << " @ " << (entry + 1) << ": " << entry->size + debug(MEMORY) << " @ " << (entry + 1) << ": " << entry->size << "B [used " << entry->function << "():" << entry->line << "]\n"; #else - debug() << " @ " << (entry + 1) << ": " << entry->size << "B [used]\n"; + debug(MEMORY) << " @ " << (entry + 1) << ": " << entry->size << "B [used]\n"; #endif } } @@ -82,7 +82,7 @@ void _kheap_check_corrupt(const char* func, unsigned line) { if (entry->magic != HEAP_MAGIC) { - debug() << "heap corruption detected in " << func << "():" << line << "\n"; + debug(MEMORY) << "heap corruption detected in " << func << "():" << line << "\n"; panic("heap corruption detected"); } } @@ -100,7 +100,7 @@ static void* kbrk(ssize_t increment) first_unmap += 1; size_t last_unmap = (size_t)orig_brk / PAGE_SIZE; - // debug() << "kheap: freeing pages " << first_unmap << " to " << last_unmap << "\n"; + // debug(MEMORY) << "kheap: freeing pages " << first_unmap << " to " << last_unmap << "\n"; for (size_t page = first_unmap; page <= last_unmap; page++) AddrSpace::kernel().unmap(page); } @@ -111,7 +111,7 @@ static void* kbrk(ssize_t increment) first_map += 1; size_t last_map = (size_t)(kheap_break_ - 1) >> PAGE_SHIFT; - //debug() << "kheap: alloc " << (last_map - first_map + 1) + //debug(MEMORY) << "kheap: alloc " << (last_map - first_map + 1) // << " pages @ " // << (void*)(first_map << PAGE_SHIFT) << "\n"; for (size_t page = first_map; page <= last_map; page++) @@ -239,7 +239,7 @@ static void mergeBlocks(HeapBlock *first, HeapBlock *second) void kfree(void *ptr) { - //debug() << "kfree(): " << ptr << "\n"; + //debug(MEMORY) << "kfree(): " << ptr << "\n"; if (ptr == nullptr) { return; diff --git a/kernel/mm/page_fault.cpp b/kernel/mm/page_fault.cpp index 5bf0de9..200550f 100644 --- a/kernel/mm/page_fault.cpp +++ b/kernel/mm/page_fault.cpp @@ -18,12 +18,12 @@ static bool checkIfValid(size_t addr, FaultFlags flags) { if (addr < MIN_LOAD_ADDR) { - debug() << "PF: nullptr dereferenced!\n"; + debug(PAGEFAULT) << "PF: nullptr dereferenced!\n"; return false; } if (addr >= USER_BREAK) { - debug() << "PF: referencing (unmapped) kernel memory!\n"; + debug(PAGEFAULT) << "PF: referencing (unmapped) kernel memory!\n"; return false; } @@ -33,7 +33,7 @@ static bool checkIfValid(size_t addr, FaultFlags flags) void killProgram() { auto& proc = sched::currentUserTask()->getProcess(); - debug() << "PID " << proc.pid() + debug(PAGEFAULT) << "PID " << proc.pid() << ": KILLED due to invalid memory reference\n"; proc.exit(-1); } diff --git a/kernel/sched/proc_list.cpp b/kernel/sched/proc_list.cpp index f223c48..9893d40 100644 --- a/kernel/sched/proc_list.cpp +++ b/kernel/sched/proc_list.cpp @@ -29,7 +29,7 @@ void ProcList::checkForDeadProcesses() if (proc->state() == UserProcess::TO_BE_DELETED) { delete proc; - debug() << "proc: deleted\n"; + debug(PROCESS) << "proc: deleted\n"; auto prev = it->prev; m_procList.remove(it); diff --git a/kernel/sched/scheduler.cpp b/kernel/sched/scheduler.cpp index 4d0f2ac..11cfdef 100644 --- a/kernel/sched/scheduler.cpp +++ b/kernel/sched/scheduler.cpp @@ -11,6 +11,7 @@ #include #include #include +#include #include /* sets the stack pointer that will be used @@ -151,4 +152,10 @@ namespace sched { { return s_taskList.size(); } + + size_t currentPid() + { + return sched::currentUserTask()->getProcess().pid(); + } + } diff --git a/kernel/sched/task_syscalls.cpp b/kernel/sched/task_syscalls.cpp index 60f17d0..6be0fe4 100644 --- a/kernel/sched/task_syscalls.cpp +++ b/kernel/sched/task_syscalls.cpp @@ -9,7 +9,7 @@ void sys_exit(int status) { - debug() << "exit(" << status << ")\n"; + debug(PROCESS) << "exit(" << status << ")\n"; auto userTask = sched::currentUserTask(); userTask->getProcess().exit(status); } @@ -17,7 +17,7 @@ void sys_exit(int status) void sys_thread_exit(void* ret) { auto userTask = sched::currentUserTask(); - debug() << "tid " << userTask->tid() << ": thread_exit(" << ret << ")\n"; + debug(TASK) << "tid " << userTask->tid() << ": thread_exit(" << ret << ")\n"; sched::currentUserTask()->exit(); } @@ -34,7 +34,11 @@ void* get_thread_ptr() ssize_t sys_thread_create(void* rt0, void* func, void* arg, int flags) { auto& proc = sched::currentUserTask()->getProcess(); - return proc.addTask(rt0, func, arg); + auto tid = proc.addTask(rt0, func, arg); + + debug(PROCESS) << "PID " << proc.pid() + << ": created new thread with TID " << tid << "\n"; + return tid; } size_t sys_thread_count() diff --git a/kernel/task.cpp b/kernel/task.cpp index e990222..c4ec421 100644 --- a/kernel/task.cpp +++ b/kernel/task.cpp @@ -36,7 +36,7 @@ Task::Task(AddrSpace& vspace) void Task::exit() { - debug() << "tid " << tid() << ": terminating\n"; + debug(TASK) << "tid " << tid() << ": terminating\n"; assert(sched::currentTask() == this); m_state = KILLED; sched::yield(); diff --git a/kernel/user_proc.cpp b/kernel/user_proc.cpp index 5db0504..136177a 100644 --- a/kernel/user_proc.cpp +++ b/kernel/user_proc.cpp @@ -80,8 +80,10 @@ size_t UserProcess::addTask(void* entryPoint, void* arg1, void* arg2) ssize_t UserProcess::fork() { assert(isOwnProcess()); - auto forked = new UserProcess(*this); + + debug(PROCESS) << "PID " << this->pid() + << " is forking PID " << forked->pid() << "\n"; return forked->pid(); } @@ -132,7 +134,7 @@ void UserProcess::checkForDeadTasks() sched::removeTask(userTask); delete userTask; - debug() << "tid " << userTask->tid() << ": deleted\n"; + debug(TASK) << "tid " << userTask->tid() << ": deleted\n"; /* some boilerplate code to remove the task from the list and * not break the for loop at the same time: */ diff --git a/platform/pc/drivers/init.cpp b/platform/pc/drivers/init.cpp index 12ae047..bc5b6be 100644 --- a/platform/pc/drivers/init.cpp +++ b/platform/pc/drivers/init.cpp @@ -12,7 +12,7 @@ extern void ps2kbd_init(); void init_drivers() { - debug() << "init platform drivers\n"; + debug(DEVICES) << "init platform drivers\n"; /* init timer to 50hz */ timer_reset(50); diff --git a/platform/pc/drivers/serial.cpp b/platform/pc/drivers/serial.cpp index 733cbee..4604212 100644 --- a/platform/pc/drivers/serial.cpp +++ b/platform/pc/drivers/serial.cpp @@ -27,7 +27,7 @@ SerialPort::SerialPort() SerialPort::SerialPort(SerialPort::Port port, bool noIrq) : m_port(port) { - debug() << "init PC serial port #" << minor() + debug(DEVICES) << "init PC serial port #" << minor() << " at port " << DEBUG_HEX << (size_t)port << "\n"; /* temporarily disable all IRQs */ @@ -123,7 +123,7 @@ void SerialPort::setBaudRate(SerialPort::BaudRate baud) outb(m_port + 1, baud >> 8); // high byte outb(m_port + 3, line_ctrl & 0x7f); // clear DLAB bit - debug() << "uart" << minor() << ": baud_rate=" + debug(DEVICES) << "uart" << minor() << ": baud_rate=" << (115200 / baud) << "\n"; } diff --git a/platform/pc/drivers/timer.cpp b/platform/pc/drivers/timer.cpp index dfe2024..cb8bb37 100644 --- a/platform/pc/drivers/timer.cpp +++ b/platform/pc/drivers/timer.cpp @@ -16,7 +16,7 @@ void timer_reset(uint16_t freqHz) { - debug() << "setting timer freq: " << freqHz << "Hz\n"; + debug(TIMER) << "setting timer freq: " << freqHz << "Hz\n"; uint16_t pit = OSCILLATOR / freqHz; outb(PIT_CMD, PIT_CMD_CH0 | PIT_ACCESS | PIT_RATEGEN);