OSDev.org

The Place to Start for Operating System Developers
It is currently Thu Mar 28, 2024 5:53 pm

All times are UTC - 6 hours




Post new topic Reply to topic  [ 3 posts ] 
Author Message
 Post subject: PIT not working
PostPosted: Fri May 10, 2019 9:08 am 
Offline

Joined: Tue Sep 11, 2018 9:42 am
Posts: 7
Hello,

I have another problem with my "OS": i'm unable to get the PIT to work.
This is what i've tried to do:
    Remapped PICs using:
    Code:
    void irq_remap() {
        outb(0x20, 0x11);
        outb(0xA0, 0x11);
        outb(0x21, 0x20);
        outb(0xA1, 0x28);
        outb(0x21, 0x04);
        outb(0xA1, 0x02);
        outb(0x21, 0x01);
        outb(0xA1, 0x01);
        outb(0x21, 0x0);
        outb(0xA1, 0x0);   
    }

    An IRQ handler that is being called from assembly irq_common_stub:
    Code:
    void irq_handler(registers_t regs) {
        if(regs.int_no >= 40) // If IRQ > 7(int_no > 40) reset slave PIC
            outb(0xA0, 0x20);
        outb(0x20, 0x20); // In either cases, reset master PIC

        // Register a new interrupt handler
        if(interrupt_handlers[regs.int_no] != 0) {
            isr_t handler = interrupt_handlers[regs.int_no];
            handler(regs);
        }
    }


    A timer initializer
    Code:
    void init_timer(uint32_t frequency) {
        register_interrupt_handler(32, &timer_callback);

        uint32_t divisor = 1193180 / frequency;

        outb(0x43, 0x36);

        uint8_t low = (uint8_t)(divisor & 0xFF);
        uint8_t high = (uint8_t)((divisor >> 8) & 0xFF);

        outb(0x40, low);
        outb(0x40, high);
    }

The problem is that, when i try to call init_timer() from the kernel nothing happen. The weird thing is that if i try to run the OS with Bochs(starting it with GRUB's countdown, without touching the keyboard) it prints this error:
Code:
03150576036e[CPU0  ] check_cs(0x0206): not a valid code segment !
.
Otherwise(with QEMU or even with Bochs, pressing "enter" from GRUB's menu)nothing gets printed at all.

This is the repo, just in case.


Top
 Profile  
 
 Post subject: Re: PIT not working
PostPosted: Fri May 10, 2019 10:03 am 
Offline
Member
Member

Joined: Wed Aug 30, 2017 8:24 am
Posts: 1593
KSMb wrote:
Code:
void irq_handler(registers_t regs) {

Not this old chestnut again. Since I highly doubt you are handing a structure over correctly (according to the ABI, that is), I suggest you make the parameter into a pointer and hand that over.

KSMb wrote:
Code:
03150576036e[CPU0  ] check_cs(0x0206): not a valid code segment !
.

The hint is in the message. There are only two ways how a code segment would be loaded: far jump or interrupt. So if you can exclude far jumps, this message is caused by an interrupt. And it means that either the CS reference in the relevant IDT entry is wrong, or the CS entry in the GDT is wrong. Happy debugging!

_________________
Carpe diem!


Top
 Profile  
 
 Post subject: Re: PIT not working
PostPosted: Fri May 10, 2019 12:08 pm 
Offline
Member
Member

Joined: Fri Aug 26, 2016 1:41 pm
Posts: 671
The issue you had with registers_t vs. registers_t * previously with isr_handler also applies to irq_handler


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 3 posts ] 

All times are UTC - 6 hours


Who is online

Users browsing this forum: Bing [Bot] and 85 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