Page 1 of 2
pic and protected mode
Posted: Tue Oct 28, 2008 6:49 pm
by mobruan
Can i use the PIC to control interrupts on protected mode?
Re: pic and protected mode
Posted: Tue Oct 28, 2008 6:53 pm
by neon
Of course.
Re: pic and protected mode
Posted: Tue Oct 28, 2008 6:59 pm
by mobruan
I´m using the following code and it didnt work.
org 0x7c00
section .text
bits 16
mov ax, word 0x0000
mov ds, ax
cli
lgdt [gdt]
mov eax,cr0
or al,0x01
mov cr0,eax
jmp 8:pm
jmp $
bits 32
pm:
mov ax, 8*2
mov ds,ax
mov ax, 8*2
mov ss,ax
mov esp, 9000
mov eax, isr
mov [idt33 + 0], ax
shr eax, 16
mov [idt33 + 6], ax
lidt [idt]
mov dx, word 0x20
mov al, byte 00010001b ;icw1
out dx, byte al
mov dx, word 0x21 ;icw2
mov al, byte 0x20
out dx, byte al
mov al, byte 00000100b ;icw3
out dx, byte al
mov al, byte 00000001b ;icw4
out dx, byte al
jmp $ ;quando volta da isr
isr:
mov [0xb8000], byte 'A'
mov [0xb8001], byte 0x17
iret
jmp $
section .data
gdt:
dw gdt_end - gdt_begin - 1
dd gdt_begin
gdt_begin:
gdt0:
limit1 dw 0
base1 dw 0
base2 db 0
type db 0
limit2 db 0
base3 db 0
gdt1:
dw 0xffff
dw 0x0000
db 0x00
db 0x9a
db 0xcf
db 0x00
gdt2:
dw 0xffff
dw 0x0000
db 0x00
db 0x92
db 0xcf
db 0x00
gdt_end:
idt:
dw idt_end - idt_begin - 1
dd idt_begin
idt_begin:
idt0:
offset1 dw 0
selector dw 0x8
misc db 0
present db 0x8e
offset2 dw 0
.
.
.
idt33:
dw 0
dw 0x8
db 0
db 0x8e
dw 0
idt_end:
Re: pic and protected mode
Posted: Tue Oct 28, 2008 7:54 pm
by neon
Describe "didnt work".
Re: pic and protected mode
Posted: Tue Oct 28, 2008 8:09 pm
by ~
Did you use STI to reenable interrupts somewhere else?
Re: pic and protected mode
Posted: Wed Oct 29, 2008 2:43 am
by djmauretto
Enable A20

Re: pic and protected mode
Posted: Wed Oct 29, 2008 5:18 am
by egos
Reload all segment registers and enable interrupts.
Furthermore I use another value for the ICW4:
Code: Select all
mov al,00010001b
out 20h,al
out 0A0h,al
mov al,IRQ_BASEINDEX
out 21h,al
mov al,IRQ_BASEINDEX+8
out 0A1h,al
mov al,00000100b
out 21h,al
mov al,02h
out 0A1h,al
mov al,00001101b
out 21h,al
mov al,00001001b
out 0A1h,al
mov al,IRQ_MASK and 0FFh
out 21h,al
mov al,IRQ_MASK shr 8 and 0FFh
out 0A1h,al
Re: pic and protected mode
Posted: Wed Oct 29, 2008 9:19 am
by mobruan
i didnt work: the isr function dont run...
Re: pic and protected mode
Posted: Wed Oct 29, 2008 9:26 am
by mobruan
I use sti and the computer resets.
Re: pic and protected mode
Posted: Wed Oct 29, 2008 11:08 am
by AJ
mobruan wrote:I use sti and the computer resets.
Which means the CPU is triple-faulting. Try using an emulator such as Bochs which will display a register dump (which may help to give you what caused the original fault - I'm guessing at an invalid IDT or stack misalignment resuling in GP or Invalid Opcode). You can then start to debug your code more effectively. Also, the use of JMP $ at strategic points throughout the code can be a big help.
Have you taken the previous advice and enabled A20, btw?
Cheers,
Adam
Re: pic and protected mode
Posted: Wed Oct 29, 2008 11:59 am
by neon
Euhm... is this a bootloader? You do know it is limited to 512 bytes, right?
I highley recommend moving your idt, gdt, and protected mode code into a different program so your are not limited to 512 bytes. Else there will be problems when it gets larger then 512 bytes.
Furthermore I use another value for the ICW4:
His value for ICW4 is fine.
Re: pic and protected mode
Posted: Wed Oct 29, 2008 1:17 pm
by mobruan
how do i move it to a diferent program?
Re: pic and protected mode
Posted: Wed Oct 29, 2008 1:18 pm
by mobruan
The idt is right because when a use a software interrupt(int 33) its work.
How do i align the stack?
Re: pic and protected mode
Posted: Wed Oct 29, 2008 2:04 pm
by neon
how do i move it to a diferent program?
Just create another program and have your bootloader load and execute it. This is a "multistage" bootloader.
Most multistage bootloaders load it using a file system.
The idt is right because when a use a software interrupt(int 33) its work.
That does not mean the idt is correct.
How are you testing your OS? Emulator? Virtual machine? Follow AJ's advice and run it through Bochs and look at the log output to see what is going on.
Re: pic and protected mode
Posted: Wed Oct 29, 2008 6:15 pm
by mobruan
do you have a example of a multstage bootloader?