OSDev.org

The Place to Start for Operating System Developers
It is currently Thu Apr 18, 2019 9:09 am

All times are UTC - 6 hours




Post new topic Reply to topic  [ 5 posts ] 
Author Message
 Post subject: [Solved] Yield function with Trap Gate
PostPosted: Thu Jan 10, 2019 8:18 pm 
Offline

Joined: Mon Feb 03, 2014 12:52 pm
Posts: 21
Hi guys
I have a question about yield function that I need to create. My kernel has support to x86 and Arm Cortex M3 and both arch uses the same function to choose witch task needs to run.

In x86 the PIT calls the function that save, choose and restore context and the Arm doing the same using Systick and PendSV interrupts.

In the arm case make Yield functions is easy, I need fill a register with value and processor calls PendSV that save, choose etc...

So, my question is, can I make a trap gate with function that PIT calls and In my yield function just call int 0x79 or any of interruprs avaliable? like syscall

Is a good decision? or bad design?

I thought in this way because is very simple to implement.

Thanks.


Last edited by gardinirafael on Fri Jan 11, 2019 7:33 am, edited 2 times in total.

Top
 Profile  
 
 Post subject: Re: Yield function with Trap Gate
PostPosted: Thu Jan 10, 2019 9:47 pm 
Offline
Member
Member

Joined: Mon Feb 02, 2015 7:11 pm
Posts: 294
Wouldn't it make sense to just have the PIC interrupt handler call your thread_yield() function?

For example:

Code:
static void pic_interrupt_handler()
{
    pic_eoi();         // end-of-interrupt
    thread_yield();    // call scheduler to yield the current thread
}

_________________
https://github.com/kiznit/rainbow-os


Top
 Profile  
 
 Post subject: Re: Yield function with Trap Gate
PostPosted: Thu Jan 10, 2019 10:45 pm 
Offline

Joined: Mon Feb 03, 2014 12:52 pm
Posts: 21
kzinti wrote:
Wouldn't it make sense to just have the PIC interrupt handler call your thread_yield() function?

For example:

Code:
static void pic_interrupt_handler()
{
    pic_eoi();         // end-of-interrupt
    thread_yield();    // call scheduler to yield the current thread
}


Yes, I tried but for something reason my Yield function doesn't work without EOI, and eoi only be sent on IRQ scope right?
So I thought to use the same interrupt structure with trap gate thinking in reuse code but my function below probably wrong.

Your tip will be perfect if my function below works without EOI.

Code:
.extern gos_task_schedule
.global gos_port_yield
gos_port_yield:
    cli
    push $0
    push $0
    pusha
    push %ds
    push %es
    push %fs
    push %gs
    movw $0x10, %ax
    movw %ax, %ds
    movw %ax, %es
    movw %ax, %fs
    movw %ax, %gs
    movl %esp, %eax
    push %eax
    call gos_task_schedule
   movl %eax, %esp
    /* ----         ----
   movb $0x20, %al
   out %al, $0x20
    */
    pop %gs
    pop %fs
    pop %es
    pop %ds
    popa
    addl $8, %esp
    sti
    retl


Top
 Profile  
 
 Post subject: Re: Yield function with Trap Gate
PostPosted: Fri Jan 11, 2019 4:34 am 
Offline
Member
Member

Joined: Mon Mar 25, 2013 7:01 pm
Posts: 1497
gardinirafael wrote:
Yes, I tried but for something reason my Yield function doesn't work without EOI, and eoi only be sent on IRQ scope right?\

Are you calling Yield in an IRQ handler before you do EOI? If so, that's why it's not working. IRQ handlers must send EOI before they yield.


Top
 Profile  
 
 Post subject: Re: Yield function with Trap Gate
PostPosted: Fri Jan 11, 2019 7:14 am 
Offline

Joined: Mon Feb 03, 2014 12:52 pm
Posts: 21
Octocontrabass wrote:
gardinirafael wrote:
Yes, I tried but for something reason my Yield function doesn't work without EOI, and eoi only be sent on IRQ scope right?\

Are you calling Yield in an IRQ handler before you do EOI? If so, that's why it's not working. IRQ handlers must send EOI before they yield.


Unfortunately, I'm not. I saw the kzinti code above and I didn't realize that I changed the order of calls. My EOI was being called after yield function, not before like both of you said.

So, now the function works. Thank you kzinti and Octocontrabass. =D> :D


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: No registered users and 11 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