From f63038518ec0b89eb6170e372a2ad5d0a24d30d3 Mon Sep 17 00:00:00 2001 From: gingold Date: Wed, 9 Apr 2008 04:01:16 +0000 Subject: Improve macosX support. Fix crashes in error handling. --- ortho/mcode/memsegs_c.c | 4 ++++ ortho/mcode/ortho_code-x86-abi.ads | 2 +- ortho/mcode/ortho_code-x86-emits.adb | 10 ++++++++-- ortho/mcode/ortho_code-x86-flags.ads | 28 ---------------------------- ortho/mcode/ortho_code-x86-flags_linux.ads | 28 ++++++++++++++++++++++++++++ ortho/mcode/ortho_code-x86-flags_macosx.ads | 28 ++++++++++++++++++++++++++++ ortho/mcode/ortho_code-x86-flags_windows.ads | 28 ++++++++++++++++++++++++++++ 7 files changed, 97 insertions(+), 31 deletions(-) delete mode 100644 ortho/mcode/ortho_code-x86-flags.ads create mode 100644 ortho/mcode/ortho_code-x86-flags_linux.ads create mode 100644 ortho/mcode/ortho_code-x86-flags_macosx.ads create mode 100644 ortho/mcode/ortho_code-x86-flags_windows.ads (limited to 'ortho') diff --git a/ortho/mcode/memsegs_c.c b/ortho/mcode/memsegs_c.c index c3114230b..f0a0e27d5 100644 --- a/ortho/mcode/memsegs_c.c +++ b/ortho/mcode/memsegs_c.c @@ -34,6 +34,10 @@ #define HAVE_MREMAP #endif +#ifndef HAVE_MREMAP +#include +#endif + void * mmap_malloc (int size) { diff --git a/ortho/mcode/ortho_code-x86-abi.ads b/ortho/mcode/ortho_code-x86-abi.ads index d13004295..613e37b2c 100644 --- a/ortho/mcode/ortho_code-x86-abi.ads +++ b/ortho/mcode/ortho_code-x86-abi.ads @@ -34,7 +34,7 @@ package Ortho_Code.X86.Abi is Mode_B2 => 0); Mode_Ptr : constant Mode_Type := Mode_P32; - + -- Procedures to layout a subprogram declaration. procedure Start_Subprogram (Subprg : O_Dnode; Abi : out O_Abi_Subprg); procedure New_Interface (Inter : O_Dnode; Abi : in out O_Abi_Subprg); diff --git a/ortho/mcode/ortho_code-x86-emits.adb b/ortho/mcode/ortho_code-x86-emits.adb index 3f71f8709..d64d0967b 100644 --- a/ortho/mcode/ortho_code-x86-emits.adb +++ b/ortho/mcode/ortho_code-x86-emits.adb @@ -1988,10 +1988,12 @@ package body Ortho_Code.X86.Emits is use Binary_File; use Interfaces; use Ortho_Code.Flags; + use Ortho_Code.X86.Insns; Sym : Symbol; Subprg_Decl : O_Dnode; Is_Global : Boolean; Frame_Size : Unsigned_32; + Saved_Regs_Size : Unsigned_32; begin Set_Current_Section (Sect_Text); Subprg_Decl := Subprg.D_Decl; @@ -2007,14 +2009,18 @@ package body Ortho_Code.X86.Emits is Set_Symbol_Pc (Sym, Is_Global); Subprg_Pc := Get_Current_Pc; + Saved_Regs_Size := Boolean'Pos(Reg_Used (R_Di)) * 4 + + Boolean'Pos(Reg_Used (R_Si)) * 4 + + Boolean'Pos(Reg_Used (R_Bx)) * 4; + -- Compute frame size. -- 8 bytes are used by return address and saved frame pointer. - Frame_Size := Unsigned_32 (Subprg.Stack_Max) + 8; + Frame_Size := Unsigned_32 (Subprg.Stack_Max) + 8 + Saved_Regs_Size; -- Align. Frame_Size := (Frame_Size + X86.Flags.Stack_Boundary - 1) and not (X86.Flags.Stack_Boundary - 1); -- The 8 bytes are already allocated. - Frame_Size := Frame_Size - 8; + Frame_Size := Frame_Size - 8 - Saved_Regs_Size; -- Emit prolog. -- push %ebp diff --git a/ortho/mcode/ortho_code-x86-flags.ads b/ortho/mcode/ortho_code-x86-flags.ads deleted file mode 100644 index 699a38c9e..000000000 --- a/ortho/mcode/ortho_code-x86-flags.ads +++ /dev/null @@ -1,28 +0,0 @@ --- X86 ABI flags. --- Copyright (C) 2006 Tristan Gingold --- --- GHDL is free software; you can redistribute it and/or modify it under --- the terms of the GNU General Public License as published by the Free --- Software Foundation; either version 2, or (at your option) any later --- version. --- --- GHDL is distributed in the hope that it will be useful, but WITHOUT ANY --- WARRANTY; without even the implied warranty of MERCHANTABILITY or --- FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License --- for more details. --- --- You should have received a copy of the GNU General Public License --- along with GCC; see the file COPYING. If not, write to the Free --- Software Foundation, 59 Temple Place - Suite 330, Boston, MA --- 02111-1307, USA. -with Interfaces; use Interfaces; - -package Ortho_Code.X86.Flags is - -- If true, OE_Alloca calls __chkstk (Windows), otherwise OE_Alloc - -- modifies ESP directly. - Flag_Alloca_Call : Boolean := False; - - -- Prefered stack alignment. - -- Must be a power of 2. - Stack_Boundary : Unsigned_32 := 2 ** 3; -- 4 for MacOSX, 3 for Linux -end Ortho_Code.X86.Flags; diff --git a/ortho/mcode/ortho_code-x86-flags_linux.ads b/ortho/mcode/ortho_code-x86-flags_linux.ads new file mode 100644 index 000000000..624c27985 --- /dev/null +++ b/ortho/mcode/ortho_code-x86-flags_linux.ads @@ -0,0 +1,28 @@ +-- X86 ABI flags. +-- Copyright (C) 2006 Tristan Gingold +-- +-- GHDL is free software; you can redistribute it and/or modify it under +-- the terms of the GNU General Public License as published by the Free +-- Software Foundation; either version 2, or (at your option) any later +-- version. +-- +-- GHDL is distributed in the hope that it will be useful, but WITHOUT ANY +-- WARRANTY; without even the implied warranty of MERCHANTABILITY or +-- FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License +-- for more details. +-- +-- You should have received a copy of the GNU General Public License +-- along with GCC; see the file COPYING. If not, write to the Free +-- Software Foundation, 59 Temple Place - Suite 330, Boston, MA +-- 02111-1307, USA. +with Interfaces; use Interfaces; + +package Ortho_Code.X86.Flags_Linux is + -- If true, OE_Alloca calls __chkstk (Windows), otherwise OE_Alloc + -- modifies ESP directly. + Flag_Alloca_Call : constant Boolean := False; + + -- Prefered stack alignment. + -- Must be a power of 2. + Stack_Boundary : constant Unsigned_32 := 2 ** 3; +end Ortho_Code.X86.Flags_Linux; diff --git a/ortho/mcode/ortho_code-x86-flags_macosx.ads b/ortho/mcode/ortho_code-x86-flags_macosx.ads new file mode 100644 index 000000000..c7531065a --- /dev/null +++ b/ortho/mcode/ortho_code-x86-flags_macosx.ads @@ -0,0 +1,28 @@ +-- X86 ABI flags. +-- Copyright (C) 2006 Tristan Gingold +-- +-- GHDL is free software; you can redistribute it and/or modify it under +-- the terms of the GNU General Public License as published by the Free +-- Software Foundation; either version 2, or (at your option) any later +-- version. +-- +-- GHDL is distributed in the hope that it will be useful, but WITHOUT ANY +-- WARRANTY; without even the implied warranty of MERCHANTABILITY or +-- FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License +-- for more details. +-- +-- You should have received a copy of the GNU General Public License +-- along with GCC; see the file COPYING. If not, write to the Free +-- Software Foundation, 59 Temple Place - Suite 330, Boston, MA +-- 02111-1307, USA. +with Interfaces; use Interfaces; + +package Ortho_Code.X86.Flags_Macosx is + -- If true, OE_Alloca calls __chkstk (Windows), otherwise OE_Alloc + -- modifies ESP directly. + Flag_Alloca_Call : constant Boolean := False; + + -- Prefered stack alignment. + -- Must be a power of 2. + Stack_Boundary : constant Unsigned_32 := 2 ** 4; +end Ortho_Code.X86.Flags_Macosx; diff --git a/ortho/mcode/ortho_code-x86-flags_windows.ads b/ortho/mcode/ortho_code-x86-flags_windows.ads new file mode 100644 index 000000000..a5ba57957 --- /dev/null +++ b/ortho/mcode/ortho_code-x86-flags_windows.ads @@ -0,0 +1,28 @@ +-- X86 ABI flags. +-- Copyright (C) 2006 Tristan Gingold +-- +-- GHDL is free software; you can redistribute it and/or modify it under +-- the terms of the GNU General Public License as published by the Free +-- Software Foundation; either version 2, or (at your option) any later +-- version. +-- +-- GHDL is distributed in the hope that it will be useful, but WITHOUT ANY +-- WARRANTY; without even the implied warranty of MERCHANTABILITY or +-- FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License +-- for more details. +-- +-- You should have received a copy of the GNU General Public License +-- along with GCC; see the file COPYING. If not, write to the Free +-- Software Foundation, 59 Temple Place - Suite 330, Boston, MA +-- 02111-1307, USA. +with Interfaces; use Interfaces; + +package Ortho_Code.X86.Flags_Windows is + -- If true, OE_Alloca calls __chkstk (Windows), otherwise OE_Alloc + -- modifies ESP directly. + Flag_Alloca_Call : constant Boolean := True; + + -- Prefered stack alignment. + -- Must be a power of 2. + Stack_Boundary : constant Unsigned_32 := 2 ** 3; +end Ortho_Code.X86.Flags_Windows; -- cgit v1.2.3