0
void test_task_a(void)
{
    int i, j, k;
    k = 0;
    /* Normal: trigger #GP */
    /*asm (
        "int $32\n\t"
    );*/
    while(TRUE){
        for(i = 0; i < 100; i++){
            for(j = 0; j < 10000; j++){} //delay
        }
        printf("#{A}-> %d", k++);

        /* Error: No trigger #GP */
        asm (
            "int $32\n\t"
        );
    }
    
}

`First of all, the function's CPL = 1, the interrupt gate DPL = 0, the interrupt target code segment DPL = 0, when the soft interrupt is called, it does not meet the authority management, and the #GP exception will be triggered under normal circumstances.

The soft interrupt is called from different positions in a function, position 1 is normal, and position 2 returns to real mode from protection mode directly. I deliberately set the register information before calling the soft interrupt in position 2 to be the same as that before calling the soft interrupt in position 1, and still return to the real mode from the protected mode. why is this happening? `

  • 1
    Going to be hard to guess without seeing your kernel code, I think. You tagged this [nasm] but didn't post any NASM source code, or any machine state from anything like Bochs's built-in debugger to confirm the privilege levels and so on you're talking about. Are you sure your printf itself isn't switching to real mode, e.g. if you're using real-mode BIOS calls for output? – Peter Cordes Nov 09 '21 at 09:08
  • Thank you for your answer sincerely. The problem has been found: the internal memory of the `printf` function is out of bounds due to large local variables, covering the area of the `TSS`. By adding these `"movl $0x68a8, %ebx\n\t"` and `"movl $0x10, (%ebx)\n\t"` in front of the software interrupt, the soft interrupt can be used normally, but there are still problems with the loop. Keep trying. @Peter Cordes – npc_stack Nov 11 '21 at 13:24

0 Answers0