OSDev.org

The Place to Start for Operating System Developers
It is currently Thu Mar 28, 2024 5:15 pm

All times are UTC - 6 hours




Post new topic Reply to topic  [ 4 posts ] 
Author Message
 Post subject: Segment Registers in 64bit
PostPosted: Thu Oct 29, 2015 10:42 am 
Offline
Member
Member

Joined: Fri Feb 15, 2013 9:29 pm
Posts: 35
Is there any reason that ES, FS, and GS cannot be used as a random place to store data in 64bit mode?

_________________
Programming is like fishing, you must be very patient if you want to succeed.


Top
 Profile  
 
 Post subject: Re: Segment Registers in 64bit
PostPosted: Thu Oct 29, 2015 10:57 am 
Offline
Member
Member
User avatar

Joined: Sat Mar 31, 2012 3:07 am
Posts: 4591
Location: Chichester, UK
Why just 64-bit mode? This would be even more useful in 32- or 16-bit modes, where you have less general-purpose registers available. But I believe that loading a segment register is a relatively expensive operation, so it may not be very efficient. And the fact that you can only write and read them makes them less useful.

You do already have an additional 8 general-purpose registers available in 64-bit mode.


Top
 Profile  
 
 Post subject: Re: Segment Registers in 64bit
PostPosted: Thu Oct 29, 2015 11:51 am 
Offline
Member
Member

Joined: Fri Feb 15, 2013 9:29 pm
Posts: 35
I was just thinking about using them as a place to cache parts of a register during certain operations. But the fact that there is still the overhead of them in 64bit mode was not something that I thought of and is a really good reason to not use them.

_________________
Programming is like fishing, you must be very patient if you want to succeed.


Top
 Profile  
 
 Post subject: Re: Segment Registers in 64bit
PostPosted: Fri Oct 30, 2015 3:59 am 
Offline
Member
Member

Joined: Thu Jul 05, 2012 5:12 am
Posts: 923
Location: Finland
I have thought this idea sometimes. If the global descriptor table contained duplicate entries, you could use the index value for storing data. It is not efficient but still one option. Untested example below.

Code:
; Input: al = byte
PutByteRegisterDs:
    shl ax, 8                   ; ah = input byte
    mov al, (DATA_SEGMENT)      ; ax = segment selector
    mov ds, ax
    ret

; Output: al = byte
GetByteRegisterDs:
    mov ax, ds                  ; ax = segment selector
    shr ax, 8                   ; al = return byte
    ret

_________________
Undefined behavior since 2012


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 4 posts ] 

All times are UTC - 6 hours


Who is online

Users browsing this forum: Bing [Bot], Google [Bot] and 25 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group