source: trunk/hal/x86_64/drivers/soclib_tty.c @ 245

Last change on this file since 245 was 244, checked in by max@…, 7 years ago

Hide the fields.

File size: 3.1 KB
Line 
1/*
2 * soclib_tty.c - soclib tty driver implementation.
3 *
4 * Author  Alain Greiner (2016)
5 *
6 * Copyright (c)  UPMC Sorbonne Universites
7 *
8 * This file is part of ALMOS-MKH..
9 *
10 * ALMOS-MKH. is free software; you can redistribute it and/or modify it
11 * under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; version 2.0 of the License.
13 *
14 * ALMOS-MKH. is distributed in the hope that it will be useful, but
15 * WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
17 * General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License
20 * along with ALMOS-MKH.; if not, write to the Free Software Foundation,
21 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
22 */
23
24#include <dev_txt.h>
25#include <chdev.h>
26#include <soclib_tty.h>
27#include <remote_spinlock.h>
28#include <thread.h>
29#include <hal_special.h>
30
31#include <hal_internal.h> // XXX
32
33void soclib_tty_init( chdev_t * chdev )
34{
35        chdev->cmd = &soclib_tty_cmd;
36        chdev->isr = &soclib_tty_isr;
37
38        // nothing to do
39}
40
41// Pour le write: tout en sync, ça part direct sur le VGA/série
42// Pour le read: là on attend l'ISR
43void __attribute__ ((noinline)) soclib_tty_cmd( xptr_t th_xp )
44{
45        // get client thread cluster and local pointer
46        cxy_t      th_cxy = GET_CXY( th_xp );
47        thread_t * th_ptr = (thread_t *)GET_PTR( th_xp );
48
49        // get command type and extended pointer on TXT device
50        uint32_t type   =         hal_remote_lw ( XPTR( th_cxy , &th_ptr->command.txt.type ) );
51        xptr_t   dev_xp = (xptr_t)hal_remote_lwd( XPTR( th_cxy , &th_ptr->command.txt.dev_xp ) );
52
53        // get TXT device cluster and local pointer
54        cxy_t     dev_cxy = GET_CXY( dev_xp );
55        chdev_t * dev_ptr = (chdev_t *)GET_PTR( dev_xp );
56
57        // get extended pointer on SOCLIB_TTY base segment
58        xptr_t tty_xp = (xptr_t)hal_remote_lwd( XPTR( dev_cxy , &dev_ptr->base ) );
59
60        // get SOCLIB_TTY base segment cluster and local pointer
61        cxy_t      tty_cxy = GET_CXY( tty_xp );
62        uint32_t * tty_ptr = (uint32_t *)GET_PTR( tty_xp );
63
64        // get TTY channel index
65        uint32_t   channel = hal_remote_lw( XPTR( dev_cxy , &dev_ptr->channel ) );
66
67        // for now, only channel zero
68        if (channel != 0) {
69                x86_panic("should have been channel zero");
70        }
71
72        if (type == TXT_READ)              // descheduling strategy for calling thread
73        {
74                x86_panic("TXT_READ not handled");
75        }
76        else if (type == TXT_WRITE || type == TXT_SYNC_WRITE) // busy waiting strategy for calling thread
77        {
78                uint32_t   i;
79
80                // get source buffer extended pointer & bytes count
81                uint32_t count  = hal_remote_lw ( XPTR( th_cxy , &th_ptr->command.txt.count ) );
82                xptr_t   buf_xp = hal_remote_lwd( XPTR( th_cxy , &th_ptr->command.txt.buf_xp ) );
83
84                // loop on characters
85                for (i = 0; i < count; i++)
86                {
87                        // get one byte from command buffer in client cluster
88                        char byte = (char)hal_remote_lb( buf_xp + i );
89
90                        // VGA output (for now)
91                        x86_putc(byte);
92                }
93        }
94}
95
96void __attribute__ ((noinline)) soclib_tty_isr( chdev_t * chdev )
97{
98        // Cette ISR est juste utile pour le clavier; on arrive ici quand une touche
99        // est pressée
100        x86_panic("soclib_tty_isr not handled");
101}
102
Note: See TracBrowser for help on using the repository browser.