mb/google/brya/var/omnigul: Modify NVMe and UFS Storage support
[coreboot.git] / payloads / libpayload / gdb / commands.c
blob63188a4d2fd3ed706df305dfb4e59736c23d512a
1 /*
2 * Copyright 2014 Google Inc.
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License as
6 * published by the Free Software Foundation; either version 2 of
7 * the License, or (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but without any warranty; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
15 #include <arch/cache.h>
16 #include <gdb.h>
17 #include <libpayload.h>
19 static void gdb_get_last_signal(struct gdb_message *command,
20 int offset, struct gdb_message *reply)
22 gdb_message_add_string(reply, "S");
23 gdb_message_encode_bytes(reply, &gdb_state.signal, 1);
26 static void gdb_read_general_registers(struct gdb_message *command,
27 int offset, struct gdb_message *reply)
29 gdb_arch_encode_regs(reply);
32 static void gdb_write_general_registers(struct gdb_message *command,
33 int offset, struct gdb_message *reply)
35 gdb_arch_decode_regs(offset, command);
36 gdb_message_add_string(reply, "OK");
39 static void gdb_read_memory(struct gdb_message *command,
40 int offset, struct gdb_message *reply)
42 int tok = gdb_message_tokenize(command, &offset);
43 uintptr_t addr = gdb_message_decode_int(command, tok, offset - 1 - tok);
44 size_t length = gdb_message_decode_int(command, offset,
45 command->used - offset);
47 gdb_message_encode_bytes(reply, (void *)addr, length);
50 static void gdb_write_memory(struct gdb_message *command,
51 int offset, struct gdb_message *reply)
53 int tok = gdb_message_tokenize(command, &offset);
54 uintptr_t addr = gdb_message_decode_int(command, tok, offset - 1 - tok);
55 tok = gdb_message_tokenize(command, &offset);
56 size_t length = gdb_message_decode_int(command, tok, offset - 1 - tok);
58 die_if(length * 2 != command->used - offset, "Invalid length field in "
59 "GDB command: %.*s", command->used, command->buf);
61 gdb_message_decode_bytes(command, offset, (void *)addr, length);
62 cache_sync_instructions();
63 gdb_message_add_string(reply, "OK");
66 static void gdb_continue(struct gdb_message *command,
67 int offset, struct gdb_message *reply)
69 /* Disable single step if it's still on. */
70 gdb_arch_set_single_step(0);
72 /* No need to support the extension that passes in new EIP/PC. */
73 if (command->used > offset)
74 gdb_message_add_string(reply, "E00");
75 else
76 gdb_state.resumed = 1;
79 static void gdb_single_step(struct gdb_message *command,
80 int offset, struct gdb_message *reply)
82 if (command->used > offset || gdb_arch_set_single_step(1))
83 gdb_message_add_string(reply, "E00");
84 else
85 gdb_state.resumed = 1;
88 struct gdb_command gdb_commands[] = {
89 { "?", &gdb_get_last_signal },
90 { "g", &gdb_read_general_registers },
91 { "G", &gdb_write_general_registers },
92 { "m", &gdb_read_memory },
93 { "M", &gdb_write_memory },
94 { "c", &gdb_continue },
95 { "s", &gdb_single_step }
97 const int gdb_command_count = ARRAY_SIZE(gdb_commands);