1 /* memrw.c - command to read / write physical memory */
3 * GRUB -- GRand Unified Bootloader
4 * Copyright (C) 2009 Free Software Foundation, Inc.
6 * GRUB is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation, either version 3 of the License, or
9 * (at your option) any later version.
11 * GRUB is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with GRUB. If not, see <http://www.gnu.org/licenses/>.
21 #include <grub/misc.h>
22 #include <grub/command.h>
24 static grub_command_t cmd_read_byte
, cmd_read_word
, cmd_read_dword
;
25 static grub_command_t cmd_write_byte
, cmd_write_word
, cmd_write_dword
;
28 grub_cmd_read (grub_command_t cmd
, int argc
, char **argv
)
30 grub_target_addr_t addr
;
34 return grub_error (GRUB_ERR_BAD_ARGUMENT
, "Invalid number of arguments");
36 addr
= grub_strtoul (argv
[0], 0, 0);
37 if (cmd
->name
[5] == 'd')
38 value
= *((grub_uint32_t
*) addr
);
39 else if (cmd
->name
[5] == 'w')
40 value
= *((grub_uint16_t
*) addr
);
42 value
= *((grub_uint8_t
*) addr
);
44 grub_printf ("0x%x\n", value
);
50 grub_cmd_write (grub_command_t cmd
, int argc
, char **argv
)
52 grub_target_addr_t addr
;
56 return grub_error (GRUB_ERR_BAD_ARGUMENT
, "Invalid number of arguments");
58 addr
= grub_strtoul (argv
[0], 0, 0);
59 value
= grub_strtoul (argv
[1], 0, 0);
60 if (cmd
->name
[6] == 'd')
61 *((grub_uint32_t
*) addr
) = value
;
62 else if (cmd
->name
[6] == 'w')
63 *((grub_uint16_t
*) addr
) = (grub_uint16_t
) value
;
65 *((grub_uint8_t
*) addr
) = (grub_uint8_t
) value
;
73 grub_register_command ("read_byte", grub_cmd_read
,
74 "read_byte ADDR", "read byte.");
76 grub_register_command ("read_word", grub_cmd_read
,
77 "read_word ADDR", "read word.");
79 grub_register_command ("read_dword", grub_cmd_read
,
80 "read_dword ADDR", "read dword.");
82 grub_register_command ("write_byte", grub_cmd_write
,
83 "write_byte ADDR VALUE", "write byte.");
85 grub_register_command ("write_word", grub_cmd_write
,
86 "write_word ADDR VALUE", "write word.");
88 grub_register_command ("write_dword", grub_cmd_write
,
89 "write_dword ADDR VALUE", "write dword.");
94 grub_unregister_command (cmd_read_byte
);
95 grub_unregister_command (cmd_read_word
);
96 grub_unregister_command (cmd_read_dword
);
97 grub_unregister_command (cmd_write_byte
);
98 grub_unregister_command (cmd_write_word
);
99 grub_unregister_command (cmd_write_dword
);