static void init_heap_space(size_t min_size, size_t max_size) { size_t pagesize, alloc_size, reserve_size, freesize_pre, freesize_post; unsigned int min_num_segments, max_num_segments, bitmap_bits; void *p; pagesize = GetPageSize(); if (SEGMENT_SIZE % pagesize != 0) sml_fatal(0, "SEGMENT_SIZE is not aligned in page size."); alloc_size = ALIGNSIZE(min_size, SEGMENT_SIZE); reserve_size = ALIGNSIZE(max_size, SEGMENT_SIZE); if (alloc_size < SEGMENT_SIZE) alloc_size = SEGMENT_SIZE; if (reserve_size < alloc_size) reserve_size = alloc_size; min_num_segments = alloc_size / SEGMENT_SIZE; max_num_segments = reserve_size / SEGMENT_SIZE; p = ReservePage(HEAP_BEGIN_ADDR, SEGMENT_SIZE + reserve_size); if (p == ReservePageError) sml_fatal(0, "failed to alloc virtual memory."); freesize_post = (uintptr_t)p & (SEGMENT_SIZE - 1); if (freesize_post == 0) { ReleasePage(p + reserve_size, SEGMENT_SIZE); } else { freesize_pre = SEGMENT_SIZE - freesize_post; ReleasePage(p, freesize_pre); p = (char*)p + freesize_pre; ReleasePage(p + reserve_size, freesize_post); } heap_space.begin = p; heap_space.end = (char*)p + reserve_size; heap_space.min_num_segments = min_num_segments; heap_space.max_num_segments = max_num_segments; heap_space.num_committed = 0; heap_space.extend_step = min_num_segments > 0 ? min_num_segments : 1; bitmap_bits = ALIGNSIZE(max_num_segments, BITPTR_WORDBITS); heap_space.bitmap = xmalloc(bitmap_bits / CHAR_BIT); memset(heap_space.bitmap, 0, bitmap_bits / CHAR_BIT); extend_heap(min_num_segments); }
/** * Initialize matrix structure and allocate space for elements. * * @param [in,out] m * On entry uninitialized matrix. On exit initialized matrix with space allocated * for elements. * @param [in] r * Number of rows * @param [in] c * Number of columns * * If number of rows or columns is zero, no space is allocated but matrix * is properly initialized to zero size. * * @return Pointer to initialized matrix. * \ingroup matrix */ armas_x_dense_t *armas_x_init(armas_x_dense_t *m, int r, int c) { int doff; if (r <= 0 || c <= 0) { m->rows = 0; m->cols = 0; m->step = 0; m->elems = (DTYPE *)0; m->__data = (void *)0; m->__nbytes = 0; return m; } // set first to adjusted element count m->__nbytes = ALIGNSIZE(r*c, DTYPE); m->__data = calloc(m->__nbytes, sizeof(DTYPE)); if ( !m->__data ) { m->__nbytes = 0; return (armas_x_dense_t *)0; } // convert to number of bytes m->__nbytes *= sizeof(DTYPE); m->rows = r; m->cols = c; m->step = r; doff = ALIGNOFFSET(m->__data); m->elems = (DTYPE *)&((unsigned char *)m->__data)[doff]; return m; }
int main(int argc, char* argv[]) { int fd; int text_start_addr/*, data_start_addr, init32_size*/; struct stat st; char buf[PATH_MAX*4]; if(argc != 5) { printf("binit32 $(LD) $(srcdir)/init32.lds init32.o decom.o"); exit(1); } if((fd = open("init16", O_RDWR)) == -1) { perror("open init16 fault:"); exit(1); } fstat(fd, &st); close(fd); text_start_addr = st.st_size; ALIGNSIZE(text_start_addr); text_start_addr += CFG_KERNEL_OSKERNELSYS_PADDR; /* sprintf(buf, "%s -T %s/init32.lds -Ttext 0x%x -o init32 init32.o decom.o\n", getenv("LD"), getenv("srcdir"), text_start_addr);*/ sprintf(buf, "%s -T %s -Ttext 0x%x -o init32 %s %s\n", argv[1], argv[2], text_start_addr, argv[3], argv[4]); printf(buf); return system(buf); return 0; }
/* ** 'push_float' pushes a floating point value on to the Basic stack */ void push_float(float64 x) { basicvars.stacktop.bytesp-=ALIGNSIZE(stack_float); basicvars.stacktop.floatsp->itemtype = STACK_FLOAT; basicvars.stacktop.floatsp->floatvalue = x; #ifdef DEBUG if (basicvars.debug_flags.allstack) fprintf(stderr, "Push floating point value on to stack at %p, value %g\n", basicvars.stacktop.floatsp, x); #endif }
/* ** 'push_int' pushes an integer value on to the Basic stack */ void push_int(int32 x) { basicvars.stacktop.bytesp-=ALIGNSIZE(stack_int); basicvars.stacktop.intsp->itemtype = STACK_INT; basicvars.stacktop.intsp->intvalue = x; #ifdef DEBUG if (basicvars.debug_flags.allstack) fprintf(stderr, "Push integer value on to stack at %p, value %d\n", basicvars.stacktop.intsp, x); #endif }
/* ** 'pop_error' removes an 'ON ERROR' control block from the stack ** and returns the error block it contained */ errorblock pop_error(void) { stack_error *p = basicvars.stacktop.errorsp; #ifdef DEBUG if (basicvars.debug_flags.stack) fprintf(stderr, "Discard 'ERROR' block at %p\n", p); #endif basicvars.stacktop.bytesp+=ALIGNSIZE(stack_error); return p->handler; }
/* ** 'pop_data' removes a stored 'DATA' pointer value from the stack ** and returns the value of the pointer */ byte *pop_data(void) { stack_data *p = basicvars.stacktop.datasp; #ifdef DEBUG if (basicvars.debug_flags.stack) fprintf(stderr, "Discard 'DATA' block at %p\n", p); #endif basicvars.stacktop.bytesp+=ALIGNSIZE(stack_data); return p->address; }
/* ** 'pop_arraytemp' removes a temporary array descriptor from thr ** Basic stack and returns it to the calling program */ basicarray pop_arraytemp(void) { stack_arraytemp *p = basicvars.stacktop.arraytempsp; #ifdef DEBUG if (basicvars.debug_flags.allstack) fprintf(stderr, "Pop temporary array block at %p\n", p); #endif basicvars.stacktop.bytesp+=ALIGNSIZE(stack_arraytemp); return p->descriptor; }
static void chunk_alloc(sml_obstack_t **obstack, size_t objsize) { size_t head_size, chunk_size; sml_obstack_t *newchunk; head_size = ALIGNSIZE(sizeof(struct sml_obstack), objsize); chunk_size = objsize + head_size; chunk_size = ALIGNSIZE(chunk_size, MINCHUNKSIZE); newchunk = xmalloc(chunk_size); newchunk->next = *obstack; newchunk->start = (char*)newchunk + head_size; newchunk->end = (char*)newchunk + chunk_size; newchunk->free = newchunk->start; newchunk->base = newchunk->start; *obstack = newchunk; }
/* ** 'push_arraytemp' pushes a descriptor for a temporary array on ** to the Basic stack. As this is a temporary array, the entire ** descriptor is copied on to the stack rather than just a pointer ** to it */ void push_arraytemp(basicarray *descriptor, int32 type) { basicvars.stacktop.bytesp-=ALIGNSIZE(stack_arraytemp); basicvars.stacktop.arraytempsp->itemtype = arraytemptype[type & TYPEMASK]; basicvars.stacktop.arraytempsp->descriptor = *descriptor; #ifdef DEBUG if (basicvars.debug_flags.allstack) fprintf(stderr, "Push temp array descriptor block at %p\n", basicvars.stacktop.arraytempsp); #endif }
/* ** 'push_string' copies a string descriptor on to the Basic stack */ void push_string(basicstring x) { basicvars.stacktop.bytesp-=ALIGNSIZE(stack_string); basicvars.stacktop.stringsp->itemtype = STACK_STRING; basicvars.stacktop.stringsp->descriptor = x; #ifdef DEBUG if (basicvars.debug_flags.allstack) fprintf(stderr, "Push string value on to stack at %p, address %p, length %d\n", basicvars.stacktop.stringsp, x.stringaddr, x.stringlen); #endif }
/* ** 'make_restart' creates an entry on the Basic stack for the ** environment block used by 'longjmp' when handling errors when ** an 'ON ERROR LOCAL' has been executed. It returns a pointer to ** the block for the longjmp's 'jmp_buf' structure */ jmp_buf *make_restart(void) { basicvars.stacktop.bytesp-=ALIGNSIZE(stack_restart); if (basicvars.stacktop.bytesp<basicvars.stacklimit.bytesp) error(ERR_STACKFULL); basicvars.stacktop.restartsp->itemtype = STACK_RESTART; #ifdef DEBUG if (basicvars.debug_flags.stack) fprintf(stderr, "Create restart block at %p\n", basicvars.stacktop.bytesp); #endif return &basicvars.stacktop.restartsp->restart; }
/* ** 'make_opstack' is called to create a new operator stack. It also ** checks that there is enough room on the Basic stack to hold ** 'OPSTACKSIZE' numeric or string entries. It returns a pointer to ** the base of the stack */ int32 *make_opstack(void) { basicvars.stacktop.bytesp-=ALIGNSIZE(stack_opstack); if (basicvars.stacktop.bytesp-OPSTACKSIZE*LARGEST_ENTRY<basicvars.stacklimit.bytesp) error(ERR_STACKFULL); basicvars.stacktop.opstacksp->itemtype = STACK_OPSTACK; #ifdef DEBUG if (basicvars.debug_flags.stack) fprintf(stderr, "Create operator stack at %p\n", basicvars.stacktop.bytesp); #endif return &basicvars.stacktop.opstacksp->opstack[0]; }
/* ** 'pop_gosub' removes a GOSUB return control block from the Basic stack. ** It updates the GOSUB call chain as well */ gosubinfo pop_gosub(void) { stack_gosub *p = basicvars.stacktop.gosubsp; #ifdef DEBUG if (basicvars.debug_flags.stack) fprintf(stderr, "Discard 'GOSUB' block at %p\n", p); #endif basicvars.gosubstack = p->gosublock.lastcall; basicvars.stacktop.bytesp+=ALIGNSIZE(stack_gosub); return p->gosublock; }
/* ** 'pop_proc' removes a procedure return control block from the Basic ** stack, updating the procedure/function call chain as well */ fnprocinfo pop_proc(void) { stack_proc *p = basicvars.stacktop.procsp; #ifdef DEBUG if (basicvars.debug_flags.stack) fprintf(stderr, "Discard 'PROC' block at %p\n", p); #endif basicvars.procstack = p->fnprocblock.lastcall; basicvars.stacktop.bytesp+=ALIGNSIZE(stack_proc); return p->fnprocblock; }
/* ** 'pop_string' pops a string descriptor from the Basic stack */ basicstring pop_string(void) { stack_string *p = basicvars.stacktop.stringsp; #ifdef DEBUG if (basicvars.debug_flags.allstack) fprintf(stderr, "Pop string from stack at %p, address %p, length %d\n", p, p->descriptor.stringaddr, p->descriptor.stringlen); #endif basicvars.stacktop.bytesp+=ALIGNSIZE(stack_string); return p->descriptor; }
/* ** 'pop_int' pops an integer from the Basic stack */ int32 pop_int(void) { stack_int *p = basicvars.stacktop.intsp; #ifdef DEBUG if (basicvars.debug_flags.allstack) fprintf(stderr, "Pop integer from stack at %p, value %d\n", p, p->intvalue); #endif basicvars.stacktop.bytesp+=ALIGNSIZE(stack_int); return p->intvalue; }
/* ** 'pop_float' pops a floating point value from the Basic stack */ float64 pop_float(void) { stack_float *p = basicvars.stacktop.floatsp; #ifdef DEBUG if (basicvars.debug_flags.allstack) fprintf(stderr, "Pop floating point value from stack at %p, value %g\n", p, p->floatvalue); #endif basicvars.stacktop.bytesp+=ALIGNSIZE(stack_float); return p->floatvalue; }
/* ** 'push_error' creates a control block on the stack for a Basic ** error handler */ void push_error(errorblock handler) { basicvars.stacktop.bytesp-=ALIGNSIZE(stack_error); if (basicvars.stacktop.bytesp<basicvars.stacklimit.bytesp) error(ERR_STACKFULL); basicvars.stacktop.errorsp->itemtype = STACK_ERROR; basicvars.stacktop.errorsp->handler = handler; #ifdef DEBUG if (basicvars.debug_flags.stack) fprintf(stderr, "Create saved 'ON ERROR' block at %p\n", basicvars.stacktop.errorsp); #endif }
/* ** 'push_data' is called to save the current value of the 'DATA' ** pointer on the Basic stack */ void push_data(byte *address) { basicvars.stacktop.bytesp-=ALIGNSIZE(stack_data); if (basicvars.stacktop.bytesp<basicvars.stacklimit.bytesp) error(ERR_STACKFULL); basicvars.stacktop.datasp->itemtype = STACK_DATA; basicvars.stacktop.datasp->address = address; #ifdef DEBUG if (basicvars.debug_flags.stack) fprintf(stderr, "Create saved 'DATA' block at %p\n", basicvars.stacktop.datasp); #endif }
/* ** 'push_repeat' creates a control block on the Basic stack for a 'REPEAT' loop */ void push_repeat(void) { basicvars.stacktop.bytesp-=ALIGNSIZE(stack_repeat); if (basicvars.stacktop.bytesp<basicvars.stacklimit.bytesp) error(ERR_STACKFULL); basicvars.stacktop.repeatsp->itemtype = STACK_REPEAT; basicvars.stacktop.repeatsp->repeataddr = basicvars.current; #ifdef DEBUG if (basicvars.debug_flags.stack) fprintf(stderr, "Create 'REPEAT' block at %p\n", basicvars.stacktop.repeatsp); #endif }
/* ** 'push_while' creates a control block on the Basic stack for a 'WHILE' loop */ void push_while(byte *expr) { basicvars.stacktop.bytesp-=ALIGNSIZE(stack_while); if (basicvars.stacktop.bytesp<basicvars.stacklimit.bytesp) error(ERR_STACKFULL); basicvars.stacktop.whilesp->itemtype = STACK_WHILE; basicvars.stacktop.whilesp->whilexpr = expr; basicvars.stacktop.whilesp->whileaddr = basicvars.current; #ifdef DEBUG if (basicvars.debug_flags.stack) fprintf(stderr, "Create 'WHILE' block at %p\n", basicvars.stacktop.whilesp); #endif }
/* ** 'push_strtemp' creates a string descriptor on the Basic stack for an ** 'intermediate value' string, that is, a string created as a result of a ** string operation such as 'STRING$'. */ void push_strtemp(int32 stringlen, char *stringaddr) { basicvars.stacktop.bytesp-=ALIGNSIZE(stack_string); basicvars.stacktop.stringsp->itemtype = STACK_STRTEMP; basicvars.stacktop.stringsp->descriptor.stringlen = stringlen; basicvars.stacktop.stringsp->descriptor.stringaddr = stringaddr; #ifdef DEBUG if (basicvars.debug_flags.allstack) fprintf(stderr, "Push string temp on to stack at %p, address %p, length %d\n", basicvars.stacktop.stringsp, stringaddr, stringlen); #endif }
/* ** 'push_dolstring' is called to push a reference to a '$<string>' ** type of string on to the Basic stack. It creates a descriptor ** for the string and copies that on to the stack */ void push_dolstring(int32 strlength, char *strtext) { basicvars.stacktop.bytesp-=ALIGNSIZE(stack_string); basicvars.stacktop.stringsp->itemtype = STACK_STRING; basicvars.stacktop.stringsp->descriptor.stringlen = strlength; basicvars.stacktop.stringsp->descriptor.stringaddr = strtext; #ifdef DEBUG if (basicvars.debug_flags.allstack) fprintf(stderr, "Push $<string> string on to stack at %p, address %p, length %d\n", basicvars.stacktop.stringsp, strtext, strlength); #endif }
/* ** 'push_gosub' pushes a 'GOSUB' return block on to the Basic stack */ void push_gosub(void) { basicvars.stacktop.bytesp-=ALIGNSIZE(stack_gosub); if (basicvars.stacktop.bytesp<basicvars.stacklimit.bytesp) error(ERR_STACKFULL); basicvars.stacktop.gosubsp->itemtype = STACK_GOSUB; basicvars.stacktop.gosubsp->gosublock.lastcall = basicvars.gosubstack; basicvars.stacktop.gosubsp->gosublock.retaddr = basicvars.current; basicvars.gosubstack = &basicvars.stacktop.gosubsp->gosublock; #ifdef DEBUG if (basicvars.debug_flags.stack) fprintf(stderr, "Saving GOSUB return block at %p\n", basicvars.stacktop.gosubsp); #endif }
void sml_obstack_align(sml_obstack_t **obstack, size_t size) { size_t offset; if (*obstack) { offset = (*obstack)->base - (char*)(*obstack); sml_obstack_blank(obstack, ALIGNSIZE(offset, size) - offset); (*obstack)->base = (*obstack)->free; } }
/* ** save_array is called to save an array descriptor on the stack when * creating a local array */ void save_array(lvalue details) { basicvars.stacktop.bytesp-=ALIGNSIZE(stack_local); if (basicvars.stacktop.bytesp<basicvars.stacklimit.bytesp) error(ERR_STACKFULL); basicvars.stacktop.localsp->itemtype = STACK_LOCAL; basicvars.stacktop.localsp->savedetails = details; basicvars.stacktop.localsp->value.savedarray = *details.address.arrayaddr; #ifdef DEBUG if (basicvars.debug_flags.stack) fprintf(stderr, "LOCAL variable - saving array dimensions from %p at %p\n", details.address.arrayaddr, basicvars.stacktop.localsp); #endif }
/* ** 'save_string' saves a string descriptor on the stack. It is used when ** dealing with local variables. ** Note that the string descriptor is passed separately as the address ** given in 'details' as the home of the string descriptor is in fact the ** address of the string itself in the case of '$<string>' type strings. ** In this case the descriptor represents the place at which the string ** has been saved */ void save_string(lvalue details, basicstring thestring) { basicvars.stacktop.bytesp-=ALIGNSIZE(stack_local); if (basicvars.stacktop.bytesp<basicvars.stacklimit.bytesp) error(ERR_STACKFULL); basicvars.stacktop.localsp->itemtype = STACK_LOCAL; basicvars.stacktop.localsp->savedetails = details; basicvars.stacktop.localsp->value.savedstring = thestring; #ifdef DEBUG if (basicvars.debug_flags.stack) fprintf(stderr, "LOCAL variable - saving string from %p at %p\n", details.address.straddr, basicvars.stacktop.localsp); #endif }
/* ** 'save_float' saves a floating point value on the stack. It is used when ** dealing with local variables */ void save_float(lvalue details, float64 floatvalue) { basicvars.stacktop.bytesp-=ALIGNSIZE(stack_local); if (basicvars.stacktop.bytesp<basicvars.stacklimit.bytesp) error(ERR_STACKFULL); basicvars.stacktop.localsp->itemtype = STACK_LOCAL; basicvars.stacktop.localsp->savedetails = details; basicvars.stacktop.localsp->value.savedfloat = floatvalue; #ifdef DEBUG if (basicvars.debug_flags.stack) fprintf(stderr, "LOCAL variable - saving floating point value from %p at %p\n", details.address.floataddr, basicvars.stacktop.localsp); #endif }
/* ** 'pop_fn' removes a function return control block from the Basic stack, ** updating the procedure/function call chain as well */ fnprocinfo pop_fn(void) { stack_fn *p = basicvars.stacktop.fnsp; #ifdef DEBUG if (basicvars.debug_flags.stack) fprintf(stderr, "Discard 'FN' block at %p, restart = %p\n", p, p->lastrestart); #endif basicvars.opstop = p->lastopstop; basicvars.opstlimit = p->lastopstlimit; basicvars.local_restart = p->lastrestart; basicvars.procstack = p->fnprocblock.lastcall; basicvars.stacktop.bytesp+=ALIGNSIZE(stack_fn); return p->fnprocblock; }