nexmon – Blame information for rev 1
?pathlinks?
Rev | Author | Line No. | Line |
---|---|---|---|
1 | office | 1 | /*************************************************************************** |
2 | * * |
||
3 | * ########### ########### ########## ########## * |
||
4 | * ############ ############ ############ ############ * |
||
5 | * ## ## ## ## ## ## ## * |
||
6 | * ## ## ## ## ## ## ## * |
||
7 | * ########### #### ###### ## ## ## ## ###### * |
||
8 | * ########### #### # ## ## ## ## # # * |
||
9 | * ## ## ###### ## ## ## ## # # * |
||
10 | * ## ## # ## ## ## ## # # * |
||
11 | * ############ ##### ###### ## ## ## ##### ###### * |
||
12 | * ########### ########### ## ## ## ########## * |
||
13 | * * |
||
14 | * S E C U R E M O B I L E N E T W O R K I N G * |
||
15 | * * |
||
16 | * This file is part of NexMon. * |
||
17 | * * |
||
18 | * Copyright (c) 2016 NexMon Team * |
||
19 | * * |
||
20 | * NexMon is free software: you can redistribute it and/or modify * |
||
21 | * it under the terms of the GNU General Public License as published by * |
||
22 | * the Free Software Foundation, either version 3 of the License, or * |
||
23 | * (at your option) any later version. * |
||
24 | * * |
||
25 | * NexMon is distributed in the hope that it will be useful, * |
||
26 | * but WITHOUT ANY WARRANTY; without even the implied warranty of * |
||
27 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * |
||
28 | * GNU General Public License for more details. * |
||
29 | * * |
||
30 | * You should have received a copy of the GNU General Public License * |
||
31 | * along with NexMon. If not, see <http://www.gnu.org/licenses/>. * |
||
32 | * * |
||
33 | **************************************************************************/ |
||
34 | |||
35 | #pragma NEXMON targetregion "patch" |
||
36 | |||
37 | #include <firmware_version.h> // definition of firmware version macros |
||
38 | #include <debug.h> // contains macros to access the debug hardware |
||
39 | #include <wrapper.h> // wrapper definitions for functions that already exist in the firmware |
||
40 | #include <structs.h> // structures that are used by the code in the firmware |
||
41 | #include <helper.h> // useful helper functions |
||
42 | #include <patcher.h> // macros used to craete patches such as BLPatch, BPatch, ... |
||
43 | #include <objmem.h> // Functions to access object memory |
||
44 | |||
45 | void |
||
46 | wlc_bmac_read_objmem32_objaddr(struct wlc_hw_info *wlc_hw, unsigned int objaddr, unsigned int *val) |
||
47 | { |
||
48 | volatile struct d11regs *regs; |
||
49 | |||
50 | regs = wlc_hw->regs; |
||
51 | regs->objaddr = objaddr; |
||
52 | regs->objaddr; |
||
53 | |||
54 | *val = regs->objdata; |
||
55 | } |
||
56 | |||
57 | void |
||
58 | wlc_bmac_read_objmem32(struct wlc_hw_info *wlc_hw, unsigned int offset, unsigned int *val, int sel) |
||
59 | { |
||
60 | wlc_bmac_read_objmem32_objaddr(wlc_hw, sel | ((offset & 0xfffffffc) >> 2), val); |
||
61 | } |
||
62 | |||
63 | void |
||
64 | wlc_bmac_read_objmem64_objaddr(struct wlc_hw_info *wlc_hw, unsigned int objaddr, unsigned int *val_low, unsigned int *val_high) |
||
65 | { |
||
66 | volatile struct d11regs *regs; |
||
67 | |||
68 | regs = wlc_hw->regs; |
||
69 | regs->objaddr = objaddr; |
||
70 | regs->objaddr; |
||
71 | |||
72 | *val_low = regs->objdata; |
||
73 | |||
74 | regs->objaddr = objaddr + 1; |
||
75 | regs->objaddr; |
||
76 | |||
77 | *val_high = regs->objdata; |
||
78 | } |
||
79 | |||
80 | void |
||
81 | wlc_bmac_read_objmem64(struct wlc_hw_info *wlc_hw, unsigned int offset, unsigned int *val_low, unsigned int *val_high, int sel) |
||
82 | { |
||
83 | wlc_bmac_read_objmem64_objaddr(wlc_hw, sel | ((offset & 0xfffffff8) >> 2), val_low, val_high); |
||
84 | } |
||
85 | |||
86 | void |
||
87 | wlc_bmac_write_objmem64_objaddr(struct wlc_hw_info *wlc_hw, unsigned int objaddr, unsigned int val_low, unsigned int val_high) |
||
88 | { |
||
89 | volatile struct d11regs *regs; |
||
90 | |||
91 | regs = wlc_hw->regs; |
||
92 | regs->objaddr = objaddr; |
||
93 | regs->objaddr; |
||
94 | |||
95 | regs->objdata = val_low; |
||
96 | |||
97 | regs->objaddr = objaddr + 1; |
||
98 | regs->objaddr; |
||
99 | |||
100 | regs->objdata = val_high; |
||
101 | } |
||
102 | |||
103 | void |
||
104 | wlc_bmac_write_objmem64(struct wlc_hw_info *wlc_hw, unsigned int offset, unsigned int val_low, unsigned int val_high, int sel) |
||
105 | { |
||
106 | wlc_bmac_write_objmem64_objaddr(wlc_hw, sel | ((offset & 0xfffffff8) >> 2), val_low, val_high); |
||
107 | } |
||
108 | |||
109 | void |
||
110 | wlc_bmac_write_objmem32_objaddr(struct wlc_hw_info *wlc_hw, unsigned int objaddr, unsigned int value) |
||
111 | { |
||
112 | unsigned int low; |
||
113 | unsigned int high; |
||
114 | |||
115 | // first we read in one QWORD of existing bytes stored in the d11 object memory |
||
116 | wlc_bmac_read_objmem64_objaddr(wlc_hw, objaddr, &low, &high); |
||
117 | |||
118 | // then we replace the DWORD that should be written in this QWORD |
||
119 | if (objaddr & 1) { |
||
120 | high = value; |
||
121 | } else { |
||
122 | low = value; |
||
123 | } |
||
124 | |||
125 | // then we write back the changed QWORD into the object memory. We always access |
||
126 | // a whole QWORD to be able to read back the written value at the next call to the |
||
127 | // wlc_bmac_read_objmem64 function. Writing less than 64 bits (one QWORD) does not |
||
128 | // deliver the new but the old value on the next read. |
||
129 | wlc_bmac_write_objmem64_objaddr(wlc_hw, objaddr, low, high); |
||
130 | } |
||
131 | |||
132 | void |
||
133 | wlc_bmac_write_objmem32(struct wlc_hw_info *wlc_hw, unsigned int offset, unsigned int value, int sel) |
||
134 | { |
||
135 | wlc_bmac_write_objmem32_objaddr(wlc_hw, sel | ((offset & 0xfffffff8) >> 2), value); |
||
136 | } |
||
137 | |||
138 | void |
||
139 | wlc_bmac_write_objmem_byte(struct wlc_hw_info *wlc_hw, unsigned int offset, unsigned char value, int sel) |
||
140 | { |
||
141 | unsigned int low; |
||
142 | unsigned int high; |
||
143 | |||
144 | // first we read in one QWORD of existing bytes stored in the d11 object memory |
||
145 | wlc_bmac_read_objmem64(wlc_hw, offset, &low, &high, sel); |
||
146 | |||
147 | // then we replace the byte that should be written in this QWORD |
||
148 | if (offset & 4) { |
||
149 | ((unsigned char *) &high)[offset & 3] = value; |
||
150 | } else { |
||
151 | ((unsigned char *) &low)[offset & 3] = value; |
||
152 | } |
||
153 | |||
154 | // then we write back the changed QWORD into the object memory. We always access |
||
155 | // a whole QWORD to be able to read back the written value at the next call to the |
||
156 | // wlc_bmac_read_objmem64 function. Writing less than 64 bits (one QWORD) does not |
||
157 | // deliver the new but the old value on the next read. |
||
158 | wlc_bmac_write_objmem64(wlc_hw, offset, low, high, sel); |
||
159 | } |
||
160 | |||
161 | unsigned char |
||
162 | wlc_bmac_read_objmem_byte(struct wlc_hw_info *wlc_hw, unsigned int offset, int sel) |
||
163 | { |
||
164 | unsigned int val; |
||
165 | |||
166 | wlc_bmac_read_objmem32(wlc_hw, offset, &val, sel); |
||
167 | |||
168 | return ((unsigned char *) &val)[offset & 0x3]; |
||
169 | } |