lib_loader.c 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. /*
  2. * Copyright (c) 2021 Alibaba Group. All rights reserved.
  3. * License-Identifier: Apache-2.0
  4. *
  5. * Licensed under the Apache License, Version 2.0 (the "License"); you may
  6. * not use this file except in compliance with the License.
  7. * You may obtain a copy of the License at
  8. *
  9. * http://www.apache.org/licenses/LICENSE-2.0
  10. *
  11. * Unless required by applicable law or agreed to in writing, software
  12. * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
  13. * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  14. * See the License for the specific language governing permissions and
  15. * limitations under the License.
  16. *
  17. */
  18. #include <xt_library_loader.h>
  19. #include <stdlib.h>
  20. #include <stdio.h>
  21. #include <string.h>
  22. #include "dsp_ps_debug.h"
  23. #include "lib_loader.h"
  24. #include "ialgo.h"
  25. wrapper_func csi_dsp_load_flo(void* obj,lib_loader_info_t *info)
  26. {
  27. wrapper_func flo_start = NULL;
  28. flo_start= xtlib_load_overlay_ext((xtlib_packaged_library * )obj,&info->ovl_info);
  29. if(flo_start==NULL)
  30. {
  31. ps_debug("failed with error code: %d\n", xtlib_error());
  32. }
  33. return flo_start;
  34. }
  35. void csi_dsp_unload_flo(lib_loader_info_t *info)
  36. {
  37. xtlib_unload_overlay_ext(&info->ovl_info);
  38. }
  39. wrapper_func csi_dsp_load_pilsl(void* obj,lib_loader_info_t *info)
  40. {
  41. unsigned int code_bytes, data_bytes;
  42. wrapper_func plo_start = NULL;
  43. if (xtlib_split_pi_library_size ((xtlib_packaged_library * )obj, &code_bytes, &data_bytes) != XTLIB_NO_ERR) {
  44. ps_err("xtlib_split_pi_library_size failed with error: %d\n", xtlib_error ());
  45. return 0;
  46. }
  47. void * data_memory = malloc (data_bytes);
  48. void * code_memory = malloc (code_bytes);
  49. if (!code_memory || !data_memory){
  50. ps_err ("malloc failed\n");
  51. return 0;
  52. }
  53. info->code_memory_num = 1;
  54. info->code_memory[0]= code_memory;
  55. info->code_size[0] = code_bytes;
  56. info->data_memory_num = 1;
  57. info->data_memory[0] = data_memory;
  58. info->data_size[0] = data_bytes;
  59. plo_start= xtlib_load_split_pi_library((xtlib_packaged_library * )obj, code_memory, data_memory, &info->pil_info);
  60. if(plo_start==NULL)
  61. {
  62. ps_debug("failed with error code: %d\n", xtlib_error());
  63. }
  64. return plo_start;
  65. }
  66. void csi_dsp_unload_pilsl(lib_loader_info_t *info)
  67. {
  68. int i;
  69. xtlib_unload_pi_library(&info->pil_info);
  70. for(i=0;i<info->code_memory_num;i++)
  71. {
  72. free(info->code_memory[i]);
  73. }
  74. for(i=0;i<info->data_memory_num;i++)
  75. {
  76. free(info->data_memory[i]);
  77. }
  78. }