maxoufox wrote:
I am following a tutorial in french wich is here:
That tutorial is very bad. Almost all of the inline assembly is wrong.
maxoufox wrote:
So, I've solved the problem... I'm just sacrifying a register to store %ds, here is
the commit where I fix everything, if someone has another idea.
I have another idea: pass all of the registers as an argument to your syscall handler.
For the assembly portion of your syscall handler:
Code:
_asm_syscalls:
SAVE_REGS
push esp ; regs_t *
call do_syscalls
add esp, 4
RESTORE_REGS
iret
And the C portion:
Code:
typedef struct regs
{
uint32_t gs, fs, es, ds;
uint32_t edi, esi, ebp, padding, ebx, edx, ecx, eax; //pushad, popad
uint32_t eip, cs, eflags, esp, ss; //int, iret
} regs_t;
void do_syscalls(regs_t * regs)
{
uint32_t ds_base;
struct gdtdesc *ds;
unsigned char *message;
if (regs->eax == 1) {
ds = (struct gdtdesc *) (GDTBASE + (regs->ds & 0xF8));
message = (unsigned char*)(regs->ebx);
// example code, you can figure out the rest
}
return;
}
And then you can use system calls like this:
Code:
asm("int $0x30" :: "a"(1), "b"(msg) : "memory" );
I haven't tested this code, so it may have mistakes.