x64 problem (Debian and Ubuntu)

Linux specific forum
infratec
Always Here
Always Here
Posts: 7662
Joined: Sun Sep 07, 2008 12:45 pm
Location: Germany

x64 problem (Debian and Ubuntu)

Post by infratec »

Hi,

still my serial problem.
Now on 64bit.

In 32bit the size of the c structure serial_struct is 60 byte.
With #PB_Structure_AlignC I get the same size of my structure.

In Debian and Ubuntu x64 I get a size of 72 bytes with a C program
and a size of 4 for int.
In PB I get a size of 120 bytes for the same structure.

What to hell is going on there :?:

Why is int 4 bytes inside of C ? I expected 8 and PB also uses 8 bytes for .i

Here is my structure

Code: Select all

Structure serial_struct Align #PB_Structure_AlignC
  type.i
  line.i
  port.i
  irq.i
  flags.i
  xmit_fifo_size.i
  custom_divisor.i
  baud_base.i
  close_delay.u
  io_type.b
  reserved_char.b[1]
  hub6.i
  closing_wait.u
  closing_wait2.u
  *iomem_base
  iomem_reg_shift.u
  port_high.i
  iomap_base.l
EndStructure
which is a 1 by 1 of /usr/include/linux/serial.h

And in x86 it works correct.
In x64 it fails.


Any ideas ?

Bernd
User avatar
idle
Always Here
Always Here
Posts: 6026
Joined: Fri Sep 21, 2007 5:52 am
Location: New Zealand

Re: x64 problem (Debian and Ubuntu)

Post by idle »

think you should be using longs for the int fields

Code: Select all

Structure serial_struct Align #PB_Structure_AlignC
  type.l
  line.l
  port.l
  irq.l
  flags.l
  xmit_fifo_size.l
  custom_divisor.l
  baud_base.l
  close_delay.u
  io_type.b
  reserved_char.b[1]
  hub6.l
  closing_wait.u
  closing_wait2.u
  *iomem_base
  iomem_reg_shift.u
  port_high.l
  iomap_base.i
EndStructure
Windows 11, Manjaro, Raspberry Pi OS
Image
infratec
Always Here
Always Here
Posts: 7662
Joined: Sun Sep 07, 2008 12:45 pm
Location: Germany

Re: x64 problem (Debian and Ubuntu)

Post by infratec »

idle wrote:think you should be using longs for the int fields
Yes, but why :?:

I have no explanation for that, since the C header is exactly the same for x86 and x64.

Bernd
User avatar
idle
Always Here
Always Here
Posts: 6026
Joined: Fri Sep 21, 2007 5:52 am
Location: New Zealand

Re: x64 problem (Debian and Ubuntu)

Post by idle »

No an Int in c is the same as a long in PB

c Short is 16 bits
c Int is 32 bits
c long is 32 or 64 bits
Windows 11, Manjaro, Raspberry Pi OS
Image
infratec
Always Here
Always Here
Posts: 7662
Joined: Sun Sep 07, 2008 12:45 pm
Location: Germany

Re: x64 problem (Debian and Ubuntu)

Post by infratec »

Hi idle,

thanks for this hint.

I'm to old for this stuff :cry:

I learned that an integer has the native size of the architecture.
So for me an integer had 64bit on a 64bit CPU/OS.

In the LP64 I32LP64 model http://en.wikipedia.org/wiki/64-bit#64-bit_data_models
I have to read that this is not the case.

But than I'm thinking about a feature request to change this in PB too.

Bernd
User avatar
idle
Always Here
Always Here
Posts: 6026
Joined: Fri Sep 21, 2007 5:52 am
Location: New Zealand

Re: x64 problem (Debian and Ubuntu)

Post by idle »

yes it's caught me out when I transitioned to x64
here are mappings to pb from common c types

Code: Select all

Macro char : b : EndMacro
Macro unsigned_char :  a : EndMacro   
Macro short : w : EndMacro 
Macro short_int  :  w : EndMacro   
Macro unsigned_short :  u : EndMacro 
Macro unsigned_short_int : u : EndMacro    
Macro int  : l : EndMacro 
Macro unsigned_int : l : EndMacro    
Macro long : i : EndMacro 
Macro long_long :  q : EndMacro 

Macro Int8 : char : EndMacro 
Macro uInt8 : unsigned_char : EndMacro
Macro int16 : short : EndMacro 
Macro uint16 : unsigned_short : EndMacro 
Macro int32 : int : EndMacro 
Macro uint32 : unsigned_int : EndMacro 
Macro int64 : long_long : EndMacro 
Macro uint64 : long_long : EndMacro 

Windows 11, Manjaro, Raspberry Pi OS
Image
Post Reply