Example #1
0
int putchar(int ic){
#if defined(__is_myos_kernel)
	char c = (char) ic;
	terminal_write(&c, sizeof(c));
//  serial_write(SERIAL_COM1_BASE, c);
#else
	/* TODO: Implement a write system call. */
#endif
	return ic;
}
Example #2
0
// Get height of client window.
// See RFC 1073 "Telnet Window Size Option"
void screen_negotiate_size(void)
{
	// An example: Server suggest and client agrees to use NAWS.
	//             (Negotiate About Window Size)
	//    (server sends)  IAC DO  NAWS
	//    (client sends)  IAC WILL NAWS
	//	  (client sends)  IAC SB  NAWS 0 80 0 24 IAC SE
	uchar_t naws[] = { IAC, DO, TELOPT_NAWS };
	terminal_write(naws, sizeof(naws));
}
Example #3
0
int putchar(int ic) {
#if defined(__is_plaid_kernel)
  char c = (char)ic;
  terminal_write(&c, sizeof(c));
#else
// TODO: Implement this syscall
#endif

  return ic;
}
Example #4
0
int putchar(int ic)
{
#if defined(__is_cenil_kernel)
	char c = (char) ic;
	terminal_write(&c, sizeof(c));
#else
	// TODO: You need to implement a write system call.
#endif
	return ic;
}
Example #5
0
/* dump an area of memory as hex to the terminal XXX fix to use "printf" rather than buffers + snprintf */
void terminal_hexdump(void *memory, size_t byte_count) {
    char buffer[256];

    for (size_t index = 0; index < byte_count + ((byte_count % HEXDUMP_WIDTH) ? (HEXDUMP_WIDTH - byte_count % HEXDUMP_WIDTH) : 0); index++) {
        /* print offset at line start */
        if (index % HEXDUMP_WIDTH == 0) {
            mini_snprintf(buffer, 256, "0x%06x: ", index);
            terminal_write(buffer);
        }

        /* print hex data */
        if (index < byte_count) {
            mini_snprintf(buffer, 256, "%02x ", 0xFF & ((char*)memory)[index]);
            terminal_write(buffer);                       
        } else {
            terminal_write("   ");                                              
        }

        if (index % HEXDUMP_WIDTH == HEXDUMP_WIDTH - 1) {
            terminal_write("\n");
        }
    }
}
Example #6
0
void kernel_main(void* mem)
{
	init_serial();


	terminal_init();
	terminal_writeln("Kernel Startup.");

	pool = tlsf_create((void*)0x2000000, 32768);
  //terminal_writehexln(pool);
	lua_State* L = lua_newstate(l_alloc, pool);

  lua_pushcfunction(L, l_Print);
  lua_setglobal(L, "print");
  

#define BUFFER_SIZE 128
#if 0
	char test[BUFFER_SIZE]; test[BUFFER_SIZE-1] = 0;
  int i ;
	for(i = 0; i < BUFFER_SIZE-1; ++i) {
		test[i] = read_serial();
		if(test[i] == 0 || test[i] == '\r' || test[i] == '\n') {
			break;
		}
		if(!IsValid(test[i])) {
			i--;
			continue;
		}
 	}
  test[i] = 0;
terminal_write("Read ");
terminal_writehexln(i);
terminal_writeln(test);
#else
  char* test = "print(1 + 2)";
#endif
  size_t len = strlen(test);
  if(luaL_loadbufferx(L, test, len, "Sample", 0) != 0) {
    terminal_writeln(lua_tostring(L, -1));
  }
  if(lua_pcall(L, 0, LUA_MULTRET, 0) != 0) {
    terminal_writeln(lua_tostring(L, -1));
  }

  terminal_writeln("Finished");
}
Example #7
0
/*
 * ---------------------------------------------------------------------------
 *      Name   : terminal_writehex
 *      Purpose: write an unsinged integer in hex of up to 32 bits without
 *               leading zeroes
 *      Args   : const uint32_t data
 *      Returns: void
 * ---------------------------------------------------------------------------
 */
void terminal_writehex(const uint32_t data)
{
    uint32_t tmp = data;
    uint32_t tmp2 = 0;
    int val = 0;
    char str[17];
    char *p = &str[sizeof(str) - 1];
    *p = '\0';
    val = tmp / 16;
    tmp2 = tmp - val * 16;
    *--p = (tmp2 >= 0xa) ? (char) ('a' + tmp2 - 0xa) : (char) ('0' + tmp2);
    tmp = val;
    while(tmp != 0)
    {
        val = tmp / 16;
        tmp2 = tmp - val * 16;
        *--p = (tmp2 >= 0xa)
               ? (char) ('a' + tmp2 - 0xa)
               : (char) ('0' + tmp2);
        tmp = val;
    }
    terminal_write(p, strlen(p));
}
Example #8
0
File: tty.c Project: rtpg/junkcode
void terminal_writestring(const char* data)
{
	terminal_write(data, strlen(data));
}
Example #9
0
static WRITE8_HANDLER( czk80_80_w )
{
	device_t *terminal = space->machine().device(TERMINAL_TAG);

	terminal_write(terminal, 0, data);
}
Example #10
0
void smp_init()
{
	int i;
	//uint8_t nop = 0x90;
	//for(i=0x100000;i<0x100810;i++)
	//{
		//memcpy(i,&nop,0x1);
	//}
	for( i = 0; i<cpu_count;i++)
	{
		gdt_insert_tss(5+i*2, &tss64, sizeof(tss_t),0);
	}
	memcpy(phys_to_virt(0x9000),phys_to_virt(0x00101000),0x800);
	terminal_write("cpus available: ");
	terminal_set_color(0,9);
	terminal_write(itoa(cpu_count,0,10));
	terminal_set_color(0,15);
	terminal_write("\n");
	uint16_t cpu_id_limit = cpu_count;// - 1;
	uint16_t localid = localapic_getid();
	for(i = 0; i < cpu_id_limit; ++i)
	{
		cpu_ready = 0;
		if(i != localid)
		{
			uint16_t apicid = acpi_cpuids[i];
			localapic_sendinit(apicid);
			PitWait(10);
			localapic_sendstartup(apicid, 0x9);
			PitWait(10);
			if(!cpu_ready)
			{
				localapic_sendstartup(apicid, 0x9);//0xA);//
				PitWait(100);
				if(!cpu_ready)
				{
					terminal_set_color(0,12);
					terminal_write("Error: ");
					terminal_set_color(0,15);
					terminal_write("Failed to start cpu ");
					terminal_write(itoa(apicid,0,10));
					terminal_write("\n");
				}
				else
				{
					cpu_ready_count++;
				}
			}
			else
			{
				cpu_ready_count++;
			}
			
		}
	}
		terminal_write("cpus started: ");
		terminal_set_color(0,9);
		terminal_write(itoa(cpu_ready_count,0,10));
		terminal_set_color(0,15);
		terminal_write("\n");
}
Example #11
0
static WRITE8_HANDLER(microdec_terminal_w)
{
	device_t *devconf = space->machine().device(TERMINAL_TAG);
	terminal_write(devconf,0,data);
}
Example #12
0
static void duart_tx(device_t *device, int channel, UINT8 data)
{
	device_t *devconf = device->machine().device(TERMINAL_TAG);
	terminal_write(devconf,0,data);
}
Example #13
0
void terminal_write_string(Terminal *instance, const char *data) {
    terminal_write(instance, data, strlen(data));
}
Example #14
0
//XXX: flags are ignored...
int vfsfd_open(const char *pathname, int flags)
{
    vfs_handle_t vh;
    errval_t err;

    char *path = vfs_path_mkabs(pathname);
    assert(path != NULL);

    // If O_CREAT was given, we use vfs_create()
    if(flags & O_CREAT) {
        // If O_EXCL was also given, we check whether we can open() first
        if(flags & O_EXCL) {
            err = vfs_open(path, &vh);
            if(err_is_ok(err)) {
                vfs_close(vh);
                errno = EEXIST;
                return -1;
            }
            assert(err_no(err) == FS_ERR_NOTFOUND);
        }

        err = vfs_create(path, &vh);
    } else {
        // Regular open()
        err = vfs_open(path, &vh);
    }

    free(path);
    if (err_is_fail(err)) {
        VFSFD_DEBUG("open('%s') failed\n", pathname);

        switch(err_no(err)) {
        case FS_ERR_NOTFOUND:
            errno = ENOENT;
            break;

        default:
#ifdef VFSFD_DEBUG_ENABLED
            DEBUG_ERR(err, "vfs_open");
#endif
            break;
        }

        return -1;
    }

    struct fdtab_entry e = {
        .type = FDTAB_TYPE_FILE,
        .handle = vh,
        .epoll_fd = -1,
    };
    int fd = fdtab_alloc(&e);
    VFSFD_DEBUG("open(%s) as fd %d\n", pathname, fd);
    if (fd < 0) {
        vfs_close(vh);
        return -1;
    } else {
        return fd;
    }
}


int vfsfd_read(int fd, void *buf, size_t len)
{
    struct fdtab_entry *e = fdtab_get(fd);
    size_t retlen = 0;
    switch(e->type) {
    case FDTAB_TYPE_FILE:
        {
            errval_t err = vfs_read((vfs_handle_t)e->handle, buf, len, &retlen);
            VFSFD_DEBUG("%d : read(%d, %d) = %lu\n", disp_get_domain_id(), fd, len, retlen);
            if (err_is_fail(err)) {
                DEBUG_ERR(err, "error in vfs_read");
                return -1;
            }
        }
        break;

    case FDTAB_TYPE_STDIN:
        retlen = terminal_read((char *)buf, len);
        break;

    case FDTAB_TYPE_STDOUT:
    case FDTAB_TYPE_STDERR:
    case FDTAB_TYPE_AVAILABLE:
    default:
        return -1;
    }

    return retlen;
}

int vfsfd_write(int fd, const void *buf, size_t len)
{
    struct fdtab_entry *e = fdtab_get(fd);
    if (e->type == FDTAB_TYPE_AVAILABLE) {
        return -1;
    }

    size_t retlen = 0;

    switch(e->type) {
    case FDTAB_TYPE_FILE:
        {
            errval_t err = vfs_write((vfs_handle_t)e->handle, buf, len, &retlen);
            VFSFD_DEBUG("write(%d, %d) = %lu\n", fd, len, retlen);
            if (err_is_fail(err)) {
                DEBUG_ERR(err, "error in vfs_write");
                return -1;
            }
        }
        break;

    case FDTAB_TYPE_STDOUT:
        /* only support writting to terminal */
        retlen = terminal_write((const char*) buf, len);
        break;

    case FDTAB_TYPE_STDERR:
        retlen = terminal_write((const char*) buf, len);
        break;

    case FDTAB_TYPE_STDIN:
    case FDTAB_TYPE_AVAILABLE:
    default:
        return -1;
    }

    return retlen;
}

int vfsfd_close(int fd)
{
    errval_t err;
    struct fdtab_entry *e = fdtab_get(fd);
    if (e->type == FDTAB_TYPE_AVAILABLE) {
        return -1;
    }

    VFSFD_DEBUG("close(%d)\n", fd);

    switch(e->type) {
    case FDTAB_TYPE_FILE:
        err = vfs_close((vfs_handle_t)e->handle);
        if (err_is_fail(err)) {
            DEBUG_ERR(err, "error in vfs_close");
            return -1;
        }
        break;

    case FDTAB_TYPE_STDIN:
    case FDTAB_TYPE_STDOUT:
    case FDTAB_TYPE_STDERR:
        // XXX: Should call fclose() when closing last FD
        break;

    default:
        return -1;
    } // end switch

    fdtab_free(fd);
    return 0;
}
Example #15
0
void terminal_writestring(const char* string)
{
	terminal_write(string, strlen(string));
}