Implement fw-cfg-read-file Forth word as a simple wrapper around fw_cfg_read_file().
Signed-off-by: Mark Cave-Ayland mark.cave-ayland@ilande.co.uk --- drivers/fw_cfg.c | 23 +++++++++++++++++++++++ include/arch/common/fw_cfg.h | 1 + libopenbios/init.c | 7 ++++++- 3 files changed, 30 insertions(+), 1 deletion(-)
diff --git a/drivers/fw_cfg.c b/drivers/fw_cfg.c index f930ea8..d72461d 100644 --- a/drivers/fw_cfg.c +++ b/drivers/fw_cfg.c @@ -114,6 +114,29 @@ fw_cfg_read_file(const char *filename, uint32_t *size) return NULL; }
+// +// ( fname fnamelen -- buf buflen -1 | 0 ) +// + +void +forth_fw_cfg_read_file(void) +{ + char *filename = pop_fstr_copy(); + char *buffer; + uint32_t size; + + buffer = fw_cfg_read_file(filename, &size); + if (buffer) { + PUSH(pointer2cell(buffer)); + PUSH(size); + PUSH(-1); + + return; + } + + PUSH(0); +} + void fw_cfg_init(void) { diff --git a/include/arch/common/fw_cfg.h b/include/arch/common/fw_cfg.h index 1c43a9d..cd2183a 100644 --- a/include/arch/common/fw_cfg.h +++ b/include/arch/common/fw_cfg.h @@ -100,6 +100,7 @@ typedef struct FWCfgFiles {
unsigned int fw_cfg_find_file(const char *filename, uint16_t *select, uint32_t *size); char *fw_cfg_read_file(const char *filename, uint32_t *size); +void forth_fw_cfg_read_file(void); #endif /* NO_OPENBIOS_PROTOS */
#endif diff --git a/libopenbios/init.c b/libopenbios/init.c index 8882bf3..aa99608 100644 --- a/libopenbios/init.c +++ b/libopenbios/init.c @@ -18,6 +18,8 @@ #include "libopenbios/openbios.h" #include "libopenbios/bindings.h" #include "libopenbios/initprogram.h" +#define NO_QEMU_PROTOS +#include "arch/common/fw_cfg.h"
void openbios_init( void ) @@ -25,7 +27,10 @@ openbios_init( void ) // Bind the saved program state context into Forth PUSH(pointer2cell((void *)&__context)); feval("['] __context cell+ !"); - + + // Bind the Forth fw_cfg file interface + bind_func("fw-cfg-read-file", forth_fw_cfg_read_file); + // Bind the C implementation of (init-program) into Forth bind_func("(init-program)", init_program);