Find the answer to your Linux question:
Results 1 to 6 of 6
CPU - Intel x86 Quick Question.... In Linux the only segment register used are %cs, %ss and %ds and these are represented with the macros __KERNEL_CS, __KERNEL_DS, __USER_CS, __USER_DS (intel ...
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1
    Linux Enthusiast gerard4143's Avatar
    Join Date
    Dec 2007
    Location
    Canada, Prince Edward Island
    Posts
    714

    es register what do you do?


    CPU - Intel x86

    Quick Question....

    In Linux the only segment register used are %cs, %ss and %ds and these are represented with
    the macros __KERNEL_CS, __KERNEL_DS, __USER_CS, __USER_DS (intel 32 bit). Now
    I have no problems with this concept and I understand how the %cs, %ss and %ds registers
    switch between user to kernel and back again...what I do have problems understanding is the %es register
    and how it fits into this picture as you can see in this code snippet from a entry.S file the %es register
    is not only saved it is loaded with the __KERNEL_DS value....Thank-you for any replies Gerard4143

    Code:
    #define SAVE_ALL \
    cld; \
    pushl %es; \
    pushl %ds; \
    pushl %eax; \
    pushl %ebp; \
    pushl %edi; \
    pushl %esi; \
    pushl %edx; \
    pushl %ecx; \
    pushl %ebx; \
    movl $(__KERNEL_DS),%edx; \
    movl %edx,%ds; \
    movl %edx,%es;
    Make mine Arch Linux

  2. #2
    Just Joined!
    Join Date
    Mar 2009
    Location
    Norway
    Posts
    67
    AFAIK, there are 6 segment regs, but only 3 have a dedicated purpose (cs, ds and ss). The remaining 3 (es, fs, gs) can be used for whatever you like, basically. So, no macro has been defined to save/restore or get the contents of these, but the kernel must handle it anyway.

    As to why SAVE_ALL only handles es, I do not really know. According to the great book (UTLK 3rd ed), es is used 'for pointers to user data structures (the kernel explicitly uses the es register)'

    Did this answer your question?

  3. #3
    Linux Enthusiast gerard4143's Avatar
    Join Date
    Dec 2007
    Location
    Canada, Prince Edward Island
    Posts
    714
    Quote Originally Posted by henrikau View Post
    As to why SAVE_ALL only handles es, I do not really know. According to the great book (UTLK 3rd ed), es is used 'for pointers to user data structures (the kernel explicitly uses the es register)'

    Did this answer your question?
    Well yes and no...If __KERNEL_DS loads the %ds structure with its value(base address 0x00000000 and limit 0xfffff) then why would you need %es to point to user data structures?

    Thank-you for the reply...Gerard4143
    Make mine Arch Linux

  4. $spacer_open
    $spacer_close
  5. #4
    Linux Enthusiast gerard4143's Avatar
    Join Date
    Dec 2007
    Location
    Canada, Prince Edward Island
    Posts
    714
    Quote Originally Posted by henrikau View Post
    for pointers to user data structures
    Just clarification....by user data structures do you mean the user data structures located in the user kernel stack or just user data? ...Gerard4143
    Make mine Arch Linux

  6. #5
    Just Joined!
    Join Date
    Mar 2009
    Location
    Norway
    Posts
    67
    Quote Originally Posted by gerard4143 View Post
    Just clarification....by user data structures do you mean the user data structures located in the user kernel stack or just user data? ...Gerard4143
    by user data structures, I mean what UTLK said
    Section 2.3.* Segmentation in Linux

    Try asking this on kernelnewbies, lots of skilled aspiring (and seasoned) hackers there

  7. #6
    Linux Enthusiast gerard4143's Avatar
    Join Date
    Dec 2007
    Location
    Canada, Prince Edward Island
    Posts
    714
    Quote Originally Posted by henrikau View Post
    Try asking this on kernelnewbies, lots of skilled aspiring (and seasoned) hackers there
    Thank-you for the link and the advice...kernelnewbies I'll check it out...Gerard4143
    Make mine Arch Linux

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •