Fix for x86-atom/CALLABI.S to handle failure for android.jni.cts.JniStaticTest#test_returnChar. CALLABI.S was not returning unsigned shorts correctly.

Change-Id: Ia6b443d41a96b0f65739c0b16a0ddb39f7eb33fa
diff --git a/vm/arch/x86-atom/Call386ABI.S b/vm/arch/x86-atom/Call386ABI.S
index 9e3b916..1146c2d 100644
--- a/vm/arch/x86-atom/Call386ABI.S
+++ b/vm/arch/x86-atom/Call386ABI.S
@@ -149,8 +149,42 @@
     movl        32(%ebp), %ecx          # %ecx<- return pointer
     je          2f                      # handle double return
     jl          1f                      # handle float return
+
+   /*
+    *  If a native function returns a result smaller than 8-bytes
+    *  then higher bytes may contain garbage.
+    *  This code does type-checking based on size of return result.
+    *  We zero higher bytes instead of allowing the garbage to go through.
+    */
+
+    cmpl        $3,%ebx
+    je  S8
+    cmpl        $4,%ebx
+    je          S4
+    cmpl        $7,%ebx
+    je          S1
+    cmpl        $6,%ebx
+    jne S2
+U2:
+    movzwl      %ax, %eax
     movl        %eax, (%ecx)            # save 32-bit return
+    jmp         CallABI_EXIT            # exit call
+
+S1:
+    movsbl      %al, %eax
+    movl        %eax, (%ecx)            # save 32-bit return
+    jmp         CallABI_EXIT            # exit call
+S2:
+    movswl      %ax, %eax
+    movl        %eax, (%ecx)            # save 32-bit return
+    jmp         CallABI_EXIT            # exit call
+S4:
+    cltd
+    movl        %eax, (%ecx)            # save 32-bit return
+    jmp         CallABI_EXIT            # exit call
+S8:
     movl        %edx, 4(%ecx)           # save 64-bit return
+    movl        %eax, (%ecx)            # save 32-bit return
     jmp         CallABI_EXIT            # exit call
 
 2: