"Fossies" - the Fresh Open Source Software Archive

Member "fasm/tools/dos/loader.inc" (9 Feb 2020, 1783 Bytes) of package /linux/misc/fasm-1.73.22.tgz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) fasm source code syntax highlighting (style: standard) with prefixed line numbers. Alternatively you can here view or download the uninterpreted source code file.

    1 
    2 segment loader use16
    3 
    4 init:
    5 
    6     mov ax,1687h
    7     int 2Fh
    8     or  ax,ax           ; DPMI installed?
    9     jnz short no_dpmi
   10     test    bl,1            ; 32-bit programs supported?
   11     jz  short no_dpmi
   12     mov word [cs:mode_switch],di
   13     mov word [cs:mode_switch+2],es
   14     mov bx,si           ; allocate memory for DPMI data
   15     mov ah,48h
   16     int 21h
   17     jnc init_protected_mode
   18   init_failed:
   19     call    init_error
   20     db  'error: DPMI initialization failed.',0Dh,0Ah,0
   21   no_dpmi:
   22     call    init_error
   23     db  'error: 32-bit DPMI services are not available.',0Dh,0Ah,0
   24   init_error:
   25     pop si
   26     push    cs
   27     pop ds
   28       display_error:
   29     lodsb
   30     test    al,al
   31     jz  short error_finish
   32     mov dl,al
   33     mov ah,2
   34     int 21h
   35     jmp short display_error
   36       error_finish:
   37     mov ax,4CFFh
   38     int 21h
   39   init_protected_mode:
   40     mov es,ax
   41     mov ds,[ds:2Ch]
   42     mov ax,1
   43     call    far [cs:mode_switch]    ; switch to protected mode
   44     jc  init_failed
   45     mov cx,1
   46     xor ax,ax
   47     int 31h         ; allocate descriptor for code
   48     jc  init_failed
   49     mov si,ax
   50     xor ax,ax
   51     int 31h         ; allocate descriptor for data
   52     jc  init_failed
   53     mov di,ax
   54     mov dx,cs
   55     lar cx,dx
   56     shr cx,8
   57     or  cx,0C000h
   58     mov bx,si
   59     mov ax,9
   60     int 31h         ; set code descriptor access rights
   61     jc  init_failed
   62     mov dx,ds
   63     lar cx,dx
   64     shr cx,8
   65     or  cx,0C000h
   66     mov bx,di
   67     int 31h         ; set data descriptor access rights
   68     jc  init_failed
   69     mov ecx,main
   70     shl ecx,4
   71     mov dx,cx
   72     shr ecx,16
   73     mov ax,7
   74     int 31h         ; set data descriptor base address
   75     jc  init_failed
   76     mov bx,si
   77     int 31h         ; set code descriptor base address
   78     jc  init_failed
   79     mov cx,0FFFFh
   80     mov dx,0FFFFh
   81     mov ax,8            ; set segment limit to 4 GB
   82     int 31h
   83     jc  init_failed
   84     mov bx,di
   85     int 31h
   86     jc  init_failed
   87     mov ax,ds
   88     mov ds,di
   89     mov [psp_selector],es
   90     mov [environment_selector],ax
   91     cli
   92     mov ss,di
   93     mov esp,stack_top
   94     sti
   95     mov es,di
   96     xor eax,eax
   97     mov [memory_handles_count],eax
   98     push    si
   99     push    start
  100     retf
  101 
  102   mode_switch dd ?