OSDev.org

The Place to Start for Operating System Developers
It is currently Wed May 15, 2024 8:08 pm

All times are UTC - 6 hours




Post new topic Reply to topic  [ 73 posts ]  Go to page Previous  1, 2, 3, 4, 5
Author Message
 Post subject: Re:tss on stack???
PostPosted: Thu Sep 22, 2005 6:56 pm 
well, ok, i've updated my code to:
Code:
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


Top
  
 
 Post subject: Re:tss on stack???
PostPosted: Thu Sep 22, 2005 10:34 pm 
Offline
Member
Member
User avatar

Joined: Tue Oct 17, 2006 6:06 pm
Posts: 1437
Location: Vancouver, BC, Canada
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!


Top
 Profile  
 
 Post subject: Re:tss on stack???
PostPosted: Fri Sep 23, 2005 6:17 pm 
so, for esp:
Code:
esp = malloc(???);

and my structs are:
Code:
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


Top
  
 
 Post subject: Re:tss on stack???
PostPosted: Fri Sep 23, 2005 7:23 pm 
Offline
Member
Member
User avatar

Joined: Tue Oct 17, 2006 6:06 pm
Posts: 1437
Location: Vancouver, BC, Canada
GLneo wrote:
so, for esp:
Code:
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!


Top
 Profile  
 
 Post subject: Re:tss on stack???
PostPosted: Sat Sep 24, 2005 7:59 am 
so esp = EIP; ???


Top
  
 
 Post subject: Re:tss on stack???
PostPosted: Sat Sep 24, 2005 12:06 pm 
Offline
Member
Member
User avatar

Joined: Tue Oct 17, 2006 6:06 pm
Posts: 1437
Location: Vancouver, BC, Canada
Try this:

Code:
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!


Top
 Profile  
 
 Post subject: Re:tss on stack???
PostPosted: Sat Sep 24, 2005 5:54 pm 
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:
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???


Top
  
 
 Post subject: Re:tss on stack???
PostPosted: Sat Sep 24, 2005 6:06 pm 
Offline
Member
Member
User avatar

Joined: Tue Oct 17, 2006 6:06 pm
Posts: 1437
Location: Vancouver, BC, Canada
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.

Quote:
Code:
    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?

Quote:
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!


Top
 Profile  
 
 Post subject: Re:tss on stack???
PostPosted: Sat Sep 24, 2005 6:57 pm 
Offline
Member
Member
User avatar

Joined: Tue Oct 17, 2006 6:06 pm
Posts: 1437
Location: Vancouver, BC, Canada
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!


Top
 Profile  
 
 Post subject: Re:tss on stack???
PostPosted: Sat Sep 24, 2005 7:00 pm 
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 :)


Top
  
 
 Post subject: Re:tss on stack???
PostPosted: Sat Sep 24, 2005 8:02 pm 
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


Top
  
 
 Post subject: Re:tss on stack???
PostPosted: Sun Sep 25, 2005 12:24 am 
Offline
Member
Member
User avatar

Joined: Tue Oct 17, 2006 6:06 pm
Posts: 1437
Location: Vancouver, BC, Canada
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!


Top
 Profile  
 
 Post subject: Re:tss on stack???
PostPosted: Sun Sep 25, 2005 7:39 am 
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


Top
  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 73 posts ]  Go to page Previous  1, 2, 3, 4, 5

All times are UTC - 6 hours


Who is online

Users browsing this forum: Google [Bot], MichaelPetch and 59 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group