[comp.os.minix] Compiling with Turbo C 2.0 fsck1.asm

mullen@sdsu.UUCP (Deborah Mullen) (04/10/89)

I left out fsck1.asm in the package of stuff for building Minix
with Turbo C 2.0. Here it is.
Deborah Mullen
---------

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;
;		Fsck1.asm
;
; This is the first file that must be linked with fsck.obj in 
; creating the fsck model for the Minix operating system
;
; Modified for TURBO C from fsck1.s by Deborah Mullen 2/89
;
;

INCLUDE model.h


STACKSIZE = 8192
JMPI = 0EAh		 ; opcode for jp inter-segment ( far jmp)

GLOBAL $main:NEAR, _main:NEAR, _exit:NEAR,  _putc:NEAR
GLOBAL _getc:NEAR, _reset_diskette:NEAR, _diskio:NEAR
GLOBAL csv:NEAR, cret:NEAR, begtext:NEAR, begdata:BYTE
GLOBAL _cylsiz:WORD, _tracksiz:WORD, _drive:WORD
GLOBAL enddata:BYTE, _end:BYTE, _brksize:WORD, endbss:BYTE, begbss:BYTE

;+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
;                      Data Segment
;+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
SEGMENT _DATA

begdata:
tmp:	DW 0
tmp1:	DW 0
tmp2:	DW 0
_brksize DW offset DGROUP:endbss

ENDS _DATA


;+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
;                      Bss Segment
;+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
SEGMENT _BSS

begbss:
kerstack:	DB STACKSIZE dup(?)	; kernel stack


ENDS	_BSS

SEGMENT _BSSEND

endbss:
_end:

ENDS	_BSSEND

;+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
;                      Code Segment
;+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
SEGMENT _TEXT
ASSUME CS:_TEXT, DS:DGROUP

$main:
begtext:
start:

IFDEF _SID
	mov	ax, DGROUP	; For dos2out, force relocation
ENDIF

	mov	dx,bx		; bootblok puts # sectors/track in bx
	xor	ax,ax
	mov	bx,OFFSET begbss; prepare to clear bss
	mov	cx,OFFSET endbss
	sub	cx,bx
	sar	cx,1
st1:
	mov	[bx],ax		; clear bss
	add	bx,2
	loop	st1
	mov	[_tracksiz],dx	; dx (was bx) is # sectors/track
	add	dx,dx
	mov	[_cylsiz],dx	; # sectors/cylinder
	mov	sp, OFFSET kerstack+STACKSIZE
	call	_main

	mov	bx,ax		; put scan code for '=' in bx
	cli
	mov	dx,60h
	mov	ds,dx
	mov	es,dx
	mov	ss,dx
	DB JMPI			; far jump
	DW 0 		         ; use trick and precode instructions
	DW 60h
;	jmpi	0, 60h        ; jmp to kernel

_exit:	mov	bx,[_tracksiz]
	jmp	start


_putc:
	xor	ax,ax
	call	csv
	mov	al,[bp+4]	; al contains char to be printed
	mov	ah,14		; 14 = print char
	mov	bl,1		; foreground color
	push	bp		; not preserved
	int	10h		; call BIOS VIDEO_IO
	pop	bp
	jmp	cret

_getc:
	xor	ah,ah
	int	16h
	ret

_reset_diskette:
	xor	ax,ax
	call	csv
	push	es		; not preserved
	int	13h		; call BIOS DISKETTE_IO
	pop	es
	jmp	cret


; handle diskio(RW, sector_number, buffer, sector_count) call
; Do not issue a BIOS call that crosses a track boundary
_diskio:
	xor	ax,ax
	call	csv
	mov	[WORD PTR tmp1],0 	; tmp1 = # sectors actually transferred
	mov	di,[bp+10]	; di = # sectors to transfer
	mov	[WORD PTR tmp2],di	; di = # sectors to transfer
d0:	mov	ax,[bp+6]	; ax = sector number to start at
	xor	dx,dx		; dx:ax is dividend
	div	[_cylsiz]	; ax = cylinder, dx = sector within cylinder
	mov	cl,ah		; cl = hi-order bits of cylinder
	ror	cl,1		; BIOS expects hi bits in a funny place
	ror	cl,1		; ditto
	mov	ch,al		; cx = sector # in BIOS format
	mov	ax,dx		; ax = sector offset within cylinder
	xor	dx,dx		; dx:ax is dividend
	div	[_tracksiz]	; ax = head, dx = sector
	mov	dh,al		; dh = head
	or	cl,dl		; cl = 2 high-order cyl bits ;; sector
	inc	cl		; BIOS counts sectors starting at 1
	mov	dl,[BYTE PTR _drive]	; dl = drive code (0-3 or 0x80 - 0x81)
	mov	bx,[bp + 8]	; bx = address of buffer
	mov	al,cl		; al = sector #
	add	al,[bp + 10]	; compute last sector
	dec	al		; al = last sector to transfer
	cmp	al,[BYTE PTR _tracksiz]	; see if last sector is on next track
	jle	d1		; jump if last sector is on this track
	mov	[WORD PTR bp+10],1	; transfer 1 sector at a time
d1:	mov	ah,[bp+4]	; ah = READING or WRITING
	add	ah,2		; BIOS codes are 2 and 3, not 0 and 1
	mov	al,[bp+10]	; al = # sectors to transfer
	mov	[WORD PTR tmp],ax 	; al is # sectors to read/write
	push	es		; BIOS ruins es
	int	13h		; issue BIOS call
	pop	es		; restore es
	cmp	ah,0		; ah != 0 means BIOS detected error
	jne	d2		; exit with error
	mov	ax,[WORD PTR tmp]	; fetch count of sectors transferred
	xor	ah,ah		; count is in ax
	add	[WORD PTR tmp1],ax 	; tmp1 accumulates sectors transferred
	mov	si,[WORD PTR tmp1]		; are we done yet?
	cmp	si,[WORD PTR tmp2]		; ditto
	je	d2		; jump if done
	inc	[WORD PTR bp + 6]; next time around, start 1 sector higher
	add	[WORD PTR bp+8],200h	; move up in buffer by 512 bytes
	jmp	d0
d2:	jmp	SHORT cret

csv:
	pop	bx
	push	bp
	mov	bp,sp
	push	di
	push	si
	sub	sp,ax
	jmp	bx

cret:
	lea	sp,[bp - 4]
	pop	si
	pop	di
	pop	bp
	ret


ENDS _TEXT

IFNDEF _SID           
SEGMENT _TEXTEND
ASSUME CS:_TEXT, DS:DGROUP

; This segment is only here to have this code at the
; end of the code segment for combined I & D.  It is never executed. 
; It forces the	linker to generate a relocation item, which dos2out 
; uses to determine the end of the text.  The way dos2out determines
; this is different for combined I & D and separate I & D.
;
	mov 	ax,DGROUP 

ENDS _TEXTEND

ENDIF


	END