Code Segment Byte Public
     Assume CS:Code, DS:Code

.386P


Public Lib_Bit
Public Set_Segment



;
; Active le 21eme bit d'adresse du processeur
;

Lib_Bit Proc Near
         CLI
         CALL Warte_8042
         JNZ  Zurueck
         MOV  AL, 0D1h
         OUT  64h, AL
         CALL Warte_8042
         JNZ  Zurueck
         MOV  AL, 0DFh
         OUT  60h, AL
         CALL Warte_8042
Zurueck: RET
Lib_Bit EndP


;
; Attend que le 8042 soit pret
;

Warte_8042 Proc Near
         XOR  CX, CX
WLoop:   IN   AL, 64h
         AND  AL, 2
         LOOPNZ  WLoop
         RET
Warte_8042 EndP




;
; GTD pour le mode proteg‚
;

GDTZeiger    DQ ?
Segment     DW 0, 0, 0, 0
             DW 0FFFFh, 0
             DB 0, 9Ah
             DW 0h

             DW 0FFFFh, 0
             DB 0, 92h
             DW 0h

             DW 0FFFFh, 0
             DB 0, 92h
             DW 0FFh
Segment_End Label Word
GDT_Groesse equ (Offset Segment_End-Segment-1)


;
; Commutation en mode proteg‚ et redef. de GS
;

Set_Segment  Proc Near
             MOV    AX,  CS
             PUSH   DS
             MOV    DS,  AX
             MOV    Word Ptr CS:AktSeg, AX
             MOVZX  EAX, AX
             SHL    EAX, 4
             MOV    EBX, EAX
             MOV    Word Ptr CS:Segment+0Ah, AX
             MOV    Word Ptr CS:Segment+12h, AX
             ROR    EAX, 16
             MOV    Byte Ptr CS:Segment+0Ch, AL
             MOV    Byte Ptr CS:Segment+14h, AL
             XOR    EAX, EAX
             MOV    AX,  Offset CS:Segment
             ADD    EBX, EAX
             MOV    Word Ptr CS:GDTZeiger, GDT_Groesse
             MOV    DWord Ptr CS:GDTZeiger+2, EBX
             PUSHF

             ; Passage en mode proteg‚.

             CLI
             IN     AL, 70h
             MOV    AH, AL
             OR     AL, 80h
             OUT    70h, AL
             AND    AH, 80h
             MOV    CH, AH
             LGDT   FWord Ptr CS:GDTZeiger
             MOV    BX, DS
             MOV    DX, SS
             MOV    EAX, CR0
             OR     AL, 1
             MOV    CR0, EAX
             Db     0EAh
             DW     (Offset PMode)
             DW     8

PMode:
             MOV    AX, 10h
             MOV    SS, AX
             MOV    DS, AX
             MOV    ES, AX

             MOV    AX, 18h
             MOV    FS, AX
             MOV    GS, AX

             MOV    EAX, CR0
             AND    EAX, Not 1
             MOV    CR0, EAX
             Db     0EAh
             DW     (Offset RMode)
AktSeg       DW     ?
RMode:       MOV    SS, DX
             MOV    DS, BX
             XOR    AX, AX
             MOV    ES, AX
             MOV    FS, AX
             MOV    GS, AX
             IN     AL, 70h
             AND    AL, Not 80h
             OR     AL, CH
             OUT    70h, AL
             POPF
             POP    DS
             STI
             CALL   Lib_Bit
             RET

Set_Segment EndP
Code         Ends
             End



