valid idt

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

valid idt

Post by mobruan »

hi, why this is not a valid idt?
Thanks
mobruan
Member
Member
Posts: 71
Joined: Thu Oct 09, 2008 8:25 am
Location: Rio de Janeiro - Brazil

Re: valid idt

Post by mobruan »

o32 mov eax, dword isr
o32 mov [3000], dword eax
mov ax, word [3002] ;interrupt descriptor
mov [3002], word 0x8
mov [3003], byte 0
mov [3004], byte 10001110b
mov [3005], word 0

mov [1006], word 263 ;limit
mov [1008], word 2992 ;base address idt
mov [1010], word 0x0000

lidt [1006]
User avatar
Combuster
Member
Member
Posts: 9301
Joined: Wed Oct 18, 2006 3:45 am
Libera.chat IRC: [com]buster
Location: On the balcony, where I can actually keep 1½m distance
Contact:

Re: valid idt

Post by Combuster »

Why are you systematically getting complaints about your coding style?

People can't read this. Rewrite it.
"Certainly avoid yourself. He is a newbie and might not realize it. You'll hate his code deeply a few years down the road." - Sortie
[ My OS ] [ VDisk/SFS ]
Craze Frog
Member
Member
Posts: 368
Joined: Sun Sep 23, 2007 4:52 am

Re: valid idt

Post by Craze Frog »

How can people complain of his coding style? He doesn't even have one!
User avatar
Combuster
Member
Member
Posts: 9301
Joined: Wed Oct 18, 2006 3:45 am
Libera.chat IRC: [com]buster
Location: On the balcony, where I can actually keep 1½m distance
Contact:

Re: valid idt

Post by Combuster »

hear hear!
"Certainly avoid yourself. He is a newbie and might not realize it. You'll hate his code deeply a few years down the road." - Sortie
[ My OS ] [ VDisk/SFS ]
User avatar
neon
Member
Member
Posts: 1567
Joined: Sun Feb 18, 2007 7:28 pm
Contact:

Re: valid idt

Post by neon »

I hope you are not going to use that coding style for every single entry in the IDT...

Also, why are you setting the base address to the first idt descriptor entry - 8 bytes? The IDT doesnt reserve the first entry. IDTRs base address should point to the first entry in your IDT. (assumes I read your code right)
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: valid idt

Post by mobruan »

i like this way! hear...
now serius what is the other way, give me some example...
thanks!
User avatar
neon
Member
Member
Posts: 1567
Joined: Sun Feb 18, 2007 7:28 pm
Contact:

Re: valid idt

Post by neon »

i like this way! hear...
now serius what is the other way, give me some example...
thanks!
Can you rephrase this? I dont understand what you are referring to here.

If you are referring to your coding style, and are looking for other methods, simply search google. There are plenty of examples online (Some were provided in your previous threads).

If you are referring to my response with regards to the way you have set up the IDTR, that is the *only* way (That I know of, anyways) as described inside of the intel processor manuals.
OS Development Series | Wiki | os | ncc
char c[2]={"\x90\xC3"};int main(){void(*f)()=(void(__cdecl*)(void))(void*)&c;f();}
User avatar
Walling
Member
Member
Posts: 158
Joined: Mon Dec 04, 2006 6:06 am
Location: Berlin, Germany

Re: valid idt

Post by Walling »

mobruan wrote:i like this way! hear...
now serius what is the other way, give me some example...
thanks!
Personally I would enter 32-bit protected mode and set up the IDT afterwards (and maybe code it in C). It makes it easier to handle things like 32-bit pointers. Just remember to disable interrupts until the IDT is setup.

Also try separating code and data, like this (I tried rewriting your code, it might contain errors though):

Code: Select all

SECTION .text ; Code section
BITS 32 ; We entered protected mode

    ...
setup_idt:
    ; Setup IDT entry 1 pointing to 'isr'.
    mov  eax, isr              ; Load the ISR offset in EAX
    mov  [idt_entry_1 + 0], ax ; Store the offset bits 0..15
    shr  eax, 16
    mov  [idt_entry_1 + 6], ax ; Store the offset bits 16..31
    ; Load IDT.
    lidt [idt]
    ...


SECTION .data ; Data section

idt:
    dw idt_table_end - idt_table_begin - 1 ; Limit (automatically calculated)
    dd idt_table_begin                     ; Base address

idt_table_begin:
; The following really should be replaced by some macro... google!
idt_entry_0:
    dw 0            ; Offset bits 0..15
    dw 0x8          ; Code segment selector
    db 0, 10001110b ; Type and attributes
    dw 0            ; Offset bits 16..31
idt_entry_1:
    dw 0            ; Offset bits 0..15
    dw 0x8          ; Code segment selector
    db 0, 10001110b ; Type and attributes
    dw 0            ; Offset bits 16..31
    ...
idt_table_end:
Oh, and by the way, use indentation and use [ code] [ /code] tags in your posts. :)
egos
Member
Member
Posts: 612
Joined: Fri Nov 16, 2007 1:59 pm

Re: valid idt

Post by egos »

The static IDT does not need initializing at all.

Code: Select all

  lidt [IDTR]
  ...

  align 2
IDTR:
  dw IDT_SIZE-1 ; 256*8-1
  dd IDT

  align 8
IDT:
  desc KCODE, ehandler_0, DF_INT32 ; or DF_TRAP32
  desc KCODE, ehandler_1, DF_INT32 ; or DF_TRAP32
  ...
  IDT_SIZE = $-IDT
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: valid idt

Post by mobruan »

Thanks!
I´ll try do this way!
mobruan
Member
Member
Posts: 71
Joined: Thu Oct 09, 2008 8:25 am
Location: Rio de Janeiro - Brazil

Re: valid idt

Post by mobruan »

it´s me again, i dont know how to use assembly together with c.
Anyone has a good tutorial?
User avatar
Walling
Member
Member
Posts: 158
Joined: Mon Dec 04, 2006 6:06 am
Location: Berlin, Germany

Re: valid idt

Post by Walling »

mobruan wrote:it´s me again, i dont know how to use assembly together with c.
Anyone has a good tutorial?
You can find a lot of information about linking object files or using inline asm in C on the wiki and the web. Have you read the forum rules, and have you searched for the knowledge yourself?
Post Reply