//////////////////////////////////////////////////////////////////////////////
//                                                                           /
// IAR ARM ANSI C/C++ Compiler V4.40A/W32 EVALUATION   28/Mar/2008  19:05:54 /
// Copyright 1999-2005 IAR Systems. All rights reserved.                     /
//                                                                           /
//    Cpu mode        =  interwork                                           /
//    Endian          =  little                                              /
//    Stack alignment =  4                                                   /
//    Source file     =  E:\Ivo\arm\IVOPLAY\conf_loader.c                    /
//    Command line    =  E:\Ivo\arm\IVOPLAY\conf_loader.c -D X65 -lC         /
//                       E:\Ivo\arm\IVOPLAY\Release\List\ -lA                /
//                       E:\Ivo\arm\IVOPLAY\Release\List\ -o                 /
//                       E:\Ivo\arm\IVOPLAY\Release\Obj\ -s9 --no_cse        /
//                       --no_unroll --no_inline --no_code_motion --no_tbaa  /
//                       --no_clustering --no_scheduling --cpu_mode arm      /
//                       --endian little --cpu ARM926EJ-S --stack_align 4    /
//                       --interwork -e --fpu None --dlib_config             /
//                       D:\arm\ARM\LIB\dl5tpainl8n.h -I D:\arm\ARM\INC\     /
//    List file       =  E:\Ivo\arm\IVOPLAY\Release\List\conf_loader.s79     /
//                                                                           /
//                                                                           /
//////////////////////////////////////////////////////////////////////////////

        NAME conf_loader

        RTMODEL "StackAlign4", "USED"
        RTMODEL "__cpu_mode", "__pcs__interwork"
        RTMODEL "__data_model", "absolute"
        RTMODEL "__endian", "little"
        RTMODEL "__rt_version", "6"

        RSEG CONFIG_C:DATA:REORDER:NOROOT(0)
        RSEG CSTACK:DATA:NOROOT(2)

        PUBWEAK `?*?DATA_ID`
        MULTWEAK ??InitConfig??rT
        MULTWEAK ??LoadConfigData??rT
        MULTWEAK ??SaveConfigData??rT
        PUBWEAK ?init?tab?DATA_I
        PUBLIC InitConfig
        FUNCTION InitConfig,0201H
        LOCFRAME CSTACK, 4, STACK
        PUBLIC LoadConfigData
        FUNCTION LoadConfigData,0203H
        LOCFRAME CSTACK, 44, STACK
        PUBLIC SaveConfigData
        FUNCTION SaveConfigData,0203H
        LOCFRAME CSTACK, 24, STACK
        PUBLIC successed_config_filename
        
        CFI Names cfiNames0
        CFI StackFrame CFA R13 HUGEDATA
        CFI Resource R0:32, R1:32, R2:32, R3:32, R4:32, R5:32, R6:32, R7:32
        CFI Resource R8:32, R9:32, R10:32, R11:32, R12:32, CPSR:32, R13:32
        CFI Resource R14:32, SPSR:32
        CFI VirtualResource ?RET:32
        CFI EndNames cfiNames0
        
        CFI Common cfiCommon0 Using cfiNames0
        CFI CodeAlign 2
        CFI DataAlign 4
        CFI ReturnAddress ?RET CODE
        CFI CFA R13+0
        CFI R0 Undefined
        CFI R1 Undefined
        CFI R2 Undefined
        CFI R3 Undefined
        CFI R4 SameValue
        CFI R5 SameValue
        CFI R6 SameValue
        CFI R7 SameValue
        CFI R8 SameValue
        CFI R9 SameValue
        CFI R10 SameValue
        CFI R11 SameValue
        CFI R12 Undefined
        CFI CPSR SameValue
        CFI R14 Undefined
        CFI SPSR SameValue
        CFI ?RET R14
        CFI EndCommon cfiCommon0
        
        
        CFI Common cfiCommon1 Using cfiNames0
        CFI CodeAlign 4
        CFI DataAlign 4
        CFI ReturnAddress ?RET CODE
        CFI CFA R13+0
        CFI R0 Undefined
        CFI R1 Undefined
        CFI R2 Undefined
        CFI R3 Undefined
        CFI R4 SameValue
        CFI R5 SameValue
        CFI R6 SameValue
        CFI R7 SameValue
        CFI R8 SameValue
        CFI R9 SameValue
        CFI R10 SameValue
        CFI R11 SameValue
        CFI R12 Undefined
        CFI CPSR SameValue
        CFI R14 Undefined
        CFI SPSR SameValue
        CFI ?RET R14
        CFI EndCommon cfiCommon1
        
InitConfig          SYMBOL "InitConfig"
??InitConfig??rT    SYMBOL "??rT", InitConfig
LoadConfigData      SYMBOL "LoadConfigData"
??LoadConfigData??rT SYMBOL "??rT", LoadConfigData
SaveConfigData      SYMBOL "SaveConfigData"
??SaveConfigData??rT SYMBOL "??rT", SaveConfigData

        EXTERN cfghdr0

// E:\Ivo\arm\IVOPLAY\conf_loader.c
//    1 #include "..\inc\swilib.h"
//    2 #include "..\inc\cfg_items.h"
//    3 #include "conf_loader.h"
//    4 

        RSEG DATA_I:DATA:SORT:NOROOT(2)
//    5 const char *successed_config_filename="";
successed_config_filename:
        DS8 4
        REQUIRE `?<Initializer for successed_config_filename>`

        RSEG CODE:CODE:NOROOT(2)
        CFI Block cfiBlock0 Using cfiCommon0
        CFI NoFunction
        THUMB
??SaveConfigData??rT:
        BX       PC
        Nop      
        CFI EndBlock cfiBlock0
        REQUIRE SaveConfigData
//    6 
//    7 #pragma segment="CONFIG_C"

        RSEG CODE:CODE:NOROOT(2)
        CFI Block cfiBlock1 Using cfiCommon1
        CFI Function SaveConfigData
        ARM
//    8 int SaveConfigData(const char *fname)
//    9 {
SaveConfigData:
        PUSH     {R4-R7,LR}
        CFI ?RET Frame(CFA, -4)
        CFI R7 Frame(CFA, -8)
        CFI R6 Frame(CFA, -12)
        CFI R5 Frame(CFA, -16)
        CFI R4 Frame(CFA, -20)
        CFI CFA R13+20
        SUB      SP,SP,#+4
        CFI CFA R13+24
//   10   int f;
//   11   unsigned int ul;
//   12   int result=-1;
        MVN      R4,#+0
//   13   unsigned int wlen;
//   14   unsigned int len=(char *)__segment_end("CONFIG_C")-(char *)__segment_begin("CONFIG_C");
        LDR      R5,??SaveConfigData_0  ;; SFE(CONFIG_C) - SFB(CONFIG_C)
//   15 
//   16   if ((f=fopen(fname,A_WriteOnly+A_BIN+A_Create+A_Truncate,P_WRITE,&ul))!=-1)
        MOV      R3,SP
        MOV      R2,#+256
        MOV      R1,#+1
        ORR      R1,R1,#0x8300
        SWI      +10
        MOV      R6,R0
        CMN      R6,#+1
        BEQ      ??SaveConfigData_1
//   17   {
//   18     wlen=fwrite(f,__segment_begin("CONFIG_C"),len,&ul);
        MOV      R3,SP
        MOV      R2,R5
        LDR      R1,??SaveConfigData_0+0x4  ;; SFB(CONFIG_C)
        SWI      +12
        MOV      R7,R0
//   19     fclose(f,&ul);
        MOV      R1,SP
        MOV      R0,R6
        SWI      +13
//   20     if (wlen==len) result=0;
        CMP      R7,R5
        MOVEQ    R4,#+0
//   21   }
//   22   return(result);
??SaveConfigData_1:
        MOV      R0,R4
        ADD      SP,SP,#+4        ;; stack cleaning
        CFI CFA R13+20
        POP      {R4-R7,PC}       ;; return
        DATA
??SaveConfigData_0:
        DC32     SFE(CONFIG_C) - SFB(CONFIG_C)
        DC32     SFB(CONFIG_C)
        CFI EndBlock cfiBlock1
//   23 }

        RSEG CODE:CODE:NOROOT(2)
        CFI Block cfiBlock2 Using cfiCommon0
        CFI NoFunction
        THUMB
??LoadConfigData??rT:
        BX       PC
        Nop      
        CFI EndBlock cfiBlock2
        REQUIRE LoadConfigData
//   24 
//   25 
//   26 #pragma segment="CONFIG_C"

        RSEG CODE:CODE:NOROOT(2)
        CFI Block cfiBlock3 Using cfiCommon1
        CFI Function LoadConfigData
        ARM
//   27 int LoadConfigData(const char *fname)
//   28 {
LoadConfigData:
        PUSH     {R4-R11,LR}
        CFI ?RET Frame(CFA, -4)
        CFI R11 Frame(CFA, -8)
        CFI R10 Frame(CFA, -12)
        CFI R9 Frame(CFA, -16)
        CFI R8 Frame(CFA, -20)
        CFI R7 Frame(CFA, -24)
        CFI R6 Frame(CFA, -28)
        CFI R5 Frame(CFA, -32)
        CFI R4 Frame(CFA, -36)
        CFI CFA R13+36
        SUB      SP,SP,#+4
        CFI CFA R13+40
        MOV      R4,R0
//   29   int f;
//   30   unsigned int ul;
//   31   char *buf;
//   32   int result=0;
        MOV      R5,#+0
//   33   void *cfg;
//   34   unsigned int rlen, end;
//   35 
//   36   extern const CFG_HDR cfghdr0; //first var in CONFIG
//   37   cfg=(void*)&cfghdr0;
        LDR      R6,??LoadConfigData_0  ;; cfghdr0
//   38 
//   39   unsigned int len=(int)__segment_end("CONFIG_C")-(int)__segment_begin("CONFIG_C");
        LDR      R7,??LoadConfigData_0+0x4  ;; SFE(CONFIG_C) - SFB(CONFIG_C)
//   40 
//   41   if (!(buf=malloc(len))) return -1;
        MOV      R0,R7
        SWI      +20
        MOVS     R8,R0
        MVNEQ    R0,R5
        BEQ      ??LoadConfigData_1
//   42   if ((f=fopen(fname,A_ReadOnly+A_BIN,P_READ,&ul))!=-1)
        MOV      R3,SP
        MOV      R2,#+128
        MOV      R1,#+32768
        MOV      R0,R4
        SWI      +10
        MOV      R10,R0
        CMN      R10,#+1
        BEQ      ??LoadConfigData_2
//   43   {
//   44     rlen=fread(f,buf,len,&ul);
        MOV      R3,SP
        MOV      R2,R7
        MOV      R1,R8
        SWI      +11
        MOV      R9,R0
//   45     end=lseek(f,0,S_END,&ul,&ul);
        MOV      R0,SP
        PUSH     {R0}
        CFI CFA R13+44
        ADD      R3,SP,#+4
        MOV      R2,#+2
        MOV      R1,#+0
        MOV      R0,R10
        SWI      +15
        MOV      R11,R0
//   46     fclose(f,&ul);
        ADD      R1,SP,#+4
        MOV      R0,R10
        SWI      +13
//   47     if (rlen!=end || rlen!=len)  goto L_SAVENEWCFG;
        CMP      R9,R11
        ADD      SP,SP,#+4        ;; stack cleaning
        CFI CFA R13+40
        CMPEQ    R9,R7
        BNE      ??LoadConfigData_2
//   48     memcpy(cfg,buf,len);
        MOV      R2,R7
        MOV      R1,R8
        MOV      R0,R6
        SWI      +286
        B        ??LoadConfigData_3
//   49   }
//   50   else
//   51   {
//   52   L_SAVENEWCFG:
//   53     result=SaveConfigData(fname);
??LoadConfigData_2:
        MOV      R0,R4
        BL       SaveConfigData
        MOV      R5,R0
//   54   }
//   55   mfree(buf);
??LoadConfigData_3:
        MOV      R0,R8
        SWI      +21
//   56   if (result>=0) successed_config_filename=fname;
        CMP      R5,#+0
        LDRPL    R0,??LoadConfigData_0+0x8  ;; successed_config_filename
        STRPL    R4,[R0, #+0]
//   57   return(result);
        MOV      R0,R5
??LoadConfigData_1:
        ADD      SP,SP,#+4        ;; stack cleaning
        CFI CFA R13+36
        POP      {R4-R11,PC}      ;; return
        DATA
??LoadConfigData_0:
        DC32     cfghdr0
        DC32     SFE(CONFIG_C) - SFB(CONFIG_C)
        DC32     successed_config_filename
        CFI EndBlock cfiBlock3
//   58 }

        RSEG CODE:CODE:NOROOT(2)
        CFI Block cfiBlock4 Using cfiCommon0
        CFI NoFunction
        THUMB
??InitConfig??rT:
        BX       PC
        Nop      
        CFI EndBlock cfiBlock4
        REQUIRE InitConfig
//   59 

        RSEG CODE:CODE:NOROOT(2)
        CFI Block cfiBlock5 Using cfiCommon1
        CFI Function InitConfig
        ARM
//   60 void InitConfig()
//   61 {
InitConfig:
        PUSH     {LR}
        CFI ?RET Frame(CFA, -4)
        CFI CFA R13+4
//   62   if (LoadConfigData("4:\\ZBin\\etc\\Ivoplay.bcfg")<0)
        LDR      R0,??InitConfig_0  ;; `?<Constant "4:\\\\ZBin\\\\etc\\\\Ivoplay.bcfg">`
        BL       LoadConfigData
        CMP      R0,#+0
        POPPL    {PC}
//   63   {
//   64     LoadConfigData("0:\\ZBin\\etc\\Ivoplay.bcfg");
        LDR      R0,??InitConfig_0+0x4  ;; `?<Constant "0:\\\\ZBin\\\\etc\\\\Ivoplay.bcfg">`
        POP      {LR}             ;; Pop
        B        LoadConfigData   ;; tailcall
        DATA
??InitConfig_0:
        DC32     `?<Constant "4:\\\\ZBin\\\\etc\\\\Ivoplay.bcfg">`
        DC32     `?<Constant "0:\\\\ZBin\\\\etc\\\\Ivoplay.bcfg">`
        CFI EndBlock cfiBlock5
//   65   }
//   66 }

        RSEG DATA_ID:CONST:SORT:NOROOT(2)
`?<Initializer for successed_config_filename>`:
        DATA
        DC32 `?<Constant "">`

        RSEG DATA_ID:CONST:SORT:NOROOT(2)
`?*?DATA_ID`:

        RSEG INITTAB:CODE:ROOT(2)
        DATA
?init?tab?DATA_I:
        DCD      sfe(DATA_I) - sfb(DATA_I), sfb(DATA_I), sfb(DATA_ID)

        RSEG CONFIG_C:DATA:REORDER:NOROOT(0)

        RSEG DATA_C:CONST:SORT:NOROOT(0)
`?<Constant "">`:
        DATA
        DC8 ""

        RSEG DATA_C:CONST:SORT:NOROOT(2)
`?<Constant "0:\\\\ZBin\\\\etc\\\\Ivoplay.bcfg">`:
        DATA
        DC8 "0:\\ZBin\\etc\\Ivoplay.bcfg"
        DC8 0, 0, 0

        RSEG DATA_C:CONST:SORT:NOROOT(2)
`?<Constant "4:\\\\ZBin\\\\etc\\\\Ivoplay.bcfg">`:
        DATA
        DC8 "4:\\ZBin\\etc\\Ivoplay.bcfg"
        DC8 0, 0, 0

        END
// 
// 392 bytes in segment CODE
//  57 bytes in segment DATA_C
//   4 bytes in segment DATA_I
//   4 bytes in segment DATA_ID
//  12 bytes in segment INITTAB
// 
// 380 bytes of CODE  memory (+ 24 bytes shared)
//  61 bytes of CONST memory
//   4 bytes of DATA  memory
//
//Errors: none
//Warnings: none
