Skip to content

Commit bd74f37

Browse files
committed
use inline asm to receive large buffers in 9p code; makes -2nu work at 2_000_000 baud
1 parent 866f0ee commit bd74f37

File tree

1 file changed

+36
-5
lines changed

1 file changed

+36
-5
lines changed

include/filesys/fs9p/fs9p_vfs.c

Lines changed: 36 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ static unsigned int zdoGet4()
3232
// startbuf is that start of the buffer (used for both send and
3333
// receive); endbuf is the end of data to send; maxlen is maximum
3434
// size
35-
static int plain_sendrecv(uint8_t *startbuf, uint8_t *endbuf, int maxlen)
35+
static int plain_sendrecv(uint8_t *startbuf, uint8_t *endbuf, int maxlen) __attribute__(opt(no-fast-inline-asm))
3636
{
3737
int len = endbuf - startbuf;
3838
uint8_t *buf = startbuf;
@@ -64,21 +64,52 @@ static int plain_sendrecv(uint8_t *startbuf, uint8_t *endbuf, int maxlen)
6464
_txraw(*buf++);
6565
--len;
6666
}
67-
len = zdoGet4();
6867
#ifdef __P2__
69-
*(int*)startbuf = len;
70-
#else
68+
int c;
69+
__asm volatile {
70+
mov buf, startbuf
71+
call #.zdoGet1
72+
mov len, c
73+
call #.zdoGet1
74+
shl c, #8
75+
or len, c
76+
call #.zdoGet1
77+
shl c, #16
78+
or len, c
79+
call #.zdoGet1
80+
shl c, #24
81+
or len, c
82+
wrlong len, buf
83+
add buf, #4
84+
mov left, len
85+
sub left, #4 wcz
86+
if_be jmp #.endit
87+
.rdloop
88+
call #.zdoGet1
89+
wrbyte c, buf
90+
add buf, #1
91+
djnz left, #.rdloop
92+
jmp #.endit
93+
.zdoGet1
94+
testp #63 wc
95+
if_nc jmp #.zdoGet1
96+
rdpin c, #63
97+
_ret_ shr c, #24
98+
.endit
99+
}
100+
#else
101+
len = zdoGet4();
71102
startbuf[0] = len & 0xff;
72103
startbuf[1] = (len>>8) & 0xff;
73104
startbuf[2] = (len>>16) & 0xff;
74105
startbuf[3] = (len>>24) & 0xff;
75-
#endif
76106
buf = startbuf+4;
77107
left = len - 4;
78108
while (left > 0 && i < maxlen) {
79109
buf[i++] = zdoGet1();
80110
--left;
81111
}
112+
#endif
82113
_setrxtxflags(flags);
83114

84115
__unlockio(0);

0 commit comments

Comments
 (0)