// SPDX-License-Identifier: MPL-2.0
#include "kernel/conf.h"
#include "std/mem.h"
sh_conf_BOOT_CONFIG boot_config;
SH_STATUS sh_conf_get_boot_config(sh_conf_BOOT_CONFIG **config) {
  if (config==SH_NULLPTR) {
    return SH_STATUS_INVALID_PARAMETER;
  }
  *config=(sh_conf_BOOT_CONFIG *)SH_CONF_BOOT_CONFIG_VA;
  static const sh_uint8 sig_start[8]={'S','h','C','f','g','B','e','g'};
  static const sh_uint8 sig_end[8]={'S','h','C','f','g','E','n','d'};
  if (sh_mem_compare((*config)->sig_start,sig_start,sizeof(sig_start))==SH_STATUS_MEM_NOT_EQUAL) {
    return SH_STATUS_INVALID_SIGNATURE;
  }
  if (sh_mem_compare((*config)->sig_end,sig_end,sizeof(sig_end))==SH_STATUS_MEM_NOT_EQUAL) {
    return SH_STATUS_INVALID_SIGNATURE;
  }
  sh_mem_copy((sh_uint8*)&boot_config,(sh_uint8*)*config,sizeof(sh_conf_BOOT_CONFIG));
  return SH_STATUS_SUCCESS;
}
SH_STATUS sh_conf_devs_query(char *sub_path,sh_devs_RESULT *result) {
  if (sub_path==SH_NULLPTR || result==SH_NULLPTR) return SH_STATUS_INVALID_PARAMETER;
  sh_uint64 path_len=sh_string_len(sub_path);
  if (path_len==0 || path_len>256) return SH_STATUS_INVALID_PARAMETER;
  if (sh_string_compare(sub_path,"/log-level",10)) {
    if (path_len==10) {
      result->type=SH_DEVS_VALUE;
      result->value=boot_config.log_level;
      return SH_STATUS_SUCCESS;
    } else {
      return SH_STATUS_NOT_FOUND;
    }
  } else if (sh_string_compare(sub_path,"/test-benchmark",15)) {
    if (path_len==15) {
      result->type=SH_DEVS_BOOL;
      result->value=boot_config.test_benchmark;
      return SH_STATUS_SUCCESS;
    } else {
      return SH_STATUS_NOT_FOUND;
    }
  } else if (sh_string_compare(sub_path,"/bench-iterations",17)) {
    if (path_len==17) {
      result->type=SH_DEVS_VALUE;
      result->value=boot_config.bench_iterations;
      return SH_STATUS_SUCCESS;
    } else {
      return SH_STATUS_NOT_FOUND;
    }
  } else if (sh_string_compare(sub_path,"/disable-serial-port",20)) {
    if (path_len==20) {
      result->type=SH_DEVS_BOOL;
      result->value=boot_config.disable_serial_port;
      return SH_STATUS_SUCCESS;
    } else {
      return SH_STATUS_NOT_FOUND;
    }
  } else if (sh_string_compare(sub_path,"/kbd-events-queue-capacity",26)) {
    if (path_len==26) {
      result->type=SH_DEVS_VALUE;
      result->value=boot_config.kbd_events_queue_capacity;
      return SH_STATUS_SUCCESS;
    } else {
      return SH_STATUS_NOT_FOUND;
    }
  } else {
    return SH_STATUS_NOT_FOUND;
  }
}
