Skip to content

Commit c7f426f

Browse files
komhH. Peter Anvin
authored andcommitted
outobj: add obj2 driver
Obj2 is an obj variation for OS/2. Obj2 has the following differences from obj. 1. Default attributes for a segment are ALIGN=16 and USE32. 2. Add a segment to FLAT group implicitly if 32-bit segment. 3. Recognize Unix sections .text, .rodata, .data and .bss as TEXT32, CONST32, DATA32 and BSS32 respectively for compatibility with other Unix platforms. 4. Set default classes implicitly for known segments such as TEXT32, CONST32, DATA32, BSS32 and so on. Signed-off-by: KO Myung-Hun <komh78@gmail.com>
1 parent a65be7d commit c7f426f

File tree

3 files changed

+127
-8
lines changed

3 files changed

+127
-8
lines changed

output/outform.h

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
* OF_ONLY -- only include specified object formats
1616
* OF_name -- ensure that output format 'name' is included
1717
* OF_NO_name -- remove output format 'name'
18-
* OF_DOS -- ensure that 'obj', 'bin', 'win32' & 'win64' are included.
18+
* OF_DOS -- ensure that 'obj', 'obj2', 'bin', 'win32' & 'win64' are included.
1919
* OF_UNIX -- ensure that 'aout', 'aoutb', 'coff', 'elf32' & 'elf64' are in.
2020
* OF_OTHERS -- ensure that 'bin', 'as86', 'rdf' 'macho32' & 'macho64' are in.
2121
* OF_ALL -- ensure that all formats are included.
@@ -56,7 +56,7 @@
5656

5757
/* ====configurable info begins here==== */
5858
/* formats configurable:
59-
* bin,obj,elf32,elf64,aout,aoutb,coff,win32,as86,rdf2,macho32,macho64 */
59+
* bin,obj,obj2,elf32,elf64,aout,aoutb,coff,win32,as86,rdf2,macho32,macho64 */
6060

6161
/* process options... */
6262

@@ -73,6 +73,9 @@
7373
#ifndef OF_OBJ
7474
#define OF_OBJ
7575
#endif
76+
#ifndef OF_OBJ2
77+
#define OF_OBJ2
78+
#endif
7679
#ifndef OF_ELF32
7780
#define OF_ELF32
7881
#endif
@@ -119,6 +122,9 @@
119122
#ifndef OF_OBJ
120123
#define OF_OBJ
121124
#endif
125+
#ifndef OF_OBJ2
126+
#define OF_OBJ2
127+
#endif
122128
#ifndef OF_BIN
123129
#define OF_BIN
124130
#endif
@@ -179,6 +185,9 @@
179185
#ifdef OF_NO_OBJ
180186
#undef OF_OBJ
181187
#endif
188+
#ifdef OF_NO_OBJ2
189+
#undef OF_OBJ2
190+
#endif
182191
#ifdef OF_NO_ELF32
183192
#undef OF_ELF32
184193
#endif
@@ -234,6 +243,7 @@ extern const struct ofmt of_elfx32;
234243
extern const struct ofmt of_elf64;
235244
extern const struct ofmt of_as86;
236245
extern const struct ofmt of_obj;
246+
extern const struct ofmt of_obj2;
237247
extern const struct ofmt of_win32;
238248
extern const struct ofmt of_win64;
239249
extern const struct ofmt of_ieee;
@@ -278,6 +288,9 @@ static const struct ofmt * const drivers[] = {
278288
#ifdef OF_OBJ
279289
&of_obj,
280290
#endif
291+
#ifdef OF_OBJ2
292+
&of_obj2,
293+
#endif
281294
#ifdef OF_WIN32
282295
&of_win32,
283296
#endif

output/outobj.c

Lines changed: 111 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
#include "outform.h"
2323
#include "outlib.h"
2424

25-
#ifdef OF_OBJ
25+
#if defined(OF_OBJ) || defined(OF_OBJ2)
2626

2727
/*
2828
* outobj.c is divided into two sections. The first section is low level
@@ -602,6 +602,11 @@ static struct ExpDef {
602602
#define EXPDEF_FLAG_NODATA 0x20
603603
#define EXPDEF_MASK_PARMCNT 0x1F
604604

605+
struct SegmentToClass {
606+
const char *segment; /* segment */
607+
const char *segclass; /* class */
608+
};
609+
605610
static int32_t obj_entry_seg, obj_entry_ofs;
606611

607612
const struct ofmt of_obj;
@@ -613,10 +618,42 @@ static struct Segment *current_seg;
613618
/* Name for segment to use if no segment directive is defined */
614619
static char DEFAULT_SEG[] = "__NASMDEFSEG";
615620

621+
/* Conversion table from known segments to default classes */
622+
static const struct SegmentToClass conv_table[] = {
623+
/* known segments, default class */
624+
{ "CODE", "CODE" },
625+
{ "TEXT", "CODE" },
626+
{ "CONST", "CONST" },
627+
{ "DATA", "DATA" },
628+
{ "BSS", "BSS" },
629+
{ "STACK", "STACK" },
630+
{ "CODE32", "CODE" },
631+
{ "TEXT32", "CODE" },
632+
{ "CONST32", "CONST" },
633+
{ "DATA32", "DATA" },
634+
{ "BSS32", "BSS" },
635+
{ "STACK32", "STACK" },
636+
{ NULL, NULL },
637+
};
638+
616639
static int32_t obj_segment(char *, int *);
617640
static void obj_write_file(void);
618641
static enum directive_result obj_directive(enum directive, char *);
619642

643+
static const char *get_default_class(const char *segment)
644+
{
645+
const struct SegmentToClass *conv;
646+
647+
if (segment && segment[0]) {
648+
for (conv = conv_table; conv->segment; conv++) {
649+
if (!strcmp(segment, conv->segment))
650+
return conv->segclass;
651+
}
652+
}
653+
654+
return NULL;
655+
}
656+
620657
static void obj_init(void)
621658
{
622659
strlcpy(obj_infile, inname, sizeof(obj_infile));
@@ -643,6 +680,21 @@ static void obj_init(void)
643680
obj_use32 = false;
644681
passtwo = 0;
645682
current_seg = NULL;
683+
684+
/*
685+
* Convert known Unix sections to OMF segments via macros.
686+
*/
687+
if (ofmt == &of_obj2) {
688+
char section_text[] = ".text=TEXT32";
689+
char section_rodata[] = ".rodata=CONST32";
690+
char section_data[] = ".data=DATA32";
691+
char section_bss[] = ".bss=BSS32";
692+
693+
pp_pre_define(section_text);
694+
pp_pre_define(section_rodata);
695+
pp_pre_define(section_data);
696+
pp_pre_define(section_bss);
697+
}
646698
}
647699

648700
static void obj_cleanup(void)
@@ -1394,9 +1446,16 @@ static int32_t obj_segment(char *name, int *bits)
13941446
any_segs = true;
13951447
seg->name = nasm_strdup(name);
13961448
seg->currentpos = 0;
1397-
seg->align = seg->origalign = 1; /* default */
1398-
seg->use32 = false; /* default */
1399-
seg->combine = CMB_PUBLIC; /* default */
1449+
if (ofmt == &of_obj) {
1450+
seg->align = 1; /* default for obj */
1451+
seg->origalign = 1; /* default for obj */
1452+
seg->use32 = false; /* default for obj */
1453+
} else {
1454+
seg->align = 16; /* default for obj2 */
1455+
seg->origalign = 16; /* default for obj2 */
1456+
seg->use32 = true; /* default for obj2 */
1457+
}
1458+
seg->combine = CMB_PUBLIC; /* default */
14001459
seg->segclass = seg->overlay = NULL;
14011460
seg->pubhead = NULL;
14021461
seg->pubtail = &seg->pubhead;
@@ -1489,6 +1548,31 @@ static int32_t obj_segment(char *name, int *bits)
14891548
if (!seg->use32 && seg->grp && !strcmp(seg->grp->name, "FLAT"))
14901549
nasm_panic("wrong combination of USE16(16-bit segment) and FLAT");
14911550

1551+
if (ofmt == &of_obj2) {
1552+
if (seg->use32 && !seg->grp) {
1553+
struct Group *grp;
1554+
for (grp = grphead; grp; grp = grp->next)
1555+
if (!strcmp(grp->name, "FLAT"))
1556+
break;
1557+
if (!grp) {
1558+
obj_directive(D_GROUP, "FLAT");
1559+
for (grp = grphead; grp; grp = grp->next)
1560+
if (!strcmp(grp->name, "FLAT"))
1561+
break;
1562+
if (!grp)
1563+
nasm_panic("failure to define FLAT?!");
1564+
}
1565+
seg->grp = grp;
1566+
}
1567+
1568+
if (!seg->segclass) {
1569+
const char *segclass = get_default_class(seg->name);
1570+
1571+
if (segclass)
1572+
seg->segclass = nasm_strdup(segclass);
1573+
}
1574+
}
1575+
14921576
/* We need to know whenever we have at least one 32-bit segment */
14931577
obj_use32 |= seg->use32;
14941578

@@ -2685,4 +2769,26 @@ const struct ofmt of_obj = {
26852769
obj_cleanup,
26862770
obj_pragma_list
26872771
};
2688-
#endif /* OF_OBJ */
2772+
2773+
const struct ofmt of_obj2 = {
2774+
"Intel/Microsoft OMF (i386) (OS/2)",
2775+
"obj2",
2776+
".obj",
2777+
0,
2778+
32,
2779+
borland_debug_arr,
2780+
&borland_debug_form,
2781+
obj_stdmac,
2782+
obj_init,
2783+
null_reset,
2784+
obj_out,
2785+
obj_deflabel,
2786+
obj_segment,
2787+
NULL,
2788+
obj_sectalign,
2789+
obj_segbase,
2790+
obj_directive,
2791+
obj_cleanup,
2792+
obj_pragma_list
2793+
};
2794+
#endif /* OF_OBJ || OF_OBJ2 */

output/outobj.mac

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
;; SPDX-License-Identifier: BSD-2-Clause
22
;; Copyright 1996-2009 The NASM Authors - All Rights Reserved
33

4-
OUT: obj
4+
OUT: obj obj2
55
%define __?SECT?__ [section .text]
66
%imacro group 1+.nolist
77
[group %1]

0 commit comments

Comments
 (0)