collaborate_NYCU
  • NEW!
    NEW!  Connect Ideas Across Notes
    Save time and share insights. With Paragraph Citation, you can quote others’ work with source info built in. If someone cites your note, you’ll see a card showing where it’s used—bringing notes closer together.
    Got it
        • Sharing URL Link copied
        • /edit
        • View mode
          • Edit mode
          • View mode
          • Book mode
          • Slide mode
          Edit mode View mode Book mode Slide mode
        • Customize slides
        • Note Permission
        • Read
          • Owners
          • Signed-in users
          • Everyone
          Owners Signed-in users Everyone
        • Write
          • Owners
          • Signed-in users
          • Everyone
          Owners Signed-in users Everyone
        • Engagement control Commenting, Suggest edit, Emoji Reply
      • Invite by email
        Invitee

        This note has no invitees

      • Publish Note

        Share your work with the world Congratulations! 🎉 Your note is out in the world Publish Note No publishing access yet

        Your note will be visible on your profile and discoverable by anyone.
        Your note is now live.
        This note is visible on your profile and discoverable online.
        Everyone on the web can find and read all notes of this public team.

        Your account was recently created. Publishing will be available soon, allowing you to share notes on your public page and in search results.

        Your team account was recently created. Publishing will be available soon, allowing you to share notes on your public page and in search results.

        Explore these features while you wait
        Complete general settings
        Bookmark and like published notes
        Write a few more notes
        Complete general settings
        Write a few more notes
        See published notes
        Unpublish note
        Please check the box to agree to the Community Guidelines.
        View profile
      • Commenting
        Permission
        Disabled Forbidden Owners Signed-in users Everyone
      • Enable
      • Permission
        • Forbidden
        • Owners
        • Signed-in users
        • Everyone
      • Suggest edit
        Permission
        Disabled Forbidden Owners Signed-in users Everyone
      • Enable
      • Permission
        • Forbidden
        • Owners
        • Signed-in users
      • Emoji Reply
      • Enable
      • Versions and GitHub Sync
      • Note settings
      • Note Insights New
      • Engagement control
      • Make a copy
      • Transfer ownership
      • Delete this note
      • Insert from template
      • Import from
        • Dropbox
        • Google Drive
        • Gist
        • Clipboard
      • Export to
        • Dropbox
        • Google Drive
        • Gist
      • Download
        • Markdown
        • HTML
        • Raw HTML
    Menu Note settings Note Insights Versions and GitHub Sync Sharing URL Help
    Menu
    Options
    Engagement control Make a copy Transfer ownership Delete this note
    Import from
    Dropbox Google Drive Gist Clipboard
    Export to
    Dropbox Google Drive Gist
    Download
    Markdown HTML Raw HTML
    Back
    Sharing URL Link copied
    /edit
    View mode
    • Edit mode
    • View mode
    • Book mode
    • Slide mode
    Edit mode View mode Book mode Slide mode
    Customize slides
    Note Permission
    Read
    Owners
    • Owners
    • Signed-in users
    • Everyone
    Owners Signed-in users Everyone
    Write
    Owners
    • Owners
    • Signed-in users
    • Everyone
    Owners Signed-in users Everyone
    Engagement control Commenting, Suggest edit, Emoji Reply
  • Invite by email
    Invitee

    This note has no invitees

  • Publish Note

    Share your work with the world Congratulations! 🎉 Your note is out in the world Publish Note No publishing access yet

    Your note will be visible on your profile and discoverable by anyone.
    Your note is now live.
    This note is visible on your profile and discoverable online.
    Everyone on the web can find and read all notes of this public team.

    Your account was recently created. Publishing will be available soon, allowing you to share notes on your public page and in search results.

    Your team account was recently created. Publishing will be available soon, allowing you to share notes on your public page and in search results.

    Explore these features while you wait
    Complete general settings
    Bookmark and like published notes
    Write a few more notes
    Complete general settings
    Write a few more notes
    See published notes
    Unpublish note
    Please check the box to agree to the Community Guidelines.
    View profile
    Engagement control
    Commenting
    Permission
    Disabled Forbidden Owners Signed-in users Everyone
    Enable
    Permission
    • Forbidden
    • Owners
    • Signed-in users
    • Everyone
    Suggest edit
    Permission
    Disabled Forbidden Owners Signed-in users Everyone
    Enable
    Permission
    • Forbidden
    • Owners
    • Signed-in users
    Emoji Reply
    Enable
    Import from Dropbox Google Drive Gist Clipboard
       Owned this note    Owned this note      
    Published Linked with GitHub
    • Any changes
      Be notified of any changes
    • Mention me
      Be notified of mention me
    • Unsubscribe
    # 🚀 NachOS Architecture & MP Implementation: 7-Day Intensive Plan In the world of Computer Science academia—particularly at universities like **National Yang Ming Chiao Tung University (NYCU)** and **National Tsing Hua University (NTHU)**—**Nachos** (Not Another Completely Heuristic Operating System) is a famous instructional software used to teach the inner workings of an Operating System. Rather than just reading about how an OS works, students use Nachos to **build one** by writing the actual code for thread management, memory allocation, and file systems. --- ## 1. The Core Concept: A "System within a System" Nachos is unique because it is a **simulated operating system** that runs as a regular process on top of a host OS (like Linux or Windows). * **The Machine Layer:** Nachos simulates a **MIPS R2000 CPU**, including its registers, physical memory, and hardware interrupts. * **The Kernel Layer:** This is where you (the student/developer) write the code. You implement the logic that manages the simulated hardware. * **User Programs:** You can write small C programs, compile them into MIPS machine code, and "run" them on your Nachos kernel. --- ## 2. What do you actually do in Nachos? (The "Machine Problems") In a typical OS course, the project is divided into several **Machine Problems (MPs)**. Each one focuses on a pillar of OS design: | Project | Focus | What you implement | | --- | --- | --- | | **MP1: Threads** | **Concurrency** | Thread switching, Semaphores, Locks, and Condition Variables. | | **MP2: Multiprogramming** | **Virtualization** | System Calls (`Read`, `Write`, `Exit`) and loading multiple programs into memory. | | **MP3: Scheduling** | **Resource Policy** | Replacing simple Round-Robin with advanced algorithms like Multilevel Feedback Queues. | | **MP4: File Systems** | **Persistence** | Creating a directory structure and handling file storage on a simulated disk. | --- ## 3. Why is it so "Famous" (and Difficult)? Nachos is known for being a "rite of passage" for CS students for several reasons: * **Low-Level Reality:** You have to deal with CPU registers and assembly-level "traps." If your memory management code is off by one byte, the simulated machine crashes. * **Concurrency Hell:** Debugging race conditions in a multi-threaded kernel is notoriously difficult. You learn very quickly why `Mutexes` and `Semaphores` are essential. * **The Gap between Theory and Practice:** You move from knowing *what* a System Call is to knowing *exactly* which registers move the data from User Space to Kernel Space. --- ## 4. How it relates to Modern Tech While Nachos simulates an older MIPS architecture, the concepts are 100% applicable to modern systems: * **Cybersecurity:** Understanding how `exception.cc` handles system calls is the foundation of understanding **Kernel Exploits** and **Privilege Escalation**. * **AI Infrastructure:** Efficient thread scheduling (MP3) is exactly what allows high-performance AI clusters to feed data to GPUs without bottlenecks. * **Systems Programming:** It provides the "low-level intuition" needed to write high-performance code in languages like **Rust** or **C++**. **Are you currently preparing to set up a Nachos environment for a course, or are you interested in a specific part of the architecture like the Thread Scheduler?** | Day | Focus Area | Key Learning Objectives & Core Files | Relatable Concepts (AI/Security) | | --- | --- | --- | --- | | **Day 1** | **Macro Architecture & Setup** | Understand directory structure, MIPS emulation, and compilation flow. <br><br> 📁 `machine/`, `threads/`, `Makefile` | Hardware-Software Abstraction & Cross-compilation. | | **Day 2** | **Boot Process & Interrupts** | Trace `main.cc` to see kernel initialization and the event-driven Interrupt Handler. <br><br> 📁 `main.cc`, `interrupt.cc`, `timer.cc` | Event Loops & Asynchronous Processing (Async/Await). | | **Day 3** | **Thread Management (MP1)** | Deep dive into Thread states (Ready, Running, Blocked) and the `Switch` assembly. <br><br> 📁 `thread.cc`, `scheduler.cc`, `switch.s` | CPU Scheduling & Context Switching (Parallelism). | | **Day 4** | **Synchronization Primitives** | Mastering Semaphores, Locks, and Condition Variables to prevent Race Conditions. <br><br> 📁 `synch.cc`, `synch.h` | Concurrency Safety (Rust Ownership & Mutexes). | | **Day 5** | **User vs. Kernel Mode (MP1/2)** | Understanding the "Trap" mechanism and the Exception Handler boundary. <br><br> 📁 `exception.cc`, `syscall.h`, `start.s` | **Security:** Privilege Escalation & System Call Hooking. | | **Day 6** | **Memory & Address Space (MP2)** | Mapping Virtual Addresses to Physical Addresses using Page Tables. <br><br> 📁 `addrspace.cc`, `machine.h` | **Security:** Buffer Overflows & Memory Isolation. | | **Day 7** | **Tooling & MP1 Kick-off** | Using GDB for kernel debugging and implementing your first `Console I/O` SysCall. <br><br> 📁 `syscall.h`, `exception.cc` | Low-level Debugging & Kernel Space I/O. | --- ### Detailed Breakdown of Core Components #### 1. The Machine Layer (`machine/`) * **MIPS Emulator:** This simulates the physical CPU. You generally **do not** modify this, but you must understand how it interacts with your code. * **Registers:** Understanding how the `PC` (Program Counter) and `Stack Pointer` work is crucial for MP1. #### 2. The Kernel Layer (`threads/` & `userprog/`) * **MP1 (System Calls):** You will modify `exception.cc` to handle requests from User Space. * **MP2 (Multiprogramming):** You will modify `addrspace.cc` to manage how multiple programs reside in memory simultaneously. * **MP3 (Scheduling):** You will modify `scheduler.cc` to replace the default Round-Robin with a Multilevel Feedback Queue. #### 3. The File System Layer (`filesys/`) * **MP4 (Advanced FS):** You will expand the 4KB limit and implement hierarchical subdirectories, similar to how modern Linux filesystems operate. --- ### 💡 Strategy for Success * **The "Grep" Method:** Since NachOS is highly interconnected, always search for where a function is defined and where it is called before making changes. * **Security Mindset:** When implementing MP1 (System Calls), imagine you are an attacker trying to pass a "malicious" pointer from User Space to the Kernel. How would you validate that data? Would you like me to provide a **sample code snippet for Day 5** (how to handle a System Call in `exception.cc`) to get you started on MP1?

    Import from clipboard

    Paste your markdown or webpage here...

    Advanced permission required

    Your current role can only read. Ask the system administrator to acquire write and comment permission.

    This team is disabled

    Sorry, this team is disabled. You can't edit this note.

    This note is locked

    Sorry, only owner can edit this note.

    Reach the limit

    Sorry, you've reached the max length this note can be.
    Please reduce the content or divide it to more notes, thank you!

    Import from Gist

    Import from Snippet

    or

    Export to Snippet

    Are you sure?

    Do you really want to delete this note?
    All users will lose their connection.

    Create a note from template

    Create a note from template

    Oops...
    This template has been removed or transferred.
    Upgrade
    All
    • All
    • Team
    No template.

    Create a template

    Upgrade

    Delete template

    Do you really want to delete this template?
    Turn this template into a regular note and keep its content, versions, and comments.

    This page need refresh

    You have an incompatible client version.
    Refresh to update.
    New version available!
    See releases notes here
    Refresh to enjoy new features.
    Your user state has changed.
    Refresh to load new user state.

    Sign in

    Forgot password
    or
    Sign in via Google Sign in via Facebook Sign in via X(Twitter) Sign in via GitHub Sign in via Dropbox Sign in with Wallet
    Wallet ( )
    Connect another wallet

    New to HackMD? Sign up

    By signing in, you agree to our terms of service.

    Help

    • English
    • 中文
    • Français
    • Deutsch
    • 日本語
    • Español
    • Català
    • Ελληνικά
    • Português
    • italiano
    • Türkçe
    • Русский
    • Nederlands
    • hrvatski jezik
    • język polski
    • Українська
    • हिन्दी
    • svenska
    • Esperanto
    • dansk

    Documents

    Help & Tutorial

    How to use Book mode

    Slide Example

    API Docs

    Edit in VSCode

    Install browser extension

    Contacts

    Feedback

    Discord

    Send us email

    Resources

    Releases

    Pricing

    Blog

    Policy

    Terms

    Privacy

    Cheatsheet

    Syntax Example Reference
    # Header Header 基本排版
    - Unordered List
    • Unordered List
    1. Ordered List
    1. Ordered List
    - [ ] Todo List
    • Todo List
    > Blockquote
    Blockquote
    **Bold font** Bold font
    *Italics font* Italics font
    ~~Strikethrough~~ Strikethrough
    19^th^ 19th
    H~2~O H2O
    ++Inserted text++ Inserted text
    ==Marked text== Marked text
    [link text](https:// "title") Link
    ![image alt](https:// "title") Image
    `Code` Code 在筆記中貼入程式碼
    ```javascript
    var i = 0;
    ```
    var i = 0;
    :smile: :smile: Emoji list
    {%youtube youtube_id %} Externals
    $L^aT_eX$ LaTeX
    :::info
    This is a alert area.
    :::

    This is a alert area.

    Versions and GitHub Sync
    Get Full History Access

    • Edit version name
    • Delete

    revision author avatar     named on  

    More Less

    Note content is identical to the latest version.
    Compare
      Choose a version
      No search result
      Version not found
    Sign in to link this note to GitHub
    Learn more
    This note is not linked with GitHub
     

    Feedback

    Submission failed, please try again

    Thanks for your support.

    On a scale of 0-10, how likely is it that you would recommend HackMD to your friends, family or business associates?

    Please give us some advice and help us improve HackMD.

     

    Thanks for your feedback

    Remove version name

    Do you want to remove this version name and description?

    Transfer ownership

    Transfer to
      Warning: is a public team. If you transfer note to this team, everyone on the web can find and read this note.

        Link with GitHub

        Please authorize HackMD on GitHub
        • Please sign in to GitHub and install the HackMD app on your GitHub repo.
        • HackMD links with GitHub through a GitHub App. You can choose which repo to install our App.
        Learn more  Sign in to GitHub

        Push the note to GitHub Push to GitHub Pull a file from GitHub

          Authorize again
         

        Choose which file to push to

        Select repo
        Refresh Authorize more repos
        Select branch
        Select file
        Select branch
        Choose version(s) to push
        • Save a new version and push
        • Choose from existing versions
        Include title and tags
        Available push count

        Pull from GitHub

         
        File from GitHub
        File from HackMD

        GitHub Link Settings

        File linked

        Linked by
        File path
        Last synced branch
        Available push count

        Danger Zone

        Unlink
        You will no longer receive notification when GitHub file changes after unlink.

        Syncing

        Push failed

        Push successfully