voiding schedule()

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

voiding schedule()

Post by GLneo »

hi all, ok, first i use to put variables on the stack then my c code got passed them: regs *schedule(regs *all_my_regs); but this is no good in non timer functions that cant pass all regs, so i'm changing code to: void schedule(); so far i have this:

Code: Select all

int front = 0;
int end = 0;
struct task_data rrq[QUE_SIZE];

int is_empty()
{
    if(end == front)
        return 1;
    return 0;
}

int cur_task_pri()
{
    if(is_empty())
        return 0;
    return rrq[front].priority;
}

void front_to_end()
{
     if(is_empty())
        return;
     rrq[end] = rrq[front];
     end++;
     if(end >= QUE_SIZE)
         end = 0;
     front++;
     if(front >= QUE_SIZE)
         front = 0;
}

void cur_task_time_equ(int time)
{
    if(is_empty())
        return;
    rrq[front].time = time;
}

int get_pri_time(int pri)
{
    switch(pri)
    {
        case 0:
            return 100;
            break;
        case 1:
            return 10;
            break;
        case 2:
            return 5;
            break;
        case 3:
            return 2;
            break;
        case 4:
            return 1;
            break;
        default:
            return 0;
     }
}

void schedule()
{
    cur_task_time_equ(get_pri_time(cur_task_pri()));
    rrq[front].stack = (struct stack_data *)old_task;
    front_to_end();
    new_task = (int)&rrq[front].stack;
//    TSS.esp0 = (int)rrq[front].stack;
//    return (stack_data_t *)TSS.esp0;
}
but this doesn't work for some reason, any idea's???

p.s. need more code just ask ;)
durand
Member
Member
Posts: 193
Joined: Wed Dec 21, 2005 12:00 am
Location: South Africa
Contact:

Re:voiding schedule()

Post by durand »

You used to return "(stack_data_t *)TSS.esp0". Now you're setting some global variable called new_task. Does the code that calls schedule handle this properly now?

Also, you've commented out the setting of TSS.esp0. Shouldn't you keep that?

You should show the code that calls schedule...
GLneo

Re:voiding schedule()

Post by GLneo »

i was never doing this:

Code: Select all

//    TSS.esp0 = (int)rrq[front].stack;
//    return (stack_data_t *)TSS.esp0;
what i did do was this:

Code: Select all

//    return (int)rrq[front].stack;
basical returning the front task on the que's stack, with would return all the way to the asm stub and put it in esp and all task regs would be poped off, it used to look like this:

Code: Select all

_task_timer:
    pushad
    push ds
    push es
    push fs
    push gs
    mov ax, 0x10
    mov ds, ax
    mov es, ax
    mov fs, ax
    mov gs, ax
;    cli
    push esp
    mov eax, _task_timer_c
    call eax
;    sti
    pop esp
    mov esp, eax
    pop gs
    pop fs
    pop es
    pop ds
    popad
    iretd

struct task_data rrq[QUE_SIZE];

stack_data_t *task_timer_c(stack_data_t *regs)
{
    clock();
//    (void)inport(0x60);
    outport(0x20, 0x20);
    if(cur_task_time() > 0)
    {
        dec_cur_task_time();
        return regs;
    }
    else
        return schedule(regs);
}

stack_data_t *schedule(stack_data_t *regs)
{
    cur_task_time_equ(get_pri_time(cur_task_pri()));
    rrq[front].stack = regs;
    front_to_end();
    return rrq[front].stack;
}

but now i dont want to return every thing, just put the (int)&rrq[front].stack; in new_task and then in asm do this:

Code: Select all

EXTERN _new_task

 _task_timer:
    pushad
    push ds
    push es
    push fs
    push gs
    mov ax, 0x10
    mov ds, ax
    mov es, ax
    mov fs, ax
    mov gs, ax
;    cli
    mov [_old_task], esp
    mov eax, _task_timer_c
    call eax
    mov esp, [_new_task]
;    sti
    pop gs
    pop fs
    pop es
    pop ds
    popad
    iretd

all tasks are in ring 0(so no TSS yet)

p.s. rrq[front].stack; is a struct:

Code: Select all

typedef 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;
}stack_data_t;

hope that helps, thx :)
Post Reply