// SPDX-License-Identifier: MPL-2.0
#include "irq/tss.h"
#include "cpu/asm.h"
SH_STATUS sh_tss_fill_tss(sh_tss_TSS *tss) {
  if (tss==SH_NULLPTR) return SH_STATUS_INVALID_PARAMETER;
  sh_mem_set_8((sh_uint8*)tss,0x0,sizeof(sh_tss_TSS));
  void* rsp0=sh_malloc(4096*4);
  if (!rsp0) return SH_STATUS_ERROR_NULLPTR_RETURNED;
  tss->rsp0=(sh_uint64)rsp0+4096*4;
  void* double_fault=sh_malloc(4096*4);
  if (!double_fault) return SH_STATUS_ERROR_NULLPTR_RETURNED;
  tss->ist1=(sh_uint64)double_fault+4096*4;
  void* nmi_fault=sh_malloc(4096*4);
  if (!nmi_fault) return SH_STATUS_ERROR_NULLPTR_RETURNED;
  tss->ist2=(sh_uint64)nmi_fault+4096*4;
  void* page_fault=sh_malloc(4096*4);
  if (!page_fault) return SH_STATUS_ERROR_NULLPTR_RETURNED;
  tss->ist3=(sh_uint64)page_fault+4096*4;
  void* ss_fault=sh_malloc(4096*4);
  if (!ss_fault) return SH_STATUS_ERROR_NULLPTR_RETURNED;
  tss->ist4=(sh_uint64)ss_fault+4096*4;
  tss->iomap_base=sizeof(*tss);
  return SH_STATUS_SUCCESS;
}
SH_STATUS sh_tss_load_tr(sh_tss_TSS *tss) {
  if (tss==SH_NULLPTR) return SH_STATUS_INVALID_PARAMETER;
  sh_uint16 tss_selector=0x28;
  sh_asm_ltr(tss_selector);
  return SH_STATUS_SUCCESS;
}
