OSDev.org

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

All times are UTC - 6 hours




Post new topic Reply to topic  [ 3 posts ] 
Author Message
 Post subject: Thoughts on IST vs no-redzone
PostPosted: Sat Apr 09, 2022 3:31 pm 
Offline
Member
Member

Joined: Thu Sep 27, 2018 5:10 pm
Posts: 28
Location: Turkey
Hi,

I was working my first osdev project for last one month or so. It was supposed to be 32 bits kernel. I did some initial work such as, setting up GDT, IDT, enabling paging, printf etc. Now I want to start an 64 bit kernel osdev project before I invest too much into 32 bit kernel because it is becoming an obsolete technology (or should I say it is an obsolete technology). Anyways...

I was reading about 64 bit kernels and how it is different than 32 bit ones, I came across this red-zone problem in System V 64 bit ABI. As far as I can see, people recommend -mno-red-zone flag while compiling kernels both in forums and in wiki.

But, it looks like you can specify alternative stack when using 64 bit version of IDT entries. You do this by filling IST bits of IDT entries with number 1 to 7. This number used as an index into Interrupt Stack Table (IST) which is located in 64 bit version of TSS.

I didn't actually try this yet, but it seems like a possible solution for interrupts trashing red-zone. Is there a reason why this is not often mentioned in forums or wiki? Was this overlooked, or simply recommended against. If so, what are the potential drawbacks of using IST with red-zone enabled.

Best Regards,


Top
 Profile  
 
 Post subject: Re: Thoughts on IST vs no-redzone
PostPosted: Sat Apr 09, 2022 4:05 pm 
Offline
Member
Member

Joined: Mon Mar 25, 2013 7:01 pm
Posts: 5100
Interrupts that share an IST entry can't nest. The later interrupt will overwrite the earlier interrupt's stack. You also only get seven IST entries, and you probably want to reserve some of those for things like NMI and double faults.

If those aren't a problem for your OS, then go ahead and use the IST.


Top
 Profile  
 
 Post subject: Re: Thoughts on IST vs no-redzone
PostPosted: Sat Apr 09, 2022 10:19 pm 
Offline
Member
Member

Joined: Wed Aug 30, 2017 8:24 am
Posts: 1593
Yup, as Octo said, the problem is that IST interrupts don't stack. The stack pointer is just hard reloaded with the value from the TSS, and if it already was in use then whatever was there before is now gone. PowerPC has a similar problem, but at least in PowerPC you can recognize the situation and panic accordingly. Here, you cannot recognize that this has taken place, and you will end up in an infinite loop

In practice, though, the absence of a red-zone in kernel is of little concern. Some functions may need a sub/add pair more than if they could utilize it. In a cost-benefit analysis, making it entirely impossible to stack faults and interrupts is probably not worth the instruction savings. There's libgcc, of course, but in practice I just don't link it in, because I don't want to faff about with multilib, and so far have not gotten a linker error. I figure, if I ever do something that requires a libgcc call, I can research the function called and write a quick version in assembler. I don't need it to be fast, only correct.

_________________
Carpe diem!


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

All times are UTC - 6 hours


Who is online

Users browsing this forum: DotBot [Bot], Google [Bot], SanderR, SemrushBot [Bot] and 59 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