pic and protected mode

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.
mobruan
Member
Member
Posts: 71
Joined: Thu Oct 09, 2008 8:25 am
Location: Rio de Janeiro - Brazil

pic and protected mode

Post by mobruan »

Can i use the PIC to control interrupts on protected mode?
User avatar
neon
Member
Member
Posts: 1568
Joined: Sun Feb 18, 2007 7:28 pm
Contact:

Re: pic and protected mode

Post by neon »

Of course.
OS Development Series | Wiki | os | ncc
char c[2]={"\x90\xC3"};int main(){void(*f)()=(void(__cdecl*)(void))(void*)&c;f();}
mobruan
Member
Member
Posts: 71
Joined: Thu Oct 09, 2008 8:25 am
Location: Rio de Janeiro - Brazil

Re: pic and protected mode

Post 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:
User avatar
neon
Member
Member
Posts: 1568
Joined: Sun Feb 18, 2007 7:28 pm
Contact:

Re: pic and protected mode

Post by neon »

Describe "didnt work".
OS Development Series | Wiki | os | ncc
char c[2]={"\x90\xC3"};int main(){void(*f)()=(void(__cdecl*)(void))(void*)&c;f();}
User avatar
~
Member
Member
Posts: 1228
Joined: Tue Mar 06, 2007 11:17 am
Libera.chat IRC: ArcheFire

Re: pic and protected mode

Post by ~ »

Did you use STI to reenable interrupts somewhere else?
djmauretto
Member
Member
Posts: 116
Joined: Wed Oct 22, 2008 2:21 am
Location: Roma,Italy

Re: pic and protected mode

Post by djmauretto »

Enable A20 :wink:
egos
Member
Member
Posts: 612
Joined: Fri Nov 16, 2007 1:59 pm

Re: pic and protected mode

Post 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
If you have seen bad English in my words, tell me what's wrong, please.
mobruan
Member
Member
Posts: 71
Joined: Thu Oct 09, 2008 8:25 am
Location: Rio de Janeiro - Brazil

Re: pic and protected mode

Post by mobruan »

i didnt work: the isr function dont run...
mobruan
Member
Member
Posts: 71
Joined: Thu Oct 09, 2008 8:25 am
Location: Rio de Janeiro - Brazil

Re: pic and protected mode

Post by mobruan »

I use sti and the computer resets.
User avatar
AJ
Member
Member
Posts: 2646
Joined: Sun Oct 22, 2006 7:01 am
Location: Devon, UK
Contact:

Re: pic and protected mode

Post 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
User avatar
neon
Member
Member
Posts: 1568
Joined: Sun Feb 18, 2007 7:28 pm
Contact:

Re: pic and protected mode

Post by neon »

Code: Select all

org 0x7c00
...
bits 16
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.
OS Development Series | Wiki | os | ncc
char c[2]={"\x90\xC3"};int main(){void(*f)()=(void(__cdecl*)(void))(void*)&c;f();}
mobruan
Member
Member
Posts: 71
Joined: Thu Oct 09, 2008 8:25 am
Location: Rio de Janeiro - Brazil

Re: pic and protected mode

Post by mobruan »

how do i move it to a diferent program?
mobruan
Member
Member
Posts: 71
Joined: Thu Oct 09, 2008 8:25 am
Location: Rio de Janeiro - Brazil

Re: pic and protected mode

Post by mobruan »

The idt is right because when a use a software interrupt(int 33) its work.
How do i align the stack?
User avatar
neon
Member
Member
Posts: 1568
Joined: Sun Feb 18, 2007 7:28 pm
Contact:

Re: pic and protected mode

Post 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.
OS Development Series | Wiki | os | ncc
char c[2]={"\x90\xC3"};int main(){void(*f)()=(void(__cdecl*)(void))(void*)&c;f();}
mobruan
Member
Member
Posts: 71
Joined: Thu Oct 09, 2008 8:25 am
Location: Rio de Janeiro - Brazil

Re: pic and protected mode

Post by mobruan »

do you have a example of a multstage bootloader?
Post Reply