Initial cut of the open ath9k htc firmware.
[open-ath9k-htc-firmware.git] / target_firmware / magpie_fw_dev / target / inc / k2 / athos_api.h
1 #ifndef __ATHOS_API_H__
2 #define __ATHOS_API_H__
3
4 /*
5  * This file contains wrappers to OS operating system functions
6  * that are available in the Athos version of the operating system.
7  *
8  * Target software must always use these wrappers to access OS
9  * services -- it may not access any OS services directly.
10  *
11  * These wrappers are intended to provide OS-independence for applications.
12  * Using this header file, an application should be able to compile and
13  * fully link without any other OS header files, source files, or
14  * binary files.
15  */
16
17 #include <osapi.h>
18 #include "dt_defs.h"
19 #include "cmnos_api.h"
20 #include "Magpie_api.h"
21
22 /* ROM Patch API */
23
24 /* save the ROM printf function point */
25 extern uint32_t save_cmnos_printf;
26
27 extern unsigned int _data_start_in_rom;
28 extern unsigned int _data_start;
29 extern unsigned int _data_end;
30 extern unsigned int _bss_start;
31 extern unsigned int _bss_end;
32 extern unsigned int _stack_sentry;
33 extern unsigned int __stack;
34 extern unsigned int _fw_image_end;
35
36 #if defined(__XTENSA__)
37 #define START_DATA      _data_start
38 #define END_DATA        _data_end
39 #define START_BSS       _bss_start
40 #define END_BSS         _bss_end
41
42 #define STACK_START  _stack_sentry
43 #define STACK_END    __stack
44 #endif
45
46 struct _A_os_linkage_check {
47         int version;
48         int table;
49 };
50
51 /* 
52  * A_INIT() handles any initialization needed by the OS abstraction,
53  * and it clears the application's BSS, if necessary.  (Application BSS
54  * is not cleared if the application is linked into a single image that
55  * includes AthOS.)
56  *
57  * A_INIT() must be called first thing in the application (from app_start)
58  * in order to guarantee that BSS has been cleared properly.
59  */
60 static INLINE int
61 A_INIT(void)
62 {
63         struct _A_os_linkage_check link_check;
64         unsigned int *clrptr;
65     
66         if (&START_BSS != _A_MAGPIE_INDIRECTION_TABLE->cmnos.start_bss) {
67                 /* Clear BSS */
68                 for (clrptr = &START_BSS; clrptr < &END_BSS; clrptr++) {
69                         *clrptr = 0;
70                 }
71         }
72
73         /* Copy writable data from flash to RAM.  */
74         unsigned int *srcptr, *destptr;
75
76         /*
77          * The _data_start symbol points to the start of data IN FLASH.
78          * It is defined by flash.ld at application link time.  If flash.ld
79          * is not used, it is defined (on the link line) as 0.
80          */
81         static int *data_start_addr = &_data_start;
82
83         if (data_start_addr != 0) {
84                 for (srcptr = &_data_start, destptr = &START_DATA;
85                      destptr < &END_DATA;
86                      srcptr++, destptr++) {
87                         *destptr = *srcptr;
88                 }
89         }
90
91 #define OS_LINKAGE_VERSION 4
92         link_check.version = OS_LINKAGE_VERSION;
93         link_check.table = _A_MAGPIE_INDIRECTION_TABLE_SIZE;
94
95         return A_CMN(hal_linkage_check(sizeof(link_check), &link_check));
96 }
97
98 #endif /* __ATHOS_API_H__ */
99