Merge pull request #3526 from jriwanek-forks/4.1-sonar

Fix 4.1 build issues and do some linting
This commit is contained in:
Miran Grča
2023-08-08 16:18:20 +02:00
committed by GitHub
8 changed files with 1056 additions and 1007 deletions

View File

@@ -1,8 +1,7 @@
struct nmc93cxx_eeprom_t;
typedef struct nmc93cxx_eeprom_t nmc93cxx_eeprom_t;
typedef struct nmc93cxx_eeprom_params_t
{
typedef struct nmc93cxx_eeprom_params_t {
uint16_t nwords;
char *filename;
uint16_t *default_content;

View File

@@ -16,7 +16,6 @@
/* Ported over from QEMU */
#include <stdint.h>
#include <stdlib.h>
#include <stdio.h>
@@ -28,6 +27,7 @@
#include <86box/timer.h>
#include <86box/nvr.h>
#include <86box/net_eeprom_nmc93cxx.h>
#include <86box/plat_unused.h>
struct nmc93cxx_eeprom_t {
uint8_t tick;
@@ -71,7 +71,7 @@ static const char *opstring[] = {
};
static void *
nmc93cxx_eeprom_init_params(const device_t *info, void* params)
nmc93cxx_eeprom_init_params(UNUSED(const device_t *info), void *params)
{
uint16_t nwords = 64;
uint8_t addrbits = 6;
@@ -105,25 +105,24 @@ nmc93cxx_eeprom_init_params(const device_t *info, void* params)
/* Output DO is tristate, read results in 1. */
eeprom->eedo = 1;
if (params_details->filename)
{
FILE* file = nvr_fopen(params_details->filename, "rb");
if (params_details->filename) {
FILE *fp = nvr_fopen(params_details->filename, "rb");
strncpy(eeprom->filename, params_details->filename, 1024);
if (file) {
filldefault = !fread(eeprom->contents, sizeof(uint16_t), nwords, file);
fclose(file);
if (fp) {
filldefault = !fread(eeprom->contents, sizeof(uint16_t), nwords, fp);
fclose(fp);
}
}
if (filldefault)
{
if (filldefault) {
memcpy(eeprom->contents, params_details->default_content, nwords * sizeof(uint16_t));
}
return eeprom;
}
void nmc93cxx_eeprom_write(nmc93cxx_eeprom_t *eeprom, int eecs, int eesk, int eedi)
void
nmc93cxx_eeprom_write(nmc93cxx_eeprom_t *eeprom, int eecs, int eesk, int eedi)
{
uint8_t tick = eeprom->tick;
uint8_t eedo = eeprom->eedo;
@@ -175,7 +174,9 @@ void nmc93cxx_eeprom_write(nmc93cxx_eeprom_t *eeprom, int eecs, int eesk, int ee
} else {
nmc93cxx_eeprom_log(1, "wrong 1st start bit (is 1, should be 0)\n");
tick = 2;
//~ assert(!"wrong start bit");
#if 0
~ assert(!"wrong start bit");
#endif
}
} else if (tick == 1) {
/* Wait for 2nd start bit. */
@@ -220,6 +221,9 @@ void nmc93cxx_eeprom_write(nmc93cxx_eeprom_t *eeprom, int eecs, int eesk, int ee
nmc93cxx_eeprom_log(1, "write enable command\n");
eeprom->writable = 1;
break;
default:
break;
}
} else {
/* Read, write or erase word. */
@@ -248,27 +252,27 @@ void nmc93cxx_eeprom_write(nmc93cxx_eeprom_t *eeprom, int eecs, int eesk, int ee
eeprom->command = command;
}
uint16_t nmc93cxx_eeprom_read(nmc93cxx_eeprom_t *eeprom)
uint16_t
nmc93cxx_eeprom_read(nmc93cxx_eeprom_t *eeprom)
{
/* Return status of pin DO (0 or 1). */
return eeprom->eedo;
}
static void
nmc93cxx_eeprom_close(void *priv)
{
nmc93cxx_eeprom_t *eeprom = (nmc93cxx_eeprom_t *) priv;
FILE* file = nvr_fopen(eeprom->filename, "wb");
if (file)
{
fwrite(eeprom->contents, 2, eeprom->size, file);
FILE *fp = nvr_fopen(eeprom->filename, "wb");
if (fp) {
fwrite(eeprom->contents, 2, eeprom->size, fp);
fclose(fp);
}
fclose(file);
free(priv);
}
uint16_t *nmc93cxx_eeprom_data(nmc93cxx_eeprom_t *eeprom)
uint16_t *
nmc93cxx_eeprom_data(nmc93cxx_eeprom_t *eeprom)
{
/* Get EEPROM data array. */
return &eeprom->contents[0];

View File

@@ -17,8 +17,7 @@
uint16_t
l80225_mii_readw(uint16_t *regs, uint16_t addr)
{
switch (addr)
{
switch (addr) {
case 0x1:
return 0x782D;
case 0x2:

File diff suppressed because it is too large Load Diff

View File

@@ -32,6 +32,7 @@
#include <86box/net_eeprom_nmc93cxx.h>
#include <86box/net_tulip.h>
#include <86box/bswap.h>
#include <86box/plat_unused.h>
#define CSR(_x) ((_x) << 3)
@@ -297,7 +298,8 @@ struct TULIPState {
uint8_t pci_slot;
uint8_t irq_state;
const device_t *device_info;
uint16_t subsys_id, subsys_ven_id;
uint16_t subsys_id;
uint16_t subsys_ven_id;
mem_mapping_t memory;
netcard_t *nic;
nmc93cxx_eeprom_t *eeprom;
@@ -437,9 +439,8 @@ tulip_filter_address(TULIPState *s, const uint8_t *addr)
{
static const char broadcast[] = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff };
bool ret = false;
int i;
for (i = 0; i < 16 && ret == false; i++) {
for (uint8_t i = 0; i < 16 && ret == false; i++) {
if (!memcmp(&s->filter[i], addr, ETH_ALEN)) {
ret = true;
}
@@ -468,10 +469,10 @@ tulip_filter_address(TULIPState *s, const uint8_t *addr)
}
static int
tulip_receive(void *p, uint8_t *buf, int size)
tulip_receive(void *priv, uint8_t *buf, int size)
{
struct tulip_descriptor desc;
TULIPState *s = (TULIPState *) p;
TULIPState *s = (TULIPState *) priv;
if (size < 14 || size > sizeof(s->rx_frame) - 4
|| s->rx_frame_len || tulip_rx_stopped(s)) {
@@ -748,7 +749,9 @@ tulip_mii(TULIPState *s)
{
uint32_t changed = s->old_csr9 ^ s->csr[9];
uint16_t data;
int op, phy, reg;
int op;
int phy;
int reg;
if (!(changed & CSR9_MDC)) {
return;
@@ -910,11 +913,10 @@ tulip_setup_frame(TULIPState *s,
{
uint8_t buf[4096];
int len = (desc->control >> TDES1_BUF1_SIZE_SHIFT) & TDES1_BUF1_SIZE_MASK;
int i;
if (len == 192) {
dma_bm_read(desc->buf_addr1, buf, len, 1);
for (i = 0; i < 16; i++) {
for (uint8_t i = 0; i < 16; i++) {
tulip_setup_filter_addr(s, buf, i);
}
}
@@ -951,14 +953,13 @@ static void
tulip_xmit_list_update(TULIPState *s)
{
#define TULIP_DESC_MAX 128
uint8_t i = 0;
struct tulip_descriptor desc;
if (tulip_ts(s) != CSR5_TS_SUSPENDED) {
return;
}
for (i = 0; i < TULIP_DESC_MAX; i++) {
for (uint8_t i = 0; i < TULIP_DESC_MAX; i++) {
tulip_desc_read(s, s->current_tx_desc, &desc);
if (!(desc.status & TDES0_OWN)) {
@@ -987,7 +988,7 @@ tulip_xmit_list_update(TULIPState *s)
}
static void
tulip_csr9_write(TULIPState *s, uint32_t old_val,
tulip_csr9_write(TULIPState *s, UNUSED(uint32_t old_val),
uint32_t new_val)
{
if (new_val & CSR9_SR) {
@@ -1002,7 +1003,7 @@ static void
tulip_reset(void *priv)
{
TULIPState *s = (TULIPState *) priv;
uint16_t *eeprom_data = nmc93cxx_eeprom_data(s->eeprom);
const uint16_t *eeprom_data = nmc93cxx_eeprom_data(s->eeprom);
s->csr[0] = 0xfe000000;
s->csr[1] = 0xffffffff;
s->csr[2] = 0xffffffff;
@@ -1142,14 +1143,13 @@ tulip_read_io(uint16_t addr, void *opaque)
static void
tulip_idblock_crc(uint16_t *srom)
{
int word;
int bit;
unsigned char bitval, crc;
unsigned char bitval;
unsigned char crc;
const int len = 9;
crc = -1;
for (word = 0; word < len; word++) {
for (bit = 15; bit >= 0; bit--) {
for (int word = 0; word < len; word++) {
for (int8_t bit = 15; bit >= 0; bit--) {
if ((word == (len - 1)) && (bit == 7)) {
/*
* Insert the correct CRC result into input data stream
@@ -1174,9 +1174,10 @@ tulip_srom_crc(uint8_t *eeprom, size_t len)
unsigned long crc = 0xffffffff;
unsigned long flippedcrc = 0;
unsigned char currentbyte;
unsigned int msb, bit, i;
unsigned int msb;
unsigned int bit;
for (i = 0; i < len; i++) {
for (size_t i = 0; i < len; i++) {
currentbyte = eeprom[i];
for (bit = 0; bit < 8; bit++) {
msb = (crc >> 31) & 1;
@@ -1189,7 +1190,7 @@ tulip_srom_crc(uint8_t *eeprom, size_t len)
}
}
for (i = 0; i < 32; i++) {
for (uint8_t i = 0; i < 32; i++) {
flippedcrc <<= 1;
bit = crc & 1;
crc >>= 1;
@@ -1471,9 +1472,9 @@ tulip_fill_eeprom(TULIPState *s)
}
static uint8_t
tulip_pci_read(int func, int addr, void *p)
tulip_pci_read(UNUSED(int func), int addr, void *priv)
{
TULIPState *s = (TULIPState *) p;
const TULIPState *s = (TULIPState *) priv;
switch (addr) {
default:
@@ -1518,17 +1519,23 @@ tulip_pci_read(int func, int addr, void *p)
}
static void
tulip_pci_write(int func, int addr, uint8_t val, void *p)
tulip_pci_write(UNUSED(int func), int addr, uint8_t val, void *priv)
{
TULIPState *s = (TULIPState *) p;
TULIPState *s = (TULIPState *) priv;
switch (addr) {
case 0x4:
mem_mapping_disable(&s->memory);
io_removehandler((s->pci_conf[0x10] & 0x80) | (s->pci_conf[0x11] << 8), 128, NULL, NULL, tulip_read_io, NULL, NULL, tulip_write_io, p);
io_removehandler((s->pci_conf[0x10] & 0x80) | (s->pci_conf[0x11] << 8), 128,
NULL, NULL, tulip_read_io,
NULL, NULL, tulip_write_io,
priv);
s->pci_conf[addr & 0xFF] = val;
if (val & PCI_COMMAND_IO)
io_sethandler((s->pci_conf[0x10] & 0x80) | (s->pci_conf[0x11] << 8), 128, NULL, NULL, tulip_read_io, NULL, NULL, tulip_write_io, p);
io_sethandler((s->pci_conf[0x10] & 0x80) | (s->pci_conf[0x11] << 8), 128,
NULL, NULL, tulip_read_io,
NULL, NULL, tulip_write_io,
priv);
if ((val & PCI_COMMAND_MEM) && s->memory.size)
mem_mapping_enable(&s->memory);
break;
@@ -1537,10 +1544,16 @@ tulip_pci_write(int func, int addr, uint8_t val, void *p)
break;
case 0x10:
case 0x11:
io_removehandler((s->pci_conf[0x10] & 0x80) | (s->pci_conf[0x11] << 8), 128, NULL, NULL, tulip_read_io, NULL, NULL, tulip_write_io, p);
io_removehandler((s->pci_conf[0x10] & 0x80) | (s->pci_conf[0x11] << 8), 128,
NULL, NULL, tulip_read_io,
NULL, NULL, tulip_write_io,
priv);
s->pci_conf[addr & 0xFF] = val;
if (s->pci_conf[0x4] & PCI_COMMAND_IO)
io_sethandler((s->pci_conf[0x10] & 0x80) | (s->pci_conf[0x11] << 8), 128, NULL, NULL, tulip_read_io, NULL, NULL, tulip_write_io, p);
io_sethandler((s->pci_conf[0x10] & 0x80) | (s->pci_conf[0x11] << 8), 128,
NULL, NULL, tulip_read_io,
NULL, NULL, tulip_write_io,
priv);
break;
case 0x14:
case 0x15:
@@ -1570,7 +1583,7 @@ nic_init(const device_t *info)
s->device_info = info;
memcpy(eeprom_default_local, s->device_info->local ? eeprom_default_24110 : eeprom_default, sizeof(eeprom_default));
tulip_idblock_crc((uint16_t *) eeprom_default_local);
(((uint16_t *) eeprom_default_local))[63] = (tulip_srom_crc((uint8_t *) eeprom_default_local, 126));
((uint16_t *) eeprom_default_local)[63] = (tulip_srom_crc((uint8_t *) eeprom_default_local, 126));
params.nwords = 64;
params.default_content = (uint16_t *) eeprom_default_local;

View File

@@ -687,9 +687,10 @@ NETOBJ := network.o \
net_pcnet.o net_wd8003.o \
net_plip.o net_event.o \
net_null.o \
net_eeprom_nmc93cxx.c \
net_tulip.c \
net_rtl8139.c
net_eeprom_nmc93cxx.o \
net_tulip.o \
net_rtl8139.o \
net_l80225.o
PRINTOBJ := png.o prt_cpmap.o \
prt_escp.o prt_text.o prt_ps.o