Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • kernel/arch/riscv64/src/drivers/ucb.c

    r28a5ebd re9bc927  
    4141static volatile uint64_t *fromhost;
    4242
    43 static outdev_operations_t htifdev_ops = {
    44         .write = htif_putuchar,
    45         .redraw = NULL,
    46         .scroll_up = NULL,
    47         .scroll_down = NULL
    48 };
    49 
    5043static void poll_fromhost()
    5144{
     
    5649        *fromhost = 0;
    5750}
     51
     52static void htif_cmd(uint8_t device, uint8_t cmd, uint64_t payload)
     53{
     54        uint64_t val = (((uint64_t) device) << 56) |
     55            (((uint64_t) cmd) << 48) |
     56            (payload & UINT64_C(0xffffffffffff));
     57
     58        while (*tohost)
     59                poll_fromhost();
     60
     61        *tohost = val;
     62}
     63
     64static void htif_write(outdev_t *dev, const char *s, size_t n)
     65{
     66        const char *top = s + n;
     67        assert(top >= s);
     68
     69        for (; s < top; s++) {
     70                if (*s == '\n')
     71                        htif_cmd(HTIF_DEVICE_CONSOLE, HTIF_CONSOLE_PUTC, '\r');
     72
     73                htif_cmd(HTIF_DEVICE_CONSOLE, HTIF_CONSOLE_PUTC, (uint8_t) *s);
     74        }
     75}
     76
     77static outdev_operations_t htifdev_ops = {
     78        .write = htif_write,
     79        .redraw = NULL,
     80        .scroll_up = NULL,
     81        .scroll_down = NULL
     82};
    5883
    5984void htif_init(volatile uint64_t *tohost_addr, volatile uint64_t *fromhost_addr)
     
    7297        return htifdev;
    7398}
    74 
    75 static void htif_cmd(uint8_t device, uint8_t cmd, uint64_t payload)
    76 {
    77         uint64_t val = (((uint64_t) device) << 56) |
    78             (((uint64_t) cmd) << 48) |
    79             (payload & UINT64_C(0xffffffffffff));
    80 
    81         while (*tohost)
    82                 poll_fromhost();
    83 
    84         *tohost = val;
    85 }
    86 
    87 void htif_putuchar(outdev_t *dev, const char32_t ch)
    88 {
    89         if (ascii_check(ch))
    90                 htif_cmd(HTIF_DEVICE_CONSOLE, HTIF_CONSOLE_PUTC, ch);
    91         else
    92                 htif_cmd(HTIF_DEVICE_CONSOLE, HTIF_CONSOLE_PUTC, U_SPECIAL);
    93 }
Note: See TracChangeset for help on using the changeset viewer.