OpenBSD/sgi on octane2 - cpu1デバッグ用のcom1向け簡易printfの実装
調子にのってprintfも実装した。
#define COM_NPORTS 8 #define COM_FREQ 1843200 /* 16-bit baud rate divisor */ #define COMBBUF_SIZE 2048 int combfreq = 22000000 / 3; int combrate = TTYDEF_SPEED; bus_addr_t combaddr = 0x500000 + IOC3_UARTB_BASE; bus_space_tag_t combiot = &sys_config.console_io; bus_space_handle_t combioh; char combbuf[COMBBUF_SIZE] = {0}; void cominit(bus_space_tag_t iot, bus_space_handle_t ioh, int rate, int frequency); static void combinit(void) { if (bus_space_map(combiot, combaddr, COM_NPORTS, 0, &combioh)) panic("comcninit: mapping failed"); if (combfreq == 0) combfreq = COM_FREQ; cominit(combiot, combioh, combrate, combfreq); } static void combputc(int c) { com_common_putc(combiot, combioh, c); } static int combprintf(const char *fmt, ...) { int i; va_list ap; va_start(ap, fmt); vsnprintf(combbuf, COMBBUF_SIZE, fmt, ap); va_end(ap); for(i = 0; i < COMBBUF_SIZE; i++) if(combbuf[i] == '\0') break; else combputc(combbuf[i]); return 0; }
こんなテケトーなコードでいいのかよ。<こまけぇことはいいんだよ!
これで走らせてみたら、なんかこんな感じに出力が乱れた。あれ、なぜ?
comb initialized by cpu1
ci:0xffffffffc00fe800
gp:0xa8000000205c0c10
sp:0xa800000020630eb0
[../../../../arch/sgi/sgi/ip30_machdep.c:prom_cpu_hatch:357]
[../../../../arch/sgi/sgi/ip30_machdep.c:prom_cpu_hatch:365]
[../../../../arch/sgi/sgi/ip30_machdep.c:prom_cpu_hatch:373]
[../../../../arch/sgi/sgi/ip30_machdep.c:prom_cpu_hatch:375]
[../../../../arch/sgi/sgi/ip30_machdep.c:prom_cpu_hatch:382]
[../../../../arch/sgi/sgi/ip30_machdep.c:prom_cpu_hatch:385]
[../../../../arch/sgi/sgi/ip30_machdep.c:prom_cpu_hatch:387]
[../../../../arch/sgi/sgi/ip30_machdep.c:prom_cpu_hatch:389]
[../../../../arch/sgi/sgi/ip30_machdep.c:prom_cpu_hatch:393]
[../../../../arch/sgi/sgi/ip30_machdep.c:prom_cpu_hatch:399]
[../../../../arch/sgi/sgi/ip30_machdep.c:prom_cpu_hatch:404]