On Thu, Jul 05, 2007 at 01:46:30AM +0100, Pedro Alves wrote:
> This is the part I was trying to get right with the macros:
>
> > __asm__(
> > // Data to be placed at start of .text section
> > "\t.section .init\n"
> > "\t.word eh_handler\n"
> > "\t.word 0\n"
> > "start_eh_text:\n"
> >
>
> This is documented to having to be placed immediately before the function it
> corresponds to ...
The trick here is that the default linker script will put sections
labeled with ".init" into the very first part of .text.
$ /opt/mingw32ce/bin/arm-wince-mingw32ce-objdump -Dr out/haret-debug
Disassembly of section .text:
00011000 <___crt_xc_end__>:
11000: 000183b8 streqh r8, [r1], -r8
11004: 00000000 andeq r0, r0, r0
00011008 <WinMainCRTStartup>:
11008: e92d40f0 stmdb sp!, {r4, r5, r6, r7, lr}
1100c: e1a04000 mov r4, r0
11010: e1a05001 mov r5, r1
[...]
Disassembly of section .pdata:
00035000 <.pdata>:
35000: 00011008 andeq r1, r1, r8
35004: cfffff02 svcgt 0x00ffff02
> Anyway,
> Looks nice and simple, I'll give it a try tomorrow too. Thanks.
Thanks. And thanks Danny for your code and comments as well.
BTW, I've attached a newer version. I think I'll check this into
haret's cvs if testing continues to look good.
Sample usage:
TRY_EXCEPTION_HANDLER
{
while (wcount--)
*vaddr++ = value;
}
CATCH_EXCEPTION_HANDLER
{
Output(C_ERROR "EXCEPTION while writing %08x to address %p",
value, vaddr);
}
I still don't know why I can't leave the exception handler with
EXCEPTION_CONTINUE_EXECUTION..
-Kevin
#include <setjmp.h> // jmp_buf
struct eh_data {
jmp_buf env;
};
#define TRY_EXCEPTION_HANDLER \
struct eh_data __ehd; \
int __ret = setjmp(__ehd.env); \
if (!__ret) { \
start_ehandling(&__ehd);
#define CATCH_EXCEPTION_HANDLER \
end_ehandling(&__ehd); \
} else
void start_ehandling(struct eh_data *d);
void end_ehandling(struct eh_data *d);
void init_thread_ehandling(void);
void init_ehandling(void);
#include <windows.h> // TlsSetValue
#include "output.h" // Output
#include "exceptions.h"
static DWORD handler_tls;
void start_ehandling(struct eh_data *d)
{
TlsSetValue(handler_tls, d);
}
void end_ehandling(struct eh_data *d)
{
TlsSetValue(handler_tls, NULL);
}
void init_thread_ehandling(void)
{
TlsSetValue(handler_tls, NULL);
}
void init_ehandling(void)
{
handler_tls = TlsAlloc();
}
extern "C" long
eh_handler(struct _EXCEPTION_RECORD *ExceptionRecord,
void *EstablisherFrame,
struct _CONTEXT *ContextRecord,
struct _DISPATCHER_CONTEXT *DispatcherContext)
{
struct eh_data *d = (struct eh_data*)TlsGetValue(handler_tls);
if (! d) {
Output(C_ERROR "Terminating haret due to unhandled exception");
exit(1);
}
end_ehandling(d);
// XXX
longjmp(d->env, 1);
ContextRecord->Pc = (ulong)longjmp;
ContextRecord->R0 = (ulong)d->env;
ContextRecord->R1 = 1;
Output("Leaving handler");
return EXCEPTION_CONTINUE_EXECUTION;
}
__asm__(
// Data to be placed at start of .text section
"\t.section .init\n"
"\t.word eh_handler\n"
"\t.word 0\n"
"start_eh_text:\n"
// Data for exception handler
"\t.section .pdata\n"
"\t.word start_eh_text\n"
"\t.word 0xc0000002 | (0xFFFFF << 8)\n" // max 22 bits for number of
instructions
"\t.text\n"
);
-------------------------------------------------------------------------
This SF.net email is sponsored by DB2 Express
Download DB2 Express C - the FREE version of DB2 express and take
control of your XML. No limits. Just data. Click to get it now.
http://sourceforge.net/powerbar/db2/
_______________________________________________
Cegcc-devel mailing list
Cegcc-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/cegcc-devel