From 9914760949bf9af073176c13f040140a4396e7a6 Mon Sep 17 00:00:00 2001 From: Bart Oldeman Date: Mon, 15 Sep 2003 10:53:09 +0000 Subject: [PATCH] driver .asm files optimizations (many from Arkady); remove obsolete rdatclk git-svn-id: https://svn.code.sf.net/p/freedos/svn/kernel/trunk@690 6ac86273-5f31-0410-b378-82cca8765d1b --- drivers/floppy.asm | 144 +++++++++++++++++++++----------------------- drivers/getvec.asm | 26 +++----- drivers/rdatclk.asm | 87 -------------------------- drivers/rdpcclk.asm | 10 +-- drivers/wrpcclk.asm | 9 ++- 5 files changed, 87 insertions(+), 189 deletions(-) delete mode 100644 drivers/rdatclk.asm diff --git a/drivers/floppy.asm b/drivers/floppy.asm index c1c6413..45747f8 100644 --- a/drivers/floppy.asm +++ b/drivers/floppy.asm @@ -45,16 +45,15 @@ global _fl_reset _fl_reset: - mov bx,sp - mov ah,0 ; BIOS reset disketter & fixed disk - mov dl,[bx+2] + pop ax ; return address + pop dx ; drive + push dx ; restore stack + push ax ; + mov ah,0 ; BIOS reset diskette & fixed disk int 13h - jc fl_rst1 ; cy==1 is error - mov ax,1 ; TRUE on success - ret - -fl_rst1: xor ax,ax ; FALSE on error + sbb ax,ax ; cy==1 is error + inc ax ; TRUE on success, FALSE on failure ret @@ -64,34 +63,30 @@ fl_rst1: xor ax,ax ; FALSE on error ; ; COUNT fl_diskchanged(WORD drive) ; -; returns 1 if disk has changed, 0 if not, 0xFF if error +; returns 1 if disk has changed, 0 if not, 0xFFFF if error ; global _fl_diskchanged _fl_diskchanged: - push bp ; C entry - mov bp,sp + pop ax ; return address + pop dx ; get the drive number + push dx ; restore stack + push ax ; - mov dl,[bp+4] ; get the drive number mov ah,16h ; read change status type int 13h - jc fl_dchanged1 ; cy==1 is error or disk has changed - xor ax,ax ; disk has not changed - pop bp ; C exit - ret + mov al,1 + jnc fl_dc_ret1 ; cy==1 is error or disk has changed -fl_dchanged1: cmp ah,6 - jne fl_dc_error - mov ax,1 - pop bp ; C exit - ret + cmp ah,6 ; ah=6: disk has changed + je fl_dc_ret + dec ax ; 0xFF on error -fl_dc_error: mov ax,0FFh ; 0xFF on error - pop bp ; C exit +fl_dc_ret1: dec ax +fl_dc_ret: cbw ret - ; ; Format Sectors ; @@ -140,37 +135,31 @@ fl_common: push bp ; C entry mov bp,sp - mov dl,[bp+4] ; get the drive (if or'ed 80h its - ; hard drive. - mov dh,[bp+6] ; get the head number - mov bx,[bp+8] ; cylinder number (lo only if hard) + mov cx,[bp+8] ; cylinder number (lo only if hard) mov al,1 ; this should be an error code - cmp bx,3ffh ; this code can't write above 3ff=1023 + cmp ch,3 ; this code can't write above 3ff=1023 ja fl_error - mov ch,bl ; low 8 bits of cyl number - - xor bl,bl ; extract bits 8+9 to cl - shr bx,1 - shr bx,1 - - - mov cl,[bp+0Ah] ; sector number - and cl,03fh ; mask to sector field bits 5-0 - or cl,bl ; or in bits 7-6 + xchg ch,cl ; ch=low 8 bits of cyl number + ror cl,1 ; extract bits 8+9 to cl + ror cl,1 + or cl,[bp+0Ah] ; or in the sector number (bits 0-5) mov al,[bp+0Ch] ; count to read/write les bx,[bp+0Eh] ; Load 32 bit buffer ptr + mov dl,[bp+4] ; get the drive (if or'ed 80h its + ; hard drive. + mov dh,[bp+6] ; get the head number + int 13h ; write sectors from mem es:bx - mov al,ah - jc fl_wr1 ; error, return error code - xor al,al ; Zero transfer count -fl_wr1: + sbb al,al ; carry: al=ff, else al=0 + and al,ah ; carry: error code, else 0 + ; (Zero transfer count) fl_error: - xor ah,ah ; force into < 255 count + mov ah,0 ; force into < 255 count pop bp ret @@ -187,21 +176,24 @@ _fl_lba_ReadWrite: push ds push si ; wasn't in kernel < KE2024Bo6!! - mov dl,[bp+4] ; get the drive (if or'ed 80h its + mov dl,[bp+4] ; get the drive (if ored 80h harddrive) mov ax,[bp+6] ; get the command lds si,[bp+8] ; get far dap pointer int 13h ; read from/write to drive - mov al,ah ; place any error code into al - - xor ah,ah ; zero out ah - pop si pop ds - + pop bp +ret_AH: + mov al,ah ; place any error code into al + mov ah,0 ; zero out ah ret +; +; void fl_readkey (void); +; + global _fl_readkey _fl_readkey: xor ah, ah int 16h @@ -209,50 +201,50 @@ _fl_readkey: xor ah, ah global _fl_setdisktype _fl_setdisktype: - push bp - mov bp, sp - mov dl,[bp+4] ; drive number - mov al,[bp+6] ; disk type + pop bx ; return address + pop dx ; drive number (dl) + pop ax ; disk type (al) + push ax ; restore stack + push dx + push bx mov ah,17h int 13h - mov al,ah - xor ah,ah - pop bp - ret + jmp short ret_AH +; +; COUNT fl_setmediatype (WORD drive, WORD tracks, WORD sectors); +; global _fl_setmediatype _fl_setmediatype: - push bp - mov bp, sp + pop ax ; return address + pop dx ; drive number + pop cx ; number of tracks + pop bx ; sectors/track + push bx ; restore stack + push cx + push dx + push ax push di - - mov dl,[bp+4] ; drive number - mov bx,[bp+6] ; number of tracks - dec bx ; should be highest track - mov ch,bl ; low 8 bits of cyl number + + dec cx ; should be highest track + xchg ch,cl ; low 8 bits of cyl number - xor bl,bl ; extract bits 8+9 to cl - shr bx,1 - shr bx,1 + ror cl,1 ; extract bits 8+9 to cl bit 6+7 + ror cl,1 - mov cl,[bp+8] ; sectors/track - and cl,03fh ; mask to sector field bits 5-0 or cl,bl ; or in bits 7-6 mov ah,18h int 13h - mov al,ah - mov ah,0 jc skipint1e - mov bx,es + push es xor dx,dx mov es,dx cli + pop word [es:0x1e*4+2] ; set int 0x1e table to es:di mov [es:0x1e*4 ], di - mov [es:0x1e*4+2], bx ; set int 0x1e table to es:di (bx:di) sti skipint1e: pop di - pop bp - ret + jmp short ret_AH diff --git a/drivers/getvec.asm b/drivers/getvec.asm index d53efc1..f7b6529 100644 --- a/drivers/getvec.asm +++ b/drivers/getvec.asm @@ -34,24 +34,14 @@ segment HMA_TEXT global _getvec _getvec: - mov bx,sp - mov ax,[ss:bx+2] - -; -; assembler version - ax = vector number -; returns vector in dx:ax -; - - global getvec -getvec: - shl ax,1 ; Multiply by 4 - shl ax,1 + pop ax ; return address + pop bx ; int # + push bx ; restore stack + push ax + add bx,bx + add bx,bx ; Multiply by 4 xor dx,dx ; and set segment to 0 mov es,dx - mov bx,ax - pushf ; Push flags - cli ; Disable interrupts - mov ax,[es:bx] - mov dx,[es:bx+2] - popf ; Pop flags + les ax,[es:bx] + mov dx,es ret diff --git a/drivers/rdatclk.asm b/drivers/rdatclk.asm deleted file mode 100644 index b5ca6a8..0000000 --- a/drivers/rdatclk.asm +++ /dev/null @@ -1,87 +0,0 @@ -; -; File: -; rdatclk.asm -; Description: -; read the AT style clock from bios -; -; Copyright (c) 1995 -; Pasquale J. Villani -; All Rights Reserved -; -; This file is part of DOS-C. -; -; DOS-C is free software; you can redistribute it and/or -; modify it under the terms of the GNU General Public License -; as published by the Free Software Foundation; either version -; 2, or (at your option) any later version. -; -; DOS-C is distributed in the hope that it will be useful, but -; WITHOUT ANY WARRANTY; without even the implied warranty of -; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See -; the GNU General Public License for more details. -; -; You should have received a copy of the GNU General Public -; License along with DOS-C; see the file COPYING. If not, -; write to the Free Software Foundation, 675 Mass Ave, -; Cambridge, MA 02139, USA. -; -; Logfile: C:/dos-c/src/drivers/rdatclk.asv -; -; $Header$ -; - - %include "../kernel/segs.inc" - -segment HMA_TEXT - -; -;COUNT ReadATClock(bcdDays, bcdHours, bcdMinutes, bcdSeconds) -;BYTE *bcdDays; -;BYTE *bcdHours; -;BYTE *bcdMinutes; -;BYTE *bcdSeconds; -; - global _ReadATClock -_ReadATClock: - push bp - mov bp, sp - xor cx, cx ; cx=dx=0 check if present - xor dx, dx ; if it returns non-zero - clc ; necessary according to RBIL - mov ah,4 - int 1ah - jc @RdATerror - - or cx, cx - jnz @RdAT1140 - or dx, dx - jnz @RdAT1140 -@RdATerror: mov ax, 1 - pop bp - ret -@RdAT1140: - clc - mov ah, 2 - int 1ah - jc @RdATerror -; bcdSeconds = 10 -; bcdMinutes = 8 -; bcdHours = 6 -; bcdDays = 4 - mov bx,word [bp+6] ;bcdHours - mov byte [bx],ch ;Hours - mov bx,word [bp+8] ;bcdMinutes - mov byte [bx],cl ;Minutes - mov bx,word [bp+10] ;bcdSeconds - mov byte [bx],dh ;Seconds - clc - mov ah,4 - int 1ah - jc @RdATerror - mov bx,word [bp+4] ;bcdDays - mov word [bx],dx ;Days - mov word [bx+2],cx - sub ax,ax - pop bp - ret - diff --git a/drivers/rdpcclk.asm b/drivers/rdpcclk.asm index 11e01b9..cc51fe7 100644 --- a/drivers/rdpcclk.asm +++ b/drivers/rdpcclk.asm @@ -38,17 +38,17 @@ segment HMA_TEXT ; global _ReadPCClock _ReadPCClock: - xor ah,ah + mov ah,0 int 1ah extern _DaysSinceEpoch ; ; update days if necessary - mov ah,0 - + ; (ah is still 0, al contains midnight flag) add word [_DaysSinceEpoch ],ax ; *some* BIOS's accumulate several days adc word [_DaysSinceEpoch+2],0 ; - mov ax,dx ; set return value - mov dx,cx + ; set return value dx:ax + xchg ax,cx ; ax=_cx, cx=_ax + xchg ax,dx ; dx=_cx, ax=_dx (cx=_ax) ret diff --git a/drivers/wrpcclk.asm b/drivers/wrpcclk.asm index 135be0c..7c14456 100644 --- a/drivers/wrpcclk.asm +++ b/drivers/wrpcclk.asm @@ -38,10 +38,13 @@ segment HMA_TEXT ; global _WritePCClock _WritePCClock: - mov bx,sp ; Ticks = 4 - mov cx,word [ss:bx+4] - mov dx,word [ss:bx+2] ;Ticks + pop ax ; return address + pop dx + pop cx ; Ticks + push cx ; restore stack + push dx + push ax mov ah,1 int 1ah ret