Wait() problem

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
Tora OS

Wait() problem

Post by Tora OS »

Well when CTRL+ALT+DEL is pressed the function below is fired. It should print a message warning of reboot in 10 seconds, switch the virtural console to console 1, wait 10 seconds, and print a reboot message and finally reboot, but it doesnt do that.

It simply prints the message, switches the virtual console and sits there. Doing nothing. Never reboots. never even prints the reboot message. Any ideas?

Ok..first the control alt del function:

Code: Select all

void CTRLATLDEL()
{
//function fired when CTRL ALT DEL is pressed. waits 10 seconds...then reboots.
vc_printf("Rebooting in 10 Seconds....",1);
switch_vc(1);
wait(10);
vc_printf("Rebooting...",1);
reboot();
vc_printf("You should not see this message.",1);
now for the timer function:

Code: Select all

int timer_ticks = 0;

//IRQ errr 0 Handler:
void timer_handler(struct regs *r)
{
    // Add 1 to our ticks used by things in TIMER.C (GLOBAL eventualy??? UNIVERSAL??? LOLNO)
    timer_ticks++;
}

//Wait function:
void wait(int seconds)
{
    unsigned long end_ticks;
    unsigned long my_ticks;

    my_ticks = seconds * 18; //multiply the seconds times 18 because of the ibm dudes on drugs back when they made that value.
   
    end_ticks = timer_ticks + my_ticks; //figuer out how what our ending value for ticks will be.
    while(timer_ticks < end_ticks); //do nothing until the elapsed time has passed.
}

void timer_install()
{
    //install the IRQ handler for IRQ0
    irq_install_handler(0, timer_handler);
}
User avatar
gaf
Member
Member
Posts: 349
Joined: Thu Oct 21, 2004 11:00 pm
Location: Munich, Germany

Re:Wait() problem

Post by gaf »

Hello,
I think you have to declare timer_ticks as volatile to avoid that the optimizer caches it in one of the CPU regs..

regards,
gaf
Post Reply