Question

I am working on a small kernel as a project for my University. I have overridden (not sure if that's the correct expression) a timer interrupt routine.

It works well until the first context switching. Context switching is in dispatch() which is called when a process uses all of its appointed time (time out).

My routine is initialized just before main process starts and it should restore after it's done (although I never got to that). I also tried initializing it every time a process is started and restoring it during context switching or when that process ends. I tried this because I have a completed project from 2005 (slightly different) which I look up to for ideas, not copy-pasting.

Timer interrupt:

void interrupt System::timer(...){
intOff;
    cout << currentTime << "\n";
    currentTime++;

    if(System::runningTime){
        System::runningTime--;
        if(!System::runningTime) {
          dispatch();
        }
    }
    else asm int 60h;
intOn;
}

initializing new and restoring old routine:

void System::init(){
  cout << "init\n";
  oldTimer = getvect(0x1c);
  setvect(0x1c, &timer);
  setvect(0x60, oldTimer);
}
void System::restore(){
  cout << "restore " << System::running->getName() << System::running->getID() << "\n";
  setvect(0x1c, oldTimer);
}

Process that I run:

void run(){
            cout << "Test" << mod << " time:" << System::currentTime << "\n";
        while(System::currentTime < 100){
        br++;
        }
    }

//mod is like id

When I run the program I get:

init Test1 time:0 //from process one, indication it has begun, it has permission to run for 2 cycles, current time is 0

0 //current time on the start of timer routine

1 //current time on the start of timer routine

Test2 time:2 //from process two, it has begun, permission to run for 2 cycles, current time is 2 as expected

I have put cout << System::currentTime; in run() after br++. What I got was "2" geting printed to infinity. That is a indication that currentTime doesn't get increased, which means that my timer routine is not called anymore.

I have looked on this problem from various angles, tried various methods and nothing worked. Any and every idea is appreciated. [:

Was it helpful?

Solution

I didn't think about sending the End-of-interrupt signal to the interrupt controller. Just needed to add

asm {
push ax
in al, 0x61
or al, 0x80 // 10000000b
out 0x61, al
and al, 0x7F // 01111111b
out 0x61, al
mov al, 0x20
out 0x20, al
pop ax
}

and now works like a charm.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top