;/////////////////////;
;Nanite OS            ;
;COPYRIGHT (C) 2026   ;
;Xircon               ;
;/////////////////////;
[bits 32]

; void __attribute__((cdecl)) GDT_Load(GDTDescriptor* descriptor, uint16_t codeSegment, uint16_t dataSegment);
global GDT_Load
GDT_Load:
    ; make new call frame
    push ebp             ; save old call frame
    mov ebp, esp         ; initialize new call frame

    ; load GDT
    mov eax, [ebp + 8]
    lgdt [eax]

    ; Reload Code Segment
    mov eax, [ebp + 12]
    push eax
    push .reload_cs
    retf

.reload_cs:

    ; reload data segments
    mov ax, [ebp + 16]
    mov ds, ax
    mov es, ax
    mov fs, ax
    mov gs, ax,
    mov ss, ax



    ; restore old call frame
    mov esp, ebp
    pop ebp
    ret