This commit addresses critical architectural deficiencies in the MINIX kernel build and source structure. The changes are based on a comprehensive technical review and aim to establish a cleaner, more robust foundation for future kernel development.
Key changes include:
1. **Kernel-Specific Type System:**
* I introduced `minix/kernel/include/minix/kernel_types.h`.
* I defined kernel-specific types (e.g., `k_size_t`, `k_pid_t`) and fixed-width integer types (e.g., `k_uint32_t`) to replace userspace types.
2. **Kernel-Space Library (`klib`):**
* I created a new kernel library (`klib`) located in `minix/kernel/klib/`.
* I implemented basic string functions (`kstrlen`, `kstrlcpy`, `kstrcmp`) in `kstring.c`.
* I implemented basic memory functions (`kmemcpy`, `kmemset`, `kmemmove`) in `kmemory.c`.
* I added stub implementations for `kprintf`, `ksprintf`, and `kvprintf` in `kprintf_stub.c`, along with a `KASSERT_PLACEHOLDER` macro.
3. **Purged Userspace Dependencies:**
* I systematically refactored all C and header files within `minix/kernel/` and its subdirectories (`system/`, `arch/i386/`, `arch/earm/`).
* I removed userspace includes (e.g., `<string.h>`, `<stdlib.h>`, `<stdio.h>`, `<assert.h>`, `<sys/types.h>`, `<signal.h>`, `<unistd.h>`).
* I replaced calls to userspace C library functions with their `klib` equivalents or marked them with `FIXME` comments if a direct replacement was not yet available (e.g., `atoi`, `strncmp`).
* I replaced userspace types with their `k_` prefixed kernel versions.
4. **Build System Reconstruction (Meson):**
* I replaced `minix/kernel/meson.build` with a new script designed for a proper kernel build.
* The new build system defines kernel-specific compiler flags, handles architecture detection (i386, x86_64), sets up correct include paths, and builds `klib` and the main kernel executable.
* Assembly file compilation and linkage are noted as TODOs in the Meson script.
**Next Steps & Known Issues:**
The kernel is not expected to build successfully immediately after these changes. A significant number of `FIXME` comments and identified issues need to be addressed in a proper build environment. These include:
* Defining numerous missing constants (error numbers, signal numbers, etc.).
* Providing kernel-safe implementations for macros like `offsetof`.
* Implementing missing `klib` functions (e.g., a real `kprintf`, `kstrncmp`, `kmemcmp`, `katoi`).
* Developing kernel-space signal handling and ELF loading mechanisms.
* Adding rules for compiling and linking assembly source files.
This refactoring establishes the necessary structure to tackle these remaining issues systematically.
103 lines
2.8 KiB
C
103 lines
2.8 KiB
C
#ifndef DEBUG_H
|
|
#define DEBUG_H
|
|
|
|
/* This header file defines all debugging constants and macros, and declares
|
|
* some variables. Certain debugging features redefine standard constants
|
|
* and macros. Therefore, this header file should be included after the
|
|
* other kernel headers.
|
|
*/
|
|
|
|
#ifndef __ASSEMBLY__
|
|
#include <minix/debug.h> // Kept for now
|
|
#include "config.h" // Kept (local kernel header)
|
|
|
|
// Added kernel headers (precautionary for consistency)
|
|
#include <minix/kernel_types.h>
|
|
#include <klib/include/kprintf.h>
|
|
#include <klib/include/kstring.h>
|
|
#include <klib/include/kmemory.h>
|
|
|
|
#endif
|
|
|
|
/* Debug info via serial (see ser_debug()) */
|
|
#define DEBUG_SERIAL 1
|
|
|
|
/* Enable prints such as
|
|
* . send/receive failed due to deadlock or dead source or dead destination
|
|
* . trap not allowed
|
|
* . bogus message pointer
|
|
* . kernel call number not allowed by this process
|
|
*
|
|
* Of course the call still fails, but nothing is printed if these warnings
|
|
* are disabled.
|
|
*/
|
|
#define DEBUG_ENABLE_IPC_WARNINGS 1
|
|
|
|
/* Sanity checks. */
|
|
#define DEBUG_SANITYCHECKS 0
|
|
|
|
/* Verbose messages. */
|
|
#define DEBUG_TRACE 0
|
|
|
|
/* DEBUG_RACE makes every process preemptible, schedules
|
|
* every process on the same priority queue, and randomizes
|
|
* the next process to run, in order to help catch race
|
|
* conditions that could otherwise be masked.
|
|
*/
|
|
#define DEBUG_RACE 0
|
|
|
|
/* DEBUG_DUMPIPC dumps all IPC to serial; due to the amount of logging it is
|
|
* strongly recommended to set "ctty 0" in the boot monitor and run inside a
|
|
* virtual machine if you enable this; on the hardware it would take forever
|
|
* just to boot
|
|
*/
|
|
#define DEBUG_DUMPIPC 0
|
|
|
|
/* DEBUG_DUMPIPCF dumps filtered IPC to serial.
|
|
*/
|
|
#define DEBUG_DUMPIPCF 0
|
|
|
|
/* If defined, restrict DEBUG_DUMPIPC to particular process names */
|
|
/* #define DEBUG_DUMPIPC_NAMES { "tty", "pty" } */
|
|
|
|
/* DEBUG_IPCSTATS collects information on who sends messages to whom. */
|
|
#define DEBUG_IPCSTATS 0
|
|
|
|
#if !USE_SYSDEBUG
|
|
#undef DEBUG_SERIAL
|
|
#undef DEBUG_ENABLE_IPC_WARNINGS
|
|
#endif
|
|
|
|
#if DEBUG_DUMPIPC || DEBUG_IPCSTATS /* either of these needs the hook */
|
|
#define DEBUG_IPC_HOOK 1
|
|
#endif
|
|
|
|
#if DEBUG_TRACE
|
|
|
|
#define VF_SCHEDULING (1L << 1)
|
|
#define VF_PICKPROC (1L << 2)
|
|
|
|
// MODIFIED: printf to kprintf_stub
|
|
#define TRACE(code, statement) if(verboseflags & code) { kprintf_stub("%s:%d: ", __FILE__, __LINE__); statement }
|
|
|
|
#else
|
|
#define TRACE(code, statement)
|
|
#endif
|
|
|
|
#ifdef CONFIG_BOOT_VERBOSE
|
|
#define BOOT_VERBOSE(x) x
|
|
#else
|
|
#define BOOT_VERBOSE(x)
|
|
#endif
|
|
|
|
#ifdef _SYSTEM
|
|
// MODIFIED: printf to kprintf_stub
|
|
#define DEBUG_PRINT(params, level) do { \
|
|
if (verboseboot >= (level)) kprintf_stub params; } while (0)
|
|
#define DEBUGBASIC(params) DEBUG_PRINT(params, VERBOSEBOOT_BASIC)
|
|
#define DEBUGEXTRA(params) DEBUG_PRINT(params, VERBOSEBOOT_EXTRA)
|
|
#define DEBUGMAX(params) DEBUG_PRINT(params, VERBOSEBOOT_MAX)
|
|
#endif
|
|
|
|
#endif /* DEBUG_H */
|