aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorgingold <gingold@b72b5c32-5f01-0410-b925-b5c7b92870f7>2006-11-18 20:33:16 +0000
committergingold <gingold@b72b5c32-5f01-0410-b925-b5c7b92870f7>2006-11-18 20:33:16 +0000
commit301584eaf540c982676f520d662b473e59890584 (patch)
tree3c8a80a0b57610fcb0e12a4f8985764fae538aa7
parentb9d724056d765418acf57c2fa7a79b7ef7e73721 (diff)
downloadghdl-301584eaf540c982676f520d662b473e59890584.tar.gz
ghdl-301584eaf540c982676f520d662b473e59890584.tar.bz2
ghdl-301584eaf540c982676f520d662b473e59890584.zip
SEH handled
Bug fixes
-rw-r--r--doc/ghdl.texi15
-rw-r--r--ortho/mcode/ortho_code-x86-abi.adb7
-rw-r--r--sem_names.adb2
-rw-r--r--sem_stmts.adb21
-rw-r--r--sem_types.adb4
-rw-r--r--translate/grt/config/win32.c97
6 files changed, 129 insertions, 17 deletions
diff --git a/doc/ghdl.texi b/doc/ghdl.texi
index 38ff82a33..b0a87c03d 100644
--- a/doc/ghdl.texi
+++ b/doc/ghdl.texi
@@ -608,21 +608,25 @@ run time library.
The actual elaboration is performed at run-time.
+On Windows this command can be skipped because it is also done by the
+run command.
+
@node Run command, Elaborate and run command, Elaboration command, Building commands
@comment node-name, next, previous, up
@subsection Run command
@cindex run
@cindex @option{-r} command
-Run (or simulate) an elaborated design hierarchy.
+Run (or simulate) a design.
@smallexample
-$ ghdl -r @var{primary_unit} [@var{secondary_unit}] [@var{simulation_options}]
+$ ghdl -r [@var{options}] @var{primary_unit} [@var{secondary_unit}] [@var{simulation_options}]
@end smallexample
-The arguments are the same as the @xref{Elaboration command}.
+The options and arguments are the same as the @xref{Elaboration command}.
On GNU/Linux this command simply build the filename of the executable
-and execute it. You may also directly execute the program.
+and execute it. Options are ignored. You may also directly execute
+the program.
This command exists for three reasons:
@itemize @bullet{}
@@ -635,7 +639,8 @@ It works with the Windows implementation, where the code is generated in
memory.
@end itemize
-On Windows this command elaborate and launch the simulation.
+On Windows this command elaborate and launch the simulation. As a consequence
+you must use the same options used during analysis.
@xref{Simulation and run time}, for details on options.
diff --git a/ortho/mcode/ortho_code-x86-abi.adb b/ortho/mcode/ortho_code-x86-abi.adb
index 67b4de236..0087bb1b9 100644
--- a/ortho/mcode/ortho_code-x86-abi.adb
+++ b/ortho/mcode/ortho_code-x86-abi.adb
@@ -26,6 +26,7 @@ with Ortho_Code.Dwarf;
with Ortho_Code.X86; use Ortho_Code.X86;
with Ortho_Code.X86.Insns;
with Ortho_Code.X86.Emits;
+with Ortho_Code.X86.Flags;
with Binary_File;
with Binary_File.Memory;
with Ada.Text_IO;
@@ -730,7 +731,9 @@ package body Ortho_Code.X86.Abi is
(Ortho_Code.X86.Emits.Intrinsics_Symbol
(Ortho_Code.X86.Intrinsic_Div_Ov_I64),
Divdi3'Address);
- Binary_File.Memory.Set_Symbol_Address
- (Ortho_Code.X86.Emits.Chkstk_Symbol, Chkstk'Address);
+ if X86.Flags.Flag_Alloca_Call then
+ Binary_File.Memory.Set_Symbol_Address
+ (Ortho_Code.X86.Emits.Chkstk_Symbol, Chkstk'Address);
+ end if;
end Link_Intrinsics;
end Ortho_Code.X86.Abi;
diff --git a/sem_names.adb b/sem_names.adb
index 80dc26e1b..be727820e 100644
--- a/sem_names.adb
+++ b/sem_names.adb
@@ -2484,7 +2484,7 @@ package body Sem_Names is
Base : Iir;
begin
Prefix := Get_Named_Entity (Get_Prefix (Attr));
- Base := Get_Base_Name (Prefix);
+ Base := Get_Object_Prefix (Prefix);
case Get_Kind (Base) is
when Iir_Kind_Signal_Declaration
| Iir_Kind_Signal_Interface_Declaration
diff --git a/sem_stmts.adb b/sem_stmts.adb
index 0bda7f117..555bfbf39 100644
--- a/sem_stmts.adb
+++ b/sem_stmts.adb
@@ -351,7 +351,8 @@ package body Sem_Stmts is
Error_Msg_Sem ("implicit GUARD signal cannot be assigned", Stmt);
return;
when others =>
- Error_Msg_Sem ("target is not a signal", Stmt);
+ Error_Msg_Sem ("target (" & Disp_Node (Get_Base_Name (Target))
+ & ") is not a signal", Stmt);
return;
end case;
if Get_Name_Staticness (Target_Object) < Staticness then
@@ -461,14 +462,18 @@ package body Sem_Stmts is
begin
Ok := True;
-- Find the signal.
- Target := Get_Target (Stmt);
- Target := Sem_Expression (Target, Sig_Type);
- if Target /= Null_Iir then
- Set_Target (Stmt, Target);
- Check_Target (Stmt, Target);
- Sem_Types.Set_Type_Has_Signal (Get_Type (Target));
- else
+ if Sig_Type = Null_Iir then
Ok := False;
+ else
+ Target := Get_Target (Stmt);
+ Target := Sem_Expression (Target, Sig_Type);
+ if Target /= Null_Iir then
+ Set_Target (Stmt, Target);
+ Check_Target (Stmt, Target);
+ Sem_Types.Set_Type_Has_Signal (Get_Type (Target));
+ else
+ Ok := False;
+ end if;
end if;
Expr := Get_Reject_Time_Expression (Stmt);
diff --git a/sem_types.adb b/sem_types.adb
index 9b35cc660..d7172c4bf 100644
--- a/sem_types.adb
+++ b/sem_types.adb
@@ -62,7 +62,9 @@ package body Sem_Types is
Func := Get_Resolution_Function (Atype);
if Func /= Null_Iir then
Func := Get_Named_Entity (Func);
- Set_Resolution_Function_Flag (Func, True);
+ if Func /= Error_Mark then
+ Set_Resolution_Function_Flag (Func, True);
+ end if;
end if;
Mark := Get_Type_Mark (Atype);
if Mark /= Null_Iir then
diff --git a/translate/grt/config/win32.c b/translate/grt/config/win32.c
index 465f9290b..de09400ce 100644
--- a/translate/grt/config/win32.c
+++ b/translate/grt/config/win32.c
@@ -21,6 +21,19 @@
#include <stdio.h>
#include <setjmp.h>
#include <assert.h>
+#include <excpt.h>
+
+static EXCEPTION_DISPOSITION
+ghdl_SEH_handler (struct _EXCEPTION_RECORD* ExceptionRecord,
+ void *EstablisherFrame,
+ struct _CONTEXT* ContextRecord,
+ void *DispatcherContext);
+
+struct exception_registration
+{
+ struct exception_registration *prev;
+ void *handler;
+};
struct stack_type
{
@@ -50,6 +63,19 @@ static VOID __stdcall
grt_stack_loop (void *v_stack)
{
struct stack_type *stack = (struct stack_type *)v_stack;
+ struct exception_registration er;
+ struct exception_registration *prev;
+
+ /* Get current handler. */
+ asm ("mov %%fs:(0),%0" : "=r" (prev));
+
+ /* Build regisration. */
+ er.prev = prev;
+ er.handler = ghdl_SEH_handler;
+
+ /* Register. */
+ asm ("mov %0,%%fs:(0)" : : "r" (&er));
+
while (1)
{
(*stack->func)(stack->arg);
@@ -117,16 +143,87 @@ __ghdl_maybe_return_via_longjump (int val)
longjmp (run_env, val);
}
+extern void grt_stack_error_grow_failed (void);
+extern void grt_stack_error_null_access (void);
+extern void grt_stack_error_memory_access (void);
+extern void grt_overflow_error (void);
+
+static EXCEPTION_DISPOSITION
+ghdl_SEH_handler (struct _EXCEPTION_RECORD* ExceptionRecord,
+ void *EstablisherFrame,
+ struct _CONTEXT* ContextRecord,
+ void *DispatcherContext)
+{
+ const char *msg = "";
+
+ switch (ExceptionRecord->ExceptionCode)
+ {
+ case EXCEPTION_ACCESS_VIOLATION:
+ if (ExceptionRecord->ExceptionInformation[1] == 0)
+ grt_stack_error_null_access ();
+ else
+ grt_stack_error_memory_access ();
+ break;
+
+ case EXCEPTION_FLT_DENORMAL_OPERAND:
+ case EXCEPTION_FLT_DIVIDE_BY_ZERO:
+ case EXCEPTION_FLT_INVALID_OPERATION:
+ case EXCEPTION_FLT_OVERFLOW:
+ case EXCEPTION_FLT_STACK_CHECK:
+ case EXCEPTION_FLT_UNDERFLOW:
+ msg = "floating point error";
+ break;
+
+ case EXCEPTION_INT_DIVIDE_BY_ZERO:
+ msg = "division by 0";
+ break;
+
+ case EXCEPTION_INT_OVERFLOW:
+ grt_overflow_error ();
+ break;
+
+ case EXCEPTION_STACK_OVERFLOW:
+ msg = "stack overflow";
+ break;
+
+ default:
+ msg = "unknown reason";
+ break;
+ }
+
+ /* FIXME: is it correct? */
+ fprintf (stderr, "exception raised: %s\n", msg);
+
+ __ghdl_maybe_return_via_longjump (1);
+ return 0; /* This is never reached, avoid compiler warning */
+}
+
int
__ghdl_run_through_longjump (int (*func)(void))
{
int res;
+ struct exception_registration er;
+ struct exception_registration *prev;
+
+ /* Get current handler. */
+ asm ("mov %%fs:(0),%0" : "=r" (prev));
+
+ /* Build regisration. */
+ er.prev = prev;
+ er.handler = ghdl_SEH_handler;
+
+ /* Register. */
+ asm ("mov %0,%%fs:(0)" : : "r" (&er));
run_env_en = 1;
res = setjmp (run_env);
if (res == 0)
res = (*func)();
run_env_en = 0;
+
+ /* Restore. */
+ asm ("mov %0,%%fs:(0)" : : "r" (prev));
+
return res;
}