Skip to content

Commit

Permalink
Merge pull request #420 from braddr/segmented
Browse files Browse the repository at this point in the history
cleanup backend TYtypes related to flat vs segmented memory models
  • Loading branch information
WalterBright committed Oct 11, 2011
2 parents 00753e3 + cd38b47 commit 90c15b3
Show file tree
Hide file tree
Showing 24 changed files with 508 additions and 247 deletions.
6 changes: 4 additions & 2 deletions src/backend/cc.h
Expand Up @@ -1422,9 +1422,12 @@ enum FL
FLasm, // (code) an ASM code
#if TX86
FLndp, // saved 8087 register
#endif
#if TARGET_SEGMENTED
FLfardata, // ref to far data segment
FLlocalsize, // replaced with # of locals in the stack frame
FLcsdata, // ref to code segment variable
#endif
FLlocalsize, // replaced with # of locals in the stack frame
FLtlsdata, // thread local storage
FLbprel, // ref to variable at fixed offset from frame pointer
FLframehandler, // ref to C++ frame handler for NT EH
Expand All @@ -1438,7 +1441,6 @@ enum FL
FLgotoff, // global offset table entry inside this object file
//FLoncedata, // link once data
//FLoncecode, // link once code
#endif
#endif
FLMAX
};
Expand Down
2 changes: 1 addition & 1 deletion src/backend/cdef.h
Expand Up @@ -233,7 +233,7 @@ One and only one of these macros must be set by the makefile:
* This is not quite the same as !SIXTEENBIT, as one could
* have near/far with 32 bit code.
*/
#define TARGET_FLAT (MARS || !TARGET_WINDOS)
#define TARGET_SEGMENTED (!MARS && TARGET_WINDOS)


#define STATEMENT_SCOPES CPP
Expand Down
6 changes: 4 additions & 2 deletions src/backend/cgcod.c
Expand Up @@ -2213,8 +2213,10 @@ code *codelem(elem *e,regm_t *pretregs,bool constflag)
case TYjhandle:
#endif
case TYnptr:
#if TARGET_SEGMENTED
case TYsptr:
case TYcptr:
#endif
*pretregs |= IDXREGS;
break;
case TYshort:
Expand All @@ -2227,11 +2229,11 @@ code *codelem(elem *e,regm_t *pretregs,bool constflag)
case TYullong:
case TYcent:
case TYucent:
#if !TARGET_FLAT
#if TARGET_SEGMENTED
case TYfptr:
case TYhptr:
#endif
case TYvptr:
#endif
*pretregs |= ALLREGS;
break;
}
Expand Down
30 changes: 22 additions & 8 deletions src/backend/cgcv.c
Expand Up @@ -406,9 +406,11 @@ void cv_init()
dttab4[TYptr] = 0x400;
dttab4[TYnptr] = 0x400;
dttab4[TYjhandle] = 0x400;
#if TARGET_SEGMENTED
dttab4[TYsptr] = 0x400;
dttab4[TYcptr] = 0x400;
dttab4[TYfptr] = 0x500;
#endif

if (config.flags & CFGeasyomf)
{ cgcv.LCFDoffset = EASY_LCFDoffset;
Expand Down Expand Up @@ -1546,15 +1548,17 @@ unsigned char cv4_callconv(type *t)

switch (tybasic(t->Tty))
{
case TYnfunc: call = 0; break;
#if TARGET_SEGMENTED
case TYffunc: call = 1; break;
case TYnpfunc: call = 2; break;
case TYfpfunc: call = 3; break;
case TYf16func: call = 3; break;
case TYnsfunc: call = 7; break;
case TYfsfunc: call = 8; break;
case TYnsysfunc: call = 9; break;
case TYfsysfunc: call = 10; break;
#endif
case TYnfunc: call = 0; break;
case TYnpfunc: call = 2; break;
case TYnsfunc: call = 7; break;
case TYifunc: call = 1; break;
case TYjfunc: call = 2; break;
case TYmfunc: call = 11; break; // this call
Expand Down Expand Up @@ -1738,13 +1742,17 @@ unsigned cv4_typidx(type *t)
if (t->Tkey)
goto Laarray;
#endif
#if TARGET_SEGMENTED
case TYsptr:
case TYcptr:
#endif
Lptr:
attribute |= I32 ? 10 : 0; goto L2;
#if TARGET_SEGMENTED
case TYfptr:
case TYvptr: attribute |= I32 ? 11 : 1; goto L2;
case TYhptr: attribute |= 2; goto L2;
#endif

L2:
#if 1
Expand Down Expand Up @@ -1877,15 +1885,17 @@ unsigned cv4_typidx(type *t)
typidx = cv_debtyp(d);
break;

case TYnfunc:
#if TARGET_SEGMENTED
case TYffunc:
case TYnpfunc:
case TYfpfunc:
case TYf16func:
case TYnsfunc:
case TYfsfunc:
case TYnsysfunc:
case TYfsysfunc:
#endif
case TYnfunc:
case TYnpfunc:
case TYnsfunc:
case TYmfunc:
case TYjfunc:
case TYifunc:
Expand Down Expand Up @@ -2406,10 +2416,12 @@ STATIC void cv4_func(Funcsym *s)
#if JHANDLE
case TYjhandle:
#endif
case TYnullptr:
case TYnptr:
#if TARGET_SEGMENTED
case TYsptr:
case TYcptr:
#endif
case TYnullptr:
case TYnptr:
if (I32)
goto case_eax;
else
Expand All @@ -2427,6 +2439,7 @@ STATIC void cv4_func(Funcsym *s)
else
goto case_dxax;

#if TARGET_SEGMENTED
case TYfptr:
case TYhptr:
if (I32)
Expand All @@ -2439,6 +2452,7 @@ STATIC void cv4_func(Funcsym *s)
goto case_edxebx;
else
goto case_dxbx;
#endif

case TYdouble:
case TYidouble:
Expand Down
28 changes: 19 additions & 9 deletions src/backend/cgelem.c
Expand Up @@ -133,17 +133,17 @@ int elemisone(elem *e)
case TYllong:
case TYullong:
case TYnullptr:
#if TX86
#if JHANDLE
case TYjhandle:
#endif
case TYnptr:
#if TARGET_SEGMENTED
case TYsptr:
case TYcptr:
case TYhptr:
#endif
case TYfptr:
case TYvptr:
#endif
case TYnptr:
case TYbool:
case TYwchar_t:
case TYdchar:
Expand Down Expand Up @@ -198,17 +198,17 @@ int elemisnegone(elem *e)
case TYllong:
case TYullong:
case TYnullptr:
#if TX86
case TYnptr:
#if JHANDLE
case TYjhandle:
#endif
case TYnptr:
#if TARGET_SEGMENTED
case TYsptr:
case TYcptr:
case TYhptr:
#endif
case TYfptr:
case TYvptr:
#endif
case TYbool:
case TYwchar_t:
case TYdchar:
Expand Down Expand Up @@ -1084,7 +1084,11 @@ STATIC elem * elmin(elem *e)
/* for floating or far or huge pointers! */
if (e1->Eoper == OPadd && e2->Eoper == OPadd &&
cnst(e1->E2) && cnst(e2->E2) &&
(tyintegral(tym) || tybasic(tym) == TYjhandle || tybasic(tym) == TYnptr || tybasic(tym) == TYsptr ))
(tyintegral(tym) || tybasic(tym) == TYjhandle || tybasic(tym) == TYnptr
#if TARGET_SEGMENTED
|| tybasic(tym) == TYsptr
#endif
))
{ elem *tmp;

e->Eoper = OPadd;
Expand Down Expand Up @@ -2306,7 +2310,7 @@ STATIC elem * elind(elem *e)
}
break;
case OPadd:
#if TX86
#if TARGET_SEGMENTED
if (OPTIMIZER)
{ /* Try to convert far pointer to stack pointer */
elem *e12 = e1->E2;
Expand Down Expand Up @@ -2556,7 +2560,11 @@ CEXTERN elem * elstruct(elem *e)
/* We should do the analysis to see if we can use
something simpler than TYfptr.
*/
#if TARGET_SEGMENTED
typ = (intsize == LONGSIZE) ? TYnptr : TYfptr;
#else
typ = TYnptr;
#endif
e2 = el_una(OPaddr,typ,e2);
e2 = optelem(e2,TRUE); /* distribute & to x and y leaves */
*pe2 = el_una(OPind,ty2,e2);
Expand Down Expand Up @@ -3401,7 +3409,7 @@ STATIC elem * elptrlptr(elem *e)
/*********************************
* Conversions of handle pointers to far pointers.
*/

// TODO: should this function go away entirely in TARGET_FLAT mode?
STATIC elem * elvptrfptr(elem *e)
{ elem *e1;
elem *e12;
Expand All @@ -3411,7 +3419,9 @@ STATIC elem * elvptrfptr(elem *e)
if (e1->Eoper == OPadd || e1->Eoper == OPmin)
{
e12 = e1->E2;
#if TARGET_SEGMENTED
if (tybasic(e12->Ety) != TYvptr)
#endif
{
/* Rewrite (vtof(e11 + e12)) to (vtof(e11) + e12) */
op = e->Eoper;
Expand Down
14 changes: 8 additions & 6 deletions src/backend/cgen.c
Expand Up @@ -535,19 +535,19 @@ void addtofixlist(symbol *s,targ_size_t soffset,int seg,targ_size_t val,int flag
ln->Lnext = *pv;
*pv = ln;

#if TARGET_FLAT
numbytes = tysize[TYnptr];
if (I64 && !(flags & CFoffset64))
numbytes = 4;
assert(!(flags & CFseg));
#else
#if TARGET_SEGMENTED
switch (flags & (CFoff | CFseg))
{
case CFoff: numbytes = tysize[TYnptr]; break;
case CFseg: numbytes = 2; break;
case CFoff | CFseg: numbytes = tysize[TYfptr]; break;
default: assert(0);
}
#else
numbytes = tysize[TYnptr];
if (I64 && !(flags & CFoffset64))
numbytes = 4;
assert(!(flags & CFseg));
#endif
#ifdef DEBUG
assert(numbytes <= sizeof(zeros));
Expand Down Expand Up @@ -629,12 +629,14 @@ STATIC int outfixlist_dg(void *parameter, void *pkey, void *pvalue)
symbol_debug(s);
//printf("outfixlist '%s' offset %04x\n",s->Sident,ln->Loffset);

#if TARGET_SEGMENTED
if (tybasic(s->ty()) == TYf16func)
{
obj_far16thunk(s); /* make it into a thunk */
searchfixlist(s);
}
else
#endif
{
if (s->Sxtrnnum == 0)
{ if (s->Sclass == SCstatic)
Expand Down
30 changes: 22 additions & 8 deletions src/backend/cgobj.c
Expand Up @@ -2971,8 +2971,14 @@ void objledata(int seg,targ_size_t offset,targ_size_t data,
{ unsigned i;
unsigned size; // number of bytes to output

#if TARGET_SEGMENTED
unsigned ptrsize = tysize[TYfptr];
#else
unsigned ptrsize = I64 ? 10 : 6;
#endif

if ((lcfd & LOCxx) == obj.LOCpointer)
size = tysize[TYfptr];
size = ptrsize;
else if ((lcfd & LOCxx) == LOCbase)
size = 2;
else
Expand Down Expand Up @@ -3016,7 +3022,7 @@ L1: ;
TOWORD(obj.ledata->data + i,data);
else
TOLONG(obj.ledata->data + i,data);
if (size == tysize[TYfptr]) // if doing a seg:offset pair
if (size == ptrsize) // if doing a seg:offset pair
TOWORD(obj.ledata->data + i + tysize[TYnptr],0); // segment portion
addfixup(offset - obj.ledata->offset,lcfd,idx1,idx2);
}
Expand All @@ -3038,19 +3044,23 @@ L1: ;

void obj_long(int seg,targ_size_t offset,unsigned long data,
unsigned lcfd,unsigned idx1,unsigned idx2)
{ unsigned i;

{
#if TARGET_SEGMENTED
unsigned sz = tysize[TYfptr];
#else
unsigned sz = I64 ? 10 : 6;
#endif
if (
(seg != obj.ledata->lseg || // or segments don't match
obj.ledata->i + tysize[TYfptr] > LEDATAMAX || // or it'll overflow
obj.ledata->i + sz > LEDATAMAX || // or it'll overflow
offset < obj.ledata->offset || // underflow
offset > obj.ledata->offset + obj.ledata->i
)
)
ledata_new(seg,offset);
i = offset - obj.ledata->offset;
if (obj.ledata->i < i + tysize[TYfptr])
obj.ledata->i = i + tysize[TYfptr];
unsigned i = offset - obj.ledata->offset;
if (obj.ledata->i < i + sz)
obj.ledata->i = i + sz;
TOLONG(obj.ledata->data + i,data);
if (I32) // if 6 byte far pointers
TOWORD(obj.ledata->data + i + LONGSIZE,0); // fill out seg
Expand Down Expand Up @@ -3239,7 +3249,11 @@ int reftoident(int seg,targ_size_t offset,Symbol *s,targ_size_t val,
break;
case CFoff | CFseg:
lc = obj.LOCpointer;
#if TARGET_SEGMENTED
numbytes = tysize[TYfptr];
#else
numbytes = I64 ? 10 : 6;
#endif
break;
}
break;
Expand Down

0 comments on commit 90c15b3

Please sign in to comment.