Author Topic: A 64 bit linux example  (Read 21429 times)

Gunther

  • Member
  • *****
  • Posts: 3585
  • Forgive your enemies, but never forget their names
A 64 bit linux example
« on: July 12, 2012, 08:53:15 AM »
I've written a small standalone assembly language application for 64 bit Linux. I wrote it with NASM, but YASM should work, too.

The program prints first a zero terminated C string and after that some values (32 bit unsigned integer, 64 bit unsigned integer, REAL 4 value, REAL 8 value). At the end it displays a CPU register dump. I'm currently working at the co-processor dump (the old FPU and the new XMM registers).

For linking information, please read the readme.txt, it's part of the archive.

Basically it is not so easy to develop for both platforms (Win64 and Linux64) in parallel, because the underlying ABIs are different. The current version of the 64 bit Linux ABI can be found here: http://www.x86-64.org/documentation/

Gunther
Get your facts first, and then you can distort them.

Antariy

  • Member
  • ****
  • Posts: 551
Re: A 64 bit linux example
« Reply #1 on: July 14, 2012, 11:21:13 AM »
Gunther, interesting and informative example! :t

Is the libc linked statically, or as "import library"? It's interesting that, for instance, the format-specifier strings are passed as a 32 bit pointers inside of the 64 bit space. If the libc linked as the import library, it should calculate the effective offset, or it lies "near", in the +/- 2 GB address range?

Gunther

  • Member
  • *****
  • Posts: 3585
  • Forgive your enemies, but never forget their names
Re: A 64 bit linux example
« Reply #2 on: July 15, 2012, 04:34:30 AM »
Hi Alex,

Gunther, interesting and informative example! :t

Thank you, Alex.

Is the libc linked statically, or as "import library"? It's interesting that, for instance, the format-specifier strings are passed as a 32 bit pointers inside of the 64 bit space. If the libc linked as the import library, it should calculate the effective offset, or it lies "near", in the +/- 2 GB address range?

The archive contains both variants. So, the truth is: I was to lazy to write my own I/O procedures; therefore the application uses libc. Your question about the address space is interesting. I think we've to check that with a look into the present libc source code.

Gunther
Get your facts first, and then you can distort them.

jj2007

  • Member
  • *****
  • Posts: 10654
  • Assembler is fun ;-)
    • MasmBasic
Re: A 64 bit linux example
« Reply #3 on: July 15, 2012, 04:44:36 AM »
Your question about the address space is interesting.

See this thread in the old forum

Quote
they have created a special ABI called x32 which allows programs to use 32-bit pointers while still being able to utilize the 64-bit extended registers from standard 64bit mode. Using 64-bit address references makes the code larger and thus fills up the cpu caches faster, so by using 32-bit adress references while still using the extra registers from 64-bit mode they were apparently able to get the same code to run ~15% faster in x32 abi mode compared to pure 64bit mode

Gunther

  • Member
  • *****
  • Posts: 3585
  • Forgive your enemies, but never forget their names
Re: A 64 bit linux example
« Reply #4 on: July 15, 2012, 08:03:27 AM »
Jochen,

See this thread in the old forum

thank you for that hint; that's the answer of the question.

Gunther
Get your facts first, and then you can distort them.

Antariy

  • Member
  • ****
  • Posts: 551
Re: A 64 bit linux example
« Reply #5 on: July 15, 2012, 08:13:50 AM »
See this thread in the old forum

Thank you, Jochen :t
Yeah, it seem they are locate an import runtime in the "near" space of +/- 2 GB range relatively to the program's (calling) code.

Gunther

  • Member
  • *****
  • Posts: 3585
  • Forgive your enemies, but never forget their names
Re: A 64 bit linux example
« Reply #6 on: July 16, 2012, 12:27:42 AM »
Hi Alex,

Thank you, Jochen :t
Yeah, it seem they are locate an import runtime in the "near" space of +/- 2 GB range relatively to the program's (calling) code.

according to the above link, yes. Right or wrong: in the next time I'll check that question again with the libc sources.

Gunther
Get your facts first, and then you can distort them.