x86

Get userspace RBP register from kernel syscall

孤者浪人 提交于 2021-02-11 15:01:31
问题 I am writing a kernel system call and I want to read the base pointer register (RBP) of the user. Maybe I can do that using the pt_regs struct that is passed for parameter, isn't it? Example code: unsigned long int data; asmlinkage int my_read(int d) { get_rbp_of_userStack(&data);#or somthing like that } I know this data saved somewhere for the context switch, how can I get to it? this is my user code void rar() {//rbp here should be rsp when it call so it basically the return addres of the

How to understand macro `likely` affecting branch prediction?

吃可爱长大的小学妹 提交于 2021-02-11 13:59:49
问题 I noticed if we know there is good chance for control flow is true or false, we can tell it to compiler, for instance, in Linux kernel, there are lots of likely unlikely , actually impled by __builtin_expect provided by gcc , so I want to find out how does it work, then checked the assembly out there: 20:branch_prediction_victim.cpp **** if (array_aka[j] >= 128) 184 .loc 3 20 0 is_stmt 1 185 00f1 488B85D0 movq -131120(%rbp), %rax 185 FFFDFF 186 00f8 8B8485F0 movl -131088(%rbp,%rax,4), %eax

Does asmlinkage mean stack or register?

别说谁变了你拦得住时间么 提交于 2021-02-11 12:32:00
问题 In most languages, C included the stack is used for function calls. That's why you get a "Stack Overflow" error if you are not careful in recursion. (Pun not intended). If that is true then what is so special about the asmlinkage GCC directive. It says, from #kernelnewbies The asmlinkage tag is one other thing that we should observe about this simple function. This is a #define for some gcc magic that tells the compiler that the function should not expect to find any of its arguments in

In assembly, how do I add a 5 byte instruction into a 3 byte space in the debugger

萝らか妹 提交于 2021-02-11 07:49:40
问题 I'm trying to change this line 0041DE91 | 8B 46 64 | mov eax,dword ptr ds:[esi+64] 0041DE94 | 83 C4 0C | add esp,C 0041DE97 | 83 F8 01 | cmp eax,1 to 0041DE91 | mov eax, 10 But the instruction which was 3 bytes occupies 5 bytes and spills into the two addresses below it: 0041DE91 | B8 0A 00 00 00 | mov eax,10 0041DE96 | 0C 83 | or al,83 0041DE98 | F8 | clc Is it possible to do this in a debugger to a pre-compiled program? 回答1: In 32-bit code (where there's no red-zone to clobber) you can move

Passing parameters from C to GNU Assembly function in 64bit

坚强是说给别人听的谎言 提交于 2021-02-11 07:09:02
问题 I have main function in C that runs code in assembly. I just want to make simple sum: main.c #include <stdio.h> extern int addByAssembly(int first_number, int second_number); int main (int argc, char **argv) { int sum=0; sum = addByAssembly(5,4); printf ("%d\n",sum); return 0; } addByAssembly.s .data SYSREAD = 0 SYSWRITE = 1 SYSEXIT = 60 STDOUT = 1 STDIN = 0 EXIT_SUCCESS = 0 .text #.global main #main: #call write #movq $SYSEXIT, %rax #movq $EXIT_SUCCESS, %rdi #syscall #******** .globl

Why are there no NAND, NOR and XNOR instructions in X86?

﹥>﹥吖頭↗ 提交于 2021-02-10 17:48:01
问题 They're one of the simplest "instructions" you could perform on a computer (they're the first ones I'd personally implement) Performing NOT(AND(x, y)) doubles execution time AND dependency chain length AND code size BMI1 introduced "andnot" which is a meaningful addition that is a unique operation - why not the ones in the title of this question? You usually read answers among the lines of "they take up valuable op-code space" but then I look at all of the kmask operations introduced with

Why are there no NAND, NOR and XNOR instructions in X86?

假如想象 提交于 2021-02-10 17:46:36
问题 They're one of the simplest "instructions" you could perform on a computer (they're the first ones I'd personally implement) Performing NOT(AND(x, y)) doubles execution time AND dependency chain length AND code size BMI1 introduced "andnot" which is a meaningful addition that is a unique operation - why not the ones in the title of this question? You usually read answers among the lines of "they take up valuable op-code space" but then I look at all of the kmask operations introduced with

Where is the Linear Address Space located?

拈花ヽ惹草 提交于 2021-02-10 15:10:58
问题 I'm reading the intel manual, and I see mentions of "Linear Address Space of the processor". I'm confused as to where or what the linear address space actually is. Where in the processor is the linear address space? The Physical Address Space is the actual RAM as I understand. A logical address is a "segment selector" + "offset", and it must be translated to a physical address. If I understand, if paging is not used, the linear address space is effectively the same as a physical address in

Where is the Linear Address Space located?

孤人 提交于 2021-02-10 15:05:59
问题 I'm reading the intel manual, and I see mentions of "Linear Address Space of the processor". I'm confused as to where or what the linear address space actually is. Where in the processor is the linear address space? The Physical Address Space is the actual RAM as I understand. A logical address is a "segment selector" + "offset", and it must be translated to a physical address. If I understand, if paging is not used, the linear address space is effectively the same as a physical address in

How do I call hex data stored in an array with inline assembly?

你。 提交于 2021-02-10 11:56:32
问题 I have an OS project that I am working on and I am trying to call data that I have read from the disk in C with inline assembly. I have already tried reading the code and executing it with the assembly call instruction, using inline assembly. void driveLoop() { uint16_t sectors = 31; uint16_t sector = 0; uint16_t basesector = 40000; uint32_t i = 40031; uint16_t code[sectors][256]; int x = 0; while(x==0) { read(i); for (int p=0; p < 256; p++) { if (readOut[p] == 0) { } else { x = 1; //kprint