On 2/7/07, Mulyadi Santosa <mulyadi.santosa@xxxxxxxxx> wrote:
Hi...
> How DS register changes when switching between user mode/kernel mode and
> switching between tasks/processes in x86?
> Can somebody explain to me or give me some hints?
Check arch/i386/kernel/entry.S. There, you'll see something like these:
ENTRY(system_call)
pushl %eax # save orig_eax
SAVE_ALL
it means, after saving original EAX content, it calls SAVE_ALL macro.
Inside this macro, it does:
movl $(__KERNEL_DS),%edx
movl %edx,%ds; \
movl %edx,%es;
that will assign kernel data segment to DS register
When the system call is about to finish, once again kernel will do:
restore_all:
RESTORE_ALL
the above macro will do lots of popping from stack, including:
popl %ds
so it restores the original DS content.
When doing task switching, IIRC DS stays still....because all task
basically share the same global GDT and memory segmentation model is
flat. Perhaps the exception happens when LDT is used. Please check
__switch_to() in arch/i386/kernel/process.c and switch_to macro in
include/asm-i386/system.h
regards,
Mulyadi