OS development problems about PIC 8259A

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
benji
Posts: 22
Joined: Fri Nov 23, 2018 10:53 pm
Libera.chat IRC: os student

OS development problems about PIC 8259A

Post by benji »

:? Hello, OS developers.
I am a os lover. But recently, I am not happy about it.
I think I faced a very weird problem that is my os kernel can run on the qemu, but it can't run on VMware.
It look like a PIC problem. Because if I turn off the all the PICs, then I found it can run on the VMware.
I guess it's problem may assicated with IDT_Gate_Descriptor. possibly, I set the incorrect IDT descriptor. So I copy the others funtions that can set IDT descriptor. But I found the problem still exist.
I use the I/O instruction to prohibit the others IRQs except the IRQ1 that is keyborad interruption in 8259A so that make you easyly find the problem localtion. the instruction is io_out8_ASM(PIC0_IMR, 0xfd ); /*(this instruction in pic.c) 0xfd = 11111101. all of PIC's interupt is prohibited except IRQ1. The PICO_IMR=0x21*/.
as long as you enter any character on my os running on VMware,It will breakdown.

Code: Select all

This is my idt.c that includes "set idt gate descriptor function" :
#include "../com/types.h"
#include "idt.h"
#include "handler_ASM.h"
#include "io_ASM.h"

void init_idt(){
	IDT_Gate_Descriptor *idt=(IDT_Gate_Descriptor*)IDT_ADDR; // The IDT_ADDR = 0x00090000, Is this address invaild?
	for (int i = 0; i <= IDT_LIMIT / 8; i++) {
		set_idt_gatedesc(idt + i, 0, 0, 0);
	}
	load_idtr(IDT_LIMIT, IDT_ADDR);
	set_idt_gatedesc(idt + 0x21, (int)_asm_inthandler21_keyboard, 8, AR_INTGATE32);
	set_idt_gatedesc(idt + 0x20, (int)_asm_inthandler20_timer, 8, AR_INTGATE32);	
}

void set_idt_gatedesc(IDT_Gate_Descriptor *gd, int offset, int selector, int ar) {
	gd->offset_low   = offset & 0xffff;
	gd->selector     = selector;
	gd->dw_count     = (ar >> 8) & 0xff;
	gd->access_right = ar & 0xff;
	gd->offset_high  = (offset >> 16) & 0xffff;
	return;
}
in the init.c, the function of io_sti is open all of descripters and include one X86 instruction STI.
I use win10 64bit to compiler the os code. a month ago, I use the ubuntu 32bit to compile the os code. If I use ubuntu to compile code, the os can run on the VMware!!! very weird!!!
without compile, You can run my os with DolphinOS.img directly.
then, this is all of my os code in rar.
Attachments
DolphinOS0.07g.rar
This is my os code
(19.25 KiB) Downloaded 86 times
Last edited by benji on Sat Jul 20, 2019 8:08 pm, edited 2 times in total.
MichaelPetch
Member
Member
Posts: 797
Joined: Fri Aug 26, 2016 1:41 pm
Libera.chat IRC: mpetch

Re: OS development problems about PIC 8259A

Post by MichaelPetch »

Do you set up your own GDT and load it with LGDT? I don't see a link to your files/project that you mention in your question.
benji
Posts: 22
Joined: Fri Nov 23, 2018 10:53 pm
Libera.chat IRC: os student

Re: OS development problems about PIC 8259A

Post by benji »

MichaelPetch wrote:Do you set up your own GDT and load it with LGDT? I don't see a link to your files/project that you mention in your question.
Yes, I think I set up. I am so sorry I don't know why my rar file would not be upload
Attachments
DolphinOS0.07g.rar
This is my os code
(19.25 KiB) Downloaded 108 times
MichaelPetch
Member
Member
Posts: 797
Joined: Fri Aug 26, 2016 1:41 pm
Libera.chat IRC: mpetch

Re: OS development problems about PIC 8259A

Post by MichaelPetch »

In this code:

Code: Select all

void inthandler21_keyboard(int32_t *esp){
        printk("  INT21 (IRQ-1)  ");
        io_out8_ASM(PIC0_OCW2,0x61);
        io_in8_ASM(0x60); //It is very important sentence in the function. If you haven't read the data, the 8042 still think the interupt hasn't be completed.
}

uint32_t times=0;

void inthandler20_timer(int32_t *esp){
        io_out8_ASM(PIC0_OCW2, 0x60);
        times++;
        //print * per second
        if(times%100==0){
                printk("*");
        }
}
In particular in the keyboard handler you do

Code: Select all

io_out8_ASM(PIC0_OCW2,0x61);
and in the timer handler you do

Code: Select all

io_out8_ASM(PIC0_OCW2, 0x60);
Because you are using cascaded mode you can send a non-specific EOI to the PIC simply by doing

Code: Select all

io_out8_ASM(PIC0_OCW2, 0x20);
in both cases instead of using a specific EOI (0x60 and 0x61)
benji
Posts: 22
Joined: Fri Nov 23, 2018 10:53 pm
Libera.chat IRC: os student

Re: OS development problems about PIC 8259A

Post by benji »

MichaelPetch wrote:In this code:

Code: Select all

void inthandler21_keyboard(int32_t *esp){
        printk("  INT21 (IRQ-1)  ");
        io_out8_ASM(PIC0_OCW2,0x61);
        io_in8_ASM(0x60); //It is very important sentence in the function. If you haven't read the data, the 8042 still think the interupt hasn't be completed.
}

uint32_t times=0;

void inthandler20_timer(int32_t *esp){
        io_out8_ASM(PIC0_OCW2, 0x60);
        times++;
        //print * per second
        if(times%100==0){
                printk("*");
        }
}
In particular in the keyboard handler you do

Code: Select all

io_out8_ASM(PIC0_OCW2,0x61);
and in the timer handler you do

Code: Select all

io_out8_ASM(PIC0_OCW2, 0x60);
Because you are using cascaded mode you can send a non-specific EOI to the PIC simply by doing

Code: Select all

io_out8_ASM(PIC0_OCW2, 0x20);
in both cases instead of using a specific EOI (0x60 and 0x61)
I changed the 0x60 to 0x20, but the problem still exist.
benji
Posts: 22
Joined: Fri Nov 23, 2018 10:53 pm
Libera.chat IRC: os student

Re: OS development problems about PIC 8259A

Post by benji »

benji wrote:
MichaelPetch wrote:In this code:

Code: Select all

void inthandler21_keyboard(int32_t *esp){
        printk("  INT21 (IRQ-1)  ");
        io_out8_ASM(PIC0_OCW2,0x61);
        io_in8_ASM(0x60); //It is very important sentence in the function. If you haven't read the data, the 8042 still think the interupt hasn't be completed.
}

uint32_t times=0;

void inthandler20_timer(int32_t *esp){
        io_out8_ASM(PIC0_OCW2, 0x60);
        times++;
        //print * per second
        if(times%100==0){
                printk("*");
        }
}
In particular in the keyboard handler you do

Code: Select all

io_out8_ASM(PIC0_OCW2,0x61);
and in the timer handler you do

Code: Select all

io_out8_ASM(PIC0_OCW2, 0x60);
Because you are using cascaded mode you can send a non-specific EOI to the PIC simply by doing

Code: Select all

io_out8_ASM(PIC0_OCW2, 0x20);
in both cases instead of using a specific EOI (0x60 and 0x61)
I changed the 0x60 to 0x20, but the problem still exist.
In the screen I can't see the printk(" INT21 (IRQ-1) ");
I ensure the kernel would not excuted this code.
benji
Posts: 22
Joined: Fri Nov 23, 2018 10:53 pm
Libera.chat IRC: os student

Re: OS development problems about PIC 8259A

Post by benji »

benji wrote:
benji wrote:
MichaelPetch wrote:In this code:

Code: Select all

void inthandler21_keyboard(int32_t *esp){
        printk("  INT21 (IRQ-1)  ");
        io_out8_ASM(PIC0_OCW2,0x61);
        io_in8_ASM(0x60); //It is very important sentence in the function. If you haven't read the data, the 8042 still think the interupt hasn't be completed.
}

uint32_t times=0;

void inthandler20_timer(int32_t *esp){
        io_out8_ASM(PIC0_OCW2, 0x60);
        times++;
        //print * per second
        if(times%100==0){
                printk("*");
        }
}
In particular in the keyboard handler you do

Code: Select all

io_out8_ASM(PIC0_OCW2,0x61);
and in the timer handler you do

Code: Select all

io_out8_ASM(PIC0_OCW2, 0x60);
Because you are using cascaded mode you can send a non-specific EOI to the PIC simply by doing

Code: Select all

io_out8_ASM(PIC0_OCW2, 0x20);
in both cases instead of using a specific EOI (0x60 and 0x61)
I changed the 0x60 to 0x20, but the problem still exist.
In the screen I can't see the printk(" INT21 (IRQ-1) ");
I ensure the kernel would not excuted this code.
I am so confuse about this.
It may not the interruption problems
benji
Posts: 22
Joined: Fri Nov 23, 2018 10:53 pm
Libera.chat IRC: os student

Re: OS development problems about PIC 8259A

Post by benji »

My classmates tell me it could be that the stack problem (register esp)
Post Reply