Skip to content

Conversation

assembler-0
Copy link
Owner

@assembler-0 assembler-0 commented Jul 15, 2025

Summary by CodeRabbit

  • New Features

    • Introduced spinlock primitives for improved concurrency control.
    • Added detailed page fault diagnostics for easier debugging.
    • Kernel now uses a dedicated, mapped virtual stack for improved stability.
    • Global Descriptor Table (GDT) and Task State Segment (TSS) setup enhanced for 64-bit support.
    • Section-wise kernel memory mapping with correct permissions.
    • Added fast memory comparison utility.
  • Bug Fixes

    • Improved atomicity in scheduler tick updates to prevent race conditions.
    • Fixed syscall return value handling for more reliable process exits.
  • Refactor

    • Updated function signatures for consistency (e.g., initialization functions now return void).
    • Enhanced memory and interrupt handling routines for clarity and maintainability.
  • Chores

    • Improved linker script with explicit section alignment and boundary symbols.
    • Updated build configuration to use the correct assembly source files.
  • Documentation

    • Added and clarified comments for better code understanding.

Copy link

coderabbitai bot commented Jul 15, 2025

Caution

Review failed

The pull request is closed.

Walkthrough

This update introduces significant architectural changes to the kernel, including 64-bit TSS support in the GDT, improved interrupt and syscall handling, a statically allocated kernel stack mapped into higher-half memory, atomic spinlock primitives, and precise kernel section mapping with page-aligned boundaries. Several function signatures are updated for consistency, and new diagnostics for page faults are added.

Changes

File(s) Change Summary
arch/x86_64/cpu/Cpu.c Removed conditional EnableSse() call; added comment about SSE being enabled by bootloader.
arch/x86_64/gdt/Gdt.c, arch/x86_64/gdt/Gdt.h, arch/x86_64/gdt/GdtTssFlush.asm Added 64-bit TSS support: expanded GDT, new TSS struct, SetTssGate, SetTssRsp0, TssFlush function.
arch/x86_64/interrupts/Interrupts.asm Added ISR_ERRCODE macro, isr_stub_table, explicit error code ISR handlers.
arch/x86_64/interrupts/Interrupts.c, arch/x86_64/interrupts/Interrupts.h Improved page fault diagnostics, removed itoa, simplified fatal exception handling.
arch/x86_64/syscall/Syscall.c, arch/x86_64/syscall/Syscall.h, arch/x86_64/syscall/SyscallEntry.asm Changed syscall exit to use KillProcess, updated return types, fixed syscall return value restoration.
drivers/Pic.c, drivers/Pic.h Changed PicInstall to void, updated PIC masking/unmasking logic.
kernel/atomic/Spinlock.h Introduced atomic spinlock primitives (SpinLock, SpinUnlock).
kernel/core/Kernel.c, kernel/memory/AsmHelpers.asm, kernel/memory/AsmHelpers.h Added 16KB kernel stack, mapped to higher-half, updated paging and stack switching logic.
kernel/memory/MemOps.c Improved SSE2 memset, added FastMemcmp.
kernel/memory/Memory.c Prepared for spinlock protection of memory bitmap (commented out), improved error handling.
kernel/memory/VMem.c, kernel/memory/VMem.h Removed inline spinlocks, improved locking discipline, mapped kernel sections individually, removed VMemUnmap.
kernel/process/Process.c Used atomic increment for scheduler ticks, added periodic log in tracer.
linker.ld Added 4K alignment and section boundary symbols for all major sections.
meson.build Switched GDT assembly source to GdtTssFlush.asm.

Sequence Diagram(s)

Kernel Boot: Paging and Stack Initialization

sequenceDiagram
    participant Bootloader
    participant KernelMain
    participant Paging
    participant Stack
    Bootloader->>KernelMain: Jump to KernelMain
    KernelMain->>Paging: Setup page tables, map kernel and stack
    KernelMain->>Stack: Allocate and map 16KB kernel stack
    KernelMain->>Paging: EnablePagingAndJump(pml4_phys, higher_half_entry, new_stack_top)
    Paging->>KernelMain: Switch to higher-half, set new stack pointer
Loading

Syscall Exit Handling

sequenceDiagram
    participant UserProcess
    participant SyscallHandler
    participant KillProcess
    UserProcess->>SyscallHandler: syscall (exit)
    SyscallHandler->>KillProcess: KillProcess(current->pid)
    KillProcess-->>SyscallHandler: (does not return)
    SyscallHandler->>SyscallHandler: hlt (infinite halt)
Loading

GDT and TSS Initialization

sequenceDiagram
    participant KernelMain
    participant GdtInit
    participant SetTssGate
    participant GdtFlush
    participant TssFlush
    KernelMain->>GdtInit: Initialize GDT
    GdtInit->>SetTssGate: Setup TSS descriptor
    GdtInit->>GdtFlush: Load new GDT
    GdtInit->>TssFlush: Load TSS selector
Loading

Possibly related PRs

  • Development #31: Introduces and elaborates on KillProcess, which is now used for syscall-based process termination.
  • pls kill me #36: Implements AtomicInc, now used for atomic scheduler tick counting.
  • Development #39: Refactors fatal exception handling to use KillProcess, paralleling changes in this update.

Poem

In the kernel’s warren, deep and wide,
A stack now mapped, with GDT as guide.
TSS stands tall, interrupts refined,
Atomic locks keep race conditions confined.
Page faults now whisper their tale,
With each aligned section, the system won’t fail.
🐰 Hooray for the code—let’s follow the trail!


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 31f20be and 185b9cf.

📒 Files selected for processing (23)
  • arch/x86_64/cpu/Cpu.c (1 hunks)
  • arch/x86_64/gdt/Gdt.c (1 hunks)
  • arch/x86_64/gdt/Gdt.h (2 hunks)
  • arch/x86_64/gdt/GdtTssFlush.asm (2 hunks)
  • arch/x86_64/interrupts/Interrupts.asm (2 hunks)
  • arch/x86_64/interrupts/Interrupts.c (3 hunks)
  • arch/x86_64/interrupts/Interrupts.h (0 hunks)
  • arch/x86_64/syscall/Syscall.c (3 hunks)
  • arch/x86_64/syscall/Syscall.h (1 hunks)
  • arch/x86_64/syscall/SyscallEntry.asm (1 hunks)
  • drivers/Pic.c (2 hunks)
  • drivers/Pic.h (1 hunks)
  • kernel/atomic/Spinlock.h (1 hunks)
  • kernel/core/Kernel.c (4 hunks)
  • kernel/memory/AsmHelpers.asm (1 hunks)
  • kernel/memory/AsmHelpers.h (1 hunks)
  • kernel/memory/MemOps.c (2 hunks)
  • kernel/memory/Memory.c (4 hunks)
  • kernel/memory/VMem.c (4 hunks)
  • kernel/memory/VMem.h (1 hunks)
  • kernel/process/Process.c (2 hunks)
  • linker.ld (1 hunks)
  • meson.build (1 hunks)
✨ Finishing Touches
  • 📝 Generate Docstrings

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@assembler-0 assembler-0 merged commit 724342e into main Jul 15, 2025
1 check was pending
This was referenced Aug 12, 2025
@coderabbitai coderabbitai bot mentioned this pull request Sep 12, 2025
@coderabbitai coderabbitai bot mentioned this pull request Sep 29, 2025
@coderabbitai coderabbitai bot mentioned this pull request Oct 8, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant