x86-64

Can you enter x64 32-bit “long compatibility sub-mode” outside of kernel mode?

坚强是说给别人听的谎言 提交于 2019-11-28 08:31:26
This might be an exact duplicate of Is it possible to execute 32-bit code in 64-bit process by doing mode-switching? , but that question is from a year ago and only has one answer that doesn't give any source code. I'm hoping for more detailed answers. I'm running 64-bit Linux (Ubuntu 12.04, if it matters). Here's some code that allocates a page, writes some 64-bit code into it, and executes that code. #include <assert.h> #include <malloc.h> #include <stdio.h> #include <sys/mman.h> // mprotect #include <unistd.h> // sysconf unsigned char test_function[] = { 0xC3 }; // RET int main() { int

How to MOVe 3 bytes (24bits) from memory to a register?

落爺英雄遲暮 提交于 2019-11-28 08:09:43
问题 I can move data items stored in memory, to a general-purpose register of my choosing, using the MOV instruction. MOV r8, [m8] MOV r16, [m16] MOV r32, [m32] MOV r64, [m64] Now, don’t shoot me, but how is the following achieved: MOV r24, [m24] ? (I appreciate the latter is not legal). In my example, I want to move the characters “Pip”, i.e. 0x706950h, to register rax . section .data ; Section containing initialized data 14 DogsName: db "PippaChips" 15 DogsNameLen: equ $-DogsName I first

How can I multiply two hex 128 bit numbers in assembly

雨燕双飞 提交于 2019-11-28 08:01:37
问题 I have two 128 bit numbers in memory in hexadecimal, for example (little endian): x:0x12 0x45 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 y:0x36 0xa1 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 I've to perform the unsigned multiplication between these two numbers so my new number will be: z:0xcc 0xe3 0x7e 0x2b 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 Now, I'm aware that I can move the half x and y number into rax and rbx

Why does Clang do this optimization trick only from Sandy Bridge onward?

柔情痞子 提交于 2019-11-28 07:41:00
问题 I noticed that Clang does an interesting division optimization trick for the following snippet int64_t s2(int64_t a, int64_t b) { return a/b; } Below is the assembly output if specifying march as Sandy Bridge or above mov rax, rdi mov rcx, rdi or rcx, rsi shr rcx, 32 je .LBB1_1 cqo idiv rsi ret .LBB1_1: xor edx, edx div esi ret Here are the Godbolt links for the signed version and the unsigned version From what I understand it checks whether the high bits of the two operands are zero, and

Why isn't RDTSC a serializing instruction?

帅比萌擦擦* 提交于 2019-11-28 07:24:47
The Intel manuals for the RDTSC instruction warn that out of order execution can change when RDTSC is actually executed, so they recommend inserting a CPUID instruction in front of it because CPUID will serialize the instruction stream (CPUID is never executed out of order). My question is simple: if they had the ability to make instructions serializing, why didn't they make RDTSC serializing? The entire point of it appears to be to get cycle accurate timings. Is there a situation under which you would not want to precede it with a serializing instruction? Newer Intel CPUs have a separate

Why does MSVC not support inline assembly for AMD64 and Itanium targets?

送分小仙女□ 提交于 2019-11-28 07:12:23
问题 Yesterday I learned that inline assembly (with the __asm keyword) is not supported under Microsoft Visual C++ when compiling for AMD64 and Itanium targets. Is that correct? And if so, does anyone know why they would not support inline assembly for those targets? It seems like a rather big feature to just drop... 回答1: Correct, it still isn't supported in VS 2010 Beta 1. My guess is that inline assembly is just too difficult to implement: the way Microsoft implemented it, it integrates with the

Generate LLVM C++ API code as backend

邮差的信 提交于 2019-11-28 06:58:07
The Online LLVM demo page had an option to generate LLVM C++ API code as backend from a source code. However, that demo page is now disabled. I was wondering how we can do it ourselves using the available LLVM tools. I tried the following clang++ -c -emit-llvm input.cpp -o input.ll llc -march=cpp -o input.ll.cpp input.ll which gives the following error llc: error: invalid target 'cpp'. I am using LLVM/Clang version 3.2. Eli Bendersky The LLVM C++ backend has to be enabled during configuration when building LLVM. It's enabled by default in the configure (autotools) build, but not in the CMake

How to save the registers on x86_64 for an interrupt service routine?

元气小坏坏 提交于 2019-11-28 06:50:25
I am looking at some old code from a school project, and in trying to compile it on my laptop I ran into some problems. It was originally written for an old 32 bit version of gcc. Anyway I was trying to convert some of the assembly over to 64 bit compatible code and hit a few snags. Here is the original code: pusha pushl %ds pushl %es pushl %fs pushl %gs pushl %ss pusha is not valid in 64 bit mode. So what would be the proper way to do this in x86_64 assembly while in 64 bit mode? There has got to be a reason why pusha is not valid in 64 bit mode, so I have a feeling manually pushing all the

Multiplying two values and printing them to the screen (NASM, Linux)

让人想犯罪 __ 提交于 2019-11-28 06:35:52
问题 I keep reading that in order for one to perform integer/floating point division on a register, the register(s) being performed on need to actually be initialized . I'm curious to what the proper assembler directive is to do this. Do I simply provide an address by something like: mov ecx, 0x65F ;0x65F represents an address for ecx to point to . And then promptly (later in code) do something like: mov byte [ecx], 0xA ;move the value of 0xA into the contents of ecx, using only a byte's worth of

Use 32bit “Program Files” directory in msbuild

旧时模样 提交于 2019-11-28 06:12:56
In 64 bit versions of windows, 32 bit software is installed in "c:\program files (x86)". This means you cannot use $(programfiles) to get the path to (32 bit) software. So I need a $(ProgramFiles32) to overcome this in my MSBuild project. I don't want to change the project depending on the os it is running on. I have a solution that I will post, but maybe there is a easier/better way. In MSBuild 4.0+, there's a $(MSBuildProgramFiles32) property for it, which you can confidently employ directly (especially if you're prepared to put a ToolsVersion="4.0" at the top of the file to guarantee it's