// SPDX-License-Identifier: MPL-2.0
#include "../include/debug.h"
#include <Uefi.h>
#include <Library/BaseMemoryLib.h>
#include <Library/MemoryAllocationLib.h>
#include <Library/PrintLib.h>
#include <Library/UefiBootServicesTableLib.h>
#include <Library/UefiLib.h>
#include <Library/BaseLib.h>
EFI_STATUS bp_debug_write(EFI_SERIAL_IO_PROTOCOL *serial_protocol,CHAR8* output,BOOLEAN allow_debugging) {
  if (serial_protocol==NULL || output==NULL) {
    return EFI_INVALID_PARAMETER;
  }
  UINTN strlen=AsciiStrLen(output);
  if (allow_debugging) serial_protocol->Write(serial_protocol,&strlen,output);
  return EFI_SUCCESS;
}
EFI_STATUS bp_debug_write_line(EFI_SERIAL_IO_PROTOCOL *serial_protocol,CHAR8* output,BOOLEAN allow_debugging) {
  if (serial_protocol==NULL || output==NULL) {
    return EFI_INVALID_PARAMETER;
  }
  UINTN strlen=AsciiStrLen(output);
  CHAR8 *output_line=AllocatePool(strlen+3);
  if (!output_line) {
    return EFI_OUT_OF_RESOURCES;
  }
  UINTN outputlen=AsciiSPrint(output_line,strlen+3,"%a\r\n",output);
  if (allow_debugging) serial_protocol->Write(serial_protocol,&outputlen,output_line);
  FreePool(output_line);
  return EFI_SUCCESS;
}
