Page 8 of 9

Re:Some IDT Code...in C

Posted: Wed Dec 18, 2002 3:06 pm
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?

Re:Some IDT Code...in C

Posted: Wed Dec 18, 2002 3:13 pm
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.

Re:Some IDT Code...in C

Posted: Wed Dec 18, 2002 3:17 pm
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 );

Re:Some IDT Code...in C

Posted: Wed Dec 18, 2002 3:20 pm
by whyme_t
Unexpected, try disabling interrupts as you enter your isr, and enable them before you leave.

Re:Some IDT Code...in C

Posted: Wed Dec 18, 2002 3:21 pm
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...

Re:Some IDT Code...in C

Posted: Wed Dec 18, 2002 3:37 pm
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.

Re:Some IDT Code...in C

Posted: Wed Dec 18, 2002 3:55 pm
by Unexpected
Sorry Tom, I just want to clear up with interrupts...

Re:Some IDT Code...in C

Posted: Wed Dec 18, 2002 4:06 pm
by jrfritz
It's ok...keep posting here...I already have a new thread.

Re:Some IDT Code...in C

Posted: Thu Dec 19, 2002 2:26 pm
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.

Re:Some IDT Code...in C

Posted: Thu Dec 19, 2002 2:28 pm
by jrfritz
0x10 is what I put into AX, then put ax into ss.

Re:Some IDT Code...in C

Posted: Wed Dec 25, 2002 3:11 pm
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

Re:Some IDT Code...in C

Posted: Wed Dec 25, 2002 3:13 pm
by hanoi
ahya, the __attribute__ ((packed)) doesn't change anything
thanks

Re:Some IDT Code...in C

Posted: Wed Dec 25, 2002 3:14 pm
by hanoi
if paging isn't switched on, i get 3rd(13)

Re:Some IDT Code...in C

Posted: Thu Dec 26, 2002 3:39 am
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?

Re:Some IDT Code...in C

Posted: Thu Dec 26, 2002 3:40 am
by hanoi
i mean the EIP of course