Strange instruction pointer behaviour
Posted: Wed Nov 02, 2011 9:57 pm
Hello,
I am working on the multitasking in my kernel. My current sequence of events involves the following.
1. Allocate pages in order to map stack to 0xE0000000.
2. Call new_start
As you can see there, the new_main is called.
EIP somehow manages to get a sub-1MB pointer through it all.
The CPU issues interrupt 5 at 0x2c6e1
Thanks in advance for your help.
EDIT: Also, in case its needed my task switch code.
edit2: ecx should contain the correct eip when i jump to it as an int3 right before the jmp reports the correct address. I'm wondering whether the stack is set up properly. If it isn't how can I go about it?
I am working on the multitasking in my kernel. My current sequence of events involves the following.
1. Allocate pages in order to map stack to 0xE0000000.
2. Call new_start
Code: Select all
new_start: ; this switches to the new stack and calls new_main
cli
nop
mov esi, [esp+4]
mov esp, esi
mov ebp, esp
push esp
push ebp
sti
call new_main
jmp $
Code: Select all
int new_main() {
fs_root = (fs_node_t*) init_initrd(initrdloc);
init_tasking();
KB_Init();
int a = fork();
kprintf("%x\n", a);
return 0;
}
The CPU issues interrupt 5 at 0x2c6e1
Thanks in advance for your help.
EDIT: Also, in case its needed my task switch code.
Code: Select all
void switch_task() {
if(!cur_task) {
return;
}
#ifdef TASK_DEBUG
kprintf("switch_task()\n");
#endif
UInt32 esp, ebp, eip;
asm volatile("mov %%esp, %0" : "=r"(esp));
asm volatile("mov %%ebp, %0" : "=r"(ebp));
eip = read_eip();
if(eip == 0x12345) {
return;
}
kprintf("%x\n", eip);
cur_task->eip = eip;
cur_task->esp = esp;
cur_task->ebp = ebp;
cur_task = cur_task->next;
if(!cur_task) cur_task = ready_queue;
eip = cur_task->eip;
esp = cur_task->esp;
ebp = cur_task->ebp;
cur_dir = cur_task->pd;
#ifdef TASK_DEBUG
kprintf("eip,esp,ebp:%x,%x,%x\n", eip, esp, ebp);
#endif
asm volatile(" \
cli; \
mov %0, %%ecx; \
mov %1, %%esp; \
mov %2, %%ebp; \
mov %3, %%cr3; \
mov $0x12345, %%eax; \
sti; \
jmp *%%ecx "
: : "r"(eip), "r"(esp), "r"(ebp), "r"(cur_dir->phys));
}