Page 1 of 1

[SOLVED]Initializing paging stops the IRQ and ISR handler...

Posted: Thu Nov 11, 2010 8:44 am
by Almamu
While i was rewriting my kernel, cause it get too heavy and without a lot of things necessaries for a kernel i have encountered with a problem. I'm working in the paging, it works correctly, i can start all i want(multitasking, user mode, timer...), but, when i enable paging, all the IRQs stop sending data and the ISR handler stops working... I have heap working... Any idea why this is caused ?

Re: Initializing paging stops the IRQ and ISR handler...

Posted: Thu Nov 11, 2010 9:21 am
by NickJohnson
The GDT is loaded as a virtual address, not a physical one. If you turn on paging and the GDT moves, you need to give the processor the GDT's new address. I would think that the system would triple fault if that was the mistake, but I suppose it could simply hang if you had the kernel wait for interrupts.

Re: Initializing paging stops the IRQ and ISR handler...

Posted: Thu Nov 11, 2010 9:27 am
by Almamu
NickJohnson wrote:The GDT is loaded as a virtual address, not a physical one. If you turn on paging and the GDT moves, you need to give the processor the GDT's new address. I would think that the system would triple fault if that was the mistake, but I suppose it could simply hang if you had the kernel wait for interrupts.
Ok, so i should resend the GDT and IDT to CPU, thats right ?

EDIT: I cant do this cause im using an interrupt to detect any page fault...

Re: Initializing paging stops the IRQ and ISR handler...

Posted: Thu Nov 11, 2010 11:21 am
by NickJohnson
Well, did the locations of the GDT and IDT change when you turned on paging? I'm not sure that the GDT and IDT addresses are the problem, it's just a guess. The existence of a page fault handler should have no affect on whether you can reload the GDT and IDT.

Re: Initializing paging stops the IRQ and ISR handler...

Posted: Thu Nov 11, 2010 11:23 am
by Combuster
I expect interrupts to be off - otherwise there's nothing that *prevents* IRQs (rather they should cause crashes because the tables are no longer where the processor thinks they are)

Re: Initializing paging stops the IRQ and ISR handler...

Posted: Fri Nov 12, 2010 11:51 am
by Almamu
Combuster wrote:I expect interrupts to be off - otherwise there's nothing that *prevents* IRQs (rather they should cause crashes because the tables are no longer where the processor thinks they are)
Ok, now seems to work(atleast with the syscalls_ functions, they use interrupts...)but now my keyboard handler doesn't seems to work. It works before i initialise paging, but when i initialize it the drivers stops working, thats my code:

Code: Select all

unsigned char keymap[128] =
{
    0,  27, '1', '2', '3', '4', '5', '6', '7', '8',
  '9', '0', '-', '=', '\b',
  '\t',
  'q', 'w', 'e', 'r',
  't', 'y', 'u', 'i', 'o', 'p', '[', ']', '\n',
    0,
  'a', 's', 'd', 'f', 'g', 'h', 'j', 'k', 'l', ';',
 '\'', '`',   0,
 '\\', 'z', 'x', 'c', 'v', 'b', 'n',
  'm', ',', '.', '/',   0,
  '*',
    0,	
  ' ',	
    0,
    0,
    0,   0,   0,   0,   0,   0,   0,   0,
    0,
    0,
    0,
    0,
    0,
    0,
  '-',
    0,
    0,
    0,
  '+',
    0,
    0,
    0,
    0,
    0,
    0,   0,   0,
    0,
    0,
    0,
};

// Read keyboard buffer
unsigned char keyboard_data(){
	unsigned char scancode;
	scancode = inb(0x60);
	return scancode;
}
static void keyboard_handler(registers_t *regs)
{
    unsigned char scancode;

    scancode = keyboard_data();
    // Write the data to the screen
    monitor_put(keymap[scancode]);
}

// Keyboard in IRQ1
void init_keyboard()
{
    register_interrupt_handler(IRQ1, &keyboard_handler);
}
Maybe im doing something wrong, or the keymap is incorrect, plus im on PMODE with A20 Line before i initialize all the systems(paging, etc...)

P.D: I know that i should scan for shift, caps, num lock, control... keys press, but atm i only want to prin a character to the screen readed from the keyboard...

Re: Initializing paging stops the IRQ and ISR handler...

Posted: Sat Nov 13, 2010 6:17 pm
by Combuster
Syscalls are not hardware interrupts.

Also, how come this question turns out to be in the FAQ? I somehow doubt you checked it.

Re: Initializing paging stops the IRQ and ISR handler...

Posted: Wed Nov 17, 2010 8:45 am
by Almamu
Combuster wrote:Syscalls are not hardware interrupts.

Also, how come this question turns out to be in the FAQ? I somehow doubt you checked it.
If you read the problem comes up when i start paging, and not when i initialize the PIT, i can receive ISRs but no IRQs, so "When I try to enable the PIT, the keyboard doesn't work anymore" and "I'm not receiving any IRQ" are not my problems, as you know, the IRQs works when no paging is enabled... This is my IRQ remap, maybe this is wrong:

Code: Select all

    outb(0x20, 0x11);
    outb(0xA0, 0x11);
    outb(0x21, 0x20);
    outb(0xA1, 0x28);
    outb(0x21, 0x04);
    outb(0xA1, 0x02);
    outb(0x21, 0x01);
    outb(0xA1, 0x01);
    outb(0x21, 0x0);
    outb(0xA1, 0x0);

Re: Initializing paging stops the IRQ and ISR handler...

Posted: Wed Nov 17, 2010 11:33 am
by Combuster
You (summarized) wrote:i can receive ISRs but no IRQs, so "I'm not receiving any IRQ" are not my problems
:^o

Re: Initializing paging stops the IRQ and ISR handler...

Posted: Wed Nov 17, 2010 1:02 pm
by gravaera
Hi:

An "interrupt" can be triggered in one of three ways: "software interrupts" are caused by executing a specific instruction which triggers an interrupt. "External", or "hardware" interrupts are raised by devices on the chipset, and they are known as "IRQs". "Exceptions" are internally generated interrupts which the processor raises when it needs to trap into the system software.

All three types of interrupts all eventually trap into the kernel. The kernel sets up "handler" functions for each type of interrupt it knows, whether generated by software, generated internally, or signaled externally. These "handlers" are known as "ISRs", which when expanded means: "Interrupt Service Routines". Interrupts trap into the kernel and the CPU vectors into some table or other and enters an ISR.

So you can't "receive" an ISR. You get an interrupt, and the CPU vectors and enters the kernel, and your kernel directs it to one or more ISRs. Just thought you should know so you could word your problem better, seeing as not doing so hasn't worked out too well for you so far.

Re: Initializing paging stops the IRQ and ISR handler...

Posted: Thu Nov 18, 2010 7:41 am
by Almamu
Combuster wrote:
You (summarized) wrote:i can receive ISRs but no IRQs, so "I'm not receiving any IRQ" are not my problems
:^o
Im talking when paging is enabled, if i disable it i can recevie IRQs and ISRs and handle them.

EDIT: Seems that now i can receive interrupts before switching to user mode...
usermode:

Code: Select all

      cli
      mov $0x23, ax
      mov ax, ds
      mov ax, es
      mov ax, fs
      mov ax, gs
      mov esp, eax
      pushl $0x23
      pushl esp
      pushf
      pushl $0x1B
      push $1f
      iret
void switch_to_user_mode():

Code: Select all

    set_kernel_stack(current_task->kernel_stack+KERNEL_STACK_SIZE);
    usermode();
EDIT2: Fixed, the ASM code was wrong, this is my new code in the asm file:

Code: Select all

      cli
      mov $0x23, ax
      mov ax, ds
      mov ax, es
      mov ax, fs
      mov ax, gs
      mov esp, eax
      pushl $0x23
      pushl esp
      pushf
      pushl $0x1B
      push $1f
      sti
      ret

Re: [SOLVED]Initializing paging stops the IRQ and ISR handle

Posted: Thu Nov 18, 2010 11:35 am
by Combuster
You have a real problem there.

Why are you mixing intel syntax and ATT syntax - half that code is not doing what you think it does, such as setting ESP to the value in GS

Re: [SOLVED]Initializing paging stops the IRQ and ISR handle

Posted: Sat Nov 20, 2010 6:15 am
by Almamu
Combuster wrote:You have a real problem there.

Why are you mixing intel syntax and ATT syntax - half that code is not doing what you think it does, such as setting ESP to the value in GS
Ok, so, how do you think that this code should look ?

Re: [SOLVED]Initializing paging stops the IRQ and ISR handle

Posted: Sat Nov 20, 2010 7:59 am
by Combuster
Almamu wrote:
Combuster wrote:You have a real problem there.

Why are you mixing intel syntax and ATT syntax - half that code is not doing what you think it does, such as setting ESP to the value in GS
Ok, so, how do you think that this code should look ?
Since you asked, it should look like it was written by someone who knew what he was doing.

Seriously, I pointed out an error, including example. What more did you expect? Us writing your OS?