2,254 questions
1
vote
2
answers
106
views
How do you use a c string (char array) in GCC with inline ARM assembly
When using ARM assembly, I know I can use CNTP_CTL_EL0 to get information about the physical timer. (https://developer.arm.com/documentation/ddi0595/2021-09/AArch64-Registers/CNTP-CTL-EL0--Counter-...
1
vote
1
answer
70
views
x86: How to obtain return address from %ebp?
Similar question: Assembly return address
I want to write a function to print the return address of the current function. This is code that prints %ebp+4:
void backtrace() {
int ebp;
asm ("movl %%...
1
vote
0
answers
37
views
Inline Assembly Bug in gcc? [duplicate]
The code in question
void _start() {
const char msg[] = "Hello, World!\n";
long ret;
__asm__ volatile (
"mov $1, %%rax\n"
"mov $1, %%rdi\n"
...
6
votes
1
answer
217
views
Compiler barrier for X86 lock prefixed instruction
The following code shows a bogus atomic increment on some counter:
__asm__ volatile(
"lock xaddl %0, %1"
: "+r"(v), "+m"(*p)
:
: "...
4
votes
1
answer
192
views
How to write a static inline macro with compile-time constants?
I am trying to write a C macro (not C preprocessor, but static inline with proper argument type checking) with inline ARM assembly that includes a compile-time constant parameter (to save instructions ...
2
votes
1
answer
71
views
Assistance with inline Assembly porting to SDCC
I am porting the GetCurrentMicro function in the Arduino Core STM8 to my SDCC code and I noticed the Cosmic C Compiler _asm function allows me to return a result as well as an input in a C var.
Is ...
1
vote
1
answer
189
views
Can you somehow grab a value from a register and put it into a C variable in C with the asm keyword for arm64 macOS assembly?
Can you somehow grab a value from a register and put it into a C variable in C with the asm keyword for arm64 macOS assembly?
I have seen code from other stack overflows that have already answered ...
1
vote
0
answers
92
views
This program with inline assembly works in CLANG with optimization enabled but does not work in GCC. Does GCC ignore `volatile` on global variables? [duplicate]
So, this piece of C++ code:
/*
* Compile on 64-bit Linux or Solaris (I guess it will probably also work on
* FreeBSD), like this:
* g++ -o bin2dec bin2dec.cpp -std=c++11 #Don't put -O3
* here, as ...
6
votes
2
answers
139
views
Rust core::arch::asm throwing error where type u64 doesn't fit into class reg
I have recently been learning how to program bare metal to write a kernal for the rpi4b. The last thing I needed to add was a way to have the main script only run on one core. The method I decided to ...
2
votes
1
answer
159
views
"Non-ASM statement in naked function is not supported" error by clangd
I'm following bare metal programming guide:
https://github.com/cpq/bare-metal-programming-guide
Clangd produces error
"Non-ASM statement in naked function is not supported"
in Helix editor ...
1
vote
0
answers
94
views
Remote process code injection with dynamic addresses
I've made a small mod app for the game Elden Ring. With this mod, whenever the player loses health, I reduce their level by 1. Everything works so far.
What I want to do now is make it happen when ...
2
votes
1
answer
265
views
Forcing a C program to take a forged epilogue made with inline-assembly to jump to arbitrary function
This comes from a post about invoking a trivial buffer overflow (to jump to a function present in the source but not called explicitly in any place of the program (2333909/how-can-i-invoke-buffer-...
8
votes
1
answer
229
views
Segfault simulating #embed on GCC 14 with .incbin into .rodata and defining a global span<>
I have a project that has to use GCC 14 which does not have #embed support.
I attempted to simulate it as follows.
namespace {
namespace {
extern "C" {
extern std::...
1
vote
1
answer
208
views
Why calling longjmp in a non-main stack causes the program to crash?
The following code attempts to create a simple stackful coroutine. It allocates a stack frame in the heap space by setting the rsp register and then calling a function. Afterwards, it exits the ...
-1
votes
1
answer
103
views
Use c++ dll to hook to an instruction and still use the registers (x86) [closed]
NOTE: This is decompiled ghidra code, the imageBase start at 0x00400000, so we are working with Program.exe+001a0d39 relative to image base.
005a0d39 01 87 94 ADD dword ptr [EDI + ...