[PATCH 2/6] score: i386: functions converting real mode pointer to physical address and back

Jan Dolezal dolezj21 at fel.cvut.cz
Tue Nov 18 15:46:40 UTC 2014


On 12.11.2014 16:25, Gedare Bloom wrote:
> On Wed, Nov 12, 2014 at 10:07 AM, Jan Dolezal <dolezj21 at fel.cvut.cz> wrote:
>> ---
>>   cpukit/score/cpu/i386/cpu_asm.S          | 63 ++++++++++++++++++++++++++++++++
>>   cpukit/score/cpu/i386/rtems/score/i386.h | 29 +++++++++++++++
>>   2 files changed, 92 insertions(+)
>>
>> diff --git a/cpukit/score/cpu/i386/cpu_asm.S b/cpukit/score/cpu/i386/cpu_asm.S
>> index 9b39567..c9e366d 100644
>> --- a/cpukit/score/cpu/i386/cpu_asm.S
>> +++ b/cpukit/score/cpu/i386/cpu_asm.S
>> @@ -327,6 +327,69 @@ SYM (i386_Physical_to_logical):
>>           movl    ecx,eax                /* eax = ecx */
>>           ret
>>
>> +/*
>> + *  void *i386_Real_mode_ptr_to_physical(
>> + *     void     *ptr
>> + *  );
>> + *
>> + *  Returns thirty-two bit physical address for segment:offset realmode pointer.
>> + */
>> +
> I suggest using the names i386_Real_to_physical() and
> i386_Physical_to_real() to be consistent with other functions like
> this in the same code.
I renamed these and changed parameters of i386_Real_to_physical
to segment and offset, so that the purpose is easily understandable.
Also I changed it to be inline function and I moved it to header file.

RTEMS_INLINE_ROUTINE void *i386_Real_to_physical(
     uint16_t segment,
     uint16_t offset)
{
     return (void *)(((uint32_t)segment<<4)+offset);
}

>
>> +.set RM_PTR_ARG, 4
>> +
>> +       PUBLIC (i386_Real_mode_ptr_to_physical)
>> +
>> +SYM (i386_Real_mode_ptr_to_physical):
>> +        movl    RM_PTR_ARG(esp),eax
>> +        xorl    ecx, ecx
>> +        movw    ax, cx
>> +        shrl    $12, eax
>> +        andl    $0xFFFF0, eax
>> +        addl    ecx, eax
>> +        ret
>> +
>
> My x86 assembly is not good enough to verify the following code. Joel?
>
>> +/*
>> + *  int i386_Physical_to_real_mode_ptr(
>> + *     void     *address,
>> + *     unsigned short *segment,
>> + *     unsigned short *offset
>> + *  );
>> + *
>> + *  Fills segment:offest realmode pointer counted from thirty-two bit physical
>> + *  address.
>> + *  Returns 0 if unconvertible, 1 if successfuly converted.
>> + */
>> +
>> +.set RM_PTR_SEG_ARG, 8
>> +.set RM_PTR_OFF_ARG, 12
>> +
>> +       PUBLIC (i386_Physical_to_real_mode_ptr)
>> +
>> +SYM (i386_Physical_to_real_mode_ptr):
>> +        movl    RM_PTR_ARG(esp),eax
>> +        cmpl    $0x10FFF0, eax
>> +        js      cvtbl
>> +        movl    $0, eax
>> +        ret
>> +cvtbl:  cmpl    $0x100000, eax
>> +        js      lowmem
>> +        subl    $0xFFFF0, eax
>> +        movl    RM_PTR_OFF_ARG(esp), ecx
>> +        movw    ax, (ecx)
>> +        movl    RM_PTR_SEG_ARG(esp), ecx
>> +        movw    $0xFFFF, (ecx)
>> +        movl    $1, eax
>> +        ret
>> +lowmem: movl    eax, edx
>> +        and     $0xF, ax
>> +        movl    RM_PTR_OFF_ARG(esp), ecx
>> +        movw    ax, (ecx)
>> +        shrl    $4, edx
>> +        movl    RM_PTR_SEG_ARG(esp), ecx
>> +        movw    dx, (ecx)
>> +        movl    $1, eax
>> +        ret
>> +
>>   END_CODE
>>
>>   END
>> diff --git a/cpukit/score/cpu/i386/rtems/score/i386.h b/cpukit/score/cpu/i386/rtems/score/i386.h
>> index 57569fc..a59e0cf 100644
>> --- a/cpukit/score/cpu/i386/rtems/score/i386.h
>> +++ b/cpukit/score/cpu/i386/rtems/score/i386.h
>> @@ -186,6 +186,35 @@ void *i386_Physical_to_logical(
>>   );
>>
>>   /*
>> + *  i386_Real_mode_ptr_to_physical
>> + *
>> + *  Converts real mode pointer {segment, offset} to physical address.
>> + */
>> +void *i386_Real_mode_ptr_to_physical(
>> +  void *ptr
>> +);
>> +
>> +/*
>> + *  i386_Physical_to_real_mode_ptr
>> + *  Retreives real mode pointer elements {segmnet, offset} from physical address
>> + *  Function returns the highest segment (base) address possible.
>> + *  Example:    input   address - 0x4B3A2
>> + *              output  segment - 0x4B3A
>> + *                      offset  - 0x2
>> + *              input   address - 0x10F12E
>> + *              output  segment - 0xFFFF
>> + *                      offset  - 0xF13E
>> + *
>> + *  return  0 address not convertible, must be less than 0x10FFEF
>> + *          1 segment and offset extracted
>> + */
>> +int i386_Physical_to_real_mode_ptr(
>> +  void *address,
>> +  unsigned short *segment,
>> +  unsigned short *offset
>> +);
>> +
>> +/*
>>    *  "Simpler" names for a lot of the things defined in this file
>>    */
>>
>> --
>> 1.9.1
>>
>> _______________________________________________
>> devel mailing list
>> devel at rtems.org
>> http://lists.rtems.org/mailman/listinfo/devel



More information about the devel mailing list