clinux-kernelembedded-linuxsystem-callssoftirq

Is there any way to make a call to linux kernel with my own softirq


Similar to how system call works on int 0x80, is it possible to implement my own ISR inside kernel so that on softirq assume int 0x120 or with any other softirq Program Counter can jump from user space to kernel space?

Is entering kernel in privileged mode is associated only with int 0x80, or with any softirq implementation I can enter privileged mode automatically or for disabling the protected mode and entering into privileged mode we have to do manually by writing its associated flag?

and one more thing, if it is possible to implement this type of ISR, is the best possible way for data exchange is with registers EBX, ECX, EDX, ESI, EDI and EBP or any other way is still there?

I already saw How to define and trigger my own new softirq in linux kernel? but didn't got the solution I was looking for.

I'll make it some more clear, why i need this
I had implemented few kernel functions, which are directly talking to hardware peripherals, I want them to trigger from user space using software interrupt. can't use system calls with available driver architecture because i need to reduce execution time.


Solution

  • First, software interrupts and softirq are completely different: software interrupt is the assembly instruction to switch from user mode to privilege mode and this is what you're looking for softirq is a mechanism to split hardware interrupt handler to top,bottom halfs

    For your question - you'll need to write assembly code and modify platform specific code

    1. You need to define the int number in Linux arch/x86/include/asm/irq_vectors.h:

      #define MY_SYSCALL_VECTOR             0x120
      
    2. Change the function trap_init in Linux arch/x86/kernel/traps.c:

      set_system_trap_gate(MY_SYSCALL_VECTOR, entry_INT120_32);
      
    3. Now you need to write the assembly function entry_INT120_32. you can see an example in the file: arch/x86/entry/entry_32.S starting at ENTRY(entry_INT80_32).

    You'll need to take care of the CPU registers as documented at the beginning of entry_32.S file.