Rev 3093 | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
3093 | svoboda | 1 | /* |
2 | * Copyright (c) 2008 Jiri Svoboda |
||
3 | * All rights reserved. |
||
4 | * |
||
5 | * Redistribution and use in source and binary forms, with or without |
||
6 | * modification, are permitted provided that the following conditions |
||
7 | * are met: |
||
8 | * |
||
9 | * - Redistributions of source code must retain the above copyright |
||
10 | * notice, this list of conditions and the following disclaimer. |
||
11 | * - Redistributions in binary form must reproduce the above copyright |
||
12 | * notice, this list of conditions and the following disclaimer in the |
||
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 |
||
15 | * derived from this software without specific prior written permission. |
||
16 | * |
||
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 |
||
19 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. |
||
20 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, |
||
21 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT |
||
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 |
||
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 |
||
26 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
||
27 | */ |
||
28 | |||
29 | /** @addtogroup debug |
||
30 | * @{ |
||
31 | */ |
||
32 | /** @file |
||
33 | */ |
||
34 | |||
35 | #include <stdio.h> |
||
36 | #include <assert.h> |
||
37 | #include <errno.h> |
||
38 | #include <sys/types.h> |
||
39 | #include <udebug.h> |
||
40 | |||
3108 | svoboda | 41 | #include "../../main.h" |
42 | #include "../../cons.h" |
||
43 | #include "bstore.h" |
||
3093 | svoboda | 44 | |
45 | void bstore_initialize(bstore_t *bs) |
||
46 | { |
||
47 | bs->valid = false; |
||
48 | } |
||
49 | |||
50 | int bstore_save(bstore_t *bs, uintptr_t addr) |
||
51 | { |
||
52 | uint32_t v; |
||
53 | int rc; |
||
54 | |||
55 | assert(bs->valid == false); |
||
56 | |||
57 | rc = udebug_mem_read(app_phone, &v, addr, sizeof(uint32_t)); |
||
58 | if (rc == EOK) { |
||
59 | bs->valid = true; |
||
60 | bs->address = addr; |
||
61 | bs->value = v; |
||
62 | } else { |
||
63 | cons_printf("Error reading memory address 0x%zx\n", addr); |
||
64 | } |
||
65 | |||
66 | return rc; |
||
67 | } |
||
68 | |||
69 | int bstore_push(bstore_t *bs, uintptr_t addr, uint32_t value) |
||
70 | { |
||
71 | int rc; |
||
72 | |||
73 | rc = bstore_save(bs, addr); |
||
74 | if (rc != EOK) return rc; |
||
75 | |||
76 | rc = udebug_mem_write(app_phone, &value, addr, sizeof(uint32_t)); |
||
77 | if (rc != EOK) { |
||
78 | cons_printf("Error writing memory address 0x%zx\n", addr); |
||
79 | bstore_empty(bs); |
||
80 | return rc; |
||
81 | } |
||
82 | |||
83 | return EOK; |
||
84 | } |
||
85 | |||
86 | int bstore_pop(bstore_t *bs) |
||
87 | { |
||
88 | int rc; |
||
89 | |||
90 | assert(bs->valid == true); |
||
91 | rc = udebug_mem_write(app_phone, &bs->value, bs->address, |
||
92 | sizeof(uint32_t)); |
||
93 | |||
94 | if (rc == EOK) { |
||
95 | bs->valid = false; |
||
96 | } else { |
||
97 | cons_printf("Error writing memory address 0x%zx\n", |
||
98 | bs->address); |
||
99 | } |
||
100 | |||
101 | return rc; |
||
102 | } |
||
103 | |||
104 | void bstore_empty(bstore_t *bs) |
||
105 | { |
||
106 | assert(bs->valid == true); |
||
107 | bs->valid = false; |
||
108 | } |
||
109 | |||
110 | /** @} |
||
111 | */ |