[SOLVED] IRET only pops SS:ESP on privilege change?
Posted: Thu Sep 15, 2011 3:00 pm
I'm back. I got frustrated, and had to take some time off of this project for a while. I had stared too long then I ended up having to reinstall my system... so you get the picture. Haha
Anyways, since then, I have rewritten Multitasking code with a simpler concept. I was having problems, and so I decided to dump the priorities until I get a better grasp on what exactly I'm doing wrong. So right now, I just have a one priority, and an idle task. As simple as you can get (aside from monotasking )
Well, my scheduler is actually working. It switches task, and I have also written a nice little set of console buffer functions so each task has it's own buffer, and can flush it whenever it likes, but I run into a problem after the first task switch. I realized that errors were stemming from the fact that all my tasks were using the same stack! I have my register state set up correctly (I have checked it in the debugger) and I even check the register structure passed to my IRQ handler that it's value is getting set and it is. Everything is set correctly, but IRET isn't popping ESP (and therefore SS either). When I return to a task, if I break, and dump a backtrace with GDB I get:
#1 0xb0000000 in ?? ()
and of course #0 is the current frame. So I have concluded that IRET isn't popping ESP, and leaving it on the stack. Anybody have any more ideas on why it would do this? My understanding is that IRET does this:
pop eip
pop cs
pop eflags
pop esp
pop ss
I have done searching but found nothing on this being a problem, so either I'm doing something wrong or there is a common solution that I'm missing. lol
EDIT:
well right as I posted this, I switched tabs to read a page I had just opened (the tech. specs. of IRET/IRETD) and it seems IRET only pops ESP/SS if there is a privilege change! Anybody know how to get around that??? Or a better way to switch the stacks? I can't think of one off the top of my head, but I will be trying... lol
Anyways, since then, I have rewritten Multitasking code with a simpler concept. I was having problems, and so I decided to dump the priorities until I get a better grasp on what exactly I'm doing wrong. So right now, I just have a one priority, and an idle task. As simple as you can get (aside from monotasking )
Well, my scheduler is actually working. It switches task, and I have also written a nice little set of console buffer functions so each task has it's own buffer, and can flush it whenever it likes, but I run into a problem after the first task switch. I realized that errors were stemming from the fact that all my tasks were using the same stack! I have my register state set up correctly (I have checked it in the debugger) and I even check the register structure passed to my IRQ handler that it's value is getting set and it is. Everything is set correctly, but IRET isn't popping ESP (and therefore SS either). When I return to a task, if I break, and dump a backtrace with GDB I get:
#1 0xb0000000 in ?? ()
and of course #0 is the current frame. So I have concluded that IRET isn't popping ESP, and leaving it on the stack. Anybody have any more ideas on why it would do this? My understanding is that IRET does this:
pop eip
pop cs
pop eflags
pop esp
pop ss
I have done searching but found nothing on this being a problem, so either I'm doing something wrong or there is a common solution that I'm missing. lol
EDIT:
well right as I posted this, I switched tabs to read a page I had just opened (the tech. specs. of IRET/IRETD) and it seems IRET only pops ESP/SS if there is a privilege change! Anybody know how to get around that??? Or a better way to switch the stacks? I can't think of one off the top of my head, but I will be trying... lol