From 5769cf67be82100c434b9b2f8f4b977239d06033 Mon Sep 17 00:00:00 2001 From: David Schmenk Date: Wed, 24 Jan 2018 18:08:18 -0800 Subject: [PATCH] Fix TCP/IP bitrot and last dataseg zero length symbol overlap with code seg --- src/libsrc/dhcp.pla | 40 ++++++++++++++++------------------------ src/libsrc/etherip.pla | 20 ++++++++++---------- src/libsrc/inet.pla | 4 ++-- src/libsrc/uthernet.pla | 28 ++++++++++++++-------------- src/samplesrc/httpd.pla | 9 +-------- src/toolsrc/codegen.c | 6 ++++++ src/toolsrc/codegen.pla | 6 ++++++ src/toolsrc/parse.pla | 1 + src/toolsrc/plasm.pla | 2 +- 9 files changed, 57 insertions(+), 59 deletions(-) diff --git a/src/libsrc/dhcp.pla b/src/libsrc/dhcp.pla index 69f0ecf..1a4f32f 100644 --- a/src/libsrc/dhcp.pla +++ b/src/libsrc/dhcp.pla @@ -87,22 +87,14 @@ byte[] endDHCP // // DEBUG // -//byte boundstr = "Apple II bound to:\n" -//byte dnsstr = "DNS: " -//def putb(hexb) -// return call($FDDA, hexb, 0, 0, 0) -//end -//def puth(hex) -// return call($F941, hex >> 8, hex, 0, 0) -//end -//def putip(ipptr) -// byte i -// -// for i = 0 to 2 -// puti(ipptr->[i]); putc('.') -// next -// puti(ipptr->[i]) -//end +def putip(ipptr)#0 + byte i + + for i = 0 to 2 + puti(ipptr->[i]); putc('.') + next + puti(ipptr->[i]) +end //def dumpbytes(buf, len) // word i // @@ -132,13 +124,13 @@ def parseopts(opts, match) i = 0 while opts->[i] <> $FF and i < 64 - while !opts->[i] and i < 64 - i = i + 1 - loop + while !opts->[i] and i < 64 + i++ + loop if opts->[i] == match - return i - fin - i = i + opts->[i + 1] + 2 + return i + fin + i = i + opts->[i + 1] + 2 loop return -1 end @@ -224,7 +216,7 @@ repeat until retry > 4 or optsOP.2 == DHCP_ACK iNet:closeUDP(portDHCP) iNet:setInterfaceIP(@localip, @localnet, @localgw) -//puts(@boundstr);putip(@localip);putc('/');putip(@localnet);putln +puts("Apple II bound to:\n");putip(@localip);putc('/');putip(@localnet);putln iNet:setDNS(@localdns) -//puts(@dnsstr);putip(@localdns);putln +//puts("DNS: ");putip(@localdns);putln done diff --git a/src/libsrc/etherip.pla b/src/libsrc/etherip.pla index 39432e8..43c1cde 100644 --- a/src/libsrc/etherip.pla +++ b/src/libsrc/etherip.pla @@ -198,15 +198,15 @@ asm sum1(prevsum, buf, len) STA ESTKL,X BEQ + !BYTE $A9 -- CLC +- CLC INC ESTKH,X -+ BCS - ++ BCS - CHKLP LDA (SRC),Y PHA INY BNE + INC SRCH -+ LDA (SRC),Y ++ LDA (SRC),Y ADC ESTKH+2,X STA ESTKH+2,X PLA @@ -215,7 +215,7 @@ CHKLP LDA (SRC),Y INY BNE + INC SRCH -+ DEC ESTKL,X ++ DEC ESTKL,X BNE CHKLP DEC ESTKH,X BNE CHKLP @@ -224,7 +224,7 @@ CHKLP LDA (SRC),Y BNE + INC ESTKL+2,X BEQ - -+ INX ++ INX INX RTS end @@ -255,10 +255,10 @@ def etherSendIP(ipdst, proto, seglist, size) memcpy(@hdr.ip_dst, ipdst, IP4ADR_SIZE) retry = 0 while hdr:ip_dst:0 <> remoteip:0 and hdr:ip_dst:2 <> remoteip:2 - if retry >= 3 + if retry >= 3 return -1 // ARP failed fin - retry = retry + 1 + retry++ memset(@dstMAC, MAC_BROADCAST, MAC_SIZE) memset(@remoteha, 0, MAC_SIZE) memcpy(@remoteip, @hdr.ip_dst, IP4ADR_SIZE) @@ -560,13 +560,13 @@ end // // Initialize the driver interface // -export def setEtherDriver(MAC, getlen, readframe, setlen, writeframe)#0 +export def setEtherDriver(MAC, getlen, readfrm, setlen, writefrm)#0 memcpy(@myMAC, MAC, MAC_SIZE) memcpy(@localha, MAC, MAC_SIZE) getFrameLen = getlen - readFrame = readframe + readFrame = readfrm setFrameLen = setlen - writeFrame = writeframe + writeFrame = writefrm end // // Set the local IP addresses diff --git a/src/libsrc/inet.pla b/src/libsrc/inet.pla index db0f59f..b25e0ed 100644 --- a/src/libsrc/inet.pla +++ b/src/libsrc/inet.pla @@ -211,7 +211,7 @@ def iNetInit // while ^driver //puts(driver);putln - if modexec(driver) >= 0 + if cmdsys:modexec(driver) >= 0 break fin driver = driver + ^driver + 1 @@ -222,7 +222,7 @@ def iNetInit // // Get an IP address // - modexec("DHCP") + cmdsys:modexec("DHCP") iNet:resolveIP = @iNetResolve return @iNet end diff --git a/src/libsrc/uthernet.pla b/src/libsrc/uthernet.pla index a21eff3..aa5ba21 100644 --- a/src/libsrc/uthernet.pla +++ b/src/libsrc/uthernet.pla @@ -6,7 +6,7 @@ include "inc/cmdsys.plh" // Include dependency on S/W IP stack // import etherip - predef setEtherDriver(MAC, getlen, readframe, setlen, writeframe)#0 + predef setEtherDriver(MAC, getlen, readfrm, setlen, writefrm)#0 end // // Uthernet register offsets @@ -100,9 +100,9 @@ asm pokefrm(buf, len) STA ESTKL,X BEQ + !BYTE $A9 -- CLC +- CLC INC ESTKH,X -+ BCS - ++ BCS - POKELP LDA (SRC),Y end asm _pokefrml @@ -114,8 +114,8 @@ asm _pokefrmh STA $C000 INY BNE + - INC SRCH -+ DEC ESTKL,X + INC SRCH ++ DEC ESTKL,X BNE POKELP DEC ESTKH,X BNE POKELP @@ -137,24 +137,24 @@ asm peekfrm(buf, len) ROR ADC #$00 STA ESTKL,X - BEQ + - !BYTE $A9 -- CLC - INC ESTKH,X -+ BCS - + BEQ + + !BYTE $A9 +- CLC + INC ESTKH,X ++ BCS - end asm _peekfrml -PEEKLP LDA $C000 +PEEKLP LDA $C000 STA (DST),Y INY end asm _peekfrmh + LDA $C000 - STA (DST),Y + STA (DST),Y INY BNE + - INC DSTH -+ DEC ESTKL,X + INC DSTH ++ DEC ESTKL,X BNE PEEKLP DEC ESTKH,X BNE PEEKLP diff --git a/src/samplesrc/httpd.pla b/src/samplesrc/httpd.pla index 4e8c2ca..ab73a90 100644 --- a/src/samplesrc/httpd.pla +++ b/src/samplesrc/httpd.pla @@ -40,12 +40,6 @@ byte mimeOctetStream = "application/octet-stream" // // DEBUG // -def putb(hexb)#0 - call($FDDA, hexb, 0, 0, 0) -end -def puth(hex)#0 - call($F941, hex >> 8, hex, 0, 0) -end def putip(ipptr)#0 byte i @@ -203,12 +197,11 @@ if !iNet:initIP() return -1 fin puts(@hello) -getpfx(@prefix) +fileio:getpfx(@prefix) // // Alloc aligned file/io buffers // filebuff = heapallocalign(1024, 8, 0) -//iobuff = heapallocalign(1024, 8, 0) // // Service IP // diff --git a/src/toolsrc/codegen.c b/src/toolsrc/codegen.c index 06b8791..2a7459e 100755 --- a/src/toolsrc/codegen.c +++ b/src/toolsrc/codegen.c @@ -17,6 +17,7 @@ static int defs = 0; static int asmdefs = 0; static int codetags = 1; // Fix check for break_tag and cont_tag static int fixups = 0; +static int lastglobalsize = 0; static char idconst_name[1024][ID_LEN+1]; static int idconst_value[1024]; static char idglobal_name[1024][ID_LEN+1]; @@ -465,7 +466,11 @@ void emit_sysflags(int val) void emit_bytecode_seg(void) { if ((outflags & MODULE) && !(outflags & BYTECODE_SEG)) + { + if (lastglobalsize == 0) // Pad a byte if last label is at end of data segment + printf("\t%s\t$00\t\t\t; PAD BYTE\n", DB); printf("_SUBSEG%c\t\t\t\t; BYTECODE STARTS\n", LBL); + } outflags |= BYTECODE_SEG; } void emit_comment(char *s) @@ -482,6 +487,7 @@ void emit_idlocal(char *name, int value) } void emit_idglobal(int tag, int size, char *name) { + lastglobalsize = size; if (size == 0) printf("_D%03d%c\t\t\t\t\t; %s\n", tag, LBL, name); else diff --git a/src/toolsrc/codegen.pla b/src/toolsrc/codegen.pla index bea16d4..ecda769 100644 --- a/src/toolsrc/codegen.pla +++ b/src/toolsrc/codegen.pla @@ -125,6 +125,11 @@ def emit_data(vartype, consttype, constval, constsize) fin return size end +def emit_codeseg#0 + if lastglobalsize == 0 + emit_byte($00) // Pad byte between last data tag and code seg + fin +end def emit_const(cval)#0 emit_pending_seq if cval == $0000 // ZERO @@ -421,6 +426,7 @@ def new_iddata(nameptr, len, type, size)#0 else lastglobal=>idval = new_tag(WORD_FIXUP)//datasize emit_tag(lastglobal=>idval) + lastglobalsize = size if size emit_fill(size) datasize = datasize + size diff --git a/src/toolsrc/parse.pla b/src/toolsrc/parse.pla index ce9644b..9ebbc89 100644 --- a/src/toolsrc/parse.pla +++ b/src/toolsrc/parse.pla @@ -1225,6 +1225,7 @@ def parse_module#0 // while parse_mods; nextln; loop while parse_vars(GLOBAL_TYPE); nextln; loop + emit_codeseg while parse_defs; nextln; loop entrypoint = codeptr prevstmnt = 0 diff --git a/src/toolsrc/plasm.pla b/src/toolsrc/plasm.pla index 5372e69..17b2fe3 100644 --- a/src/toolsrc/plasm.pla +++ b/src/toolsrc/plasm.pla @@ -246,7 +246,7 @@ word fixup_tag, fixup_addr word tag_addr, tag_type word idglobal_tbl, idlocal_tbl word pending_seq -word globals, lastglobal, lastlocal, savelast +word globals, lastglobal, lastglobalsize, lastlocal, savelast word tag_num, fixup_num, globalbufsz, localbufsz, codebufsz word datasize, framesize, savesize byte locals, savelocals