give me some advice for hardware programming.

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
User avatar
lemonyii
Member
Member
Posts: 153
Joined: Thu Mar 25, 2010 11:28 pm
Location: China

give me some advice for hardware programming.

Post by lemonyii »

Hi again,
i think i have been at a point where i should go out of CPU,to program the hardwares.
I have set up local apic and its timer,and now i hope to start the outside interrupts,such as keyboard and harddisk.
then i want to try IOAPIC,and EHCI and so on.
and then file system,graphic,mouse. No further has considered so far.
But now i have a problem again:

add this in apic_init:

Code: Select all

apic_write(0x350ull, 0x7|INT_VECTOR_IRQ0);
then init 8259:

Code: Select all

extern i64 init_i8259(){
	outbyte(INT_M_CTL,	0x11);			// Master 8259, ICW1.
	outbyte(INT_S_CTL,	0x11);			// Slave  8259, ICW1.
	outbyte(INT_M_CTLMASK,	INT_VECTOR_IRQ0);	// Master 8259, ICW2. 设置 '主8259' 的中断入口地址
	outbyte(INT_S_CTLMASK,	INT_VECTOR_IRQ8);	// Slave  8259, ICW2. 设置 '从8259' 的中断入口地址
	outbyte(INT_M_CTLMASK,	0x4);			// Master 8259, ICW3. IR2 对应 '从8259'.
	outbyte(INT_S_CTLMASK,	0x2);			// Slave  8259, ICW3. 对应 '主8259' 的 IR2.
	outbyte(INT_M_CTLMASK,	0x1);			// Master 8259, ICW4.
	outbyte(INT_S_CTLMASK,	0x1);			// Slave  8259, ICW4.
	outbyte(INT_M_CTLMASK,	0x00);	// Master 8259, OCW1. 
	outbyte(INT_S_CTLMASK,	0xFF);	// Slave  8259, OCW1. 
	return 0;
}
set the keyboard to lights up:

Code: Select all

	while(inbyte(0x64)&0x2) inbyte(0x60);
	outbyte(0x64,0xAE);
	outbyte(0x64,0xD1);
	outbyte(0x60,0xED);
	outbyte(0x60,0x7);
but got a restart in bochs.the key debug info:(i deleted the things like "<bochs>s next at xxxx")

Code: Select all

(0) [0x00101a90] 0031:0000000000101a90 (unk. ctxt): mov esi, 0x000000ed       ;
beed000000
(0) [0x00101a95] 0031:0000000000101a95 (unk. ctxt): mov edi, 0x00000060       ;
bf60000000
(0) [0x00101a9a] 0031:0000000000101a9a (unk. ctxt): call .+0x0000000000000571 (
x0000000000102010) ; e871050000
(0) [0x00102010] 0031:0000000000102010 (unk. ctxt): push rdx                  ;
52
(0) [0x00102011] 0031:0000000000102011 (unk. ctxt): mov rdx, rdi              ;
4889fa
(0) [0x00102014] 0031:0000000000102014 (unk. ctxt): mov rax, rsi              ;
4889f0
(0) [0x00102017] 0031:0000000000102017 (unk. ctxt): out dx, al                ;
ee
(0) [0x00102018] 0031:0000000000102018 (unk. ctxt): pop rdx                   ;
5a
(0) [0x00102019] 0031:0000000000102019 (unk. ctxt): nop                       ;
90
(0) [0x0010201a] 0031:000000000010201a (unk. ctxt): nop                       ;
90
(0) [0x0010201b] 0031:000000000010201b (unk. ctxt): nop                       ;
90
(0) [0x0010201c] 0031:000000000010201c (unk. ctxt): nop                       ;
90
(0) [0x0010201d] 0031:000000000010201d (unk. ctxt): ret                       ;
c3
(0) [0x00000000] 0031:0000000000000000 (unk. ctxt): adc byte ptr ds:[rbx], cl ;
100b
notice the last ret ,it did not return to the address expected(and i check the stack,nothing wrong).
and that in bochs logfile is:

Code: Select all

00061894912i[CPU0 ] 0x0000000000000010>> (invalid)  : 60
00061894912e[CPU0 ] exception(): 3rd (14) exception with no resolution, shutdown status is 00h, resetting
00061894912i[SYS  ] bx_pc_system_c::Reset(HARDWARE) called
00061894912i[CPU0 ] cpu hardware reset
but if i set the keyboard like this:

Code: Select all

	while(inbyte(0x64)&0x2) inbyte(0x60);
	outbyte(0x64,0xAE);
	//outbyte(0x64,0xD1);
	//outbyte(0x60,0xED);
	//outbyte(0x60,0x7);
nothihg will happen,and no response on my hitting the keyboard.
so,how to get out my first step?say,how to enable the keyboard?
thx
Enjoy my life!------A fish with a tattooed retina
User avatar
lemonyii
Member
Member
Posts: 153
Joined: Thu Mar 25, 2010 11:28 pm
Location: China

Re: give me some advice for hardware programming.

Post by lemonyii »

and surely i set the IDT,and set the IF bit.
Enjoy my life!------A fish with a tattooed retina
Gigasoft
Member
Member
Posts: 856
Joined: Sat Nov 21, 2009 5:11 pm

Re: give me some advice for hardware programming.

Post by Gigasoft »

You're setting the output port to 0xED. This disables the A20 gate. The 0xED should be sent to the keyboard, so don't issue command 0xD1.

Other things to check:
- Is bit 0 of the command register set?
- Is bit 4 of the command register clear?
- Has command 0xF4 been sent to the keyboard to enable it?
- Is the output register filled on keyboard and mouse input?
- Do other interrupts work? (For example, the timer channel 0 interrupt)
- Is an EOI sent in the interrupt handler?
- Are INT_VECTOR_IRQ0 and INT_VECTOR_IRQ8 multiples of 8?
- Is the keyboard ISR installed on the right IRQ (1)?
User avatar
lemonyii
Member
Member
Posts: 153
Joined: Thu Mar 25, 2010 11:28 pm
Location: China

Re: give me some advice for hardware programming.

Post by lemonyii »

thank you at first!
a lot of problems.. :mrgreen: and there is some point where i do not understand.
Gigasoft wrote:You're setting the output port to 0xED. This disables the A20 gate. The 0xED should be sent to the keyboard, so don't issue command 0xD1.
this is the way i saw from a book to set the lights on the keyboard,so how should i set them now?
- Are INT_VECTOR_IRQ0 and INT_VECTOR_IRQ8 multiples of 8?
really? never heard it before,thanks.
- Is the keyboard ISR installed on the right IRQ (1)?
what does this mean? the i8259?
i have many classes these two days,so i will try it once i am free.
thx
Enjoy my life!------A fish with a tattooed retina
Gigasoft
Member
Member
Posts: 856
Joined: Sat Nov 21, 2009 5:11 pm

Re: give me some advice for hardware programming.

Post by Gigasoft »

Just write 0xED, then 0x07 to port 0x60, without writing 0xD1 to port 0x64.
what does this mean? the i8259?
Well, I mean, the keyboard service routine should be associated with IRQ vector 1 (entry number INT_VECTOR_IRQ0+1), if it isn't already.
User avatar
lemonyii
Member
Member
Posts: 153
Joined: Thu Mar 25, 2010 11:28 pm
Location: China

Re: give me some advice for hardware programming.

Post by lemonyii »

Are INT_VECTOR_IRQ0 and INT_VECTOR_IRQ8 multiples of 8?
that's where i got a mistake! and now, everything is so smooth now.
thank you so much!
Enjoy my life!------A fish with a tattooed retina
Post Reply