; virtual memory mgr
bits 16
%define xvmemory

section .modhdr
    init2: jmp initvir
    name2: dw virname

section .data
    virname: db "memmgr-vir",0x00

section .text
    %include "std"
    %include "bits"
    %include "memory"
    %include "confseg"
    %include "printf"

    %define gdtidx2sel(i,r)    _gdtidx2sel i,r   ; gdtidx2sel :: int16 idx
                                                 ;   -> int8 ring -> int16 sel
    %define getempty()         _getempty         ; getempty :: void -> int16 idx
    %define growgdt()              _growgdt      ; growgdt :: void -> bool
    %define show(s,a)           _show s,a       ; show :: gdtentry *seg:addr
                                                ;   -> void
    %define setgdtbitmap(i,x)   setbit(csselector,confseg.virbm,i,x)
                                                ; setgdtbitmap :: int16 idx
                                                ;   -> bool val -> void

    %macro _show 2
        mov ax,%2
        push ax
        mov ax,%1
        push ax
        call __show
        add sp,4
    %endmacro

    %macro _gdtidx2sel 2
        mov ax,%2
        push ax
        mov ax,%1
        push ax
        call __gdtidx2sel
        add sp,4
    %endmacro

    %macro _getempty 0
        call __getempty
    %endmacro

    %macro _growgdt 0
        call __growgdt
    %endmacro

    %include "virmem.s"
