This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Re: [cfe-dev] RFC: Support x86 interrupt and exception handlers
- From: "H. Peter Anvin" <hpa at zytor dot com>
- To: David Chisnall <David dot Chisnall at cl dot cam dot ac dot uk>, "H.J. Lu" <hjl dot tools at gmail dot com>
- Cc: John Criswell <jtcriswel at gmail dot com>, GCC Development <gcc at gcc dot gnu dot org>, cfe-dev at lists dot llvm dot org
- Date: Tue, 22 Sep 2015 12:21:46 -0700
- Subject: Re: [cfe-dev] RFC: Support x86 interrupt and exception handlers
- Authentication-results: sourceware.org; auth=none
- References: <CAMe9rOpKPxK-79pBO-MyiMzGqd=9gxDxJdRnDvdq4UumUTakHQ at mail dot gmail dot com> <CAMe9rOp8hma_3b49oMjWeixLPTeiQFX2MUxSbftMNmfjP4A0-Q at mail dot gmail dot com> <CAMe9rOpOC43+AOBsp8CMdzhCMQrGqzjpj+zTzaZ=SDKmd4GB1w at mail dot gmail dot com> <CAMe9rOpRRuBxHXzEKhSOO67VPkUQnx=gVuMAxq0snyTFxF+gaA at mail dot gmail dot com> <560051EF dot 70405 at gmail dot com> <CAMe9rOpLcvZOLrE+4v-M+CbWs5hw0j4EpfNGuE+myoaFdhpf5Q at mail dot gmail dot com> <9038C99C-408A-4E41-AA9A-6481227BFACB at cl dot cam dot ac dot uk> <CAMe9rOqPTMnrJ+aHVdLp+xvHXXUGONcyyCzmjMmqcLCJ7bduRQ at mail dot gmail dot com> <73DC1193-8F96-40D9-91F3-5E3E82291FE8 at cl dot cam dot ac dot uk>
On 09/22/15 04:52, David Chisnall wrote:
> On 22 Sep 2015, at 12:47, H.J. Lu <hjl.tools@gmail.com> wrote:
>>
>> since __builtin_exception_error () is the same as
>> __builtin_return_address (0) and __builtin_interrupt_data () is
>> address of __builtin_exception_error () + size of register.
>
> Except that theyâre *not*. __builtin_return_address(0) is guaranteed to be the same for the duration of the function. __builtin_exception_error() needs to either:
>
> 1) Fetch the values early with interrupts disabled, store them in a
> well-known location, and load them from this place when the intrinsic
> is called, or
>
> 2) Force any function that calls the intrinsic (and wants a
> meaningful result) to run with interrupts disabled, which is
> something that the compiler canât verify without knowing the full
> chain of code from the interrupt handler to the current point (and
> therefore prone to error).
>
> It is trivial to write a little bit of inline assembly that reads
> these values from the CPU and expose that for C code. There is a
> good reason why no one does this.
>
This is why it makes no sense for the intrinsics to be callable from
anywhere except inside the interrupt handler. It is really nothing
other than a way to pass arguments -- whether or not it is simpler for
the compilers to implement than supporting a different function
signature is beyond my scope of expertise.
-hpa