tss on stack???

Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
GLneo

Re:tss on stack???

Post 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
User avatar
Colonel Kernel
Member
Member
Posts: 1437
Joined: Tue Oct 17, 2006 6:06 pm
Location: Vancouver, BC, Canada
Contact:

Re:tss on stack???

Post 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...
Top three reasons why my OS project died:
  1. Too much overtime at work
  2. Got married
  3. My brain got stuck in an infinite loop while trying to design the memory manager
Don't let this happen to you!
GLneo

Re:tss on stack???

Post by GLneo »

so, for esp:

Code: Select all

esp = malloc(???);
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
User avatar
Colonel Kernel
Member
Member
Posts: 1437
Joined: Tue Oct 17, 2006 6:06 pm
Location: Vancouver, BC, Canada
Contact:

Re:tss on stack???

Post by Colonel Kernel »

GLneo wrote: so, for esp:

Code: Select all

esp = malloc(???);
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.
Top three reasons why my OS project died:
  1. Too much overtime at work
  2. Got married
  3. My brain got stuck in an infinite loop while trying to design the memory manager
Don't let this happen to you!
GLneo

Re:tss on stack???

Post by GLneo »

so esp = EIP; ???
User avatar
Colonel Kernel
Member
Member
Posts: 1437
Joined: Tue Oct 17, 2006 6:06 pm
Location: Vancouver, BC, Canada
Contact:

Re:tss on stack???

Post 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...
Top three reasons why my OS project died:
  1. Too much overtime at work
  2. Got married
  3. My brain got stuck in an infinite loop while trying to design the memory manager
Don't let this happen to you!
GLneo

Re:tss on stack???

Post 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???
User avatar
Colonel Kernel
Member
Member
Posts: 1437
Joined: Tue Oct 17, 2006 6:06 pm
Location: Vancouver, BC, Canada
Contact:

Re:tss on stack???

Post 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. ;)
Top three reasons why my OS project died:
  1. Too much overtime at work
  2. Got married
  3. My brain got stuck in an infinite loop while trying to design the memory manager
Don't let this happen to you!
User avatar
Colonel Kernel
Member
Member
Posts: 1437
Joined: Tue Oct 17, 2006 6:06 pm
Location: Vancouver, BC, Canada
Contact:

Re:tss on stack???

Post 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>
Top three reasons why my OS project died:
  1. Too much overtime at work
  2. Got married
  3. My brain got stuck in an infinite loop while trying to design the memory manager
Don't let this happen to you!
GLneo

Re:tss on stack???

Post 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 :)
GLneo

Re:tss on stack???

Post 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
User avatar
Colonel Kernel
Member
Member
Posts: 1437
Joined: Tue Oct 17, 2006 6:06 pm
Location: Vancouver, BC, Canada
Contact:

Re:tss on stack???

Post 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).
Top three reasons why my OS project died:
  1. Too much overtime at work
  2. Got married
  3. My brain got stuck in an infinite loop while trying to design the memory manager
Don't let this happen to you!
GLneo

Re:tss on stack???

Post 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
Post Reply