#include "console.h" #include "string.h" #include void console_init( console_t *console ) { memset( console, 0, sizeof( console_t ) ); console->vga_text = NULL; console->serial = NULL; console->network = NULL; } void console_add_vga_text_output( console_t *console, vga_text_t *vga_text ) { console->vga_text = vga_text; } void console_add_serial_output( console_t *console, serial_t *serial ) { console->serial = serial; } void console_add_network_output( console_t *console, network_t *network ) { console->network = network; } static void send_via_udp( network_t *network, const char *s, size_t n ) { //~ network_ethernet_packet_t *packet = (network_ethernet_packet_t *)event->buf.data; //~ network_mac_address_t dst_addr; //~ network_mac_address_t src_addr; //~ network_ether_type_t type; //~ } __attribute__( ( packed ) ) network_ethernet_packet_header_t; //~ typedef struct { //~ network_ethernet_packet_header_t header; //~ uint8_t *data; //~ } __attribute__( ( packed ) ) network_ethernet_packet_t; //~ packet->header.dst_addr = arp->source_hardware_address; //~ packet->header.src_addr = global_context.network->mac_address; //~ arp->operation = ARP_OPERATION_ANSWER; //~ arp->destination_hardware_address = arp->source_hardware_address; //~ arp->source_hardware_address = global_context.network->mac_address; //~ network_ipv4_address_t tmp = arp->destination_protocol_address; //~ arp->destination_protocol_address = arp->source_protocol_address; //~ arp->source_protocol_address = tmp; //~ event->buf.length = sizeof( network_ethernet_packet_header_t ) + sizeof( network_arp_packet_t ); //~ ((network_vtable_t *)( global_context.network->base.vtable ))->send( global_context.network, event->buf ); } void console_put_char( console_t *console, const char c ) { if( console->vga_text != NULL ) { vga_text_put_char( console->vga_text, c ); } if( console->serial != NULL ) { serial_put_char( console->serial, c ); } if( console->network != NULL ) { send_via_udp( console->network, &c, 1 ); } } void console_put_string( console_t *console, const char *s ) { if( console->vga_text != NULL ) { vga_text_put_string( console->vga_text, s ); } if( console->serial != NULL ) { serial_put_string( console->serial, s ); } if( console->network != NULL ) { send_via_udp( console->network, s, strlen( s ) ); } } void console_put_newline( console_t *console ) { if( console->vga_text != NULL ) { // wipe contents till the end of the line on the // VGA text console, old data could still be there // from the BIOS(es) int x = vga_text_get_cursor_x( console->vga_text ); for( int i = x; i < console->vga_text->res_x; i++ ) { vga_text_put_char( console->vga_text, ' ' ); } } if( console->serial != NULL ) { serial_put_newline( console->serial ); } if( console->network != NULL ) { char c = '\n'; send_via_udp( console->network, &c, 1 ); } }