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.
72 lines
2.2 KiB
C
72 lines
2.2 KiB
C
#ifndef KERNEL_H
|
|
#define KERNEL_H
|
|
|
|
/* boot verbose */
|
|
#define CONFIG_BOOT_VERBOSE
|
|
|
|
#ifndef CONFIG_MAX_CPUS
|
|
#define CONFIG_MAX_CPUS 1
|
|
#endif
|
|
|
|
/* OXPCIe952 PCIe with 2 UARTs in-kernel support */
|
|
#define CONFIG_OXPCIE 0
|
|
|
|
/* This is the master header for the kernel. It includes some other files
|
|
* and defines the principal constants.
|
|
*/
|
|
#define _SYSTEM 1 /* tell headers that this is the kernel */
|
|
|
|
/*
|
|
* we need the defines above in assembly files to configure the kernel
|
|
* correctly. However we don't need the rest
|
|
*/
|
|
#ifndef __ASSEMBLY__
|
|
|
|
/* The following are so basic, all the *.c files get them automatically. */
|
|
#include <minix/config.h> /* global configuration, MUST be first */
|
|
// #include <sys/types.h> /* general system types - Replaced */
|
|
#include <minix/const.h> /* MINIX specific constants */
|
|
#include <minix/type.h> /* MINIX specific types, e.g. message */
|
|
#include <minix/ipc.h> /* MINIX run-time system */
|
|
// #include <minix/sysutil.h> /* MINIX utility library functions - Removed */
|
|
#include <minix/timers.h> /* watchdog timer management */
|
|
// #include <errno.h> /* return codes and error numbers - Removed */
|
|
// #include <sys/param.h> // Removed
|
|
#include <minix/param.h> // Kept for now
|
|
|
|
// Added kernel headers
|
|
#include <minix/kernel_types.h> // Added
|
|
#include <klib/include/kprintf.h> // Precautionary
|
|
#include <klib/include/kstring.h> // Precautionary
|
|
#include <klib/include/kmemory.h> // Precautionary
|
|
|
|
|
|
/* Important kernel header files. */
|
|
#include "kernel/config.h" /* configuration, MUST be first */
|
|
#include "kernel/const.h" /* constants, MUST be second */
|
|
#include "kernel/type.h" /* type definitions, MUST be third */
|
|
#include "kernel/proto.h" /* function prototypes */
|
|
#include "kernel/glo.h" /* global variables */
|
|
#include "kernel/ipc.h" /* IPC constants */
|
|
#include "kernel/profile.h" /* system profiling */
|
|
#include "kernel/proc.h" /* process table */
|
|
#include "kernel/cpulocals.h" /* CPU-local variables */
|
|
#include "kernel/debug.h" /* debugging, MUST be last kernel header */
|
|
|
|
#ifndef CONFIG_SMP
|
|
/* We only support 1 cpu now */
|
|
#define CONFIG_MAX_CPUS 1
|
|
#define cpuid 0
|
|
/* this is always true on an uniprocessor */
|
|
#define cpu_is_bsp(x) 1
|
|
|
|
#else
|
|
|
|
#include "kernel/smp.h"
|
|
|
|
#endif
|
|
|
|
#endif /* __ASSEMBLY__ */
|
|
|
|
#endif /* KERNEL_H */
|