2000-05-09 01:01:16 +02:00
|
|
|
; File:
|
|
|
|
; intr.asm
|
|
|
|
; Description:
|
|
|
|
; Assembly implementation of calling an interrupt
|
|
|
|
;
|
|
|
|
; Copyright (c) 2000
|
|
|
|
; Steffen Kaiser
|
|
|
|
; All Rights Reserved
|
|
|
|
;
|
|
|
|
; This file is part of FreeDOS.
|
|
|
|
;
|
|
|
|
; FreeDOS 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,
|
2003-06-30 20:42:51 +02:00
|
|
|
; write to the Free Software Foundation, Inc.,
|
|
|
|
; 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
|
2000-05-09 01:01:16 +02:00
|
|
|
;
|
|
|
|
|
|
|
|
%include "segs.inc"
|
|
|
|
|
2003-06-30 20:42:51 +02:00
|
|
|
%macro INTR 0
|
|
|
|
|
2000-05-09 01:01:16 +02:00
|
|
|
push bp ; Standard C entry
|
|
|
|
mov bp,sp
|
|
|
|
push si
|
|
|
|
push di
|
2004-04-09 13:37:40 +02:00
|
|
|
%ifdef WATCOM
|
|
|
|
push bx
|
|
|
|
push cx
|
|
|
|
push dx
|
2000-05-09 01:01:16 +02:00
|
|
|
push es
|
2004-04-09 13:37:40 +02:00
|
|
|
%endif
|
|
|
|
push ds
|
2000-05-09 01:01:16 +02:00
|
|
|
|
2004-04-09 13:37:40 +02:00
|
|
|
mov ax, [bp+6] ; interrupt number
|
2003-06-30 20:42:51 +02:00
|
|
|
mov [cs:%%intr_1-1], al
|
|
|
|
jmp short %%intr_2 ; flush the instruction cache
|
2004-04-09 13:37:40 +02:00
|
|
|
%%intr_2 mov bx, [bp+4] ; regpack structure
|
2003-06-30 20:42:51 +02:00
|
|
|
mov ax, [bx]
|
|
|
|
mov cx, [bx+4]
|
|
|
|
mov dx, [bx+6]
|
|
|
|
mov si, [bx+8]
|
|
|
|
mov di, [bx+10]
|
|
|
|
mov bp, [bx+12]
|
|
|
|
push word [bx+14] ; ds
|
|
|
|
mov es, [bx+16]
|
|
|
|
mov bx, [bx+2]
|
|
|
|
pop ds
|
|
|
|
int 0
|
|
|
|
%%intr_1:
|
2000-05-09 01:01:16 +02:00
|
|
|
|
2003-06-30 20:42:51 +02:00
|
|
|
pushf
|
|
|
|
push ds
|
|
|
|
push bx
|
|
|
|
mov bx, sp
|
2004-04-09 13:37:40 +02:00
|
|
|
mov ds, [ss:bx+6]
|
|
|
|
%ifdef WATCOM
|
|
|
|
mov bx, [ss:bx+24] ; address of REGPACK
|
|
|
|
%else
|
|
|
|
mov bx, [ss:bx+16] ; address of REGPACK
|
|
|
|
%endif
|
2003-06-30 20:42:51 +02:00
|
|
|
mov [bx], ax
|
|
|
|
pop word [bx+2]
|
|
|
|
mov [bx+4], cx
|
|
|
|
mov [bx+6], dx
|
|
|
|
mov [bx+8], si
|
|
|
|
mov [bx+10], di
|
|
|
|
mov [bx+12], bp
|
|
|
|
pop word [bx+14]
|
|
|
|
mov [bx+16], es
|
|
|
|
pop word [bx+22]
|
2000-05-09 01:01:16 +02:00
|
|
|
|
2003-06-30 20:42:51 +02:00
|
|
|
pop ds
|
2004-04-09 13:37:40 +02:00
|
|
|
%ifdef WATCOM
|
|
|
|
pop es
|
|
|
|
pop dx
|
|
|
|
pop cx
|
|
|
|
pop bx
|
|
|
|
%endif
|
2003-06-30 20:42:51 +02:00
|
|
|
pop di
|
|
|
|
pop si
|
|
|
|
pop bp
|
2004-04-09 13:37:40 +02:00
|
|
|
ret 4
|
2003-06-30 20:42:51 +02:00
|
|
|
%endmacro
|
2000-05-09 01:01:16 +02:00
|
|
|
|
2003-06-30 20:42:51 +02:00
|
|
|
segment HMA_TEXT
|
2000-05-09 01:01:16 +02:00
|
|
|
|
2004-04-09 13:37:40 +02:00
|
|
|
;; COUNT ASMPASCAL res_DosExec(COUNT mode, exec_blk * ep, BYTE * lp)
|
|
|
|
global RES_DOSEXEC
|
|
|
|
RES_DOSEXEC:
|
|
|
|
pop es ; ret address
|
|
|
|
pop dx ; filename
|
|
|
|
pop bx ; exec block
|
|
|
|
pop ax ; mode
|
|
|
|
push es ; ret address
|
2004-03-07 13:19:43 +01:00
|
|
|
mov ah, 4bh
|
2004-04-09 13:37:40 +02:00
|
|
|
push ds
|
|
|
|
pop es ; es = ds
|
2004-03-07 13:19:43 +01:00
|
|
|
int 21h
|
|
|
|
jc short no_exec_error
|
|
|
|
xor ax, ax
|
|
|
|
no_exec_error:
|
|
|
|
ret
|
|
|
|
|
2004-04-09 13:37:40 +02:00
|
|
|
;; UCOUNT ASMPASCAL res_read(int fd, void *buf, UCOUNT count);
|
|
|
|
global RES_READ
|
|
|
|
RES_READ:
|
|
|
|
pop ax ; ret address
|
|
|
|
pop cx ; count
|
|
|
|
pop dx ; buf
|
|
|
|
pop bx ; fd
|
|
|
|
push ax ; ret address
|
2004-03-07 13:19:43 +01:00
|
|
|
mov ah, 3fh
|
|
|
|
int 21h
|
|
|
|
jnc no_read_error
|
|
|
|
mov ax, -1
|
|
|
|
no_read_error:
|
|
|
|
ret
|
|
|
|
|
2001-03-21 03:56:26 +01:00
|
|
|
segment INIT_TEXT
|
|
|
|
;
|
|
|
|
; void init_call_intr(nr, rp)
|
|
|
|
; REG int nr
|
|
|
|
; REG struct REGPACK *rp
|
|
|
|
;
|
2004-04-09 13:37:40 +02:00
|
|
|
global INIT_CALL_INTR
|
|
|
|
INIT_CALL_INTR:
|
2003-06-30 20:42:51 +02:00
|
|
|
INTR
|
2001-03-21 03:56:26 +01:00
|
|
|
|
|
|
|
;
|
|
|
|
; int init_call_XMScall( (WORD FAR * driverAddress)(), WORD AX, WORD DX)
|
|
|
|
;
|
|
|
|
; this calls HIMEM.SYS
|
|
|
|
;
|
2004-04-09 15:13:06 +02:00
|
|
|
global INIT_CALL_XMSCALL
|
|
|
|
INIT_CALL_XMSCALL:
|
|
|
|
pop bx ; ret address
|
|
|
|
pop dx
|
|
|
|
pop ax
|
|
|
|
pop cx ; driver address
|
|
|
|
pop es
|
2001-03-21 03:56:26 +01:00
|
|
|
|
2004-04-09 15:13:06 +02:00
|
|
|
push cs ; ret address
|
|
|
|
push bx
|
|
|
|
push es ; driver address ("jmp es:cx")
|
|
|
|
push cx
|
|
|
|
retf
|
2001-03-21 03:56:26 +01:00
|
|
|
|
2001-04-15 05:21:50 +02:00
|
|
|
; void FAR *DetectXMSDriver(VOID)
|
2004-04-09 15:13:06 +02:00
|
|
|
global DETECTXMSDRIVER
|
|
|
|
DETECTXMSDRIVER:
|
2001-04-15 05:21:50 +02:00
|
|
|
mov ax, 4300h
|
|
|
|
int 2fh ; XMS installation check
|
|
|
|
|
|
|
|
cmp al, 80h
|
|
|
|
je detected
|
|
|
|
xor ax, ax
|
|
|
|
xor dx, dx
|
|
|
|
ret
|
|
|
|
|
|
|
|
detected:
|
|
|
|
push es
|
|
|
|
push bx
|
|
|
|
mov ax, 4310h ; XMS get driver address
|
|
|
|
int 2fh
|
|
|
|
|
|
|
|
mov ax, bx
|
|
|
|
mov dx, es
|
|
|
|
pop bx
|
|
|
|
pop es
|
|
|
|
ret
|
|
|
|
|
2004-04-09 13:37:40 +02:00
|
|
|
global KEYCHECK
|
|
|
|
KEYCHECK:
|
2001-04-15 05:21:50 +02:00
|
|
|
mov ah, 1
|
|
|
|
int 16h
|
|
|
|
ret
|
|
|
|
|
2001-04-22 00:32:53 +02:00
|
|
|
;; int open(const char *pathname, int flags);
|
2004-04-09 13:37:40 +02:00
|
|
|
global INIT_DOSOPEN
|
|
|
|
INIT_DOSOPEN:
|
|
|
|
;; init calling DOS through ints:
|
|
|
|
pop bx ; ret address
|
|
|
|
pop ax ; flags
|
|
|
|
pop dx ; pathname
|
|
|
|
push bx ; ret address
|
2001-04-15 05:21:50 +02:00
|
|
|
mov ah, 3dh
|
2004-04-09 13:37:40 +02:00
|
|
|
;; AX will have the file handle
|
2001-04-22 00:32:53 +02:00
|
|
|
|
2004-04-09 13:37:40 +02:00
|
|
|
common_int21:
|
|
|
|
int 21h
|
2001-04-22 00:32:53 +02:00
|
|
|
jnc common_no_error
|
|
|
|
common_error:
|
|
|
|
mov ax, -1
|
|
|
|
common_no_error:
|
2001-04-15 05:21:50 +02:00
|
|
|
ret
|
|
|
|
|
2001-04-22 00:32:53 +02:00
|
|
|
;; int close(int fd);
|
2004-04-09 13:37:40 +02:00
|
|
|
global CLOSE
|
|
|
|
CLOSE:
|
|
|
|
pop ax ; ret address
|
|
|
|
pop bx ; fd
|
|
|
|
push ax ; ret address
|
2001-04-15 05:21:50 +02:00
|
|
|
mov ah, 3eh
|
2004-04-09 13:37:40 +02:00
|
|
|
jmp short common_int21
|
2001-04-15 05:21:50 +02:00
|
|
|
|
2001-04-22 00:32:53 +02:00
|
|
|
;; UCOUNT read(int fd, void *buf, UCOUNT count);
|
2004-04-09 13:37:40 +02:00
|
|
|
global READ
|
|
|
|
READ:
|
|
|
|
pop ax ; ret address
|
|
|
|
pop cx ; count
|
|
|
|
pop dx ; buf
|
|
|
|
pop bx ; fd
|
|
|
|
push ax ; ret address
|
2001-04-15 05:21:50 +02:00
|
|
|
mov ah, 3fh
|
2004-04-09 13:37:40 +02:00
|
|
|
jmp short common_int21
|
2001-04-15 05:21:50 +02:00
|
|
|
|
2001-04-22 00:32:53 +02:00
|
|
|
;; int dup2(int oldfd, int newfd);
|
2004-04-09 13:37:40 +02:00
|
|
|
global DUP2
|
|
|
|
DUP2:
|
|
|
|
pop ax ; ret address
|
|
|
|
pop cx ; newfd
|
|
|
|
pop bx ; oldfd
|
|
|
|
push ax ; ret address
|
2001-04-22 00:32:53 +02:00
|
|
|
mov ah, 46h
|
2004-04-09 13:37:40 +02:00
|
|
|
jmp short common_int21
|
2001-04-22 00:32:53 +02:00
|
|
|
|
2001-06-03 16:16:18 +02:00
|
|
|
;; VOID init_PSPSet(seg psp_seg)
|
2004-04-09 13:37:40 +02:00
|
|
|
global INIT_PSPSET
|
|
|
|
INIT_PSPSET:
|
|
|
|
pop ax ; ret address
|
|
|
|
pop bx ; psp_seg
|
|
|
|
push ax ; ret_address
|
2001-06-03 16:16:18 +02:00
|
|
|
mov ah, 50h
|
2004-04-09 13:37:40 +02:00
|
|
|
int 21h
|
|
|
|
ret
|
2001-06-03 16:16:18 +02:00
|
|
|
|
2001-04-22 00:32:53 +02:00
|
|
|
;; COUNT init_DosExec(COUNT mode, exec_blk * ep, BYTE * lp)
|
2004-04-09 13:37:40 +02:00
|
|
|
global INIT_DOSEXEC
|
|
|
|
INIT_DOSEXEC:
|
|
|
|
pop es ; ret address
|
|
|
|
pop dx ; filename
|
|
|
|
pop bx ; exec block
|
|
|
|
pop ax ; mode
|
|
|
|
push es ; ret address
|
2001-04-22 00:32:53 +02:00
|
|
|
mov ah, 4bh
|
2004-04-09 13:37:40 +02:00
|
|
|
push ds
|
|
|
|
pop es ; es = ds
|
2001-04-22 00:32:53 +02:00
|
|
|
int 21h
|
|
|
|
jc short exec_no_error
|
|
|
|
xor ax, ax
|
2003-06-30 20:42:51 +02:00
|
|
|
exec_no_error:
|
2001-04-22 00:32:53 +02:00
|
|
|
ret
|
|
|
|
|
2003-06-15 17:53:58 +02:00
|
|
|
;; int init_setdrive(int drive)
|
2004-04-09 13:37:40 +02:00
|
|
|
global INIT_SETDRIVE
|
|
|
|
INIT_SETDRIVE:
|
2003-06-15 17:53:58 +02:00
|
|
|
mov ah, 0x0e
|
2003-06-30 20:42:51 +02:00
|
|
|
common_dl_int21:
|
2004-04-09 13:37:40 +02:00
|
|
|
pop bx ; ret address
|
|
|
|
pop dx ; drive/char
|
|
|
|
push bx
|
|
|
|
int 21h
|
|
|
|
ret
|
2003-06-15 17:53:58 +02:00
|
|
|
|
|
|
|
;; int init_switchar(int char)
|
2004-04-09 13:37:40 +02:00
|
|
|
global INIT_SWITCHAR
|
|
|
|
INIT_SWITCHAR:
|
2003-06-15 17:53:58 +02:00
|
|
|
mov ax, 0x3701
|
2003-06-30 20:42:51 +02:00
|
|
|
jmp short common_dl_int21
|
2003-06-15 17:53:58 +02:00
|
|
|
|
2001-04-22 00:32:53 +02:00
|
|
|
;; int allocmem(UWORD size, seg *segp)
|
2004-04-09 13:37:40 +02:00
|
|
|
global ALLOCMEM
|
|
|
|
ALLOCMEM:
|
|
|
|
pop ax ; ret address
|
|
|
|
pop dx ; segp
|
|
|
|
pop bx ; size
|
|
|
|
push ax ; ret address
|
2001-04-22 00:32:53 +02:00
|
|
|
mov ah, 48h
|
|
|
|
int 21h
|
|
|
|
jc short common_error
|
2004-04-09 13:37:40 +02:00
|
|
|
mov bx, dx ; segp
|
2001-04-22 00:32:53 +02:00
|
|
|
mov [bx], ax
|
|
|
|
xor ax, ax
|
|
|
|
ret
|
2001-04-29 19:34:41 +02:00
|
|
|
|
2003-06-15 17:53:58 +02:00
|
|
|
;; void set_DTA(void far *dta)
|
2004-04-09 13:37:40 +02:00
|
|
|
global SET_DTA
|
|
|
|
SET_DTA:
|
|
|
|
pop ax ; ret address
|
|
|
|
pop bx ; seg(dta)
|
|
|
|
pop dx ; off(dta)
|
|
|
|
push ax ; ret address
|
|
|
|
mov ah, 1ah
|
|
|
|
push ds
|
|
|
|
mov ds, bx
|
|
|
|
int 21h
|
|
|
|
pop ds
|
|
|
|
ret
|