flat assembler
Message board for the users of flat assembler.

Index > OS Construction > UEFI data structures alignment

Author
Thread Post new topic Reply to topic
zhak



Joined: 12 Apr 2005
Posts: 501
Location: Belarus
zhak 03 May 2014, 19:09
Hi guys,

UEFI spec says:
Quote:
Unless otherwise specified all data types are naturally aligned. Structures are aligned on boundaries equal to the largest internal datum of the structure and internal data are implicitly padded to achieve natural alignment.

Does it mean that I should manually align all structures?
Example:
There's BOOLEAN type defined as follows:
Quote:
Logical Boolean. 1-byte value containing a 0 for FALSE or a 1 for TRUE. Other values are undefined.

There's also UINT32, which is 4-byte unsigned value, and a structure:
Code:
//*******************************************************
// SIMPLE_TEXT_OUTPUT_MODE
//*******************************************************
typedef struct {
  INT32 MaxMode;
// current settings
  INT32 Mode;
  INT32 Attribute;
  INT32 CursorColumn;
  INT32 CursorRow;
  BOOLEAN CursorVisible;
} SIMPLE_TEXT_OUTPUT_MODE;    

Does it mean that I should explicitely add 3-byte padding to BOOLEAN when defining the structure for fasm?
Code:
struct SIMPLE_TEXT_OUTPUT_MODE
  MaxMode               rd 1
  Mode                  rd 1
  Attribute             rd 1
  CursorColumn          rd 1
  CursorRow             rd 1
  CursorVisible         rb 1
                        rb 3    ;needed?
ends    
Post 03 May 2014, 19:09
View user's profile Send private message Reply with quote
sid123



Joined: 30 Jul 2013
Posts: 339
Location: Asia, Singapore
sid123 04 May 2014, 07:49
Any sane compiler should always align the structures; so yes I think you should stick with alignment.
P S.: I'm not sure if FASM really aligns the structures or not
Post 04 May 2014, 07:49
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 20430
Location: In your JS exploiting you and your system
revolution 04 May 2014, 09:23
sid123 wrote:
P S.: I'm not sure if FASM really aligns the structures or not
It won't align anything unless you tell it to.
Post 04 May 2014, 09:23
View user's profile Send private message Visit poster's website Reply with quote
cod3b453



Joined: 25 Aug 2004
Posts: 618
cod3b453 05 May 2014, 20:52
[Nothing to see here Rolling Eyes ]


Last edited by cod3b453 on 06 May 2014, 16:26; edited 1 time in total
Post 05 May 2014, 20:52
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 20430
Location: In your JS exploiting you and your system
revolution 05 May 2014, 23:31
cod3b453 wrote:
In the example, no padding is needed because CursorVisible is aligned to its size (1).
The overall size of the structure should also be respected with proper padding since there is no guarantee that the API will not write to unused padding bytes. If you have some other data that follows the structure in the memory space of the padding bytes than it might be at risk of being corrupted.
Post 05 May 2014, 23:31
View user's profile Send private message Visit poster's website Reply with quote
cod3b453



Joined: 25 Aug 2004
Posts: 618
cod3b453 06 May 2014, 16:25
revolution wrote:
cod3b453 wrote:
In the example, no padding is needed because CursorVisible is aligned to its size (1).
The overall size of the structure should also be respected with proper padding since there is no guarantee that the API will not write to unused padding bytes. If you have some other data that follows the structure in the memory space of the padding bytes than it might be at risk of being corrupted.
Yeah, I'd misread the second line in that spec so ignore me Embarassed
Post 06 May 2014, 16:25
View user's profile Send private message Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  


< Last Thread | Next Thread >
Forum Rules:
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Copyright © 1999-2024, Tomasz Grysztar. Also on GitHub, YouTube.

Website powered by rwasa.