9

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.

Community
  • 1
  • 1
Samrat Das
  • 1,781
  • 1
  • 21
  • 33
  • The easiest way to enter kernel mode in Linux is to write your own driver. – n. m. could be an AI Apr 18 '16 at 07:46
  • 1
    only that was not my requirement, how to enter kernel mode with a new soft interrupt from user space is what i was looking for – Samrat Das Apr 18 '16 at 08:04
  • Please explain your problem not what you think might be the implementation. – Harry Apr 18 '16 at 08:05
  • 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. – Samrat Das Apr 18 '16 at 08:10

1 Answers1

4

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.

Sam Protsenko
  • 14,045
  • 4
  • 59
  • 75
Liran Ben Haim
  • 436
  • 3
  • 10