1988-06-22 16:57:09 +00:00
|
|
|
/*
|
|
|
|
Memory access facilities
|
|
|
|
*/
|
|
|
|
|
1994-06-24 11:31:16 +00:00
|
|
|
/* $Id$ */
|
1988-06-22 16:57:09 +00:00
|
|
|
|
Cut down some clang warnings
Edit C code to reduce warnings from clang. Most warnings are for
implicit declarations of functions, but some warnings want me to add
parentheses or curly braces, or to cast arguments for printf().
Make a few other changes, like declaring float_cst() in h/con_float to
be static, and using C99 bool in ego/ra/makeitems.c and
ego/share/makecldef.c. Such changes don't silence warnings; I make
such changes while I silence warnings in the same file. In
float_cst(), rename parameter `str` to `float_str`, so it doesn't
share a name with the global variable `str`.
Remove `const` from `newmodule(const char *)` in mach/proto/as to
silence a warning. I wrongly added the `const` in d347207.
For warnings about implicit declarations of functions, the fix is to
declare the function before calling it. For example, my OpenBSD
system needs <sys/wait.h> to declare wait().
In util/int, add "whatever.h" to declare more functions. Remove old
declarations from "mem.h", to prefer the newer declarations of the
same functions in "data.h" and "stack.h".
2019-10-23 20:06:36 +00:00
|
|
|
#include "data.h"
|
2019-03-17 14:42:00 +00:00
|
|
|
#include "stack.h"
|
1988-06-22 16:57:09 +00:00
|
|
|
|
|
|
|
/******** Memory address & location defines ********/
|
|
|
|
|
|
|
|
#define data_loc(a) (*(data + (p2i(a))))
|
1989-11-13 15:36:12 +00:00
|
|
|
#define stack_loc(a) (*(stackML - (a)))
|
1988-06-22 16:57:09 +00:00
|
|
|
#define mem_loc(a) (in_stack(a) ? stack_loc(a) : data_loc(a))
|
|
|
|
|
|
|
|
#define loc_addr(o) (((o) < 0) ? (LB + (o)) : (AB + (o)))
|
|
|
|
|
|
|
|
|
|
|
|
/******** Checks on adresses and ranges ********/
|
|
|
|
|
|
|
|
#define is_aligned(a,n) ((p2i(a)) % (n) == 0)
|
1989-11-22 13:38:37 +00:00
|
|
|
#define is_wordaligned(a) \
|
|
|
|
(((p2i(a)) & wsizem1) == 0)
|
1988-06-22 16:57:09 +00:00
|
|
|
|
|
|
|
#define ch_aligned(a,n) { if (!is_aligned(a, min(n, wsize))) \
|
|
|
|
{ trap(EBADPTR); } }
|
1989-11-22 13:38:37 +00:00
|
|
|
#define ch_wordaligned(a) \
|
|
|
|
{ if (!is_wordaligned(a)) \
|
1989-11-13 15:36:12 +00:00
|
|
|
{ trap(EBADPTR); } }
|
1988-06-22 16:57:09 +00:00
|
|
|
|
|
|
|
#define in_gda(p) ((p) < HB)
|
|
|
|
#define in_stack(p) (SP <= (p) && (p) <= ML)
|
|
|
|
|
|
|
|
#define is_in_data(a,n) ((a) + (n) <= HP)
|
|
|
|
#define ch_in_data(a,n) { if (!is_in_data(a, n)) { trap(EMEMFLT); } }
|
|
|
|
|
|
|
|
#define is_in_stack(a,n) (SP <= (a) && (a) + (n) - 1 <= ML)
|
|
|
|
#define ch_in_stack(a,n) { if (!is_in_stack(a, n)) { trap(EMEMFLT); } }
|
|
|
|
|
1989-11-22 13:38:37 +00:00
|
|
|
#define w_is_in_stack(a) (SP <= (a) && (a) + wsizem1 <= ML)
|
|
|
|
#define ch_w_in_stack(a) { if (!w_is_in_stack(a)) { trap(EMEMFLT); } }
|
|
|
|
|
1988-06-22 16:57:09 +00:00
|
|
|
#define is_in_FRA(a,n) ((a) + (n) <= FRASize)
|
|
|
|
|
|
|
|
|
|
|
|
/******* Address-depending memory defines *******/
|
|
|
|
|
|
|
|
#define is_in_mem(a,n) (is_in_data(a, n) || is_in_stack(a, n))
|
|
|
|
|
|
|
|
#define mem_stn(a,l,n) { if (in_stack(a)) st_stn(a, l, n); else dt_stn(a, l, n); }
|
|
|
|
|
|
|
|
#define mem_lddp(a) (in_stack(a) ? st_lddp(a) : dt_lddp(a))
|
|
|
|
#define mem_ldip(a) (in_stack(a) ? st_ldip(a) : dt_ldip(a))
|
|
|
|
#define mem_ldu(a,n) (in_stack(a) ? st_ldu(a, n) : dt_ldu(a, n))
|
1989-11-22 13:38:37 +00:00
|
|
|
#define mem_lduw(a) (in_stack(a) ? st_lduw(a) : dt_lduw(a))
|
1988-06-22 16:57:09 +00:00
|
|
|
#define mem_lds(a,n) (in_stack(a) ? st_lds(a, n) : dt_lds(a, n))
|
1989-11-22 13:38:37 +00:00
|
|
|
#define mem_ldsw(a) (in_stack(a) ? st_ldsw(a) : dt_ldsw(a))
|
1988-06-22 16:57:09 +00:00
|
|
|
|
|
|
|
#define push_m(a,n) { if (in_stack(a)) push_st(a, n); else push_dt(a, n); }
|
1989-11-22 13:38:37 +00:00
|
|
|
#define pushw_m(a) { if (in_stack(a)) pushw_st(a); else pushw_dt(a); }
|
1988-06-22 16:57:09 +00:00
|
|
|
#define pop_m(a,n) { if (in_stack(a)) pop_st(a, n); else pop_dt(a, n); }
|
1989-11-22 13:38:37 +00:00
|
|
|
#define popw_m(a) { if (in_stack(a)) popw_st(a); else popw_dt(a); }
|
1988-06-22 16:57:09 +00:00
|
|
|
|
|
|
|
|
|
|
|
/******** Simple stack manipulation ********/
|
|
|
|
|
|
|
|
#define st_inc(n) newSP(SP - (n)) /* stack grows */
|
|
|
|
#define st_dec(n) newSP(SP + (n)) /* stack shrinks */
|