minix/minix/kernel/arch/i386/debugreg.h
google-labs-jules[bot] 581f21e31d Kernel Architecture Refactor (Foundational Pass)
This commit culminates a significant refactoring effort to address foundational architectural issues in the MINIX kernel, based on your initial technical review and subsequent detailed architectural roadmap feedback. It aims to establish a cleaner separation between kernel and userspace, introduce kernel-specific types and libraries, and prepare the build system for more robust kernel development.

**Key Achievements:**

1.  **Critical Fixes (Phase 0):**
    *   Corrected `kmemmove` implementation in `klib/kmemory.c` to prevent data corruption.
    *   Integrated i386 assembly files (`.S`) into the `meson.build` process, enabling kernel linkage.

2.  **Foundational Infrastructure (Phase 1 - Partial):**
    *   **Assertion Framework:**
        *   Introduced `include/sys/kassert.h` with `KASSERT` (conditional on `DEBUG_KERNEL`) and `KSTATIC_ASSERT` macros.
        *   Added `klib/kpanic.c` with a `kpanic` function (using `kprintf_stub` for now, relies on `extern arch_halt` and `arch_disable_interrupts`).
    *   **Memory Barriers:** Created `include/sys/barrier.h` with `kcompiler_barrier`, x86 memory barriers (`kmb`, `krmb`, `kwmb`), and SMP atomic operation barriers.
    *   **Enhanced Type System (`include/minix/kernel_types.h`):**
        *   Added `k_atomic_t`, `k_atomic_long_t`.
        *   Added opaque handle forward declarations (e.g., `k_proc_handle_t`).
        *   Added `K_CACHE_LINE_SIZE` and `__k_cacheline_aligned` macros.
        *   Added a kernel-safe `K_OFFSETOF` macro.
        *   Verified presence of previously added kernel-specific fixed-width integer types (e.g., `k_uint32_t`).
    *   **`offsetof` Replacement:** Replaced `offsetof` macro usage with `K_OFFSETOF` in files under `minix/kernel/` and `minix/kernel/system/`.

3.  **Initial Codebase Refactoring (Base for current work):**
    *   Established initial `kernel_types.h` with basic `k_` prefixed types.
    *   Created `klib` with `kstring.c`, `kmemory.c` (initial versions), and `kprintf_stub.c`.
    *   Systematically refactored all `.c` and `.h` files across `minix/kernel/` and its subdirectories (`system/`, `arch/i386/`, `arch/earm/`) to remove userspace headers, types, and function calls, replacing them with kernel-specific versions or `FIXME` placeholders.
    *   Overhauled `minix/kernel/meson.build` with kernel-specific flags, architecture handling, and definitions for `klib` and the kernel executable.

**Deferred Tasks & Known Next Steps:**

Due to environment limitations and the scale of changes, the following tasks are deferred for handling in a suitable build environment, ideally with scripting:
*   **`KASSERT_PLACEHOLDER` Migration:** Codebase-wide replacement of `KASSERT_PLACEHOLDER` with the new `KASSERT` macro and inclusion of `<sys/kassert.h>`.
*   **`offsetof` Migration (arch dirs):** Completion of `offsetof` to `K_OFFSETOF` replacement for `arch/i386/` and `arch/earm/` directories.

**Critical Outstanding Work (requiring a build environment):**
*   **Resolve FIXMEs:** Address all `FIXME` comments generated during refactoring. This includes defining numerous missing constants (error numbers, signal numbers, hardware constants), types (fixed-width if not covered, `struct exec_info`, `struct sigcontext`), and macros.
*   **Implement Missing `klib` Functions:** Provide full implementations for `kprintf`/`ksprintf` (currently stubs), `kstrncmp`, `kmemcmp`, `katoi`, `kstrlcat`, etc.
*   **Kernel Services:** Develop kernel-space signal handling, ELF loading mechanisms.
*   **Build System Enhancements:** Add full assembly language file support (specific flags, rules), manage linker scripts, and incorporate advanced linker options.
*   **HAL Implementation:** Define and implement Hardware Abstraction Layer interfaces as per the detailed roadmap.
*   **Thorough Build & Testing:** Iteratively build, resolve errors, and test on target hardware/emulators.

This commit represents a significant step towards a more robust MINIX kernel architecture. The subsequent phases outlined in your "Structured Implementation Roadmap" should be followed to achieve a production-ready state.
2025-06-07 00:07:54 +00:00

51 lines
1.7 KiB
C

#ifndef __DEBUGREG_H__
#define __DEBUGREG_H__
// 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>
/* DR6: status flags */
#define DR6_B(bp) (1 << (bp)) /* breakpoint was triggered */
#define DR6_BD (1 << 13) /* debug register access detected */
#define DR6_BS (1 << 14) /* single step */
#define DR6_BT (1 << 15) /* task switch */
/* DR7: control flags */
#define DR7_L(bp) (1 << (2*(bp))) /* breakpoint armed locally */
#define DR7_G(bp) (1 << (1+2*(bp))) /* breakpoint armed globally */
#define DR7_LE (1 << 8) /* exact local breakpoints */
#define DR7_GE (1 << 9) /* exact global breakpoints */
#define DR7_GD (1 << 13) /* detect debug reg movs */
#define DR7_RW_MASK(bp) (3 << (16+4*(bp)))
#define DR7_RW_EXEC(bp) (0 << (16+4*(bp))) /* execute */
#define DR7_RW_WRITE(bp) (1 << (16+4*(bp))) /* write */
#define DR7_RW_IO(bp) (2 << (16+4*(bp))) /* IO */
#define DR7_RW_RW(bp) (3 << (16+4*(bp))) /* read or write */
#define DR7_LN_MASK(bp) (3 << (18+4*(bp)))
#define DR7_LN_1(bp) (0 << (18+4*(bp))) /* 1 byte */
#define DR7_LN_2(bp) (1 << (18+4*(bp))) /* 2 bytes */
#define DR7_LN_8(bp) (2 << (18+4*(bp))) /* 8 bytes */
#define DR7_LN_4(bp) (3 << (18+4*(bp))) /* 4 bytes */
/* debugreg.S */
void ld_dr0(phys_bytes value);
void ld_dr1(phys_bytes value);
void ld_dr2(phys_bytes value);
void ld_dr3(phys_bytes value);
void ld_dr6(unsigned long value);
void ld_dr7(unsigned long value);
phys_bytes st_dr0(void);
phys_bytes st_dr1(void);
phys_bytes st_dr2(void);
phys_bytes st_dr3(void);
unsigned long st_dr6(void);
unsigned long st_dr7(void);
#endif /* __DEBUGREG_H__ */