Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding support for 'A' (python bytes) memory type, to allow reading and writing of arbitrary data. #213

Open
wants to merge 1 commit into
base: MicroPythonTestFramework
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 25 additions & 2 deletions MicroPythonPkg/MicroPythonDxe/Uefi/objuefi.c
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ STATIC char type_size [] = {
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
// 'B' 'E' 'F' 'G' 'H' 'I' 'L' 'N' 'O'
0, 0, sizeof(UINT8), 0, 0, sizeof(EFI_STATUS), sizeof(void*), sizeof(EFI_GUID), sizeof(UINT16), sizeof(unsigned int), 0, 0, sizeof(UINT32), 0, sizeof(UINTN), 0,
// 'A' 'B' 'E' 'F' 'G' 'H' 'I' 'L' 'N' 'O'
0, sizeof(UINT8), sizeof(UINT8), 0, 0, sizeof(EFI_STATUS), sizeof(void*), sizeof(EFI_GUID), sizeof(UINT16), sizeof(unsigned int), 0, 0, sizeof(UINT32), 0, sizeof(UINTN), 0,
// 'P' 'Q' 'T'
sizeof(void*), sizeof(UINT64), 0, 0, sizeof(EFI_HANDLE), 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
// 'a' 'b' 'h' 'i' 'l' 'n'
Expand Down Expand Up @@ -777,6 +777,14 @@ STATIC mp_obj_t get_value(mp_obj_mem_t *self, mp_obj_t index_in)
FreePool(str);
break;

case 'A':
if (index_in == mp_const_none) {
value = mp_obj_new_bytes(self->addr, self->size);
} else {
value = MP_OBJ_NEW_SMALL_INT(((UINT8 *)addr)[index]);
}
break;

case 'a':
if (index_in == mp_const_none) {
len = AsciiStrLen(addr);
Expand Down Expand Up @@ -996,6 +1004,21 @@ STATIC void set_value(mp_obj_mem_t *self, mp_obj_t index_in, mp_obj_t value)
}
break;

case 'A':
if (index_in == mp_const_none && MP_OBJ_IS_STR_OR_BYTES(value)) {
mp_buffer_info_t bufinfo;
mp_get_buffer(value, &bufinfo, MP_BUFFER_READ);

if (bufinfo.buf == NULL || bufinfo.len > self->size) {
mp_raise_msg(&mp_type_ValueError, "Out of buffer");
}
SetMem(self->addr, self->size, 0);
CopyMem(self->addr, bufinfo.buf, bufinfo.len);
} else {
set_mem_from_obj(self, value, index, len - index);
}
break;

case 'a':
if (index_in == mp_const_none && MP_OBJ_IS_STR_OR_BYTES(value)) {
str = mp_obj_str_get_data(value, &len);
Expand Down