flat assembler
Message board for the users of flat assembler.

Index > Main > Code assembling with binary format but not with COFF

Author
Thread Post new topic Reply to topic
kwistjhp



Joined: 18 Jun 2009
Posts: 2
kwistjhp 18 Jun 2009, 10:15
dear all,

What am I doing wrong here? The code does assemble when I comment out the first two lines (format/section) but gives an invalid expression error for the line with :

Code:
dw (tss_start and 0xffff)     


any comments (or solution/workaround)?

Many thanks!
Johan

Code:
format COFF
section '.data' data

; Global descriptor pointer

gdtr:
dw gdt_end-gdt-1 ; GDT limit
dd gdt ; linear, physical address of GDT

; Basic global descriptor table

gdt:
; Null descriptor
dd      0 
dd      0

; Linear code segment descriptor
CODE_SEL = $-gdt
dw      0xFFFF
dw      0
db      0
db      0x9A ; Present, Ring 0, Code, Non-conforming, Readable
db      0xCF
db      0
  
; Linear data segment descriptor
DATA_SEL = $-gdt
dw      0xFFFF
dw      0
db      0
db      0x92 ; Present, Ring 0, Data, Expand-up, Writable
db      0xCF
db      0

TSS_SEL = $-gdt
dw      103 ; 104 byte TSS
dw      (tss_start and 0xffff) ; low word address
db      ((tss_start shr 16) and 0xff) ; mid byte address
db      0x89 ; P = 1, DPL = 00 TYPE = 01001 BUSY = FALSE
db      0x10 ; G = 0 LIMIT = 0 AVL = 1
db      (tss_start shr 24) ; high byte address

gdt_end:

tss_start:      dw      TSS_SEL, 0
; remainder of TSS follows here     
Post 18 Jun 2009, 10:15
View user's profile Send private message Reply with quote
Japheth



Joined: 26 Oct 2004
Posts: 151
Japheth 18 Jun 2009, 10:49
> What am I doing wrong here?

This is a slightly advanced topic.

tss_start is a label, which becomes a so-called "relocatable item" in the object module. The value of relocatable items is, unlike absolute constants, not known at assembly time. Instead the linker (or OS loader) will assign the final value.

To help the linker the assembler has to add fixups for relocatable items, which tell the linker how the final value is to be calculated. However, the types of fixups is rather limited and depends on the object format. That's why you cannot do all kinds of arithmetic with labels.

Now, as far as your source is concerned: there might exist a work-around in Fasm for expression (<label> and 0xffff), because COFF supports a fixup for the lower 16bits of an address. However, some other label calculations in your source - which use "shift right" operators - surely won't work.
Post 18 Jun 2009, 10:49
View user's profile Send private message Reply with quote
kwistjhp



Joined: 18 Jun 2009
Posts: 2
kwistjhp 18 Jun 2009, 10:57
Ah, I see, thanks! So I suppose best thing to do is to compute the values at runtime then.
Post 18 Jun 2009, 10:57
View user's profile Send private message Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  


< Last Thread | Next Thread >
Forum Rules:
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Copyright © 1999-2025, Tomasz Grysztar. Also on GitHub, YouTube.

Website powered by rwasa.