From: Oliver Lehmann on
Hi,

first I've to admit, that I'm not that familiar with ASM but I'm starting
to learn and implemented my first own hello world programs ;)

I've a Z8k system running UNIX. I've fixed a bug the C-Compiler on that
system had (source was available) regarding a libc system call, but I
didn't fully understand the ASM listings. Both, the listing from my
test-c-Program the compiler produced, and the asm implementation of the
libc function where not fully understandable to me. So I'm asking my
questions here hoping that one of you could explain the thing to me and
answer my questions.

Precondition - a function "_fopen" gets called and after the call
register r2 contains a filepointer (integer).

This filepointer shall be processed further by the function "_fcntl".


.seg
fp := r13
FP := rr12
sp := r15
SP := rr14
[...]
callr _open
inc sp,#%6
ld FP(#~L1+%5a),r2
xor r2,r2
push @SP,r2
xor r2,r2
push @SP,r2
push @SP,_stkseg+~L1+%5a(fp)
callr _fcntl
inc sp,#%6

_fcntl is defined as follows:

.seg

sp := r15
SP := rr14

.psec
.code
_fcntl::
{
ldm r0,|_stkseg+4|(sp),#4
xor r4,r4
sc #38 // switch
ld r2,r4
ret nc
jp cerror
}

The systemcall 38 calls the fcntl() Implementation in the UNIX kernel
which expects 3 arguments in r0,r1 and r2 and returns its status in r4.

Now my questions:

a) _open returns the filepointer in r2. What exactly means "FP(#~L1+%5a)"
where r2 gets loaded to?
b) A stack gets filled with push. In this case the stack is the register
rr14. What does the @ in front of SP mean?
c) What means "_stkseg+~L1+%5a(fp)"? For me it looks like the register
"@SP" gets filled with the values from the "stack segment(=_stkseg?)"
+ ~L1 + 90. Wy +~L1 and 90 is done at the end? What is ~L1? Why is
there a (fp) at the end?

Now the FILO-Stack contains 0,0,filepointer from r2.

d) what exaclty happens in the _fcntl's ldm call? I understand, that it
loads 4 words from "|_stkseg+4|(sp)" into r0. But what is the meaning
of the pipes "|" and why is there (sp) at the end?
e) The function in the kernel which gets called with the systemcall 38
expects 3 parameters as I noted previous in r0,r1 and r2. I understand,
that the ldm call reads 4 words into r0. But how are r1 and r2 are
filled up? does the ldm automatically fills the next register each
with a single word read? But why are there 4 words read then and not
only 3?

Greetings, Oliver




--
Oliver Lehmann
http://www.pofo.de/
http://wishlist.ans-netz.de/
From: Herbert Kleebauer on
Oliver Lehmann wrote:

> first I've to admit, that I'm not that familiar with ASM but I'm starting
> to learn and implemented my first own hello world programs ;)
>
> I've a Z8k system running UNIX. I've fixed a bug the C-Compiler on that
> system had (source was available) regarding a libc system call, but I
> didn't fully understand the ASM listings. Both, the listing from my
> test-c-Program the compiler produced, and the asm implementation of the
> libc function where not fully understandable to me. So I'm asking my
> questions here hoping that one of you could explain the thing to me and
> answer my questions.

Try:

ftp://ftp.groessler.org/pub/chris/olivetti_m20/doc/english/Z8000_prog_guide/Z8000_prog_guide.pdf
http://bitsavers.vt100.net/pdf/zilog/Z8000Tech.pdf
http://www.tech-systems-labs.com/booksdata/Z8000.pdf
http://www.tech-systems-labs.com/booksdata/Z8000-1.pdf
From: Oliver Lehmann on
Herbert Kleebauer wrote:

> ftp://ftp.groessler.org/pub/chris/olivetti_m20/doc/english/Z8000_prog_guide/Z8000_prog_guide.pdf

Ok, I understand:

"@" means the data gets not loaded into the register, but into the
address the register points too (indirect adressing).

An adress enclosed in pipes "|" means that a Short Offset is read
from a place in the specified segment. For example "LDB RH4,|<<34>>%F0|
reads the data of the memoryspace %F0 from the segment 34 in the
short-offset format into the register RH4.

LD R0,XXXX(YY) means that the register R0 will be loaded with the data of
adress (XXXX + index of Register YY), So if XXXX is %4000 and the register
YY contains 4, R0 contains the data written at adress %4004.

# indicates that data is following so "LD R0,#1234" loads "1234" into R0

I understand that ldm loads each of the read words into the specified and
all the following registers

So the remaining questions are...

f) What I don't understand out of "ld FP(#~L1+%5a),r2" the ~L1 part.
What is ~L1?

g) _stkseg+~L1+%5a(fp) - does _stkseg contain an adress? is this a
function? Is this an automatic alias to a specific register? - Again
the mysterious ~L1 part.

h) ldm r0,|_stkseg+4|(sp),#4
_stkseg should be a segment adress like <<34>> or? So what does
_stkseg here? is this an alias for a base segment adress where 4 is
added then? Where is the memoryspace? shouldn't be the syntax
|<<segment>>%adress|? And then the data in the register sp gets then
added to the short offset adress? to what exactly? I still don't get
it.




--
Oliver Lehmann
http://www.pofo.de/
http://wishlist.ans-netz.de/