BMW wrote:<snip> So if you were using IRQ 2 for system calls (what I use in my OS): <snip> I'm not sure why you are using interrupt 0x7F as your IRQs are only interrupts 32-47. <snip>
Well... I'm not sure why you'd limit yourself to the IRQ range? Those things are usually wired up to devices (legacy devices yes, but still) and when you go into the APIC or the PCI business, you'll want to allocate IRQs from that range to various devices.
Nothing stops you from using values greater than 47. IIRC the IDT is able to handle up to 256 entries, so you can use anything from 0x30 to 0xFF. Linux uses 0x80, Windows uses something else, I personally use 0xF8.
BMW wrote:EDIT #2: Actually, if he goes straight to his syscall_handler() (i.e. puts that in the IDT), the value of EAX should still be in the register shouldn't it? So @joshbeitler, either use the value of the register EAX in your syscall_handler() or use the 'global handler'.
Mmhmm. But looking at your code Josh, a couple of things;
1. You should handle the system call in assembly.
2. In your void syscall_handler(cpu::regs* r), you're expecting a pointer to a structure on the stack. Forgive me if I'm wrong, but I think %eax is used to pass the first parameter in x86... so your 'pointer' is the value of %eax, which is zero; so you're probably getting rubbish values from the BIOS IVT.
Instead, make your system call handler in assembly, it's not too difficult;
Code: Select all
// multiply %r10 by 8
salq $3, %r10
movq SyscallTable(%r10), %r10
jmp *%r10
CleanUp:
iretq
// Syscall functions
PrintChar:
call Syscall_PrintChar
jmp CleanUp
Fail:
jmp CleanUp
// End
.section .data
// Function table
.align 8
SyscallTable:
.quad Fail
.quad PrintChar
That's what I use. You'd put the sys call number in some register, and since you're in 32-bit mode, shift it by two, not three; then replace '.quad' with '.long'.
Not difficult.
Your problem lies in the face that you're still expecting syscall_handler to get registers passed to it on the stack, by means of your global handler. Since you bypass that, you can just pluck the values straight from the register. Pushing all the values on the stack would be unnecessary.
Remember though what you call in the assembly (Syscall_PrintChar in my case), needs to be prefixed with extern "C".
@BMW: no offence but we're probably confusing him with conflicting advice hahaha
