pic and protected mode
pic and protected mode
Can i use the PIC to control interrupts on protected mode?
Re: pic and protected mode
Of course.
OS Development Series | Wiki | os | ncc
char c[2]={"\x90\xC3"};int main(){void(*f)()=(void(__cdecl*)(void))(void*)&c;f();}
char c[2]={"\x90\xC3"};int main(){void(*f)()=(void(__cdecl*)(void))(void*)&c;f();}
Re: pic and protected mode
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:
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
Describe "didnt work".
OS Development Series | Wiki | os | ncc
char c[2]={"\x90\xC3"};int main(){void(*f)()=(void(__cdecl*)(void))(void*)&c;f();}
char c[2]={"\x90\xC3"};int main(){void(*f)()=(void(__cdecl*)(void))(void*)&c;f();}
Re: pic and protected mode
Did you use STI to reenable interrupts somewhere else?
YouTube:
http://youtube.com/@AltComp126
My x86 OS/software:
https://sourceforge.net/projects/api-simple-completa/
Donate to get more food/programming resources/computers:
https://www.paypal.com/donate/?hosted_b ... QS2YTW3V64
http://youtube.com/@AltComp126
My x86 OS/software:
https://sourceforge.net/projects/api-simple-completa/
Donate to get more food/programming resources/computers:
https://www.paypal.com/donate/?hosted_b ... QS2YTW3V64
-
djmauretto
- Member

- Posts: 116
- Joined: Wed Oct 22, 2008 2:21 am
- Location: Roma,Italy
Re: pic and protected mode
Enable A20 
Re: pic and protected mode
Reload all segment registers and enable interrupts.
Furthermore I use another value for the ICW4:
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,alIf you have seen bad English in my words, tell me what's wrong, please.
Re: pic and protected mode
i didnt work: the isr function dont run...
Re: pic and protected mode
I use sti and the computer resets.
Re: pic and protected mode
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.mobruan wrote:I use sti and the computer resets.
Have you taken the previous advice and enabled A20, btw?
Cheers,
Adam
Re: pic and protected mode
Code: Select all
org 0x7c00
...
bits 16I 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.
His value for ICW4 is fine.Furthermore I use another value for the ICW4:
OS Development Series | Wiki | os | ncc
char c[2]={"\x90\xC3"};int main(){void(*f)()=(void(__cdecl*)(void))(void*)&c;f();}
char c[2]={"\x90\xC3"};int main(){void(*f)()=(void(__cdecl*)(void))(void*)&c;f();}
Re: pic and protected mode
how do i move it to a diferent program?
Re: pic and protected mode
The idt is right because when a use a software interrupt(int 33) its work.
How do i align the stack?
How do i align the stack?
Re: pic and protected mode
Just create another program and have your bootloader load and execute it. This is a "multistage" bootloader.how do i move it to a diferent program?
Most multistage bootloaders load it using a file system.
That does not mean the idt is correct.The idt is right because when a use a software interrupt(int 33) its work.
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.
OS Development Series | Wiki | os | ncc
char c[2]={"\x90\xC3"};int main(){void(*f)()=(void(__cdecl*)(void))(void*)&c;f();}
char c[2]={"\x90\xC3"};int main(){void(*f)()=(void(__cdecl*)(void))(void*)&c;f();}
Re: pic and protected mode
do you have a example of a multstage bootloader?


