Skip to content

Commit

Permalink
core: drivers: Embed console data in semihosting console driver
Browse files Browse the repository at this point in the history
Semihosting console driver is a cross-platform console driver (i.e., ARM
and RISC-V both supports semihosting). It is unnecessary to maintain the
private console data in the platform sources. Embed the semihosting
console data into the semihosting console driver.

Signed-off-by: Alvin Chang <alvinga@andestech.com>
  • Loading branch information
gagachang committed Feb 27, 2024
1 parent dc4d7ad commit 07bc659
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 22 deletions.
30 changes: 23 additions & 7 deletions core/drivers/semihosting_console.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,25 @@
*/

#include <compiler.h>
#include <console.h>
#include <drivers/semihosting_console.h>
#include <drivers/serial.h>
#include <kernel/semihosting.h>
#include <util.h>

/*
* struct semihosting_console_data - Structure for semihosting console driver
* @chip - General structure for each serial chip
* @fd - Handle of the file at @file_path when semihosting_console_init() is
* called, or -1 if using the semihosting console
*/
struct semihosting_console_data {
struct serial_chip chip;
int fd;
};

static struct semihosting_console_data sh_console_data __nex_bss;

static void semihosting_console_putc(struct serial_chip *chip __unused, int ch)
{
semihosting_sys_writec(ch);
Expand Down Expand Up @@ -37,17 +52,18 @@ static const struct serial_ops semihosting_console_fd_ops = {
};
DECLARE_KEEP_PAGER(semihosting_console_fd_ops);

void semihosting_console_init(struct semihosting_console_data *pd,
const char *file_path)
void semihosting_console_init(const char *file_path)
{
if (file_path) {
/* Output log to given file on the semihosting host system. */
pd->chip.ops = &semihosting_console_fd_ops;
pd->fd = semihosting_open(file_path,
O_RDWR | O_CREAT | O_TRUNC);
sh_console_data.chip.ops = &semihosting_console_fd_ops;
sh_console_data.fd =
semihosting_open(file_path, O_RDWR | O_CREAT | O_TRUNC);
} else {
/* Output log to semihosting host debug console. */
pd->chip.ops = &semihosting_console_ops;
pd->fd = -1;
sh_console_data.chip.ops = &semihosting_console_ops;
sh_console_data.fd = -1;
}

register_serial_console(&sh_console_data.chip);
}
16 changes: 1 addition & 15 deletions core/include/drivers/semihosting_console.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,27 +5,13 @@
#ifndef __DRIVERS_SEMIHOSTING_CONSOLE_H
#define __DRIVERS_SEMIHOSTING_CONSOLE_H

#include <drivers/serial.h>

/*
* struct semihosting_console_data - Structure for semihosting console driver
* @chip - General structure for each serial chip
* @fd - Handle of the file at @file_path when semihosting_console_init() is
* called, or -1 if using the semihosting console
*/
struct semihosting_console_data {
struct serial_chip chip;
int fd;
};

/*
* Initialize console which uses architecture-specific semihosting mechanism.
* If @file_path is not NULL, OP-TEE OS will try to output log to that file,
* which is on the semihosting host system.
* Otherwise, if @file_path is NULL, OP-TEE OS will try to output log to the
* semihosting host debug console.
*/
void semihosting_console_init(struct semihosting_console_data *pd,
const char *file_path);
void semihosting_console_init(const char *file_path);

#endif /* __DRIVERS_SEMIHOSTING_CONSOLE_H */

0 comments on commit 07bc659

Please sign in to comment.