JustOneMan
JustOneMan

Reputation: 202

How to translate this code from Intel(nasm) to AT&T(gas) syntax?

gdt64:
  dq 0 ; zero entry
.code: equ $ - gdt64
  ; 0x08 kernel CS 0x8
  ; bits set: descriptor type, present, executable, 64bit
  dq (1<<53) | (1<<47) |                     (1<<44) | (1<<43) ; kernel
  ; 0x10 user CS
  ; works when its set to kernel mode, but when in user mode, it doesnt, duh
  ;dq (1<<53) | (1<<47) |                     (1<<44) | (1<<43) ; kernel
  dq (1<<53) | (1<<47) | (1<<46) | (1<<45) | (1<<44) | (1<<43)

I understand that dq is .long. And I can translate first part of this:

gdt64:
  .long 0 // zero entry
.code = . - gdt64

But How to translate line like this:

  dq (1<<53) | (1<<47) | (1<<46) | (1<<45) | (1<<44) | (1<<43)

Upvotes: 0

Views: 238

Answers (1)

Nate Eldredge
Nate Eldredge

Reputation: 58052

First of all, dq in NASM assembles an 8-byte quadword, whereas .long in x86 GAS is a 4-byte doubleword, so that's not what you want. The correct equivalent is .quad.

Your (1<<53) | ... is just an arithmetic expression using C-like shift and bitwise operators, and dq (1 << 53) | ... assembles a quadword having as its value the result of this expression. GAS accepts this syntax as well, so you can simply write

.quad (1<<53) | (1<<47) | (1<<46) | (1<<45) | (1<<44) | (1<<43)

Upvotes: 3

Related Questions