Yahoo Groups archive

Lpc2000

Index last updated: 2026-04-28 23:31 UTC

Thread

Can andyone solve this program problem?

Can andyone solve this program problem?

2005-05-02 by 김동휘

Can andyone solve this program problem?

 

The following source code : 

 

/*

             Partition table entry structure

*/

typedef struct _tagPTINFO {

             uint8_t                 active;                //446

             uint8_t                 start_h;               // 447

             uint8_t                 start_cs_l;          // 448

             uint8_t                 start_cs_h;         // 449

             uint8_t                 type;                   // 450

             uint8_t                 end_h;                // 451

             uint8_t                 end_cs_l;            // 452

             uint8_t                 end_cs_h;           // 453

             uint8_t                 start_0;               // 454

             uint8_t                 start_1;               //455

             uint8_t                 start_2;               //456

             uint8_t                 start_3;               // 457

             uint8_t                 size_0;                // 458

             uint8_t                 size_1;               //459

             uint8_t                 size_2;                //460

             uint8_t                 size_3;                // 461

} PTINFO, *PPTINFO;

 

/*

             Master Boot Record structure

*/

typedef struct _tagMBR {

             uint8_t bootcode[0x1be];              // boot sector

             PTINFO ptable[4];                         // four partition table structures

             uint8_t sig_55;                               // 0x55 signature byte

             uint8_t sig_aa;                               // 0xaa signature byte

} MBR, *PMBR;

 

{

             uint32_t result;

             PMBR mbr = (PMBR) scratchsector;

 

             result = (uint32_t) mbr->ptable[pnum].start_0 |

               (((uint32_t) mbr->ptable[pnum].start_1) << 8) |

               (((uint32_t) mbr->ptable[pnum].start_2) << 16) |

               (((uint32_t) mbr->ptable[pnum].start_3) << 24);

}

 

Assembled code of above source code : 

-            0x215c   <DFS_GetPtnStart+76>:                               add        r6, r7, r8, lsl #4

-            0x2164   <DFS_GetPtnStart+84>:                               ldrb       r5, [r6, #457]

-            0x2168   <DFS_GetPtnStart+88>:                               ldrb       r4, [r6, #458]

-            0x216c   <DFS_GetPtnStart+92>:                               ldrb       r0, [r6, #456]

-            0x2170   <DFS_GetPtnStart+96>:                               ldrb       r1, [r6, #459]

-            0x2184   <DFS_GetPtnStart+116>:                orr         r1, r1, r4

-            0x2188   <DFS_GetPtnStart+120>:                orr         r0, r0, r5

-            0x2194   <DFS_GetPtnStart+132>:                orr         r5, r0, r1

 

 

To work properly, assembled code must be like below :

-            0x215c   <DFS_GetPtnStart+76>:                               add        r6, r7, r8, lsl #4

-            0x2164   <DFS_GetPtnStart+84>:                               ldrb       r5, [r6, #455]

-            0x2168   <DFS_GetPtnStart+88>:                               ldrb       r4, [r6, #456]

-            0x216c   <DFS_GetPtnStart+92>:                               ldrb       r0, [r6, #454]

-            0x2170   <DFS_GetPtnStart+96>:                               ldrb       r1, [r6, #457]

-            0x2184   <DFS_GetPtnStart+116>:                orr         r1, r1, r4

-            0x2188   <DFS_GetPtnStart+120>:                orr         r0, r0, r5

-            0x2194   <DFS_GetPtnStart+132>:                orr         r5, r0, r1

 

That is, ‘mbr->ptable[pnum].start_0’ of source code doesn’t point a correct position.

 

it may be a allign problem

 

How can I solve this problem.

-------------------------------------------------
Dong-hwi Kim(金桐煇)

Senior Engineer of FAE Team.
Syncoam Co., Ltd.
TEL : 82-31-788-7843
FAX : 82-31-788-7846
E-mail : dhkim@...
-------------------------------------------------

[Non-text portions of this message have been removed]

Re: [lpc2000] Can andyone solve this program problem?

2006-05-02 by Dave Hylands

> typedef struct _tagMBR {
>
>              uint8_t bootcode[0x1be];              // boot sector
>
>              PTINFO ptable[4];                         // four partition table structures
>
>              uint8_t sig_55;                               // 0x55 signature byte
>
>              uint8_t sig_aa;                               // 0xaa signature byte
>
> } MBR, *PMBR;

It's probably a packing issue.

Structures are generally aligned on 32 bit boundaries, so you'll
probably find 2 bytes of pad are being inserted between bootcode and
ptable.

You'll need to use the appropriate directoves for your compiler to
select 8-bit or 16-bit packing.


--
Dave Hylands
Vancouver, BC, Canada
http://www.DaveHylands.com/

Move to quarantaine

This moves the raw source file on disk only. The archive index is not changed automatically, so you still need to run a manual refresh afterward.