📄 fat_entry.asm
字号:
dnl x86 fat binary entrypoints.dnl Copyright 2003 Free Software Foundation, Inc.dnldnl This file is part of the GNU MP Library.dnldnl The GNU MP Library is free software; you can redistribute it and/ordnl modify it under the terms of the GNU Lesser General Public License asdnl published by the Free Software Foundation; either version 3 of thednl License, or (at your option) any later version.dnldnl The GNU MP Library is distributed in the hope that it will be useful,dnl but WITHOUT ANY WARRANTY; without even the implied warranty ofdnl MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNUdnl Lesser General Public License for more details.dnldnl You should have received a copy of the GNU Lesser General Public Licensednl along with the GNU MP Library. If not, see http://www.gnu.org/licenses/.include(`../config.m4')dnl Forcibly disable profiling.dnldnl The entrypoints and inits are small enough not to worry about, the realdnl routines arrived at will have any profiling. Also, the way the codednl here ends with a jump means we won't work properly with thednl "instrument" profiling scheme anyway.define(`WANT_PROFILING',no) TEXTdnl Usage: FAT_ENTRY(name, offset)dnldnl Emit a fat binary entrypoint function of the given name. This is thednl normal entry for applications, eg. __gmpn_add_n.dnldnl The code simply jumps through the function pointer in __gmpn_cpuvec atdnl the given "offset" (in bytes).dnldnl For non-PIC, the jumps are 5 bytes each, aligning them to 8 should bednl fine for all x86s.dnldnl For PIC, the jumps are 20 bytes each, and are best aligned to 16 todnl ensure at least the first two instructions don't cross a cache linednl boundary.dnldnl Note the extra `' ahead of PROLOGUE obscures it from the HAVE_NATIVEdnl grepping in configure, stopping that code trying to eval something withdnl $1 in it.define(FAT_ENTRY,m4_assert_numargs(2)` ALIGN(ifdef(`PIC',16,8))`'PROLOGUE($1)ifdef(`PIC',` call L(movl_eip_edx)L(entry_here$2): addl $_GLOBAL_OFFSET_TABLE_+[.-L(entry_here$2)], %edx movl GSYM_PREFIX`'__gmpn_cpuvec@GOT(%edx), %edx jmp *m4_empty_if_zero($2)(%edx)',`dnl non-PIC jmp *GSYM_PREFIX`'__gmpn_cpuvec+$2')EPILOGUE()')dnl FAT_ENTRY for each CPUVEC_FUNCS_LISTdnldefine(`CPUVEC_offset',0)foreach(i,`FAT_ENTRY(MPN(i),CPUVEC_offset)define(`CPUVEC_offset',eval(CPUVEC_offset + 4))',CPUVEC_FUNCS_LIST)ifdef(`PIC',` ALIGN(8)L(movl_eip_edx): movl (%esp), %edx ret_internal')dnl Usage: FAT_INIT(name, offset)dnldnl Emit a fat binary initializer function of the given name. Thesednl functions are the initial values for the pointers in __gmpn_cpuvec.dnldnl The code simply calls __gmpn_cpuvec_init, and then jumps back throughdnl the __gmpn_cpuvec pointer, at the given "offset" (in bytes).dnl __gmpn_cpuvec_init will have stored the address of the selecteddnl implementation there.dnldnl Only one of these routines will be executed, and only once, since afterdnl that all the __gmpn_cpuvec pointers go to real routines. So there's nodnl need for anything special here, just something small and simple. Todnl keep code size down, "fat_init" is a shared bit of code, arrived atdnl with the offset in %al. %al is used since the movb instruction is 2dnl bytes where %eax would be 4.dnldnl Note having `PROLOGUE in FAT_INIT obscures that PROLOGUE from thednl HAVE_NATIVE grepping in configure, preventing that code trying to evaldnl something with $1 in it.define(FAT_INIT,m4_assert_numargs(2)`PROLOGUE($1) movb $`'$2, %al jmp L(fat_init)EPILOGUE()')L(fat_init): C al __gmpn_cpuvec byte offset movsbl %al, %eax pushl %eaxifdef(`PIC',` pushl %ebx call L(movl_eip_ebx)L(init_here): addl $_GLOBAL_OFFSET_TABLE_+[.-L(init_here)], %ebx call GSYM_PREFIX`'__gmpn_cpuvec_init@PLT movl GSYM_PREFIX`'__gmpn_cpuvec@GOT(%ebx), %edx popl %ebx popl %eax jmp *(%edx,%eax)L(movl_eip_ebx): movl (%esp), %ebx ret_internal',`dnl non-PIC call GSYM_PREFIX`'__gmpn_cpuvec_init popl %eax jmp *GSYM_PREFIX`'__gmpn_cpuvec(%eax)')dnl FAT_INIT for each CPUVEC_FUNCS_LISTdnldefine(`CPUVEC_offset',0)foreach(i,`FAT_INIT(MPN(i`'_init),CPUVEC_offset)define(`CPUVEC_offset',eval(CPUVEC_offset + 4))',CPUVEC_FUNCS_LIST)C long __gmpn_cpuid (char dst[12], int id);CC This is called only once, so just something simple and compact is fine.defframe(PARAM_ID, 8)defframe(PARAM_DST, 4)deflit(`FRAME',0)PROLOGUE(__gmpn_cpuid) pushl %esi FRAME_pushl() pushl %ebx FRAME_pushl() movl PARAM_ID, %eax cpuid movl PARAM_DST, %esi movl %ebx, (%esi) movl %edx, 4(%esi) movl %ecx, 8(%esi) popl %ebx popl %esi retEPILOGUE()C int __gmpn_cpuid_available (void);CC Return non-zero if the cpuid instruction is available, which means lateC model 80486 and higher. 80386 and early 80486 don't have cpuid.CC The test follows Intel AP-485 application note, namely that if bit 21 isC modifiable then cpuid is supported. This test is reentrant and threadC safe, since of course any interrupt or context switch will preserve theC flags while we're tinkering with them.CC This is called only once, so just something simple and compact is fine.PROLOGUE(__gmpn_cpuid_available) pushf popl %ecx C old flags movl %ecx, %edx xorl $0x200000, %edx pushl %edx popf pushf popl %edx C tweaked flags movl $1, %eax cmpl %ecx, %edx jne L(available) xorl %eax, %eax C not changed, so cpuid not availableL(available): retEPILOGUE()
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -