OSDev.org
https://forum.osdev.org/

[Solved] Yield function with Trap Gate
https://forum.osdev.org/viewtopic.php?f=1&t=33428
Page 1 of 1

Author:  gardinirafael [ Thu Jan 10, 2019 8:18 pm ]
Post subject:  [Solved] Yield function with Trap Gate

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.

Author:  kzinti [ Thu Jan 10, 2019 9:47 pm ]
Post subject:  Re: Yield function with Trap Gate

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
}

Author:  gardinirafael [ Thu Jan 10, 2019 10:45 pm ]
Post subject:  Re: Yield function with Trap Gate

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

Author:  Octocontrabass [ Fri Jan 11, 2019 4:34 am ]
Post subject:  Re: Yield function with Trap Gate

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.

Author:  gardinirafael [ Fri Jan 11, 2019 7:14 am ]
Post subject:  Re: Yield function with Trap Gate

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

Page 1 of 1 All times are UTC - 6 hours
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
http://www.phpbb.com/