3

I downloaded the intel IA-64 and 32 book because I wanted to know more in depth about how a CPU works. So I read the book and started to code some stuff. I enabled the IDT and when I want to program an interrupt handler I have that code :

extern "C"  __attribute__((interrupt)) void test (void* ptr)
{

}

int main (void)
{
    return 0;
}

when I compile with i686-elf-g++ -Wall -Wextra -O2 -c -m32 main.cpp I have the following warning : main.cpp:6:60: warning: 'interrupt' attribute directive ignored, but when I compile with g++ -Wall -Wextra -O2 -c -m32 main.cpp the compilation just works well and the code generated is like it should be with the iret instruction at the end (and that's what I want) :

Disassembly of section __TEXT,__text:
_test:
       0:       55      push    ebp
       1:       89 e5   mov     ebp, esp
       3:       fc      cld
       4:       5d      pop     ebp
       5:       cf      iretd
       6:       66 2e 0f 1f 84 00 00 00 00 00   nop     word ptr cs:[eax + eax]

Does anyone have any idea of why I have this warning with my cross platform version of gcc ? (and I am also wondering why an interrupt handler must have a pointer at parameter for gcc)

4
  • Are you on Windows with your "regular" g++ set up to build Windows object files? I was confused at first because you don't need a special i686 version of gcc to make 32-bit x86 code. Commented Oct 30, 2017 at 4:58
  • @PeterCordes I am on macOS and my g++ is clang++ 9.0.0. To tell the truth, when I started I had no idea of what I was doing, so I just followed the tutoriel on OSDev link . But I guess that if I doesn't set a prefix value to null gcc set its value to the targeted architecture (and in my case it was i686- and the elf is because of the tutoriel but maybe I don't need that) Commented Oct 30, 2017 at 8:29
  • 2
    @PeterCordes : I assumed from the question (using interrupt directive) that h'es doing OS development and using a cross compiler (which is recommended on OSDev wiki since the old days some distros use to tie/patch libgcc to use some host OS features). As well, on OS/X LD doesn't support many of the options needed (like linker scripts) that allow you to OS Dev (So GNU Binutils is also much handier). Commented Oct 30, 2017 at 13:33
  • @MichaelPetch you're right even if I wouldn't have the pretension of saying that I am developing an OS ^^ I am just trying to put the CPU in a usable mode, but I will be pretty happy if this little project could ends up in an nice working OS Commented Oct 30, 2017 at 22:09

1 Answer 1

4

The interrupt attribute is only a recent addition to G++ when targeting x86/x86-64 architectures and is available in G++ 7.0 and later.I would guess that your i686-elf-g++ cross compiler is earlier than 7.0 and your host compiler g++ is 7.0 or later. You'll have to upgrade your i686 cross compiler to a newer version.

Sign up to request clarification or add additional context in comments.

6 Comments

Really ? My regular version of g++ is clang++ 9.0.0 (I am on macOS) and my i686-elf-g++ version is 6.3.0. I founded the interrupt attribute when searching in the 6.3.0 documentation of g++ it is a little bit weird to document a feature that is not present oO
Apple's Clang/LLVM seems to have only supported the interrupt attribute since version 9 when targeting x86/x86-64. It has supported the interrupt attribute on functions for other targets like ARM and MIPS for much longer.
@Adrien : GCC and CLANG are different projects. And Apple has its own version of CLANG/LLVM with later XCode releases. The interrupt attribute has been around a while but only properly implemented for architectures like ARM and MIPS. It has been only more recently in GCC/CLANG/Apple CLANG(since about 2016). for the x86 and x86-64 platforms.
Older versions would ignore the interrupt attribute and usually throw a warning on unsupported platforms and it would be ignored.
Thanks it works well with gcc 7+, but I remember an advice saying that I should not use the last release but a one a little bit older because the newest are not tested enough, so maybe I should find another way to program interrupt handler in C/C++ ?
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.