| 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 |  | 
|---|
| 33 | void soclib_tty_init( chdev_t * chdev ) | 
|---|
| 34 | { | 
|---|
| 35 | // nothing to do | 
|---|
| 36 | } | 
|---|
| 37 |  | 
|---|
| 38 | // Pour le write: tout en sync, ça part direct sur le VGA/série | 
|---|
| 39 | // Pour le read: là on attend l'ISR | 
|---|
| 40 | void __attribute__ ((noinline)) soclib_tty_cmd( xptr_t th_xp ) | 
|---|
| 41 | { | 
|---|
| 42 | // get client thread cluster and local pointer | 
|---|
| 43 | cxy_t      th_cxy = GET_CXY( th_xp ); | 
|---|
| 44 | thread_t * th_ptr = (thread_t *)GET_PTR( th_xp ); | 
|---|
| 45 |  | 
|---|
| 46 | // get command type and extended pointer on TXT device | 
|---|
| 47 | uint32_t type   =         hal_remote_lw ( XPTR( th_cxy , &th_ptr->command.txt.type ) ); | 
|---|
| 48 | xptr_t   dev_xp = (xptr_t)hal_remote_lwd( XPTR( th_cxy , &th_ptr->command.txt.dev_xp ) ); | 
|---|
| 49 |  | 
|---|
| 50 | // get TXT device cluster and local pointer | 
|---|
| 51 | cxy_t     dev_cxy = GET_CXY( dev_xp ); | 
|---|
| 52 | chdev_t * dev_ptr = (chdev_t *)GET_PTR( dev_xp ); | 
|---|
| 53 |  | 
|---|
| 54 | // get extended pointer on SOCLIB_TTY base segment | 
|---|
| 55 | xptr_t tty_xp = (xptr_t)hal_remote_lwd( XPTR( dev_cxy , &dev_ptr->base ) ); | 
|---|
| 56 |  | 
|---|
| 57 | // get SOCLIB_TTY base segment cluster and local pointer | 
|---|
| 58 | cxy_t      tty_cxy = GET_CXY( tty_xp ); | 
|---|
| 59 | uint32_t * tty_ptr = (uint32_t *)GET_PTR( tty_xp ); | 
|---|
| 60 |  | 
|---|
| 61 | // get TTY channel index | 
|---|
| 62 | uint32_t   channel = hal_remote_lw( XPTR( dev_cxy , &dev_ptr->channel ) ); | 
|---|
| 63 |  | 
|---|
| 64 | // for now, only channel zero | 
|---|
| 65 | if (channel != 0) { | 
|---|
| 66 | x86_panic("should have been channel zero"); | 
|---|
| 67 | } | 
|---|
| 68 |  | 
|---|
| 69 | if (type == TXT_READ)              // descheduling strategy for calling thread | 
|---|
| 70 | { | 
|---|
| 71 | x86_panic("TXT_READ not handled"); | 
|---|
| 72 | } | 
|---|
| 73 | else if (type == TXT_WRITE || type == TXT_SYNC_WRITE) // busy waiting strategy for calling thread | 
|---|
| 74 | { | 
|---|
| 75 | uint32_t   i; | 
|---|
| 76 |  | 
|---|
| 77 | // get source buffer extended pointer & bytes count | 
|---|
| 78 | uint32_t count  = hal_remote_lw ( XPTR( th_cxy , &th_ptr->command.txt.count ) ); | 
|---|
| 79 | xptr_t   buf_xp = hal_remote_lwd( XPTR( th_cxy , &th_ptr->command.txt.buf_xp ) ); | 
|---|
| 80 |  | 
|---|
| 81 | // loop on characters | 
|---|
| 82 | for (i = 0; i < count; i++) | 
|---|
| 83 | { | 
|---|
| 84 | // get one byte from command buffer in client cluster | 
|---|
| 85 | char byte = (char)hal_remote_lb( buf_xp + i ); | 
|---|
| 86 |  | 
|---|
| 87 | // VGA output (for now) | 
|---|
| 88 | x86_putc(byte); | 
|---|
| 89 | } | 
|---|
| 90 | } | 
|---|
| 91 | } | 
|---|
| 92 |  | 
|---|
| 93 | void __attribute__ ((noinline)) soclib_tty_isr( chdev_t * chdev ) | 
|---|
| 94 | { | 
|---|
| 95 | // Cette ISR est juste utile pour le clavier; on arrive ici quand une touche | 
|---|
| 96 | // est pressée | 
|---|
| 97 | x86_panic("soclib_tty_isr not handled"); | 
|---|
| 98 | } | 
|---|
| 99 |  | 
|---|