From d0c3acd4c4b3cf48e025db8a22b8a181454813fc Mon Sep 17 00:00:00 2001 From: andrewfish Date: Wed, 1 Dec 2010 00:41:31 +0000 Subject: [PATCH] 2nd wave of r11105 checkin.2nd wave of r11105 checkin. git-svn-id: https://edk2.svn.sourceforge.net/svnroot/edk2/trunk/edk2@11106 6f19259b-4bc3-4df7-8a09-765794883524 --- UnixPkg/Include/Common/UnixInclude.h | 157 +++++++++++++++++++++- UnixPkg/Include/Protocol/UnixThunk.h | 132 +----------------- UnixPkg/Library/UnixBaseLib/X64/Thunk16.S | 60 +++++---- UnixPkg/Sec/UgaX11.c | 3 +- UnixPkg/UnixSerialIoDxe/UnixSerialIo.c | 3 +- UnixPkg/UnixSerialIoDxe/UnixSerialIo.h | 14 +- 6 files changed, 190 insertions(+), 179 deletions(-) diff --git a/UnixPkg/Include/Common/UnixInclude.h b/UnixPkg/Include/Common/UnixInclude.h index cc02353cd2..8cfa2a3deb 100644 --- a/UnixPkg/Include/Common/UnixInclude.h +++ b/UnixPkg/Include/Common/UnixInclude.h @@ -1,7 +1,7 @@ /*++ Copyright (c) 2006 - 2009, Intel Corporation. All rights reserved.
-Portions copyright (c) 2008 - 2009, Apple Inc. All rights reserved.
+Portions copyright (c) 2008 - 2010, Apple Inc. All rights reserved.
This program and the accompanying materials are licensed and made available under the terms and conditions of the BSD License which accompanies this distribution. The full text of the license may be found at @@ -20,21 +20,164 @@ Abstract: #ifndef __UNIX_INCLUDE_H__ #define __UNIX_INCLUDE_H__ + +// #include +// #include + +// +// Name mangle to prevent build errors. I.e conflicts between EFI and OS +// +#define NTOHL _UNIX_EFI_NAME_MANGLE_NTOHL_ +#define HTONL _UNIX_EFI_NAME_MANGLE_HTONL_ +#define NTOHS _UNIX_EFI_NAME_MANGLE_NTOHS_ +#define HTONS _UNIX_EFI_NAME_MANGLE_HTOHS_ +#define B0 _UNIX_EFI_NAME_MANGLE_B0_ + + +#include +#include + #include #include +#include +#include + +#if __CYGWIN__ +#include +#else +#include +#endif + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include #ifdef __APPLE__ #include #include +#define _XOPEN_SOURCE +#ifndef _Bool + #define _Bool char // for clang debug +#endif #else +#include #include #endif -#include -#include -#include -#include -#include #include -#include + +#if __APPLE__ +// +// EFI packing is not compatible witht he default OS packing for struct stat. +// st_size is 64-bit but starts on a 32-bit offset in the structure. The compiler +// flags used to produce compatible EFI images, break struct stat +// +#ifdef MDE_CPU_IA32 +#pragma pack(4) #endif + +#if defined(__DARWIN_64_BIT_INO_T) + + +typedef struct { + UINTN tv_sec; /* seconds */ + UINTN tv_nsec; /* and nanoseconds */ +} EFI_timespec; + + + +typedef struct stat_fix { \ + dev_t st_dev; /* [XSI] ID of device containing file */ + mode_t st_mode; /* [XSI] Mode of file (see below) */ + nlink_t st_nlink; /* [XSI] Number of hard links */ + __darwin_ino64_t st_ino; /* [XSI] File serial number */ + uid_t st_uid; /* [XSI] User ID of the file */ + gid_t st_gid; /* [XSI] Group ID of the file */ + dev_t st_rdev; /* [XSI] Device ID */ + + // clang for X64 ABI follows Windows and a long is 32-bits + // this breaks system inlcude files so that is why we need + // to redefine timespec as EFI_timespec + EFI_timespec st_atimespec; + EFI_timespec st_mtimespec; + EFI_timespec st_ctimespec; + EFI_timespec st_birthtimespec; + + off_t st_size; /* [XSI] file size, in bytes */ + blkcnt_t st_blocks; /* [XSI] blocks allocated for file */ + blksize_t st_blksize; /* [XSI] optimal blocksize for I/O */ + __uint32_t st_flags; /* user defined flags for file */ + __uint32_t st_gen; /* file generation number */ + __int32_t st_lspare; /* RESERVED: DO NOT USE! */ + __int64_t st_qspare[2]; /* RESERVED: DO NOT USE! */ +} STAT_FIX; + +#else /* !__DARWIN_64_BIT_INO_T */ + +typedef struct stat_fix { + dev_t st_dev; /* [XSI] ID of device containing file */ + ino_t st_ino; /* [XSI] File serial number */ + mode_t st_mode; /* [XSI] Mode of file (see below) */ + nlink_t st_nlink; /* [XSI] Number of hard links */ + uid_t st_uid; /* [XSI] User ID of the file */ + gid_t st_gid; /* [XSI] Group ID of the file */ + dev_t st_rdev; /* [XSI] Device ID */ +#if !defined(_POSIX_C_SOURCE) || defined(_DARWIN_C_SOURCE) + struct timespec st_atimespec; /* time of last access */ + struct timespec st_mtimespec; /* time of last data modification */ + struct timespec st_ctimespec; /* time of last status change */ +#else + time_t st_atime; /* [XSI] Time of last access */ + long st_atimensec; /* nsec of last access */ + time_t st_mtime; /* [XSI] Last data modification time */ + long st_mtimensec; /* last data modification nsec */ + time_t st_ctime; /* [XSI] Time of last status change */ + long st_ctimensec; /* nsec of last status change */ +#endif + off_t st_size; /* [XSI] file size, in bytes */ + blkcnt_t st_blocks; /* [XSI] blocks allocated for file */ + blksize_t st_blksize; /* [XSI] optimal blocksize for I/O */ + __uint32_t st_flags; /* user defined flags for file */ + __uint32_t st_gen; /* file generation number */ + __int32_t st_lspare; /* RESERVED: DO NOT USE! */ + __int64_t st_qspare[2]; /* RESERVED: DO NOT USE! */ +} STAT_FIX; + +#endif + +#ifdef MDE_CPU_IA32 +#pragma pack(4) +#endif + +#else + + typedef struct stat STAT_FIX; + +#endif + +// +// Undo name mangling +// +#undef NTOHL +#undef HTONL +#undef NTOHS +#undef HTONS +#undef B0 + + +#endif + diff --git a/UnixPkg/Include/Protocol/UnixThunk.h b/UnixPkg/Include/Protocol/UnixThunk.h index a5383be29e..85ac5f9086 100644 --- a/UnixPkg/Include/Protocol/UnixThunk.h +++ b/UnixPkg/Include/Protocol/UnixThunk.h @@ -29,142 +29,12 @@ Abstract: #ifndef _UNIX_THUNK_H_ #define _UNIX_THUNK_H_ -#include -#include -#include - -#if __CYGWIN__ -#include -#else -#include -#endif - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include -#include -#include -#include -#include -#include -#include - -#ifdef __APPLE__ -#include -#include -#define _XOPEN_SOURCE -#ifndef _Bool - #define _Bool char // for clang debug -#endif -#else -#include -#include -#endif - -#include +#include #include #include -#if __APPLE__ -// -// EFI packing is not compatible witht he default OS packing for struct stat. -// st_size is 64-bit but starts on a 32-bit offset in the structure. The compiler -// flags used to produce compatible EFI images, break struct stat -// -#ifdef MDE_CPU_IA32 -#pragma pack(4) -#endif - -#if defined(__DARWIN_64_BIT_INO_T) - - -typedef struct { - UINTN tv_sec; /* seconds */ - UINTN tv_nsec; /* and nanoseconds */ -} EFI_timespec; - - - -typedef struct stat_fix { \ - dev_t st_dev; /* [XSI] ID of device containing file */ - mode_t st_mode; /* [XSI] Mode of file (see below) */ - nlink_t st_nlink; /* [XSI] Number of hard links */ - __darwin_ino64_t st_ino; /* [XSI] File serial number */ - uid_t st_uid; /* [XSI] User ID of the file */ - gid_t st_gid; /* [XSI] Group ID of the file */ - dev_t st_rdev; /* [XSI] Device ID */ - - // clang for X64 ABI follows Windows and a long is 32-bits - // this breaks system inlcude files so that is why we need - // to redefine timespec as EFI_timespec - EFI_timespec st_atimespec; - EFI_timespec st_mtimespec; - EFI_timespec st_ctimespec; - EFI_timespec st_birthtimespec; - - off_t st_size; /* [XSI] file size, in bytes */ - blkcnt_t st_blocks; /* [XSI] blocks allocated for file */ - blksize_t st_blksize; /* [XSI] optimal blocksize for I/O */ - __uint32_t st_flags; /* user defined flags for file */ - __uint32_t st_gen; /* file generation number */ - __int32_t st_lspare; /* RESERVED: DO NOT USE! */ - __int64_t st_qspare[2]; /* RESERVED: DO NOT USE! */ -} STAT_FIX; - -#else /* !__DARWIN_64_BIT_INO_T */ - -typedef struct stat_fix { - dev_t st_dev; /* [XSI] ID of device containing file */ - ino_t st_ino; /* [XSI] File serial number */ - mode_t st_mode; /* [XSI] Mode of file (see below) */ - nlink_t st_nlink; /* [XSI] Number of hard links */ - uid_t st_uid; /* [XSI] User ID of the file */ - gid_t st_gid; /* [XSI] Group ID of the file */ - dev_t st_rdev; /* [XSI] Device ID */ -#if !defined(_POSIX_C_SOURCE) || defined(_DARWIN_C_SOURCE) - struct timespec st_atimespec; /* time of last access */ - struct timespec st_mtimespec; /* time of last data modification */ - struct timespec st_ctimespec; /* time of last status change */ -#else - time_t st_atime; /* [XSI] Time of last access */ - long st_atimensec; /* nsec of last access */ - time_t st_mtime; /* [XSI] Last data modification time */ - long st_mtimensec; /* last data modification nsec */ - time_t st_ctime; /* [XSI] Time of last status change */ - long st_ctimensec; /* nsec of last status change */ -#endif - off_t st_size; /* [XSI] file size, in bytes */ - blkcnt_t st_blocks; /* [XSI] blocks allocated for file */ - blksize_t st_blksize; /* [XSI] optimal blocksize for I/O */ - __uint32_t st_flags; /* user defined flags for file */ - __uint32_t st_gen; /* file generation number */ - __int32_t st_lspare; /* RESERVED: DO NOT USE! */ - __int64_t st_qspare[2]; /* RESERVED: DO NOT USE! */ -} STAT_FIX; - -#endif - -#ifdef MDE_CPU_IA32 -#pragma pack(4) -#endif - -#else - - typedef struct stat STAT_FIX; - -#endif #define EFI_UNIX_THUNK_PROTOCOL_GUID \ { \ diff --git a/UnixPkg/Library/UnixBaseLib/X64/Thunk16.S b/UnixPkg/Library/UnixBaseLib/X64/Thunk16.S index 049ec86355..0ec71cd4b0 100644 --- a/UnixPkg/Library/UnixBaseLib/X64/Thunk16.S +++ b/UnixPkg/Library/UnixBaseLib/X64/Thunk16.S @@ -30,31 +30,37 @@ ASM_GLOBAL ASM_PFX(mTransition) ASM_GLOBAL ASM_PFX(InternalAsmThunk16) # define the structure of IA32_REGS -.set _EDI, 0 #size 4 -.set _ESI, 4 #size 4 -.set _EBP, 8 #size 4 -.set _ESP, 12 #size 4 -.set _EBX, 16 #size 4 -.set _EDX, 20 #size 4 -.set _ECX, 24 #size 4 -.set _EAX, 28 #size 4 -.set _DS, 32 #size 2 -.set _ES, 34 #size 2 -.set _FS, 36 #size 2 -.set _GS, 38 #size 2 -.set _EFLAGS, 40 #size 8 -.set _EIP, 48 #size 4 -.set _CS, 52 #size 2 -.set _SS, 54 #size 2 -.set IA32_REGS_SIZE, 56 +#define _EDI 0 // size 4 +#define _ESI 4 // size 4 +#define _EBP 8 // size 4 +#define _ESP 12 // size 4 +#define _EBX 16 // size 4 +#define _EDX 20 // size 4 +#define _ECX 24 // size 4 +#define _EAX 28 // size 4 +#define _DS 32 // size 2 +#define _ES 34 // size 2 +#define _FS 36 // size 2 +#define _GS 38 // size 2 +#define _EFLAGS 40 // size 8 +#define _EIP 48 // size 4 +#define _CS 52 // size 2 +#define _SS 54 // size 2 +#define IA32_REGS_SIZE 56 .data -ASM_PFX(m16Size): .word ASM_PFX(InternalAsmThunk16) - ASM_PFX(m16Start) -ASM_PFX(mThunk16Attr): .word _ThunkAttr - ASM_PFX(m16Start) -ASM_PFX(m16Gdt): .word ASM_PFX(NullSeg) - ASM_PFX(m16Start) -ASM_PFX(m16GdtrBase): .word _16GdtrBase - ASM_PFX(m16Start) -ASM_PFX(mTransition): .word _EntryPoint - ASM_PFX(m16Start) +.set L_m16SizeSym, ASM_PFX(InternalAsmThunk16) - ASM_PFX(m16Start) +.set L_mThunk16AttrSym, _ThunkAttr - ASM_PFX(m16Start) +.set L_m16GdtSym, ASM_PFX(NullSeg) - ASM_PFX(m16Start) +.set L_m16GdtrBaseSym, _16GdtrBase - ASM_PFX(m16Start) +.set L_mTransitionSym, _EntryPoint - ASM_PFX(m16Start) + +ASM_PFX(m16Size): .word L_m16SizeSym +ASM_PFX(mThunk16Attr): .word L_mThunk16AttrSym +ASM_PFX(m16Gdt): .word L_m16GdtSym +ASM_PFX(m16GdtrBase): .word L_m16GdtrBaseSym +ASM_PFX(mTransition): .word L_mTransitionSym .text @@ -118,7 +124,8 @@ L_2: shlw $4,%ax lea (L_64BitCode - L_Base)(%ebx, %eax), %ax .byte 0x66,0x2e,0x89,0x87 # mov cs:[bx + (L_64Eip - L_Base)], eax - .word L_64Eip - L_Base +.set EipOffset, L_64Eip - L_Base + .word EipOffset .byte 0x66,0xb8 # mov eax, imm32 SavedCr4: .space 4 movq %rax, %cr4 @@ -147,7 +154,7 @@ SavedSp: .space 4 # restore stack _EntryPoint: .long ASM_PFX(ToUserCode) - ASM_PFX(m16Start) .word CODE16 -_16Gdtr: .word GDT_SIZE - 1 +_16Gdtr: .word L_GDT_SIZE - 1 _16GdtrBase: .quad ASM_PFX(NullSeg) _16Idtr: .word 0x3ff .long 0 @@ -220,7 +227,7 @@ ASM_PFX(_32Data): .byte 0xcf # 16-bit segment, 4GB limit .byte 0 -.set GDT_SIZE, . - ASM_PFX(NullSeg) +.set L_GDT_SIZE, . - ASM_PFX(NullSeg) #------------------------------------------------------------------------------ # IA32_REGISTER_SET * @@ -301,7 +308,8 @@ ASM_PFX(InternalAsmThunk16): movw %r8w, (SavedCs - SavedCr4)(%rcx) movl %esp, (SavedSp - SavedCr4)(%rcx) .byte 0xff, 0x69 # jmp (_EntryPoint - SavedCr4)(%rcx) - .byte _EntryPoint - SavedCr4 +.set EntryPointSavedCr4Offset, _EntryPoint - SavedCr4 + .byte EntryPointSavedCr4Offset L_RetFromRealMode: popfq lgdt 0x60(%rsp) # restore protected mode GDTR diff --git a/UnixPkg/Sec/UgaX11.c b/UnixPkg/Sec/UgaX11.c index c1a2b2d7a5..0a9b0a314c 100644 --- a/UnixPkg/Sec/UgaX11.c +++ b/UnixPkg/Sec/UgaX11.c @@ -11,11 +11,10 @@ THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. --*/ +#include #include #include -#include -#include #include #include diff --git a/UnixPkg/UnixSerialIoDxe/UnixSerialIo.c b/UnixPkg/UnixSerialIoDxe/UnixSerialIo.c index 0f3ac51f55..b197ae624a 100644 --- a/UnixPkg/UnixSerialIoDxe/UnixSerialIo.c +++ b/UnixPkg/UnixSerialIoDxe/UnixSerialIo.c @@ -108,7 +108,8 @@ ConvertBaud2Unix ( { switch (BaudRate) { case 0: - return B0; + return 0; // Don't use B0 as it is also used in EFI #includes as a name so termios.h #define + // can break the build. case 50: return B50; case 75: diff --git a/UnixPkg/UnixSerialIoDxe/UnixSerialIo.h b/UnixPkg/UnixSerialIoDxe/UnixSerialIo.h index f58014eaa8..484a07c482 100644 --- a/UnixPkg/UnixSerialIoDxe/UnixSerialIo.h +++ b/UnixPkg/UnixSerialIoDxe/UnixSerialIo.h @@ -21,20 +21,10 @@ Abstract: #ifndef _UNIXPKG_SERIAL_IO_ #define _UNIXPKG_SERIAL_IO_ -#include -#include -#include - -#ifdef __APPLE__ -#else -#include -#include -#endif -#include -#include +#include -#include "Uefi.h" +#include #include #include -- 2.39.2