OSDev.org

The Place to Start for Operating System Developers
It is currently Tue Apr 23, 2024 12:36 am

All times are UTC - 6 hours




Post new topic Reply to topic  [ 5 posts ] 
Author Message
 Post subject: GDT Tutorial Clarification
PostPosted: Fri Dec 02, 2016 4:56 pm 
Offline

Joined: Fri Dec 02, 2016 4:42 pm
Posts: 2
Why in none of the example functions for setGdt in the GDT tutorial is there a line for push ebp? I guess I'm just confused since I thought when calling a function from C that the ebp value had to be pushed on the stack to save the frame pointer.


Top
 Profile  
 
 Post subject: Re: GDT Tutorial Clarification
PostPosted: Fri Dec 02, 2016 5:09 pm 
Offline
Member
Member

Joined: Sat Mar 28, 2015 11:23 am
Posts: 103
xls10 wrote:
Why in none of the example functions for setGdt in the GDT tutorial is there a line for push ebp? I guess I'm just confused since I thought when calling a function from C that the ebp value had to be pushed on the stack to save the frame pointer.


Hi,

Stack frames aren't exactly needed when you're calling functions from C. Sometimes they're even eliminated for optimization purposes. Stack frames (what your push %ebp; mov %esp, %ebp; and pop %ebp are setting up) are usually just a debugging feature for you to be able to trace the stack. So yeah, it's safe to not include push %ebp; although there's no harm in including it as well.

_________________
If some of you people keep insisting on having backwards compatibitity with the stone age, we'll have stone tools forever.
My Hobby OS: https://github.com/heatd/Onyx


Top
 Profile  
 
 Post subject: Re: GDT Tutorial Clarification
PostPosted: Fri Dec 02, 2016 5:15 pm 
Offline

Joined: Fri Dec 02, 2016 4:42 pm
Posts: 2
Oh I see. I'm just starting to learn how to write assembly callable from C and all of the examples I've seen have that function preamble which includes push ebp. In what cases would absolutely need to have it? Would it be when the function needs to use variables local to the called function? Thanks for the reply though!


Top
 Profile  
 
 Post subject: Re: GDT Tutorial Clarification
PostPosted: Fri Dec 02, 2016 6:22 pm 
Offline
Member
Member

Joined: Sat Mar 28, 2015 11:23 am
Posts: 103
xls10 wrote:
Oh I see. I'm just starting to learn how to write assembly callable from C and all of the examples I've seen have that function preamble which includes push ebp. In what cases would absolutely need to have it? Would it be when the function needs to use variables local to the called function? Thanks for the reply though!


For your assembly function to be callable from C, you essentially need to respect your compiler's ABI. That means that if you're using the SYSV ABI, you need to respect it(saving the registers specified by the ABI, for example).

But yeah, I think you can access local variables without ebp. If I recall correctly, it's only for debugging purposes(take that with a grain of salt though).

_________________
If some of you people keep insisting on having backwards compatibitity with the stone age, we'll have stone tools forever.
My Hobby OS: https://github.com/heatd/Onyx


Top
 Profile  
 
 Post subject: Re: GDT Tutorial Clarification
PostPosted: Sat Dec 03, 2016 3:12 am 
Offline
Member
Member

Joined: Wed Oct 01, 2008 1:55 pm
Posts: 3192
It depends on the C compiler. A few compilers have ways to specify how parameters are passed, and some even allow you to do this for each function, and allow you to use registers instead of the stack.


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

All times are UTC - 6 hours


Who is online

Users browsing this forum: Bing [Bot] and 100 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