Rev 3093 | Go to most recent revision | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 3093 | Rev 3108 | ||
---|---|---|---|
1 | /* |
1 | /* |
2 | * Copyright (c) 2008 Jiri Svoboda |
2 | * Copyright (c) 2008 Jiri Svoboda |
3 | * All rights reserved. |
3 | * All rights reserved. |
4 | * |
4 | * |
5 | * Redistribution and use in source and binary forms, with or without |
5 | * Redistribution and use in source and binary forms, with or without |
6 | * modification, are permitted provided that the following conditions |
6 | * modification, are permitted provided that the following conditions |
7 | * are met: |
7 | * are met: |
8 | * |
8 | * |
9 | * - Redistributions of source code must retain the above copyright |
9 | * - Redistributions of source code must retain the above copyright |
10 | * notice, this list of conditions and the following disclaimer. |
10 | * notice, this list of conditions and the following disclaimer. |
11 | * - Redistributions in binary form must reproduce the above copyright |
11 | * - Redistributions in binary form must reproduce the above copyright |
12 | * notice, this list of conditions and the following disclaimer in the |
12 | * notice, this list of conditions and the following disclaimer in the |
13 | * documentation and/or other materials provided with the distribution. |
13 | * documentation and/or other materials provided with the distribution. |
14 | * - The name of the author may not be used to endorse or promote products |
14 | * - The name of the author may not be used to endorse or promote products |
15 | * derived from this software without specific prior written permission. |
15 | * derived from this software without specific prior written permission. |
16 | * |
16 | * |
17 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR |
17 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR |
18 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES |
18 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES |
19 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. |
19 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. |
20 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, |
20 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, |
21 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT |
21 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT |
22 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
22 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
23 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
23 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
24 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
24 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
25 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF |
25 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF |
26 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
26 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
27 | */ |
27 | */ |
28 | 28 | ||
29 | /** @addtogroup debug |
29 | /** @addtogroup debug |
30 | * @{ |
30 | * @{ |
31 | */ |
31 | */ |
32 | /** @file |
32 | /** @file |
33 | */ |
33 | */ |
34 | 34 | ||
35 | #include <stdio.h> |
35 | #include <stdio.h> |
36 | #include <assert.h> |
36 | #include <assert.h> |
37 | #include <errno.h> |
37 | #include <errno.h> |
38 | #include <sys/types.h> |
38 | #include <sys/types.h> |
39 | #include <udebug.h> |
39 | #include <udebug.h> |
40 | 40 | ||
41 | #include "../../../main.h" |
41 | #include "../../main.h" |
42 | #include "../../../cons.h" |
42 | #include "../../cons.h" |
43 | #include "../include/bstore.h" |
43 | #include "bstore.h" |
44 | 44 | ||
45 | void bstore_initialize(bstore_t *bs) |
45 | void bstore_initialize(bstore_t *bs) |
46 | { |
46 | { |
47 | bs->valid = false; |
47 | bs->valid = false; |
48 | } |
48 | } |
49 | 49 | ||
50 | int bstore_save(bstore_t *bs, uintptr_t addr) |
50 | int bstore_save(bstore_t *bs, uintptr_t addr) |
51 | { |
51 | { |
52 | uint32_t v; |
52 | uint32_t v; |
53 | int rc; |
53 | int rc; |
54 | 54 | ||
55 | assert(bs->valid == false); |
55 | assert(bs->valid == false); |
56 | 56 | ||
57 | rc = udebug_mem_read(app_phone, &v, addr, sizeof(uint32_t)); |
57 | rc = udebug_mem_read(app_phone, &v, addr, sizeof(uint32_t)); |
58 | if (rc == EOK) { |
58 | if (rc == EOK) { |
59 | bs->valid = true; |
59 | bs->valid = true; |
60 | bs->address = addr; |
60 | bs->address = addr; |
61 | bs->value = v; |
61 | bs->value = v; |
62 | } else { |
62 | } else { |
63 | cons_printf("Error reading memory address 0x%zx\n", addr); |
63 | cons_printf("Error reading memory address 0x%zx\n", addr); |
64 | } |
64 | } |
65 | 65 | ||
66 | return rc; |
66 | return rc; |
67 | } |
67 | } |
68 | 68 | ||
69 | int bstore_push(bstore_t *bs, uintptr_t addr, uint32_t value) |
69 | int bstore_push(bstore_t *bs, uintptr_t addr, uint32_t value) |
70 | { |
70 | { |
71 | int rc; |
71 | int rc; |
72 | 72 | ||
73 | rc = bstore_save(bs, addr); |
73 | rc = bstore_save(bs, addr); |
74 | if (rc != EOK) return rc; |
74 | if (rc != EOK) return rc; |
75 | 75 | ||
76 | rc = udebug_mem_write(app_phone, &value, addr, sizeof(uint32_t)); |
76 | rc = udebug_mem_write(app_phone, &value, addr, sizeof(uint32_t)); |
77 | if (rc != EOK) { |
77 | if (rc != EOK) { |
78 | cons_printf("Error writing memory address 0x%zx\n", addr); |
78 | cons_printf("Error writing memory address 0x%zx\n", addr); |
79 | bstore_empty(bs); |
79 | bstore_empty(bs); |
80 | return rc; |
80 | return rc; |
81 | } |
81 | } |
82 | 82 | ||
83 | return EOK; |
83 | return EOK; |
84 | } |
84 | } |
85 | 85 | ||
86 | int bstore_pop(bstore_t *bs) |
86 | int bstore_pop(bstore_t *bs) |
87 | { |
87 | { |
88 | int rc; |
88 | int rc; |
89 | 89 | ||
90 | assert(bs->valid == true); |
90 | assert(bs->valid == true); |
91 | rc = udebug_mem_write(app_phone, &bs->value, bs->address, |
91 | rc = udebug_mem_write(app_phone, &bs->value, bs->address, |
92 | sizeof(uint32_t)); |
92 | sizeof(uint32_t)); |
93 | 93 | ||
94 | if (rc == EOK) { |
94 | if (rc == EOK) { |
95 | bs->valid = false; |
95 | bs->valid = false; |
96 | } else { |
96 | } else { |
97 | cons_printf("Error writing memory address 0x%zx\n", |
97 | cons_printf("Error writing memory address 0x%zx\n", |
98 | bs->address); |
98 | bs->address); |
99 | } |
99 | } |
100 | 100 | ||
101 | return rc; |
101 | return rc; |
102 | } |
102 | } |
103 | 103 | ||
104 | void bstore_empty(bstore_t *bs) |
104 | void bstore_empty(bstore_t *bs) |
105 | { |
105 | { |
106 | assert(bs->valid == true); |
106 | assert(bs->valid == true); |
107 | bs->valid = false; |
107 | bs->valid = false; |
108 | } |
108 | } |
109 | 109 | ||
110 | /** @} |
110 | /** @} |
111 | */ |
111 | */ |
112 | 112 |