📄 io.asm
字号:
;; File:; io.asm; Description:; DOS-C I/O Subsystem;; Copyright (c) 1998; 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.;; $Header: /cvsroot/freedos/kernel/kernel/io.asm,v 1.17 2004/05/30 19:31:07 bartoldeman Exp $; %include "segs.inc" %include "stacks.inc" extern ConTable:wrt LGROUP extern LptTable:wrt LGROUP extern ComTable:wrt LGROUP extern uPrtNo:wrt LGROUP extern CommonNdRdExit:wrt LGROUP;!! extern _NumFloppies:wrt DGROUP extern blk_stk_top:wrt DGROUP extern clk_stk_top:wrt DGROUP extern _reloc_call_blk_driver extern _reloc_call_clk_driver extern _TEXT_DGROUP:wrt LGROUP ;---------------------------------------------------;; Device entry points;; This really should be a struct and go into a request.inc file;cmdlen equ 0 ; Length of this commandunit equ 1 ; Subunit Specifiedcmd equ 2 ; Command Codestatus equ 3 ; Statusmedia equ 13 ; Media Descriptortrans equ 14 ; Transfer Addresscount equ 18 ; Count of blocks or charactersstart equ 20 ; First block to transfervid equ 22 ; Volume id pointerhuge equ 26 ; First block (32-bit) to transfer;; The following is the "array" of device driver headers for the internal; devices. There is one header per device including special aux: and prn: ; pseudo devices. These psuedo devices are necessary for printer ; redirection, i.e., serial or parallel ports, and com port aux selection.;; The devices are linked into each other and terminate with a -1 next ; pointer. This saves some time on boot up and also allows us to throw all; device initialization into a single io_init function that may be placed ; into a discardable code segmemnt.;segment _IO_FIXED_DATA ; ; The "CON" device ; ; This device is the standard console device used by ; DOS-C and kernel ; global _con_dev_con_dev equ $ dw _prn_dev,LGROUP dw 8013h ; con device (stdin & stdout) dw GenStrategy dw ConIntr db 'CON ' ; ; Generic prn device that can be redirected via mode ; global _prn_dev_prn_dev dw _aux_dev,LGROUP dw 0A040h dw GenStrategy dw PrnIntr db 'PRN ' ; ; Generic aux device that can be redirected via mode ; global _aux_dev_aux_dev dw _Lpt1Dev,LGROUP dw 8000h dw GenStrategy dw AuxIntr db 'AUX ' ; ; Printer device drivers ;_Lpt1Dev dw _Lpt2Dev,LGROUP dw 0A040h dw GenStrategy dw Lpt1Intr db 'LPT1 '_Lpt2Dev dw _Lpt3Dev,LGROUP dw 0A040h dw GenStrategy dw Lpt2Intr db 'LPT2 '_Lpt3Dev dw _Com1Dev,LGROUP dw 0A040h dw GenStrategy dw Lpt3Intr db 'LPT3 ' ; ; Com device drivers ;_Com1Dev dw _Com2Dev,LGROUP dw 8000h dw GenStrategy dw AuxIntr db 'COM1 '_Com2Dev dw _Com3Dev,LGROUP dw 8000h dw GenStrategy dw Com2Intr db 'COM2 '_Com3Dev dw _Com4Dev,LGROUP dw 8000h dw GenStrategy dw Com3Intr db 'COM3 '_Com4Dev dw _clk_dev,LGROUP dw 8000h dw GenStrategy dw Com4Intr db 'COM4 ' ; ; Header for clock device ; global _clk_dev_clk_dev equ $ dw _blk_dev,LGROUP dw 8008h ; clock device dw GenStrategy dw clk_entry db 'CLOCK$ ' ; ; Header for device ; global _blk_dev_blk_dev equ $ dd -1 dw 08c2h ; block device with ioctl dw GenStrategy dw blk_entry db 4 db 0,0,0,0,0,0,0;; Temporary table until next release;segment _IO_FIXED_DATADiskTable db 0;; Local storage;%if 0segment _BSSblk_dos_stk resw 1blk_dos_seg resw 1clk_dos_stk resw 1clk_dos_seg resw 1%endifsegment _IO_TEXT global _ReqPktPtr_ReqPktPtr dd 0uUnitNumber dw 0;; Name:; GenStrategy;; Function:; Store the pointer to the request packet passed in es:bx;; Description:; Generic strategy routine. Unlike the original multitasking versions, ; this version assumes that no more thank one device driver is active; at any time. The request is stored into memory in the one and only; location available for that purpose.;GenStrategy: mov word [cs:_ReqPktPtr],bx mov word [cs:_ReqPktPtr+2],es retf;; Name:; XXXXIntr;; Function:; Individual Interrupt routines for each device driver;; Description:; This is actually a single routine with entry points for each device. ; The name used for the entry point is the device name with Intr ; appended to it.;; Funtionally, each device driver has an entry and an associated ; table. The table is a structure that consists of a control byte ; followed by an array of pointers to C functions or assembly ; subroutines that implement the individual device driver functions. ; This allows the usage of common error dummy filler code to be used. ; It also allows standardization of the calling procedure for these ; internal device driver functions.;; Assembler call/return convention:; Each driver function is entered by a jump into the function and ; exits by a jump to the appropriate success or error exit routine. ; This speeds up the call and return and helps to minimize the stack ; useage. The contents of the request packet are passed to each ; routine in registers as follows:;; Register Function Description; -------- -------- -----------; al unit Subunit Specified; ah media Media Descriptor; cx count Count of blocks or characters; dx start First block to transfer; es:di trans Transfer Address; ds:bx reqptr Request pointer; cs kernel code segment; ds kernel data segment;; The exit routines generally set the status based on the individual ; routine. For example, _IOSuccess will clear the count where ; _IOErrCnt will subtract the remaining amount in cx from the original ; count. See each utility routine for expectations.;; C call/return convention:; The C calling convention simply sets up the C stack and passes the; request packet pointer as a far pointer to the function. Although ; the utility routine names are such that they are accesible from the ; C name space, they are cannot used. Instead, the common interrupt ; code expects a return status to set in the request packet. It is up ; to the device driver function to set the appropriate fields such as ; count when an error occurs.;; How to differntiate between the two calling conventions:; This code is entirely table driven. The table is a structure that ; is generally in the _IO_FIXED_DATA segment. It consists of a flag ; byte followed by short pointers to the driver functions. Selecting ; a driver type is accomplished by setting the type bit in the flag ; (see below).;; 7 6 5 4 3 2 1 0; +---+---+---+---+---+---+---+---+; | | | | | | | | |; +---+---+---+---+---+---+---+---+; | | | |--- Number of table entries; | | +-------------------+; | | |----------------------- Reserved; | +-------+; +--------------------------------- type bit (1 == C / 0 == asm);ConIntr: push si mov si,ConTable jmp short CharIntrEntryPrnIntr: push si push ax
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -