From fd6646f21b70d0268596dd014963051e61ae28ad Mon Sep 17 00:00:00 2001 From: RichardG867 Date: Wed, 16 Mar 2022 14:12:45 -0300 Subject: [PATCH] Run clang-format on all my new code --- src/gdbstub.c | 1798 ++++++++++++++++++----------------- src/include/86box/gdbstub.h | 52 +- src/sound/snd_ad1848.c | 18 +- src/sound/snd_cmi8x38.c | 1459 ++++++++++++++-------------- src/sound/snd_cs423x.c | 80 +- src/sound/snd_sb.c | 323 ++++--- src/sound/snd_sb_dsp.c | 4 +- 7 files changed, 1877 insertions(+), 1857 deletions(-) diff --git a/src/gdbstub.c b/src/gdbstub.c index 70c67d662..d6b410a95 100644 --- a/src/gdbstub.c +++ b/src/gdbstub.c @@ -16,17 +16,17 @@ */ #include #include -#include #include -#include +#include #include +#include #include #ifdef _WIN32 -# include -# include +# include +# include #else -# include -# include +# include +# include #endif #define HAVE_STDARG_H #include <86box/86box.h> @@ -39,24 +39,64 @@ #include <86box/plat.h> #include <86box/gdbstub.h> - -#define FAST_RESPONSE(s) strcpy(client->response, s); client->response_pos = sizeof(s); +#define FAST_RESPONSE(s) \ + strcpy(client->response, s); \ + client->response_pos = sizeof(s); #define FAST_RESPONSE_HEX(s) gdbstub_client_respond_hex(client, (uint8_t *) s, sizeof(s)); - enum { - GDB_SIGINT = 2, + GDB_SIGINT = 2, GDB_SIGTRAP = 5 }; enum { - GDB_REG_EAX = 0, GDB_REG_ECX, GDB_REG_EDX, GDB_REG_EBX, GDB_REG_ESP, GDB_REG_EBP, GDB_REG_ESI, GDB_REG_EDI, - GDB_REG_EIP, GDB_REG_EFLAGS, - GDB_REG_CS, GDB_REG_SS, GDB_REG_DS, GDB_REG_ES, GDB_REG_FS, GDB_REG_GS, GDB_REG_FS_BASE, GDB_REG_GS_BASE, - GDB_REG_CR0, GDB_REG_CR2, GDB_REG_CR3, GDB_REG_CR4, GDB_REG_EFER, - GDB_REG_ST0, GDB_REG_ST1, GDB_REG_ST2, GDB_REG_ST3, GDB_REG_ST4, GDB_REG_ST5, GDB_REG_ST6, GDB_REG_ST7, - GDB_REG_FCTRL, GDB_REG_FSTAT, GDB_REG_FTAG, GDB_REG_FISEG, GDB_REG_FIOFF, GDB_REG_FOSEG, GDB_REG_FOOFF, GDB_REG_FOP, - GDB_REG_MM0, GDB_REG_MM1, GDB_REG_MM2, GDB_REG_MM3, GDB_REG_MM4, GDB_REG_MM5, GDB_REG_MM6, GDB_REG_MM7, + GDB_REG_EAX = 0, + GDB_REG_ECX, + GDB_REG_EDX, + GDB_REG_EBX, + GDB_REG_ESP, + GDB_REG_EBP, + GDB_REG_ESI, + GDB_REG_EDI, + GDB_REG_EIP, + GDB_REG_EFLAGS, + GDB_REG_CS, + GDB_REG_SS, + GDB_REG_DS, + GDB_REG_ES, + GDB_REG_FS, + GDB_REG_GS, + GDB_REG_FS_BASE, + GDB_REG_GS_BASE, + GDB_REG_CR0, + GDB_REG_CR2, + GDB_REG_CR3, + GDB_REG_CR4, + GDB_REG_EFER, + GDB_REG_ST0, + GDB_REG_ST1, + GDB_REG_ST2, + GDB_REG_ST3, + GDB_REG_ST4, + GDB_REG_ST5, + GDB_REG_ST6, + GDB_REG_ST7, + GDB_REG_FCTRL, + GDB_REG_FSTAT, + GDB_REG_FTAG, + GDB_REG_FISEG, + GDB_REG_FIOFF, + GDB_REG_FOSEG, + GDB_REG_FOOFF, + GDB_REG_FOP, + GDB_REG_MM0, + GDB_REG_MM1, + GDB_REG_MM2, + GDB_REG_MM3, + GDB_REG_MM4, + GDB_REG_MM5, + GDB_REG_MM6, + GDB_REG_MM7, GDB_REG_MAX }; @@ -107,163 +147,165 @@ gdbstub_log(const char *fmt, ...) } } #else -#define gdbstub_log(fmt, ...) +# define gdbstub_log(fmt, ...) #endif -static x86seg *segment_regs[] = {&cpu_state.seg_cs, &cpu_state.seg_ss, &cpu_state.seg_ds, &cpu_state.seg_es, &cpu_state.seg_fs, &cpu_state.seg_gs}; -static uint32_t *cr_regs[] = {&cpu_state.CR0.l, &cr2, &cr3, &cr4}; -static void *fpu_regs[] = {&cpu_state.npxc, &cpu_state.npxs, NULL, &x87_pc_seg, &x87_pc_off, &x87_op_seg, &x87_op_off}; -static const char target_xml[] = /* based on qemu's i386-32bit.xml */ +static x86seg *segment_regs[] = { &cpu_state.seg_cs, &cpu_state.seg_ss, &cpu_state.seg_ds, &cpu_state.seg_es, &cpu_state.seg_fs, &cpu_state.seg_gs }; +static uint32_t *cr_regs[] = { &cpu_state.CR0.l, &cr2, &cr3, &cr4 }; +static void *fpu_regs[] = { &cpu_state.npxc, &cpu_state.npxs, NULL, &x87_pc_seg, &x87_pc_off, &x87_op_seg, &x87_op_off }; +static const char target_xml[] = /* based on qemu's i386-32bit.xml */ + // clang-format off "" "" "" "i8086" "" - "" - "" - "" - "" - "" - "" - "" - "" - "" - "" - "" - "" - "" - "" - "" - "" - "" - "" - "" - "" - "" - "" - "" - "" - "" - "" - "" - "" - "" - "" - "" - "" - "" - "" - "" - "" - "" - "" - "" - "" - "" - "" - "" - "" - "" - "" - "" - "" - "" - "" - "" - "" - "" - "" - "" - "" - "" - "" - "" - "" - "" - "" - "" - "" - "" - "" - "" - "" - "" - "" - "" - "" - "" - "" - "" - "" - "" - "" - "" - "" - "" - "" - "" - "" - "" - "" - "" - "" - "" - "" - "" - "" - "" - "" - "" - "" - "" - "" - "" - "" - "" - "" - "" - "" - "" - "" - "" - "" - "" - "" - "" - "" - "" - "" - "" - "" - "" - "" - "" - "" - "" - "" - "" - "" - "" - "" - "" - "" - "" - "" - "" - "" - "" - "" - "" - "" - "" - "" - "" - "" + "" + "" + "" + "" + "" + "" + "" + "" + "" + "" + "" + "" + "" + "" + "" + "" + "" + "" + "" + "" + "" + "" + "" + "" + "" + "" + "" + "" + "" + "" + "" + "" + "" + "" + "" + "" + "" + "" + "" + "" + "" + "" + "" + "" + "" + "" + "" + "" + "" + "" + "" + "" + "" + "" + "" + "" + "" + "" + "" + "" + "" + "" + "" + "" + "" + "" + "" + "" + "" + "" + "" + "" + "" + "" + "" + "" + "" + "" + "" + "" + "" + "" + "" + "" + "" + "" + "" + "" + "" + "" + "" + "" + "" + "" + "" + "" + "" + "" + "" + "" + "" + "" + "" + "" + "" + "" + "" + "" + "" + "" + "" + "" + "" + "" + "" + "" + "" + "" + "" + "" + "" + "" + "" + "" + "" + "" + "" + "" + "" + "" + "" + "" + "" + "" + "" + "" + "" + "" + "" + "" "" ""; +// clang-format on #ifdef _WIN32 -static WSADATA wsa; +static WSADATA wsa; #endif static int gdbstub_socket = -1, stop_reason_len = 0, in_gdbstub = 0; static uint32_t watch_addr; @@ -272,14 +314,13 @@ static char stop_reason[2048]; static gdbstub_client_t *first_client = NULL, *last_client = NULL; static mutex_t *client_list_mutex; -static void (*cpu_exec_shadow)(int cycs); +static void (*cpu_exec_shadow)(int cycs); static gdbstub_breakpoint_t *first_swbreak = NULL, *first_hwbreak = NULL, *first_rwatch = NULL, *first_wwatch = NULL, *first_awatch = NULL; -int gdbstub_step = 0, gdbstub_next_asap = 0; +int gdbstub_step = 0, gdbstub_next_asap = 0; uint64_t gdbstub_watch_pages[(((uint32_t) -1) >> (MEM_GRANULARITY_BITS + 6)) + 1]; - static void gdbstub_break() { @@ -288,7 +329,6 @@ gdbstub_break() gdbstub_step = GDBSTUB_BREAK; } - static void gdbstub_jump(uint32_t new_pc) { @@ -302,7 +342,6 @@ gdbstub_jump(uint32_t new_pc) flushmmucache(); } - static inline int gdbstub_hex_decode(int c) { @@ -316,7 +355,6 @@ gdbstub_hex_decode(int c) return 0; } - static inline int gdbstub_hex_encode(int c) { @@ -326,7 +364,6 @@ gdbstub_hex_encode(int c) return c - 10 + 'A'; } - static int gdbstub_num_decode(char *p, int *dest, int mode) { @@ -338,36 +375,36 @@ gdbstub_num_decode(char *p, int *dest, int mode) int sign = 1; if ((p[0] == '+') || (p[0] == '-')) { if (p[0] == '-') - sign = -1; + sign = -1; p++; } /* Read type identifer if present (0x/0o/0b/0n) */ if (p[0] == '0') { switch (p[1]) { - case 'x': - mode = GDB_MODE_HEX; - break; + case 'x': + mode = GDB_MODE_HEX; + break; - case '0' ... '7': - p -= 1; - /* fall-through */ + case '0' ... '7': + p -= 1; + /* fall-through */ - case 'o': - mode = GDB_MODE_OCT; - break; + case 'o': + mode = GDB_MODE_OCT; + break; - case 'b': - mode = GDB_MODE_BIN; - break; + case 'b': + mode = GDB_MODE_BIN; + break; - case 'n': - mode = GDB_MODE_BASE10; - break; + case 'n': + mode = GDB_MODE_BASE10; + break; - default: - p -= 2; - break; + default: + p -= 2; + break; } p += 2; } @@ -376,33 +413,33 @@ gdbstub_num_decode(char *p, int *dest, int mode) *dest = 0; while (*p) { switch (mode) { - case GDB_MODE_BASE10: - if ((*p >= '0') && (*p <= '9')) - *dest = ((*dest) * 10) + ((*p) - '0'); - else - return 0; - break; + case GDB_MODE_BASE10: + if ((*p >= '0') && (*p <= '9')) + *dest = ((*dest) * 10) + ((*p) - '0'); + else + return 0; + break; - case GDB_MODE_HEX: - if (((*p >= '0') && (*p <= '9')) || ((*p >= 'A') && (*p <= 'F')) || ((*p >= 'a') && (*p <= 'f'))) - *dest = ((*dest) << 4) | gdbstub_hex_decode(*p); - else - return 0; - break; + case GDB_MODE_HEX: + if (((*p >= '0') && (*p <= '9')) || ((*p >= 'A') && (*p <= 'F')) || ((*p >= 'a') && (*p <= 'f'))) + *dest = ((*dest) << 4) | gdbstub_hex_decode(*p); + else + return 0; + break; - case GDB_MODE_OCT: - if ((*p >= '0') && (*p <= '7')) - *dest = ((*dest) << 3) | ((*p) - '0'); - else - return 0; - break; + case GDB_MODE_OCT: + if ((*p >= '0') && (*p <= '7')) + *dest = ((*dest) << 3) | ((*p) - '0'); + else + return 0; + break; - case GDB_MODE_BIN: - if ((*p == '0') || (*p == '1')) - *dest = ((*dest) << 1) | ((*p) - '0'); - else - return 0; - break; + case GDB_MODE_BIN: + if ((*p == '0') || (*p == '1')) + *dest = ((*dest) << 1) | ((*p) - '0'); + else + return 0; + break; } p++; } @@ -415,7 +452,6 @@ gdbstub_num_decode(char *p, int *dest, int mode) return 1; } - static int gdbstub_client_read_word(gdbstub_client_t *client, int *dest) { @@ -425,29 +461,27 @@ gdbstub_client_read_word(gdbstub_client_t *client, int *dest) return p - q; } - static int gdbstub_client_read_hex(gdbstub_client_t *client, uint8_t *buf, int size) { int pp = client->packet_pos; while (size-- && (pp < (sizeof(client->packet) - 2))) { - *buf = gdbstub_hex_decode(client->packet[pp++]) << 4; + *buf = gdbstub_hex_decode(client->packet[pp++]) << 4; *buf++ |= gdbstub_hex_decode(client->packet[pp++]); } return pp - client->packet_pos; } - static int gdbstub_client_read_string(gdbstub_client_t *client, char *buf, int size, char terminator) { - int pp = client->packet_pos; + int pp = client->packet_pos; char c; while (size-- && (pp < (sizeof(client->packet) - 1))) { c = client->packet[pp]; if ((c == terminator) || (c == '\0')) { - *buf = '\0'; - break; + *buf = '\0'; + break; } pp++; *buf++ = c; @@ -455,91 +489,89 @@ gdbstub_client_read_string(gdbstub_client_t *client, char *buf, int size, char t return pp - client->packet_pos; } - static int gdbstub_client_write_reg(int index, uint8_t *buf) { int width = 4; switch (index) { case GDB_REG_EAX ... GDB_REG_EDI: - cpu_state.regs[index - GDB_REG_EAX].l = *((uint32_t *) buf); - break; + cpu_state.regs[index - GDB_REG_EAX].l = *((uint32_t *) buf); + break; case GDB_REG_EIP: - gdbstub_jump(*((uint32_t *) buf)); - break; + gdbstub_jump(*((uint32_t *) buf)); + break; case GDB_REG_EFLAGS: - cpu_state.flags = *((uint16_t *) &buf[0]); - cpu_state.eflags = *((uint16_t *) &buf[2]); - break; + cpu_state.flags = *((uint16_t *) &buf[0]); + cpu_state.eflags = *((uint16_t *) &buf[2]); + break; case GDB_REG_CS ... GDB_REG_GS: - width = 2; - loadseg(*((uint16_t *) buf), segment_regs[index - GDB_REG_CS]); - flushmmucache(); - break; + width = 2; + loadseg(*((uint16_t *) buf), segment_regs[index - GDB_REG_CS]); + flushmmucache(); + break; case GDB_REG_FS_BASE ... GDB_REG_GS_BASE: - /* Do what qemu does and just load the base. */ - segment_regs[(index - 16) + (GDB_REG_FS - GDB_REG_CS)]->base = *((uint32_t *) buf); - break; + /* Do what qemu does and just load the base. */ + segment_regs[(index - 16) + (GDB_REG_FS - GDB_REG_CS)]->base = *((uint32_t *) buf); + break; case GDB_REG_CR0 ... GDB_REG_CR4: - *cr_regs[index - GDB_REG_CR0] = *((uint32_t *) buf); - flushmmucache(); - break; + *cr_regs[index - GDB_REG_CR0] = *((uint32_t *) buf); + flushmmucache(); + break; case GDB_REG_EFER: - msr.amd_efer = *((uint64_t *) buf); - break; + msr.amd_efer = *((uint64_t *) buf); + break; case GDB_REG_ST0 ... GDB_REG_ST7: - width = 10; - x87_conv_t conv = { - .eind = { .ll = *((uint64_t *) &buf[0]) }, - .begin = *((uint16_t *) &buf[8]) - }; - cpu_state.ST[(cpu_state.TOP + (index - GDB_REG_ST0)) & 7] = x87_from80(&conv); - break; + width = 10; + x87_conv_t conv = { + .eind = { .ll = *((uint64_t *) &buf[0]) }, + .begin = *((uint16_t *) &buf[8]) + }; + cpu_state.ST[(cpu_state.TOP + (index - GDB_REG_ST0)) & 7] = x87_from80(&conv); + break; case GDB_REG_FCTRL: case GDB_REG_FISEG: case GDB_REG_FOSEG: - width = 2; - *((uint16_t *) fpu_regs[index - GDB_REG_FCTRL]) = *((uint16_t *) buf); - if (index >= GDB_REG_FISEG) - flushmmucache(); - break; + width = 2; + *((uint16_t *) fpu_regs[index - GDB_REG_FCTRL]) = *((uint16_t *) buf); + if (index >= GDB_REG_FISEG) + flushmmucache(); + break; case GDB_REG_FSTAT: case GDB_REG_FOP: - width = 2; - break; + width = 2; + break; case GDB_REG_FTAG: - width = 2; - x87_settag(*((uint16_t *) buf)); - break; + width = 2; + x87_settag(*((uint16_t *) buf)); + break; case GDB_REG_FIOFF: case GDB_REG_FOOFF: - *((uint32_t *) fpu_regs[index - GDB_REG_FCTRL]) = *((uint32_t *) buf); - break; + *((uint32_t *) fpu_regs[index - GDB_REG_FCTRL]) = *((uint32_t *) buf); + break; case GDB_REG_MM0 ... GDB_REG_MM7: - width = 8; - cpu_state.MM[index - GDB_REG_MM0].q = *((uint64_t *) &buf); - break; + width = 8; + cpu_state.MM[index - GDB_REG_MM0].q = *((uint64_t *) &buf); + break; default: - width = 0; + width = 0; } return width; } - static void gdbstub_client_respond(gdbstub_client_t *client) { @@ -551,18 +583,17 @@ gdbstub_client_respond(gdbstub_client_t *client) /* Send response packet. */ client->response[client->response_pos] = '\0'; #ifdef ENABLE_GDBSTUB_LOG - i = client->response[995]; /* pclog_ex buffer too small */ + i = client->response[995]; /* pclog_ex buffer too small */ client->response[995] = '\0'; gdbstub_log("GDB Stub: Sending response: %s\n", client->response); client->response[995] = i; #endif send(client->socket, "$", 1, 0); send(client->socket, client->response, client->response_pos, 0); - char response_cksum[3] = {'#', gdbstub_hex_encode((checksum >> 4) & 0x0f), gdbstub_hex_encode(checksum & 0x0f)}; + char response_cksum[3] = { '#', gdbstub_hex_encode((checksum >> 4) & 0x0f), gdbstub_hex_encode(checksum & 0x0f) }; send(client->socket, response_cksum, sizeof(response_cksum), 0); } - static void gdbstub_client_respond_partial(gdbstub_client_t *client) { @@ -574,7 +605,6 @@ gdbstub_client_respond_partial(gdbstub_client_t *client) thread_reset_event(client->response_event); } - static void gdbstub_client_respond_hex(gdbstub_client_t *client, uint8_t *buf, int size) { @@ -584,93 +614,91 @@ gdbstub_client_respond_hex(gdbstub_client_t *client, uint8_t *buf, int size) } } - static int gdbstub_client_read_reg(int index, uint8_t *buf) { int width = 4; switch (index) { case GDB_REG_EAX ... GDB_REG_EDI: - *((uint32_t *) buf) = cpu_state.regs[index].l; - break; + *((uint32_t *) buf) = cpu_state.regs[index].l; + break; case GDB_REG_EIP: - *((uint32_t *) buf) = cs + cpu_state.pc; - break; + *((uint32_t *) buf) = cs + cpu_state.pc; + break; case GDB_REG_EFLAGS: - *((uint16_t *) &buf[0]) = cpu_state.flags; - *((uint16_t *) &buf[2]) = cpu_state.eflags; - break; + *((uint16_t *) &buf[0]) = cpu_state.flags; + *((uint16_t *) &buf[2]) = cpu_state.eflags; + break; case GDB_REG_CS ... GDB_REG_GS: - *((uint16_t *) buf) = segment_regs[index - GDB_REG_CS]->seg; - break; + *((uint16_t *) buf) = segment_regs[index - GDB_REG_CS]->seg; + break; case GDB_REG_FS_BASE ... GDB_REG_GS_BASE: - *((uint32_t *) buf) = segment_regs[(index - 16) + (GDB_REG_FS - GDB_REG_CS)]->base; - break; + *((uint32_t *) buf) = segment_regs[(index - 16) + (GDB_REG_FS - GDB_REG_CS)]->base; + break; case GDB_REG_CR0 ... GDB_REG_CR4: - *((uint32_t *) buf) = *cr_regs[index - GDB_REG_CR0]; - break; + *((uint32_t *) buf) = *cr_regs[index - GDB_REG_CR0]; + break; case GDB_REG_EFER: - *((uint64_t *) buf) = msr.amd_efer; - break; + *((uint64_t *) buf) = msr.amd_efer; + break; case GDB_REG_ST0 ... GDB_REG_ST7: - width = 10; - x87_conv_t conv; - x87_to80(cpu_state.ST[(cpu_state.TOP + (index - GDB_REG_ST0)) & 7], &conv); - *((uint64_t *) &buf[0]) = conv.eind.ll; - *((uint16_t *) &buf[8]) = conv.begin; - break; + width = 10; + x87_conv_t conv; + x87_to80(cpu_state.ST[(cpu_state.TOP + (index - GDB_REG_ST0)) & 7], &conv); + *((uint64_t *) &buf[0]) = conv.eind.ll; + *((uint16_t *) &buf[8]) = conv.begin; + break; case GDB_REG_FCTRL ... GDB_REG_FSTAT: case GDB_REG_FISEG: case GDB_REG_FOSEG: - width = 2; - *((uint16_t *) buf) = *((uint16_t *) fpu_regs[index - GDB_REG_FCTRL]); - break; + width = 2; + *((uint16_t *) buf) = *((uint16_t *) fpu_regs[index - GDB_REG_FCTRL]); + break; case GDB_REG_FTAG: - width = 2; - *((uint16_t *) buf) = x87_gettag(); - break; + width = 2; + *((uint16_t *) buf) = x87_gettag(); + break; case GDB_REG_FIOFF: case GDB_REG_FOOFF: - *((uint32_t *) buf) = *((uint32_t *) fpu_regs[index - GDB_REG_FCTRL]); - break; + *((uint32_t *) buf) = *((uint32_t *) fpu_regs[index - GDB_REG_FCTRL]); + break; case GDB_REG_FOP: - width = 2; - *((uint16_t *) buf) = 0; /* we don't store the FPU opcode */ - break; + width = 2; + *((uint16_t *) buf) = 0; /* we don't store the FPU opcode */ + break; case GDB_REG_MM0 ... GDB_REG_MM7: - width = 8; - cpu_state.MM[index - GDB_REG_MM0].q = *((uint64_t *) &buf); - break; + width = 8; + cpu_state.MM[index - GDB_REG_MM0].q = *((uint64_t *) &buf); + break; default: - width = 0; + width = 0; } return width; } - static void gdbstub_client_packet(gdbstub_client_t *client) { #ifdef GDBSTUB_CHECK_CHECKSUM /* msys2 gdb 11.1 transmits qSupported and H with invalid checksum... */ uint8_t rcv_checksum = 0, checksum = 0; #endif - int i, j = 0, k = 0, l; - uint8_t buf[10] = {0}; - char *p; + int i, j = 0, k = 0, l; + uint8_t buf[10] = { 0 }; + char *p; /* Validate checksum. */ client->packet_pos -= 2; @@ -684,12 +712,12 @@ gdbstub_client_packet(gdbstub_client_t *client) if (checksum != rcv_checksum) { /* Send negative acknowledgement. */ -#ifdef ENABLE_GDBSTUB_LOG - i = client->packet[953]; /* pclog_ex buffer too small */ +# ifdef ENABLE_GDBSTUB_LOG + i = client->packet[953]; /* pclog_ex buffer too small */ client->packet[953] = '\0'; gdbstub_log("GDB Stub: Received packet with invalid checksum (expected %02X got %02X): %s\n", checksum, rcv_checksum, client->packet); client->packet[953] = i; -#endif +# endif send(client->socket, "-", 1, 0); return; } @@ -697,7 +725,7 @@ gdbstub_client_packet(gdbstub_client_t *client) /* Send positive acknowledgement. */ #ifdef ENABLE_GDBSTUB_LOG - i = client->packet[996]; /* pclog_ex buffer too small */ + i = client->packet[996]; /* pclog_ex buffer too small */ client->packet[996] = '\0'; gdbstub_log("GDB Stub: Received packet: %s\n", client->packet); client->packet[996] = i; @@ -710,498 +738,496 @@ gdbstub_client_packet(gdbstub_client_t *client) thread_reset_event(client->response_event); } client->response_pos = 0; - client->packet_pos = 1; + client->packet_pos = 1; /* Parse command. */ switch (client->packet[0]) { case '?': /* stop reason */ - /* Respond with a stop reply packet if one is present. */ - if (stop_reason_len) { - strcpy(client->response, stop_reason); - client->response_pos = strlen(client->response); - } - break; + /* Respond with a stop reply packet if one is present. */ + if (stop_reason_len) { + strcpy(client->response, stop_reason); + client->response_pos = strlen(client->response); + } + break; case 'c': /* continue */ case 's': /* step */ - /* Flag that the client is waiting for a stop reason. */ - client->waiting_stop = 1; + /* Flag that the client is waiting for a stop reason. */ + client->waiting_stop = 1; - /* Jump to address if specified. */ - if (client->packet[1] && gdbstub_client_read_word(client, &j)) - gdbstub_jump(j); + /* Jump to address if specified. */ + if (client->packet[1] && gdbstub_client_read_word(client, &j)) + gdbstub_jump(j); - /* Resume CPU. */ - gdbstub_step = gdbstub_next_asap = (client->packet[0] == 's') ? GDBSTUB_SSTEP : GDBSTUB_EXEC; - return; + /* Resume CPU. */ + gdbstub_step = gdbstub_next_asap = (client->packet[0] == 's') ? GDBSTUB_SSTEP : GDBSTUB_EXEC; + return; case 'D': /* detach */ - /* Resume emulation. */ - gdbstub_step = GDBSTUB_EXEC; + /* Resume emulation. */ + gdbstub_step = GDBSTUB_EXEC; - /* Respond positively. */ -ok: FAST_RESPONSE("OK"); - break; + /* Respond positively. */ +ok: + FAST_RESPONSE("OK"); + break; case 'g': /* read all registers */ - /* Output the values of all registers. */ - for (i = 0; i < GDB_REG_MAX; i++) - gdbstub_client_respond_hex(client, buf, gdbstub_client_read_reg(i, buf)); - break; + /* Output the values of all registers. */ + for (i = 0; i < GDB_REG_MAX; i++) + gdbstub_client_respond_hex(client, buf, gdbstub_client_read_reg(i, buf)); + break; case 'G': /* write all registers */ - /* Write the values of all registers. */ - for (i = 0; i < GDB_REG_MAX; i++) { - if (!gdbstub_client_read_hex(client, buf, sizeof(buf))) - break; - client->packet_pos += gdbstub_client_write_reg(i, buf); - } - break; + /* Write the values of all registers. */ + for (i = 0; i < GDB_REG_MAX; i++) { + if (!gdbstub_client_read_hex(client, buf, sizeof(buf))) + break; + client->packet_pos += gdbstub_client_write_reg(i, buf); + } + break; case 'H': /* set thread */ - /* Read operation type and thread ID. */ - if ((client->packet[1] == '\0') || (client->packet[2] == '\0')) { -e22: FAST_RESPONSE("E22"); - break; - } + /* Read operation type and thread ID. */ + if ((client->packet[1] == '\0') || (client->packet[2] == '\0')) { +e22: + FAST_RESPONSE("E22"); + break; + } - /* Respond positively only on thread 1. */ - if ((client->packet[2] == '1') && !client->packet[3]) - goto ok; - else - goto e22; + /* Respond positively only on thread 1. */ + if ((client->packet[2] == '1') && !client->packet[3]) + goto ok; + else + goto e22; case 'm': /* read memory */ - /* Read address and length. */ - if (!(i = gdbstub_client_read_word(client, &j))) - goto e22; - client->packet_pos += i + 1; - gdbstub_client_read_word(client, &k); - if (!k) - goto e22; + /* Read address and length. */ + if (!(i = gdbstub_client_read_word(client, &j))) + goto e22; + client->packet_pos += i + 1; + gdbstub_client_read_word(client, &k); + if (!k) + goto e22; - /* Clamp length. */ - if (k >= (sizeof(client->response) >> 1)) - k = (sizeof(client->response) >> 1) - 1; + /* Clamp length. */ + if (k >= (sizeof(client->response) >> 1)) + k = (sizeof(client->response) >> 1) - 1; - /* Read by qwords, then by dwords, then by words, then by bytes. */ - i = 0; - if (is386) { - for (; i < (k & ~7); i += 8) { - *((uint64_t *) buf) = readmemql(j); - j += 8; - gdbstub_client_respond_hex(client, buf, 8); - } - for (; i < (k & ~3); i += 4) { - *((uint32_t *) buf) = readmemll(j); - j += 4; - gdbstub_client_respond_hex(client, buf, 4); - } + /* Read by qwords, then by dwords, then by words, then by bytes. */ + i = 0; + if (is386) { + for (; i < (k & ~7); i += 8) { + *((uint64_t *) buf) = readmemql(j); + j += 8; + gdbstub_client_respond_hex(client, buf, 8); } - for (; i < (k & ~1); i += 2) { - *((uint16_t *) buf) = readmemwl(j); - j += 2; - gdbstub_client_respond_hex(client, buf, 2); + for (; i < (k & ~3); i += 4) { + *((uint32_t *) buf) = readmemll(j); + j += 4; + gdbstub_client_respond_hex(client, buf, 4); } - for (; i < k; i++) { - buf[0] = readmembl(j++); - gdbstub_client_respond_hex(client, buf, 1); - } - break; + } + for (; i < (k & ~1); i += 2) { + *((uint16_t *) buf) = readmemwl(j); + j += 2; + gdbstub_client_respond_hex(client, buf, 2); + } + for (; i < k; i++) { + buf[0] = readmembl(j++); + gdbstub_client_respond_hex(client, buf, 1); + } + break; case 'M': /* write memory */ case 'X': /* write memory binary */ - /* Read address and length. */ - if (!(i = gdbstub_client_read_word(client, &j))) - goto e22; - client->packet_pos += i + 1; - client->packet_pos += gdbstub_client_read_word(client, &k) + 1; - if (!k) - goto e22; + /* Read address and length. */ + if (!(i = gdbstub_client_read_word(client, &j))) + goto e22; + client->packet_pos += i + 1; + client->packet_pos += gdbstub_client_read_word(client, &k) + 1; + if (!k) + goto e22; - /* Clamp length. */ - if (k >= ((sizeof(client->response) >> 1) - client->packet_pos)) - k = (sizeof(client->response) >> 1) - client->packet_pos - 1; + /* Clamp length. */ + if (k >= ((sizeof(client->response) >> 1) - client->packet_pos)) + k = (sizeof(client->response) >> 1) - client->packet_pos - 1; - /* Decode the data. */ - if (client->packet[0] == 'M') { /* hex encoded */ - gdbstub_client_read_hex(client, (uint8_t *) client->packet, k); - } else { /* binary encoded */ - i = 0; - while (i < k) { - if (client->packet[client->packet_pos] == '}') { - client->packet_pos++; - client->packet[i++] = client->packet[client->packet_pos++] ^ 0x20; - } else { - client->packet[i++] = client->packet[client->packet_pos++]; - } - } - } - - /* Write by qwords, then by dwords, then by words, then by bytes. */ - p = client->packet; + /* Decode the data. */ + if (client->packet[0] == 'M') { /* hex encoded */ + gdbstub_client_read_hex(client, (uint8_t *) client->packet, k); + } else { /* binary encoded */ i = 0; - if (is386) { - for (; i < (k & ~7); i += 8) { - writememql(j, *((uint64_t *) p)); - j += 8; - p += 8; - } - for (; i < (k & ~3); i += 4) { - writememll(j, *((uint32_t *) p)); - j += 4; - p += 4; - } + while (i < k) { + if (client->packet[client->packet_pos] == '}') { + client->packet_pos++; + client->packet[i++] = client->packet[client->packet_pos++] ^ 0x20; + } else { + client->packet[i++] = client->packet[client->packet_pos++]; + } } - for (; i < (k & ~1); i += 2) { - writememwl(j, *((uint16_t *) p)); - j += 2; - p += 2; - } - for (; i < k; i++) { - writemembl(j++, p[0]); - p++; - } + } - /* Respond positively. */ - goto ok; + /* Write by qwords, then by dwords, then by words, then by bytes. */ + p = client->packet; + i = 0; + if (is386) { + for (; i < (k & ~7); i += 8) { + writememql(j, *((uint64_t *) p)); + j += 8; + p += 8; + } + for (; i < (k & ~3); i += 4) { + writememll(j, *((uint32_t *) p)); + j += 4; + p += 4; + } + } + for (; i < (k & ~1); i += 2) { + writememwl(j, *((uint16_t *) p)); + j += 2; + p += 2; + } + for (; i < k; i++) { + writemembl(j++, p[0]); + p++; + } + + /* Respond positively. */ + goto ok; case 'p': /* read register */ - /* Read register index. */ - if (!gdbstub_client_read_word(client, &j)) { -e14: FAST_RESPONSE("E14"); - break; - } - - /* Read the register's value. */ - if (!(i = gdbstub_client_read_reg(j, buf))) - goto e14; - - /* Return value. */ - gdbstub_client_respond_hex(client, buf, i); + /* Read register index. */ + if (!gdbstub_client_read_word(client, &j)) { +e14: + FAST_RESPONSE("E14"); break; + } + + /* Read the register's value. */ + if (!(i = gdbstub_client_read_reg(j, buf))) + goto e14; + + /* Return value. */ + gdbstub_client_respond_hex(client, buf, i); + break; case 'P': /* write register */ - /* Read register index and value. */ - if (!(i = gdbstub_client_read_word(client, &j))) - goto e14; - client->packet_pos += i + 1; - if (!gdbstub_client_read_hex(client, buf, sizeof(buf))) - goto e14; + /* Read register index and value. */ + if (!(i = gdbstub_client_read_word(client, &j))) + goto e14; + client->packet_pos += i + 1; + if (!gdbstub_client_read_hex(client, buf, sizeof(buf))) + goto e14; - /* Write the value to the register. */ - if (!gdbstub_client_write_reg(j, buf)) - goto e14; + /* Write the value to the register. */ + if (!gdbstub_client_write_reg(j, buf)) + goto e14; - /* Respond positively. */ - goto ok; + /* Respond positively. */ + goto ok; case 'q': /* query */ - /* Erase response, as we'll use it as a scratch buffer. */ - memset(client->response, 0, sizeof(client->response)); + /* Erase response, as we'll use it as a scratch buffer. */ + memset(client->response, 0, sizeof(client->response)); - /* Read the query type. */ - client->packet_pos += gdbstub_client_read_string(client, client->response, sizeof(client->response) - 1, - (client->packet[1] == 'R') ? ',' : ':') + 1; + /* Read the query type. */ + client->packet_pos += gdbstub_client_read_string(client, client->response, sizeof(client->response) - 1, + (client->packet[1] == 'R') ? ',' : ':') + + 1; - /* Perform the query. */ - if (!strcmp(client->response, "Supported")) { - /* Go through the feature list and negate ones we don't support. */ - while ((client->response_pos < (sizeof(client->response) - 1)) && - (i = gdbstub_client_read_string(client, &client->response[client->response_pos], sizeof(client->response) - client->response_pos - 1, ';'))) { - client->packet_pos += i + 1; - if (strncmp(&client->response[client->response_pos], "PacketSize", 10) && - strcmp(&client->response[client->response_pos], "swbreak") && - strcmp(&client->response[client->response_pos], "hwbreak") && - strncmp(&client->response[client->response_pos], "xmlRegisters", 12) && - strcmp(&client->response[client->response_pos], "qXfer:features:read")) { - gdbstub_log("GDB Stub: Feature \"%s\" is not supported\n", &client->response[client->response_pos]); - client->response_pos += i; - client->response[client->response_pos++] = '-'; - client->response[client->response_pos++] = ';'; - } else { - gdbstub_log("GDB Stub: Feature \"%s\" is supported\n", &client->response[client->response_pos]); - } - } + /* Perform the query. */ + if (!strcmp(client->response, "Supported")) { + /* Go through the feature list and negate ones we don't support. */ + while ((client->response_pos < (sizeof(client->response) - 1)) && (i = gdbstub_client_read_string(client, &client->response[client->response_pos], sizeof(client->response) - client->response_pos - 1, ';'))) { + client->packet_pos += i + 1; + if (strncmp(&client->response[client->response_pos], "PacketSize", 10) && strcmp(&client->response[client->response_pos], "swbreak") && strcmp(&client->response[client->response_pos], "hwbreak") && strncmp(&client->response[client->response_pos], "xmlRegisters", 12) && strcmp(&client->response[client->response_pos], "qXfer:features:read")) { + gdbstub_log("GDB Stub: Feature \"%s\" is not supported\n", &client->response[client->response_pos]); + client->response_pos += i; + client->response[client->response_pos++] = '-'; + client->response[client->response_pos++] = ';'; + } else { + gdbstub_log("GDB Stub: Feature \"%s\" is supported\n", &client->response[client->response_pos]); + } + } - /* Add our supported features to the end. */ - if (client->response_pos < (sizeof(client->response) - 1)) - client->response_pos += snprintf(&client->response[client->response_pos], sizeof(client->response) - client->response_pos, - "PacketSize=%X;swbreak+;hwbreak+;qXfer:features:read+", sizeof(client->packet) - 1); - break; - } else if (!strcmp(client->response, "Xfer")) { - /* Read the transfer object. */ + /* Add our supported features to the end. */ + if (client->response_pos < (sizeof(client->response) - 1)) + client->response_pos += snprintf(&client->response[client->response_pos], sizeof(client->response) - client->response_pos, + "PacketSize=%X;swbreak+;hwbreak+;qXfer:features:read+", sizeof(client->packet) - 1); + break; + } else if (!strcmp(client->response, "Xfer")) { + /* Read the transfer object. */ + client->packet_pos += gdbstub_client_read_string(client, client->response, sizeof(client->response) - 1, ':') + 1; + if (!strcmp(client->response, "features")) { + /* Read the transfer operation. */ + client->packet_pos += gdbstub_client_read_string(client, client->response, sizeof(client->response) - 1, ':') + 1; + if (!strcmp(client->response, "read")) { + /* Read the transfer annex. */ client->packet_pos += gdbstub_client_read_string(client, client->response, sizeof(client->response) - 1, ':') + 1; - if (!strcmp(client->response, "features")) { - /* Read the transfer operation. */ - client->packet_pos += gdbstub_client_read_string(client, client->response, sizeof(client->response) - 1, ':') + 1; - if (!strcmp(client->response, "read")) { - /* Read the transfer annex. */ - client->packet_pos += gdbstub_client_read_string(client, client->response, sizeof(client->response) - 1, ':') + 1; - if (!strcmp(client->response, "target.xml")) - p = (char *) target_xml; - else - p = NULL; + if (!strcmp(client->response, "target.xml")) + p = (char *) target_xml; + else + p = NULL; - /* Stop if the file wasn't found. */ - if (!p) { -e00: FAST_RESPONSE("E00"); - break; - } - - /* Read offset and length. */ - if (!(i = gdbstub_client_read_word(client, &j))) - goto e22; - client->packet_pos += i + 1; - client->packet_pos += gdbstub_client_read_word(client, &k) + 1; - if (!k) - goto e22; - - /* Check if the offset is valid. */ - l = strlen(p); - if (j > l) - goto e00; - p += j; - - /* Return the more/less flag while also clamping the length. */ - if (k >= ((sizeof(client->response) >> 1) - 2)) - k = (sizeof(client->response) >> 1) - 3; - if (k < (l - j)) { - client->response[client->response_pos++] = 'm'; - } else { - client->response[client->response_pos++] = 'l'; - k = l - j; - } - - /* Encode the data. */ - while (k--) { - i = *p++; - if ((i == '\0') || (i == '#') || (i == '$') || (i == '*') || (i == '}')) { - client->response[client->response_pos++] = '}'; - client->response[client->response_pos++] = i ^ 0x20; - } else { - client->response[client->response_pos++] = i; - } - } - break; - } + /* Stop if the file wasn't found. */ + if (!p) { +e00: + FAST_RESPONSE("E00"); + break; } - } else if (!strcmp(client->response, "Rcmd")) { - /* Read and decode command in-place. */ - i = gdbstub_client_read_hex(client, (uint8_t *) client->packet, strlen(client->packet) - client->packet_pos); - client->packet[i] = 0; - gdbstub_log("GDB Stub: Monitor command: %s\n", client->packet); - /* Parse the command name. */ - char *strtok_save; - p = strtok_r(client->packet, " ", &strtok_save); - if (!p) - goto ok; + /* Read offset and length. */ + if (!(i = gdbstub_client_read_word(client, &j))) + goto e22; + client->packet_pos += i + 1; + client->packet_pos += gdbstub_client_read_word(client, &k) + 1; + if (!k) + goto e22; - /* Interpret the command. */ - if (p[0] == 'i') { - /* Read I/O operation width. */ - l = (p[1] == 'n') ? p[2] : p[1]; + /* Check if the offset is valid. */ + l = strlen(p); + if (j > l) + goto e00; + p += j; - /* Read optional I/O port. */ - if (!(p = strtok_r(NULL, " ", &strtok_save)) || - !gdbstub_num_decode(p, &j, GDB_MODE_HEX) || - (j < 0) || (j >= 65536)) - j = client->last_io_base; + /* Return the more/less flag while also clamping the length. */ + if (k >= ((sizeof(client->response) >> 1) - 2)) + k = (sizeof(client->response) >> 1) - 3; + if (k < (l - j)) { + client->response[client->response_pos++] = 'm'; + } else { + client->response[client->response_pos++] = 'l'; + k = l - j; + } - /* Read optional length. */ - if (!(p = strtok_r(NULL, " ", &strtok_save)) || !gdbstub_num_decode(p, &k, GDB_MODE_BASE10)) - k = client->last_io_len; + /* Encode the data. */ + while (k--) { + i = *p++; + if ((i == '\0') || (i == '#') || (i == '$') || (i == '*') || (i == '}')) { + client->response[client->response_pos++] = '}'; + client->response[client->response_pos++] = i ^ 0x20; + } else { + client->response[client->response_pos++] = i; + } + } + break; + } + } + } else if (!strcmp(client->response, "Rcmd")) { + /* Read and decode command in-place. */ + i = gdbstub_client_read_hex(client, (uint8_t *) client->packet, strlen(client->packet) - client->packet_pos); + client->packet[i] = 0; + gdbstub_log("GDB Stub: Monitor command: %s\n", client->packet); - /* Clamp length. */ - if (k < 1) - k = 1; - if (k > (65536 - j)) - k = 65536 - j; + /* Parse the command name. */ + char *strtok_save; + p = strtok_r(client->packet, " ", &strtok_save); + if (!p) + goto ok; - /* Read ports. */ - i = 0; - while (i < k) { - if ((i % 16) == 0) { - if (i) { - client->packet[client->packet_pos++] = '\n'; + /* Interpret the command. */ + if (p[0] == 'i') { + /* Read I/O operation width. */ + l = (p[1] == 'n') ? p[2] : p[1]; - /* Provide partial response with the last line. */ - client->response_pos = 0; - client->response[client->response_pos++] = 'O'; - gdbstub_client_respond_hex(client, (uint8_t *) client->packet, client->packet_pos); - gdbstub_client_respond_partial(client); - } - client->packet_pos = sprintf(client->packet, "%04X:", j + i); - } - /* Act according to I/O operation width. */ - switch (l) { - case 'd': - case 'l': - client->packet_pos += sprintf(&client->packet[client->packet_pos], " %08X", inl(j + i)); - i += 4; - break; + /* Read optional I/O port. */ + if (!(p = strtok_r(NULL, " ", &strtok_save)) || !gdbstub_num_decode(p, &j, GDB_MODE_HEX) || (j < 0) || (j >= 65536)) + j = client->last_io_base; - case 'w': - client->packet_pos += sprintf(&client->packet[client->packet_pos], " %04X", inw(j + i)); - i += 2; - break; + /* Read optional length. */ + if (!(p = strtok_r(NULL, " ", &strtok_save)) || !gdbstub_num_decode(p, &k, GDB_MODE_BASE10)) + k = client->last_io_len; - case 'b': - case '\0': - client->packet_pos += sprintf(&client->packet[client->packet_pos], " %02X", inb(j + i)); - i++; - break; + /* Clamp length. */ + if (k < 1) + k = 1; + if (k > (65536 - j)) + k = 65536 - j; - default: - goto unknown; - } - } + /* Read ports. */ + i = 0; + while (i < k) { + if ((i % 16) == 0) { + if (i) { client->packet[client->packet_pos++] = '\n'; - /* Respond with the final line. */ - client->response_pos = 0; - gdbstub_client_respond_hex(client, (uint8_t *) &client->packet, client->packet_pos); - break; - } else { -unknown: FAST_RESPONSE_HEX("Unknown command\n"); - break; + /* Provide partial response with the last line. */ + client->response_pos = 0; + client->response[client->response_pos++] = 'O'; + gdbstub_client_respond_hex(client, (uint8_t *) client->packet, client->packet_pos); + gdbstub_client_respond_partial(client); + } + client->packet_pos = sprintf(client->packet, "%04X:", j + i); } + /* Act according to I/O operation width. */ + switch (l) { + case 'd': + case 'l': + client->packet_pos += sprintf(&client->packet[client->packet_pos], " %08X", inl(j + i)); + i += 4; + break; - goto ok; + case 'w': + client->packet_pos += sprintf(&client->packet[client->packet_pos], " %04X", inw(j + i)); + i += 2; + break; + + case 'b': + case '\0': + client->packet_pos += sprintf(&client->packet[client->packet_pos], " %02X", inb(j + i)); + i++; + break; + + default: + goto unknown; + } + } + client->packet[client->packet_pos++] = '\n'; + + /* Respond with the final line. */ + client->response_pos = 0; + gdbstub_client_respond_hex(client, (uint8_t *) &client->packet, client->packet_pos); + break; + } else { +unknown: + FAST_RESPONSE_HEX("Unknown command\n"); + break; } - break; + + goto ok; + } + break; case 'z': /* remove break/watchpoint */ case 'Z': /* insert break/watchpoint */ - gdbstub_breakpoint_t *breakpoint, *prev_breakpoint = NULL, **first_breakpoint; + gdbstub_breakpoint_t *breakpoint, *prev_breakpoint = NULL, **first_breakpoint; - /* Parse breakpoint type. */ - switch (client->packet[1]) { - case '0': /* software breakpoint */ - first_breakpoint = &first_swbreak; - break; + /* Parse breakpoint type. */ + switch (client->packet[1]) { + case '0': /* software breakpoint */ + first_breakpoint = &first_swbreak; + break; - case '1': /* hardware breakpoint */ - first_breakpoint = &first_hwbreak; - break; + case '1': /* hardware breakpoint */ + first_breakpoint = &first_hwbreak; + break; - case '2': /* write watchpoint */ - first_breakpoint = &first_wwatch; - break; + case '2': /* write watchpoint */ + first_breakpoint = &first_wwatch; + break; - case '3': /* read watchpoint */ - first_breakpoint = &first_rwatch; - break; + case '3': /* read watchpoint */ + first_breakpoint = &first_rwatch; + break; - case '4': /* access watchpoint */ - first_breakpoint = &first_awatch; - break; + case '4': /* access watchpoint */ + first_breakpoint = &first_awatch; + break; - default: /* unknown type */ - client->packet[2] = '\0'; /* force address check to fail */ - break; - } + default: /* unknown type */ + client->packet[2] = '\0'; /* force address check to fail */ + break; + } - /* Read address. */ - if (client->packet[2] != ',') - break; - client->packet_pos = 3; - if (!(i = gdbstub_client_read_word(client, &j))) - break; - client->packet_pos += i; - if (client->packet[client->packet_pos++] == ',') - gdbstub_client_read_word(client, &k); - else - k = 1; + /* Read address. */ + if (client->packet[2] != ',') + break; + client->packet_pos = 3; + if (!(i = gdbstub_client_read_word(client, &j))) + break; + client->packet_pos += i; + if (client->packet[client->packet_pos++] == ',') + gdbstub_client_read_word(client, &k); + else + k = 1; - /* Test writability of software breakpoint. */ - if (client->packet[1] == '0') { - buf[0] = readmembl(j); - writemembl(j, 0xcc); - buf[1] = readmembl(j); - writemembl(j, buf[0]); - if (buf[1] != 0xcc) - goto end; - } + /* Test writability of software breakpoint. */ + if (client->packet[1] == '0') { + buf[0] = readmembl(j); + writemembl(j, 0xcc); + buf[1] = readmembl(j); + writemembl(j, buf[0]); + if (buf[1] != 0xcc) + goto end; + } + + /* Find an existing breakpoint with this address. */ + breakpoint = *first_breakpoint; + while (breakpoint) { + if (breakpoint->addr == j) + break; + prev_breakpoint = breakpoint; + breakpoint = breakpoint->next; + } + + /* Check if the breakpoint is already present (when inserting) or not found (when removing). */ + if ((!!breakpoint) ^ (client->packet[0] == 'z')) + goto e22; + + /* Insert or remove the breakpoint. */ + if (client->packet[0] != 'z') { + /* Allocate a new breakpoint. */ + breakpoint = malloc(sizeof(gdbstub_breakpoint_t)); + breakpoint->addr = j; + breakpoint->end = j + k; + breakpoint->next = NULL; + + /* Add the new breakpoint to the list. */ + if (!(*first_breakpoint)) + *first_breakpoint = breakpoint; + else if (prev_breakpoint) + prev_breakpoint->next = breakpoint; + } else { + /* Remove breakpoint from the list. */ + if (breakpoint == *first_breakpoint) + *first_breakpoint = breakpoint->next; + else if (prev_breakpoint) + prev_breakpoint->next = breakpoint->next; + + /* De-allocate breakpoint. */ + free(breakpoint); + } + + /* Update the page watchpoint map if we're dealing with a watchpoint. */ + if (client->packet[1] >= '2') { + /* Clear this watchpoint's corresponding page map groups, + as everything is going to be recomputed soon anyway. */ + memset(&gdbstub_watch_pages[j >> (MEM_GRANULARITY_BITS + 6)], 0, + (((k - 1) >> (MEM_GRANULARITY_BITS + 6)) + 1) * sizeof(gdbstub_watch_pages[0])); + + /* Go through all watchpoint lists. */ + l = 0; + breakpoint = first_rwatch; + while (1) { + if (breakpoint) { + /* Flag this watchpoint's corresponding pages as having a watchpoint. */ + k = (breakpoint->end - 1) >> MEM_GRANULARITY_BITS; + for (i = breakpoint->addr >> MEM_GRANULARITY_BITS; i <= k; i++) + gdbstub_watch_pages[i >> 6] |= (1 << (i & 63)); - /* Find an existing breakpoint with this address. */ - breakpoint = *first_breakpoint; - while (breakpoint) { - if (breakpoint->addr == j) - break; - prev_breakpoint = breakpoint; breakpoint = breakpoint->next; + } else { + /* Jump from list to list as a shortcut. */ + if (l == 0) + breakpoint = first_wwatch; + else if (l == 1) + breakpoint = first_awatch; + else + break; + l++; + } } + } - /* Check if the breakpoint is already present (when inserting) or not found (when removing). */ - if ((!!breakpoint) ^ (client->packet[0] == 'z')) - goto e22; - - /* Insert or remove the breakpoint. */ - if (client->packet[0] != 'z') { - /* Allocate a new breakpoint. */ - breakpoint = malloc(sizeof(gdbstub_breakpoint_t)); - breakpoint->addr = j; - breakpoint->end = j + k; - breakpoint->next = NULL; - - /* Add the new breakpoint to the list. */ - if (!(*first_breakpoint)) - *first_breakpoint = breakpoint; - else if (prev_breakpoint) - prev_breakpoint->next = breakpoint; - } else { - /* Remove breakpoint from the list. */ - if (breakpoint == *first_breakpoint) - *first_breakpoint = breakpoint->next; - else if (prev_breakpoint) - prev_breakpoint->next = breakpoint->next; - - /* De-allocate breakpoint. */ - free(breakpoint); - } - - /* Update the page watchpoint map if we're dealing with a watchpoint. */ - if (client->packet[1] >= '2') { - /* Clear this watchpoint's corresponding page map groups, - as everything is going to be recomputed soon anyway. */ - memset(&gdbstub_watch_pages[j >> (MEM_GRANULARITY_BITS + 6)], 0, - (((k - 1) >> (MEM_GRANULARITY_BITS + 6)) + 1) * sizeof(gdbstub_watch_pages[0])); - - /* Go through all watchpoint lists. */ - l = 0; - breakpoint = first_rwatch; - while (1) { - if (breakpoint) { - /* Flag this watchpoint's corresponding pages as having a watchpoint. */ - k = (breakpoint->end - 1) >> MEM_GRANULARITY_BITS; - for (i = breakpoint->addr >> MEM_GRANULARITY_BITS; i <= k; i++) - gdbstub_watch_pages[i >> 6] |= (1 << (i & 63)); - - breakpoint = breakpoint->next; - } else { - /* Jump from list to list as a shortcut. */ - if (l == 0) - breakpoint = first_wwatch; - else if (l == 1) - breakpoint = first_awatch; - else - break; - l++; - } - } - } - - /* Respond positively. */ - goto ok; + /* Respond positively. */ + goto ok; } end: /* Send response. */ gdbstub_client_respond(client); } - static void gdbstub_cpu_exec(int cycs) { @@ -1213,15 +1239,15 @@ gdbstub_cpu_exec(int cycs) /* Swap in any software breakpoints. */ gdbstub_breakpoint_t *swbreak = first_swbreak; while (swbreak) { - /* Swap the INT 3 opcode into the address. */ - swbreak->orig_val = readmembl(swbreak->addr); - writemembl(swbreak->addr, 0xcc); - swbreak = swbreak->next; + /* Swap the INT 3 opcode into the address. */ + swbreak->orig_val = readmembl(swbreak->addr); + writemembl(swbreak->addr, 0xcc); + swbreak = swbreak->next; } /* Call the original cpu_exec function outside the debugger context. */ if ((gdbstub_step == GDBSTUB_SSTEP) && ((cycles + cycs) <= 0)) - cycs += -(cycles + cycs) + 1; + cycs += -(cycles + cycs) + 1; in_gdbstub = 0; cpu_exec_shadow(cycs); in_gdbstub = 1; @@ -1229,9 +1255,9 @@ gdbstub_cpu_exec(int cycs) /* Swap out any software breakpoints. */ swbreak = first_swbreak; while (swbreak) { - if (readmembl(swbreak->addr) == 0xcc) - writemembl(swbreak->addr, swbreak->orig_val); - swbreak = swbreak->next; + if (readmembl(swbreak->addr) == 0xcc) + writemembl(swbreak->addr, swbreak->orig_val); + swbreak = swbreak->next; } } @@ -1245,41 +1271,41 @@ gdbstub_cpu_exec(int cycs) /* Add extended break reason. */ if (gdbstub_step >= GDBSTUB_BREAK_RWATCH) { - if (gdbstub_step != GDBSTUB_BREAK_WWATCH) - stop_reason[stop_reason_len++] = (gdbstub_step == GDBSTUB_BREAK_RWATCH) ? 'r' : 'a'; - stop_reason[stop_reason_len++] = 'w'; - stop_reason[stop_reason_len++] = 'a'; - stop_reason[stop_reason_len++] = 't'; - stop_reason[stop_reason_len++] = 'c'; - stop_reason[stop_reason_len++] = 'h'; - stop_reason[stop_reason_len++] = ':'; - stop_reason_len += sprintf(&stop_reason[stop_reason_len], "%X;", watch_addr); + if (gdbstub_step != GDBSTUB_BREAK_WWATCH) + stop_reason[stop_reason_len++] = (gdbstub_step == GDBSTUB_BREAK_RWATCH) ? 'r' : 'a'; + stop_reason[stop_reason_len++] = 'w'; + stop_reason[stop_reason_len++] = 'a'; + stop_reason[stop_reason_len++] = 't'; + stop_reason[stop_reason_len++] = 'c'; + stop_reason[stop_reason_len++] = 'h'; + stop_reason[stop_reason_len++] = ':'; + stop_reason_len += sprintf(&stop_reason[stop_reason_len], "%X;", watch_addr); } else if (gdbstub_step >= GDBSTUB_BREAK_SW) { - stop_reason[stop_reason_len++] = (gdbstub_step == GDBSTUB_BREAK_SW) ? 's' : 'h'; - stop_reason[stop_reason_len++] = 'w'; - stop_reason[stop_reason_len++] = 'b'; - stop_reason[stop_reason_len++] = 'r'; - stop_reason[stop_reason_len++] = 'e'; - stop_reason[stop_reason_len++] = 'a'; - stop_reason[stop_reason_len++] = 'k'; - stop_reason[stop_reason_len++] = ':'; - stop_reason[stop_reason_len++] = ';'; + stop_reason[stop_reason_len++] = (gdbstub_step == GDBSTUB_BREAK_SW) ? 's' : 'h'; + stop_reason[stop_reason_len++] = 'w'; + stop_reason[stop_reason_len++] = 'b'; + stop_reason[stop_reason_len++] = 'r'; + stop_reason[stop_reason_len++] = 'e'; + stop_reason[stop_reason_len++] = 'a'; + stop_reason[stop_reason_len++] = 'k'; + stop_reason[stop_reason_len++] = ':'; + stop_reason[stop_reason_len++] = ';'; } /* Add register dump. */ - uint8_t buf[10] = {0}; - int i, j, k; + uint8_t buf[10] = { 0 }; + int i, j, k; for (i = 0; i < GDB_REG_MAX; i++) { - if (i >= 0x10) - stop_reason[stop_reason_len++] = gdbstub_hex_encode(i >> 4); - stop_reason[stop_reason_len++] = gdbstub_hex_encode(i & 0x0f); - stop_reason[stop_reason_len++] = ':'; - j = gdbstub_client_read_reg(i, buf); - for (k = 0; k < j; k++) { - stop_reason[stop_reason_len++] = gdbstub_hex_encode(buf[k] >> 4); - stop_reason[stop_reason_len++] = gdbstub_hex_encode(buf[k] & 0x0f); - } - stop_reason[stop_reason_len++] = ';'; + if (i >= 0x10) + stop_reason[stop_reason_len++] = gdbstub_hex_encode(i >> 4); + stop_reason[stop_reason_len++] = gdbstub_hex_encode(i & 0x0f); + stop_reason[stop_reason_len++] = ':'; + j = gdbstub_client_read_reg(i, buf); + for (k = 0; k < j; k++) { + stop_reason[stop_reason_len++] = gdbstub_hex_encode(buf[k] >> 4); + stop_reason[stop_reason_len++] = gdbstub_hex_encode(buf[k] & 0x0f); + } + stop_reason[stop_reason_len++] = ';'; } /* Don't execute the CPU any further if single-stepping. */ @@ -1295,26 +1321,26 @@ gdbstub_cpu_exec(int cycs) while (client) { /* Report stop reason if the client is waiting for one. */ if (client->waiting_stop && stop_reason_len) { - client->waiting_stop = 0; + client->waiting_stop = 0; - /* Wait for any pending responses to be acknowledged. */ - if (!thread_wait_event(client->response_event, -1)) { - /* Block other responses from being written while this one isn't acknowledged. */ - thread_reset_event(client->response_event); + /* Wait for any pending responses to be acknowledged. */ + if (!thread_wait_event(client->response_event, -1)) { + /* Block other responses from being written while this one isn't acknowledged. */ + thread_reset_event(client->response_event); - /* Write stop reason response. */ - strcpy(client->response, stop_reason); - client->response_pos = stop_reason_len; - gdbstub_client_respond(client); - } else { - gdbstub_log("GDB Stub: Timed out waiting for client %s:%d\n", inet_ntoa(client->addr.sin_addr), client->addr.sin_port); - } + /* Write stop reason response. */ + strcpy(client->response, stop_reason); + client->response_pos = stop_reason_len; + gdbstub_client_respond(client); + } else { + gdbstub_log("GDB Stub: Timed out waiting for client %s:%d\n", inet_ntoa(client->addr.sin_addr), client->addr.sin_port); + } } if (client->has_packet) { - gdbstub_client_packet(client); - client->has_packet = client->packet_pos = 0; - thread_set_event(client->processed_event); + gdbstub_client_packet(client); + client->has_packet = client->packet_pos = 0; + thread_set_event(client->processed_event); } #ifdef GDBSTUB_ALLOW_MULTI_CLIENTS @@ -1329,7 +1355,6 @@ gdbstub_cpu_exec(int cycs) in_gdbstub = 0; } - static void gdbstub_client_thread(void *priv) { @@ -1346,60 +1371,60 @@ gdbstub_client_thread(void *priv) /* Read data from client. */ while ((bytes_read = recv(client->socket, (char *) buf, sizeof(buf), 0)) > 0) { for (i = 0; i < bytes_read; i++) { - switch (buf[i]) { - case '$': /* packet start */ - /* Wait for any existing packets to be processed. */ - thread_wait_event(client->processed_event, -1); + switch (buf[i]) { + case '$': /* packet start */ + /* Wait for any existing packets to be processed. */ + thread_wait_event(client->processed_event, -1); - client->packet_pos = 0; - break; + client->packet_pos = 0; + break; - case '-': /* negative acknowledgement */ - /* Retransmit the current response. */ - gdbstub_client_respond(client); - break; + case '-': /* negative acknowledgement */ + /* Retransmit the current response. */ + gdbstub_client_respond(client); + break; - case '+': /* positive acknowledgement */ - /* Allow another response to be written. */ - thread_set_event(client->response_event); - break; + case '+': /* positive acknowledgement */ + /* Allow another response to be written. */ + thread_set_event(client->response_event); + break; - case 0x03: /* break */ - /* Wait for any existing packets to be processed. */ - thread_wait_event(client->processed_event, -1); + case 0x03: /* break */ + /* Wait for any existing packets to be processed. */ + thread_wait_event(client->processed_event, -1); - /* Break immediately. */ - gdbstub_log("GDB Stub: Break requested\n"); - gdbstub_break(); - break; + /* Break immediately. */ + gdbstub_log("GDB Stub: Break requested\n"); + gdbstub_break(); + break; - default: - /* Wait for any existing packets to be processed, just in case. */ - thread_wait_event(client->processed_event, -1); + default: + /* Wait for any existing packets to be processed, just in case. */ + thread_wait_event(client->processed_event, -1); - if (client->packet_pos < (sizeof(client->packet) - 1)) { - /* Append byte to the packet. */ - client->packet[client->packet_pos++] = buf[i]; + if (client->packet_pos < (sizeof(client->packet) - 1)) { + /* Append byte to the packet. */ + client->packet[client->packet_pos++] = buf[i]; - /* Check if we're at the end of a packet. */ - if ((client->packet_pos >= 3) && (client->packet[client->packet_pos - 3] == '#')) { /* packet checksum start */ - /* Small hack to speed up IDA instruction trace mode. */ - if (*((uint32_t *) client->packet) == ('H' | ('c' << 8) | ('1' << 16) | ('#' << 24))) { - /* Send pre-computed response. */ - send(client->socket, "+$OK#9A", 7, 0); + /* Check if we're at the end of a packet. */ + if ((client->packet_pos >= 3) && (client->packet[client->packet_pos - 3] == '#')) { /* packet checksum start */ + /* Small hack to speed up IDA instruction trace mode. */ + if (*((uint32_t *) client->packet) == ('H' | ('c' << 8) | ('1' << 16) | ('#' << 24))) { + /* Send pre-computed response. */ + send(client->socket, "+$OK#9A", 7, 0); - /* Skip processing. */ - continue; - } + /* Skip processing. */ + continue; + } - /* Flag that a packet should be processed. */ - client->packet[client->packet_pos] = '\0'; - thread_reset_event(client->processed_event); - gdbstub_next_asap = client->has_packet = 1; - } - } - break; - } + /* Flag that a packet should be processed. */ + client->packet[client->packet_pos] = '\0'; + thread_reset_event(client->processed_event); + gdbstub_next_asap = client->has_packet = 1; + } + } + break; + } } } @@ -1421,20 +1446,20 @@ gdbstub_client_thread(void *priv) #endif first_client = client->next; if (first_client == NULL) { - last_client = NULL; - gdbstub_step = GDBSTUB_EXEC; /* unpause CPU when all clients are disconnected */ + last_client = NULL; + gdbstub_step = GDBSTUB_EXEC; /* unpause CPU when all clients are disconnected */ } #ifdef GDBSTUB_ALLOW_MULTI_CLIENTS } else { other_client = first_client; while (other_client) { - if (other_client->next == client) { - if (last_client == client) - last_client = other_client; - other_client->next = client->next; - break; - } - other_client = other_client->next; + if (other_client->next == client) { + if (last_client == client) + last_client = other_client; + other_client->next = client->next; + break; + } + other_client = other_client->next; } } #endif @@ -1443,7 +1468,6 @@ gdbstub_client_thread(void *priv) thread_release_mutex(client_list_mutex); } - static void gdbstub_server_thread(void *priv) { @@ -1452,31 +1476,31 @@ gdbstub_server_thread(void *priv) /* Accept connections. */ gdbstub_client_t *client; - socklen_t sl = sizeof(struct sockaddr_in); + socklen_t sl = sizeof(struct sockaddr_in); while (1) { /* Allocate client structure. */ client = malloc(sizeof(gdbstub_client_t)); memset(client, 0, sizeof(gdbstub_client_t)); client->processed_event = thread_create_event(); - client->response_event = thread_create_event(); + client->response_event = thread_create_event(); /* Accept connection. */ client->socket = accept(gdbstub_socket, (struct sockaddr *) &client->addr, &sl); if (client->socket < 0) - break; + break; /* Add to client list. */ thread_wait_mutex(client_list_mutex); if (first_client) { #ifdef GDBSTUB_ALLOW_MULTI_CLIENTS - last_client->next = client; - last_client = client; + last_client->next = client; + last_client = client; #else - first_client->next = last_client = client; - close(first_client->socket); + first_client->next = last_client = client; + close(first_client->socket); #endif } else { - first_client = last_client = client; + first_client = last_client = client; } thread_release_mutex(client_list_mutex); @@ -1493,18 +1517,16 @@ gdbstub_server_thread(void *priv) free(client); } - void gdbstub_cpu_init() { /* Replace cpu_exec with our own function if the GDB stub is active. */ if ((gdbstub_socket != -1) && (cpu_exec != gdbstub_cpu_exec)) { cpu_exec_shadow = cpu_exec; - cpu_exec = gdbstub_cpu_exec; + cpu_exec = gdbstub_cpu_exec; } } - int gdbstub_instruction() { @@ -1516,18 +1538,18 @@ gdbstub_instruction() /* Go through the list of software breakpoints. */ do { - /* Check if the breakpoint coincides with this address. */ - if (breakpoint->addr == wanted_addr) { - gdbstub_log("GDB Stub: Hardware breakpoint at %08X\n", wanted_addr); + /* Check if the breakpoint coincides with this address. */ + if (breakpoint->addr == wanted_addr) { + gdbstub_log("GDB Stub: Hardware breakpoint at %08X\n", wanted_addr); - /* Flag that we're in a hardware breakpoint. */ - gdbstub_step = GDBSTUB_BREAK_HW; + /* Flag that we're in a hardware breakpoint. */ + gdbstub_step = GDBSTUB_BREAK_HW; - /* Pause execution. */ - return 1; - } + /* Pause execution. */ + return 1; + } - breakpoint = breakpoint->next; + breakpoint = breakpoint->next; } while (breakpoint); } @@ -1535,7 +1557,6 @@ gdbstub_instruction() return gdbstub_step - GDBSTUB_EXEC; } - int gdbstub_int3() { @@ -1545,26 +1566,26 @@ gdbstub_int3() /* Calculate the breakpoint instruction's address. */ uint32_t new_pc = cpu_state.pc - 1; if (cpu_state.op32) - new_pc &= 0xffff; + new_pc &= 0xffff; uint32_t wanted_addr = cs + new_pc; /* Go through the list of software breakpoints. */ do { - /* Check if the breakpoint coincides with this address. */ - if (breakpoint->addr == wanted_addr) { - gdbstub_log("GDB Stub: Software breakpoint at %08X\n", wanted_addr); + /* Check if the breakpoint coincides with this address. */ + if (breakpoint->addr == wanted_addr) { + gdbstub_log("GDB Stub: Software breakpoint at %08X\n", wanted_addr); - /* Move EIP back to where the break instruction was. */ - cpu_state.pc = new_pc; + /* Move EIP back to where the break instruction was. */ + cpu_state.pc = new_pc; - /* Flag that we're in a software breakpoint. */ - gdbstub_step = GDBSTUB_BREAK_SW; + /* Flag that we're in a software breakpoint. */ + gdbstub_step = GDBSTUB_BREAK_SW; - /* Abort INT 3 execution. */ - return 1; - } + /* Abort INT 3 execution. */ + return 1; + } - breakpoint = breakpoint->next; + breakpoint = breakpoint->next; } while (breakpoint); } @@ -1572,7 +1593,6 @@ gdbstub_int3() return 0; } - void gdbstub_mem_access(uint32_t *addrs, int access) { @@ -1586,35 +1606,34 @@ gdbstub_mem_access(uint32_t *addrs, int access) gdbstub_breakpoint_t *watchpoint = (access & GDBSTUB_MEM_WRITE) ? first_wwatch : first_rwatch; while (1) { if (watchpoint) { - /* Check if any component of this address is within the breakpoint's range. */ - for (i = 0; i < width; i++) { - if ((addrs[i] >= watchpoint->addr) && (addrs[i] < watchpoint->end)) - break; - } - if (i < width) { - gdbstub_log("GDB Stub: %s watchpoint at %08X\n", (access & GDBSTUB_MEM_AWATCH) ? "Access" : ((access & GDBSTUB_MEM_WRITE) ? "Write" : "Read"), watch_addr); + /* Check if any component of this address is within the breakpoint's range. */ + for (i = 0; i < width; i++) { + if ((addrs[i] >= watchpoint->addr) && (addrs[i] < watchpoint->end)) + break; + } + if (i < width) { + gdbstub_log("GDB Stub: %s watchpoint at %08X\n", (access & GDBSTUB_MEM_AWATCH) ? "Access" : ((access & GDBSTUB_MEM_WRITE) ? "Write" : "Read"), watch_addr); - /* Flag that we're in a read/write watchpoint. */ - gdbstub_step = (access & GDBSTUB_MEM_AWATCH) ? GDBSTUB_BREAK_AWATCH : ((access & GDBSTUB_MEM_WRITE) ? GDBSTUB_BREAK_WWATCH : GDBSTUB_BREAK_RWATCH); + /* Flag that we're in a read/write watchpoint. */ + gdbstub_step = (access & GDBSTUB_MEM_AWATCH) ? GDBSTUB_BREAK_AWATCH : ((access & GDBSTUB_MEM_WRITE) ? GDBSTUB_BREAK_WWATCH : GDBSTUB_BREAK_RWATCH); - /* Stop looking. */ - return; - } + /* Stop looking. */ + return; + } - watchpoint = watchpoint->next; + watchpoint = watchpoint->next; } else { - /* Jump from list to list as a shortcut. */ - if (access & GDBSTUB_MEM_AWATCH) { - break; - } else { - watchpoint = first_awatch; - access |= GDBSTUB_MEM_AWATCH; - } + /* Jump from list to list as a shortcut. */ + if (access & GDBSTUB_MEM_AWATCH) { + break; + } else { + watchpoint = first_awatch; + access |= GDBSTUB_MEM_AWATCH; + } } } } - void gdbstub_init() { @@ -1629,11 +1648,11 @@ gdbstub_init() } /* Bind GDB server socket. */ - int port = 12345; + int port = 12345; struct sockaddr_in bind_addr = { .sin_family = AF_INET, - .sin_addr = { .s_addr = INADDR_ANY }, - .sin_port = htons(port) + .sin_addr = { .s_addr = INADDR_ANY }, + .sin_port = htons(port) }; if (bind(gdbstub_socket, (struct sockaddr *) &bind_addr, sizeof(bind_addr)) == -1) { pclog("GDB Stub: Failed to bind on port %d (%d)\n", port, WSAGetLastError()); @@ -1655,7 +1674,6 @@ gdbstub_init() gdbstub_step = GDBSTUB_BREAK; } - void gdbstub_close() { @@ -1669,9 +1687,9 @@ gdbstub_close() /* Clear client list. */ thread_wait_mutex(client_list_mutex); gdbstub_client_t *client = first_client; - int socket; + int socket; while (client) { - socket = client->socket; + socket = client->socket; client->socket = -1; close(socket); client = client->next; diff --git a/src/include/86box/gdbstub.h b/src/include/86box/gdbstub.h index d562f6a6e..7ed893392 100644 --- a/src/include/86box/gdbstub.h +++ b/src/include/86box/gdbstub.h @@ -15,12 +15,12 @@ * Copyright 2022 RichardG. */ #ifndef EMU_GDBSTUB_H -# define EMU_GDBSTUB_H +#define EMU_GDBSTUB_H #include <86box/mem.h> -#define GDBSTUB_MEM_READ 0 -#define GDBSTUB_MEM_WRITE 16 -#define GDBSTUB_MEM_AWATCH 32 +#define GDBSTUB_MEM_READ 0 +#define GDBSTUB_MEM_WRITE 16 +#define GDBSTUB_MEM_AWATCH 32 enum { GDBSTUB_EXEC = 0, @@ -35,21 +35,21 @@ enum { #ifdef USE_GDBSTUB -#define GDBSTUB_MEM_ACCESS(addr, access, width) \ - uint32_t gdbstub_page = addr >> MEM_GRANULARITY_BITS; \ - if (gdbstub_watch_pages[gdbstub_page >> 6] & (1 << (gdbstub_page & 63)) || (addr == 0xb8dd4)) { \ - uint32_t gdbstub_addrs[width]; \ - for (int gdbstub_i = 0; gdbstub_i < width; gdbstub_i++) \ - gdbstub_addrs[gdbstub_i] = addr + gdbstub_i; \ - gdbstub_mem_access(gdbstub_addrs, access | width); \ - } +# define GDBSTUB_MEM_ACCESS(addr, access, width) \ + uint32_t gdbstub_page = addr >> MEM_GRANULARITY_BITS; \ + if (gdbstub_watch_pages[gdbstub_page >> 6] & (1 << (gdbstub_page & 63))) { \ + uint32_t gdbstub_addrs[width]; \ + for (int gdbstub_i = 0; gdbstub_i < width; gdbstub_i++) \ + gdbstub_addrs[gdbstub_i] = addr + gdbstub_i; \ + gdbstub_mem_access(gdbstub_addrs, access | width); \ + } -#define GDBSTUB_MEM_ACCESS_FAST(addrs, access, width) \ - uint32_t gdbstub_page = addr >> MEM_GRANULARITY_BITS; \ - if (gdbstub_watch_pages[gdbstub_page >> 6] & (1 << (gdbstub_page & 63)) || (addr == 0xb8dd4)) \ - gdbstub_mem_access(addrs, access | width); +# define GDBSTUB_MEM_ACCESS_FAST(addrs, access, width) \ + uint32_t gdbstub_page = addr >> MEM_GRANULARITY_BITS; \ + if (gdbstub_watch_pages[gdbstub_page >> 6] & (1 << (gdbstub_page & 63))) \ + gdbstub_mem_access(addrs, access | width); -extern int gdbstub_step, gdbstub_next_asap; +extern int gdbstub_step, gdbstub_next_asap; extern uint64_t gdbstub_watch_pages[(((uint32_t) -1) >> (MEM_GRANULARITY_BITS + 6)) + 1]; extern void gdbstub_cpu_init(); @@ -61,17 +61,17 @@ extern void gdbstub_close(); #else -#define GDBSTUB_MEM_ACCESS(addr, access, width) -#define GDBSTUB_MEM_ACCESS_FAST(addrs, access, width) +# define GDBSTUB_MEM_ACCESS(addr, access, width) +# define GDBSTUB_MEM_ACCESS_FAST(addrs, access, width) -#define gdbstub_step 0 -#define gdbstub_next_asap 0 +# define gdbstub_step 0 +# define gdbstub_next_asap 0 -#define gdbstub_cpu_init() -#define gdbstub_instruction() 0 -#define gdbstub_int3() 0 -#define gdbstub_init() -#define gdbstub_close() +# define gdbstub_cpu_init() +# define gdbstub_instruction() 0 +# define gdbstub_int3() 0 +# define gdbstub_init() +# define gdbstub_close() #endif diff --git a/src/sound/snd_ad1848.c b/src/sound/snd_ad1848.c index 87713712a..bf3858aa3 100644 --- a/src/sound/snd_ad1848.c +++ b/src/sound/snd_ad1848.c @@ -423,7 +423,7 @@ ad1848_update(ad1848_t *ad1848) static int16_t ad1848_process_mulaw(uint8_t byte) { - byte = ~byte; + byte = ~byte; int16_t dec = ((byte & 0x0f) << 3) + 0x84; dec <<= (byte & 0x70) >> 4; return (byte & 0x80) ? (0x84 - dec) : (dec - 0x84); @@ -434,18 +434,18 @@ ad1848_process_alaw(uint8_t byte) { byte ^= 0x55; int16_t dec = (byte & 0x0f) << 4; - int seg = (byte & 0x70) >> 4; + int seg = (byte & 0x70) >> 4; switch (seg) { case 0: - dec += 0x8; + dec |= 0x8; break; case 1: - dec += 0x108; + dec |= 0x108; break; default: - dec += 0x108; + dec |= 0x108; dec <<= seg - 1; break; } @@ -460,7 +460,7 @@ ad1848_process_adpcm(ad1848_t *ad1848) temp = (ad1848->adpcm_data & 0x0f) + ad1848->adpcm_step; } else { ad1848->adpcm_data = dma_channel_read(ad1848->dma); - temp = (ad1848->adpcm_data >> 4) + ad1848->adpcm_step; + temp = (ad1848->adpcm_data >> 4) + ad1848->adpcm_step; } if (temp < 0) temp = 0; @@ -533,7 +533,7 @@ ad1848_poll(void *priv) ad1848->out_r = ad1848_process_alaw(dma_channel_read(ad1848->dma)); break; - /* 0x80 and 0x90 reserved */ + /* 0x80 and 0x90 reserved */ case 0xa0: /* Mono, 4-bit ADPCM */ ad1848->out_l = ad1848->out_r = ad1848_process_adpcm(ad1848); @@ -556,7 +556,7 @@ ad1848_poll(void *priv) ad1848->out_r = dma_channel_read(ad1848->dma) | (temp << 8); break; - /* 0xe0 and 0xf0 reserved */ + /* 0xe0 and 0xf0 reserved */ } if (ad1848->regs[6] & 0x80) @@ -581,7 +581,7 @@ ad1848_poll(void *priv) } if (!(ad1848->adpcm_pos & 7)) /* ADPCM counts down every 4 bytes */ - ad1848->count--; + ad1848->count--; } else { ad1848->out_l = ad1848->out_r = 0; ad1848->cd_vol_l = ad1848->cd_vol_r = 0; diff --git a/src/sound/snd_cmi8x38.c b/src/sound/snd_cmi8x38.c index bcfb7ba21..4d02afcaa 100644 --- a/src/sound/snd_cmi8x38.c +++ b/src/sound/snd_cmi8x38.c @@ -35,15 +35,14 @@ #include <86box/nmi.h> #include <86box/ui.h> - enum { /* [23:16] = reg 0F [7:0] (reg 0C [31:24]) [13] = onboard flag [12:8] = reg 0B [4:0] (reg 08 [28:24]) [7:0] = PCI device ID [7:0] */ - CMEDIA_CMI8338 = 0x000000, + CMEDIA_CMI8338 = 0x000000, CMEDIA_CMI8738_4CH = 0x040011, /* chip version 039 with 4-channel output */ - CMEDIA_CMI8738_6CH = 0x080011 /* chip version 055 with 6-channel output */ + CMEDIA_CMI8738_6CH = 0x080011 /* chip version 055 with 6-channel output */ }; enum { @@ -55,39 +54,38 @@ enum { }; typedef struct { - uint8_t id, reg, always_run, playback_enabled, channels; + uint8_t id, reg, always_run, playback_enabled, channels; struct _cmi8x38_ *dev; - uint32_t sample_ptr, fifo_pos, fifo_end; - int32_t frame_count_dma, frame_count_fragment, sample_count_out; - uint8_t fifo[256], restart; + uint32_t sample_ptr, fifo_pos, fifo_end; + int32_t frame_count_dma, frame_count_fragment, sample_count_out; + uint8_t fifo[256], restart; - int16_t out_fl, out_fr, out_rl, out_rr, out_c, out_lfe; - int vol_l, vol_r, pos; - int32_t buffer[SOUNDBUFLEN * 2]; - uint64_t timer_latch; - double dma_latch; + int16_t out_fl, out_fr, out_rl, out_rr, out_c, out_lfe; + int vol_l, vol_r, pos; + int32_t buffer[SOUNDBUFLEN * 2]; + uint64_t timer_latch; + double dma_latch; - pc_timer_t dma_timer, poll_timer; + pc_timer_t dma_timer, poll_timer; } cmi8x38_dma_t; typedef struct _cmi8x38_ { - uint32_t type; - uint16_t io_base, sb_base, opl_base, mpu_base; - uint8_t pci_regs[256], io_regs[256]; - int slot; + uint32_t type; + uint16_t io_base, sb_base, opl_base, mpu_base; + uint8_t pci_regs[256], io_regs[256]; + int slot; - sb_t *sb; - void *gameport, *io_traps[TRAP_MAX]; + sb_t *sb; + void *gameport, *io_traps[TRAP_MAX]; cmi8x38_dma_t dma[2]; - uint16_t tdma_base_addr, tdma_base_count; - int tdma_8, tdma_16, tdma_mask, prev_mask; + uint16_t tdma_base_addr, tdma_base_count; + int tdma_8, tdma_16, tdma_mask, prev_mask; - int master_vol_l, master_vol_r, cd_vol_l, cd_vol_r; + int master_vol_l, master_vol_r, cd_vol_l, cd_vol_r; } cmi8x38_t; - #ifdef ENABLE_CMI8X38_LOG int cmi8x38_do_log = ENABLE_CMI8X38_LOG; @@ -97,50 +95,46 @@ cmi8x38_log(const char *fmt, ...) va_list ap; if (cmi8x38_do_log) { - va_start(ap, fmt); - pclog_ex(fmt, ap); - va_end(ap); + va_start(ap, fmt); + pclog_ex(fmt, ap); + va_end(ap); } } #else -#define cmi8x38_log(fmt, ...) +# define cmi8x38_log(fmt, ...) #endif -static const double freqs[] = {5512.0, 11025.0, 22050.0, 44100.0, 8000.0, 16000.0, 32000.0, 48000.0}; -static const uint16_t opl_ports_cmi8738[] = {0x388, 0x3c8, 0x3e0, 0x3e8}; - - -static void cmi8x38_dma_process(void *priv); -static void cmi8x38_speed_changed(void *priv); +static const double freqs[] = { 5512.0, 11025.0, 22050.0, 44100.0, 8000.0, 16000.0, 32000.0, 48000.0 }; +static const uint16_t opl_ports_cmi8738[] = { 0x388, 0x3c8, 0x3e0, 0x3e8 }; +static void cmi8x38_dma_process(void *priv); +static void cmi8x38_speed_changed(void *priv); static void cmi8x38_update_irqs(cmi8x38_t *dev) { /* Calculate and use the INTR flag. */ if (*((uint32_t *) &dev->io_regs[0x10]) & 0x0401c003) { - dev->io_regs[0x13] |= 0x80; - pci_set_irq(dev->slot, PCI_INTA); - cmi8x38_log("CMI8x38: Raising IRQ\n"); + dev->io_regs[0x13] |= 0x80; + pci_set_irq(dev->slot, PCI_INTA); + cmi8x38_log("CMI8x38: Raising IRQ\n"); } else { - dev->io_regs[0x13] &= ~0x80; - pci_clear_irq(dev->slot, PCI_INTA); + dev->io_regs[0x13] &= ~0x80; + pci_clear_irq(dev->slot, PCI_INTA); } } - static void cmi8x38_mpu_irq_update(void *priv, int set) { cmi8x38_t *dev = (cmi8x38_t *) priv; if (set) - dev->io_regs[0x12] |= 0x01; + dev->io_regs[0x12] |= 0x01; else - dev->io_regs[0x12] &= ~0x01; + dev->io_regs[0x12] &= ~0x01; cmi8x38_update_irqs(dev); } - static int cmi8x38_mpu_irq_pending(void *priv) { @@ -148,7 +142,6 @@ cmi8x38_mpu_irq_pending(void *priv) return dev->io_regs[0x12] & 0x01; } - static void cmi8x38_sb_irq_update(void *priv, int set) { @@ -156,13 +149,12 @@ cmi8x38_sb_irq_update(void *priv, int set) /* Interrupt flag shared with the first DMA channel. Combining SB and PCI DMA is undefined; the VxD driver disables SB if PCI is in use. */ if (set) - dev->io_regs[0x10] |= 0x01; + dev->io_regs[0x10] |= 0x01; else - dev->io_regs[0x10] &= ~0x01; + dev->io_regs[0x10] &= ~0x01; cmi8x38_update_irqs(dev); } - static int cmi8x38_sb_dma_post(cmi8x38_t *dev, uint16_t *addr, uint16_t *count, int channel) { @@ -173,43 +165,43 @@ cmi8x38_sb_dma_post(cmi8x38_t *dev, uint16_t *addr, uint16_t *count, int channel /* Copy TDMA registers to DMA on CMI8738+. Everything so far suggests that those chips use PCI bus mastering to directly write to the DMA registers. */ #if 0 /* TSRs don't set ENWR8237, except for the patched C3DPCI - does that bit have no effect? */ - if ((dev->type != CMEDIA_CMI8338) && (dev->io_regs[0x17] & 0x10)) { + if ((dev->type != CMEDIA_CMI8338) && (dev->io_regs[0x17] & 0x10)) #else - if (dev->type != CMEDIA_CMI8338) { + if (dev->type != CMEDIA_CMI8338) #endif - if (channel & 4) - dma[channel].ab = (dma[channel].ab & 0xfffe0000) | ((*addr) << 1); - else - dma[channel].ab = (dma[channel].ab & 0xffff0000) | *addr; - dma[channel].ac = dma[channel].ab; - dma[channel].cc = dma[channel].cb = *count; + { + if (channel & 4) + dma[channel].ab = (dma[channel].ab & 0xfffe0000) | ((*addr) << 1); + else + dma[channel].ab = (dma[channel].ab & 0xffff0000) | *addr; + dma[channel].ac = dma[channel].ab; + dma[channel].cc = dma[channel].cb = *count; } /* Handle end of DMA. */ if (*count == 0xffff) { - if (dma[channel].mode & 0x10) { /* auto-init */ - /* Restart TDMA. */ - *addr = dev->tdma_base_addr; - *count = dev->tdma_base_count; - cmi8x38_log("CMI8x38: Restarting TDMA on DMA %d with addr %08X count %04X\n", - channel, - (channel & 4) ? ((dma[channel].ab & 0xfffe0000) | ((*addr) << 1)) : ((dma[channel].ab & 0xffff0000) | *addr), - *count); - } else { - /* Mask TDMA. */ - dev->tdma_mask |= 1 << channel; - } + if (dma[channel].mode & 0x10) { /* auto-init */ + /* Restart TDMA. */ + *addr = dev->tdma_base_addr; + *count = dev->tdma_base_count; + cmi8x38_log("CMI8x38: Restarting TDMA on DMA %d with addr %08X count %04X\n", + channel, + (channel & 4) ? ((dma[channel].ab & 0xfffe0000) | ((*addr) << 1)) : ((dma[channel].ab & 0xffff0000) | *addr), + *count); + } else { + /* Mask TDMA. */ + dev->tdma_mask |= 1 << channel; + } - /* Set the mysterious LHBTOG bit, assuming it corresponds to - the 8237 channel status bit. Nothing appears to read it. */ - dev->io_regs[0x10] |= 0x40; + /* Set the mysterious LHBTOG bit, assuming it corresponds to + the 8237 channel status bit. Nothing appears to read it. */ + dev->io_regs[0x10] |= 0x40; - return DMA_OVER; + return DMA_OVER; } return 0; } - static int cmi8x38_sb_dma_readb(void *priv) { @@ -218,10 +210,10 @@ cmi8x38_sb_dma_readb(void *priv) /* Stop if the DMA channel is invalid or if TDMA is masked. */ int channel = dev->tdma_8; if ((channel < 0) || (dev->tdma_mask & (1 << channel))) - return DMA_NODATA; + return DMA_NODATA; /* Get 16-bit address and count registers. */ - uint16_t *addr = (uint16_t *) &dev->io_regs[0x1c], + uint16_t *addr = (uint16_t *) &dev->io_regs[0x1c], *count = (uint16_t *) &dev->io_regs[0x1e]; /* Read data. */ @@ -233,7 +225,6 @@ cmi8x38_sb_dma_readb(void *priv) return ret; } - static int cmi8x38_sb_dma_readw(void *priv) { @@ -242,10 +233,10 @@ cmi8x38_sb_dma_readw(void *priv) /* Stop if the DMA channel is invalid or if TDMA is masked. */ int channel = dev->tdma_16; if ((channel < 0) || (dev->tdma_mask & (1 << channel))) - return DMA_NODATA; + return DMA_NODATA; /* Get 16-bit address and count registers. */ - uint16_t *addr = (uint16_t *) &dev->io_regs[0x1c], + uint16_t *addr = (uint16_t *) &dev->io_regs[0x1c], *count = (uint16_t *) &dev->io_regs[0x1e]; /* Read data. */ @@ -257,7 +248,6 @@ cmi8x38_sb_dma_readw(void *priv) return ret; } - static int cmi8x38_sb_dma_writeb(void *priv, uint8_t val) { @@ -266,10 +256,10 @@ cmi8x38_sb_dma_writeb(void *priv, uint8_t val) /* Stop if the DMA channel is invalid or if TDMA is masked. */ int channel = dev->tdma_8; if ((channel < 0) || (dev->tdma_mask & (1 << channel))) - return 1; + return 1; /* Get 16-bit address and count registers. */ - uint16_t *addr = (uint16_t *) &dev->io_regs[0x1c], + uint16_t *addr = (uint16_t *) &dev->io_regs[0x1c], *count = (uint16_t *) &dev->io_regs[0x1e]; /* Write data. */ @@ -281,7 +271,6 @@ cmi8x38_sb_dma_writeb(void *priv, uint8_t val) return 0; } - static int cmi8x38_sb_dma_writew(void *priv, uint16_t val) { @@ -290,10 +279,10 @@ cmi8x38_sb_dma_writew(void *priv, uint16_t val) /* Stop if the DMA channel is invalid or if TDMA is masked. */ int channel = dev->tdma_16; if ((channel < 0) || (dev->tdma_mask & (1 << channel))) - return 1; + return 1; /* Get 16-bit address and count registers. */ - uint16_t *addr = (uint16_t *) &dev->io_regs[0x1c], + uint16_t *addr = (uint16_t *) &dev->io_regs[0x1c], *count = (uint16_t *) &dev->io_regs[0x1e]; /* Write data. */ @@ -305,7 +294,6 @@ cmi8x38_sb_dma_writew(void *priv, uint16_t val) return 0; } - static void cmi8x38_dma_write(uint16_t addr, uint8_t val, void *priv) { @@ -315,21 +303,21 @@ cmi8x38_dma_write(uint16_t addr, uint8_t val, void *priv) which disables auto-detection while copying the TDMA address/count to the SB DMA channel, so that those writes don't loop back to the DMA register snoop mechanism implemented here. */ if (!(dev->io_regs[0x27] & 0x01)) - return; + return; /* Stop if this is not a TDMA channel. Also set or clear the high channel flag while we're here. */ int channel; if (addr < 0x08) { - channel = addr >> 1; - if (channel != dev->tdma_8) - return; - dev->io_regs[0x10] &= ~0x20; + channel = addr >> 1; + if (channel != dev->tdma_8) + return; + dev->io_regs[0x10] &= ~0x20; } else { - channel = 4 | ((addr >> 2) & 3); - if (channel != dev->tdma_16) - return; - dev->io_regs[0x10] |= 0x20; + channel = 4 | ((addr >> 2) & 3); + if (channel != dev->tdma_16) + return; + dev->io_regs[0x10] |= 0x20; } /* Write base address and count. */ @@ -354,17 +342,16 @@ cmi8x38_dma_mask_write(uint16_t addr, uint8_t val, void *priv) /* See comment on dma_write above. */ if (!(dev->io_regs[0x27] & 0x01)) - return; + return; /* Unmask TDMA on DMA unmasking edge. */ if ((dev->tdma_8 >= 0) && (dev->prev_mask & (1 << dev->tdma_8)) && !(dma_m & (1 << dev->tdma_8))) - dev->tdma_mask &= ~(1 << dev->tdma_8); + dev->tdma_mask &= ~(1 << dev->tdma_8); else if ((dev->tdma_16 >= 0) && (dev->prev_mask & (1 << dev->tdma_16)) && !(dma_m & (1 << dev->tdma_16))) - dev->tdma_mask &= ~(1 << dev->tdma_16); + dev->tdma_mask &= ~(1 << dev->tdma_16); dev->prev_mask = dma_m; } - static void cmi8338_io_trap(int size, uint16_t addr, uint8_t write, uint8_t val, void *priv) { @@ -372,9 +359,9 @@ cmi8338_io_trap(int size, uint16_t addr, uint8_t write, uint8_t val, void *priv) #ifdef ENABLE_CMI8X38_LOG if (write) - cmi8x38_log("CMI8x38: cmi8338_io_trap(%04X, %02X)\n", addr, val); + cmi8x38_log("CMI8x38: cmi8338_io_trap(%04X, %02X)\n", addr, val); else - cmi8x38_log("CMI8x38: cmi8338_io_trap(%04X)\n", addr); + cmi8x38_log("CMI8x38: cmi8338_io_trap(%04X)\n", addr); #endif /* Weird offsets, it's best to just treat the register as a big dword. */ @@ -382,175 +369,169 @@ cmi8338_io_trap(int size, uint16_t addr, uint8_t write, uint8_t val, void *priv) *lcs &= ~0x0003dff0; *lcs |= (addr & 0x0f) << 14; if (write) - *lcs |= 0x1000 | (val << 4); + *lcs |= 0x1000 | (val << 4); /* Raise NMI. */ nmi = 1; } - static uint8_t cmi8x38_sb_mixer_read(uint16_t addr, void *priv) { - cmi8x38_t *dev = (cmi8x38_t *) priv; + cmi8x38_t *dev = (cmi8x38_t *) priv; sb_ct1745_mixer_t *mixer = &dev->sb->mixer_sb16; - uint8_t ret = sb_ct1745_mixer_read(addr, dev->sb); + uint8_t ret = sb_ct1745_mixer_read(addr, dev->sb); if (addr & 1) { - if ((mixer->index == 0x0e) || (mixer->index >= 0xf0)) - ret = mixer->regs[mixer->index]; - cmi8x38_log("CMI8x38: sb_mixer_read(1, %02X) = %02X\n", mixer->index, ret); + if ((mixer->index == 0x0e) || (mixer->index >= 0xf0)) + ret = mixer->regs[mixer->index]; + cmi8x38_log("CMI8x38: sb_mixer_read(1, %02X) = %02X\n", mixer->index, ret); } else { - cmi8x38_log("CMI8x38: sb_mixer_read(0) = %02X\n", ret); + cmi8x38_log("CMI8x38: sb_mixer_read(0) = %02X\n", ret); } return ret; } - static void cmi8x38_sb_mixer_write(uint16_t addr, uint8_t val, void *priv) { - cmi8x38_t *dev = (cmi8x38_t *) priv; + cmi8x38_t *dev = (cmi8x38_t *) priv; sb_ct1745_mixer_t *mixer = &dev->sb->mixer_sb16; /* Our clone mixer has a few differences. */ if (addr & 1) { - cmi8x38_log("CMI8x38: sb_mixer_write(1, %02X, %02X)\n", mixer->index, val); + cmi8x38_log("CMI8x38: sb_mixer_write(1, %02X, %02X)\n", mixer->index, val); - switch (mixer->index) { - /* Reset interleaved stereo flag for SBPro mode. */ - case 0x00: - mixer->regs[0x0e] = 0x00; - break; + switch (mixer->index) { + /* Reset interleaved stereo flag for SBPro mode. */ + case 0x00: + mixer->regs[0x0e] = 0x00; + break; - /* No dynamic MPU port assignment. */ - case 0x84: - return; + /* No dynamic MPU port assignment. */ + case 0x84: + return; - /* Some extended registers beyond those accepted by the CT1745. */ - case 0xf0: - if (dev->type == CMEDIA_CMI8338) - val &= 0xfe; - mixer->regs[mixer->index] = val; - return; + /* Some extended registers beyond those accepted by the CT1745. */ + case 0xf0: + if (dev->type == CMEDIA_CMI8338) + val &= 0xfe; + mixer->regs[mixer->index] = val; + return; - case 0xf8 ... 0xff: - if (dev->type == CMEDIA_CMI8338) - mixer->regs[mixer->index] = val; - /* fall-through */ + case 0xf8 ... 0xff: + if (dev->type == CMEDIA_CMI8338) + mixer->regs[mixer->index] = val; + /* fall-through */ - case 0xf1 ... 0xf7: - return; - } + case 0xf1 ... 0xf7: + return; + } - sb_ct1745_mixer_write(addr, val, dev->sb); + sb_ct1745_mixer_write(addr, val, dev->sb); - /* No [3F:47] controls. */ - mixer->input_gain_L = 0; - mixer->input_gain_R = 0; - mixer->output_gain_L = (double) 1.0; - mixer->output_gain_R = (double) 1.0; - mixer->bass_l = 8; - mixer->bass_r = 8; - mixer->treble_l = 8; - mixer->treble_r = 8; + /* No [3F:47] controls. */ + mixer->input_gain_L = 0; + mixer->input_gain_R = 0; + mixer->output_gain_L = (double) 1.0; + mixer->output_gain_R = (double) 1.0; + mixer->bass_l = 8; + mixer->bass_r = 8; + mixer->treble_l = 8; + mixer->treble_r = 8; - /* Check interleaved stereo flag for SBPro mode. */ - if ((mixer->index == 0x00) || (mixer->index == 0x0e)) - sb_dsp_set_stereo(&dev->sb->dsp, mixer->regs[0x0e] & 2); + /* Check interleaved stereo flag for SBPro mode. */ + if ((mixer->index == 0x00) || (mixer->index == 0x0e)) + sb_dsp_set_stereo(&dev->sb->dsp, mixer->regs[0x0e] & 2); - /* Set TDMA channels if autodetection is enabled. */ - if ((dev->io_regs[0x27] & 0x01) && (mixer->index == 0x81)) { - dev->tdma_8 = dev->sb->dsp.sb_8_dmanum; - if (dev->sb->dsp.sb_type >= SB16) - dev->tdma_16 = dev->sb->dsp.sb_16_dmanum; - } + /* Set TDMA channels if autodetection is enabled. */ + if ((dev->io_regs[0x27] & 0x01) && (mixer->index == 0x81)) { + dev->tdma_8 = dev->sb->dsp.sb_8_dmanum; + if (dev->sb->dsp.sb_type >= SB16) + dev->tdma_16 = dev->sb->dsp.sb_16_dmanum; + } } else { - cmi8x38_log("CMI8x38: sb_mixer_write(0, %02X)\n", val); - sb_ct1745_mixer_write(addr, val, dev->sb); + cmi8x38_log("CMI8x38: sb_mixer_write(0, %02X)\n", val); + sb_ct1745_mixer_write(addr, val, dev->sb); } } - static void cmi8x38_remap_sb(cmi8x38_t *dev) { if (dev->sb_base) { - io_removehandler(dev->sb_base, 0x0004, opl3_read, NULL, NULL, - opl3_write, NULL, NULL, &dev->sb->opl); - io_removehandler(dev->sb_base + 8, 0x0002, opl3_read, NULL, NULL, - opl3_write, NULL, NULL, &dev->sb->opl); - io_removehandler(dev->sb_base + 4, 0x0002, cmi8x38_sb_mixer_read, NULL, NULL, - cmi8x38_sb_mixer_write, NULL, NULL, dev); + io_removehandler(dev->sb_base, 0x0004, opl3_read, NULL, NULL, + opl3_write, NULL, NULL, &dev->sb->opl); + io_removehandler(dev->sb_base + 8, 0x0002, opl3_read, NULL, NULL, + opl3_write, NULL, NULL, &dev->sb->opl); + io_removehandler(dev->sb_base + 4, 0x0002, cmi8x38_sb_mixer_read, NULL, NULL, + cmi8x38_sb_mixer_write, NULL, NULL, dev); - sb_dsp_setaddr(&dev->sb->dsp, 0); + sb_dsp_setaddr(&dev->sb->dsp, 0); } dev->sb_base = 0x220; if (dev->type == CMEDIA_CMI8338) - dev->sb_base += (dev->io_regs[0x17] & 0x80) >> 2; + dev->sb_base += (dev->io_regs[0x17] & 0x80) >> 2; else - dev->sb_base += (dev->io_regs[0x17] & 0x0c) << 3; + dev->sb_base += (dev->io_regs[0x17] & 0x0c) << 3; if (!(dev->io_regs[0x04] & 0x08)) - dev->sb_base = 0; + dev->sb_base = 0; cmi8x38_log("CMI8x38: remap_sb(%04X)\n", dev->sb_base); if (dev->sb_base) { - io_sethandler(dev->sb_base, 0x0004, opl3_read, NULL, NULL, - opl3_write, NULL, NULL, &dev->sb->opl); - io_sethandler(dev->sb_base + 8, 0x0002, opl3_read, NULL, NULL, - opl3_write, NULL, NULL, &dev->sb->opl); - io_sethandler(dev->sb_base + 4, 0x0002, cmi8x38_sb_mixer_read, NULL, NULL, - cmi8x38_sb_mixer_write, NULL, NULL, dev); + io_sethandler(dev->sb_base, 0x0004, opl3_read, NULL, NULL, + opl3_write, NULL, NULL, &dev->sb->opl); + io_sethandler(dev->sb_base + 8, 0x0002, opl3_read, NULL, NULL, + opl3_write, NULL, NULL, &dev->sb->opl); + io_sethandler(dev->sb_base + 4, 0x0002, cmi8x38_sb_mixer_read, NULL, NULL, + cmi8x38_sb_mixer_write, NULL, NULL, dev); - sb_dsp_setaddr(&dev->sb->dsp, dev->sb_base); + sb_dsp_setaddr(&dev->sb->dsp, dev->sb_base); } } - static void cmi8x38_remap_opl(cmi8x38_t *dev) { if (dev->opl_base) { - io_removehandler(dev->opl_base, 0x0004, opl3_read, NULL, NULL, - opl3_write, NULL, NULL, &dev->sb->opl); + io_removehandler(dev->opl_base, 0x0004, opl3_read, NULL, NULL, + opl3_write, NULL, NULL, &dev->sb->opl); } dev->opl_base = (dev->type == CMEDIA_CMI8338) ? 0x388 : opl_ports_cmi8738[dev->io_regs[0x17] & 0x03]; io_trap_remap(dev->io_traps[TRAP_OPL], (dev->io_regs[0x04] & 0x01) && (dev->io_regs[0x16] & 0x80), dev->opl_base, 4); if (!(dev->io_regs[0x1a] & 0x08)) - dev->opl_base = 0; + dev->opl_base = 0; cmi8x38_log("CMI8x38: remap_opl(%04X)\n", dev->opl_base); if (dev->opl_base) { - io_sethandler(dev->opl_base, 0x0004, opl3_read, NULL, NULL, - opl3_write, NULL, NULL, &dev->sb->opl); + io_sethandler(dev->opl_base, 0x0004, opl3_read, NULL, NULL, + opl3_write, NULL, NULL, &dev->sb->opl); } } - static void cmi8x38_remap_mpu(cmi8x38_t *dev) { if (dev->mpu_base) - mpu401_change_addr(dev->sb->mpu, 0); + mpu401_change_addr(dev->sb->mpu, 0); /* The CMI8338 datasheet's port range of [300:330] is inaccurate. Drivers expect [330:300] like CMI8738. */ dev->mpu_base = 0x330 - ((dev->io_regs[0x17] & 0x60) >> 1); io_trap_remap(dev->io_traps[TRAP_MPU], (dev->io_regs[0x04] & 0x01) && (dev->io_regs[0x16] & 0x20), dev->mpu_base, 2); if (!(dev->io_regs[0x04] & 0x04)) - dev->mpu_base = 0; + dev->mpu_base = 0; cmi8x38_log("CMI8x38: remap_mpu(%04X)\n", dev->mpu_base); if (dev->mpu_base) - mpu401_change_addr(dev->sb->mpu, dev->mpu_base); + mpu401_change_addr(dev->sb->mpu, dev->mpu_base); } - static void cmi8x38_remap_traps(cmi8x38_t *dev) { @@ -560,7 +541,6 @@ cmi8x38_remap_traps(cmi8x38_t *dev) io_trap_remap(dev->io_traps[TRAP_PIC], (dev->io_regs[0x04] & 0x01) && (dev->io_regs[0x17] & 0x01), 0x0020, 2); } - static void cmi8x38_start_playback(cmi8x38_t *dev) { @@ -568,16 +548,15 @@ cmi8x38_start_playback(cmi8x38_t *dev) i = !(val & 0x01); if (!dev->dma[0].playback_enabled && i) - timer_advance_u64(&dev->dma[0].poll_timer, dev->dma[0].timer_latch); + timer_advance_u64(&dev->dma[0].poll_timer, dev->dma[0].timer_latch); dev->dma[0].playback_enabled = i; i = !(val & 0x02); if (!dev->dma[1].playback_enabled && i) - timer_advance_u64(&dev->dma[1].poll_timer, dev->dma[1].timer_latch); + timer_advance_u64(&dev->dma[1].poll_timer, dev->dma[1].timer_latch); dev->dma[1].playback_enabled = i; } - static uint8_t cmi8x38_read(uint16_t addr, void *priv) { @@ -586,66 +565,75 @@ cmi8x38_read(uint16_t addr, void *priv) uint8_t ret; switch (addr) { - case 0x22: case 0x23: - ret = cmi8x38_sb_mixer_read(addr ^ 1, dev); - break; + case 0x22: + case 0x23: + ret = cmi8x38_sb_mixer_read(addr ^ 1, dev); + break; - case 0x40 ... 0x4f: - if (dev->type == CMEDIA_CMI8338) - goto io_reg; - else - ret = mpu401_read(addr, dev->sb->mpu); - break; + case 0x40 ... 0x4f: + if (dev->type == CMEDIA_CMI8338) + goto io_reg; + else + ret = mpu401_read(addr, dev->sb->mpu); + break; - case 0x50 ... 0x5f: - if (dev->type == CMEDIA_CMI8338) - goto io_reg; - else - ret = opl3_read(addr, &dev->sb->opl); - break; + case 0x50 ... 0x5f: + if (dev->type == CMEDIA_CMI8338) + goto io_reg; + else + ret = opl3_read(addr, &dev->sb->opl); + break; - case 0x80: case 0x88: - ret = dev->dma[(addr & 0x78) >> 3].sample_ptr; - break; + case 0x80: + case 0x88: + ret = dev->dma[(addr & 0x78) >> 3].sample_ptr; + break; - case 0x81: case 0x89: - ret = dev->dma[(addr & 0x78) >> 3].sample_ptr >> 8; - break; + case 0x81: + case 0x89: + ret = dev->dma[(addr & 0x78) >> 3].sample_ptr >> 8; + break; - case 0x82: case 0x8a: - ret = dev->dma[(addr & 0x78) >> 3].sample_ptr >> 16; - break; + case 0x82: + case 0x8a: + ret = dev->dma[(addr & 0x78) >> 3].sample_ptr >> 16; + break; - case 0x83: case 0x8b: - ret = dev->dma[(addr & 0x78) >> 3].sample_ptr >> 24; - break; + case 0x83: + case 0x8b: + ret = dev->dma[(addr & 0x78) >> 3].sample_ptr >> 24; + break; - case 0x84: case 0x8c: - ret = dev->dma[(addr & 0x78) >> 3].frame_count_dma; - break; + case 0x84: + case 0x8c: + ret = dev->dma[(addr & 0x78) >> 3].frame_count_dma; + break; - case 0x85: case 0x8d: - ret = dev->dma[(addr & 0x78) >> 3].frame_count_dma >> 8; - break; + case 0x85: + case 0x8d: + ret = dev->dma[(addr & 0x78) >> 3].frame_count_dma >> 8; + break; - case 0x86: case 0x8e: - ret = dev->dma[(addr & 0x78) >> 3].sample_count_out >> 2; - break; + case 0x86: + case 0x8e: + ret = dev->dma[(addr & 0x78) >> 3].sample_count_out >> 2; + break; - case 0x87: case 0x8f: - ret = dev->dma[(addr & 0x78) >> 3].sample_count_out >> 10; - break; + case 0x87: + case 0x8f: + ret = dev->dma[(addr & 0x78) >> 3].sample_count_out >> 10; + break; - default: -io_reg: ret = dev->io_regs[addr]; - break; + default: +io_reg: + ret = dev->io_regs[addr]; + break; } - + cmi8x38_log("CMI8x38: read(%02X) = %02X\n", addr, ret); return ret; } - static void cmi8x38_write(uint16_t addr, uint8_t val, void *priv) { @@ -654,358 +642,361 @@ cmi8x38_write(uint16_t addr, uint8_t val, void *priv) cmi8x38_log("CMI8x38: write(%02X, %02X)\n", addr, val); switch (addr) { - case 0x00: - val &= 0x0f; + case 0x00: + val &= 0x0f; - /* Don't care about recording DMA. */ - dev->dma[0].always_run = val & 0x01; - dev->dma[1].always_run = val & 0x02; + /* Don't care about recording DMA. */ + dev->dma[0].always_run = val & 0x01; + dev->dma[1].always_run = val & 0x02; - /* Start playback if requested. */ - dev->io_regs[addr] = val; - cmi8x38_start_playback(dev); - break; + /* Start playback if requested. */ + dev->io_regs[addr] = val; + cmi8x38_start_playback(dev); + break; - case 0x02: - /* Reset DMA channels if requested. */ - if (val & 0x04) { - val &= ~0x01; + case 0x02: + /* Reset DMA channels if requested. */ + if (val & 0x04) { + val &= ~0x01; - if (dev->sb->dsp.sb_8_enable || dev->sb->dsp.sb_16_enable || dev->sb->dsp.sb_irq8 || dev->sb->dsp.sb_irq16) { - dev->sb->dsp.sb_8_enable = dev->sb->dsp.sb_16_enable = dev->sb->dsp.sb_irq8 = dev->sb->dsp.sb_irq16 = 0; - cmi8x38_update_irqs(dev); - } - } - if (val & 0x08) - val &= ~0x02; + if (dev->sb->dsp.sb_8_enable || dev->sb->dsp.sb_16_enable || dev->sb->dsp.sb_irq8 || dev->sb->dsp.sb_irq16) { + dev->sb->dsp.sb_8_enable = dev->sb->dsp.sb_16_enable = dev->sb->dsp.sb_irq8 = dev->sb->dsp.sb_irq16 = 0; + cmi8x38_update_irqs(dev); + } + } + if (val & 0x08) + val &= ~0x02; - val &= 0x03; - dev->io_regs[addr] = val; + val &= 0x03; + dev->io_regs[addr] = val; - /* Start DMA channels if requested. */ - if (val & 0x01) { - cmi8x38_log("CMI8x38: DMA 0 trigger\n"); - dev->dma[0].restart = 1; - cmi8x38_dma_process(&dev->dma[0]); - } - if (val & 0x02) { - cmi8x38_log("CMI8x38: DMA 1 trigger\n"); - dev->dma[1].restart = 1; - cmi8x38_dma_process(&dev->dma[1]); - } + /* Start DMA channels if requested. */ + if (val & 0x01) { + cmi8x38_log("CMI8x38: DMA 0 trigger\n"); + dev->dma[0].restart = 1; + cmi8x38_dma_process(&dev->dma[0]); + } + if (val & 0x02) { + cmi8x38_log("CMI8x38: DMA 1 trigger\n"); + dev->dma[1].restart = 1; + cmi8x38_dma_process(&dev->dma[1]); + } - /* Start playback along with DMA channels. */ - if (val & 0x03) - cmi8x38_start_playback(dev); - break; + /* Start playback along with DMA channels. */ + if (val & 0x03) + cmi8x38_start_playback(dev); + break; - case 0x04: - /* Enable or disable the game port. */ - gameport_remap(dev->gameport, (val & 0x02) ? 0x200 : 0); + case 0x04: + /* Enable or disable the game port. */ + gameport_remap(dev->gameport, (val & 0x02) ? 0x200 : 0); - /* Enable or disable the legacy devices. */ - dev->io_regs[addr] = val; - cmi8x38_remap_sb(dev); - /* remap_mpu called by remap_traps */ + /* Enable or disable the legacy devices. */ + dev->io_regs[addr] = val; + cmi8x38_remap_sb(dev); + /* remap_mpu called by remap_traps */ - /* Enable or disable I/O traps. */ - cmi8x38_remap_traps(dev); - break; + /* Enable or disable I/O traps. */ + cmi8x38_remap_traps(dev); + break; - case 0x05: - dev->io_regs[addr] = val; - cmi8x38_speed_changed(dev); - break; + case 0x05: + dev->io_regs[addr] = val; + cmi8x38_speed_changed(dev); + break; - case 0x08: - if (dev->type == CMEDIA_CMI8338) - val &= 0x0f; - break; + case 0x08: + if (dev->type == CMEDIA_CMI8338) + val &= 0x0f; + break; - case 0x09: + case 0x09: #if 0 /* actual CMI8338 behavior unconfirmed; this register is required for the Windows XP driver which outputs 96K */ if (dev->type == CMEDIA_CMI8338) return; #endif - /* Update sample rate. */ - dev->io_regs[addr] = val; - cmi8x38_speed_changed(dev); - break; + /* Update sample rate. */ + dev->io_regs[addr] = val; + cmi8x38_speed_changed(dev); + break; - case 0x0a: case 0x0b: - if (dev->type == CMEDIA_CMI8338) - return; - else - val &= 0xe0; + case 0x0a: + case 0x0b: + if (dev->type == CMEDIA_CMI8338) + return; + else + val &= 0xe0; - if (addr == 0x0a) { - /* Set PCI latency timer if requested. */ - dev->pci_regs[0x0d] = (val & 0x80) ? 0x48 : 0x20; /* clearing SETLAT48 is undefined */ - } else { - /* Update channel count. */ - dev->io_regs[addr] = val; - cmi8x38_speed_changed(dev); - } - break; + if (addr == 0x0a) { + /* Set PCI latency timer if requested. */ + dev->pci_regs[0x0d] = (val & 0x80) ? 0x48 : 0x20; /* clearing SETLAT48 is undefined */ + } else { + /* Update channel count. */ + dev->io_regs[addr] = val; + cmi8x38_speed_changed(dev); + } + break; - case 0x0e: - val &= 0x07; + case 0x0e: + val &= 0x07; - /* Clear interrupts. */ - dev->io_regs[0x10] &= val | 0xfc; - if (!(val & 0x04)) - dev->io_regs[0x11] &= ~0xc0; - cmi8x38_update_irqs(dev); - break; + /* Clear interrupts. */ + dev->io_regs[0x10] &= val | 0xfc; + if (!(val & 0x04)) + dev->io_regs[0x11] &= ~0xc0; + cmi8x38_update_irqs(dev); + break; - case 0x15: - if (dev->type == CMEDIA_CMI8338) - return; - else - val &= 0xf0; + case 0x15: + if (dev->type == CMEDIA_CMI8338) + return; + else + val &= 0xf0; - /* Update channel count. */ - dev->io_regs[addr] = val; - cmi8x38_speed_changed(dev); - break; + /* Update channel count. */ + dev->io_regs[addr] = val; + cmi8x38_speed_changed(dev); + break; - case 0x16: - if (dev->type == CMEDIA_CMI8338) { - val &= 0xa0; + case 0x16: + if (dev->type == CMEDIA_CMI8338) { + val &= 0xa0; - /* Enable or disable I/O traps. */ - dev->io_regs[addr] = val; - cmi8x38_remap_traps(dev); - } - break; + /* Enable or disable I/O traps. */ + dev->io_regs[addr] = val; + cmi8x38_remap_traps(dev); + } + break; - case 0x17: - if (dev->type == CMEDIA_CMI8338) { - val &= 0xf3; + case 0x17: + if (dev->type == CMEDIA_CMI8338) { + val &= 0xf3; - /* Force IRQ if requested. Clearing this bit is undefined. */ - if (val & 0x10) - pci_set_irq(dev->slot, PCI_INTA); - else if ((dev->io_regs[0x17] & 0x10) && !(val & 0x10)) - pci_clear_irq(dev->slot, PCI_INTA); + /* Force IRQ if requested. Clearing this bit is undefined. */ + if (val & 0x10) + pci_set_irq(dev->slot, PCI_INTA); + else if ((dev->io_regs[0x17] & 0x10) && !(val & 0x10)) + pci_clear_irq(dev->slot, PCI_INTA); - /* Enable or disable I/O traps. */ - dev->io_regs[addr] = val; - cmi8x38_remap_traps(dev); - } + /* Enable or disable I/O traps. */ + dev->io_regs[addr] = val; + cmi8x38_remap_traps(dev); + } - /* Remap the legacy devices. */ - dev->io_regs[addr] = val; - cmi8x38_remap_sb(dev); - cmi8x38_remap_mpu(dev); - break; + /* Remap the legacy devices. */ + dev->io_regs[addr] = val; + cmi8x38_remap_sb(dev); + cmi8x38_remap_mpu(dev); + break; - case 0x18: - if (dev->type == CMEDIA_CMI8338) - val &= 0x0f; - else - val &= 0xdf; - break; + case 0x18: + if (dev->type == CMEDIA_CMI8338) + val &= 0x0f; + else + val &= 0xdf; + break; - case 0x19: - if (dev->type == CMEDIA_CMI8338) - return; - else - val &= 0xe0; - break; + case 0x19: + if (dev->type == CMEDIA_CMI8338) + return; + else + val &= 0xe0; + break; - case 0x1a: - val &= 0xfd; + case 0x1a: + val &= 0xfd; - /* Enable or disable the OPL. */ - dev->io_regs[addr] = val; - cmi8x38_remap_opl(dev); - break; + /* Enable or disable the OPL. */ + dev->io_regs[addr] = val; + cmi8x38_remap_opl(dev); + break; - case 0x1b: - if (dev->type == CMEDIA_CMI8338) - val &= 0xf0; - else - val &= 0xd7; - break; + case 0x1b: + if (dev->type == CMEDIA_CMI8338) + val &= 0xf0; + else + val &= 0xd7; + break; - case 0x20: - /* ??? */ - break; + case 0x20: + /* ??? */ + break; - case 0x21: - if (dev->type == CMEDIA_CMI8338) - val &= 0xf7; - else - val &= 0x07; + case 0x21: + if (dev->type == CMEDIA_CMI8338) + val &= 0xf7; + else + val &= 0x07; - /* Enable or disable SBPro channel swapping. */ - dev->sb->dsp.sbleftright_default = !!(val & 0x02); + /* Enable or disable SBPro channel swapping. */ + dev->sb->dsp.sbleftright_default = !!(val & 0x02); - /* Enable or disable SB16 mode. */ - dev->sb->dsp.sb_type = (val & 0x01) ? SBPRO2 : SB16; - break; + /* Enable or disable SB16 mode. */ + dev->sb->dsp.sb_type = (val & 0x01) ? SBPRO2 : SB16; + break; - case 0x22: case 0x23: - cmi8x38_sb_mixer_write(addr ^ 1, val, dev); - return; + case 0x22: + case 0x23: + cmi8x38_sb_mixer_write(addr ^ 1, val, dev); + return; - case 0x24: - if (dev->type == CMEDIA_CMI8338) - val &= 0xcf; - break; + case 0x24: + if (dev->type == CMEDIA_CMI8338) + val &= 0xcf; + break; - case 0x27: - if (dev->type == CMEDIA_CMI8338) - val &= 0x03; - else - val &= 0x27; - break; + case 0x27: + if (dev->type == CMEDIA_CMI8338) + val &= 0x03; + else + val &= 0x27; + break; - case 0x40 ... 0x4f: - if (dev->type != CMEDIA_CMI8338) - mpu401_write(addr, val, dev->sb->mpu); - return; + case 0x40 ... 0x4f: + if (dev->type != CMEDIA_CMI8338) + mpu401_write(addr, val, dev->sb->mpu); + return; - case 0x50 ... 0x5f: - if (dev->type != CMEDIA_CMI8338) - opl3_write(addr, val, &dev->sb->opl); - return; + case 0x50 ... 0x5f: + if (dev->type != CMEDIA_CMI8338) + opl3_write(addr, val, &dev->sb->opl); + return; - case 0x92: - if (dev->type == CMEDIA_CMI8338) - return; - else - val &= 0x1f; - break; + case 0x92: + if (dev->type == CMEDIA_CMI8338) + return; + else + val &= 0x1f; + break; - case 0x93: - if (dev->type == CMEDIA_CMI8338) - return; - else - val &= 0x10; - break; + case 0x93: + if (dev->type == CMEDIA_CMI8338) + return; + else + val &= 0x10; + break; - case 0x25: case 0x26: - case 0x70: case 0x71: - case 0x80 ... 0x8f: - break; + case 0x25: + case 0x26: + case 0x70: + case 0x71: + case 0x80 ... 0x8f: + break; - default: - return; + default: + return; } dev->io_regs[addr] = val; } - static void cmi8x38_remap(cmi8x38_t *dev) { if (dev->io_base) - io_removehandler(dev->io_base, 256, cmi8x38_read, NULL, NULL, cmi8x38_write, NULL, NULL, dev); + io_removehandler(dev->io_base, 256, cmi8x38_read, NULL, NULL, cmi8x38_write, NULL, NULL, dev); dev->io_base = (dev->pci_regs[0x04] & 0x01) ? (dev->pci_regs[0x11] << 8) : 0; cmi8x38_log("CMI8x38: remap(%04X)\n", dev->io_base); if (dev->io_base) - io_sethandler(dev->io_base, 256, cmi8x38_read, NULL, NULL, cmi8x38_write, NULL, NULL, dev); + io_sethandler(dev->io_base, 256, cmi8x38_read, NULL, NULL, cmi8x38_write, NULL, NULL, dev); } - static uint8_t cmi8x38_pci_read(int func, int addr, void *priv) { cmi8x38_t *dev = (cmi8x38_t *) priv; - uint8_t ret = 0xff; + uint8_t ret = 0xff; if (!func) { - ret = dev->pci_regs[addr]; - cmi8x38_log("CMI8x38: pci_read(%02X) = %02X\n", addr, ret); + ret = dev->pci_regs[addr]; + cmi8x38_log("CMI8x38: pci_read(%02X) = %02X\n", addr, ret); } return ret; } - static void cmi8x38_pci_write(int func, int addr, uint8_t val, void *priv) { cmi8x38_t *dev = (cmi8x38_t *) priv; if (func) - return; + return; cmi8x38_log("CMI8x38: pci_write(%02X, %02X)\n", addr, val); switch (addr) { - case 0x04: - val &= 0x05; + case 0x04: + val &= 0x05; - /* Enable or disable the I/O BAR. */ - dev->pci_regs[addr] = val; - cmi8x38_remap(dev); - break; + /* Enable or disable the I/O BAR. */ + dev->pci_regs[addr] = val; + cmi8x38_remap(dev); + break; - case 0x05: - val &= 0x01; - break; + case 0x05: + val &= 0x01; + break; - case 0x11: - /* Remap the I/O BAR. */ - dev->pci_regs[addr] = val; - cmi8x38_remap(dev); - break; + case 0x11: + /* Remap the I/O BAR. */ + dev->pci_regs[addr] = val; + cmi8x38_remap(dev); + break; - case 0x2c: case 0x2d: case 0x2e: case 0x2f: - if (!(dev->io_regs[0x1a] & 0x01)) - return; - break; + case 0x2c: + case 0x2d: + case 0x2e: + case 0x2f: + if (!(dev->io_regs[0x1a] & 0x01)) + return; + break; - case 0x40: - if (dev->type == CMEDIA_CMI8338) - val &= 0x0f; - else - return; - break; + case 0x40: + if (dev->type == CMEDIA_CMI8338) + val &= 0x0f; + else + return; + break; - case 0x0c: case 0x0d: - case 0x3c: - break; + case 0x0c: + case 0x0d: + case 0x3c: + break; - default: - return; + default: + return; } dev->pci_regs[addr] = val; } - static void cmi8x38_update(cmi8x38_t *dev, cmi8x38_dma_t *dma) { sb_ct1745_mixer_t *mixer = &dev->sb->mixer_sb16; - int32_t l = (dma->out_fl * mixer->voice_l) * mixer->master_l, - r = (dma->out_fr * mixer->voice_r) * mixer->master_r; + int32_t l = (dma->out_fl * mixer->voice_l) * mixer->master_l, + r = (dma->out_fr * mixer->voice_r) * mixer->master_r; for (; dma->pos < sound_pos_global; dma->pos++) { - dma->buffer[dma->pos*2] = l; - dma->buffer[dma->pos*2 + 1] = r; + dma->buffer[dma->pos * 2] = l; + dma->buffer[dma->pos * 2 + 1] = r; } } - static void cmi8x38_dma_process(void *priv) { cmi8x38_dma_t *dma = (cmi8x38_dma_t *) priv; - cmi8x38_t *dev = dma->dev; + cmi8x38_t *dev = dma->dev; /* Stop if this DMA channel is not active. */ uint8_t dma_bit = 0x01 << dma->id; if (!(dev->io_regs[0x02] & dma_bit)) { - cmi8x38_log("CMI8x38: Stopping DMA %d due to inactive channel (%02X)\n", dma->id, dev->io_regs[0x02]); - return; + cmi8x38_log("CMI8x38: Stopping DMA %d due to inactive channel (%02X)\n", dma->id, dev->io_regs[0x02]); + return; } /* Schedule next run. */ @@ -1014,185 +1005,184 @@ cmi8x38_dma_process(void *priv) /* Process DMA if it's active, and the FIFO has room or is disabled. */ uint8_t dma_status = dev->io_regs[0x00] >> dma->id; if (!(dma_status & 0x04) && (dma->always_run || ((dma->fifo_end - dma->fifo_pos) <= (sizeof(dma->fifo) - 4)))) { - /* Start DMA if requested. */ - if (dma->restart) { - /* Set up base address and counters. - I have no idea how sample_count_out is supposed to work, - nothing consumes it, so it's implemented as an assumption. */ - dma->restart = 0; - dma->sample_ptr = *((uint32_t *) &dev->io_regs[dma->reg]); - dma->frame_count_dma = dma->sample_count_out = *((uint16_t *) &dev->io_regs[dma->reg | 0x4]) + 1; - dma->frame_count_fragment = *((uint16_t *) &dev->io_regs[dma->reg | 0x6]) + 1; + /* Start DMA if requested. */ + if (dma->restart) { + /* Set up base address and counters. + I have no idea how sample_count_out is supposed to work, + nothing consumes it, so it's implemented as an assumption. */ + dma->restart = 0; + dma->sample_ptr = *((uint32_t *) &dev->io_regs[dma->reg]); + dma->frame_count_dma = dma->sample_count_out = *((uint16_t *) &dev->io_regs[dma->reg | 0x4]) + 1; + dma->frame_count_fragment = *((uint16_t *) &dev->io_regs[dma->reg | 0x6]) + 1; - cmi8x38_log("CMI8x38: Starting DMA %d at %08X (count %04X fragment %04X)\n", dma->id, dma->sample_ptr, dma->frame_count_dma, dma->frame_count_fragment); - } + cmi8x38_log("CMI8x38: Starting DMA %d at %08X (count %04X fragment %04X)\n", dma->id, dma->sample_ptr, dma->frame_count_dma, dma->frame_count_fragment); + } - if (dma_status & 0x01) { - /* Write channel: read data from FIFO. */ - mem_writel_phys(dma->sample_ptr, *((uint32_t *) &dma->fifo[dma->fifo_end & (sizeof(dma->fifo) - 1)])); - } else { - /* Read channel: write data to FIFO. */ - *((uint32_t *) &dma->fifo[dma->fifo_end & (sizeof(dma->fifo) - 1)]) = mem_readl_phys(dma->sample_ptr); - } - dma->fifo_end += 4; - dma->sample_ptr += 4; + if (dma_status & 0x01) { + /* Write channel: read data from FIFO. */ + mem_writel_phys(dma->sample_ptr, *((uint32_t *) &dma->fifo[dma->fifo_end & (sizeof(dma->fifo) - 1)])); + } else { + /* Read channel: write data to FIFO. */ + *((uint32_t *) &dma->fifo[dma->fifo_end & (sizeof(dma->fifo) - 1)]) = mem_readl_phys(dma->sample_ptr); + } + dma->fifo_end += 4; + dma->sample_ptr += 4; - /* Check if the fragment size was reached. */ - if (--dma->frame_count_fragment <= 0) { - cmi8x38_log("CMI8x38: DMA %d fragment size reached at %04X frames left", dma->id, dma->frame_count_dma - 1); + /* Check if the fragment size was reached. */ + if (--dma->frame_count_fragment <= 0) { + cmi8x38_log("CMI8x38: DMA %d fragment size reached at %04X frames left", dma->id, dma->frame_count_dma - 1); - /* Reset fragment counter. */ - dma->frame_count_fragment = *((uint16_t *) &dev->io_regs[dma->reg | 0x6]) + 1; + /* Reset fragment counter. */ + dma->frame_count_fragment = *((uint16_t *) &dev->io_regs[dma->reg | 0x6]) + 1; - /* Fire interrupt if requested. */ - if (dev->io_regs[0x0e] & dma_bit) { - cmi8x38_log(", firing interrupt\n"); + /* Fire interrupt if requested. */ + if (dev->io_regs[0x0e] & dma_bit) { + cmi8x38_log(", firing interrupt\n"); - /* Set channel interrupt flag. */ - dev->io_regs[0x10] |= dma_bit; + /* Set channel interrupt flag. */ + dev->io_regs[0x10] |= dma_bit; - /* Fire interrupt. */ - cmi8x38_update_irqs(dev); - } else { - cmi8x38_log("\n"); - } - } + /* Fire interrupt. */ + cmi8x38_update_irqs(dev); + } else { + cmi8x38_log("\n"); + } + } - /* Check if the buffer's end was reached. */ - if (--dma->frame_count_dma <= 0) { - dma->frame_count_dma = 0; - cmi8x38_log("CMI8x38: DMA %d end reached, restarting\n", dma->id); + /* Check if the buffer's end was reached. */ + if (--dma->frame_count_dma <= 0) { + dma->frame_count_dma = 0; + cmi8x38_log("CMI8x38: DMA %d end reached, restarting\n", dma->id); - /* Restart DMA on the next run. */ - dma->restart = 1; - } + /* Restart DMA on the next run. */ + dma->restart = 1; + } } } - static void cmi8x38_poll(void *priv) { cmi8x38_dma_t *dma = (cmi8x38_dma_t *) priv; - cmi8x38_t *dev = dma->dev; - int16_t *out_l, *out_r, *out_ol, *out_or; /* o = opposite */ + cmi8x38_t *dev = dma->dev; + int16_t *out_l, *out_r, *out_ol, *out_or; /* o = opposite */ /* Schedule next run if playback is enabled. */ if (dev->io_regs[0x00] & (1 << dma->id)) - dma->playback_enabled = 0; + dma->playback_enabled = 0; else - timer_advance_u64(&dma->poll_timer, dma->timer_latch); + timer_advance_u64(&dma->poll_timer, dma->timer_latch); /* Update audio buffer. */ cmi8x38_update(dev, dma); /* Swap stereo pair if this is the rear DMA channel according to ENDBDAC and XCHGDAC. */ if ((dev->io_regs[0x1a] & 0x80) && (!!(dev->io_regs[0x1a] & 0x40) ^ dma->id)) { - out_l = &dma->out_rl; - out_r = &dma->out_rr; - out_ol = &dma->out_fl; - out_or = &dma->out_fr; + out_l = &dma->out_rl; + out_r = &dma->out_rr; + out_ol = &dma->out_fl; + out_or = &dma->out_fr; } else { - out_l = &dma->out_fl; - out_r = &dma->out_fr; - out_ol = &dma->out_rl; - out_or = &dma->out_rr; + out_l = &dma->out_fl; + out_r = &dma->out_fr; + out_ol = &dma->out_rl; + out_or = &dma->out_rr; } *out_ol = *out_or = dma->out_c = dma->out_lfe = 0; /* Feed next sample from the FIFO. */ switch ((dev->io_regs[0x08] >> (dma->id << 1)) & 0x03) { - case 0x00: /* Mono, 8-bit PCM */ - if ((dma->fifo_end - dma->fifo_pos) >= 1) { - *out_l = *out_r = (dma->fifo[dma->fifo_pos++ & (sizeof(dma->fifo) - 1)] ^ 0x80) << 8; - dma->sample_count_out--; - goto n4spk3d; - } - break; + case 0x00: /* Mono, 8-bit PCM */ + if ((dma->fifo_end - dma->fifo_pos) >= 1) { + *out_l = *out_r = (dma->fifo[dma->fifo_pos++ & (sizeof(dma->fifo) - 1)] ^ 0x80) << 8; + dma->sample_count_out--; + goto n4spk3d; + } + break; - case 0x01: /* Stereo, 8-bit PCM */ - if ((dma->fifo_end - dma->fifo_pos) >= 2) { - *out_l = (dma->fifo[dma->fifo_pos++ & (sizeof(dma->fifo) - 1)] ^ 0x80) << 8; - *out_r = (dma->fifo[dma->fifo_pos++ & (sizeof(dma->fifo) - 1)] ^ 0x80) << 8; - dma->sample_count_out -= 2; - goto n4spk3d; - } - break; + case 0x01: /* Stereo, 8-bit PCM */ + if ((dma->fifo_end - dma->fifo_pos) >= 2) { + *out_l = (dma->fifo[dma->fifo_pos++ & (sizeof(dma->fifo) - 1)] ^ 0x80) << 8; + *out_r = (dma->fifo[dma->fifo_pos++ & (sizeof(dma->fifo) - 1)] ^ 0x80) << 8; + dma->sample_count_out -= 2; + goto n4spk3d; + } + break; - case 0x02: /* Mono, 16-bit PCM */ - if ((dma->fifo_end - dma->fifo_pos) >= 2) { - *out_l = *out_r = *((uint16_t *) &dma->fifo[dma->fifo_pos & (sizeof(dma->fifo) - 1)]); - dma->fifo_pos += 2; - dma->sample_count_out -= 2; - goto n4spk3d; - } - break; + case 0x02: /* Mono, 16-bit PCM */ + if ((dma->fifo_end - dma->fifo_pos) >= 2) { + *out_l = *out_r = *((uint16_t *) &dma->fifo[dma->fifo_pos & (sizeof(dma->fifo) - 1)]); + dma->fifo_pos += 2; + dma->sample_count_out -= 2; + goto n4spk3d; + } + break; - case 0x03: /* Stereo, 16-bit PCM */ - switch (dma->channels) { - case 2: - if ((dma->fifo_end - dma->fifo_pos) >= 4) { - *out_l = *((uint16_t *) &dma->fifo[dma->fifo_pos & (sizeof(dma->fifo) - 1)]); - dma->fifo_pos += 2; - *out_r = *((uint16_t *) &dma->fifo[dma->fifo_pos & (sizeof(dma->fifo) - 1)]); - dma->fifo_pos += 2; - dma->sample_count_out -= 4; - goto n4spk3d; - } - break; + case 0x03: /* Stereo, 16-bit PCM */ + switch (dma->channels) { + case 2: + if ((dma->fifo_end - dma->fifo_pos) >= 4) { + *out_l = *((uint16_t *) &dma->fifo[dma->fifo_pos & (sizeof(dma->fifo) - 1)]); + dma->fifo_pos += 2; + *out_r = *((uint16_t *) &dma->fifo[dma->fifo_pos & (sizeof(dma->fifo) - 1)]); + dma->fifo_pos += 2; + dma->sample_count_out -= 4; + goto n4spk3d; + } + break; - case 4: - if ((dma->fifo_end - dma->fifo_pos) >= 8) { - dma->out_fl = *((uint16_t *) &dma->fifo[dma->fifo_pos & (sizeof(dma->fifo) - 1)]); - dma->fifo_pos += 2; - dma->out_fr = *((uint16_t *) &dma->fifo[dma->fifo_pos & (sizeof(dma->fifo) - 1)]); - dma->fifo_pos += 2; - dma->out_rl = *((uint16_t *) &dma->fifo[dma->fifo_pos & (sizeof(dma->fifo) - 1)]); - dma->fifo_pos += 2; - dma->out_rr = *((uint16_t *) &dma->fifo[dma->fifo_pos & (sizeof(dma->fifo) - 1)]); - dma->fifo_pos += 2; - dma->sample_count_out -= 8; - return; - } - break; + case 4: + if ((dma->fifo_end - dma->fifo_pos) >= 8) { + dma->out_fl = *((uint16_t *) &dma->fifo[dma->fifo_pos & (sizeof(dma->fifo) - 1)]); + dma->fifo_pos += 2; + dma->out_fr = *((uint16_t *) &dma->fifo[dma->fifo_pos & (sizeof(dma->fifo) - 1)]); + dma->fifo_pos += 2; + dma->out_rl = *((uint16_t *) &dma->fifo[dma->fifo_pos & (sizeof(dma->fifo) - 1)]); + dma->fifo_pos += 2; + dma->out_rr = *((uint16_t *) &dma->fifo[dma->fifo_pos & (sizeof(dma->fifo) - 1)]); + dma->fifo_pos += 2; + dma->sample_count_out -= 8; + return; + } + break; - case 5: /* not supported by WDM and Linux drivers; channel layout assumed */ - if ((dma->fifo_end - dma->fifo_pos) >= 10) { - dma->out_fl = *((uint16_t *) &dma->fifo[dma->fifo_pos & (sizeof(dma->fifo) - 1)]); - dma->fifo_pos += 2; - dma->out_fr = *((uint16_t *) &dma->fifo[dma->fifo_pos & (sizeof(dma->fifo) - 1)]); - dma->fifo_pos += 2; - dma->out_rl = *((uint16_t *) &dma->fifo[dma->fifo_pos & (sizeof(dma->fifo) - 1)]); - dma->fifo_pos += 2; - dma->out_rr = *((uint16_t *) &dma->fifo[dma->fifo_pos & (sizeof(dma->fifo) - 1)]); - dma->fifo_pos += 2; - dma->out_c = *((uint16_t *) &dma->fifo[dma->fifo_pos & (sizeof(dma->fifo) - 1)]); - dma->fifo_pos += 2; - dma->sample_count_out -= 10; - return; - } - break; + case 5: /* not supported by WDM and Linux drivers; channel layout assumed */ + if ((dma->fifo_end - dma->fifo_pos) >= 10) { + dma->out_fl = *((uint16_t *) &dma->fifo[dma->fifo_pos & (sizeof(dma->fifo) - 1)]); + dma->fifo_pos += 2; + dma->out_fr = *((uint16_t *) &dma->fifo[dma->fifo_pos & (sizeof(dma->fifo) - 1)]); + dma->fifo_pos += 2; + dma->out_rl = *((uint16_t *) &dma->fifo[dma->fifo_pos & (sizeof(dma->fifo) - 1)]); + dma->fifo_pos += 2; + dma->out_rr = *((uint16_t *) &dma->fifo[dma->fifo_pos & (sizeof(dma->fifo) - 1)]); + dma->fifo_pos += 2; + dma->out_c = *((uint16_t *) &dma->fifo[dma->fifo_pos & (sizeof(dma->fifo) - 1)]); + dma->fifo_pos += 2; + dma->sample_count_out -= 10; + return; + } + break; - case 6: - if ((dma->fifo_end - dma->fifo_pos) >= 12) { - dma->out_fl = *((uint16_t *) &dma->fifo[dma->fifo_pos & (sizeof(dma->fifo) - 1)]); - dma->fifo_pos += 2; - dma->out_fr = *((uint16_t *) &dma->fifo[dma->fifo_pos & (sizeof(dma->fifo) - 1)]); - dma->fifo_pos += 2; - dma->out_rl = *((uint16_t *) &dma->fifo[dma->fifo_pos & (sizeof(dma->fifo) - 1)]); - dma->fifo_pos += 2; - dma->out_rr = *((uint16_t *) &dma->fifo[dma->fifo_pos & (sizeof(dma->fifo) - 1)]); - dma->fifo_pos += 2; - dma->out_c = *((uint16_t *) &dma->fifo[dma->fifo_pos & (sizeof(dma->fifo) - 1)]); - dma->fifo_pos += 2; - dma->out_lfe= *((uint16_t *) &dma->fifo[dma->fifo_pos & (sizeof(dma->fifo) - 1)]); - dma->fifo_pos += 2; - dma->sample_count_out -= 12; - return; - } - break; - } - break; + case 6: + if ((dma->fifo_end - dma->fifo_pos) >= 12) { + dma->out_fl = *((uint16_t *) &dma->fifo[dma->fifo_pos & (sizeof(dma->fifo) - 1)]); + dma->fifo_pos += 2; + dma->out_fr = *((uint16_t *) &dma->fifo[dma->fifo_pos & (sizeof(dma->fifo) - 1)]); + dma->fifo_pos += 2; + dma->out_rl = *((uint16_t *) &dma->fifo[dma->fifo_pos & (sizeof(dma->fifo) - 1)]); + dma->fifo_pos += 2; + dma->out_rr = *((uint16_t *) &dma->fifo[dma->fifo_pos & (sizeof(dma->fifo) - 1)]); + dma->fifo_pos += 2; + dma->out_c = *((uint16_t *) &dma->fifo[dma->fifo_pos & (sizeof(dma->fifo) - 1)]); + dma->fifo_pos += 2; + dma->out_lfe = *((uint16_t *) &dma->fifo[dma->fifo_pos & (sizeof(dma->fifo) - 1)]); + dma->fifo_pos += 2; + dma->sample_count_out -= 12; + return; + } + break; + } + break; } /* Feed silence if the FIFO is empty. */ @@ -1202,12 +1192,11 @@ cmi8x38_poll(void *priv) n4spk3d: /* Mirror front and rear channels if requested. */ if (dev->io_regs[0x1b] & 0x04) { - *out_ol = *out_l; - *out_or = *out_r; + *out_ol = *out_l; + *out_or = *out_r; } } - static void cmi8x38_get_buffer(int32_t *buffer, int len, void *priv) { @@ -1219,24 +1208,23 @@ cmi8x38_get_buffer(int32_t *buffer, int len, void *priv) /* Apply wave mute. */ if (!(dev->io_regs[0x24] & 0x40)) { - /* Fill buffer. */ - for (int c = 0; c < len * 2; c++) { - buffer[c] += dev->dma[0].buffer[c]; - buffer[c] += dev->dma[1].buffer[c]; - } + /* Fill buffer. */ + for (int c = 0; c < len * 2; c++) { + buffer[c] += dev->dma[0].buffer[c]; + buffer[c] += dev->dma[1].buffer[c]; + } } dev->dma[0].pos = dev->dma[1].pos = 0; } - static void cmi8x38_speed_changed(void *priv) { cmi8x38_t *dev = (cmi8x38_t *) priv; - double freq; - uint8_t dsr = dev->io_regs[0x09], freqreg = dev->io_regs[0x05] >> 2, - chfmt45 = dev->io_regs[0x0b], chfmt6 = dev->io_regs[0x15]; + double freq; + uint8_t dsr = dev->io_regs[0x09], freqreg = dev->io_regs[0x05] >> 2, + chfmt45 = dev->io_regs[0x0b], chfmt6 = dev->io_regs[0x15]; #ifdef ENABLE_CMI8X38_LOG char buf[256]; @@ -1247,48 +1235,56 @@ cmi8x38_speed_changed(void *priv) respectively, while CMI8738 claims they're for channel 0 and channel 1. The Linux driver just assumes the latter definition, so that's what we're going to use here. */ for (int i = 0; i < (sizeof(dev->dma) / sizeof(dev->dma[0])); i++) { - /* More confusion. The Linux driver implies the sample rate doubling - bits take precedence over any configured sample rate. 128K with both - doubling bits set is also supported there, but that's for newer chips. */ - switch (dsr & 0x03) { - case 0x01: freq = 88200.0; break; - case 0x02: freq = 96000.0; break; - case 0x03: freq = 128000.0; break; - default: freq = freqs[freqreg & 0x07]; break; - } + /* More confusion. The Linux driver implies the sample rate doubling + bits take precedence over any configured sample rate. 128K with both + doubling bits set is also supported there, but that's for newer chips. */ + switch (dsr & 0x03) { + case 0x01: + freq = 88200.0; + break; + case 0x02: + freq = 96000.0; + break; + case 0x03: + freq = 128000.0; + break; + default: + freq = freqs[freqreg & 0x07]; + break; + } - /* Set polling timer period. */ - freq = 1000000.0 / freq; - dev->dma[i].timer_latch = (uint64_t) ((double) TIMER_USEC * freq); + /* Set polling timer period. */ + freq = 1000000.0 / freq; + dev->dma[i].timer_latch = (uint64_t) ((double) TIMER_USEC * freq); - /* Calculate channel count and set DMA timer period. */ - if ((dev->type == CMEDIA_CMI8338) || (i == 0)) { -stereo: dev->dma[i].channels = 2; - } else { - if (chfmt45 & 0x80) - dev->dma[i].channels = (chfmt6 & 0x80) ? 6 : 5; - else if (chfmt45 & 0x20) - dev->dma[i].channels = 4; - else - goto stereo; - } - dev->dma[i].dma_latch = freq / dev->dma[i].channels; /* frequency / approximately(dwords * 2) */ + /* Calculate channel count and set DMA timer period. */ + if ((dev->type == CMEDIA_CMI8338) || (i == 0)) { +stereo: + dev->dma[i].channels = 2; + } else { + if (chfmt45 & 0x80) + dev->dma[i].channels = (chfmt6 & 0x80) ? 6 : 5; + else if (chfmt45 & 0x20) + dev->dma[i].channels = 4; + else + goto stereo; + } + dev->dma[i].dma_latch = freq / dev->dma[i].channels; /* frequency / approximately(dwords * 2) */ - /* Shift sample rate configuration registers. */ + /* Shift sample rate configuration registers. */ #ifdef ENABLE_CMI8X38_LOG - sprintf(&buf[strlen(buf)], " %d:%X-%X-%.0f-%dC", i, dsr & 0x03, freqreg & 0x07, 1000000.0 / freq, dev->dma[i].channels); + sprintf(&buf[strlen(buf)], " %d:%X-%X-%.0f-%dC", i, dsr & 0x03, freqreg & 0x07, 1000000.0 / freq, dev->dma[i].channels); #endif - dsr >>= 2; - freqreg >>= 3; + dsr >>= 2; + freqreg >>= 3; } #ifdef ENABLE_CMI8X38_LOG if (cmi8x38_do_log) - ui_sb_bugui(buf); + ui_sb_bugui(buf); #endif } - static void cmi8x38_reset(void *priv) { @@ -1296,19 +1292,26 @@ cmi8x38_reset(void *priv) /* Reset PCI configuration registers. */ memset(dev->pci_regs, 0, sizeof(dev->pci_regs)); - dev->pci_regs[0x00] = 0xf6; dev->pci_regs[0x01] = 0x13; - dev->pci_regs[0x02] = dev->type; dev->pci_regs[0x03] = 0x01; - dev->pci_regs[0x06] = (dev->type == CMEDIA_CMI8338) ? 0x80 : 0x10; dev->pci_regs[0x07] = 0x02; + dev->pci_regs[0x00] = 0xf6; + dev->pci_regs[0x01] = 0x13; + dev->pci_regs[0x02] = dev->type; + dev->pci_regs[0x03] = 0x01; + dev->pci_regs[0x06] = (dev->type == CMEDIA_CMI8338) ? 0x80 : 0x10; + dev->pci_regs[0x07] = 0x02; dev->pci_regs[0x08] = 0x10; - dev->pci_regs[0x0a] = 0x01; dev->pci_regs[0x0b] = 0x04; + dev->pci_regs[0x0a] = 0x01; + dev->pci_regs[0x0b] = 0x04; dev->pci_regs[0x0d] = 0x20; dev->pci_regs[0x10] = 0x01; - dev->pci_regs[0x2c] = 0xf6; dev->pci_regs[0x2d] = 0x13; + dev->pci_regs[0x2c] = 0xf6; + dev->pci_regs[0x2d] = 0x13; if (dev->type == CMEDIA_CMI8338) { - dev->pci_regs[0x2e] = 0xff; dev->pci_regs[0x2f] = 0xff; + dev->pci_regs[0x2e] = 0xff; + dev->pci_regs[0x2f] = 0xff; } else { - dev->pci_regs[0x2e] = dev->type; dev->pci_regs[0x2f] = 0x01; - dev->pci_regs[0x34] = 0x40; + dev->pci_regs[0x2e] = dev->type; + dev->pci_regs[0x2f] = 0x01; + dev->pci_regs[0x34] = 0x40; } dev->pci_regs[0x3d] = 0x01; dev->pci_regs[0x3e] = 0x02; @@ -1327,22 +1330,21 @@ cmi8x38_reset(void *priv) /* Reset DMA channels. */ for (int i = 0; i < (sizeof(dev->dma) / sizeof(dev->dma[0])); i++) { - dev->dma[i].playback_enabled = 0; + dev->dma[i].playback_enabled = 0; - dev->dma[i].fifo_pos = dev->dma[i].fifo_end = 0; - memset(dev->dma[i].fifo, 0, sizeof(dev->dma[i].fifo)); + dev->dma[i].fifo_pos = dev->dma[i].fifo_end = 0; + memset(dev->dma[i].fifo, 0, sizeof(dev->dma[i].fifo)); } /* Reset legacy DMA channel. */ - dev->tdma_8 = 1; - dev->tdma_16 = 5; + dev->tdma_8 = 1; + dev->tdma_16 = 5; dev->tdma_mask = 0; /* Reset Sound Blaster 16 mixer. */ sb_ct1745_mixer_reset(dev->sb); } - static void * cmi8x38_init(const device_t *info) { @@ -1351,33 +1353,33 @@ cmi8x38_init(const device_t *info) /* Set the chip type. */ if ((info->local == CMEDIA_CMI8738_6CH) && !device_get_config_int("six_channel")) - dev->type = CMEDIA_CMI8738_4CH; + dev->type = CMEDIA_CMI8738_4CH; else - dev->type = info->local; + dev->type = info->local; cmi8x38_log("CMI8x38: init(%06X)\n", dev->type); /* Initialize Sound Blaster 16. */ - dev->sb = device_add_inst(device_get_config_int("receive_input") ? &sb_16_compat_device : &sb_16_compat_nompu_device, 1); - dev->sb->opl_enabled = 1; /* let snd_sb.c handle the OPL3 */ + dev->sb = device_add_inst(device_get_config_int("receive_input") ? &sb_16_compat_device : &sb_16_compat_nompu_device, 1); + dev->sb->opl_enabled = 1; /* let snd_sb.c handle the OPL3 */ dev->sb->mixer_sb16.output_filter = 0; /* no output filtering */ /* Initialize legacy interrupt and DMA handlers. */ mpu401_irq_attach(dev->sb->mpu, cmi8x38_mpu_irq_update, cmi8x38_mpu_irq_pending, dev); sb_dsp_irq_attach(&dev->sb->dsp, cmi8x38_sb_irq_update, dev); sb_dsp_dma_attach(&dev->sb->dsp, cmi8x38_sb_dma_readb, cmi8x38_sb_dma_readw, cmi8x38_sb_dma_writeb, cmi8x38_sb_dma_writew, dev); - io_sethandler(0x00, 8, NULL, NULL, NULL, cmi8x38_dma_write, NULL, NULL, dev); - io_sethandler(0x08, 8, NULL, NULL, NULL, cmi8x38_dma_mask_write, NULL, NULL, dev); - io_sethandler(0xc0, 16, NULL, NULL, NULL, cmi8x38_dma_write, NULL, NULL, dev); + io_sethandler(0x00, 8, NULL, NULL, NULL, cmi8x38_dma_write, NULL, NULL, dev); + io_sethandler(0x08, 8, NULL, NULL, NULL, cmi8x38_dma_mask_write, NULL, NULL, dev); + io_sethandler(0xc0, 16, NULL, NULL, NULL, cmi8x38_dma_write, NULL, NULL, dev); io_sethandler(0xd0, 16, NULL, NULL, NULL, cmi8x38_dma_mask_write, NULL, NULL, dev); /* Initialize DMA channels. */ for (int i = 0; i < (sizeof(dev->dma) / sizeof(dev->dma[0])); i++) { - dev->dma[i].id = i; - dev->dma[i].reg = 0x80 + (8 * i); - dev->dma[i].dev = dev; + dev->dma[i].id = i; + dev->dma[i].reg = 0x80 + (8 * i); + dev->dma[i].dev = dev; - timer_add(&dev->dma[i].dma_timer, cmi8x38_dma_process, &dev->dma[i], 0); - timer_add(&dev->dma[i].poll_timer, cmi8x38_poll, &dev->dma[i], 0); + timer_add(&dev->dma[i].dma_timer, cmi8x38_dma_process, &dev->dma[i], 0); + timer_add(&dev->dma[i].poll_timer, cmi8x38_poll, &dev->dma[i], 0); } cmi8x38_speed_changed(dev); @@ -1390,10 +1392,10 @@ cmi8x38_init(const device_t *info) /* Initialize I/O traps. */ if (dev->type == CMEDIA_CMI8338) { - dev->io_traps[TRAP_DMA] = io_trap_add(cmi8338_io_trap, dev); - dev->io_traps[TRAP_PIC] = io_trap_add(cmi8338_io_trap, dev); - dev->io_traps[TRAP_OPL] = io_trap_add(cmi8338_io_trap, dev); - dev->io_traps[TRAP_MPU] = io_trap_add(cmi8338_io_trap, dev); + dev->io_traps[TRAP_DMA] = io_trap_add(cmi8338_io_trap, dev); + dev->io_traps[TRAP_PIC] = io_trap_add(cmi8338_io_trap, dev); + dev->io_traps[TRAP_OPL] = io_trap_add(cmi8338_io_trap, dev); + dev->io_traps[TRAP_MPU] = io_trap_add(cmi8338_io_trap, dev); } /* Add PCI card. */ @@ -1405,7 +1407,6 @@ cmi8x38_init(const device_t *info) return dev; } - static void cmi8x38_close(void *priv) { @@ -1414,88 +1415,92 @@ cmi8x38_close(void *priv) cmi8x38_log("CMI8x38: close()\n"); for (int i = 0; i < TRAP_MAX; i++) - io_trap_remove(dev->io_traps[i]); + io_trap_remove(dev->io_traps[i]); free(dev); } static const device_config_t cmi8x38_config[] = { - { "receive_input", "Receive input (MPU-401)", CONFIG_BINARY, "", 1 }, - { "", "", -1 } + // clang-format off + {"receive_input", "Receive input (MPU-401)", CONFIG_BINARY, "", 1 }, + { "", "", -1 } + // clang-format on }; static const device_config_t cmi8738_config[] = { - { "six_channel", "6CH variant (6-channel)", CONFIG_BINARY, "", 1 }, - { "receive_input", "Receive input (MPU-401)", CONFIG_BINARY, "", 1 }, - { "", "", -1 } + // clang-format off + { "six_channel", "6CH variant (6-channel)", CONFIG_BINARY, "", 1 }, + { "receive_input", "Receive input (MPU-401)", CONFIG_BINARY, "", 1 }, + { "", "", -1 } + // clang-format on }; const device_t cmi8338_device = { - .name = "C-Media CMI8338", + .name = "C-Media CMI8338", .internal_name = "cmi8338", - .flags = DEVICE_PCI, - .local = CMEDIA_CMI8338, - .init = cmi8x38_init, - .close = cmi8x38_close, - .reset = cmi8x38_reset, + .flags = DEVICE_PCI, + .local = CMEDIA_CMI8338, + .init = cmi8x38_init, + .close = cmi8x38_close, + .reset = cmi8x38_reset, { .available = NULL }, .speed_changed = cmi8x38_speed_changed, - .force_redraw = NULL, - .config = cmi8x38_config + .force_redraw = NULL, + .config = cmi8x38_config }; const device_t cmi8338_onboard_device = { - .name = "C-Media CMI8338 (On-Board)", + .name = "C-Media CMI8338 (On-Board)", .internal_name = "cmi8338_onboard", - .flags = DEVICE_PCI, - .local = CMEDIA_CMI8338 | (1 << 13), - .init = cmi8x38_init, - .close = cmi8x38_close, - .reset = cmi8x38_reset, + .flags = DEVICE_PCI, + .local = CMEDIA_CMI8338 | (1 << 13), + .init = cmi8x38_init, + .close = cmi8x38_close, + .reset = cmi8x38_reset, { .available = NULL }, .speed_changed = cmi8x38_speed_changed, - .force_redraw = NULL, - .config = cmi8x38_config + .force_redraw = NULL, + .config = cmi8x38_config }; const device_t cmi8738_device = { - .name = "C-Media CMI8738", + .name = "C-Media CMI8738", .internal_name = "cmi8738", - .flags = DEVICE_PCI, - .local = CMEDIA_CMI8738_6CH, - .init = cmi8x38_init, - .close = cmi8x38_close, - .reset = cmi8x38_reset, + .flags = DEVICE_PCI, + .local = CMEDIA_CMI8738_6CH, + .init = cmi8x38_init, + .close = cmi8x38_close, + .reset = cmi8x38_reset, { .available = NULL }, .speed_changed = cmi8x38_speed_changed, - .force_redraw = NULL, - .config = cmi8738_config + .force_redraw = NULL, + .config = cmi8738_config }; const device_t cmi8738_onboard_device = { - .name = "C-Media CMI8738 (On-Board)", + .name = "C-Media CMI8738 (On-Board)", .internal_name = "cmi8738_onboard", - .flags = DEVICE_PCI, - .local = CMEDIA_CMI8738_4CH | (1 << 13), - .init = cmi8x38_init, - .close = cmi8x38_close, - .reset = cmi8x38_reset, + .flags = DEVICE_PCI, + .local = CMEDIA_CMI8738_4CH | (1 << 13), + .init = cmi8x38_init, + .close = cmi8x38_close, + .reset = cmi8x38_reset, { .available = NULL }, .speed_changed = cmi8x38_speed_changed, - .force_redraw = NULL, - .config = cmi8x38_config + .force_redraw = NULL, + .config = cmi8x38_config }; const device_t cmi8738_6ch_onboard_device = { - .name = "C-Media CMI8738-6CH (On-Board)", + .name = "C-Media CMI8738-6CH (On-Board)", .internal_name = "cmi8738_6ch_onboard", - .flags = DEVICE_PCI, - .local = CMEDIA_CMI8738_6CH | (1 << 13), - .init = cmi8x38_init, - .close = cmi8x38_close, - .reset = cmi8x38_reset, + .flags = DEVICE_PCI, + .local = CMEDIA_CMI8738_6CH | (1 << 13), + .init = cmi8x38_init, + .close = cmi8x38_close, + .reset = cmi8x38_reset, { .available = NULL }, .speed_changed = cmi8x38_speed_changed, - .force_redraw = NULL, - .config = cmi8x38_config + .force_redraw = NULL, + .config = cmi8x38_config }; diff --git a/src/sound/snd_cs423x.c b/src/sound/snd_cs423x.c index 5a4a8108e..1f366e373 100644 --- a/src/sound/snd_cs423x.c +++ b/src/sound/snd_cs423x.c @@ -827,71 +827,71 @@ cs423x_speed_changed(void *priv) } const device_t cs4235_device = { - .name = "Crystal CS4235", + .name = "Crystal CS4235", .internal_name = "cs4235", - .flags = DEVICE_ISA | DEVICE_AT, - .local = CRYSTAL_CS4235, - .init = cs423x_init, - .close = cs423x_close, - .reset = cs423x_reset, + .flags = DEVICE_ISA | DEVICE_AT, + .local = CRYSTAL_CS4235, + .init = cs423x_init, + .close = cs423x_close, + .reset = cs423x_reset, { .available = NULL }, .speed_changed = cs423x_speed_changed, - .force_redraw = NULL, - .config = NULL + .force_redraw = NULL, + .config = NULL }; const device_t cs4235_onboard_device = { - .name = "Crystal CS4235 (On-Board)", + .name = "Crystal CS4235 (On-Board)", .internal_name = "cs4235_onboard", - .flags = DEVICE_ISA | DEVICE_AT, - .local = CRYSTAL_CS4235 | CRYSTAL_NOEEPROM, - .init = cs423x_init, - .close = cs423x_close, - .reset = cs423x_reset, + .flags = DEVICE_ISA | DEVICE_AT, + .local = CRYSTAL_CS4235 | CRYSTAL_NOEEPROM, + .init = cs423x_init, + .close = cs423x_close, + .reset = cs423x_reset, { .available = NULL }, .speed_changed = cs423x_speed_changed, - .force_redraw = NULL, - .config = NULL + .force_redraw = NULL, + .config = NULL }; const device_t cs4236b_device = { - .name = "Crystal CS4236B", + .name = "Crystal CS4236B", .internal_name = "cs4236b", - .flags = DEVICE_ISA | DEVICE_AT, - .local = CRYSTAL_CS4236B, - .init = cs423x_init, - .close = cs423x_close, - .reset = cs423x_reset, + .flags = DEVICE_ISA | DEVICE_AT, + .local = CRYSTAL_CS4236B, + .init = cs423x_init, + .close = cs423x_close, + .reset = cs423x_reset, { .available = NULL }, .speed_changed = cs423x_speed_changed, - .force_redraw = NULL, - .config = NULL + .force_redraw = NULL, + .config = NULL }; const device_t cs4237b_device = { - .name = "Crystal CS4237B", + .name = "Crystal CS4237B", .internal_name = "cs4237b", - .flags = DEVICE_ISA | DEVICE_AT, - .local = CRYSTAL_CS4237B, - .init = cs423x_init, - .close = cs423x_close, - .reset = cs423x_reset, + .flags = DEVICE_ISA | DEVICE_AT, + .local = CRYSTAL_CS4237B, + .init = cs423x_init, + .close = cs423x_close, + .reset = cs423x_reset, { .available = NULL }, .speed_changed = cs423x_speed_changed, - .force_redraw = NULL, - .config = NULL + .force_redraw = NULL, + .config = NULL }; const device_t cs4238b_device = { - .name = "Crystal CS4238B", + .name = "Crystal CS4238B", .internal_name = "cs4238b", - .flags = DEVICE_ISA | DEVICE_AT, - .local = CRYSTAL_CS4238B, - .init = cs423x_init, - .close = cs423x_close, - .reset = cs423x_reset, + .flags = DEVICE_ISA | DEVICE_AT, + .local = CRYSTAL_CS4238B, + .init = cs423x_init, + .close = cs423x_close, + .reset = cs423x_reset, { .available = NULL }, .speed_changed = cs423x_speed_changed, - .force_redraw = NULL, - .config = NULL + .force_redraw = NULL, + .config = NULL }; diff --git a/src/sound/snd_sb.c b/src/sound/snd_sb.c index 5f5aa5899..9d80ef65c 100644 --- a/src/sound/snd_sb.c +++ b/src/sound/snd_sb.c @@ -377,12 +377,12 @@ sb_get_buffer_sb16_awe32(int32_t *buffer, int len, void *p) : 0; if (mixer->output_filter) { - /* We divide by 3 to get the volume down to normal. */ - out_l += (low_fir_sb16(0, 0, (double) sb->dsp.buffer[c]) * mixer->voice_l) / 3.0; - out_r += (low_fir_sb16(0, 1, (double) sb->dsp.buffer[c + 1]) * mixer->voice_r) / 3.0; + /* We divide by 3 to get the volume down to normal. */ + out_l += (low_fir_sb16(0, 0, (double) sb->dsp.buffer[c]) * mixer->voice_l) / 3.0; + out_r += (low_fir_sb16(0, 1, (double) sb->dsp.buffer[c + 1]) * mixer->voice_r) / 3.0; } else { - out_l += (((double) sb->dsp.buffer[c]) * mixer->voice_l) / 3.0; - out_r += (((double) sb->dsp.buffer[c + 1]) * mixer->voice_r) / 3.0; + out_l += (((double) sb->dsp.buffer[c]) * mixer->voice_l) / 3.0; + out_r += (((double) sb->dsp.buffer[c + 1]) * mixer->voice_r) / 3.0; } out_l *= mixer->master_l; @@ -1764,10 +1764,10 @@ sb_16_init(const device_t *info) &sb->opl); } - sb->mixer_enabled = 1; + sb->mixer_enabled = 1; sb->mixer_sb16.output_filter = 1; - io_sethandler(addr + 4, 0x0002, sb_ct1745_mixer_read, NULL, NULL, - sb_ct1745_mixer_write, NULL, NULL, sb); + io_sethandler(addr + 4, 0x0002, sb_ct1745_mixer_read, NULL, NULL, + sb_ct1745_mixer_write, NULL, NULL, sb); sound_add_handler(sb_get_buffer_sb16_awe32, sb); sound_set_cd_audio_filter(sb16_awe32_filter_cd_audio, sb); @@ -1797,7 +1797,7 @@ sb_16_pnp_init(const device_t *info) sb_dsp_init(&sb->dsp, SB16, SB_SUBTYPE_DEFAULT, sb); sb_ct1745_mixer_reset(sb); - sb->mixer_enabled = 1; + sb->mixer_enabled = 1; sb->mixer_sb16.output_filter = 1; sound_add_handler(sb_get_buffer_sb16_awe32, sb); sound_set_cd_audio_filter(sb16_awe32_filter_cd_audio, sb); @@ -1841,7 +1841,6 @@ sb_16_compat_init(const device_t *info) return sb; } - static int sb_awe32_available() { @@ -1915,10 +1914,10 @@ sb_awe32_init(const device_t *info) &sb->opl); } - sb->mixer_enabled = 1; + sb->mixer_enabled = 1; sb->mixer_sb16.output_filter = 1; - io_sethandler(addr + 4, 0x0002, sb_ct1745_mixer_read, NULL, NULL, - sb_ct1745_mixer_write, NULL, NULL, sb); + io_sethandler(addr + 4, 0x0002, sb_ct1745_mixer_read, NULL, NULL, + sb_ct1745_mixer_write, NULL, NULL, sb); sound_add_handler(sb_get_buffer_sb16_awe32, sb); sound_set_cd_audio_filter(sb16_awe32_filter_cd_audio, sb); @@ -1952,7 +1951,7 @@ sb_awe32_pnp_init(const device_t *info) sb_dsp_init(&sb->dsp, ((info->local == 2) || (info->local == 3) || (info->local == 4)) ? SBAWE64 : SBAWE32, SB_SUBTYPE_DEFAULT, sb); sb_ct1745_mixer_reset(sb); - sb->mixer_enabled = 1; + sb->mixer_enabled = 1; sb->mixer_sb16.output_filter = 1; sound_add_handler(sb_get_buffer_sb16_awe32, sb); sound_set_cd_audio_filter(sb16_awe32_filter_cd_audio, sb); @@ -2425,255 +2424,253 @@ static const device_config_t sb_awe64_gold_config[] = { // clang-format on const device_t sb_1_device = { - .name = "Sound Blaster v1.0", + .name = "Sound Blaster v1.0", .internal_name = "sb", - .flags = DEVICE_ISA, - .local = 0, - .init = sb_1_init, - .close = sb_close, - .reset = NULL, + .flags = DEVICE_ISA, + .local = 0, + .init = sb_1_init, + .close = sb_close, + .reset = NULL, { .available = NULL }, .speed_changed = sb_speed_changed, - .force_redraw = NULL, - .config = sb_config + .force_redraw = NULL, + .config = sb_config }; const device_t sb_15_device = { - .name = "Sound Blaster v1.5", + .name = "Sound Blaster v1.5", .internal_name = "sb1.5", - .flags = DEVICE_ISA, - .local = 0, - .init = sb_15_init, - .close = sb_close, - .reset = NULL, + .flags = DEVICE_ISA, + .local = 0, + .init = sb_15_init, + .close = sb_close, + .reset = NULL, { .available = NULL }, .speed_changed = sb_speed_changed, - .force_redraw = NULL, - .config = sb15_config + .force_redraw = NULL, + .config = sb15_config }; const device_t sb_mcv_device = { - .name = "Sound Blaster MCV", + .name = "Sound Blaster MCV", .internal_name = "sbmcv", - .flags = DEVICE_MCA, - .local = 0, - .init = sb_mcv_init, - .close = sb_close, - .reset = NULL, + .flags = DEVICE_MCA, + .local = 0, + .init = sb_mcv_init, + .close = sb_close, + .reset = NULL, { .available = NULL }, .speed_changed = sb_speed_changed, - .force_redraw = NULL, - .config = sb_mcv_config + .force_redraw = NULL, + .config = sb_mcv_config }; const device_t sb_2_device = { - .name = "Sound Blaster v2.0", + .name = "Sound Blaster v2.0", .internal_name = "sb2.0", - .flags = DEVICE_ISA, - .local = 0, - .init = sb_2_init, - .close = sb_close, - .reset = NULL, + .flags = DEVICE_ISA, + .local = 0, + .init = sb_2_init, + .close = sb_close, + .reset = NULL, { .available = NULL }, .speed_changed = sb_speed_changed, - .force_redraw = NULL, - .config = sb2_config + .force_redraw = NULL, + .config = sb2_config }; const device_t sb_pro_v1_device = { - .name = "Sound Blaster Pro v1", + .name = "Sound Blaster Pro v1", .internal_name = "sbprov1", - .flags = DEVICE_ISA, - .local = 0, - .init = sb_pro_v1_init, - .close = sb_close, - .reset = NULL, + .flags = DEVICE_ISA, + .local = 0, + .init = sb_pro_v1_init, + .close = sb_close, + .reset = NULL, { .available = NULL }, .speed_changed = sb_speed_changed, - .force_redraw = NULL, - .config = sb_pro_config + .force_redraw = NULL, + .config = sb_pro_config }; const device_t sb_pro_v2_device = { - .name = "Sound Blaster Pro v2", + .name = "Sound Blaster Pro v2", .internal_name = "sbprov2", - .flags = DEVICE_ISA, - .local = 0, - .init = sb_pro_v2_init, - .close = sb_close, - .reset = NULL, + .flags = DEVICE_ISA, + .local = 0, + .init = sb_pro_v2_init, + .close = sb_close, + .reset = NULL, { .available = NULL }, .speed_changed = sb_speed_changed, - .force_redraw = NULL, - .config = sb_pro_config + .force_redraw = NULL, + .config = sb_pro_config }; const device_t sb_pro_mcv_device = { - .name = "Sound Blaster Pro MCV", + .name = "Sound Blaster Pro MCV", .internal_name = "sbpromcv", - .flags = DEVICE_MCA, - .local = 0, - .init = sb_pro_mcv_init, - .close = sb_close, - .reset = NULL, + .flags = DEVICE_MCA, + .local = 0, + .init = sb_pro_mcv_init, + .close = sb_close, + .reset = NULL, { .available = NULL }, .speed_changed = sb_speed_changed, - .force_redraw = NULL, - .config = NULL + .force_redraw = NULL, + .config = NULL }; const device_t sb_pro_compat_device = { - .name = "Sound Blaster Pro (Compatibility)", + .name = "Sound Blaster Pro (Compatibility)", .internal_name = "sbpro_compat", - .flags = DEVICE_ISA | DEVICE_AT, - .local = 0, - .init = sb_pro_compat_init, - .close = sb_close, - .reset = NULL, + .flags = DEVICE_ISA | DEVICE_AT, + .local = 0, + .init = sb_pro_compat_init, + .close = sb_close, + .reset = NULL, { .available = NULL }, .speed_changed = sb_speed_changed, - .force_redraw = NULL, - .config = NULL + .force_redraw = NULL, + .config = NULL }; const device_t sb_16_device = { - .name = "Sound Blaster 16", + .name = "Sound Blaster 16", .internal_name = "sb16", - .flags = DEVICE_ISA | DEVICE_AT, - .local = 0, - .init = sb_16_init, - .close = sb_close, - .reset = NULL, + .flags = DEVICE_ISA | DEVICE_AT, + .local = 0, + .init = sb_16_init, + .close = sb_close, + .reset = NULL, { .available = NULL }, .speed_changed = sb_speed_changed, - .force_redraw = NULL, - .config = sb_16_config + .force_redraw = NULL, + .config = sb_16_config }; const device_t sb_16_pnp_device = { - .name = "Sound Blaster 16 PnP", + .name = "Sound Blaster 16 PnP", .internal_name = "sb16_pnp", - .flags = DEVICE_ISA | DEVICE_AT, - .local = 0, - .init = sb_16_pnp_init, - .close = sb_close, - .reset = NULL, + .flags = DEVICE_ISA | DEVICE_AT, + .local = 0, + .init = sb_16_pnp_init, + .close = sb_close, + .reset = NULL, { .available = NULL }, .speed_changed = sb_speed_changed, - .force_redraw = NULL, - .config = sb_16_pnp_config + .force_redraw = NULL, + .config = sb_16_pnp_config }; -const device_t sb_16_compat_device = -{ - .name = "Sound Blaster 16 (Compatibility)", +const device_t sb_16_compat_device = { + .name = "Sound Blaster 16 (Compatibility)", .internal_name = "sb16_compat", - .flags = DEVICE_ISA | DEVICE_AT, - .local = 1, - .init = sb_16_compat_init, - .close = sb_close, - .reset = NULL, + .flags = DEVICE_ISA | DEVICE_AT, + .local = 1, + .init = sb_16_compat_init, + .close = sb_close, + .reset = NULL, { .available = NULL }, .speed_changed = sb_speed_changed, - .force_redraw = NULL, - .config = NULL + .force_redraw = NULL, + .config = NULL }; -const device_t sb_16_compat_nompu_device = -{ - .name = "Sound Blaster 16 (Compatibility - MPU-401 Off)", +const device_t sb_16_compat_nompu_device = { + .name = "Sound Blaster 16 (Compatibility - MPU-401 Off)", .internal_name = "sb16_compat", - .flags = DEVICE_ISA | DEVICE_AT, - .local = 0, - .init = sb_16_compat_init, - .close = sb_close, - .reset = NULL, + .flags = DEVICE_ISA | DEVICE_AT, + .local = 0, + .init = sb_16_compat_init, + .close = sb_close, + .reset = NULL, { .available = NULL }, - .speed_changed =sb_speed_changed, - .force_redraw = NULL, - .config = NULL + .speed_changed = sb_speed_changed, + .force_redraw = NULL, + .config = NULL }; const device_t sb_32_pnp_device = { - .name = "Sound Blaster 32 PnP", + .name = "Sound Blaster 32 PnP", .internal_name = "sb32_pnp", - .flags = DEVICE_ISA | DEVICE_AT, - .local = 0, - .init = sb_awe32_pnp_init, - .close = sb_awe32_close, - .reset = NULL, + .flags = DEVICE_ISA | DEVICE_AT, + .local = 0, + .init = sb_awe32_pnp_init, + .close = sb_awe32_close, + .reset = NULL, { .available = sb_32_pnp_available }, .speed_changed = sb_speed_changed, - .force_redraw = NULL, - .config = sb_32_pnp_config + .force_redraw = NULL, + .config = sb_32_pnp_config }; const device_t sb_awe32_device = { - .name = "Sound Blaster AWE32", + .name = "Sound Blaster AWE32", .internal_name = "sbawe32", - .flags = DEVICE_ISA | DEVICE_AT, - .local = 0, - .init = sb_awe32_init, - .close = sb_awe32_close, - .reset = NULL, + .flags = DEVICE_ISA | DEVICE_AT, + .local = 0, + .init = sb_awe32_init, + .close = sb_awe32_close, + .reset = NULL, { .available = sb_awe32_available }, .speed_changed = sb_speed_changed, - .force_redraw = NULL, - .config = sb_awe32_config + .force_redraw = NULL, + .config = sb_awe32_config }; const device_t sb_awe32_pnp_device = { - .name = "Sound Blaster AWE32 PnP", + .name = "Sound Blaster AWE32 PnP", .internal_name = "sbawe32_pnp", - .flags = DEVICE_ISA | DEVICE_AT, - .local = 1, - .init = sb_awe32_pnp_init, - .close = sb_awe32_close, - .reset = NULL, + .flags = DEVICE_ISA | DEVICE_AT, + .local = 1, + .init = sb_awe32_pnp_init, + .close = sb_awe32_close, + .reset = NULL, { .available = sb_awe32_pnp_available }, .speed_changed = sb_speed_changed, - .force_redraw = NULL, - .config = sb_awe32_pnp_config + .force_redraw = NULL, + .config = sb_awe32_pnp_config }; const device_t sb_awe64_value_device = { - .name = "Sound Blaster AWE64 Value", + .name = "Sound Blaster AWE64 Value", .internal_name = "sbawe64_value", - .flags = DEVICE_ISA | DEVICE_AT, - .local = 2, - .init = sb_awe32_pnp_init, - .close = sb_awe32_close, - .reset = NULL, + .flags = DEVICE_ISA | DEVICE_AT, + .local = 2, + .init = sb_awe32_pnp_init, + .close = sb_awe32_close, + .reset = NULL, { .available = sb_awe64_value_available }, .speed_changed = sb_speed_changed, - .force_redraw = NULL, - .config = sb_awe64_value_config + .force_redraw = NULL, + .config = sb_awe64_value_config }; const device_t sb_awe64_device = { - .name = "Sound Blaster AWE64", + .name = "Sound Blaster AWE64", .internal_name = "sbawe64", - .flags = DEVICE_ISA | DEVICE_AT, - .local = 3, - .init = sb_awe32_pnp_init, - .close = sb_awe32_close, - .reset = NULL, + .flags = DEVICE_ISA | DEVICE_AT, + .local = 3, + .init = sb_awe32_pnp_init, + .close = sb_awe32_close, + .reset = NULL, { .available = sb_awe64_available }, .speed_changed = sb_speed_changed, - .force_redraw = NULL, - .config = sb_awe64_config + .force_redraw = NULL, + .config = sb_awe64_config }; const device_t sb_awe64_gold_device = { - .name = "Sound Blaster AWE64 Gold", + .name = "Sound Blaster AWE64 Gold", .internal_name = "sbawe64_gold", - .flags = DEVICE_ISA | DEVICE_AT, - .local = 4, - .init = sb_awe32_pnp_init, - .close = sb_awe32_close, - .reset = NULL, + .flags = DEVICE_ISA | DEVICE_AT, + .local = 4, + .init = sb_awe32_pnp_init, + .close = sb_awe32_close, + .reset = NULL, { .available = sb_awe64_gold_available }, .speed_changed = sb_speed_changed, - .force_redraw = NULL, - .config = sb_awe64_gold_config + .force_redraw = NULL, + .config = sb_awe64_gold_config }; diff --git a/src/sound/snd_sb_dsp.c b/src/sound/snd_sb_dsp.c index 147a1c4e6..194beee41 100644 --- a/src/sound/snd_sb_dsp.c +++ b/src/sound/snd_sb_dsp.c @@ -174,9 +174,9 @@ sb_irq_update_pic(void *priv, int set) { sb_dsp_t *dsp = (sb_dsp_t *) priv; if (set) - picint(1 << dsp->sb_irqnum); + picint(1 << dsp->sb_irqnum); else - picintc(1 << dsp->sb_irqnum); + picintc(1 << dsp->sb_irqnum); } void