OSDev.org

The Place to Start for Operating System Developers
It is currently Thu Mar 28, 2024 4:22 am

All times are UTC - 6 hours




Post new topic Reply to topic  [ 13 posts ] 
Author Message
 Post subject: [Solved] Consistent System Calls
PostPosted: Mon Jan 14, 2013 7:32 am 
Offline
Member
Member
User avatar

Joined: Wed Feb 09, 2011 2:21 am
Posts: 87
Location: Raipur, India
It came to my attention a while ago that there are major differences in the Intel implementation and AMD implementation of x86-64.
Intel processors do not have SYSCFG, TOP_MEM, etc; not a very big deal as one can live without them. But the one thing that irritates me most is the way of doing system calls.
Intel processors allow SYSENTER and SYSEXIT in both sub-modes of long-mode; and allows SYSCALL and SYSRET only in 64bit mode.
AMD do not allow SYSENTER and SYSEXIT in any sub-mode of long mode.

If I understand correctly, that would create a problem for writing the standard library as one will have to create 2 versions of it. One using SYSENTER/SYSEXIT, the other using SYSCALL/SYSRET. Also, the OS will need to install the correct version.
Is there a good way of getting around this problem other than using INT?

_________________
Always give a difficult task to a lazy person. He will find an easy way to do it.


Last edited by trinopoty on Mon Jan 14, 2013 10:29 pm, edited 1 time in total.

Top
 Profile  
 
 Post subject: Re: Consistent System Calls
PostPosted: Mon Jan 14, 2013 7:42 am 
Offline
Member
Member
User avatar

Joined: Wed Dec 01, 2010 3:41 am
Posts: 1761
Location: Hong Kong
Try break down the problem into kernel and user land.

For kernel, it's probably good and trivial to setup all syscall stub entries if available (syscall, sysenter, optionally INT)

For userland, you may have one single syscall() interface in a system library, and possible multiple versions for different mechanism (eg. /usr/arch/i386/lib/syscall.so and /usr/arch/x86_64/lib/syscall.so), the correct version can be linked to application on load time.


Top
 Profile  
 
 Post subject: Re: Consistent System Calls
PostPosted: Mon Jan 14, 2013 10:08 am 
Offline
Member
Member
User avatar

Joined: Wed Feb 09, 2011 2:21 am
Posts: 87
Location: Raipur, India
Linking the correct version at load isn't required, the correct version needs to be copied during the install process.
Basically, copy the SYSENTER/SYSEXIT version if Intel processor; copy the SYSCALL/SYSRET version if AMD processor.

By version, I mean whether the library uses SYSENTER/SYSEXIT or SYSCALL/SYSRET.

_________________
Always give a difficult task to a lazy person. He will find an easy way to do it.


Top
 Profile  
 
 Post subject: Re: Consistent System Calls
PostPosted: Mon Jan 14, 2013 12:06 pm 
Offline
Member
Member
User avatar

Joined: Wed Dec 01, 2010 3:41 am
Posts: 1761
Location: Hong Kong
If you feel good when the theoretical user upgrade his computer (which was using sysenter, set by installer) to a new computer (which cannot use sysenter)...

IMO, that code is tiny and it's trivial to support them all with some detections, you want to do it for CPU extensions anyway (MMX, SSE, etc).
It may be a be tricky to do it elegantly.


Top
 Profile  
 
 Post subject: Re: Consistent System Calls
PostPosted: Mon Jan 14, 2013 12:12 pm 
Offline
Member
Member
User avatar

Joined: Wed Dec 01, 2010 3:41 am
Posts: 1761
Location: Hong Kong
By the way, the other approach is to catch the #UD and emulate it.


Top
 Profile  
 
 Post subject: Re: Consistent System Calls
PostPosted: Mon Jan 14, 2013 1:11 pm 
Offline
Member
Member
User avatar

Joined: Wed Feb 09, 2011 2:21 am
Posts: 87
Location: Raipur, India
One does not simple upgrade to a new processor without reinstalling the OS.

_________________
Always give a difficult task to a lazy person. He will find an easy way to do it.


Top
 Profile  
 
 Post subject: Re: Consistent System Calls
PostPosted: Mon Jan 14, 2013 1:20 pm 
Offline
Member
Member
User avatar

Joined: Wed Feb 13, 2008 9:38 am
Posts: 138
Why don't you just use SYSENTER/SYSEXIT in i386 mode and SYSCALL/SYSRET in amd64 mode?


Top
 Profile  
 
 Post subject: Re: Consistent System Calls
PostPosted: Mon Jan 14, 2013 1:22 pm 
Offline
Member
Member
User avatar

Joined: Sat Jul 30, 2011 10:07 am
Posts: 374
Location: Wrocław/Racibórz, Poland
Why don't you just leave support for pmode away? :lol:

_________________
Reaver Project :: Repository :: Ohloh project page
<klange> This is a horror story about what happens when you need a hammer and all you have is the skulls of the damned.
<drake1> as long as the lock is read and modified by atomic operations


Top
 Profile  
 
 Post subject: Re: Consistent System Calls
PostPosted: Mon Jan 14, 2013 1:49 pm 
Offline
Member
Member
User avatar

Joined: Wed Dec 01, 2010 3:41 am
Posts: 1761
Location: Hong Kong
trinopoty wrote:
One does not simple upgrade to a new processor without reinstalling the OS.


This is not required by Windows, Linux(2.6+), BSD(6+), Mac, and Solaris 9+ (intel version). And my personal experience is that my server machine running FreeBSD 6.2 has be upgrade passed a few processor generations without reinstalling nor "update world", until I was bored enough to upgrade it to 9 recently.

Anyway, if you are talking about One does not simple upgrade to a new processor without reinstalling the(your) hobby OS - I agree and it is acceptable restriction, although this restriction can be avoided easily.


Top
 Profile  
 
 Post subject: Re: Consistent System Calls
PostPosted: Mon Jan 14, 2013 8:04 pm 
Offline
Member
Member

Joined: Sat Nov 21, 2009 5:11 pm
Posts: 852
It's trivial to place all the system calls together in a table, and initialize them according to what is needed. You can even do all this in C.


Top
 Profile  
 
 Post subject: Re: Consistent System Calls
PostPosted: Mon Jan 14, 2013 10:29 pm 
Offline
Member
Member
User avatar

Joined: Wed Feb 09, 2011 2:21 am
Posts: 87
Location: Raipur, India
Well, I agree that it is easy to keep all of it in the kernel. As for the user-mode library, I think i will write two versions of the syscall() function.

_________________
Always give a difficult task to a lazy person. He will find an easy way to do it.


Top
 Profile  
 
 Post subject: Re: Consistent System Calls
PostPosted: Wed Apr 24, 2013 3:22 am 
Offline
Member
Member

Joined: Wed Jul 18, 2007 5:51 am
Posts: 170
AMD were stupid in designing their version of AMD64.
They decided that SYSENTER/SYSEXIT won't work in compatibility mode, but will work in legacy mode (32 bit operating system).
There was no excuse for that design decision.

You have 32bit cpl3 code using SYSENTER that works perfectly ok when an AMD processor is running a 32 bit protected mode OS.
But the exact same 32bit cpl3 application code won't work ON THE SAME CPU when in 64 bit compatibility mode.
Absolutely atrocious. AMD can not make any justification for this.


Top
 Profile  
 
 Post subject: Re: [Solved] Consistent System Calls
PostPosted: Wed Apr 24, 2013 6:34 pm 
Offline

Joined: Thu Dec 13, 2012 3:24 am
Posts: 7
One Possibility is to have 1 Memorypage for the Systemcall in userspace
and 3 Pages with different Syscall/sysenter/int Options in your Kernelspace.
And - dependent on your CPU - you map one of those 3 Pages from your kernel into Userspace.
i'm not sure, but i think this is the way Windows kernel does.
(google Kernelbase.dll)

Best regards


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

All times are UTC - 6 hours


Who is online

Users browsing this forum: No registered users and 29 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