
Alternatively, today after work I will add some modifications such that I have two stacks for each process; kernel stack and user stack, instead of having to set registers manually.
Will keep you posted.
Thanks,
Karim.
Code: Select all
asm volatile(" \
cli; \
mov %0, %%rcx; \
mov %1, %%rsp; \
mov %2, %%rbp; \
mov %3, %%cr3; \
mov $0x12345, %%rax; \
sti; \
jmp *%%rcx " : : "r"(rip), "r"(rsp), "r"(rbp), "r"(page_directory_address));
Code: Select all
287a8: fa cli
287a9: 4c 89 e9 mov %r13,%rcx
287ac: 4c 89 f4 mov %r14,%rsp
287af: 4c 89 fd mov %r15,%rbp
287b2: 0f 22 d9 mov %rcx,%cr3
287b5: 48 c7 c0 45 23 01 00 mov $0x12345,%rax
287bc: fb sti
287bd: ff e1 jmpq *%rcx
Code: Select all
asm volatile(" \
cli; \
mov %3, %%cr3; \
mov %0, %%rcx; \
mov %1, %%rsp; \
mov %2, %%rbp; \
mov $0x12345, %%rax; \
sti; \
jmp *%%rcx " : : "r"(rip), "r"(rsp), "r"(rbp), "r"(page_directory_address));
Code: Select all
asm volatile(" \
cli; \
mov %0, %%rcx; \
mov %1, %%rsp; \
mov %2, %%rbp; \
mov %3, %%cr3; \
mov $0x12345, %%rax; \
sti; \
jmp *%%rcx " : : "c"(rip), "r"(rsp), "r"(rbp), "r"(page_directory_address));
The compiler doesn't know anything about assembly other than what you tell it. You didn't tell it that you're clobbering rcx, so the compiler thinks there's no problem placing one of the input values in rcx. (Why are you clobbering rcx, anyway? Couldn't you just use "jmpq *%0" instead?)kemosparc wrote:My question is why does the compiler use rcx, I mean it should detect the dependability and use some other register.