OSDev.org

The Place to Start for Operating System Developers
It is currently Tue Apr 16, 2024 7:03 am

All times are UTC - 6 hours




Post new topic Reply to topic  [ 9 posts ] 
Author Message
 Post subject: Switching tasks suspends interrupts
PostPosted: Thu Jul 09, 2020 10:43 am 
Offline
Member
Member
User avatar

Joined: Sun Jul 21, 2019 7:34 am
Posts: 300
Hi.
I have problems after my scheduler switches the task.
Using the task_switch(), the control is passed to the task01() function, the problem is that after the task01() ends, the control is not returned back(I expect the control to return to the pit_handler())
But this is not the main problem, the main oddity is that interrupts stop working when the task01() function is called, even though the interrupt flag is set. I have no guesses as to why task switching suspends interrupts.
What's going wrong?


Top
 Profile  
 
 Post subject: Re: Switching tasks suspends interrupts
PostPosted: Thu Jul 09, 2020 11:12 am 
Offline
Member
Member

Joined: Mon Mar 25, 2013 7:01 pm
Posts: 5134
You switch tasks before sending the EOI, so the PIC thinks you're still handling IRQ0, and won't allow another IRQ0 or any lower-priority IRQs to occur.

Since IRQ0 is the highest priority, there are no other IRQs that can occur.


Top
 Profile  
 
 Post subject: Re: Switching tasks suspends interrupts
PostPosted: Thu Jul 09, 2020 11:48 am 
Offline
Member
Member
User avatar

Joined: Thu Oct 13, 2016 4:55 pm
Posts: 1584
Octocontrabass wrote:
You switch tasks before sending the EOI, so the PIC thinks you're still handling IRQ0, and won't allow another IRQ0 or any lower-priority IRQs to occur.

Since IRQ0 is the highest priority, there are no other IRQs that can occur.
I agree. The OP is missing a proper EOI.

Cheers,
bzt


Top
 Profile  
 
 Post subject: Re: Switching tasks suspends interrupts
PostPosted: Thu Jul 09, 2020 1:44 pm 
Offline
Member
Member
User avatar

Joined: Sun Jul 21, 2019 7:34 am
Posts: 300
Exactly, you're right.

But, how can I get the return statement in task01() to return control back to pit_handler()?


Top
 Profile  
 
 Post subject: Re: Switching tasks suspends interrupts
PostPosted: Thu Jul 09, 2020 2:05 pm 
Offline
Member
Member

Joined: Mon Mar 25, 2013 7:01 pm
Posts: 5134
Set up the stack so the function will return to a function that performs the "end task" system call. The "end task" system call will remove the task from the queue, clean up (or enqueue deferred cleanup), and switch to another task in the queue.

One of the tasks in the queue is the one that switched tasks in the middle of pit_handler(). When you switch to that task, you'll return control to pit_handler().

You cannot return control to pit_handler() without another task switch.


Top
 Profile  
 
 Post subject: Re: Switching tasks suspends interrupts
PostPosted: Fri Jul 10, 2020 3:27 am 
Offline
Member
Member
User avatar

Joined: Sun Jul 21, 2019 7:34 am
Posts: 300
Octocontrabass wrote:
Set up the stack so the function will return to a function that performs the "end task" system call. The "end task" system call will remove the task from the queue, clean up (or enqueue deferred cleanup), and switch to another task in the queue.

One of the tasks in the queue is the one that switched tasks in the middle of pit_handler(). When you switch to that task, you'll return control to pit_handler().

You cannot return control to pit_handler() without another task switch.


I realized that I think using system calls will be even more convenient.

The main difficulty will be that OS will need to monitor the presence of the system call "end_task ()" instead of return () in user programs, because if it is not there, the program will hang in the queue.


Top
 Profile  
 
 Post subject: Re: Switching tasks suspends interrupts
PostPosted: Fri Jul 10, 2020 3:52 am 
Offline
Member
Member
User avatar

Joined: Sat Mar 31, 2012 3:07 am
Posts: 4594
Location: Chichester, UK
When you compile programs for your OS you should include startup code that calls "main()" and, on return calls your end_task() (more usually called _exit()) system call. It would be poor design to require the programmer to insert the system call at the end of every program. Always let the compiler do any standard work rather than relying on the programmer.


Top
 Profile  
 
 Post subject: Re: Switching tasks suspends interrupts
PostPosted: Fri Jul 10, 2020 4:02 am 
Offline
Member
Member
User avatar

Joined: Sun Jul 21, 2019 7:34 am
Posts: 300
iansjack wrote:
When you compile programs for your OS you should include startup code that calls "main()" and, on return calls your end_task() (more usually called _exit()) system call. It would be poor design to require the programmer to insert the system call at the end of every program. Always let the compiler do any standard work rather than relying on the programmer.

I think I can get the compiler to insert "_exit()" instead of "return" in the required places so that the program ends correctly.


Last edited by mrjbom on Fri Jul 10, 2020 7:12 am, edited 1 time in total.

Top
 Profile  
 
 Post subject: Re: Switching tasks suspends interrupts
PostPosted: Fri Jul 10, 2020 6:30 am 
Offline
Member
Member

Joined: Tue Feb 18, 2020 3:29 pm
Posts: 1071
What happens is main() is called by the runtime. The runtime is the first code executed in an app, and it is a part libc. It calls global constructors, creates a heap, and calls main. main returns when execution is over and returns a value. It actually returns to the runtime. The runtime destroys its heap, calls global destructors, and lastly calls _exit() to exit the app/

_________________
"How did you do this?"
"It's very simple — you read the protocol and write the code." - Bill Joy
Projects: NexNix | libnex | nnpkg


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

All times are UTC - 6 hours


Who is online

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