1987-03-10 17:51:10 +00:00
|
|
|
/*
|
|
|
|
* (c) copyright 1987 by the Vrije Universiteit, Amsterdam, The Netherlands.
|
|
|
|
* See the copyright notice in the ACK home directory, in the file "Copyright".
|
|
|
|
*/
|
1986-03-10 13:07:55 +00:00
|
|
|
/* $Header$ */
|
|
|
|
/* B L O C K S T O R I N G A N D L O A D I N G */
|
|
|
|
|
1986-09-29 14:01:34 +00:00
|
|
|
#include <em.h>
|
1987-07-16 13:27:37 +00:00
|
|
|
#include <em_reg.h>
|
1986-09-29 14:01:34 +00:00
|
|
|
#include "arith.h"
|
|
|
|
#include "sizes.h"
|
|
|
|
#include "atw.h"
|
1987-03-20 08:30:31 +00:00
|
|
|
#include "align.h"
|
1986-09-29 14:01:34 +00:00
|
|
|
#ifndef STB
|
|
|
|
#include "label.h"
|
|
|
|
#include "stack.h"
|
1988-04-26 15:33:48 +00:00
|
|
|
#include "Lpars.h"
|
1987-07-16 13:27:37 +00:00
|
|
|
extern arith NewLocal();
|
1988-04-26 15:33:48 +00:00
|
|
|
#define LocalPtrVar() NewLocal(pointer_size, pointer_align, reg_pointer, REGISTER)
|
1986-09-29 14:01:34 +00:00
|
|
|
#endif STB
|
1986-03-10 13:07:55 +00:00
|
|
|
|
|
|
|
/* Because EM does not support the loading and storing of
|
|
|
|
objects having other sizes than word fragment and multiple,
|
|
|
|
we need to have a way of transferring these objects, whereby
|
|
|
|
we simulate "loi" and "sti": the address of the source resp.
|
|
|
|
destination is located on top of stack and a call is done
|
|
|
|
to load_block() resp. store_block().
|
|
|
|
===============================================================
|
|
|
|
# Loadblock() works on the stack as follows: ([ ] indicates the
|
|
|
|
# position of the stackpointer)
|
|
|
|
# lower address--->
|
|
|
|
# 1) | &object
|
|
|
|
# 2) | ... ATW(sz) bytes ... | sz | &stack_block | &object
|
|
|
|
# 3) | ... ATW(sz) bytes ...
|
|
|
|
===============================================================
|
|
|
|
Loadblock() pushes ATW(sz) bytes directly onto the stack!
|
|
|
|
|
|
|
|
Store_block() works on the stack as follows:
|
|
|
|
lower address--->
|
|
|
|
1) | ... ATW(sz) bytes ... | &object
|
|
|
|
2) | ... ATW(sz) bytes ... | &object | &stack_block | sz
|
|
|
|
3) <empty>
|
|
|
|
|
|
|
|
If sz is a legal argument for "loi" or "sti", just one EM
|
|
|
|
instruction is generated.
|
|
|
|
In the other cases, the notion of alignment is taken into account:
|
|
|
|
we only push an object of the size accepted by EM onto the stack,
|
|
|
|
while we need a loop to store the stack block into a memory object.
|
|
|
|
*/
|
|
|
|
store_block(sz, al)
|
|
|
|
arith sz;
|
|
|
|
int al;
|
|
|
|
{
|
|
|
|
if (
|
|
|
|
((sz == al) && (word_align % al == 0)) ||
|
|
|
|
(
|
|
|
|
(sz % word_size == 0 || word_size % sz == 0) &&
|
|
|
|
(al % word_align == 0)
|
|
|
|
)
|
1986-09-29 14:01:34 +00:00
|
|
|
) /* Lots of Irritating Stupid Parentheses */
|
1986-03-10 13:07:55 +00:00
|
|
|
C_sti(sz);
|
1986-09-29 14:01:34 +00:00
|
|
|
else {
|
|
|
|
#ifndef STB
|
1987-07-16 13:27:37 +00:00
|
|
|
arith src, dst;
|
1986-09-29 14:01:34 +00:00
|
|
|
|
|
|
|
/* allocate two pointer temporaries */
|
1987-07-16 13:27:37 +00:00
|
|
|
src = LocalPtrVar();
|
|
|
|
dst = LocalPtrVar();
|
1986-09-29 14:01:34 +00:00
|
|
|
|
|
|
|
/* load the addresses */
|
1987-07-16 13:27:37 +00:00
|
|
|
StoreLocal(dst, pointer_size);
|
1986-09-29 14:01:34 +00:00
|
|
|
C_lor((arith)1); /* push current sp */
|
1987-07-16 13:27:37 +00:00
|
|
|
StoreLocal(src, pointer_size);
|
1986-09-29 14:01:34 +00:00
|
|
|
copy_loop(sz, src, dst);
|
|
|
|
C_asp(ATW(sz));
|
1987-07-16 13:27:37 +00:00
|
|
|
FreeLocal(dst);
|
|
|
|
FreeLocal(src);
|
1986-09-29 14:01:34 +00:00
|
|
|
#else STB
|
1986-03-10 13:07:55 +00:00
|
|
|
/* address of destination lies on the stack */
|
|
|
|
|
|
|
|
/* push address of first byte of block on stack onto
|
|
|
|
the stack by computing it from the current stack
|
|
|
|
pointer position
|
|
|
|
*/
|
|
|
|
C_lor((arith)1); /* push current sp */
|
|
|
|
C_adp(pointer_size); /* set & to 1st byte of block */
|
|
|
|
C_loc(sz); /* number of bytes to transfer */
|
|
|
|
C_cal("__stb"); /* call transfer routine */
|
|
|
|
C_asp(pointer_size + pointer_size + int_size + ATW(sz));
|
1986-09-29 14:01:34 +00:00
|
|
|
#endif STB
|
1986-03-10 13:07:55 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
load_block(sz, al)
|
|
|
|
arith sz;
|
|
|
|
int al;
|
|
|
|
{
|
|
|
|
arith esz = ATW(sz); /* effective size == actual # pushed bytes */
|
|
|
|
|
1987-08-03 14:40:49 +00:00
|
|
|
if (
|
|
|
|
((sz == al) && (word_align % al == 0)) ||
|
|
|
|
(
|
|
|
|
(sz % word_size == 0 || word_size % sz == 0) &&
|
|
|
|
(al % word_align == 0)
|
|
|
|
)
|
|
|
|
) /* Lots of Irritating Stupid Parentheses */
|
1986-03-10 13:07:55 +00:00
|
|
|
C_loi(sz);
|
|
|
|
else {
|
1986-09-29 14:01:34 +00:00
|
|
|
#ifndef STB
|
1987-07-16 13:27:37 +00:00
|
|
|
arith src, dst;
|
1986-09-29 14:01:34 +00:00
|
|
|
|
|
|
|
/* allocate two pointer temporaries */
|
1987-07-16 13:27:37 +00:00
|
|
|
src = LocalPtrVar();
|
|
|
|
dst = LocalPtrVar();
|
1986-09-29 14:01:34 +00:00
|
|
|
|
1987-07-16 13:27:37 +00:00
|
|
|
StoreLocal(src, pointer_size);
|
1986-09-29 14:01:34 +00:00
|
|
|
C_asp(-esz); /* allocate stack block */
|
|
|
|
C_lor((arith)1); /* push & of stack block as dst */
|
1987-07-16 13:27:37 +00:00
|
|
|
StoreLocal(dst, pointer_size);
|
1986-09-29 14:01:34 +00:00
|
|
|
copy_loop(sz, src, dst);
|
1987-07-16 13:27:37 +00:00
|
|
|
FreeLocal(dst);
|
|
|
|
FreeLocal(src);
|
1986-09-29 14:01:34 +00:00
|
|
|
#else STB
|
1986-03-10 13:07:55 +00:00
|
|
|
C_asp(-(esz - pointer_size)); /* allocate stack block */
|
|
|
|
C_lor((arith)1); /* push & of stack block as dst */
|
|
|
|
C_dup(pointer_size); /* fetch source address */
|
|
|
|
C_adp(esz - pointer_size);
|
|
|
|
C_loi(pointer_size);
|
|
|
|
C_loc(sz); /* # bytes to copy */
|
|
|
|
C_cal("__stb"); /* library copy routine */
|
|
|
|
C_asp(int_size + pointer_size + pointer_size);
|
1986-09-29 14:01:34 +00:00
|
|
|
#endif STB
|
1986-03-10 13:07:55 +00:00
|
|
|
}
|
|
|
|
}
|
1986-09-29 14:01:34 +00:00
|
|
|
|
|
|
|
#ifndef STB
|
|
|
|
copy_loop(sz, src, dst)
|
|
|
|
arith sz, src, dst;
|
|
|
|
{
|
|
|
|
/* generate inline byte-copy loop */
|
|
|
|
label l_cont = text_label(), l_stop = text_label();
|
|
|
|
|
|
|
|
C_loc(sz); /* amount of bytes */
|
|
|
|
C_df_ilb(l_cont);
|
|
|
|
C_dup(word_size);
|
|
|
|
C_zle(l_stop);
|
|
|
|
C_dec();
|
1987-07-16 13:27:37 +00:00
|
|
|
LoadLocal(src, pointer_size);
|
1986-09-29 14:01:34 +00:00
|
|
|
C_dup(pointer_size);
|
|
|
|
C_adp((arith)1);
|
1987-07-16 13:27:37 +00:00
|
|
|
StoreLocal(src, pointer_size);
|
1986-09-29 14:01:34 +00:00
|
|
|
C_loi((arith)1);
|
1987-07-16 13:27:37 +00:00
|
|
|
LoadLocal(dst, pointer_size);
|
1986-09-29 14:01:34 +00:00
|
|
|
C_dup(pointer_size);
|
|
|
|
C_adp((arith)1);
|
1987-07-16 13:27:37 +00:00
|
|
|
StoreLocal(dst, pointer_size);
|
1986-09-29 14:01:34 +00:00
|
|
|
C_sti((arith)1);
|
|
|
|
C_bra(l_cont);
|
|
|
|
C_df_ilb(l_stop);
|
|
|
|
C_asp(word_size);
|
|
|
|
}
|
|
|
|
#endif STB
|
1988-08-19 13:55:22 +00:00
|
|
|
|