x86-64

Fastest Linux system call

偶尔善良 提交于 2020-01-10 02:53:08
问题 On an x86-64 Intel system that supports syscall and sysret what's the "fastest" system call from 64-bit user code on a vanilla kernel? In particular, it must be a system call that exercises the syscall / sysret user <-> kernel transition 1 , but does the least amount of work beyond that. It doesn't even need to do the syscall itself: some type of early error which never dispatches to the specific call on the kernel side is fine, as long as it doesn't go down some slow path because of that.

Fastest Linux system call

旧巷老猫 提交于 2020-01-10 02:53:05
问题 On an x86-64 Intel system that supports syscall and sysret what's the "fastest" system call from 64-bit user code on a vanilla kernel? In particular, it must be a system call that exercises the syscall / sysret user <-> kernel transition 1 , but does the least amount of work beyond that. It doesn't even need to do the syscall itself: some type of early error which never dispatches to the specific call on the kernel side is fine, as long as it doesn't go down some slow path because of that.

Segfault while calling C function (printf) from Assembly

守給你的承諾、 提交于 2020-01-07 04:36:30
问题 I am using NASM on linux to write a basic assembly program that calls a function from the C libraries (printf). Unfortunately, I am incurring a segmentation fault while doing so. Commenting out the call to printf allows the program to run without error. ; Build using these commands: ; nasm -f elf64 -g -F stabs <filename>.asm ; gcc <filename>.o -o <filename> ; SECTION .bss ; Section containing uninitialized data SECTION .data ; Section containing initialized data text db "hello world",10 ;

How to turn hex code into x86 instructions

自作多情 提交于 2020-01-07 02:52:09
问题 I'm trying to make a script or program that will take given bytes (given in hexadecimal), and convert them into a x86 instructions (For example c3 -> retq) I've tried doing it by calling gcc -c on an assembly file just containing retq retq and then using a script to insert bytes where it says "c3 c3", then using objdump -d to see what it says now. But it seems that it messes up the format of the file unless I only pass an instruction of the same size as the original instruction bytes. I'm

x86-64 address calculation in 64bit mode with 32-bit address-size

时光怂恿深爱的人放手 提交于 2020-01-07 02:21:02
问题 I read Intel manual about address calculation in 64 bit mode. Suppose we have 64 bit mode, default address size is 64 bit. Suppose also that instruction in question is preceded by address size override prefix, so address size becomes 32 bit. Now, imagine that instruction encodes memory operand with address specified by register number 0 (rax/eax/ax ...). Now the thing that I don't fully understand, whether CPU looks only at eax value and internally zero-extends it to form "native" 64 bit

微架构、指令集架构与汇编语言的关系

和自甴很熟 提交于 2020-01-06 18:57:43
最近老是碰到x86 IA32 MIPS什么的对应的汇编又是有好几种,感觉很迷。遂查资料理清这些个概念如下(大部分内容来自维基百科,如有错误谢指正!) 微架构、指令集架构和汇编语言这三者的关系大概是这样的,我们分别来介绍下 指令集 指令就是要计算机执行某种操作的命令。 从计算机组成的层次结构来说 指令分为微指令(微程序级的指令,属硬件)、宏指令(若干机器指令组成的 属软件)和机器指令(二者之间 简称指令)。 我们这里只讨论机器指令,每一条机器指令指令可以完成一个独立的算术运算或逻辑运算操作(如加减移位等)。 一台计算机中所有机器指令的集合指令集。它存在于CPU内部,对CPU运算进行指导和优化。 从指令集来说,计算机分为我们熟悉的 CISC(复杂指令集计算机)和 RISC(精简指令集计算机)。这两种的设计理念和优缺点各不相同,这里不再展开。 微架构 微架构,是处理器核心的实现方式,是 将一种给定的指令集架构在处理器中执行的方法(指令集的实现)。 通常认为只有具备独立的微架构研发能力的企业才算具备了CPU研发能力。 指令集架构(处理器架构) 是计算机体系结构中与程序设计有关的部分,包含了基本数据类型,指令集,寄存器,寻址模式,存储体系,中断,异常处理以及外部I/O。指令集架构为汇编语言的设计师和编译器所见。 几种常见的架构(详细内容和异同网上的介绍很多) x86 的32位 -> IA32

* in front of instruction operand, GNU assembly, AMD64

无人久伴 提交于 2020-01-06 17:26:12
问题 I have been trying to learn to write assembly code for the AMD64 processor. I have been looking at code generated by gcc. Eventually, I began seeing instructions such as call *(%rax) What is the * doing in front of the operand? Something like this came up in the System V ABI document I'm reading, and the answer to the above will help me continue on. Here is an example of the syntax used in context, taken from the System V ABI document itself: // System V ABI suggested implementation of a // C

Difference in data alignment in struct vs parameter?

余生颓废 提交于 2020-01-06 13:09:12
问题 Given the following code: typedef struct tagRECT { int left; int top; int right; int bottom; } RECT; extern int Func(RECT *a, int b, char *c, int d, char e, long f, int g, int h, int i, int j); int main() { } void gui() { RECT x = {4, 5, 6, 7}; Func(&x, 1, 0, 3, 4, 5, 6, 7, 8, 9); } This is the assembly generated gcc x86_64 presumably on linux (I used compiler explorer). main: mov eax, 0 ret gui: push rbp mov rbp, rsp sub rsp, 16 ; RECT x assignment mov DWORD PTR [rbp-16], 4 mov DWORD PTR

Assembly language - Why are characters stored in register as little endian?

岁酱吖の 提交于 2020-01-06 05:30:18
问题 I am new to assembly language. I am trying the below code and as you can see the below code. bits 64 global _start section .text _start: mov rcx, 1234567890 xor rcx, rcx mov rcx, 'wxyz' mov rax, 60 mov rdi, 0 syscall I would like to know why digits are stored as Big endian in register and characters are stored in registers as Little-endian Below screenshots are from the debugger. I thought only in the memory, data is stored as Little endian. But I don't understand why the characters are

Passing arrays to NASM DLL, pointer value gets reset to zero

孤街醉人 提交于 2020-01-06 05:16:11
问题 I am passing three arrays of doubles from Python (3.6.2) into a DLL written in 64-bit NASM (Windows) using CTypes. The pointers to the arrays are in rcx, rdx, r8 and r9. On entry, I extract the pointers into three separate arrays, called a_in_data, b_in_data, and c_in_data. The elements of those arrays are (1) pointer (2) data type and (3) length. In the area preceded by "Test #1" in the code below we check the value at b_in_data[0] and we get a valid pointer (just remove the comment symbols