x86interface.c 16.2 KB
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814
#include "x86emu.h"
#include "glue.h"


/*
 * This isn't nice, but there are a lot of incompatibilities in the U-Boot and scitech include
 * files that this is the only really workable solution.
 * Might be cleaned out later. 
 */

#ifdef DEBUG
#undef DEBUG
#endif

#undef IO_LOGGING
#undef MEM_LOGGING

#ifdef IO_LOGGING
#define LOGIO(port, format, args...) if (dolog(port)) _printf(format , ## args)
#else
#define LOGIO(port, format, args...)
#endif

#ifdef MEM_LOGGIN
#define LOGMEM(format, args...) _printf(format , ## args)
#else
#define LOGMEM(format, args...)
#endif

#ifdef DEBUG
#define PRINTF(format, args...) _printf(format , ## args)
#else
#define PRINTF(format, argc...)
#endif

typedef unsigned char UBYTE;
typedef unsigned short UWORD;
typedef unsigned long ULONG;

typedef char BYTE;
typedef short WORT;
typedef long LONG;

#define EMULATOR_MEM_SIZE       (1024*1024)
#define EMULATOR_BIOS_OFFSET    0xC0000
#define EMULATOR_STRAP_OFFSET   0x30000
#define EMULATOR_STACK_OFFSET   0x20000
#define EMULATOR_LOGO_OFFSET    0x40000 // If you change this, change the strap code, too
#define VIDEO_BASE (void *)0xFD0B8000

extern char *getenv(char *);
extern int tstc(void);
extern int getc(void);
extern unsigned char video_get_attr(void);

int atoi(char *string)
{
    int res = 0;
    while (*string>='0' && *string <='9')
    {
	res *= 10;
	res += *string-'0';
	string++;
    }

    return res;
}

void cons_gets(char *buffer)
{
    int i = 0;
    char c = 0;

    buffer[0] = 0;
    if (getenv("x86_runthru")) return; //FIXME:
    while (c != 0x0D && c != 0x0A)
    {
	while (!tstc());
	c = getc();
	if (c>=32 && c < 127)
	{
	    buffer[i] = c;
	    i++;
	    buffer[i] = 0;
	    putc(c);
	}
	else
	{
	    if (c == 0x08)
	    {
		if (i>0) i--;
		buffer[i] = 0;
	    }
	}
    }
    buffer[i] = '\n';
    buffer[i+1] = 0;
}

char *bios_date = "08/14/02";
UBYTE model = 0xFC;
UBYTE submodel = 0x00;

static inline UBYTE read_byte(volatile UBYTE* from)
{
    int x;
    asm volatile ("lbz %0,%1\n eieio" : "=r" (x) : "m" (*from));
    return (UBYTE)x;
}

static inline void write_byte(volatile UBYTE *to, int x)
{
    asm volatile ("stb %1,%0\n eieio" : "=m" (*to) : "r" (x));
}

static inline UWORD read_word_little(volatile UWORD *from)
{
    int x;
    asm volatile ("lhbrx %0,0,%1\n eieio" : "=r" (x) : "r" (from), "m" (*from));
    return (UWORD)x;
}

static inline UWORD read_word_big(volatile UWORD *from)
{
    int x;
    asm volatile ("lhz %0,%1\n eieio" : "=r" (x) : "m" (*from));
    return (UWORD)x;
}

static inline void write_word_little(volatile UWORD *to, int x)
{
    asm volatile ("sthbrx %1,0,%2\n eieio" : "=m" (*to) : "r" (x), "r" (to));
}

static inline void write_word_big(volatile UWORD *to, int x)
{
    asm volatile ("sth %1,%0\n eieio" : "=m" (*to) : "r" (x));
}

static inline ULONG read_long_little(volatile ULONG *from)
{
    unsigned long x;
    asm volatile ("lwbrx %0,0,%1\n eieio" : "=r" (x) : "r" (from), "m"(*from));
    return (ULONG)x;
}

static inline ULONG read_long_big(volatile ULONG *from)
{
    unsigned long x;
    asm volatile ("lwz %0,%1\n eieio" : "=r" (x) : "m" (*from));
    return (ULONG)x;
}

static inline void write_long_little(volatile ULONG *to, ULONG x)
{
    asm volatile ("stwbrx %1,0,%2\n eieio" : "=m" (*to) : "r" (x), "r" (to));
}

static inline void write_long_big(volatile ULONG *to, ULONG x)
{
    asm volatile ("stw %1,%0\n eieio" : "=m" (*to) : "r" (x));
}

static int log_init = 0;
static int log_do = 0;
static int log_low = 0;

int dolog(int port)
{
    if (log_init && log_do) 
    {
	if (log_low && port > 0x400) return 0;
	return 1;
    }

    if (!log_init)
    {
	log_init = 1;
	log_do = (getenv("x86_logio") != (char *)0);
	log_low = (getenv("x86_loglow") != (char *)0);
	if (log_do) 
	{
	    if (log_low && port > 0x400) return 0;
	    return 1;
	}
    }
    return 0;
}

// Converts an emulator address to a physical address.
// Handles all special cases (bios date, model etc), and might need work
u32 memaddr(u32 addr)
{
//    if (addr >= 0xF0000 && addr < 0xFFFFF) printf("WARNING: Segment F access (0x%x)\n", addr);
//    printf("MemAddr=%p\n", addr);
    if (addr >= 0xA0000 && addr < 0xC0000)
	return 0xFD000000 + addr;
    else if (addr >= 0xFFFF5 && addr < 0xFFFFE)
    {
	return (u32)bios_date+addr-0xFFFF5;
    }
    else if (addr == 0xFFFFE)
	return (u32)&model;
    else if (addr == 0xFFFFF)
	return (u32)&submodel;
    else if (addr >= 0x80000000)
    {
	//printf("Warning: High memory access at 0x%x\n", addr);
	return addr;
    }
    else
	return (u32)M.mem_base+addr;
}

u8 A1_rdb(u32 addr)
{
    u8 a = read_byte((UBYTE *)memaddr(addr));
    LOGMEM("rdb: %x -> %x\n", addr, a);
    return a;
}

u16 A1_rdw(u32 addr)
{
    u16 a = read_word_little((UWORD *)memaddr(addr));
    LOGMEM("rdw: %x -> %x\n", addr, a);
    return a;
}

u32 A1_rdl(u32 addr)
{
    u32 a = read_long_little((ULONG *)memaddr(addr));
    LOGMEM("rdl: %x -> %x\n", addr, a);
    return a;
}

void A1_wrb(u32 addr, u8 val)
{
    LOGMEM("wrb: %x <- %x\n", addr, val);
    write_byte((UBYTE *)memaddr(addr), val);
}

void A1_wrw(u32 addr, u16 val)
{
    LOGMEM("wrw: %x <- %x\n", addr, val);
    write_word_little((UWORD *)memaddr(addr), val);
}

void A1_wrl(u32 addr, u32 val)
{
    LOGMEM("wrl: %x <- %x\n", addr, val);
    write_long_little((ULONG *)memaddr(addr), val);
}

X86EMU_memFuncs _A1_mem = 
{
    A1_rdb,
    A1_rdw,
    A1_rdl,
    A1_wrb,
    A1_wrw,
    A1_wrl,
};

#define ARTICIAS_PCI_CFGADDR  0xfec00cf8
#define ARTICIAS_PCI_CFGDATA  0xfee00cfc
#define IOBASE                0xFE000000

#define in_byte(from) read_byte( (UBYTE *)port_to_mem(from))
#define in_word(from) read_word_little((UWORD *)port_to_mem(from))
#define in_long(from) read_long_little((ULONG *)port_to_mem(from))
#define out_byte(to, val) write_byte((UBYTE *)port_to_mem(to), val)
#define out_word(to, val) write_word_little((UWORD *)port_to_mem(to), val)
#define out_long(to, val) write_long_little((ULONG *)port_to_mem(to), val)

u32 port_to_mem(int port)
{
    if (port >= 0xCFC && port <= 0xCFF) return 0xFEE00000+port;
    else if (port >= 0xCF8 && port <= 0xCFB) return 0xFEC00000+port;
    else return IOBASE + port;
}

u8 A1_inb(int port)
{
    u8 a;
    //if (port == 0x3BA) return 0;
    a = in_byte(port);
    LOGIO(port, "inb: %Xh -> %d (%Xh)\n", port, a, a);
    return a;
}

u16 A1_inw(int port)
{
    u16 a = in_word(port);
    LOGIO(port, "inw: %Xh -> %d (%Xh)\n", port, a, a);
    return a;
}

u32 A1_inl(int port)
{
    u32 a = in_long(port);
    LOGIO(port, "inl: %Xh -> %d (%Xh)\n", port, a, a);
    return a;
}

void A1_outb(int port, u8 val)
{
    LOGIO(port, "outb: %Xh <- %d (%Xh)\n", port, val, val);
/*    if (port == 0xCF8) port = 0xCFB;
    else if (port == 0xCF9) port = 0xCFA;
    else if (port == 0xCFA) port = 0xCF9;
    else if (port == 0xCFB) port = 0xCF8;*/
    out_byte(port, val);
}

void A1_outw(int port, u16 val)
{
    LOGIO(port, "outw: %Xh <- %d (%Xh)\n", port, val, val);
    out_word(port, val);
}

void A1_outl(int port, u32 val)
{
    LOGIO(port, "outl: %Xh <- %d (%Xh)\n", port, val, val);
    out_long(port, val);
}

X86EMU_pioFuncs _A1_pio = 
{
    A1_inb,
    A1_inw,
    A1_inl,
    A1_outb,
    A1_outw,
    A1_outl,
};

static int reloced_ops = 0;

void reloc_ops(void *reloc_addr)
{
    extern void (*x86emu_optab[256])(u8);
    extern void (*x86emu_optab2[256])(u8);
    extern void tables_relocate(unsigned int offset);
    int i;
    unsigned long delta;
    if (reloced_ops == 1) return;
    reloced_ops = 1;

    delta = TEXT_BASE - (unsigned long)reloc_addr;

    for (i=0; i<256; i++)
    {
	x86emu_optab[i] -= delta;
	x86emu_optab2[i] -= delta;
    }
    
    _A1_mem.rdb = A1_rdb;
    _A1_mem.rdw = A1_rdw;
    _A1_mem.rdl = A1_rdl;
    _A1_mem.wrb = A1_wrb;
    _A1_mem.wrw = A1_wrw;
    _A1_mem.wrl = A1_wrl;

    _A1_pio.inb = A1_inb;
    _A1_pio.inw = A1_inw;
    _A1_pio.inl = A1_inl;
    _A1_pio.outb = A1_outb;
    _A1_pio.outw = A1_outw;
    _A1_pio.outl = A1_outl;
    
    tables_relocate(delta);

}


#define ANY_KEY(text)				\
    printf(text);				\
    while (!tstc());


unsigned char more_strap[] = {
        0xb4, 0x0, 0xb0, 0x2, 0xcd, 0x10,
};
#define MORE_STRAP_BYTES 6 // Additional bytes of strap code


unsigned char *done_msg="VGA Initialized\0";

int execute_bios(pci_dev_t gr_dev, void *reloc_addr)
{
    extern void bios_init(void);
    extern void remove_init_data(void);
    extern int video_rows(void);
    extern int video_cols(void);
    extern int video_size(int, int);
    u8 *strap;
    unsigned char *logo;
    u8 cfg;
    int i;
    char c;
    char *s;
#ifdef EASTEREGG
    int easteregg_active = 0;
#endif
    char *pal_reset;
    u8 *fb;
    unsigned char *msg;
    unsigned char current_attr;

    PRINTF("Trying to remove init data\n");
    remove_init_data();
    PRINTF("Removed init data from cache, now in RAM\n");

    reloc_ops(reloc_addr);
    PRINTF("Attempting to run emulator on %02x:%02x:%02x\n",
	   PCI_BUS(gr_dev), PCI_DEV(gr_dev), PCI_FUNC(gr_dev));

    // Enable compatibility hole for emulator access to frame buffer
    PRINTF("Enabling compatibility hole\n");
    enable_compatibility_hole();

    // Allocate memory
    // FIXME: We shouldn't use this much memory really.
    memset(&M, 0, sizeof(X86EMU_sysEnv));
    M.mem_base = malloc(EMULATOR_MEM_SIZE);
    M.mem_size = EMULATOR_MEM_SIZE;

    if (!M.mem_base)
    {
	PRINTF("Unable to allocate one megabyte for emulator\n");
	return 0;
    }

    if (attempt_map_rom(gr_dev, M.mem_base + EMULATOR_BIOS_OFFSET) == 0)
    {
	PRINTF("Error mapping rom. Emulation terminated\n");
	return 0;
    }

#if 1 /*def DEBUG*/
    s = getenv("x86_ask_start");
    if (s)
    {
	printf("Press 'q' to skip initialization, 'd' for dry init\n'i' for i/o session");
	while (!tstc());
	c = getc();
	if (c == 'q') return 0;
	if (c == 'd')
	{
	    extern void bios_set_mode(int mode);
	    bios_set_mode(0x03);
	    return 0;
	}
	if (c == 'i') do_inout();
    }


#endif

#ifdef EASTEREGG
/*    if (tstc())
    {
	if (getc() == 'c')
	{
	    easteregg_active = 1;
	}
    }
*/
    if (getenv("easteregg"))
    {
	easteregg_active = 1;
    }
    
    if (easteregg_active)
    {
	// Yay!
	setenv("x86_mode", "1");
	setenv("vga_fg_color", "11");
	setenv("vga_bg_color", "1");
	easteregg_active = 1;
    }
#endif

    strap = (u8*)M.mem_base + EMULATOR_STRAP_OFFSET;

    {
	char *m = getenv("x86_mode");
	if (m)
	{
	    more_strap[3] = atoi(m);
	    if (more_strap[3] == 1) video_size(40, 25);
	    else                    video_size(80, 25);
	}
    }

    /* 
     * Poke the strap routine. This might need a bit of extending
     * if there is a mode switch involved, i.e. we want to int10 
     * afterwards to set a different graphics mode, or alternatively
     * there might be a different start address requirement if the
     * ROM doesn't have an x86 image in its first image.
     */

    PRINTF("Poking strap...\n");

    // FAR CALL c000:0003
    *strap++ = 0x9A; *strap++ = 0x03; *strap++ = 0x00;
    *strap++ = 0x00; *strap++ = 0xC0; 

#if 1
    // insert additional strap code
    for (i=0; i < MORE_STRAP_BYTES; i++)
    {
	*strap++ = more_strap[i];
    }
#endif
    // HALT
    *strap++ = 0xF4; 

    PRINTF("Setting up logo data\n");
    logo = (unsigned char *)M.mem_base + EMULATOR_LOGO_OFFSET;
    for (i=0; i<16; i++)
    {
	*logo++ = 0xFF;
    }

    /*
     * Setup the init parameters.
     * Per PCI specs, AH must contain the bus and AL
     * must contain the devfn, encoded as (dev<<3)|fn
     */

    // Execution starts here
    M.x86.R_CS = SEG(EMULATOR_STRAP_OFFSET); 
    M.x86.R_IP = OFF(EMULATOR_STRAP_OFFSET); 

    // Stack at top of ram
    M.x86.R_SS = SEG(EMULATOR_STACK_OFFSET);
    M.x86.R_SP = OFF(EMULATOR_STACK_OFFSET);

    // Input parameters
    M.x86.R_AH = PCI_BUS(gr_dev);
    M.x86.R_AL = (PCI_DEV(gr_dev)<<3) | PCI_FUNC(gr_dev);

    // Set the I/O and memory access functions
    X86EMU_setupMemFuncs(&_A1_mem);
    X86EMU_setupPioFuncs(&_A1_pio);

    // Enable timer 2
    cfg = in_byte(0x61); // Get Misc control
    cfg |= 0x01;         // Enable timer 2
    out_byte(0x61, cfg); // output again

    // Set up the timers
    out_byte(0x43, 0x54);
    out_byte(0x41, 0x18);

    out_byte(0x43, 0x36);
    out_byte(0x40, 0x00);
    out_byte(0x40, 0x00);

    out_byte(0x43, 0xb6);
    out_byte(0x42, 0x31);
    out_byte(0x42, 0x13);

    // Init the "BIOS".
    bios_init();

    // Video Card Reset
    out_byte(0x3D8, 0);
    out_byte(0x3B8, 1);
    (void)in_byte(0x3BA);
    (void)in_byte(0x3DA);
    out_byte(0x3C0, 0);
    out_byte(0x61, 0xFC);

#ifdef DEBUG
    s = _getenv("x86_singlestep");
    if (s && strcmp(s, "on")==0)
    {
	PRINTF("Enabling single stepping for debug\n");
	X86EMU_trace_on();
    }
#endif

    // Ready set go...
    PRINTF("Running emulator\n");
    X86EMU_exec();
    PRINTF("Done running emulator\n");

/* FIXME: Remove me */
    pal_reset = getenv("x86_palette_reset");
    if (pal_reset && strcmp(pal_reset, "on") == 0)
    {
	PRINTF("Palette reset\n");
	//(void)in_byte(0x3da);
	//out_byte(0x3c0, 0);

	out_byte(0x3C8, 0);
	out_byte(0x3C9, 0);
	out_byte(0x3C9, 0);
	out_byte(0x3C9, 0);
	for (i=0; i<254; i++)
	{
	    out_byte(0x3C9, 63);
	    out_byte(0x3C9, 63);
	    out_byte(0x3C9, 63);
	}

	out_byte(0x3c0, 0x20);
    }
/* FIXME: remove me */
#ifdef EASTEREGG
    if (easteregg_active)
    {
	extern void video_easteregg(void);
	video_easteregg();
    }
#endif
/*
    current_attr = video_get_attr();
    fb = (u8 *)VIDEO_BASE;
    for (i=0; i<video_rows()*video_cols()*2; i+=2)
    {
	*(fb+i) = ' ';
	*(fb+i+1) = current_attr;
    }

    fb = (u8 *)VIDEO_BASE + (video_rows())-1*(video_cols()*2);
    for (i=0; i<video_cols(); i++)
    {
	*(fb + 2*i)     = 32;
	*(fb + 2*i + 1) = 0x17;
    }

    msg = done_msg;
    while (*msg)
    {
	*fb = *msg;
	fb  += 2;
	msg ++;
    }
*/
#ifdef DEBUG
    if (getenv("x86_do_inout")) do_inout();
#endif

//FIXME:    dcache_disable();
    return 1;
}

// Clean up the x86 mess
void shutdown_bios(void)
{
//    disable_compatibility_hole();
    // Free the memory associated
    free(M.mem_base);

}

int to_int(char *buffer)
{
    int base = 0;
    int res  = 0;

    if (*buffer == '$') 
    {
	base = 16;
	buffer++;
    }
    else base = 10;

    for (;;)
    {
	switch(*buffer)
	{
	case '0' ... '9':
	    res *= base;
	    res += *buffer - '0';
	    break;
	case 'A':
	case 'a':
	    res *= base;
	    res += 10;
	    break;
	case 'B':
	case 'b':
	    res *= base;
	    res += 11;
	    break;	    
	case 'C':
	case 'c':
	    res *= base;
	    res += 12;
	    break;	    
	case 'D':
	case 'd':
	    res *= base;
	    res += 13;
	    break;	    
	case 'E':
	case 'e':
	    res *= base;
	    res += 14;
	    break;	    
	case 'F':
	case 'f':
	    res *= base;
	    res += 15;
	    break;	
	default:
	    return res;
	}
	buffer++;
    }
    return res;
}

void one_arg(char *buffer, int *a)
{
    while (*buffer && *buffer != '\n')
    {
	if (*buffer == ' ') buffer++;
	else break;
    }

    *a = to_int(buffer);
}

void two_args(char *buffer, int *a, int *b)
{
    while (*buffer && *buffer != '\n')
    {
	if (*buffer == ' ') buffer++;
	else break;
    }

    *a = to_int(buffer);

    while (*buffer && *buffer != '\n')
    {
	if (*buffer != ' ') buffer++;
	else break;
    }

    while (*buffer && *buffer != '\n')
    {
	if (*buffer == ' ') buffer++;
	else break;
    }

    *b = to_int(buffer);
}

void do_inout(void)
{
    char buffer[256];
    char *arg1, *arg2;
    int a,b;

    printf("In/Out Session\nUse 'i[bwl]' for in, 'o[bwl]' for out and 'q' to quit\n");

    do
    {
	cons_gets(buffer);
	printf("\n");

	*arg1 = buffer;
	while (*arg1 != ' ' ) arg1++;
	while (*arg1 == ' ') arg1++;

	if (buffer[0] == 'i')
	{
	    one_arg(buffer+2, &a);
	    switch (buffer[1])
	    {
	    case 'b':
		printf("in_byte(%xh) = %xh\n", a, A1_inb(a));
		break;
	    case 'w':
		printf("in_word(%xh) = %xh\n", a, A1_inw(a));
		break;
	    case 'l':
		printf("in_dword(%xh) = %xh\n", a, A1_inl(a));
		break;
	    default:
		printf("Invalid length '%c'\n", buffer[1]);
		break;
	    }
	}
	else if (buffer[0] == 'o')
	{
	    two_args(buffer+2, &a, &b);
	    switch (buffer[1])
	    {
	    case 'b':
		printf("out_byte(%d, %d)\n", a, b);
		A1_outb(a,b);
		break;
	    case 'w':
		printf("out_word(%d, %d)\n", a, b);
		A1_outw(a, b);
		break;
	    case 'l':
		printf("out_long(%d, %d)\n", a, b);
		A1_outl(a, b);
		break;
	    default:
		printf("Invalid length '%c'\n", buffer[1]);
		break;
	    }
	} else if (buffer[0] == 'q') return;
    } while (1);
}