; memory headers

%define chseg(x,y)      _chseg x,y    ; chseg :: reg *seg -> int16 new -> void
%define sret(x)         _sret x         ; sret :: reg *seg -> void
%define palloc(x)       _palloc x       ; palloc :: int8 _blocks -> int32 *addr


%ifdef xpmemory
  global Palloc
%else
  extern Palloc
%endif

%ifdef xvmemory
  global Valloc
%else
  extern Valloc
%endif

struc gdtentry
    .limit:   resw 1
    .baselo:  resw 1
    .basehi   resb 1
    .xs:      resb 1
    .reserv:  resw 1
endstruc

%macro _chseg 2
   mov ax,%1
   push ax
   cmp word ax,%2
   je %%eq
 %%neq:
   mov ax,%2   ; ax=new seg
   mov %1,ax
 %%eq:
%endmacro

%macro _sret 1
   pop bx
   mov cx,%1
   cmp bx,cx
   je %%eq
 %%neq:
   mov %1,bx
 %%eq:
%endmacro

%macro _palloc 1
  mov ax,%1
  push ax
  call Palloc
  add sp,0x0002
%endmacro
