Some IDT Code...in C

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.
Unexpected

Re:Some IDT Code...in C

Post by Unexpected »

Tom, my PIC is intialized and outportb(0x20, 0x20) is before IRET ;)
But here is another problem...

In ASM file:

Code: Select all

EXTERN _KBD_Handler
GLOBAL _IRQ1_Handler

_IRQ1_Handler:
     PUSHA
     CALL _KBD_Handler
     POPA
IRET
In C file:

Code: Select all

...
extern void IRQ1_Handler();
...
void KBD_Handler()
{
     Print("KBD_Test\n");
     ScanCode = inportb(0x60);
     KBD_BufAdd(ScanCode);
     outportb(0x20, 0x20);
}
So if I pressing a key two times, then must print to screen two "KBD_Test" messages...
But prints only one?
Whats the problem?
jrfritz

Re:Some IDT Code...in C

Post by jrfritz »

Does it print the text over itself?

or are you using my Print() C++ function?

Also try printing the ASCII non shifted value of inportb.
whyme_t

Re:Some IDT Code...in C

Post by whyme_t »

Unexpected wrote: If no then why?
Because for irq's 0-7 you must send end of interrupt to master pic.

Code: Select all

//send EOI (0x20) to port 0x20
outportb(0x20, 0x20);
And for irq's 8-15 you must send EOI to both pics.

Code: Select all

//send EOI (0x20) to port (0xA0) and to port(0x20)
outportb(0xA0, 0x20);
outportb(0x20, 0x20);
If you don't send EOI, you will not receive any further interrupts.

In addition to this, the keyboard will not trigger another interrupt until you read the scancode from port 0x60.

Code: Select all

int scancode = inportb( 0x60 );
whyme_t

Re:Some IDT Code...in C

Post by whyme_t »

Unexpected, try disabling interrupts as you enter your isr, and enable them before you leave.
Unexpected

Re:Some IDT Code...in C

Post by Unexpected »

I'm using my own Print function and it work correctly ;)
I think error is somewhere in handlers and asm mixing with C...
jrfritz

Re:Some IDT Code...in C

Post by jrfritz »

I don't mean to be rude, but this is like two people fighing over the same thread...i'm going to start a new one.
Unexpected

Re:Some IDT Code...in C

Post by Unexpected »

Sorry Tom, I just want to clear up with interrupts...
jrfritz

Re:Some IDT Code...in C

Post by jrfritz »

It's ok...keep posting here...I already have a new thread.
Slasher

Re:Some IDT Code...in C

Post by Slasher »

hi,
if you are not using paging, then their is no need to map anything!
also what is the selector you placed in the SS register?
has to be one thai spans the whole address space if you are going to put 0xffffffff in ESP.
jrfritz

Re:Some IDT Code...in C

Post by jrfritz »

0x10 is what I put into AX, then put ax into ss.
hanoi

Re:Some IDT Code...in C

Post by hanoi »

hey
I have also some problems with my IDT
-Code-
C:
typedef struct {
   unsigned short int Offset1;
   unsigned short int Segment;
   unsigned short int t;
   unsigned short int Offset2;
} intdes;
typedef struct
{
   unsigned short limit;
   intdes *lIDT;
} IDTR;

typedef union
{
   void *p;
   unsigned short a;
   unsigned short b;
} part;

extern void unhandled();
void setVector(int nr, void *function);
void LIDT();
void STI();

intdes IDT[256];
IDTR sysreg;

for(i=0; i <256; i++)
   {
   setVector(i, (void *)(unhandled));
   }
   LIDT();
   asm("sti");

void setVector(int nr, void *function)
{
   intdes n;
   part p;
   p.p = function;
   n.Offset1 = p.a;
   n.Offset2 = p.b;
   n.Segment = 0x8;
   n.t = 0x8e00;
   IDT[nr] = n;
   return;
}


void LIDT()
{
   sysreg.limit = 1024;
   sysreg.lIDT = IDT;
   asm volatile ("lidt _sysreg");
   return;
}
asm:
[extern _unhandled]
_unhandled:
iret
-Code-
problem: 31d exception(14)
thank you
hanoi

Re:Some IDT Code...in C

Post by hanoi »

ahya, the __attribute__ ((packed)) doesn't change anything
thanks
hanoi

Re:Some IDT Code...in C

Post by hanoi »

if paging isn't switched on, i get 3rd(13)
hanoi

Re:Some IDT Code...in C

Post by hanoi »

i have changed now:
void LIDT()
{
unsigned int x[2];

x[0]=((256*sizeof(intdes))-1)<<16;
x[1]= (unsigned int)IDT;

__asm__ __volatile__ ("lidt (%0)"::"d"((int)((unsigned char*)x)+2):"memory");
return;
}

now i got:
-3rd(12)(stack error) when i set stack to 0x7BFF (code is at 0x100000)
-3rd(13)(general protection fault) when i set stack to 0x9FFFF; bochs says:
00001024150i[CPU ] WARNING: Encountered an unknown instruction (signalling illegal instruction):
00001024182i[CPU ] BxError: instruction with op1=0xfe
00001024182i[CPU ] nnn was 4
00001024182i[CPU ] WARNING: Encountered an unknown instruction (signalling illegal instruction):
00001024182p[CPU ] >>PANIC<< exception(): 3rd (13) exception with no resolution
00001024182i[SYS ] Last time is 1040895234
00001024182i[CPU ] protected mode
00001024182i[CPU ] CS.d_b = 32 bit
00001024182i[CPU ] SS.d_b = 32 bit
00001024182i[CPU ] | EAX=0009fff7 EBX=00000007 ECX=000017fa EDX=0009ffd1
00001024182i[CPU ] | ESP=00007be5 EBP=000a16f2 ESI=000207d8 EDI=001107d8
00001024182i[CPU ] | IOPL=0 NV UP DI NG NZ AC PO CY
00001024182i[CPU ] | SEG selector base limit G D
00001024182i[CPU ] | SEG sltr(index|ti|rpl) base limit G D
00001024182i[CPU ] | DS:0010( 0002| 0| 0) 00000000 000fffff 1 1
00001024182i[CPU ] | ES:0010( 0002| 0| 0) 00000000 000fffff 1 1
00001024182i[CPU ] | FS:0000( 0000| 0| 0) 00000000 0000ffff 0 0
00001024182i[CPU ] | GS:0000( 0000| 0| 0) 00000000 0000ffff 0 0
00001024182i[CPU ] | SS:0010( 0002| 0| 0) 00000000 000fffff 1 1
00001024182i[CPU ] | CS:0008( 0001| 0| 0) 00000000 000fffff 1 1
00001024182i[CPU ] | EIP=0000004c (0000004c)
00001024182i[CPU ] | CR0=0xe0000011 CR1=0x00000000 CR2=0x00000000
00001024182i[CPU ] | CR3=0x00300000 CR4=0x00000000 strange, isn't it?
hanoi

Re:Some IDT Code...in C

Post by hanoi »

i mean the EIP of course
Post Reply