[Solved] Yield function with Trap Gate

Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
Post Reply
gardinirafael
Posts: 21
Joined: Mon Feb 03, 2014 12:52 pm

[Solved] Yield function with Trap Gate

Post by gardinirafael »

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.
kzinti
Member
Member
Posts: 898
Joined: Mon Feb 02, 2015 7:11 pm

Re: Yield function with Trap Gate

Post by kzinti »

Wouldn't it make sense to just have the PIC interrupt handler call your thread_yield() function?

For example:

Code: Select all

static void pic_interrupt_handler()
{
    pic_eoi();         // end-of-interrupt
    thread_yield();    // call scheduler to yield the current thread
}
gardinirafael
Posts: 21
Joined: Mon Feb 03, 2014 12:52 pm

Re: Yield function with Trap Gate

Post by gardinirafael »

kzinti wrote:Wouldn't it make sense to just have the PIC interrupt handler call your thread_yield() function?

For example:

Code: Select all

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: Select all

.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
Octocontrabass
Member
Member
Posts: 5586
Joined: Mon Mar 25, 2013 7:01 pm

Re: Yield function with Trap Gate

Post by Octocontrabass »

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.
gardinirafael
Posts: 21
Joined: Mon Feb 03, 2014 12:52 pm

Re: Yield function with Trap Gate

Post by gardinirafael »

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
Post Reply