Page 5 of 5
Re:tss on stack???
Posted: Thu Sep 22, 2005 6:56 pm
by GLneo
well, ok, i've updated my code to:
Code: Select all
struct stack_data *schedule(struct stack_data *regs)
{
cur_task_time_equ(get_pri_time(cur_task_pri()));
front_to_end();
return rrq[front].stack;
}
struct stack_data *task_timer_c(struct stack_data *regs)
{
clock();
outport(0x20, 0x20);
if(cur_task_time() > 0)
{
dec_cur_task_time();
return regs;
}
else
return schedule(regs);
}
void make_task(int pri, char *name, void (*entry)())
{
void *stack_mem;
struct stack_data *stack;
stack_mem = (unsigned int *)malloc(STACK_SIZE);
stack_mem += STACK_SIZE - sizeof(struct stack_data);
stack = stack_mem;
stack->gs = DATA_SEG;
stack->fs = DATA_SEG;
stack->es = DATA_SEG;
stack->ds = DATA_SEG;
stack->edi = 0;
stack->esi = 0;
stack->ebp = 0;
stack->esp = 0;
stack->ebx = 0;
stack->edx = 0;
stack->ecx = 0;
stack->eax = 0;
stack->eip = (unsigned int)entry;
stack->cs = KERNEL_CODE_SEG;
stack->eflags = 0x00000202;
strncpy(rrq[end].name, name, 32);
rrq[end].stack = stack;
rrq[end].ss = KERNEL_STACK_SEG;
rrq[end].priority = pri;
rrq[end].time = get_pri_time(pri);
end++;
}
but it says "in valaded opcode" i was thinking, at a fault where does the prosessor put the EIP of the error code???, thx
Re:tss on stack???
Posted: Thu Sep 22, 2005 10:34 pm
by Colonel Kernel
You're still setting esp to 0. Re-read my previous posts. This is probably the problem.
You didn't post the latest version of your stack_data struct, so I can't tell if EIP is in the right place or not. It pays to consult the Intel manuals...
Re:tss on stack???
Posted: Fri Sep 23, 2005 6:17 pm
by GLneo
so, for esp:
and my structs are:
Code: Select all
struct stack_data
{
unsigned int gs;
unsigned int fs;
unsigned int es;
unsigned int ds;
unsigned int edi;
unsigned int esi;
unsigned int ebp;
unsigned int esp;
unsigned int ebx;
unsigned int edx;
unsigned int ecx;
unsigned int eax;
unsigned int eip;
unsigned int cs;
unsigned int eflags;
};
struct task_data
{
char name[33];
struct stack_data *stack;
unsigned int ss;
unsigned int kstack;
unsigned int ustack;
unsigned int time;
unsigned int priority;
};
thx
Re:tss on stack???
Posted: Fri Sep 23, 2005 7:23 pm
by Colonel Kernel
GLneo wrote:
so, for esp:
Colonel Kernel wrote:According to the way that pusha works (remember, the Intel manuals are your friend), the value of ESP that gets pushed is the value that ESP was before pushing EAX (that is, before the pusha instruction began executing). So, it should point to the eip field of the stack_data struct.
Re:tss on stack???
Posted: Sat Sep 24, 2005 7:59 am
by GLneo
so esp = EIP; ???
Re:tss on stack???
Posted: Sat Sep 24, 2005 12:06 pm
by Colonel Kernel
Try this:
Code: Select all
stack->ebp = (unsigned int) stack + sizeof( struct stack_data );
stack->esp = (unsigned int) &(stack->eip);
I haven't tried this myself yet, so someone please correct me if I'm wrong here...
Re:tss on stack???
Posted: Sat Sep 24, 2005 5:54 pm
by GLneo
ok, i've done a little research, and it sayed that the return address is stored at ebp + 1 so should i do this:
Code: Select all
void make_task(int pri, char *name, void (*entry)())
{
void *stack_mem;
struct stack_data *stack;
stack_mem = (unsigned int *)malloc(STACK_SIZE);
stack_mem += STACK_SIZE - sizeof(struct stack_data);
stack = stack_mem;
stack->gs = DATA_SEG;
stack->fs = DATA_SEG;
stack->es = DATA_SEG;
stack->ds = DATA_SEG;
stack->edi = 0;
stack->esi = 0;
stack->esp = (unsigned int)(malloc(64*4) + (64*4));
stack->ebp = stack->esp;
*(&(stack->esp) + 1) = (unsigned int)entry;
stack->ebx = 0;
stack->edx = 0;
stack->ecx = 0;
stack->eax = 0;
stack->eip = (unsigned int)entry;
stack->cs = KERNEL_CODE_SEG;
stack->eflags = 0x00000202;
strncpy(rrq[end].name, name, 32);
rrq[end].stack = stack;
rrq[end].ss = KERNEL_STACK_SEG;
rrq[end].priority = pri;
rrq[end].time = get_pri_time(pri);
end++;
}
p.s. whats your code look like???
Re:tss on stack???
Posted: Sat Sep 24, 2005 6:06 pm
by Colonel Kernel
GLneo wrote:ok, i've done a little research, and it sayed that the return address is stored at ebp + 1 so should i do this:
Where did you read this? It doesn't make any sense... If it didn't come from the Intel Manuals, I don't consider it to be a reliable source.
Code: Select all
stack->esp = (unsigned int)(malloc(64*4) + (64*4));
stack->ebp = stack->esp;
*(&(stack->esp) + 1) = (unsigned int)entry;
Why the heck are you allocating yet another stack? You already allocated it at the beginning of make_task()! Did my suggestion not make any sense?
p.s. whats your code look like???
I haven't implemented task creation yet, so my code is exactly what I'm suggesting to you in this thread.
You need to take a step back and really try to understand what you're doing. Otherwise, you're operating on pure superstition and you're not going to get anywhere. Read the Intel Manuals. Grab a good book (the Minix book includes source, and is worth reading). Just chill out and stop making random guesses.
But first, try my suggestion and tell me if it works.
Re:tss on stack???
Posted: Sat Sep 24, 2005 6:57 pm
by Colonel Kernel
nm, I'm mental. :-[ POPA doesn't pop ESP; it just ignores it. And EBP will get set up by your task function as soon as it starts running. So, you should be able to leave both of them zero. As for why it doesn't work, now I'm stumped.
BTW, are you trying to run your tasks in ring 0 or ring 3? I have assumed up until now that you want them to run in ring 0, since you set CS to point to the kernel code segment...
<edit>
When you get the invalid opcode fault, is it possible to see what the value of EIP was when the fault was raised?
</edit>
Re:tss on stack???
Posted: Sat Sep 24, 2005 7:00 pm
by GLneo
the EIP says 519(31232) with is not in my kernel??? and yes i am in ring0 to see if i can even get it running
Re:tss on stack???
Posted: Sat Sep 24, 2005 8:02 pm
by GLneo
ok, i have found one problem my hlt(); was doing something weird and making invaled opcode. but that didn't solve any thing, it still only gets 1 timer IRQ, the system is still running but its like the timer gets disabled???
p.s. hopefully I get a sourceforge site, so you can look at source there so i dont have to post my entire kernel ;D
Re:tss on stack???
Posted: Sun Sep 25, 2005 12:24 am
by Colonel Kernel
GLneo wrote:but that didn't solve any thing, it still only gets 1 timer IRQ, the system is still running but its like the timer gets disabled???
What does your timer IRQ handler do? Mine currently does absolutely nothing (apart from sending the EOI), and I get the same behaviour as you, presumably because the handler needs to send some kind of acknowledgement to the PIT before another timer IRQ will fire. I haven't looked into it yet.
Either way, I'd say your problems with task switching are over (for now).
Re:tss on stack???
Posted: Sun Sep 25, 2005 7:39 am
by GLneo
your right, it finaly did a switch ;D ;D ;D ;D ;D ;D ;D ;D ;D ;D but only one, well that is becouse only one irq fires, but still the switch to task1() worked!!! ;D