Fixed bug relating to FS and MEMORY during startup;
Relocated some syslib functions to utils library; Changed location of 'Multiuser startup ..." echo in /etc/rc
This commit is contained in:
@@ -7,9 +7,6 @@ LIBSYS = ../libsys.a
|
||||
all: $(LIBSYS)
|
||||
|
||||
OBJECTS = \
|
||||
$(LIBSYS)(kmalloc.o) \
|
||||
$(LIBSYS)(kprintf.o) \
|
||||
$(LIBSYS)(kputc.o) \
|
||||
$(LIBSYS)(sys_times.o) \
|
||||
$(LIBSYS)(sys_getuptm.o) \
|
||||
$(LIBSYS)(sys_abort.o) \
|
||||
@@ -50,15 +47,6 @@ $(LIBSYS): $(OBJECTS)
|
||||
aal cr $@ *.o
|
||||
rm *.o
|
||||
|
||||
$(LIBSYS)(kmalloc.o): kmalloc.c
|
||||
$(CC1) kmalloc.c
|
||||
|
||||
$(LIBSYS)(kprintf.o): kprintf.c
|
||||
$(CC1) kprintf.c
|
||||
|
||||
$(LIBSYS)(kputc.o): kputc.c
|
||||
$(CC1) kputc.c
|
||||
|
||||
$(LIBSYS)(sys_times.o): sys_times.c
|
||||
$(CC1) sys_times.c
|
||||
|
||||
|
||||
@@ -1,177 +0,0 @@
|
||||
/* malloc(), realloc(), free() - simple memory allocation routines
|
||||
*
|
||||
* This is a very small and simple minded malloc Author: Kees J. Bot
|
||||
* implementation. Ideal for things like a 29 Jan 1994
|
||||
* bootstrap program, or for debugging. Six times
|
||||
* slower than any good malloc.
|
||||
*/
|
||||
#define nil 0
|
||||
|
||||
#define sbrk _sbrk
|
||||
#include <stddef.h>
|
||||
#include <stdlib.h>
|
||||
#include <unistd.h>
|
||||
#include <string.h>
|
||||
#include <limits.h>
|
||||
#if !DEBUG
|
||||
#define NDEBUG 1
|
||||
#define debug(expr) ((void) 0)
|
||||
#else
|
||||
#define debug(expr) expr
|
||||
#endif
|
||||
#include <assert.h>
|
||||
|
||||
typedef struct cell {
|
||||
size_t size; /* Size of a malloc()'ed object. */
|
||||
#if DEBUG
|
||||
unsigned magic; /* To recognize a cell. */
|
||||
#endif
|
||||
struct cell *next; /* Next cell on the free list. */
|
||||
#if DEBUG
|
||||
unsigned sacred; /* Don't touch while unallocated. */
|
||||
#endif
|
||||
} cell_t;
|
||||
|
||||
#if UINT_MAX <= 0xFFFF
|
||||
#define MAGIC 0x537B
|
||||
#else
|
||||
#define MAGIC 0x537BC0D8
|
||||
#endif
|
||||
|
||||
/* Size of the header of an object. */
|
||||
#define HDR_SIZE offsetof(cell_t, next)
|
||||
|
||||
/* An offset from a cell pointer to a next cell. */
|
||||
#define offset(cp, size) ((cell_t *) ((char *) (cp) + (size)))
|
||||
|
||||
/* Address of the object in a cell and back. */
|
||||
#define cell2obj(cp) ((void *) ((char *) (cp) + HDR_SIZE))
|
||||
#define obj2cell(op) ((cell_t *) ((char *) (op) - HDR_SIZE))
|
||||
|
||||
/* The free list. */
|
||||
static cell_t *freelist;
|
||||
|
||||
void *malloc(size_t size)
|
||||
/* Allocate an object of at least the given size. */
|
||||
{
|
||||
cell_t **pcp, *cp;
|
||||
|
||||
size += HDR_SIZE;
|
||||
if (size < sizeof(cell_t)) size= sizeof(cell_t);
|
||||
|
||||
/* Align to a word. Use a real malloc if you need better alignment. */
|
||||
size= (size + sizeof(int) - 1) & ~(sizeof(int) - 1);
|
||||
|
||||
/* Space for a magic number at the end of the chunk. */
|
||||
debug(size += sizeof(unsigned));
|
||||
|
||||
for (;;) {
|
||||
/* Do a first fit search. */
|
||||
pcp= &freelist;
|
||||
while ((cp= *pcp) != nil) {
|
||||
cell_t *next= cp->next;
|
||||
|
||||
assert(cp->magic == MAGIC);
|
||||
assert(cp->sacred == MAGIC);
|
||||
|
||||
if (offset(cp, cp->size) == next) {
|
||||
/* Join adjacent free cells. */
|
||||
assert(next->magic == MAGIC);
|
||||
assert(next->sacred == MAGIC);
|
||||
|
||||
cp->size+= next->size;
|
||||
cp->next= next->next;
|
||||
|
||||
continue; /* Try again. */
|
||||
}
|
||||
if (size <= cp->size) break; /* Big enough. */
|
||||
|
||||
/* Next cell. */
|
||||
pcp= &cp->next;
|
||||
}
|
||||
|
||||
if (cp != nil) break; /* Found a big enough chunk. */
|
||||
|
||||
/* Allocate a new chunk at the break. */
|
||||
if ((cp= (cell_t *) sbrk(size)) == (cell_t *) -1) {
|
||||
return nil;
|
||||
}
|
||||
|
||||
cp->size= size;
|
||||
cp->next= nil;
|
||||
debug(cp->magic= MAGIC);
|
||||
debug(cp->sacred= MAGIC);
|
||||
*pcp= cp;
|
||||
}
|
||||
|
||||
/* We've got a cell that is big enough. Can we break it up? */
|
||||
if (cp->size >= size + sizeof(cell_t)) {
|
||||
cell_t *next= offset(cp, size);
|
||||
|
||||
next->size= cp->size - size;
|
||||
next->next= cp->next;
|
||||
debug(next->magic= MAGIC);
|
||||
debug(next->sacred= MAGIC);
|
||||
cp->size= size;
|
||||
cp->next= next;
|
||||
}
|
||||
|
||||
/* Unchain the cell we've found and return an address in it. */
|
||||
*pcp= cp->next;
|
||||
debug(memset(cell2obj(cp), 0xAA, cp->size - HDR_SIZE));
|
||||
debug(((unsigned *) offset(cp, cp->size))[-1]= MAGIC);
|
||||
|
||||
return cell2obj(cp);
|
||||
}
|
||||
|
||||
void free(void *op)
|
||||
/* Deallocate an object. */
|
||||
{
|
||||
cell_t **prev, *next, *cp;
|
||||
|
||||
if (op == nil) return; /* Aaargh. */
|
||||
|
||||
cp= obj2cell(op);
|
||||
assert(cp->magic == MAGIC);
|
||||
assert(((unsigned *) offset(cp, cp->size))[-1] == MAGIC);
|
||||
debug(cp->sacred= MAGIC);
|
||||
|
||||
/* Find the spot where the object belongs. */
|
||||
prev= &freelist;
|
||||
while ((next= *prev) != nil && next < cp) {
|
||||
assert(next->magic == MAGIC);
|
||||
assert(next->sacred == MAGIC);
|
||||
prev= &next->next;
|
||||
}
|
||||
|
||||
/* Put the new free cell in the list. */
|
||||
*prev= cp;
|
||||
cp->next= next;
|
||||
|
||||
#if DEBUG
|
||||
/* Check the rest of the list. */
|
||||
while (next != nil) {
|
||||
assert(next->magic == MAGIC);
|
||||
assert(next->sacred == MAGIC);
|
||||
next= next->next;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
void *realloc(void *op, size_t size)
|
||||
/* Change the size of an object. Don't bother being smart, just copy it. */
|
||||
{
|
||||
size_t oldsize;
|
||||
void *new;
|
||||
|
||||
oldsize= op == nil ? 0 : obj2cell(op)->size - HDR_SIZE;
|
||||
|
||||
new= malloc(size);
|
||||
memcpy(new, op, oldsize > size ? size : oldsize);
|
||||
free(op);
|
||||
return new;
|
||||
}
|
||||
|
||||
/*
|
||||
* $PchId: malloc.c,v 1.4 1996/02/22 09:15:56 philip Exp $
|
||||
*/
|
||||
@@ -1,191 +0,0 @@
|
||||
/* printf() - system services printf() Author: Kees J. Bot
|
||||
* 15 Jan 1994
|
||||
*/
|
||||
#define nil 0
|
||||
#include <stdarg.h>
|
||||
#include <stddef.h>
|
||||
#include <limits.h>
|
||||
|
||||
#define isdigit(c) ((unsigned) ((c) - '0') < (unsigned) 10)
|
||||
|
||||
#if !__STDC__
|
||||
/* Classic C stuff, ignore. */
|
||||
void kputc();
|
||||
int printf(fmt) char *fmt;
|
||||
#else
|
||||
|
||||
/* Printf() uses kputc() to print characters. */
|
||||
void kputc(int c);
|
||||
|
||||
#define count_kputc(c) do { charcount++; kputc(c); } while(0)
|
||||
|
||||
int printf(const char *fmt, ...)
|
||||
#endif
|
||||
{
|
||||
int c, charcount = 0;
|
||||
enum { LEFT, RIGHT } adjust;
|
||||
enum { LONG, INT } intsize;
|
||||
int fill;
|
||||
int width, max, len, base;
|
||||
static char X2C_tab[]= "0123456789ABCDEF";
|
||||
static char x2c_tab[]= "0123456789abcdef";
|
||||
char *x2c;
|
||||
char *p;
|
||||
long i;
|
||||
unsigned long u;
|
||||
char temp[8 * sizeof(long) / 3 + 2];
|
||||
|
||||
va_list argp;
|
||||
|
||||
va_start(argp, fmt);
|
||||
|
||||
while ((c= *fmt++) != 0) {
|
||||
if (c != '%') {
|
||||
/* Ordinary character. */
|
||||
count_kputc(c);
|
||||
continue;
|
||||
}
|
||||
|
||||
/* Format specifier of the form:
|
||||
* %[adjust][fill][width][.max]keys
|
||||
*/
|
||||
c= *fmt++;
|
||||
|
||||
adjust= RIGHT;
|
||||
if (c == '-') {
|
||||
adjust= LEFT;
|
||||
c= *fmt++;
|
||||
}
|
||||
|
||||
fill= ' ';
|
||||
if (c == '0') {
|
||||
fill= '0';
|
||||
c= *fmt++;
|
||||
}
|
||||
|
||||
width= 0;
|
||||
if (c == '*') {
|
||||
/* Width is specified as an argument, e.g. %*d. */
|
||||
width= va_arg(argp, int);
|
||||
c= *fmt++;
|
||||
} else
|
||||
if (isdigit(c)) {
|
||||
/* A number tells the width, e.g. %10d. */
|
||||
do {
|
||||
width= width * 10 + (c - '0');
|
||||
} while (isdigit(c= *fmt++));
|
||||
}
|
||||
|
||||
max= INT_MAX;
|
||||
if (c == '.') {
|
||||
/* Max field length coming up. */
|
||||
if ((c= *fmt++) == '*') {
|
||||
max= va_arg(argp, int);
|
||||
c= *fmt++;
|
||||
} else
|
||||
if (isdigit(c)) {
|
||||
max= 0;
|
||||
do {
|
||||
max= max * 10 + (c - '0');
|
||||
} while (isdigit(c= *fmt++));
|
||||
}
|
||||
}
|
||||
|
||||
/* Set a few flags to the default. */
|
||||
x2c= x2c_tab;
|
||||
i= 0;
|
||||
base= 10;
|
||||
intsize= INT;
|
||||
if (c == 'l' || c == 'L') {
|
||||
/* "Long" key, e.g. %ld. */
|
||||
intsize= LONG;
|
||||
c= *fmt++;
|
||||
}
|
||||
if (c == 0) break;
|
||||
|
||||
switch (c) {
|
||||
/* Decimal. */
|
||||
case 'd':
|
||||
i= intsize == LONG ? va_arg(argp, long)
|
||||
: va_arg(argp, int);
|
||||
u= i < 0 ? -i : i;
|
||||
goto int2ascii;
|
||||
|
||||
/* Octal. */
|
||||
case 'o':
|
||||
base= 010;
|
||||
goto getint;
|
||||
|
||||
/* Pointer, interpret as %X or %lX. */
|
||||
case 'p':
|
||||
if (sizeof(char *) > sizeof(int)) intsize= LONG;
|
||||
|
||||
/* Hexadecimal. %X prints upper case A-F, not %lx. */
|
||||
case 'X':
|
||||
x2c= X2C_tab;
|
||||
case 'x':
|
||||
base= 0x10;
|
||||
goto getint;
|
||||
|
||||
/* Unsigned decimal. */
|
||||
case 'u':
|
||||
getint:
|
||||
u= intsize == LONG ? va_arg(argp, unsigned long)
|
||||
: va_arg(argp, unsigned int);
|
||||
int2ascii:
|
||||
p= temp + sizeof(temp)-1;
|
||||
*p= 0;
|
||||
do {
|
||||
*--p= x2c[(ptrdiff_t) (u % base)];
|
||||
} while ((u /= base) > 0);
|
||||
goto string_length;
|
||||
|
||||
/* A character. */
|
||||
case 'c':
|
||||
p= temp;
|
||||
*p= va_arg(argp, int);
|
||||
len= 1;
|
||||
goto string_print;
|
||||
|
||||
/* Simply a percent. */
|
||||
case '%':
|
||||
p= temp;
|
||||
*p= '%';
|
||||
len= 1;
|
||||
goto string_print;
|
||||
|
||||
/* A string. The other cases will join in here. */
|
||||
case 's':
|
||||
p= va_arg(argp, char *);
|
||||
|
||||
string_length:
|
||||
for (len= 0; p[len] != 0 && len < max; len++) {}
|
||||
|
||||
string_print:
|
||||
width -= len;
|
||||
if (i < 0) width--;
|
||||
if (fill == '0' && i < 0) count_kputc('-');
|
||||
if (adjust == RIGHT) {
|
||||
while (width > 0) { count_kputc(fill); width--; }
|
||||
}
|
||||
if (fill == ' ' && i < 0) count_kputc('-');
|
||||
while (len > 0) { count_kputc((unsigned char) *p++); len--; }
|
||||
while (width > 0) { count_kputc(fill); width--; }
|
||||
break;
|
||||
|
||||
/* Unrecognized format key, echo it back. */
|
||||
default:
|
||||
count_kputc('%');
|
||||
count_kputc(c);
|
||||
}
|
||||
}
|
||||
|
||||
/* Mark the end with a null (should be something else, like -1). */
|
||||
kputc(0);
|
||||
va_end(argp);
|
||||
return charcount;
|
||||
}
|
||||
|
||||
/*
|
||||
* $PchId: kprintf.c,v 1.5 1996/04/11 06:59:05 philip Exp $
|
||||
*/
|
||||
@@ -1,47 +0,0 @@
|
||||
/* A server must occasionally print some message. It uses a simple version of
|
||||
* printf() found in the system lib that calls kputc() to output characters.
|
||||
* Printing is done with a call to the kernel, and not by going through FS.
|
||||
* This way system messages end up in the kernel messages buffer and can be
|
||||
* reviewed at a later time.
|
||||
*
|
||||
* This routine can only be used by servers and device drivers. The kernel
|
||||
* must define its own kputc(). Note that the IS also defines its own kputc()
|
||||
* to directly call the TTY instead of the kernel, because it does not want
|
||||
* to pollute the kernel message buffer with its debug dumps.
|
||||
*/
|
||||
|
||||
#include "syslib.h"
|
||||
#include <minix/callnr.h>
|
||||
#include <minix/minlib.h>
|
||||
|
||||
/*===========================================================================*
|
||||
* kputc *
|
||||
*===========================================================================*/
|
||||
void kputc(c)
|
||||
int c;
|
||||
{
|
||||
/* Accumulate another character. If 0 or buffer full, print it. */
|
||||
|
||||
static int buf_count; /* # characters in the buffer */
|
||||
static char print_buf[80]; /* output is buffered here */
|
||||
message m;
|
||||
|
||||
if ((c == 0 && buf_count > 0) || buf_count == sizeof(print_buf)) {
|
||||
/* Send the buffer to the system task, or, if this process is not a
|
||||
* server yet, to standard error.
|
||||
*/
|
||||
m.DIAG_BUF_COUNT = buf_count;
|
||||
m.DIAG_PRINT_BUF = print_buf;
|
||||
m.DIAG_PROC_NR = SELF;
|
||||
m.m_type = DIAGNOSTICS;
|
||||
if (_sendrec(IS_PROC_NR, &m) != 0) {
|
||||
m.m1_i1 = 2;
|
||||
m.m1_i2 = buf_count;
|
||||
m.m1_p1 = print_buf;
|
||||
m.m_type = WRITE;
|
||||
(void) _sendrec(FS, &m);
|
||||
}
|
||||
buf_count = 0;
|
||||
}
|
||||
if (c != 0) print_buf[buf_count++] = c;
|
||||
}
|
||||
Reference in New Issue
Block a user