上下文切换内部定时器中断,意外编译错误

时间:2012-08-16 09:15:51

标签: c++ timer compiler-errors interrupt context-switch

我正在测试在dispatch()函数中实现的上下文切换。 根据我的理解,当我在中断计时器内调用dispatch时会出现问题。如果我这样做,它甚至都不会编译!奇怪的是,如果我实现调度只是为了调用定时器中断和定时器来进行上下文切换,它就能很好地工作。我试图调度一个宏或内联函数,但问题是一样的 - 当我尝试构建它时,会发生一些意外的异常?

这足以让你告诉我什么是错的吗?

class PCB{ // this class represents a thread
  public:
unsigned sp;
unsigned ss;
Status status;
Time kvant; // time slice
static PCB* running;

void createProcess(void (*body)());
};

PCB* PCB::running = 0;

void PCB::createProcess(void (*body)()){

unsigned* stek = new unsigned[1024];

st1[1023] =0x200; // PSW register with I flag setted to be 1
st1[1022] = FP_SEG(body);
st1[1021] = FP_OFF(body);

this->sp = FP_OFF(st1+1012); // space for registers ax,bx,cx,d,si,es,ds,di,bp
this->ss = FP_SEG(st1+1012);

this->status = NEW;
}

void interrupt timer(){
timer_counter--; 
if (timer_counter == 0) dispatch(); 

 else asm int 60h; // invoking the old routine
}

void interrupt dispatch(){
asm cli;
    asm {
        // store sp
        mov tsp, sp
        mov tss, ss
    }

    PCB::running->sp = tsp;
    PCB::running->ss = tss;

    cout<<"Context change!"<<endl;

    if(PCB::running->status !=END){
     PCB::running->status = READY;
     Scheduler::put(PCB::running);
    }
    PCB::running=Scheduler::get();
    PCB::running->status = RUNNING;

    tsp = PCB::running->sp;
    tss = PCB::running->ss; 

    timer_counter = PCB::running->kvant;

    asm {
        mov sp, tsp   // restore sp
        mov ss, tss
    } 

    asm sti;
}

0 个答案:

没有答案
相关问题