Issues with system call
Re: Issues with system call
When going through my IRQ handler, I get a general protection fault. The only thing I can think might be causing this would be IRQ map conflicts, as the fault only happens when I call "int $0x7F".
Re: Issues with system call
Hello again.
A couple of issues:
1. I don't know if this is intentional, but your isr_handler simply calls core::panic().
2. I think your problem lies in the fact that you didn't do a idt::set_gate for your sys call handler.
3. As it is now, when you do int $0x7F, the CPU will start faulting all over the place, because you don't have an interrupt handler set for that vector. You simply set an entry in the array (which, BTW, only needs to be 256 - 32 entries long) -- the thing is, you never get to irq_handler to call the system call handler inside the array, because you didn't register your irq127() function (in irq.asm) inside the IDT, which is why the CPU faults.
4. Because your system call goes through your global handler (ie. irq_handler() ), you need to either get rid of the clause { if (r->int_no > 47 || r->int_no < 32) }, or modify it to allow your system call through.
5. Remove the isr127() function in your ASM, it's not required.
A couple of issues:
1. I don't know if this is intentional, but your isr_handler simply calls core::panic().
2. I think your problem lies in the fact that you didn't do a idt::set_gate for your sys call handler.
Code: Select all
extern "C" irq127();
...
idt::set_gate(127, (unsigned long)irq127, 0x08, 0xEE);
3. As it is now, when you do int $0x7F, the CPU will start faulting all over the place, because you don't have an interrupt handler set for that vector. You simply set an entry in the array (which, BTW, only needs to be 256 - 32 entries long) -- the thing is, you never get to irq_handler to call the system call handler inside the array, because you didn't register your irq127() function (in irq.asm) inside the IDT, which is why the CPU faults.
4. Because your system call goes through your global handler (ie. irq_handler() ), you need to either get rid of the clause { if (r->int_no > 47 || r->int_no < 32) }, or modify it to allow your system call through.
5. Remove the isr127() function in your ASM, it's not required.
[nx] kernel: http://github.com/zhiayang/nx
Re: Issues with system call
I've got those things, though it still isn't working. I register the entry in the IDT and with my IRQ handler, but I'm still getting garbage values.As it is now, when you do int $0x7F, the CPU will start faulting all over the place, because you don't have an interrupt handler set for that vector. You simply set an entry in the array (which, BTW, only needs to be 256 - 32 entries long) -- the thing is, you never get to irq_handler to call the system call handler inside the array, because you didn't register your irq127() function (in irq.asm) inside the IDT, which is why the CPU faults.
Code: Select all
cpu::idt::set_gate(0x7F, (unsigned long)syscall_handler, 0x08, 0x8E);
cpu::irq::install_handler(127, syscall_handler);
Re: Issues with system call
In your irq::gates function, you setup the system call IRQ so that it goes through your global IRQ handler (which is correct)joshbeitler wrote:I've got those things, though it still isn't working. I register the entry in the IDT and with my IRQ handler, but I'm still getting garbage values.Code: Select all
cpu::idt::set_gate(0x7F, (unsigned long)syscall_handler, 0x08, 0x8E); cpu::irq::install_handler(127, syscall_handler);
Code: Select all
void irq::gates()
{
...
idt::set_gate(127, (unsigned long)irq127, 0x08, 0xEE);
}
Code: Select all
void init_syscalls()
{
cpu::idt::set_gate(0x7F, (unsigned long)syscall_handler, 0x08, 0x8E); // This line is incorrect
cpu::irq::install_handler(127, syscall_handler);
}
EDIT: While browsing your source, I have spotted some more issues:
You are meant to send an EOI to the slave controller if the IRQ number is greater than or equal to 8, however you are only sending it if the IRQ number is greater than or equal to 12:
Code: Select all
void irq::ack(int irq_no)
{
if (irq_no >= 12)
{
outb(0xA0, 0x20);
}
outb(0x20, 0x20);
}
In your irq_handler, you only send an EOI if there is no handler. Why? You should send an EOI whether you handled the IRQ or not.
Code: Select all
extern "C" void irq_handler(struct regs* r)
{
void (*handler)(struct regs* r);
handler = irq_routines[r->int_no - 32];
if (handler)
handler(r);
else
irq::ack(r->int_no - 32);
}
Code: Select all
extern "C" void irq_handler(struct regs* r)
{
void (*handler)(struct regs* r);
handler = irq_routines[r->int_no - 32];
if (handler)
handler(r);
irq::ack(r->int_no - 32);
}
Last edited by BMW on Mon Dec 16, 2013 4:26 am, edited 2 times in total.
Currently developing Lithium OS (LiOS).
Recursive paging saves lives.
"I want to change the world, but they won't give me the source code."
Recursive paging saves lives.
"I want to change the world, but they won't give me the source code."
- Combuster
- 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: Issues with system call
What nonsense is this?BMW wrote:IRQ 95
IRQ0 - IRQ15 are the names for the (virtual) pins on the PIC, each connected to a specific legacy device. The PIC maps these to interrupt numbers, which means that IRQ 0 can manifest itself as a wide range of interrupt numbers. Traditionally the likely results for IRQ0 are either interrupt 8 or 32, but any multiple of 8 is technically possible.
If you have modern hardware with the necessary driver support, each hardware interrupt source can be mapped to any interrupt number, and in many cases there isn't even an physical interrupt line involved, let alone being numbered.
Re: Issues with system call
Sorry, I was waffling based on a stupid assumption.Combuster wrote:What nonsense is this?BMW wrote:IRQ 95![]()
IRQ0 - IRQ15 are the names for the (virtual) pins on the PIC, each connected to a specific legacy device. The PIC maps these to interrupt numbers, which means that IRQ 0 can manifest itself as a wide range of interrupt numbers. Traditionally the likely results for IRQ0 are either interrupt 8 or 32, but any multiple of 8 is technically possible.
If you have modern hardware with the necessary driver support, each hardware interrupt source can be mapped to any interrupt number, and in many cases there isn't even an physical interrupt line involved, let alone being numbered.
What is the actual difference between an interrupt and an IRQ? Is the interrupt the OP is using for system calls actually an IRQ? I thought IRQs were caused by hardware.
Currently developing Lithium OS (LiOS).
Recursive paging saves lives.
"I want to change the world, but they won't give me the source code."
Recursive paging saves lives.
"I want to change the world, but they won't give me the source code."
- Combuster
- 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: Issues with system call
What is the difference between an actual interrupt and an Interrupt ReQuest?What is the actual difference between an interrupt and an IRQ?
Re: Issues with system call
Wait, I think I just got it. An Interrupt ReQuest (IRQ) is a interrupt requested by a hardware device, hence the name IRQ. IRQs are mapped to interrupts by sending commands to the PIC. So if you call an interrupt from your program which corresponds to an IRQ e.g. INT 34, although it may go through an IRQ handler, it is not actually an IRQ?Combuster wrote:What is the difference between an actual interrupt and an Interrupt ReQuest?What is the actual difference between an interrupt and an IRQ?
Is that correct, or am I waffling based on more assumptions?
Currently developing Lithium OS (LiOS).
Recursive paging saves lives.
"I want to change the world, but they won't give me the source code."
Recursive paging saves lives.
"I want to change the world, but they won't give me the source code."
Re: Issues with system call
Wow. That has to be some of the worst advice I've seen on the Internet in a while.BMW wrote:So, what you need to do is change the init_syscalls() function so that it sets up your system call handler correctly by going to your IRQ handler. So if you were using IRQ 2 for system calls (what I use in my OS):
Re: Issues with system call
And that has to be one of the worst posts I've seen in a while. Aside from being void of any informational quality, it criticizes without reason. If you are going to criticize my advice, fine, but at least tell me why you are criticizing it.Gigasoft wrote:Wow. That has to be some of the worst advice I've seen on the Internet in a while.
Currently developing Lithium OS (LiOS).
Recursive paging saves lives.
"I want to change the world, but they won't give me the source code."
Recursive paging saves lives.
"I want to change the world, but they won't give me the source code."
- Combuster
- 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: Issues with system call
What lack of reason? Your fundamental ideas have been broken and you already admitted to waffling. And while you might have cut out one particular source of the comment, there's still an entire rest of a post originally written with a lack of understanding you did not fix. You can expect mockery and people putting up warning signs for the OP - they're the same text anyway.
And let's be honest here, how do you imagine software performing a system call by invoking IRQ2 - which is a wire outside of the processor?

And let's be honest here, how do you imagine software performing a system call by invoking IRQ2 - which is a wire outside of the processor?
And by the way, it looks like you gave someone else something memorable to talk about to his friends. Congratulations.The forum rules wrote:When this happens, the worst thing you can do is whine about the experience, claim to have been verbally assaulted, demand apologies, scream, hold your breath, threaten lawsuits, complain to people's employers, leave the toilet seat up, etc. Instead, here's what you do:
Get over it. It's normal. In fact, it's healthy and appropriate.
Re: Issues with system call
@Gigasoft, I did not advise the OP to use IRQ 2, I only said (erroneously, I admit) that I use it it my OS. That erroneous statement was due to a lack of understanding, on my part, of IRQs, which Combuster kindly pointed out and corrected me on. I learned from that mistake because Combuster constructively criticized me, however the criticism given by you was pure criticism, and therefore pointless.
Thanks for pointing that out.
By "lack of reason" I meant he didn't supply a reason. He may have a good reason, but he didn't tell me. How do you expect me to learn from a mistake if I don't know the mistake?Combuster wrote:What lack of reason?
Combuster wrote:And let's be honest here, how do you imagine software performing a system call by invoking IRQ2 - which is a wire outside of the processor?![]()
The forum rules wrote:When this happens, the worst thing you can do is whine about the experience, claim to have been verbally assaulted, demand apologies, scream, hold your breath, threaten lawsuits, complain to people's employers, leave the toilet seat up, etc. Instead, here's what you do:
Get over it. It's normal. In fact, it's healthy and appropriate.
- Click: http://forum.osdev.org/viewtopic.php?f=1&t=16944
- Ctrl + F -> Type "When this happens, the worst thing you can do"
- Observe the result - no matches
- Wonder what Combuster was quoting from
Currently developing Lithium OS (LiOS).
Recursive paging saves lives.
"I want to change the world, but they won't give me the source code."
Recursive paging saves lives.
"I want to change the world, but they won't give me the source code."
- Combuster
- 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: Issues with system call
Observe the result - no matches

Follow the #includes. Particularly the one in point 4.
Re: Issues with system call
@requimrar: After I implemented your changes, the handler isn't even getting called anymore.
Re: Issues with system call
Hello.
In your irq::gates() function, you correctly set irq127() to be called on irq 127. From there, it enters your global handler; all expected.
Here's your problem: in your syscall_install() function, you install your system call handler into entry number 127. However, in your global handler, you attempt to call the handler at position (127 - 32).
Since your syscall uses interrupt 0x7F, entry 127 is the absolute index -- there are two wags to fix this.
1. In your irq_install() function, subtract 32 from the given index. (ie. handlers[num - 32])
2. In your global handler, don't subtract 32. (ie. call handlers[regs->id] directly)
Both will require you add 32 to existing calls to irq_install; irq 0, the PIT interrupt, will now be vector 32. (0 + 32), and so on.
The other solution is not to modify install_handler(), but instead change install_syscall() to call irq_install with (127 - 32).
Choose whichever you think is best.
In your irq::gates() function, you correctly set irq127() to be called on irq 127. From there, it enters your global handler; all expected.
Here's your problem: in your syscall_install() function, you install your system call handler into entry number 127. However, in your global handler, you attempt to call the handler at position (127 - 32).
Since your syscall uses interrupt 0x7F, entry 127 is the absolute index -- there are two wags to fix this.
1. In your irq_install() function, subtract 32 from the given index. (ie. handlers[num - 32])
2. In your global handler, don't subtract 32. (ie. call handlers[regs->id] directly)
Both will require you add 32 to existing calls to irq_install; irq 0, the PIT interrupt, will now be vector 32. (0 + 32), and so on.
The other solution is not to modify install_handler(), but instead change install_syscall() to call irq_install with (127 - 32).
Choose whichever you think is best.
[nx] kernel: http://github.com/zhiayang/nx

