Gcc inline assembly ljmp syntax

I thought of using long jump to set the code segment register (CS). Getting into why I do this and why I do segmentation will take some time, so bear with me and consider this an academic exercise. I cannot get the syntax correctly.

Error: suffix or operands invalid for 'ljmp'

I know it’s stupid to put cs in a different register, but I decided that I would try, since using %0 does not work ( ax register does not work either).

I look at some code that compiles fine, and it drives me crazy, as I thought ljmp would be the same: __asm volatile ( "lcall $0x8, $far_call" );

Of course, I would welcome other hacker ways to influence the CS register.

 void set_cs(u16 cs) { __asm__ volatile ( "mov %0, %%ax \n\t" "ljmp %%ax, $fake_label \n\t" "fake_label: \n\t" : : "r" (cs) : "ax" ); } 
+4
source share
1 answer

It would seem that ljmp requires the constants to work while it generates more code and is obviously not particularly safe, it seems like it works when I enter a value that is not the current cs value, the application crashes. Instead, it uses the following value:

#define set_cs( cs ) asm volatile ( "ljmp %0, $fake_label \n\t fake_label: \n\t" :: "i"(cs) )

It is not as elegant as I assume you wanted it to be, and it completely depends on what you are trying to do. I can not imagine that this is ever useful or even works if you compile it to work under linux / windows.

+2
source

All Articles