home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / wunderki.zip / WAPP.ASM < prev    next >
Assembly Source File  |  1993-08-16  |  7KB  |  183 lines

  1. ;//////////////////////////////////////////////////////
  2. ;/                                                    /
  3. ;/ Run-time Library für Borland Pascal 7.0 unter OS/2 /
  4. ;/ Startup-Routine für OS/2-Programme.                /
  5. ;/                                                    /
  6. ;/ 1993 Matthias Withopf / c't                        /
  7. ;/ Originalversion (c) 1988,92 Borland International  /
  8. ;/                                                    /
  9. ;//////////////////////////////////////////////////////
  10.  
  11.                 .286p                                         
  12.  
  13.                 _NOMACROS_ = 1                  ; keine Macros definieren
  14.                 INCLUDE SE.ASM
  15.                 INCLUDE OS2.ASM
  16.  
  17. DATA            SEGMENT WORD PUBLIC
  18.                 EXTRN   Input:BYTE,Output:BYTE,CmdLine:DWORD,SelectorInc:WORD
  19.                 EXTRN   ExitProc:DWORD,EnvironmentSeg:WORD,Test8086:BYTE
  20.                 EXTRN   SaveInt00:DWORD,SaveInt0C:DWORD,SaveInt0D:DWORD
  21. DATA            ENDS
  22.  
  23. CODE            SEGMENT BYTE PUBLIC
  24.                 ASSUME  CS:CODE,DS:DATA
  25.  
  26.                 EXTRN   AssignText:NEAR,ResetText:NEAR,RewriteText:NEAR
  27.                 EXTRN   CloseText:NEAR,HaltError:FAR
  28.  
  29.                 ;
  30.                 ; Startup-Routine für OS/2-Programme.
  31.                 ; Jedes Programm beginnt mit einem Far-Call
  32.                 ; dieser Routine.
  33.                 ;
  34.  
  35.                 PUBLIC  InitTurbo
  36. InitTurbo       PROC    FAR
  37.                 XOR     BP,BP                   ; setze Markierung für ungültigen Stack-Frame
  38.                 MOV     EnvironmentSeg,AX       ; speichere Selektor des Environment-Blocks
  39.                 MOV     CmdLine.offs,BX         ; speichere Zeiger
  40.                 MOV     CmdLine.segm,AX         ; auf die Kommandozeile
  41.                 MOV     AX,SP
  42.                 ADD     AX,4
  43.                 MOV     SS:pStackTop,10H        
  44.                 MOV     SS:pStackBot,AX         
  45.                 MOV     SS:pStackMin,AX         
  46.                 CALL    Check8086               ; bestimme Prozessortyp
  47.                 PUSH    VECTOR_DIVIDE_BY_ZERO   ; setze Handler für INT 00
  48.                 PUSH    CS                      ; (Divide by zero)
  49.                 PUSH    OFFSET Int00Handler
  50.                 PUSH    DS
  51.                 PUSH    OFFSET SaveInt00
  52.                 CALL    DosSetVec
  53.                 PUSH    12                      ; setze Handler für INT 0C
  54.                 PUSH    CS                      ; (Stack Fault)
  55.                 PUSH    OFFSET Int0DHandler
  56.                 PUSH    DS
  57.                 PUSH    OFFSET SaveInt0C
  58.                 CALL    DosSetVec
  59.                 PUSH    13                      ; setze Handler für INT 0D
  60.                 PUSH    CS                      ; (General Protection Fault)
  61.                 PUSH    OFFSET Int0DHandler
  62.                 PUSH    DS
  63.                 PUSH    OFFSET SaveInt0D
  64.                 CALL    DosSetVec
  65.                 MOV     AX,OFFSET Input         ;Assign/Reset Input file
  66.                 PUSH    DS
  67.                 PUSH    AX
  68.                 PUSH    DS
  69.                 PUSH    AX
  70.                 MOV     AX,OFFSET ZeroString
  71.                 PUSH    CS
  72.                 PUSH    AX
  73.                 PUSH    CS
  74.                 CALL    AssignText
  75.                 PUSH    CS
  76.                 CALL    ResetText
  77.                 MOV     AX,OFFSET Output        ;Assign/Rewrite Output file
  78.                 PUSH    DS
  79.                 PUSH    AX
  80.                 PUSH    DS
  81.                 PUSH    AX
  82.                 MOV     AX,OFFSET ZeroString
  83.                 PUSH    CS
  84.                 PUSH    AX
  85.                 PUSH    CS
  86.                 CALL    AssignText
  87.                 PUSH    CS
  88.                 CALL    RewriteText
  89.                 PUSH    DS                      ; erfrage
  90.                 PUSH    OFFSET SelectorInc      ; den Wert
  91.                 CALL    DosGetHugeShift         ; für AHugeShift
  92.                 MOV     AX,1                    ; berechne
  93.                 MOV     CX,SelectorInc          ; daraus den
  94.                 SHL     AX,CL                   ; SelectorInc-Wert
  95.                 MOV     SelectorInc,AX          ; (SelectorInc := 1 Shl AHugeShift)
  96.                 MOV     ExitProc.offs,OFFSET ExitTurbo ; setze standardmäßige
  97.                 MOV     ExitProc.segm,CS        ; Exit-Prozedur
  98.                 RET
  99.  
  100.                 ;
  101.                 ; Bestimme den CPU-Typ und setze
  102.                 ; Variable Test8086 entsprechend.
  103.                 ;
  104.  
  105.                 PUBLIC  Check8086
  106. Check8086       PROC    NEAR
  107.                 XOR     AX,AX                   ;lese 0 als Kennzeichen für 8088/8086
  108.                 PUSHF                           ;BX = Flags
  109.                 POP     BX
  110.                 AND     BH,0FH                  ;Clear bits 12-15
  111.                 PUSH    BX                      ;Flags = BX
  112.                 POPF
  113.                 PUSHF                           ;CX = Flags
  114.                 POP     CX
  115.                 AND     CH,0F0H                 ;Bits 12-15 set?
  116.                 CMP     CH,0F0H
  117.                 JE      @@End                   ; ja -> Typ = 8088/86
  118.                 INC     AX                      ; lese 1 als Kennzeichen für 80286
  119.                 OR      BH,0F0H                 ;Set bits 12-15
  120.                 PUSH    BX                      ;Flags = BX
  121.                 POPF
  122.                 PUSHF                           ;CX = Flags
  123.                 POP     CX
  124.                 AND     CH,0F0H                 ;Bits 12-15 cleared?
  125.                 JE      @@End                   ; ja -> Typ = 80286
  126.                 INC     AX                      ; lese 2 als Kennzeichen für 80386
  127. @@End:          MOV     Test8086,AL             ; speichere Ergebnis
  128.                 RET
  129. Check8086       ENDP
  130.  
  131.                 ;
  132.                 ; Routine für INT 00: Division by zero.
  133.                 ;
  134.  
  135. Int00Handler    PROC    FAR
  136.                 MOV     AX,200                  ; Fehler: 'Division by zero'
  137.                 JMP     HaltError
  138. Int00Handler    ENDP
  139.  
  140.                 ;
  141.                 ; Routine für INT 0C: Stack Fault.
  142.                 ;
  143.  
  144. Int0CHandler    PROC    FAR
  145.                 MOV     AX,202                  ; Fehler: 'Stack overflow error'
  146.                 JMP     HaltError
  147. Int0CHandler    ENDP
  148.  
  149.                 ;
  150.                 ; Routine für INT 0D: General Protection Fault.
  151.                 ;
  152.  
  153. Int0DHandler    PROC    FAR
  154.                 MOV     AX,216                  ; Fehler: 'General Protection fault'
  155.                 JMP     HaltError
  156. Int0DHandler    ENDP
  157.  
  158. ZeroString      DB      0
  159. InitTurbo       ENDP
  160.  
  161.                 ;
  162.                 ; Beende das OS/2-Programm.
  163.                 ; Schließe die Standard-Ein-/Ausgabedateien.
  164.                 ;
  165.  
  166. ExitTurbo       PROC    FAR
  167.                 MOV     AX,OFFSET Input         
  168.                 PUSH    DS
  169.                 PUSH    AX
  170.                 PUSH    CS
  171.                 CALL    CloseText
  172.                 MOV     AX,OFFSET Output        
  173.                 PUSH    DS
  174.                 PUSH    AX
  175.                 PUSH    CS
  176.                 CALL    CloseText
  177.                 RET
  178. ExitTurbo       ENDP
  179.  
  180. CODE            ENDS
  181.  
  182.                 END
  183.