Code: Select all
00650553140e[CPU0 ] stackPrefetch(4): access [0x0000002c] > SS.limit [0x00000fff] ED
00650553159e[CPU0 ] fetch_raw_descriptor: GDT: index (f37) 1e6 > limit (7f8)
Code: Select all
00650553140e[CPU0 ] stackPrefetch(4): access [0x0000002c] > SS.limit [0x00000fff] ED
00650553159e[CPU0 ] fetch_raw_descriptor: GDT: index (f37) 1e6 > limit (7f8)
Code: Select all
#include <stddef.h>
#include <kernel/gdt.h>
#include <stdio.h>
#include <stdlib.h>
void do_syscalls(int sys_num) {
uint16_t ds_select;
uint32_t ds_base;
struct gdtdesc *ds;
char *message;
if (sys_num == 1) {
asm(" mov 44(%%ebp), %%eax \n \
mov %%eax, %0 \n \
mov 24(%%ebp), %%ax \n \
mov %%ax, %1" : "=m"(message), "=m"(ds_select) : );
printf("printf\n");
ds = (struct gdtdesc *) (GDTBASE + (ds_select & 0xF8));
ds_base = ds->base0_15 + (ds->base16_23 << 16) + (ds->base24_31 << 24);
char* buf;
itoa((uint64_t)(ds_base + message), 16, buf);
printf("%s", buf);
asm("xchgw %bx, %bx");
printf((ds_base + message));
} else {
printf("syscall\n");
}
return;
}
That tutorial is very bad. Almost all of the inline assembly is wrong.maxoufox wrote:I am following a tutorial in french wich is here:
I have another idea: pass all of the registers as an argument to your syscall handler.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.
Code: Select all
_asm_syscalls:
SAVE_REGS
push esp ; regs_t *
call do_syscalls
add esp, 4
RESTORE_REGS
iret
Code: Select all
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;
}
Code: Select all
asm("int $0x30" :: "a"(1), "b"(msg) : "memory" );