[comp.unix.xenix] Lex

dave@sds.UUCP (04/16/87)

I just found a nasty problem with lex on Microsoft XENIX System V; 
everything works as it ought except in large model, where the input()
call will fail with the error ENOTTY (Not a typewriter).  Unfortunately,
no description of ENOTTY is to be found in the system manuals, so I don't
even know what that's supposed to mean.  Since I was reading from a text
file, the error seems particularly strange.

What's even worse about the matter is that I can't always duplicate
the problem -- if I write a simple lex program and compile it under
large model, it works fine.  I thought maybe some of my code was trashing
memory, but when I replaced their input() macro (which should be a 
function by the way) with my own input() function it worked.  The only
difference between their macro and my function was that I used fgetc(yyin)
rather than getc(yyin).

Has anyone seen or heard of anything similiar?

Dave Schmidt

(Currently not a member of the MicroSoft[-In-The-Head] fan club).

stuart@bms-at.UUCP (04/18/87)

Your problem was not with Lex, Xenix has numerous bugs with large model
compiles.  For some programs, the only solution is to hand patch the assembly
after every compile!  Needless to say, I avoid large model like the plague.
As an example, here is a trivial program which will not run in large model:

The program runs correctly when compiled using
the small model.  It bombs using the huge model whether optomized or not. 
To see it fail, extract bug.c, bug.s(optimized), bug.s.u(unoptimized);

	cc -M2h bug.c
	a.out		# see it run (no buffering)
	a.out>temp	# see it bomb
	cc -M2 bug.c
	a.out>temp	# see it run (small model)

Our kernel version:	release=2.1.3
Our development system:	release 2.1

-------------CUT HERE----<bug.c>-------------
#include <stdio.h>

char buf[] = "This is a test\n";

main()
{
  register int rcnt, cnt;	/* use both si & di */
  register char *bp;
  rcnt = 0;
  bp = buf;
  cnt = sizeof buf - 1;
  do
    putchar(*bp++);		/* use macro, not function */
  while (--cnt);
  return rcnt;			/* tie up register */
}
-------------CUT HERE-----<bug.s>---------------
;	Static Name Aliases
;
	TITLE   bug

BUG_TEXT	SEGMENT  BYTE PUBLIC 'CODE'
BUG_TEXT	ENDS
_DATA	SEGMENT  WORD PUBLIC 'DATA'
_DATA	ENDS
CONST	SEGMENT  WORD PUBLIC 'CONST'
CONST	ENDS
_BSS	SEGMENT  WORD PUBLIC 'BSS'
_BSS	ENDS
DGROUP	GROUP	CONST,	_BSS,	_DATA
	ASSUME  CS: BUG_TEXT, DS: DGROUP, SS: DGROUP, ES: DGROUP
PUBLIC  _buf
EXTRN	__chkstk:FAR
EXTRN	__AHSHIFT:FAR
EXTRN	__flsbuf:FAR
_DATA	SEGMENT
EXTRN	__iob:BYTE
_DATA	ENDS
_DATA      SEGMENT
	PUBLIC	_buf
_buf	DB	'This is a test',  0aH,  00H
_DATA      ENDS
BUG_TEXT      SEGMENT
; Line 6
	PUBLIC	_main
_main	PROC FAR
	push	bp
	mov	bp,sp
	mov	ax,14
	call	FAR PTR __chkstk
	push	di
	push	si
;	bp = -4
;	register di = cnt
;	register si = rcnt
; Line 9
	sub	si,si
; Line 10
	mov	ax,OFFSET DGROUP:_buf
	mov	[bp-4],ax	;bp
	mov	[bp-2],ds
; Line 11
	mov	di,15
; Line 12
$D35:
; Line 13
	mov	ax,16
	cwd	
	add	ax,OFFSET __iob
	adc	dx,0
	mov	cl,OFFSET __AHSHIFT
	shl	dx,cl
	add	dx,SEG __iob
	mov	es,dx
	mov	bx,ax
	dec	WORD PTR es:[bx]
	cmp	WORD PTR es:[bx],0
	jl	$L20001
	mov	ax,1
	cwd	
	add	ax,[bp-4]	;bp
	adc	dx,0
	shl	dx,cl
	add	dx,[bp-2]
	les	bx,[bp-4]	;bp
	mov	[bp-4],ax	;bp
	mov	[bp-2],dx
	mov	al,es:[bx]
	mov	cx,ax
	mov	ax,12
	cwd	
	mov	bx,cx
	add	ax,OFFSET __iob
	adc	dx,0
	mov	cl,OFFSET __AHSHIFT
	shl	dx,cl
	add	dx,SEG __iob
	mov	cx,bx
	mov	es,dx
	mov	bx,ax
	mov	ax,1
	cwd	
	mov	[bp-10],cx
	lea	cx,[bx]
	mov	[bp-14],cx
	mov	[bp-12],bx	; %%%%% bx not segment !
	mov	es,bx
	mov	bx,cx
	add	ax,es:[bx]
	adc	dx,0
	mov	cl,OFFSET __AHSHIFT
	shl	dx,cl
	add	dx,es:[bx+2]
	mov	cx,es:[bx]
	mov	es:[bx],ax
	mov	ax,cx
	mov	cx,es:[bx+2]
	mov	es:[bx+2],dx
	mov	dx,cx
	mov	es,dx
	mov	bx,ax
	mov	al,[bp-10]
	mov	es:[bx],al
	sub	ah,ah
	jmp	SHORT $L20002
$L20001:
	mov	ax,12
	cwd	
	add	ax,OFFSET __iob
	adc	dx,0
	mov	cl,OFFSET __AHSHIFT
	shl	dx,cl
	add	dx,SEG __iob
	push	dx
	push	ax
	mov	ax,1
	cwd	
	add	ax,[bp-4]	;bp
	adc	dx,0
	shl	dx,cl
	add	dx,[bp-2]
	les	bx,[bp-4]	;bp
	mov	[bp-4],ax	;bp
	mov	[bp-2],dx
	mov	al,es:[bx]
	cbw	
	push	ax
	call	FAR PTR __flsbuf
	add	sp,6
$L20002:
; Line 14
	dec	di
	je	$+5
	jmp	$D35
; Line 15
	mov	ax,si
	pop	si
	pop	di
	leave	
	ret	
_main	ENDP

BUG_TEXT	ENDS
END
----------CUT HERE--------<bug.s.u>---------
;	Static Name Aliases
;
	TITLE   bug

BUG_TEXT	SEGMENT  BYTE PUBLIC 'CODE'
BUG_TEXT	ENDS
_DATA	SEGMENT  WORD PUBLIC 'DATA'
_DATA	ENDS
CONST	SEGMENT  WORD PUBLIC 'CONST'
CONST	ENDS
_BSS	SEGMENT  WORD PUBLIC 'BSS'
_BSS	ENDS
DGROUP	GROUP	CONST,	_BSS,	_DATA
	ASSUME  CS: BUG_TEXT, DS: DGROUP, SS: DGROUP, ES: DGROUP
PUBLIC  _buf
EXTRN	__chkstk:FAR
EXTRN	__AHSHIFT:FAR
EXTRN	__flsbuf:FAR
_DATA	SEGMENT
EXTRN	__iob:BYTE
_DATA	ENDS
_DATA      SEGMENT
	PUBLIC	_buf
_buf	DB	'This is a test',  0aH,  00H
_DATA      ENDS
BUG_TEXT      SEGMENT
; Line 6
	PUBLIC	_main
_main	PROC FAR
	push	bp
	mov	bp,sp
	mov	ax,14
	call	FAR PTR __chkstk
	push	di
	push	si
;	bp = -4
;	register di = cnt
;	register si = rcnt
; Line 7
; Line 8
; Line 9
	mov	si,0
; Line 10
	mov	ax,OFFSET DGROUP:_buf
	mov	[bp-4],ax	;bp
	mov	[bp-2],ds
; Line 11
	mov	di,15
; Line 12
$D35:
; Line 13
	mov	ax,16
	mov	dx,0
	add	ax,OFFSET __iob
	adc	dx,0
	mov	cl,OFFSET __AHSHIFT
	shl	dx,cl
	add	dx,SEG __iob
	mov	es,dx
	mov	bx,ax
	dec	WORD PTR es:[bx]
	cmp	WORD PTR es:[bx],0
	jge	$+5
	jmp	$L20001
	mov	ax,1
	mov	dx,0
	add	ax,[bp-4]	;bp
	adc	dx,0
	mov	cl,OFFSET __AHSHIFT
	shl	dx,cl
	add	dx,[bp-2]
	les	bx,[bp-4]	;bp
	mov	[bp-4],ax	;bp
	mov	[bp-2],dx
	mov	al,es:[bx]
	mov	cx,ax
	mov	ax,12
	mov	dx,0
	mov	bx,cx
	add	ax,OFFSET __iob
	adc	dx,0
	mov	cl,OFFSET __AHSHIFT
	shl	dx,cl
	add	dx,SEG __iob
	mov	cx,bx
	mov	es,dx
	mov	bx,ax
	mov	ax,1
	mov	dx,0
	mov	[bp-10],cx
	lea	cx,[bx]
	mov	[bp-14],cx
	mov	[bp-12],bx	; %%%%% bx not segment !
	mov	es,[bp-12]
	mov	bx,[bp-14]
	add	ax,es:[bx]
	adc	dx,0
	mov	cl,OFFSET __AHSHIFT
	shl	dx,cl
	add	dx,es:[bx+2]
	mov	cx,es:[bx]
	mov	es:[bx],ax
	mov	ax,cx
	mov	cx,es:[bx+2]
	mov	es:[bx+2],dx
	mov	dx,cx
	mov	es,dx
	mov	bx,ax
	mov	al,[bp-10]
	mov	es:[bx],al
	sub	ah,ah
	jmp	$L20002
$L20001:
	mov	ax,12
	mov	dx,0
	add	ax,OFFSET __iob
	adc	dx,0
	mov	cl,OFFSET __AHSHIFT
	shl	dx,cl
	add	dx,SEG __iob
	push	dx
	push	ax
	mov	ax,1
	mov	dx,0
	add	ax,[bp-4]	;bp
	adc	dx,0
	mov	cl,OFFSET __AHSHIFT
	shl	dx,cl
	add	dx,[bp-2]
	les	bx,[bp-4]	;bp
	mov	[bp-4],ax	;bp
	mov	[bp-2],dx
	mov	al,es:[bx]
	cbw	
	push	ax
	call	FAR PTR __flsbuf
	add	sp,6
$L20002:
; Line 14
$DC36:
	dec	di
	je	$+5
	jmp	$D35
$DB37:
; Line 15
	mov	ax,si
	jmp	$EX31
; Line 16
$EX31:
	pop	si
	pop	di
	leave	
	ret	
_main	ENDP

BUG_TEXT	ENDS
END
-- 
Stuart D. Gathman	<..!seismo!dgis!bms-at!stuart>