Search code examples
assemblyx86gnu-assembleratt

unsupported instruction `lidt`


I am building a kernel for educational purposes.

Right my OS boots as follows: GRUB -> boot.S -> init.c

In boot.S I want to load an interrupt descriptor table. This is an excerpt of my file:

# load_idt - Loads the interrupt descriptor table (IDT).
# stack: [esp + 4] the address of the first entry in the IDT
#        [esp    ] the return address
load_idt: 
    movl    4(%esp),%eax    # load the address of the IDT into register eax
    lidt   %eax            # load the IDT
    ret                     # return to the calling function

I am using gas to compile, so I am working in the at&t syntax.
However when I try and compile this, the compiler doesn't seem to recognize the lidt instruction.

gcc -Wa,--32 -MMD -c -o boot.o boot.S boot.S: Assembler messages:
boot.S:65: Error: unsupported instruction `lidt' : recipe for
target 'boot.o' failed make: *** [boot.o] Error 1

What is the correct instruction then?

Edit: I tried using lidtl, this doesn't work also


Solution

  • lidt requires a memory reference. The correct syntax is lidt (%eax). Admittedly, the error message could be better. Then again, my gas version (from GNU Binutils for Debian 2.22) does say operand type mismatch for 'lidt'.

    PS: gas can be switched to intel syntax, so that's no reason to use at&t. The intel syntax equivalent is of course lidt [eax], and lidt eax would produce the same error.