김재우
    • Create new note
    • Create a note from template
      • 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
        • Only me
        • Signed-in users
        • Everyone
        Only me Signed-in users Everyone
      • Write
        • Only me
        • Signed-in users
        • Everyone
        Only me 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

      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.
      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
    • Save as template
    • 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 Create Help
Create Create new note Create a note from template
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
Only me
  • Only me
  • Signed-in users
  • Everyone
Only me Signed-in users Everyone
Write
Only me
  • Only me
  • Signed-in users
  • Everyone
Only me 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

    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.
    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
    # JOS Lab 1 3. - The transition happens by a Ljump. (`boot.S:99 - ljmp $PROT_MODE_CSEG, $protcseg`) The first instruction after the LJump (shown below) is the first instruction that is first exectued in 32-bit mode. `movw $PROT_MODE_DSEG, %ax`. - Before the ljump, the processor was set to protected mode by modifying the %cr0 register. - Ljump in protected mode behaves differently from when it is in a real mode. The code segment operand($PROT_MODE_CSEG, or equally 0x8, in this case) is interpreted as a code segment selector. Ljump will use the selector to grap segment descriptor from the global descriptor table. The grapped segment descriptor includes information about the segment, particulary the type of the segment, e.g. whether the segment is a code segment or a data segment, whether the segment is 16-bit or 32-bit. Ljump in our case will read the segment descriptor, and after figuring out that the segment is a 32-bit code segment, moves the processor to a 32-bit mode. - https://wiki.osdev.org/Segment_Selector - https://wiki.osdev.org/Global_Descriptor_Table - https://shell-storm.org/x86doc/JMP.html - The last instruction executed in the bootloader is as below \ `(main.c:65) 7dea: jmp *0x10018` - The first instruction executed in the kernel is as below \ `(bootstrap.S:22) movl $multiboot_info, %eax` - Short answer: The bootloader finds out the location of the sectors to read using the information in file header and the program header table saved at the start of the disk. - The bootloader reads the first 8 sectors to load the file header and the program header table. The location of the file header is exactly at the beggining of the disk, so the bootloader can easily identify and read the file header. Using the file header, the bootloader finds out where and how long is the program header table, and read each entry one by one. Each entry contains the data about offset and number of sectors to read, and even where in the memory the data should be loaded. 5. `ljmp $PROT_MODE_CSEG, $protcseg`에서. $protcseg가 잘못된 값으로 되어 있음. 6. At the bootloader entrypoint. ``` (gdb) x/10x 0x100000 0x100000 <_head64>: 0x00000000 0x00000000 0x00000000 0x00000000 0x100010 <_head64+16>: 0x00000000 0x00000000 0x00000000 0x00000000 0x100020 <_head64+32>: 0x00000000 0x00000000 ``` At the kernel entrypoint ``` (gdb) x/10x 0x100000 0x100000 <_head64>: 0x107000b8 0x66188900 0x047205c7 0x12340000 0x100010 <_head64+16>: 0x007c00bc 0x00cce800 0x20b80000 0x0f000000 0x100020 <_head64+32>: 0x00bfe022 0x31001020 ``` It's different because the bootloader has loaded kernel into the address space. Since 0x100000 is the entrypoint of the kernel, the data loaded there will be the kernel codes to executed first, which will be the compiled output of kern/bootstrap.S. 7. - The new mapping takes effect when the PG flag of the cr0 register is set to true; that is, after the codes below are executed. `(kern/bootstrap.S:117) movl %eax,%cr0` `(kern/bootstrap.S:121) movl %eax,%cr0` - The GDT used in the kernel codes are as below in bootstrap.S ``` gdt_64: SEG_NULL .quad 0x00af9a000000ffff #64 bit CS .quad 0x00cf92000000ffff #64 bit DS ``` in entry.S ``` kernel_64: SEG_NULL SEG64(STA_X|STA_R,0x0,0xffffffff) #64 bit CS SEG64(STA_R|STA_W,0x0,0xffffffff) #64 bit DS SEG64USER(STA_X|STA_R,0x0,0xffffffff) #64 bit USER CS SEG64USER(STA_R|STA_W,0x0,0xffffffff) # USER data .quad 0x0080890000000000 /* TS descriptor */ .quad 0x0000000000000000 /* TS continued */ ``` If you interpret the GDT in bootstrap.S according to https://wiki.osdev.org/Global_Descriptor_Table, the upper GDT entry is a 64-bit code segment, and the lower is a 32-bit data segment(contrary to the comment), both with base of 0 and limit of 0xffffffff. All the segments cover all the memory space with base 0. This means that we will not be using memory segmentation and all the addresses will be interpreted and protected only by paging. 9. Initialized here. ``` # entry.S:70 # Set the stack pointer movabs $(bootstacktop),%rax movq %rax,%rsp ``` ``` # entry.S:82 .data ################################################################### # boot stack ################################################################### .p2align PGSHIFT # force page alignment .globl bootstack bootstack: .space KSTKSIZE .globl bootstacktop bootstacktop: ``` At the .data section of the kernel program, a memory of size KSTKSIZE is reserved for the stack. The stack pointer is initialized to point at the top end (where the address is highest). 10. 4 64-bit words

    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

    By clicking below, you agree to our terms of service.

    Sign in via Facebook Sign in via Twitter Sign in via GitHub Sign in via Dropbox Sign in with Wallet
    Wallet ( )
    Connect another wallet

    New to HackMD? Sign up

    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