;   creatgdt.inc, Copyright (c) 1997-1998 by Lukas Ruf,
;   Swiss Federal Institute of Technology,
;   Computer Engineering and Networks Laboratory.
;
;   TOPSY -- A Teachable Operating System.
;            Implementation of a tiny and simple
;            micro kernel for teaching purposes.
;
;   For further information, please visit http://www.tik.ee.ethz.ch/~topsy
;
;   This software is provided under the terms of the GNU General Public Licence.
;   A full copy of the GNU GPL is provided in the file COPYING found in the 
;   development root of Topsy.
;
;       This copyright notice supercedes all originally or previously used 
;       copyrights being used within the source code.
;       
;       Author: Lukas Ruf, lr@lpr.ch


;Topsy i386                                             Lukas Ruf, December 1997
;-------------------------------------------------------------------------------
;////
;// All Interrupts are disabled. (Reprogramming of IRQs)
;// There is no return to Real Mode Interrupts after execution of Create_GDT.
;// This Routine is executed in Real Mode as the GDT has to be initialized
;// before jumping to PM.
;////
;Create_GDT      PROC NEAR
.align 8
Create_GDT:

        JMP     ljGDT1

.align 8
   GDT00:
        dd       0,0
   GDT01:  ; OS-Code
        dw       0xFFFF             ; Limit 15..0   A0000 / 1000 - 1 = 9F
        dw       0x0000             ; Base  15..0
        db       0x0000             ; Base  23..16
        db       MM_CODE_B5         ; see structur.inc
        db       MM_CODE_B6_OR_0x0F ; see structur.inc
        db       0x0000             ; Base  31..24
   GDT02:  ; OS-Data
        dw       0xFFFFF            ; Limit 15..0   4GB / 1000 - 1 = FFFFF
        dw       0x0000             ; Base  15..0
        db       0x0000             ; Base  23..16
        db       MM_DATA_B5         ; see structur.inc
        db       MM_DATA_B6_OR_0x0F ; see structur.inc
        db       0x0000             ; Base  31..24
   GDT03:  ; Global-Data
        dw       0xFFFFF            ; Limit 15..0   4GB / 1000 - 1 = FFFFF
        dw       0x0000             ; Base  15..0
        db       0x0000             ; Base  23..16
        db       MM_DATA_B5         ; see structur.inc
        db       MM_DATA_B6_OR_0x0F ; see structur.inc (set lower nibbble to 15)
        db       0x0000             ; Base  31..24
   GDT04:  ; Video                   !!! GRANULARITY IS BYTE !!!
        dw       0x0FBF             ; Limit 15..0
        dw       0x8000             ; Base  15..0
        db       0x000B             ; Base  23..16
        db       MM_DATA_B5         ; see structur.inc
        db       MM_DATA_B6_BYTE    ; see structur.inc
        db       0x0000             ; Base  31..24
   GDT05:  ; GDT                     !!! GRANULARITY IS BYTE !!!
        dw       0xEFFF             ; Limit 15..0
        dw       0x1000             ; Base  15..0 at 2nd Page
        db       0x0000             ; Base  23..16
        db       MM_DATA_B5         ; see structur.inc
        db       MM_DATA_B6_BYTE    ; see structur.inc
        db       0x0000             ; Base  31..24
   ljGDT1:
        ;GDTxSIZE = #ljGDT1 - #GDT00
        ;-LR GDTxSIZE = * - GDT00

        ;Store GDT as defined above at correct location
        MOV     AX,#GDTSEG
        MOV     ES,AX
        MOV     AX,#GDTOFS
        MOV     DI,AX
        MOV     CX,#GDTxSIZE     ; (Bytes)
        SHR     CX,#1            ; (Word)
        MOV     AX,#GDT00
        MOV     SI,AX
        CLD
        REP     
        MOVSW           ; Overwrite segment.

        RET
;Create_GDT      ENDP

