OS/2 codes: NASM and 32-bit FLAT sections/segments

NASM is a widely used assembler, and the only modern assembler for OS/2. Almost all the open-source projects using assembly codes are using NASM. Because of this, porting them to OS/2 is much easier.

BTW, NASM manual says that FLAT property is necessary to declare OS/2 32-bit sections/segments for 32-bit FLAT memory model. Unfortunately, however, NASM manual seems to be wrong because FLAT is not enough nor necessary for OS/2 32-bit FLAT memory model.

Here is the correct way to declare 32-bit FLAT section/segment on OS/2.

In general, OS/2 32-bit section/segment is declared like this: 

section TEXT32 public align=16 use32 class=CODE

This declares 32-bit(use32) CODE segment(class=CODE) whose name is TEXT32 with 16-bytes aligned(align=16). And this segment will be concatenated with segments with the same segment name(public) at linke time. For details, see NASM docs(https://www.nasm.us/xdoc/2.15.05/html/nasmdoc8.html#section-8.4.1).

Here, 'FLAT' property is not needed. Rather, it may cause unnecessary warnings such as multiple-grouping of the same segment. I recommend not to use 'FLAT' property.

Instead, the important is to declare proper groups.

For example, kLIBC uses CGROUP for code segments and DGROUP for data, const and bss segments. 

In case of CGROUP, if you use the other segment name than TEXT32 for a code segment name, if you use Open Watcom linker such as wl.exe and if you don't have any special reason, then the segment should be included into CGROUP like this:

group CGROUP code_segment_name

Without this, segment ordering of kLIBC may be broken.

In case of DGROUP, if you don't use DATA32 for a data segment name, if you don't use BSS32 for a bss segment name, if you don't use CONST32 for a const segment name, then they should be included into DGROUP like this:

group DGROUP segment_name

Consequently, the best is to use

  • TEXT32 for a code segment name
  • DATA32 for a data segment name
  • CONST32 for a const segment name
  • BSS32 for a bss segment name
  • STACK32 for a stack segment name 

With the above, there is no need to declare proper group additionaly nor to use FLAT property.

Finally, here is the macros to help this:


댓글

이 블로그의 인기 게시물

토렌트: < 왕좌의 게임 > 시즌 1 ~ 시즌 8 완결편 마그넷

토렌트: NGC < 코스모스 > 우리말 더빙 전편(1편~13편) 마그넷

토렌트: < 스타워즈 > Ep.1 ~ Ep.6 마그넷