// SPDX-License-Identifier: MPL-2.0
#ifndef SH_LIB_ASM_H
#define SH_LIB_ASM_H
#include "std/type.h"
#include "std/status.h"
// inb instruction wrapper
static inline sh_uint8 sh_asm_inb(sh_uint16 port) {
  sh_uint8 val;
  __asm__ volatile ("inb %1, %0":"=a"(val):"Nd"(port));
  return val;
}
// outb instruction wrapper
static inline void sh_asm_outb(sh_uint16 port,sh_uint8 val) {
  __asm__ volatile ("outb %0, %1"::"a"(val),"Nd"(port));
}
// rdtsc instruction wrapper
static inline sh_uint64 sh_asm_rdtsc() {
  sh_uint32 lo,hi;
  __asm__ volatile ("rdtsc":"=a"(lo),"=d"(hi));
  return ((sh_uint64)hi<<32)|lo;
}
// invlpg instruction wrapper
static inline void sh_asm_invlpg(void *addr) {
  __asm__ volatile ("invlpg (%0)"::"r"(addr):"memory");
}
#endif
