assembly - NASM: emit MSW of non-scalar (link-time) value -


i attempting define constant idt (interrupt descriptor table) entry in nasm, , so, need emit data table high word of double-word address that not resolved until link time. there way it?

here's interrupt handler:

;;; interrupt 3 (breakpoint) handler.  now, poke screen , halt.          align   8 int3:         mov     [0xb8000],dword '* * '         hlt 

and here's idt entry references it. most-significant , least-significant words of offset need stored separately , non-contiguously:

        ;; interrupt 3 - breakpoint         dw      int3                    ; offset (low)    <---- works         dw      codesel                 ; code selector         db      0                       ; unused         db      0b10001111              ; present, ring 0, 32-bit trap gate         dw      int3 >> 16              ; offset (high)   <---- assembly error 

nasm correctly causes ld emit low word of int3's address, high word fails @ assembly error:

 pgm.asm:240: error: shift operator may applied scalar values 

nasm won't math value isn't defined until link time. understand, need way work around this. could:

  • locate int3 absolutely
  • build idt @ runtime instead of assembly time

i'll end building idt @ runtime, it'd know if there way cause assembler/linker emit data table high word of address not resolved until link time.


particulars:

  • nasm 2.20.01
  • nasm output format "aout"
  • ld version 2.22
  • 32-bit mode (nasm "bits 32" directive issued)

well... know, nasm condescend shift on difference between 2 labels. usual construct like:

dw (int3 - $$) >> 16

where $$ refers beginning of section. calculates "file offset". not value want shift.

dw (int3 - $$ + origin) >> 16

may want... origin is... well, told nasm org, if using flat binary. assume you're assembling -f elf32 or -f elf64, telling ld --oformat=binary, , telling ld either in linker script or on command line want .text (?). seems work. made interesting discovery: if tell ld -oformat=binary (one hyphen) instead of --oformat=binary (two hyphens), ld silently outputs nothing! don't - waste lot of time!


Comments

Popular posts from this blog

linux - Does gcc have any options to add version info in ELF binary file? -

android - send complex objects as post php java -

charts - What graph/dashboard product is facebook using in Dashboard: PUE & WUE -