Index: trunk/XTIDE_Universal_BIOS/Inc/RamVars.inc
===================================================================
--- trunk/XTIDE_Universal_BIOS/Inc/RamVars.inc	(revision 524)
+++ trunk/XTIDE_Universal_BIOS/Inc/RamVars.inc	(revision 525)
@@ -37,10 +37,10 @@
 struc RAMVARS
 %ifdef RELOCATE_INT13H_STACK
-						resb	256	; Size of our stack
-	.rgbTopOfStack:
+						resb	252
+	.dwStackChangeDSDI:
+	.wStackChangeDI		resb	2	; Used during stack
+	.wStackChangeDS		resb	2	; switching only
+	.rgbTopOfStack:					; 256 bytes of stack
 	.fpInt13hEntryStack	resb	4
-	.dwStackChangeDSDI:
-	.wStackChangeDI		resb	2
-	.wStackChangeDS		resb	2
 %endif
 	.wDrvDetectSignature:			; Signature when BIOS is in drive detection mode
Index: trunk/XTIDE_Universal_BIOS/Src/Handlers/Int13h.asm
===================================================================
--- trunk/XTIDE_Universal_BIOS/Src/Handlers/Int13h.asm	(revision 524)
+++ trunk/XTIDE_Universal_BIOS/Src/Handlers/Int13h.asm	(revision 525)
@@ -37,19 +37,26 @@
 ALIGN JUMP_ALIGN
 Int13h_DiskFunctionsHandlerWithStackChange:
-	push	ds
+	sti			; Enable interrupts
+	; TODO: Maybe we need to save Flags (DF) as well?
+	push	ds	; Save DS:DI on the original stack
 	push	di
 	call	RamVars_GetSegmentToDS
 
 	; Store entry registers to RAMVARS
+%ifdef USE_386
+	pop		DWORD [RAMVARS.dwStackChangeDSDI]
+%else
+	pop		WORD [RAMVARS.wStackChangeDI]	; Pop DS:DI to the top of what
+	pop		WORD [RAMVARS.wStackChangeDS]	; is to become the new stack
+%endif
 	mov		[RAMVARS.fpInt13hEntryStack], sp
 	mov		[RAMVARS.fpInt13hEntryStack+2], ss
-	pop		WORD [RAMVARS.wStackChangeDI]
-	pop		WORD [RAMVARS.wStackChangeDS]
 
 	; Load new stack and restore DS and DI
-	mov		di, ds		; We do not want to overwrite DS and DI in stack
-	mov		ss, di
-	mov		sp, RAMVARS.rgbTopOfStack
-	lds		di, [RAMVARS.dwStackChangeDSDI]
+	mov		di, ds		; We can save 2 bytes by using PUSH/POP but it's slower
+	mov		ss, di		; No need to wrap with CLI/STI since this is for AT only (286+)
+	mov		sp, RAMVARS.rgbTopOfStack-4
+	pop		di			; DI before stack change
+	pop		ds			; DS before stack change
 
 	; Call INT 13h
@@ -59,13 +66,12 @@
 
 	; Restore stack (we must not corrupt FLAGS!)
-	cli
 %ifdef USE_386
 	lss		sp, [ss:RAMVARS.fpInt13hEntryStack]
 %else
+	cli
 	mov		sp, [ss:RAMVARS.fpInt13hEntryStack]
 	mov		ss, [ss:RAMVARS.fpInt13hEntryStack+2]
-%endif
-	pop		di			; DI before stack change
-	pop		ds			; DS before stack change
+	sti
+%endif
 	retf	2			; Skip FLAGS from stack
 %endif ; RELOCATE_INT13H_STACK
@@ -88,5 +94,7 @@
 ALIGN JUMP_ALIGN
 Int13h_DiskFunctionsHandler:
+%ifndef RELOCATE_INT13H_STACK
 	sti									; Enable interrupts
+%endif
 	cld									; String instructions to increment pointers
 	CREATE_FRAME_INTPACK_TO_SSBP	SIZE_OF_IDEPACK_WITHOUT_INTPACK
@@ -398,5 +406,5 @@
 	dw	AH1Eh_HandlerForXTCFfeatures				; 1Eh, Lo-tech XT-CF features (XTIDE Universal BIOS)
 %else
-	dw	UnsupportedFunction							; 1Eh, 
+	dw	UnsupportedFunction							; 1Eh,
 %endif
 	dw	UnsupportedFunction							; 1Fh,
Index: trunk/XTIDE_Universal_BIOS/Src/Handlers/Int13h/AH1Eh_XTCF.asm
===================================================================
--- trunk/XTIDE_Universal_BIOS/Src/Handlers/Int13h/AH1Eh_XTCF.asm	(revision 524)
+++ trunk/XTIDE_Universal_BIOS/Src/Handlers/Int13h/AH1Eh_XTCF.asm	(revision 525)
@@ -112,15 +112,11 @@
 	jae		SHORT .SetMemoryMappedMode
 
-; We need to limit block size here. Consider this scenario;
-; 1. While in PIO mode or memory mapped mode, the drive is set to do
-;    block transfers larger than XTCF_DMA_MODE_MAX_BLOCK_SIZE.
-; 2. A call is subsequently made to change device mode to DEVICE_8BIT_XTCF_DMA.
-; 3. The call to AH24h_SetBlockSize fails but the change in device mode has been made.
-
 	; Set DMA Mode
 	mov		BYTE [di+DPT_ATA.bDevice], DEVICE_8BIT_XTCF_DMA
 	mov		al, [di+DPT_ATA.bBlockSize]
-	MIN_U	al, XTCF_DMA_MODE_MAX_BLOCK_SIZE
-	jmp		SHORT AH24h_SetBlockSize	; Returns via AH23h_Enable8bitPioMode
+	cmp		al, XTCF_DMA_MODE_MAX_BLOCK_SIZE
+	jbe		SHORT AH24h_SetBlockSize
+	mov		al, XTCF_DMA_MODE_MAX_BLOCK_SIZE
+	jmp		SHORT AH24h_SetBlockSize
 
 .SetMemoryMappedMode:
