Merge branch 'master' into more-updates

This commit is contained in:
Jasmine Iwanek
2022-02-20 16:28:50 -05:00
8 changed files with 92 additions and 143 deletions

View File

@@ -9,7 +9,7 @@
All registers must have been written back or discarded. All registers must have been written back or discarded.
This should be used when calling external functions that may change any emulated This should be used when calling external functions that may change any emulated
registers.*/ registers.*/
#define UOP_TYPE_BARRIER (1 << 31) #define UOP_TYPE_BARRIER (1u << 31)
/*uOP is a barrier. All previous uOPs must have completed before this one executes. /*uOP is a barrier. All previous uOPs must have completed before this one executes.
All registers must have been written back, but do not have to be discarded. All registers must have been written back, but do not have to be discarded.

View File

@@ -106,9 +106,6 @@ extern netdev_t network_devs[32];
/* Function prototypes. */ /* Function prototypes. */
extern void network_wait(uint8_t wait); extern void network_wait(uint8_t wait);
extern void network_poll(void);
extern void network_busy(uint8_t set);
extern void network_end(void);
extern void network_init(void); extern void network_init(void);
extern void network_attach(void *, uint8_t *, NETRXCB, NETWAITCB, NETSETLINKSTATE); extern void network_attach(void *, uint8_t *, NETRXCB, NETWAITCB, NETSETLINKSTATE);
@@ -116,7 +113,6 @@ extern void network_close(void);
extern void network_reset(void); extern void network_reset(void);
extern int network_available(void); extern int network_available(void);
extern void network_tx(uint8_t *, int); extern void network_tx(uint8_t *, int);
extern void network_do_tx(void);
extern int network_tx_queue_check(void); extern int network_tx_queue_check(void);
extern int net_pcap_prepare(netdev_t *); extern int net_pcap_prepare(netdev_t *);

View File

@@ -180,11 +180,6 @@ poll_thread(void *arg)
/* Request ownership of the device. */ /* Request ownership of the device. */
network_wait(1); network_wait(1);
#if 0
/* Wait for a poll request. */
network_poll();
#endif
if (pcap == NULL) { if (pcap == NULL) {
network_wait(0); network_wait(0);
break; break;
@@ -211,12 +206,9 @@ poll_thread(void *arg)
} }
} }
/* Wait for the next packet to arrive. */ /* Wait for the next packet to arrive - network_do_tx() is called from there. */
tx = network_tx_queue_check(); tx = network_tx_queue_check();
if (tx)
network_do_tx();
/* Release ownership of the device. */ /* Release ownership of the device. */
network_wait(0); network_wait(0);
@@ -346,8 +338,6 @@ net_pcap_close(void)
/* Tell the thread to terminate. */ /* Tell the thread to terminate. */
if (poll_tid != NULL) { if (poll_tid != NULL) {
network_busy(0);
/* Wait for the thread to finish. */ /* Wait for the thread to finish. */
pcap_log("PCAP: waiting for thread to end...\n"); pcap_log("PCAP: waiting for thread to end...\n");
thread_wait_event(poll_state, -1); thread_wait_event(poll_state, -1);

View File

@@ -362,11 +362,6 @@ poll_thread(void *arg)
/* Request ownership of the queue. */ /* Request ownership of the queue. */
network_wait(1); network_wait(1);
#if 0
/* Wait for a poll request. */
network_poll();
#endif
/* Stop processing if asked to. */ /* Stop processing if asked to. */
if (slirp->stop) { if (slirp->stop) {
network_wait(0); network_wait(0);
@@ -376,12 +371,9 @@ poll_thread(void *arg)
/* See if there is any work. */ /* See if there is any work. */
slirp_tic(slirp); slirp_tic(slirp);
/* Wait for the next packet to arrive. */ /* Wait for the next packet to arrive - network_do_tx() is called from there. */
tx = network_tx_queue_check(); tx = network_tx_queue_check();
if (tx)
network_do_tx();
/* Release ownership of the queue. */ /* Release ownership of the queue. */
network_wait(0); network_wait(0);
@@ -454,8 +446,6 @@ net_slirp_close(void)
/* Tell the thread to terminate. */ /* Tell the thread to terminate. */
if (slirp->poll_tid) { if (slirp->poll_tid) {
network_busy(0);
/* Wait for the thread to finish. */ /* Wait for the thread to finish. */
slirp_log("SLiRP: waiting for thread to end...\n"); slirp_log("SLiRP: waiting for thread to end...\n");
thread_wait_event(slirp->poll_state, -1); thread_wait_event(slirp->poll_state, -1);

View File

@@ -120,18 +120,9 @@ static mutex_t *network_mutex;
static uint8_t *network_mac; static uint8_t *network_mac;
static uint8_t network_timer_active = 0; static uint8_t network_timer_active = 0;
static pc_timer_t network_rx_queue_timer; static pc_timer_t network_rx_queue_timer;
static netpkt_t *first_pkt[2] = { NULL, NULL }, static netpkt_t *first_pkt[3] = { NULL, NULL, NULL },
*last_pkt[2] = { NULL, NULL }; *last_pkt[3] = { NULL, NULL, NULL };
static netpkt_t queued_pkt;
static struct {
volatile int busy,
queue_in_use;
event_t *wake_poll_thread,
*poll_complete,
*queue_not_in_use;
} poll_data;
#ifdef ENABLE_NETWORK_LOG #ifdef ENABLE_NETWORK_LOG
@@ -201,37 +192,6 @@ network_wait(uint8_t wait)
} }
void
network_poll(void)
{
network_wait(0);
while (poll_data.busy)
thread_wait_event(poll_data.wake_poll_thread, -1);
network_wait(1);
thread_reset_event(poll_data.wake_poll_thread);
}
void
network_busy(uint8_t set)
{
poll_data.busy = !!set;
if (! set)
thread_set_event(poll_data.wake_poll_thread);
}
void
network_end(void)
{
thread_set_event(poll_data.poll_complete);
}
/* /*
* Initialize the configured network cards. * Initialize the configured network cards.
* *
@@ -284,8 +244,7 @@ network_queue_put(int tx, void *priv, uint8_t *data, int len)
{ {
netpkt_t *temp; netpkt_t *temp;
temp = (netpkt_t *) malloc(sizeof(netpkt_t)); temp = (netpkt_t *) calloc(sizeof(netpkt_t), 1);
memset(temp, 0, sizeof(netpkt_t));
temp->priv = priv; temp->priv = priv;
memcpy(temp->data, data, len); memcpy(temp->data, data, len);
temp->len = len; temp->len = len;
@@ -302,17 +261,29 @@ network_queue_put(int tx, void *priv, uint8_t *data, int len)
static void static void
network_queue_get(int tx, netpkt_t **pkt) network_queue_get(int tx, netpkt_t *pkt)
{ {
netpkt_t *temp;
temp = first_pkt[tx];
if (temp == NULL) {
memset(pkt, 0x00, sizeof(netpkt_t));
return;
}
memcpy(pkt, temp, sizeof(netpkt_t));
first_pkt[tx] = temp->next;
free(temp);
if (first_pkt[tx] == NULL) if (first_pkt[tx] == NULL)
*pkt = NULL; last_pkt[tx] = NULL;
else
*pkt = first_pkt[tx];
} }
static void static void
network_queue_advance(int tx) network_queue_transmit(int tx)
{ {
netpkt_t *temp; netpkt_t *temp;
@@ -321,6 +292,20 @@ network_queue_advance(int tx)
if (temp == NULL) if (temp == NULL)
return; return;
if (temp->len > 0) {
network_dump_packet(temp);
/* Why on earth is this not a function pointer?! */
switch(network_type) {
case NET_TYPE_PCAP:
net_pcap_in(temp->data, temp->len);
break;
case NET_TYPE_SLIRP:
net_slirp_in(temp->data, temp->len);
break;
}
}
first_pkt[tx] = temp->next; first_pkt[tx] = temp->next;
free(temp); free(temp);
@@ -329,6 +314,38 @@ network_queue_advance(int tx)
} }
static void
network_queue_copy(int dest, int src)
{
netpkt_t *temp, *temp2;
temp = first_pkt[src];
if (temp == NULL)
return;
temp2 = (netpkt_t *) calloc(sizeof(netpkt_t), 1);
temp2->priv = temp->priv;
memcpy(temp2->data, temp->data, temp->len);
temp2->len = temp->len;
temp2->prev = last_pkt[dest];
temp2->next = NULL;
if (last_pkt[dest] != NULL)
last_pkt[dest]->next = temp2;
last_pkt[dest] = temp2;
if (first_pkt[dest] == NULL)
first_pkt[dest] = temp2;
first_pkt[src] = temp->next;
free(temp);
if (first_pkt[src] == NULL)
last_pkt[src] = NULL;
}
static void static void
network_queue_clear(int tx) network_queue_clear(int tx)
{ {
@@ -352,29 +369,23 @@ network_rx_queue(void *priv)
{ {
int ret = 1; int ret = 1;
netpkt_t *pkt = NULL;
if (network_rx_pause || !thread_test_mutex(network_mutex)) { if (network_rx_pause || !thread_test_mutex(network_mutex)) {
timer_on_auto(&network_rx_queue_timer, 0.762939453125 * 2.0 * 128.0); timer_on_auto(&network_rx_queue_timer, 0.762939453125 * 2.0 * 128.0);
return; return;
} }
network_busy(1); if (queued_pkt.len == 0)
network_queue_get(0, &queued_pkt);
network_queue_get(0, &pkt); if (queued_pkt.len > 0) {
if ((pkt != NULL) && (pkt->len > 0)) { network_dump_packet(&queued_pkt);
network_dump_packet(pkt); ret = net_cards[network_card].rx(queued_pkt.priv, queued_pkt.data, queued_pkt.len);
ret = net_cards[network_card].rx(pkt->priv, pkt->data, pkt->len); }
if (pkt->len >= 128) timer_on_auto(&network_rx_queue_timer, 0.762939453125 * 2.0 * ((queued_pkt.len >= 128) ? ((double) queued_pkt.len) : 128.0));
timer_on_auto(&network_rx_queue_timer, 0.762939453125 * 2.0 * ((double) pkt->len));
else
timer_on_auto(&network_rx_queue_timer, 0.762939453125 * 2.0 * 128.0);
} else
timer_on_auto(&network_rx_queue_timer, 0.762939453125 * 2.0 * 128.0);
if (ret) if (ret)
network_queue_advance(0); queued_pkt.len = 0;
network_busy(0); /* Transmission. */
network_queue_copy(1, 2);
network_wait(0); network_wait(0);
} }
@@ -401,10 +412,6 @@ network_attach(void *dev, uint8_t *mac, NETRXCB rx, NETWAITCB wait, NETSETLINKST
network_set_wait(0); network_set_wait(0);
/* Create the network events. */
poll_data.poll_complete = thread_create_event();
poll_data.wake_poll_thread = thread_create_event();
/* Activate the platform module. */ /* Activate the platform module. */
switch(network_type) { switch(network_type) {
case NET_TYPE_PCAP: case NET_TYPE_PCAP:
@@ -416,8 +423,9 @@ network_attach(void *dev, uint8_t *mac, NETRXCB rx, NETWAITCB wait, NETSETLINKST
break; break;
} }
first_pkt[0] = first_pkt[1] = NULL; first_pkt[0] = first_pkt[1] = first_pkt[2] = NULL;
last_pkt[0] = last_pkt[1] = NULL; last_pkt[0] = last_pkt[1] = last_pkt[2] = NULL;
memset(&queued_pkt, 0x00, sizeof(netpkt_t));
memset(&network_rx_queue_timer, 0x00, sizeof(pc_timer_t)); memset(&network_rx_queue_timer, 0x00, sizeof(pc_timer_t));
timer_add(&network_rx_queue_timer, network_rx_queue, NULL, 0); timer_add(&network_rx_queue_timer, network_rx_queue, NULL, 0);
/* 10 mbps. */ /* 10 mbps. */
@@ -453,16 +461,6 @@ network_close(void)
/* Force-close the SLIRP module. */ /* Force-close the SLIRP module. */
net_slirp_close(); net_slirp_close();
/* Close the network events. */
if (poll_data.wake_poll_thread != NULL) {
thread_destroy_event(poll_data.wake_poll_thread);
poll_data.wake_poll_thread = NULL;
}
if (poll_data.poll_complete != NULL) {
thread_destroy_event(poll_data.poll_complete);
poll_data.poll_complete = NULL;
}
/* Close the network thread mutex. */ /* Close the network thread mutex. */
thread_close_mutex(network_mutex); thread_close_mutex(network_mutex);
network_mutex = NULL; network_mutex = NULL;
@@ -551,50 +549,25 @@ network_reset(void)
void void
network_tx(uint8_t *bufp, int len) network_tx(uint8_t *bufp, int len)
{ {
network_busy(1);
ui_sb_update_icon(SB_NETWORK, 1); ui_sb_update_icon(SB_NETWORK, 1);
network_queue_put(1, NULL, bufp, len); network_queue_put(2, NULL, bufp, len);
ui_sb_update_icon(SB_NETWORK, 0); ui_sb_update_icon(SB_NETWORK, 0);
network_busy(0);
} }
/* Actually transmit the packet. */ /* Actually transmit the packet. */
void
network_do_tx(void)
{
netpkt_t *pkt = NULL;
if (network_tx_pause)
return;
network_queue_get(1, &pkt);
if ((pkt != NULL) && (pkt->len > 0)) {
network_dump_packet(pkt);
switch(network_type) {
case NET_TYPE_PCAP:
net_pcap_in(pkt->data, pkt->len);
break;
case NET_TYPE_SLIRP:
net_slirp_in(pkt->data, pkt->len);
break;
}
}
network_queue_advance(1);
}
int int
network_tx_queue_check(void) network_tx_queue_check(void)
{ {
if ((first_pkt[1] == NULL) && (last_pkt[1] == NULL)) if ((first_pkt[1] == NULL) && (last_pkt[1] == NULL))
return 0; return 0;
if (network_tx_pause)
return 1;
network_queue_transmit(1);
return 1; return 1;
} }

View File

@@ -222,7 +222,7 @@ find_best_interrupt(pic_t *dev)
if (dev == &pic2) if (dev == &pic2)
intr += 8; intr += 8;
if (cpu_fast_off_flags & (1 << intr)) if (cpu_fast_off_flags & (1u << intr))
cpu_fast_off_count = cpu_fast_off_val + 1; cpu_fast_off_count = cpu_fast_off_val + 1;
} }

View File

@@ -114,7 +114,7 @@ main_thread_fn()
} }
} else { } else {
/* Just so we dont overload the host OS. */ /* Just so we dont overload the host OS. */
if (drawits < -1) if (drawits < -1 || dopause)
std::this_thread::sleep_for(std::chrono::milliseconds(1)); std::this_thread::sleep_for(std::chrono::milliseconds(1));
else else
std::this_thread::yield(); std::this_thread::yield();

View File

@@ -936,11 +936,11 @@ svga_init(const device_t *info, svga_t *svga, void *p, int memsize,
svga->dispontime = 1000ull << 32; svga->dispontime = 1000ull << 32;
svga->dispofftime = 1000ull << 32; svga->dispofftime = 1000ull << 32;
svga->bpp = 8; svga->bpp = 8;
svga->vram = malloc(memsize); svga->vram = calloc(memsize, 1);
svga->vram_max = memsize; svga->vram_max = memsize;
svga->vram_display_mask = svga->vram_mask = memsize - 1; svga->vram_display_mask = svga->vram_mask = memsize - 1;
svga->decode_mask = 0x7fffff; svga->decode_mask = 0x7fffff;
svga->changedvram = malloc(memsize >> 12); svga->changedvram = calloc(memsize >> 12, 1);
svga->recalctimings_ex = recalctimings_ex; svga->recalctimings_ex = recalctimings_ex;
svga->video_in = video_in; svga->video_in = video_in;
svga->video_out = video_out; svga->video_out = video_out;