x86-64

Why does this REPNE SCASB implementation of strlen work?

房东的猫 提交于 2020-05-09 07:41:06
问题 Why does this code work? http://www.int80h.org/strlen/ says that the string address has to be in EDI register for scasb to work, but this assembly function doesn't seem to do this. Assembly code for mystrlen : global mystrlen mystrlen: sub ecx, ecx not ecx sub al, al cld repne scasb neg ecx dec ecx dec ecx mov eax, ecx ret C main: int mystrlen(const char *); int main() { return (mystrlen("1234")); } Compilation: nasm -f elf64 test.asm gcc -c main.c gcc main.o test.o Output: ./a.out echo $? 4

Has Hardware Lock Elision gone forever due to Spectre Mitigation?

*爱你&永不变心* 提交于 2020-05-07 03:48:57
问题 Is this correct that Hardware Lock Elision is disabled for all current CPUs due to Spectre mitigation, and any attempt to have a mutex using HLE intrinsics/instructions would result in usual mutex? Is this likely that there will not be anything like HLE mutexes in future to avoid vulnerabilities like Spectre? 回答1: So, TSX may be disabled not to mitigate Spectre, but as a part of another vulnerability mitigation, TSX Asynchronous Abort (TAA). Here's relevant article on Intel website: Intel®

Can atomic operations on a non-atomic<> pointer be safe and faster than atomic<>?

心不动则不痛 提交于 2020-04-30 06:29:13
问题 I have a dozen threads reading a pointer, and one thread that may change that pointer maybe once an hour or so. The readers are super, super, super time-sensitive. I hear that atomic<char**> or whatever is the speed of going to main memory, which I want to avoid. In modern (say, 2012 and later) server and high-end desktop Intel, can an 8-byte-aligned regular pointer be guaranteed not to tear if read and written normally? A test of mine runs an hour without seeing a tear. Otherwise, would it

Referencing x86 COM wrapper from 64 bit project

主宰稳场 提交于 2020-04-16 02:59:05
问题 I have created an x86 "wrapper" for an x86 library we have from a vendor. I've been following the steps mostly from this post as well a couple links for calling COM here and here. I marked the project as "Register for COM interop". I was able to find by COM interface using oleview and marked it as "Use Surrogate Process". So hopefully I'm good to this point as far as the DllSurrogate registry settings go. Now I can't seem to get the reference correct to consume the x86 COM. Supposedly I can

How to load a avx-512 zmm register from a ioremap() address?

跟風遠走 提交于 2020-04-16 02:58:10
问题 My goal is to create a PCIe transaction with more than 64b payload. For that I need to read an ioremap() address. For 128b and 256b I can use xmm and ymm registers respectively and that works as expected. Now, I'd like to do the same for 512b zmm registers (memory-like storage?!) A code under license I'm not allowed to show here, uses assembly code for 256b: void __iomem *addr; uint8_t datareg[32]; [...] // Read memory address to ymm (to have 256b at once): asm volatile("vmovdqa %0,%%ymm1" :

Counting number of allocations into the Write Pending Queue - unexpected low result on NV memory

孤人 提交于 2020-04-13 08:06:08
问题 I am trying to use some of the uncore hardware counters, such as: skx_unc_imc0-5::UNC_M_WPQ_INSERTS . It's supposed to count the number of allocations into the Write Pending Queue. The machine has 2 Intel Xeon Gold 5218 CPUs with cascade lake architecture, with 2 memory controllers per CPU. linux version is 5.4.0-3-amd64. I have the following simple loop and I am reading this counter for it. Array elements are 64 byte in size, equal to cache line. for(int i=0; i < 1000000; i++){ array[i]

How to read input from STDIN in x86_64 assembly?

倾然丶 夕夏残阳落幕 提交于 2020-04-07 18:51:09
问题 I am trying to learn x86_64 assembly and I was trying standard input output today and stumbled upon this post Learning assembly - echo program name How would I do the same for reading the input from STDIN (using SYSCALL instruction)? Especially if I know that the input will always be an integer and I want to read it to a register? EDIT: @Daniel Kozar's answer below helped me understand how STDIN and STDOUT stuff work with the SYSCALL instruction on Linux. I attempted to write a small program,

How to read input from STDIN in x86_64 assembly?

落花浮王杯 提交于 2020-04-07 18:48:24
问题 I am trying to learn x86_64 assembly and I was trying standard input output today and stumbled upon this post Learning assembly - echo program name How would I do the same for reading the input from STDIN (using SYSCALL instruction)? Especially if I know that the input will always be an integer and I want to read it to a register? EDIT: @Daniel Kozar's answer below helped me understand how STDIN and STDOUT stuff work with the SYSCALL instruction on Linux. I attempted to write a small program,

linux x86_64 nasm assembly syscalls

萝らか妹 提交于 2020-04-07 06:29:53
问题 I have found charts online showing various syscalls for x86_64 linux nasm assembly and there appears to be 380ish total syscalls, however every book or tutorial I can find only "how a few of the syscalls work and what they do?" Does anyone know where I can find information on every single syscall for x86_64 linux assembly using the nasm assembler? Any help would be great. 回答1: Look at the Linux man pages (section 2). http://man7.org/linux/man-pages/dir_section_2.html It doesn't matter what

How can I call printf normally in assembly without @PLT but just call printf with -l option in gcc with standard library,

巧了我就是萌 提交于 2020-03-26 06:48:09
问题 I want to call printf in assembly and link it using gcc -l option with standard library, But it says: Symbol `printf' causes overflow in R_X86_64_PC32 relocation Segmentation fault (core dumped) this is How i compile: gcc mod.s -l:libc.so -o mod when I replace libc.so with libc.a, It still shows Sementation fault .file "mod.c" .text .section .rodata .LC0: .string "%d" .text .globl main .type main, @function main: pushq %rbp movq %rsp, %rbp subq $16, %rsp movl $3, -8(%rbp) movl $2, -4(%rbp)