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.
[Solved] Yield function with Trap Gate
-
- Posts: 21
- Joined: Mon Feb 03, 2014 12:52 pm
[Solved] Yield function with Trap Gate
Last edited by gardinirafael on Fri Jan 11, 2019 7:33 am, edited 2 times in total.
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:
For example:
Code: Select all
static void pic_interrupt_handler()
{
pic_eoi(); // end-of-interrupt
thread_yield(); // call scheduler to yield the current thread
}
-
- Posts: 21
- Joined: Mon Feb 03, 2014 12:52 pm
Re: Yield function with Trap Gate
Yes, I tried but for something reason my Yield function doesn't work without EOI, and eoi only be sent on IRQ scope right?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 }
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
-
- Member
- Posts: 5586
- Joined: Mon Mar 25, 2013 7:01 pm
Re: Yield function with Trap Gate
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 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?\
-
- Posts: 21
- Joined: Mon Feb 03, 2014 12:52 pm
Re: Yield function with Trap Gate
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.Octocontrabass wrote: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 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?\
So, now the function works. Thank you kzinti and Octocontrabass.