Skip to content

Commit efec8c2

Browse files
various language stability tweaks
1 parent ae976df commit efec8c2

File tree

8 files changed

+120
-108
lines changed

8 files changed

+120
-108
lines changed

include/ubasic.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -206,6 +206,9 @@ typedef struct ubasic_ctx {
206206
uint64_t gosub_stack[MAX_CALL_STACK_DEPTH];
207207
uint64_t gosub_stack_ptr;
208208

209+
uint64_t repeat_stack[MAX_LOOP_STACK_DEPTH];
210+
uint64_t repeat_stack_ptr;
211+
209212
int oldlen;
210213
int64_t eval_linenum;
211214

os/programs/irc.rrbasic

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -132,16 +132,14 @@ DEF PROCpartCommand(channel$)
132132
PROCsend("PART " + c$)
133133
RETPROC
134134

135-
DEF PROCmessageCommand(cam$)
136-
channelAndMessage$ = cam$
135+
DEF PROCmessageCommand(channelAndMessage$)
137136
msgSpace = INSTR(channelAndMessage$, " ")
138137
msgChannel$ = LEFT$(channelAndMessage$, msgSpace - 1)
139138
msgText$ = MID$(channelAndMessage$, msgSpace, LEN(channelAndMessage$))
140139
PROCsend("PRIVMSG " + msgChannel$ + " :" + msgText$)
141140
RETPROC
142141

143-
DEF PROCnoticeCommand(cams$)
144-
channelAndMessage$ = cam$
142+
DEF PROCnoticeCommand(channelAndMessage$)
145143
msgSpace = INSTR(channelAndMessage$, " ")
146144
msgChannel$ = LEFT$(channelAndMessage$, msgSpace - 1)
147145
msgText$ = MID$(channelAndMessage$, msgSpace, LEN(channelAndMessage$))
@@ -268,11 +266,10 @@ RETPROC
268266

269267
DEF PROCout(col, text$)
270268
safeText$ = text$
271-
safeCol = col
272269
REPEAT
273270
scrollback$(scrollptr) = LEFT$(safeText$, TERMWIDTH - 1)
274271
safeText$ = MID$(safeText$, TERMWIDTH - 1, LEN(safeText$))
275-
lineColour(scrollptr) = safeCol
272+
lineColour(scrollptr) = col
276273
scrollptr = scrollptr + 1
277274
top = top + 1
278275
IF scrollptr > SCROLLBACK - 1 THEN PROCdiscard

src/ip.c

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -235,7 +235,6 @@ void ip_send_packet(uint8_t* dst_ip, void* data, uint16_t len, uint8_t protocol)
235235
arp_send_packet(zero_hardware_addr, dst_ip);
236236
return;
237237
}
238-
dprintf("IP: Ethernet send\n");
239238
ethernet_send_packet(dst_hardware_addr, (uint8_t*)packet, htons(packet->length), ETHERNET_TYPE_IP);
240239
// Remember to free the packet!
241240
kfree(packet);
@@ -316,12 +315,10 @@ uint64_t ip_frag_hash(const void *item, uint64_t seed0, uint64_t seed1) {
316315
* @param n_len Packet length
317316
*/
318317
void ip_handle_packet(ip_packet_t* packet, [[maybe_unused]] int n_len) {
319-
dprintf("ip_handle_packet\n");
320318
char src_ip[20];
321319
*((uint8_t*)(&packet->version_ihl_ptr)) = ntohb(*((uint8_t*)(&packet->version_ihl_ptr)), 4);
322320
*((uint8_t*)(packet->flags_fragment_ptr)) = ntohb(*((uint8_t*)(packet->flags_fragment_ptr)), 3);
323321
if (packet->version == IP_IPV4) {
324-
dprintf("IPv4 packet\n");
325322
get_ip_str(src_ip, packet->src_ip);
326323
void * data_ptr = (void*)packet + packet->ihl * 4;
327324
size_t data_len = ntohs(packet->length) - (packet->ihl * 4);
@@ -340,7 +337,6 @@ void ip_handle_packet(ip_packet_t* packet, [[maybe_unused]] int n_len) {
340337
*/
341338
uint16_t frag_offset = ((uint16_t)packet->frag.fragment_offset_low | ((uint16_t)packet->frag.fragment_offset_high << 8));
342339
if (!packet->frag.dont_fragment) {
343-
dprintf("Packet can be fragmented\n");
344340
if (packet->frag.more_fragments_follow) {
345341
dprintf("Fragment is one of set (MF)\n");
346342
/* Packet is part of a fragmented set */
@@ -420,18 +416,14 @@ void ip_handle_packet(ip_packet_t* packet, [[maybe_unused]] int n_len) {
420416
}
421417

422418
if (packet->protocol == PROTOCOL_ICMP) {
423-
dprintf("Passing to ICMP handler\n");
424419
icmp_handle_packet(packet, data_ptr, data_len);
425420
} else if (packet->protocol == PROTOCOL_UDP) {
426-
dprintf("Passing to UDP handler\n");
427421
udp_handle_packet(packet, data_ptr, data_len);
428422
} else if (packet->protocol == PROTOCOL_TCP) {
429-
dprintf("Passing to TCP handler\n");
430423
tcp_handle_packet(packet, data_ptr, data_len);
431424
}
432425

433426
if (fragment_to_free) {
434-
dprintf("Freeing fragment\n");
435427
kfree(data_ptr);
436428
}
437429
} else {

src/rtl8139.c

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -39,14 +39,12 @@ static uint32_t rtl_inl(uint32_t io) {
3939
bool packet_is_ok(uint16_t* packet)
4040
{
4141
uint8_t flags = *((uint8_t*)packet);
42-
dump_hex((unsigned char*)packet, 4);
4342
bool bad = (flags & (RX_RUNT | RX_LONG | RX_CRC | RX_FAE));
4443
if (!bad && (flags & RX_ROK)) {
4544
if (*(packet + 1) > 8192 || *(packet + 1) < 20) {
4645
dprintf("Bad packet, out of size range\n");
4746
return false;
4847
}
49-
dprintf("GOOD packet, RX flags set: %02x len=%d\n", flags, *(packet+1));
5048
return true;
5149
}
5250
dprintf("Bad packet, RX error flags set: %02x\n", flags);
@@ -58,7 +56,6 @@ void receive_packet() {
5856

5957
uint8_t tmp_cmd = rtl_inb(ChipCmd);
6058
if (tmp_cmd & CR_BUFE) {
61-
dprintf("CR_BUFE is set, bailing receive loop\n");
6259
break;
6360
}
6461

@@ -75,7 +72,6 @@ void receive_packet() {
7572
t += 2;
7673

7774
if (packet_length) {
78-
dprintf("Copy to ethernet handler\n");
7975
void* packet = kmalloc(packet_length);
8076
memcpy(packet, t, packet_length);
8177
ethernet_handle_packet(packet, packet_length);
@@ -95,8 +91,6 @@ void receive_packet() {
9591

9692
tmp_cmd = rtl_inb(ChipCmd);
9793

98-
dprintf("Received one packet\n");
99-
10094
} while (!(tmp_cmd & CR_BUFE));
10195

10296
}
@@ -124,7 +118,6 @@ void rtl8139_handler([[maybe_unused]] uint8_t isr, [[maybe_unused]] uint64_t err
124118
if(status & TOK) {
125119
// Sent
126120
rtl_outw(IntrStatus, TX_OK);
127-
dprintf("RTL8139: Packet sent\n");
128121
}
129122
if (status & ROK) {
130123
// Received
@@ -182,8 +175,6 @@ void rtl8139_send_packet(void* data, uint32_t len) {
182175

183176
interrupts_off();
184177

185-
dprintf("RTL8139 send packet (%s): ", in_interrupt ? "in int" : "outside int");
186-
187178
// Static buffer below 4GB
188179
uint32_t transfer_data = rtl8139_device.tx_buffers + 8192 * rtl8139_device.tx_cur;
189180
void* transfer_data_p = (void*)((uint64_t)rtl8139_device.tx_buffers + 8192 * rtl8139_device.tx_cur);
@@ -209,7 +200,7 @@ void rtl8139_send_packet(void* data, uint32_t len) {
209200
uint32_t tx_status;
210201
while ((tx_status = rtl_inl(TxStatus0 + old_cur)) & (TX_OWN | TX_TUN | TX_TOK | TX_OWC | TX_TABT | TX_CRS)) {
211202
if (tx_status & TX_OWN) {
212-
dprintf("DMA transfer of packet completed\n");
203+
//dprintf("DMA transfer of packet completed\n");
213204
}
214205
if (tx_status & TX_TUN) {
215206
dprintf("Transmit buffer overrun!\n");
@@ -219,7 +210,6 @@ void rtl8139_send_packet(void* data, uint32_t len) {
219210
/*
220211
* When the whole packet is moved to line, the TOK(in TSD) is set to 1.
221212
*/
222-
dprintf("Send success and complete\n");
223213
break;
224214
}
225215
if (tx_status & TX_OWC) {
@@ -236,8 +226,6 @@ void rtl8139_send_packet(void* data, uint32_t len) {
236226
}
237227
}
238228

239-
dprintf("RTL8139 send packet done\n");
240-
241229
interrupts_on();
242230
}
243231

src/tcp.c

Lines changed: 1 addition & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ static const char* error_messages[] = {
1818
};
1919

2020
/* Set this to output or record a trace of the TCP I/O. This is very noisy! */
21-
#define TCP_TRACE 1
21+
#define TCP_TRACE 0
2222

2323
bool tcp_state_receive_fin(ip_packet_t* encap_packet, tcp_segment_t* segment, tcp_conn_t* conn, const tcp_options_t* options, size_t len);
2424

@@ -333,8 +333,6 @@ tcp_conn_t* tcp_send_segment(tcp_conn_t *conn, uint32_t seq, uint8_t flags, cons
333333
return NULL;
334334
}
335335

336-
dprintf("TCP send segment\n");
337-
338336
ip_packet_t encap;
339337
tcp_options_t options = { .mss = flags & TCP_SYN ? 1460 : 0 };
340338
uint16_t length = sizeof(tcp_segment_t) + count + (flags & TCP_SYN ? 4 : 0);
@@ -371,9 +369,7 @@ tcp_conn_t* tcp_send_segment(tcp_conn_t *conn, uint32_t seq, uint8_t flags, cons
371369
memcpy((void*)packet->payload + (flags & TCP_SYN ? 4 : 0), data, count);
372370

373371
packet->checksum = htons(tcp_calculate_checksum(&encap, packet, length));
374-
dprintf("TCP -> IP send packet\n");
375372
ip_send_packet(encap.dst_ip, packet, length, PROTOCOL_TCP);
376-
dprintf("TCP -> IP send packet DONE\n");
377373

378374
conn->snd_nxt += count;
379375
if (flags & (TCP_SYN | TCP_FIN)) {
@@ -935,7 +931,6 @@ bool tcp_state_time_wait(ip_packet_t* encap_packet, tcp_segment_t* segment, tcp_
935931
*/
936932
bool tcp_state_machine(ip_packet_t* encap_packet, tcp_segment_t* segment, tcp_conn_t* conn, const tcp_options_t* options, size_t len)
937933
{
938-
dprintf("tcp_state_machine");
939934
switch (conn->state) {
940935
case TCP_LISTEN:
941936
return tcp_state_listen(encap_packet, segment, conn, options, len);
@@ -971,25 +966,20 @@ bool tcp_state_machine(ip_packet_t* encap_packet, tcp_segment_t* segment, tcp_co
971966
*/
972967
void tcp_handle_packet([[maybe_unused]] ip_packet_t* encap_packet, tcp_segment_t* segment, size_t len)
973968
{
974-
dprintf("tcp_handle_packet\n");
975969
tcp_options_t options;
976970
uint16_t our_checksum = tcp_calculate_checksum(encap_packet, segment, len);
977971
tcp_byte_order_in(segment);
978972
tcp_parse_options(segment, &options);
979973
if (our_checksum == segment->checksum) {
980-
dprintf("tcp with valid checksum\n");
981974
tcp_conn_t* conn = tcp_find(*((uint32_t*)(&encap_packet->dst_ip)), *((uint32_t*)(&encap_packet->src_ip)), segment->dst_port, segment->src_port);
982975
if (conn) {
983976
//tcp_dump_segment(true, conn, encap_packet, segment, &options, len, our_checksum);
984977
tcp_state_machine(encap_packet, segment, conn, &options, len);
985-
} else {
986-
dprintf("tcp packet with no TCB\n");
987978
}
988979
} else {
989980
dprintf("tcp packet with invalid checksum\n");
990981
//tcp_dump_segment(true, NULL, encap_packet, segment, &options, len, our_checksum);
991982
}
992-
dprintf("tcp_handle_packet done\n");
993983
}
994984

995985
/**
@@ -1020,7 +1010,6 @@ void tcp_idle()
10201010
}
10211011
conn->send_buffer_len -= amount_to_send;
10221012
interrupts_on();
1023-
dprintf("done send buffer resize down\n");
10241013
}
10251014
} else if (conn->state == TCP_TIME_WAIT && seq_gte(get_isn(), conn->msl_time)) {
10261015
tcp_free(conn);
@@ -1094,8 +1083,6 @@ int tcp_connect(uint32_t target_addr, uint16_t target_port, uint16_t source_port
10941083
uint32_t isn = get_isn();
10951084
unsigned char ip[4] = { 0 };
10961085

1097-
dprintf("tcp_connect() with isn=%d\n", isn);
1098-
10991086
gethostaddr(ip);
11001087

11011088
conn.remote_addr = target_addr;
@@ -1136,21 +1123,12 @@ int tcp_connect(uint32_t target_addr, uint16_t target_port, uint16_t source_port
11361123
conn.recv_buffer_spinlock = 0;
11371124
conn.send_buffer_spinlock = 0;
11381125

1139-
dprintf("tcp_connect() local port=%d\n", conn.local_port);
1140-
11411126
tcp_set_state(&conn, TCP_SYN_SENT);
1142-
1143-
dprintf("tcp_connect() sending segment\n");
1144-
11451127
tcp_send_segment(&conn, conn.snd_nxt, TCP_SYN, NULL, 0);
1146-
1147-
dprintf("tcp_connect() setting hashmap\n");
1148-
11491128
hashmap_set(tcb, &conn);
11501129

11511130
tcp_conn_t* new_conn = tcp_find(conn.local_addr, conn.remote_addr, conn.local_port, conn.remote_port);
11521131
if (new_conn) {
1153-
dprintf("tcp_connect() setting conn fd\n");
11541132
new_conn->fd = tcp_allocate_fd(new_conn);
11551133
if (new_conn->fd == -1) {
11561134
dprintf("tcp_connect() allocation of fd failed\n");
@@ -1197,7 +1175,6 @@ int tcp_close(tcp_conn_t* conn)
11971175

11981176
int send(int socket, const void* buffer, uint32_t length)
11991177
{
1200-
dprintf("send(): %d\n", length);
12011178
tcp_conn_t* conn = tcp_find_by_fd(socket);
12021179
if (conn == NULL) {
12031180
dprintf("send(): invalid socket %d\n", socket);
@@ -1211,7 +1188,6 @@ int send(int socket, const void* buffer, uint32_t length)
12111188
memcpy(conn->send_buffer + conn->send_buffer_len, buffer, length);
12121189
conn->send_buffer_len += length;
12131190
interrupts_on();
1214-
dprintf("send(): done\n");
12151191
return (int)length;
12161192
}
12171193

@@ -1224,18 +1200,14 @@ int connect(uint32_t target_addr, uint16_t target_port, uint16_t source_port, bo
12241200
}
12251201
return result;
12261202
}
1227-
dprintf("connect(): tcp_connect() gave us fd %d\n", result);
12281203
tcp_conn_t* conn = tcp_find_by_fd(result);
12291204
time_t start = time(NULL);
1230-
dprintf("Connect waiting: ");
12311205
while (conn && conn->state < TCP_ESTABLISHED) {
1232-
dprintf(".");
12331206
__asm__ volatile("hlt");
12341207
if (time(NULL) - start > 10) {
12351208
return TCP_ERROR_CONNECTION_FAILED;
12361209
}
12371210
};
1238-
dprintf("\nconnect(): socket state ESTABLISHED\n");
12391211
return conn->state == TCP_ESTABLISHED ? result : TCP_ERROR_CONNECTION_FAILED;
12401212
}
12411213

@@ -1262,7 +1234,6 @@ bool is_connected(int socket)
12621234

12631235
int recv(int socket, void* buffer, uint32_t maxlen, bool blocking, uint32_t timeout)
12641236
{
1265-
//dprintf("recv(): socket=%d blocking=%d\n", socket, blocking);
12661237
tcp_conn_t* conn = tcp_find_by_fd(socket);
12671238
if (conn == NULL) {
12681239
dprintf("recv(): invalid socket\n");
@@ -1273,7 +1244,6 @@ int recv(int socket, void* buffer, uint32_t maxlen, bool blocking, uint32_t time
12731244
}
12741245

12751246
if (blocking) {
1276-
//dprintf("recv(): start blocking wait\n");
12771247
time_t now = time(NULL);
12781248
while (conn->recv_buffer_len == 0 || conn->recv_buffer == NULL) {
12791249
if (time(NULL) - now > timeout || conn->state != TCP_ESTABLISHED) {
@@ -1284,7 +1254,6 @@ int recv(int socket, void* buffer, uint32_t maxlen, bool blocking, uint32_t time
12841254
if (conn->recv_buffer_len > 0 && conn->recv_buffer != NULL) {
12851255
interrupts_off();
12861256
/* There is buffered data to receive */
1287-
//dprintf("recv buffer resize down\n");
12881257
size_t amount_to_recv = conn->recv_buffer_len > maxlen ? maxlen : conn->recv_buffer_len;
12891258
memcpy(buffer, conn->recv_buffer, amount_to_recv);
12901259
/* Resize recv buffer down */

0 commit comments

Comments
 (0)