Skip to contentSkip to conversation

unix lite

DISCUSSION Omar Khan 2 participants 2 messages Apr 23, 2007 – Apr 24, 2007 1 message not in the archive KVM

lore
Share & tools
lore

Omar Khan

author
#0 lore raw

hi,

I am trying to run unix like operating system (mainly meant for educational
purposes) on kvm called "Unix Lite" (http://www.unixlite.org/). It runs fine on qemu but on kvm it gives the unhandled vm exit 0x9. This is caused by the hardware task switch that is used in unix lite. The code for the switch is :

void gdt_t::swtch(tss_t * from, tss_t * to)

{
        /* also clear "busy tss" flag */
        tss[0].init(X86AVL386TSS, (u32_t)from, sizeof(tss_t)-1);
        tss[1].init(X86AVL386TSS, (u32_t)to, sizeof(tss_t)-1);
        asm volatile(
                "ltr %w0\n\t"
                "ljmp %1,$0\n\t"
                ::"r"(TSS0SEL),"i"(TSS1SEL));
}

As you can see the code is basically saving the context of one task and loading from the next. The unhandled exit is caused by the ljmp which causes the switch. What would be a good way to convert this to a software switch only? Just manually push the current state on the outgoing task state segment(we have the pointers to this) and load from the incoming task's state segment? I am new to this therefore I am not sure how to save the current CS:IP pair and whether this is the way to do it or not, any help/hints will be welcomed.

Thanks

Omar

-------------------------------------------------------------------------
This SF.net email is sponsored by DB2 Express
Download DB2 Express C - the FREE version of DB2 express and take control of your XML. No limits. Just data. Click to get it now.
http://sourceforge.net/powerbar/db2/

A message that is not in the archive (sent off-list or not yet received): [email protected]

#2 lore raw
Quoted 18 lines · Omar Khan

hi,

I am trying to run unix like operating system (mainly meant for educational
purposes) on kvm called "Unix Lite" (http://www.unixlite.org/). It runs fine on qemu but on kvm it gives the unhandled vm exit 0x9. This is caused by the hardware task switch that is used in unix lite. The code for the switch is :

void gdt_t::swtch(tss_t * from, tss_t * to)

{
        /* also clear "busy tss" flag */
        tss[0].init(X86AVL386TSS, (u32_t)from, sizeof(tss_t)-1);
        tss[1].init(X86AVL386TSS, (u32_t)to, sizeof(tss_t)-1);
        asm volatile(
                "ltr %w0\n\t"
                "ljmp %1,$0\n\t"
                ::"r"(TSS0SEL),"i"(TSS1SEL));
}
Quoted 8 lines

As you can see the code is basically saving the context of one task and loading from the next. The unhandled exit is caused by the ljmp which causes the switch. What would be a good way to convert this to a software switch only? Just manually push the current state on the outgoing task state segment(we have the pointers to this) and load from the incoming task's state segment? I am new to this therefore I am not sure how to save the current CS:IP pair and whether this is the way to do it or not, any help/hints will be welcomed.

There are two ways that you can go about this.

First, tying to change the code. For that you need to find out exactly what state is changed on the task switch. If the different contexts map the kernel differently, then you can't really change the code. If they don't, just follow the study task switching in the manuals and perform the same actions in software.

Changing esp and eip is not too difficult, see Linux__switch_to() in include/asm-i386/system.h.

Second, you can teach kvm about task switching. Code the actions that the processor takes into a kvm_task_switch() function and wire the vmexit handlers accordingly.

Signature · 8 lines
Do not meddle in the internals of kernels, for they are subtle and quick to panic.


-------------------------------------------------------------------------
This SF.net email is sponsored by DB2 Express
Download DB2 Express C - the FREE version of DB2 express and take
control of your XML. No limits. Just data. Click to get it now.
http://sourceforge.net/powerbar/db2/