尝试运行FASM程序时DOS分配错误

时间:2019-06-30 12:58:43

标签: assembly dos x86-16 osdev fasm

我对某些代码有疑问。这是我自己的操作系统的一部分,我想在将来构建并在SourceForge上共享。我有两个程序集文件:

  1. gdos.asm,内核。还有...
  2. vga.asm,我自己的VGA驱动程序。

在DOSBox中一切正常。
但是当我在外部驱动器上的普通MS-DOS上运行它时,会导致此错误:

  

内存分配错误:
  加载COMMAND.COM失败。系统停止

此问题可能与代码有关,在代码中我通过调整大小来为程序分配额外的内存。完整的源代码是:

第一个文件:GDOS.ASM

format MZ
stack 4096
entry GDOS_MAINSEG:GDOS_KERNEL_START

segment GDOS_MAINSEG
        GDOS_KERNEL_START: ; Punkt startowy jĄdra / Kernel start point
                        push cs
                        pop ds

                        push cs
                        pop es

                        mov ax,GDOS_KERNEL_END ;Autoalokacja do konkretnego rozmiaru / Autoallocation for concrete size
                        shr ax,4
                        inc ax
                        init: ;Inicjujemy GDOS
                        mov bx,ax
                        mov ah,0x4a
                        int 0x21

                        mov dx,DrvString0
                        call far GDOS_MAINSEG:gdosLoadDriverDOS

                        call far GDOS_MAINSEG:gdosSetModeByID


                        mov ax,0x4c00
                        int 0x21

                        GDOS_KERNEL_DATA:
                                DrvString0 : db 'VGA.BIN',0 ;Nazwa pliku dla sterownika VGA / Filename for VGA driver

                                GraphicsDriver: dw 0x0

                                g3:
                                dw 0,0
                                dw 0,0

                                DriverDeletionBuffer: TIMES 16 db 0
                                RecommendedDriverPosition: db 0

                        GDOS_KERNEL_FUNC:
                                gdosLoadDriverDOS: ;Funkcja adujĄca sterownik za pomocĄ DOS-a / Function loading driver with DOS
                                        push ds
                                        push es
                                        mov ax,0x3d00
                                        mov cl,0x0
                                        int 0x21
                                        jc end_gdosLoadDriverDOS
                                        mov si,ax ;Zapisz uchwyt / Save handle
                                        mov ah,0x48
                                        mov bx,1
                                        int 0x21
                                        jc end_gdosLoadDriverDOS
                                        mov es,ax
                                        mov ds,ax
                                        mov ah,0x3f
                                        mov cx,16
                                        mov bx,si
                                        mov dx,0
                                        int 0x21
                                        jc end_gdosLoadDriverDOS
                                        mov ah,0x42
                                        mov al,0x00
                                        mov cx,0
                                        mov dx,0
                                        int 0x21
                                        jc end_gdosLoadDriverDOS
                                        mov bx,[0x2]
                                        mov cx,bx
                                        shr bx,4
                                        inc bx
                                        mov ah,0x4a
                                        int 0x21
                                        mov bx,si
                                        mov dx,0
                                        mov ah,0x3f
                                        int 0x21
                                        mov [0x2],es
                                        mov bp,0x0
                                        call far [es:bp]
                                        push cs
                                        pop ds
                                        mov bp,g3
                                        mov [bp+2],es


                                        end_gdosLoadDriverDOS:
                                        pop es
                                        pop ds
                                        retf

                                gdosSetModeByID:
                                        push es
                                        push ds

                                        push cs
                                        pop ds

                                        mov bp,g3
                                        mov ax,[GraphicsDriver]
                                        shl ax,2
                                        add bp,ax

                                        mov di,[bp+2]
                                        mov es,di

                                        mov di,[es:11]

                                        sub sp,4
                                        mov bp,sp
                                        mov [ss:bp],di
                                        mov [ss:bp+2],es
                                        call far [ss:bp]

                                        add sp,4
                                        pop ds
                                        pop es
                                        retf

        GDOS_KERNEL_END:

第二个文件:VGA.ASM

    GDOS_DRIVER_START:
        GDOS_SECTION_DRIVER_HEADER:
                gEntry: dw vgaEntry ;Punkt wejścia sterownika / Driver entry
                gDriverSize: dw GDOS_DRIVER_END ;Rozmiar sterownika w bajtach  / Driver size in bytes
                gDriverType: db 1 ;0x1 - Sterownik grafiki / 0x1 - Graphics driver
                gPortsData: dw vgaPorts
                gMemData: dw vgaMem
                gShared: dw vgaShared ;Lista sterowników dla których zasoby są udostępnione
                gBasicFunc: dw vgaChangeModeID
                gBasicPtrs: dw vgaPtrs
        GDOS_SECTION_DRIVER_DATA:
                vgaIDString: db 'vga-drv$',0 ;SĹ‚uĹĽy do wyszukiwania sterownika przez GDOS / It's for GDOS driver search
                vgaShared0: db 'svga-drv',0
                vgaEntry:
                        retf
                vgaPorts:
                db 0x1
                db 2 
                dw 0x3c8,0x3c9
                db 0x0
                vgaMem:
                db 0x1
                db 2
                dd 0x0000A000,0x0000BFFF
                db 0x0
                vgaShared:
                db 0x1
                dw vgaShared0
                db 0x0

                vgaPtrs:
                        dw vgaModes
                vgaModes:


                vgaFunc:
                dw vgaChangeModeID

                vgaMisc_Common db 0x63
                R_W256 db 0x00
                R_W320 db 0x00
                R_W360 db 0x04
                R_W376 db 0x04
                R_W400 db 0x04

                R_H200 db 0x00
                R_H224 db 0x80
                R_H240 db 0x80
                R_H256 db 0x80
                R_H270 db 0x80
                R_H300 db 0x80
                R_H360 db 0x00
                R_H400 db 0x00
                R_H480 db 0x80
                R_H564 db 0x80
                R_H600 db 0x80

                HOR_REGS db 0x0,0x1,0x2,0x3,0x4,0x5,0x13
                VER_REGS db 0x6,0x7,0x9,0x10,0x11,0x12,0x15,0x16

                W256: db 0x5f,0x3f,0x40,0x82,0x4a,0x9a,0x20


                vgaChangeModeID: ;TEST
                push ds
                push cs
                pop ds
                mov ah,9
                mov dx,vgaIDString
                int 0x21
                pop ds
                retf

GDOS_DRIVER_END:

要将文件组装成GDOS.EXE和VGA.BIN,请使用以下命令:

fasm GDOS.ASM
fasm VGA.ASM

程序运行时,我希望它显示以下内容,然后返回到DOS提示符:

  

vga-drv

0 个答案:

没有答案