Esempio n. 1
0
void serial_init(void)
{
	serial_enable(SERIAL_PORT_A);
	serial_enable(SERIAL_PORT_B);

	register_interrupt_handler(SERIAL_IRQ, serial_handler_a); /* Install the serial input handler */
	register_interrupt_handler(SERIAL_IRQ - 1, serial_handler_b); /* Install the serial input handler */
	outportb(SERIAL_PORT_A + 1, 0x01);      /* Enable interrupts on receive */
	outportb(SERIAL_PORT_B + 1, 0x01);      /* Enable interrupts on receive */
}
Esempio n. 2
0
extern "C" void
serial_init(void)
{
#ifdef ENABLE_SERIAL
	serial_enable();
#endif
}
Esempio n. 3
0
void __attribute__((noreturn)) serial_recv_task(struct vcom * vcom)
{
	struct serial_dev * serial = vcom->serial;
	struct usb_cdc_class * cdc = vcom->cdc;
	uint8_t buf[VCOM_BUF_SIZE];
	int len;

	DCC_LOG1(LOG_TRACE, "[%d] started.", thinkos_thread_self());

	/* wait for line configuration */
	usb_cdc_acm_lc_wait(cdc);

	/* enable serial */
	serial_enable(serial);

	for (;;) {
		len = serial_read(serial, buf, VCOM_BUF_SIZE, 1000);
		if (len > 0) {
//			dbg_write(buf, len);
			if (vcom->mode == VCOM_MODE_CONVERTER) {
				led_flash(LED_AMBER, 50);
				usb_cdc_write(cdc, buf, len);
			}
			if (vcom->mode == VCOM_MODE_SDU_TRACE) {
				led_flash(LED_AMBER, 50);
				sdu_decode(buf, len);
			}
#if RAW_TRACE
			if (len == 1)
				DCC_LOG1(LOG_TRACE, "RX: %02x", buf[0]);
			else if (len == 2)
				DCC_LOG2(LOG_TRACE, "RX: %02x %02x", 
						 buf[0], buf[1]);
			else if (len == 3)
				DCC_LOG3(LOG_TRACE, "RX: %02x %02x %02x", 
						 buf[0], buf[1], buf[2]);
			else if (len == 4)
				DCC_LOG4(LOG_TRACE, "RX: %02x %02x %02x %02x", 
						 buf[0], buf[1], buf[2], buf[3]);
			else if (len == 5)
				DCC_LOG5(LOG_TRACE, "RX: %02x %02x %02x %02x %02x", 
						 buf[0], buf[1], buf[2], buf[3], buf[4]);
			else if (len == 6)
				DCC_LOG6(LOG_TRACE, "RX: %02x %02x %02x %02x %02x %02x", 
						 buf[0], buf[1], buf[2], buf[3], buf[4], buf[5]);
			else if (len == 7)
				DCC_LOG7(LOG_TRACE, "RX: %02x %02x %02x %02x %02x %02x %02x ",
						 buf[0], buf[1], buf[2], buf[3], 
						 buf[4], buf[5], buf[6]);
			else
				DCC_LOG8(LOG_TRACE, "RX: %02x %02x %02x %02x %02x %02x "
						 "%02x %02x ...", buf[0], buf[1], buf[2], buf[3], 
						 buf[4], buf[5], buf[6], buf[7]);
#endif
#if SDU_TRACE
			RX(buf, len);
#endif
		}
	}
}
Esempio n. 4
0
extern "C" void
serial_init(void)
{
    // copy the base ports of the optional 4 serial ports to the kernel args
    // 0x0000:0x0400 is the location of that information in the BIOS data
    // segment
    uint16* ports = (uint16*)0x400;
    memcpy(gKernelArgs.platform_args.serial_base_ports, ports,
           sizeof(uint16) * MAX_SERIAL_PORTS);

    // only use the port if we could find one, else use the standard port
    if (gKernelArgs.platform_args.serial_base_ports[0] != 0)
        sSerialBasePort = gKernelArgs.platform_args.serial_base_ports[0];

    uint16 divisor = uint16(115200 / kSerialBaudRate);

    out8(0x80, sSerialBasePort + SERIAL_LINE_CONTROL);
    // set divisor latch access bit
    out8(divisor & 0xf, sSerialBasePort + SERIAL_DIVISOR_LATCH_LOW);
    out8(divisor >> 8, sSerialBasePort + SERIAL_DIVISOR_LATCH_HIGH);
    out8(3, sSerialBasePort + SERIAL_LINE_CONTROL);
    // 8N1

#ifdef ENABLE_SERIAL
    serial_enable();
#endif
}
Esempio n. 5
0
extern "C" void
serial_init(void)
{
	gUART = arch_get_uart_8250(BOARD_UART_DEBUG, BOARD_UART_CLOCK);
	if (gUART == 0)
		return;

	serial_enable();
}
Esempio n. 6
0
extern "C" void
serial_init(void)
{
	gUART = arch_get_uart_pl011(BOARD_UART_DEBUG, BOARD_UART_CLOCK);
	gUART->InitEarly();
	gUART->InitPort(9600);

	serial_enable();

	serial_puts("\n\n********************\n", 23);
	serial_puts("Haiku serial startup\n", 21);
}
Esempio n. 7
0
extern "C" void
serial_init(const void *fdt)
{
    // first try with hints from the FDT
    gUART = debug_uart_from_fdt(fdt);

    // fallback to known board UARTs
#if defined(BOARD_UART_DEBUG) && defined(BOARD_UART_CLOCK)
    if (gUART == NULL) {
#ifdef BOARD_UART_PL011
        gUART = arch_get_uart_pl011(BOARD_UART_DEBUG, BOARD_UART_CLOCK);
#else
        gUART = arch_get_uart_8250(BOARD_UART_DEBUG, BOARD_UART_CLOCK);
#endif
    }
#endif

    if (gUART == NULL)
        return;

    serial_enable();
}
Esempio n. 8
0
static fs_node_t * serial_device_create(int device) {
	fs_node_t * fnode = malloc(sizeof(fs_node_t));
	memset(fnode, 0x00, sizeof(fs_node_t));
	fnode->device= (void *)device;
	strcpy(fnode->name, "serial");
	fnode->uid = 0;
	fnode->gid = 0;
	fnode->mask    = 0660;
	fnode->flags   = FS_CHARDEVICE;
	fnode->read    = read_serial;
	fnode->write   = write_serial;
	fnode->open    = open_serial;
	fnode->close   = close_serial;
	fnode->readdir = NULL;
	fnode->finddir = NULL;
	fnode->ioctl   = NULL; /* TODO ioctls for raw serial devices */

	fnode->selectcheck = check_serial;
	fnode->selectwait  = wait_serial;

	fnode->atime = now();
	fnode->mtime = fnode->atime;
	fnode->ctime = fnode->atime;

	serial_enable(device);

	if (device == SERIAL_PORT_A || device == SERIAL_PORT_C) {
		irq_install_handler(SERIAL_IRQ_AC, serial_handler_ac);
	} else {
		irq_install_handler(SERIAL_IRQ_BD, serial_handler_bd);
	}

	*pipe_for_port(device) = make_pipe(128);

	return fnode;
}
Esempio n. 9
0
extern "C" int
start_gen(int argc, const char **argv, struct image_header *uimage, void *fdt)
{
	stage2_args args;

	clear_bss();
		// call C++ constructors before doing anything else
	call_ctors();
	args.heap_size = HEAP_SIZE;
	args.arguments = NULL;
	args.arguments_count = 0;
	args.platform.boot_tgz_data = NULL;
	args.platform.boot_tgz_size = 0;
	args.platform.fdt_data = NULL;
	args.platform.fdt_size = 0;

	gUImage = uimage;
	gFDT = fdt;	//XXX: make a copy?
		// TODO: check for atags instead and convert them

	if (argv) {
		// skip the kernel name
		++argv;
		--argc;
	}
	// TODO: Ensure cmdline is mapped into memory by MMU before usage.

	// if we get passed a uimage, try to find the third blob
	// only if we do not have FDT data yet
	if (gUImage != NULL
		&& !gFDT
		&& image_multi_getimg(gUImage, 2,
			(uint32*)&args.platform.fdt_data,
			&args.platform.fdt_size)) {
		// found a blob, assume it is FDT data, when working on a platform
		// which does not have an FDT enabled U-Boot
		gFDT = args.platform.fdt_data;
	}

	// We have to cpu_init *before* calling FDT functions
	cpu_init();

	serial_init(gFDT);

	#if defined(__ARM__)
	arch_mailbox_init();
	#endif

	// initialize the OpenFirmware wrapper
	of_init(NULL);

	console_init();

	// if we get passed an FDT, check /chosen for initrd and bootargs
	if (gFDT != NULL) {
		int node = fdt_path_offset(gFDT, "/chosen");
		const void *prop;
		int len;
		phys_addr_t initrd_start = 0, initrd_end = 0;

		if (node >= 0) {
			prop = fdt_getprop(gFDT, node, "linux,initrd-start", &len);
			if (prop && len == 4)
				initrd_start = fdt32_to_cpu(*(uint32_t *)prop);
			prop = fdt_getprop(gFDT, node, "linux,initrd-end", &len);
			if (prop && len == 4)
				initrd_end = fdt32_to_cpu(*(uint32_t *)prop);
			if (initrd_end > initrd_start) {
				args.platform.boot_tgz_data = (void *)initrd_start;
				args.platform.boot_tgz_size = initrd_end - initrd_start;
				dprintf("Found boot tgz from FDT @ %p, %" B_PRIu32 " bytes\n",
					args.platform.boot_tgz_data, args.platform.boot_tgz_size);
			}
			// we check for bootargs after remapping the FDT
		}
	}

	// if we get passed a uimage, try to find the second blob
	if (gUImage != NULL
		&& image_multi_getimg(gUImage, 1,
			(uint32*)&args.platform.boot_tgz_data,
			&args.platform.boot_tgz_size)) {
		dprintf("Found boot tgz from uimage @ %p, %" B_PRIu32 " bytes\n",
			args.platform.boot_tgz_data, args.platform.boot_tgz_size);
	}

	{ //DEBUG:
		int i;
		dprintf("argc = %d\n", argc);
		for (i = 0; i < argc; i++)
			dprintf("argv[%d] @%lx = '%s'\n", i, (uint32)argv[i], argv[i]);
		dprintf("os: %d\n", (int)gUBootOS);
		dprintf("gd @ %p\n", gUBootGlobalData);
		if (gUBootGlobalData) {
			dprintf("gd->bd @ %p\n", gUBootGlobalData->bd);
			dprintf("gd->fb_base @ %p\n", (void*)gUBootGlobalData->fb_base);
		}
		if (gUImage)
			dump_uimage(gUImage);
		if (gFDT)
			dump_fdt(gFDT);
	}
	
	if (args.platform.boot_tgz_size > 0) {
		insert_physical_allocated_range((addr_t)args.platform.boot_tgz_data,
			args.platform.boot_tgz_size);
	}

	// save the size of the FDT so we can map it easily after mmu_init
	size_t fdtSize = gFDT ? fdt_totalsize(gFDT) : 0;
	dprintf("fdtSize: 0x%" B_PRIxSIZE "\n", fdtSize);

	mmu_init();

	// Handle our tarFS post-mmu
	if (args.platform.boot_tgz_size > 0) {
		args.platform.boot_tgz_data = (void*)mmu_map_physical_memory((addr_t)
			args.platform.boot_tgz_data, args.platform.boot_tgz_size,
			kDefaultPageFlags);
	}
	// .. and our FDT
	if (gFDT != NULL)
		gFDT = (void*)mmu_map_physical_memory((addr_t)gFDT, fdtSize, kDefaultPageFlags);

	// if we get passed an FDT, check /chosen for bootargs now
	// to avoid having to copy them.
	if (gFDT != NULL) {
		int node = fdt_path_offset(gFDT, "/chosen");
		const void *prop;
		int len;

		if (node >= 0) {
			prop = fdt_getprop(gFDT, node, "bootargs", &len);
			if (prop) {
				dprintf("Found bootargs: %s\n", (const char *)prop);
				static const char *sArgs[] = { NULL, NULL };
				sArgs[0] = (const char *)prop;
				// override main() args
				args.arguments = sArgs;
				args.arguments_count = 1;
			}
		}
		dprintf("args.arguments_count = %" B_PRId32 "\n", args.arguments_count);
		for (int i = 0; i < args.arguments_count; i++)
			dprintf("args.arguments[%d] @%lx = '%s'\n", i,
				(uint32)args.arguments[i], args.arguments[i]);
	}

	// wait a bit to give the user the opportunity to press a key
//	spin(750000);

	// reading the keyboard doesn't seem to work in graphics mode
	// (maybe a bochs problem)
//	sBootOptions = check_for_boot_keys();
	//if (sBootOptions & BOOT_OPTION_DEBUG_OUTPUT)
		serial_enable();

	main(&args);
	return 0;
}
Esempio n. 10
0
extern "C" int
start_raw(int argc, const char **argv)
{
	stage2_args args;

	clear_bss();
		// call C++ constructors before doing anything else
	call_ctors();
	args.heap_size = HEAP_SIZE;
	args.arguments = NULL;
	args.platform.boot_tgz_data = NULL;
	args.platform.boot_tgz_size = 0;
	args.platform.fdt_data = NULL;
	args.platform.fdt_size = 0;

	// if we get passed a uimage, try to find the third blob only if we do not have FDT data yet
	if (gUImage != NULL
		&& !gFDT
		&& image_multi_getimg(gUImage, 2,
			(uint32*)&args.platform.fdt_data,
			&args.platform.fdt_size)) {
		// found a blob, assume it is FDT data, when working on a platform
		// which does not have an FDT enabled U-Boot
		gFDT = args.platform.fdt_data;
	}

	serial_init(gFDT);
	console_init();
	cpu_init();

	if (args.platform.fdt_data) {
		dprintf("Found FDT from uimage @ %p, %" B_PRIu32 " bytes\n",
			args.platform.fdt_data, args.platform.fdt_size);
	} else if (gFDT) {
		/* Fixup args so we can pass the gFDT on to the kernel */
		args.platform.fdt_data = gFDT;
		args.platform.fdt_size = fdt_totalsize(gFDT);
	}

	// if we get passed an FDT, check /chosen for initrd
	if (gFDT != NULL) {
		int node = fdt_path_offset(gFDT, "/chosen");
		const void *prop;
		int len;
		phys_addr_t initrd_start = 0, initrd_end = 0;

		if (node >= 0) {
			prop = fdt_getprop(gFDT, node, "linux,initrd-start", &len);
			if (prop && len == 4)
				initrd_start = fdt32_to_cpu(*(uint32_t *)prop);
			prop = fdt_getprop(gFDT, node, "linux,initrd-end", &len);
			if (prop && len == 4)
				initrd_end = fdt32_to_cpu(*(uint32_t *)prop);
			if (initrd_end > initrd_start) {
				args.platform.boot_tgz_data = (void *)initrd_start;
				args.platform.boot_tgz_size = initrd_end - initrd_start;
		dprintf("Found boot tgz from FDT @ %p, %" B_PRIu32 " bytes\n",
			args.platform.boot_tgz_data, args.platform.boot_tgz_size);
			}
		}
	}

	// if we get passed a uimage, try to find the second blob
	if (gUImage != NULL
		&& image_multi_getimg(gUImage, 1,
			(uint32*)&args.platform.boot_tgz_data,
			&args.platform.boot_tgz_size)) {
		dprintf("Found boot tgz from uimage @ %p, %" B_PRIu32 " bytes\n",
			args.platform.boot_tgz_data, args.platform.boot_tgz_size);
	}

	{ //DEBUG:
		int i;
		dprintf("argc = %d\n", argc);
		for (i = 0; i < argc; i++)
			dprintf("argv[%d] @%lx = '%s'\n", i, (uint32)argv[i], argv[i]);
		dprintf("os: %d\n", (int)gUBootOS);
		dprintf("gd @ %p\n", gUBootGlobalData);
		if (gUBootGlobalData)
			dprintf("gd->bd @ %p\n", gUBootGlobalData->bd);
		//dprintf("fb_base %p\n", (void*)gUBootGlobalData->fb_base);
		if (gUImage)
			dump_uimage(gUImage);
		if (gFDT)
			dump_fdt(gFDT);
	}
	
	mmu_init();

	// wait a bit to give the user the opportunity to press a key
//	spin(750000);

	// reading the keyboard doesn't seem to work in graphics mode
	// (maybe a bochs problem)
//	sBootOptions = check_for_boot_keys();
	//if (sBootOptions & BOOT_OPTION_DEBUG_OUTPUT)
		serial_enable();

	main(&args);
	return 0;
}