struc problems

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Spike

    #1

    struc problems

    Hi I'm using GCC (and NASM) to send over a asm table...

    BootDrv db 0
    BIOS_Mem_Map_En tries dd 0
    APM_Status db 0
    APM_Major_Versi on db 0
    APM_Minor_Versi on db 0
    APM_Code_Base dd 0
    APM_Data_Base dd 0
    APM_Data_Length dd 0
    APM_Code_Length dd 0
    VESA_Struct_Sta rt:
    ;VESA
    VESASignature db 'VESA'
    VESAVersion dw 0
    OemStringPtr dd 0
    Capabilities dd 0
    VideoModePtr dd 0
    TotalMemory dw 0
    ;VBE2
    OemSoftwareRev dw 0
    OemVendorNamePt r dd 0
    OemProductNameP tr dd 0
    OemProductRevPt r dd 0
    VBE2_reserved times 222 db 0
    VBE_OemData times 256 db 0
    VESA_ModeInfo dd 0
    VESA_Mode_Count er dw 0
    VGA_Mode_Counte r dw 0
    VGA_ModeInfo dd 0
    Graphics_Mode_C hoosen db 1
    Graphics_SubMod e_Choosen db 0
    TimerLoop dd 0
    Current_X dw 0
    Current_Y dw 0

    ....to a C struc...

    typedef struct BIOSInfo
    {
    BYTE BootDrv;
    ULONG BIOS_Mem_Entrie s;
    BYTE APM_Status;
    BYTE APM_Major_Versi on;
    BYTE APM_Minor_Versi on;
    ULONG APM_Code_Base;
    ULONG APM_Data_Base;
    ULONG APM_Data_Length ;
    ULONG APM_Code_Length ;
    //VESA Struct Start
    BYTE VESA_Signature[4];
    USHORT VESAVersion;
    ULONG OemStringPtr;
    ULONG Capabilities;
    ULONG VideoModePtr;
    USHORT TotalMemory;
    //VBE2 tillägg
    USHORT OemSoftwareRev;
    ULONG OemVendorNamePt r;
    ULONG OemProductNameP tr;
    ULONG OemProductRevPt r;
    BYTE VBE2_reserved[222];
    BYTE VBE_OemData[256];
    ULONG VESA_ModeInfo;
    USHORT VESA_Mode_Count er;
    USHORT VGA_Mode_Counte r;
    ULONG VGA_ModeInfo;
    BYTE Graphics_Mode_C hoosen;
    BYTE Graphics_SubMod e_Choosen;
    ULONG TimerLoop;
    USHORT Current_X;
    USHORT Current_Y;
    }BIOSInfo;

    .... but for some reason:

    BIOSInfo *BIOS_Info_Poin ter = Get_ASM_Params( );
    ScreenMode[0] = BIOS_Info_Point er->Graphics_Mode_ Choosen;
    ScreenMode[1] = BIOS_Info_Point er->Graphics_SubMo de_Choosen;

    ScreenMode[0] isn't equal to 1 (Graphics_Mode_ Choosen) and ScreenMode[1]
    isn't equal to 0 (Graphics_SubMo de_Choosen).

    Can anybody give me a hint on what's wrong?

    btw:

    _Get_ASM_Params :
    lea eax,[BootDrv]
    ret

    TIA!


  • Mark A. Odell

    #2
    Re: struc problems

    "Spike" <me.hates:spam@ me.net> wrote in
    news:9wiyd.1250 46$dP1.449333@n ewsc.telia.net:
    [color=blue]
    > Hi I'm using GCC (and NASM) to send over a asm table...[/color]


    Have you read you compiler documentation about packing structs? C
    compilers can add padding bytes after the first element of a struct.


    --
    - Mark ->
    --

    Comment

    • Spike

      #3
      Re: struc problems

      no I haven't... where can I find information about if GCC padds struc:s?

      //SPike

      "Mark A. Odell" <odellmark@hotm ail.com> skrev i meddelandet
      news:Xns95C787A 6689B0Copyright MarkOdell@130.1 33.1.4...[color=blue]
      > "Spike" <me.hates:spam@ me.net> wrote in
      > news:9wiyd.1250 46$dP1.449333@n ewsc.telia.net:
      >[color=green]
      >> Hi I'm using GCC (and NASM) to send over a asm table...[/color]
      >
      >
      > Have you read you compiler documentation about packing structs? C
      > compilers can add padding bytes after the first element of a struct.
      >
      >
      > --
      > - Mark ->
      > --[/color]


      Comment

      • Alex Fraser

        #4
        Re: struc problems

        "Mark A. Odell" <odellmark@hotm ail.com> wrote in message
        news:Xns95C787A 6689B0Copyright MarkOdell@130.1 33.1.4...[color=blue]
        > "Spike" <me.hates:spam@ me.net> wrote in
        > news:9wiyd.1250 46$dP1.449333@n ewsc.telia.net:[color=green]
        > > Hi I'm using GCC (and NASM) to send over a asm table...[/color]
        >
        > Have you read you compiler documentation about packing structs? C
        > compilers can add padding bytes after the first element of a struct.[/color]

        After the first? There can be padding after any member (for some reason I
        don't understand, most people say "between members and after the last
        member").

        Alex


        Comment

        • Mike Wahler

          #5
          Re: struc problems

          "Spike" <me.hates:spam@ me.net> wrote in message
          news:6_iyd.1250 48$dP1.449354@n ewsc.telia.net. ..[color=blue]
          > no I haven't... where can I find information about if GCC padds struc:s?[/color]

          Um, the GCC documentation?

          -Mike


          Comment

          • Spike

            #6
            Re: struc problems

            yes I know that. But I was hoping you know where in the manual or if you
            knew the answer.

            //SPike

            "Mike Wahler" <mkwahler@mkwah ler.net> skrev i meddelandet
            news:tajyd.7349 $RH4.2386@newsr ead1.news.pas.e arthlink.net...[color=blue]
            > "Spike" <me.hates:spam@ me.net> wrote in message
            > news:6_iyd.1250 48$dP1.449354@n ewsc.telia.net. ..[color=green]
            >> no I haven't... where can I find information about if GCC padds struc:s?[/color]
            >
            > Um, the GCC documentation?
            >
            > -Mike
            >
            >[/color]


            Comment

            • William Ahern

              #7
              Re: struc problems

              Alex Fraser <me@privacy.net > wrote:[color=blue]
              > "Mark A. Odell" <odellmark@hotm ail.com> wrote in message
              > news:Xns95C787A 6689B0Copyright MarkOdell@130.1 33.1.4...[color=green]
              > > "Spike" <me.hates:spam@ me.net> wrote in
              > > news:9wiyd.1250 46$dP1.449333@n ewsc.telia.net:[color=darkred]
              > > > Hi I'm using GCC (and NASM) to send over a asm table...[/color]
              > >
              > > Have you read you compiler documentation about packing structs? C
              > > compilers can add padding bytes after the first element of a struct.[/color]
              >
              > After the first? There can be padding after any member (for some reason I
              > don't understand, most people say "between members and after the last
              > member").[/color]

              Both are other ways of saying that padding can occur anywhere except before
              the first element, since a pointer to the first element of a struct must
              also be a pointer to that struct and vice versa.

              Comment

              • Alex Fraser

                #8
                Re: struc problems

                "William Ahern" <william@wilbur .25thandClement .com> wrote in message
                news:v4so92-onq.ln1@wilbur. 25thandClement. com...[color=blue]
                > Alex Fraser <me@privacy.net > wrote:[color=green]
                > > "Mark A. Odell" <odellmark@hotm ail.com> wrote in message
                > > news:Xns95C787A 6689B0Copyright MarkOdell@130.1 33.1.4...[color=darkred]
                > > > "Spike" <me.hates:spam@ me.net> wrote in
                > > > news:9wiyd.1250 46$dP1.449333@n ewsc.telia.net:
                > > > > Hi I'm using GCC (and NASM) to send over a asm table...
                > > >
                > > > Have you read you compiler documentation about packing structs? C
                > > > compilers can add padding bytes after the first element of a struct.[/color]
                > >
                > > After the first? There can be padding after any member (for some
                > > reason I don't understand, most people say "between members and after
                > > the last member").[/color]
                >
                > Both are other ways of saying that padding can occur anywhere except
                > before the first element, since a pointer to the first element of a
                > struct must also be a pointer to that struct and vice versa.[/color]

                OK, I think Mark's description was unclear. The two I gave are equivalent to
                each other and equally clear IMO, but "between members and after the last"
                seems pointlessly long-winded.

                Alex


                Comment

                • Default User

                  #9
                  Re: struc problems


                  Spike wrote:[color=blue]
                  > no I haven't... where can I find information about if GCC padds[/color]
                  struc:s?


                  1. Don't top-post. Your replies belong following or interspersed with
                  quoted material.

                  2. Implementation-specific questions should be directed towards an
                  implementation-specific newsgroup. gnu.gcc.help comes to mind.



                  Brian

                  Comment

                  • Lawrence Kirby

                    #10
                    Re: struc problems

                    On Wed, 22 Dec 2004 10:48:31 -0800, William Ahern wrote:
                    [color=blue]
                    > Alex Fraser <me@privacy.net > wrote:[color=green]
                    >> "Mark A. Odell" <odellmark@hotm ail.com> wrote in message
                    >> news:Xns95C787A 6689B0Copyright MarkOdell@130.1 33.1.4...[color=darkred]
                    >> > "Spike" <me.hates:spam@ me.net> wrote in
                    >> > news:9wiyd.1250 46$dP1.449333@n ewsc.telia.net:
                    >> > > Hi I'm using GCC (and NASM) to send over a asm table...
                    >> >
                    >> > Have you read you compiler documentation about packing structs? C
                    >> > compilers can add padding bytes after the first element of a struct.[/color]
                    >>
                    >> After the first? There can be padding after any member (for some reason I
                    >> don't understand, most people say "between members and after the last
                    >> member").[/color]
                    >
                    > Both are other ways of saying that padding can occur anywhere except before
                    > the first element,[/color]

                    True, although "after the first element of a struct" could be interpreted
                    as "only after the first element of the struct", so it is ambiguous.
                    [color=blue]
                    > since a pointer to the first element of a struct must
                    > also be a pointer to that struct and vice versa.[/color]

                    This is incorrect. A pointer to a struct may be *converted* to a pointer
                    to the type of the first member of the struct and the result will be a
                    pointer to the first member of the struct, and vice versa. This is
                    insufficient in itself to disallow padding before the first member
                    because there is nothing to prevent the conversion operation making the
                    appropriate adjustment for padding. C has a separate requirement that
                    there be no padding before the first member.

                    Lawrence

                    Comment

                    • Mark A. Odell

                      #11
                      Re: struc problems

                      "Alex Fraser" <me@privacy.net > wrote in
                      news:32turgF3qd 97lU1@individua l.net:
                      [color=blue][color=green][color=darkred]
                      >> > > Have you read you compiler documentation about packing structs? C
                      >> > > compilers can add padding bytes after the first element of a
                      >> > > struct.
                      >> >
                      >> > After the first? There can be padding after any member (for some
                      >> > reason I don't understand, most people say "between members and after
                      >> > the last member").[/color]
                      >>
                      >> Both are other ways of saying that padding can occur anywhere except
                      >> before the first element, since a pointer to the first element of a
                      >> struct must also be a pointer to that struct and vice versa.[/color]
                      >
                      > OK, I think Mark's description was unclear.[/color]

                      Unclear maybe but not wrong:

                      struct Foo
                      {
                      int a;
                      char b;
                      short c;
                      };

                      "compilers can add padding bytes after the first element"

                      So, the compiler can add padding bytes after 'a', but not before, after
                      'b', and after 'c'. Still sounds like my original statement.

                      --
                      - Mark ->
                      --

                      Comment

                      • Mark A. Odell

                        #12
                        Re: struc problems

                        Lawrence Kirby <lknews@netacti ve.co.uk> wrote in
                        news:pan.2004.1 2.23.10.26.10.2 35000@netactive .co.uk:
                        [color=blue][color=green][color=darkred]
                        >>> > Have you read you compiler documentation about packing structs? C
                        >>> > compilers can add padding bytes after the first element of a struct.
                        >>>
                        >>> After the first? There can be padding after any member (for some
                        >>> reason I don't understand, most people say "between members and after
                        >>> the last member").[/color]
                        >>
                        >> Both are other ways of saying that padding can occur anywhere except
                        >> before the first element,[/color]
                        >
                        > True, although "after the first element of a struct" could be
                        > interpreted as "only after the first element of the struct", so it is
                        > ambiguous.[/color]

                        I'll give you that but in the absense of a constraint, e.g. "only after"
                        why would you think to add such a constraint?

                        --
                        - Mark ->
                        --

                        Comment

                        • Mark A. Odell

                          #13
                          Re: struc problems

                          "Spike" <me.hates:spam@ me.net> wrote in
                          news:agjyd.1250 51$dP1.449239@n ewsc.telia.net:
                          [color=blue][color=green][color=darkred]
                          >>> no I haven't... where can I find information about if GCC padds
                          >>> struc:s?[/color]
                          >>
                          >> Um, the GCC documentation?[/color][/color]
                          [color=blue]
                          > yes I know that. But I was hoping you know where in the manual or if you
                          > knew the answer.[/color]

                          Just search for the word "pack"!

                          --
                          - Mark ->
                          --

                          Comment

                          • Lawrence Kirby

                            #14
                            Re: struc problems

                            On Thu, 23 Dec 2004 13:40:00 +0000, Mark A. Odell wrote:
                            [color=blue]
                            > Lawrence Kirby <lknews@netacti ve.co.uk> wrote in
                            > news:pan.2004.1 2.23.10.26.10.2 35000@netactive .co.uk:[/color]

                            ....
                            [color=blue][color=green]
                            >> True, although "after the first element of a struct" could be
                            >> interpreted as "only after the first element of the struct", so it is
                            >> ambiguous.[/color]
                            >
                            > I'll give you that but in the absense of a constraint, e.g. "only after"
                            > why would you think to add such a constraint?[/color]

                            I only suggest that use of English is loose enough to allow that as a
                            possible interpretation.

                            Lawrence

                            Comment

                            • Mike Wahler

                              #15
                              Re: struc problems

                              "Spike" <me.hates:spam@ me.net> wrote in message
                              news:agjyd.1250 51$dP1.449239@n ewsc.telia.net. ..[color=blue]
                              > yes I know that. But I was hoping you know where in the manual[/color]

                              Sorry, no, I won't read the manual for you.

                              [color=blue]
                              > or if you
                              > knew the answer.[/color]

                              If I need the answer, I know where I can find it.
                              So do you.

                              -Mike


                              Comment

                              Working...