give me some advice for hardware programming.
Posted: Sun Apr 11, 2010 3:35 am
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:
then init 8259:
set the keyboard to lights up:
but got a restart in bochs.the key debug info:(i deleted the things like "<bochs>s next at xxxx")
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:
but if i set the keyboard like this:
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
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);
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;
}
Code: Select all
while(inbyte(0x64)&0x2) inbyte(0x60);
outbyte(0x64,0xAE);
outbyte(0x64,0xD1);
outbyte(0x60,0xED);
outbyte(0x60,0x7);
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
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
Code: Select all
while(inbyte(0x64)&0x2) inbyte(0x60);
outbyte(0x64,0xAE);
//outbyte(0x64,0xD1);
//outbyte(0x60,0xED);
//outbyte(0x60,0x7);
so,how to get out my first step?say,how to enable the keyboard?
thx