From 33d9436dd4dc2a94ea71a01a6ba23ffc8e48867c Mon Sep 17 00:00:00 2001 From: mellvik Date: Tue, 19 Nov 2024 14:17:33 +0100 Subject: [PATCH 1/4] [kernel,cmd] heap fix, meminfo update --- tlvc/include/linuxmt/heap.h | 16 ++--- tlvc/lib/heap.c | 105 +++++++++++++++--------------- tlvccmd/sys_utils/Makefile | 4 +- tlvccmd/sys_utils/meminfo.c | 123 ++++++++++++++++++++++++------------ 4 files changed, 146 insertions(+), 102 deletions(-) diff --git a/tlvc/include/linuxmt/heap.h b/tlvc/include/linuxmt/heap.h index b9a922ad5..103ae3f89 100644 --- a/tlvc/include/linuxmt/heap.h +++ b/tlvc/include/linuxmt/heap.h @@ -23,10 +23,10 @@ #define HEAP_TAG_TASK 0x04 #define HEAP_TAG_BUFHEAD 0x05 #define HEAP_TAG_PIPE 0x06 -#define HEAP_TAG_NETWORK 0x07 /* packet buffer allocations */ -#define HEAP_TAG_INDOE 0x08 +#define HEAP_TAG_INODE 0x07 +#define HEAP_TAG_FILE 0x08 #define HEAP_TAG_CACHE 0x09 -#define HEAP_TAG_FILE 0x0A +#define HEAP_TAG_NETWORK 0x0A /* packet buffer allocations */ // TODO: move free list node from header to body @@ -48,14 +48,14 @@ extern list_s _heap_all; // Heap functions -void * heap_alloc (word_t size, byte_t tag); -void heap_free (void * data); +void *heap_alloc(word_t size, byte_t tag); +void heap_free(void *data); -void heap_add (void * data, word_t size); -void heap_init (); +void heap_add(void *data, word_t size); +void heap_init(); #ifdef HEAP_DEBUG -void heap_iterate (void (* cb) (heap_s * h)); +void heap_iterate(void (*cb)(heap_s *h)); #endif /* HEAP_DEBUG */ #endif diff --git a/tlvc/lib/heap.c b/tlvc/lib/heap.c index 85d7156b8..5bf9c827f 100644 --- a/tlvc/lib/heap.c +++ b/tlvc/lib/heap.c @@ -4,22 +4,23 @@ #include #include #include -//#include // Minimal block size to hold heap header // plus enough space in body to be useful // (= size of the smallest allocation) #define HEAP_MIN_SIZE (sizeof (heap_s) + 16) -#define HEAP_SEG_OPT /* allocate small SEG descriptors from the uppper */ +#define HEAP_SEG_OPT /* allocate small SEG descriptors from the upper */ /* end of the heap to reduce fragmentation */ -// Heap root +#define HEAP_DEBUG 0 +#if HEAP_DEBUG +#define debug_heap printk +#else +#define debug_heap(...) +#endif -// locks not needed unless SMP or reentrant kernel -//static lock_t _heap_lock; -#define WAIT_LOCK(lockp) -#define EVENT_UNLOCK(lockp) +// Heap root list_s _heap_all; static list_s _heap_free; @@ -27,8 +28,8 @@ static list_s _heap_free; #ifdef HEAP_SEG_OPT static heap_s *high_free; /* keep track of the free segment at the high end of the heap */ -// allocate a SEG descriptor from the end of the free block at the end of the heap -// to keep these descriptors from fragmenting the main part of the heap. +// allocate a SEG descriptor from the end of the free block at the high end of the heap +// to keep these descriptors from fragmenting the 'main' part of the heap. static heap_s *heap_rsplit(word_t size0) { @@ -39,7 +40,7 @@ static heap_s *heap_rsplit(word_t size0) h1->size -= size0 + sizeof(heap_s); list_insert_after(&(h1->all), &(h2->all)); - //printk("rsplit 1:%x/%d - 2:%x/%d\n", h1, h1->size, h2, h2->size); + debug_heap("rsplit 1:%x/%u - 2:%x/%u\n", h1, h1->size, h2, h2->size); return h2; } #endif @@ -53,7 +54,7 @@ static void heap_split(heap_s *h1, word_t size0) if (size2 >= HEAP_MIN_SIZE) { h1->size = size0; - heap_s *h2 = (heap_s *) ((byte_t *) (h1 + 1) + size0); + heap_s *h2 = (heap_s *)((byte_t *)(h1 + 1) + size0); h2->size = size2 - sizeof(heap_s); h2->tag = HEAP_TAG_FREE; @@ -61,7 +62,7 @@ static void heap_split(heap_s *h1, word_t size0) list_insert_after(&(h1->free), &(h2->free)); #ifdef HEAP_SEG_OPT if (h1 == high_free) high_free = h2; - //printk("heap_split 1:%x/%d - 2:%x/%d hf %x\n", h1, h1->size, h2, h2->size, high_free); + debug_heap("heap_split 1:%x/%u - 2:%x/%u hf %x\n", h1, h1->size, h2, h2->size, high_free); #endif } } @@ -78,13 +79,13 @@ static heap_s *free_get(word_t size0, byte_t tag) list_s *n = _heap_free.next; while (n != &_heap_free) { - heap_s * h = structof (n, heap_s, free); - word_t size1 = h->size; + heap_s *h = structof(n, heap_s, free); + word_t size1 = h->size; if ((h->tag == HEAP_TAG_FREE) && (size1 >= size0) && (size1 < best_size)) { best_h = h; best_size = size1; - //printk("get: %x/%d/%d; ", h, size0, size1); + debug_heap("get: %x/%u/%u; ", h, size0, size1); if (size1 == size0) break; } @@ -106,7 +107,7 @@ static heap_s *free_get(word_t size0, byte_t tag) best_h->tag = HEAP_TAG_USED | tag; } #ifdef HEAP_SEG_OPT - //printk("highfree: %x/%d\n", high_free, high_free->size); + debug_heap("highfree: %x/%u, tag 0x%x\n", high_free, high_free->size, tag); #endif return best_h; @@ -114,10 +115,10 @@ static heap_s *free_get(word_t size0, byte_t tag) // Merge two contiguous blocks -static void heap_merge (heap_s * h1, heap_s * h2) +static void heap_merge(heap_s *h1, heap_s *h2) { - h1->size = h1->size + sizeof (heap_s) + h2->size; - list_remove (&(h2->all)); + h1->size = h1->size + sizeof(heap_s) + h2->size; + list_remove(&(h2->all)); } @@ -125,7 +126,6 @@ static void heap_merge (heap_s * h1, heap_s * h2) void *heap_alloc(word_t size, byte_t tag) { - WAIT_LOCK(&_heap_lock); heap_s *h = free_get(size, tag); if (h) { h++; // skip header @@ -133,34 +133,33 @@ void *heap_alloc(word_t size, byte_t tag) memset(h, 0, size); } if (!h) printk("HEAP: no memory (%u bytes)\n", size); - EVENT_UNLOCK(&_heap_lock); return h; } // Free block -void heap_free (void * data) +void heap_free(void *data) { - WAIT_LOCK (&_heap_lock); - heap_s * h = ((heap_s *) (data)) - 1; // back to header + heap_s *h = ((heap_s *)(data)) - 1; // back to header // Free block will be inserted to free list: // - tail if merged to previous or next free block // - head if still alone to increase 'exact hit' // chance on next allocation of same size - list_s * i = &_heap_free; + list_s *i = &_heap_free; + debug_heap("free 0x%x/%u; ", h, h->size); // Try to merge with previous block if free - list_s * p = h->all.prev; + list_s *p = h->all.prev; if (&_heap_all != p) { - heap_s * prev = structof (p, heap_s, all); + heap_s *prev = structof(p, heap_s, all); if (prev->tag == HEAP_TAG_FREE) { - list_remove (&(prev->free)); - heap_merge (prev, h); + list_remove(&(prev->free)); + heap_merge(prev, h); i = _heap_free.prev; h = prev; } else { @@ -170,12 +169,12 @@ void heap_free (void * data) // Try to merge with next block if free - list_s * n = h->all.next; + list_s *n = h->all.next; if (n != &_heap_all) { - heap_s * next = structof (n, heap_s, all); + heap_s *next = structof(n, heap_s, all); if (next->tag == HEAP_TAG_FREE) { - list_remove (&(next->free)); - heap_merge (h, next); + list_remove(&(next->free)); + heap_merge(h, next); i = _heap_free.prev; #ifdef HEAP_SEG_OPT if (high_free == next) high_free = h; @@ -185,54 +184,56 @@ void heap_free (void * data) // Insert to free list head or tail - list_insert_after (i, &(h->free)); + list_insert_after(i, &(h->free)); - EVENT_UNLOCK (&_heap_lock); } // Add space to heap -void heap_add (void * data, word_t size) +void heap_add(void *data, word_t size) { if (size >= HEAP_MIN_SIZE) { - WAIT_LOCK (&_heap_lock); - heap_s * h = (heap_s *) data; - h->size = size - sizeof (heap_s); + heap_s *h = (heap_s *)data; + h->size = size - sizeof(heap_s); h->tag = HEAP_TAG_FREE; // Add large block to tails of both lists // as almost no chance for 'exact hit' - list_insert_before (&_heap_all, &(h->all)); - list_insert_before (&_heap_free, &(h->free)); + list_insert_before(&_heap_all, &(h->all)); + list_insert_before(&_heap_free, &(h->free)); #ifdef HEAP_SEG_OPT - high_free = h; + if (!high_free) high_free = h; /* only when heap is created */ + /* ie. ignore later additioons to the heap */ + debug_heap("new hf @ %x size %u\n", h, size); #endif - EVENT_UNLOCK (&_heap_lock); } } // Initialize heap -void heap_init () +void heap_init() { - list_init (&_heap_all); - list_init (&_heap_free); + list_init(&_heap_all); + list_init(&_heap_free); } -// Dump heap +#ifdef HEAP_DEBUG_UNUSED -#ifdef HEAP_DEBUG +static void heap_cb(heap_s *h) +{ + printk ("heap:%Xh:%u:%hxh\n",h, h->size, h->tag); +} -void heap_iterate (void (* cb) (heap_s *)) +void heap_iterate(void (*cb)(heap_s *)) { - list_s * n = _heap_all.next; + list_s *n = _heap_all.next; while (n != &_heap_all) { - heap_s * h = structof (n, heap_s, all); - (*cb) (h); + heap_s *h = structof(n, heap_s, all); + (*cb)(h); n = h->all.next; } } diff --git a/tlvccmd/sys_utils/Makefile b/tlvccmd/sys_utils/Makefile index 2272a88dd..c20b11a25 100644 --- a/tlvccmd/sys_utils/Makefile +++ b/tlvccmd/sys_utils/Makefile @@ -69,8 +69,8 @@ shutdown: shutdown.o ps: ps.o $(TINYPRINTF) $(LD) $(LDFLAGS) -maout-heap=1024 -maout-stack=2048 -o ps ps.o $(TINYPRINTF) $(LDLIBS) -meminfo: meminfo.o $(TINYPRINTF) - $(LD) $(LDFLAGS) -maout-heap=1 -maout-stack=512 -o meminfo meminfo.o $(TINYPRINTF) $(LDLIBS) +meminfo: meminfo.o + $(LD) $(LDFLAGS) -maout-heap=1 -maout-stack=512 -o meminfo meminfo.o $(LDLIBS) who: who.o $(LD) $(LDFLAGS) -o who who.o $(LDLIBS) diff --git a/tlvccmd/sys_utils/meminfo.c b/tlvccmd/sys_utils/meminfo.c index 185d1e38d..10626e87a 100644 --- a/tlvccmd/sys_utils/meminfo.c +++ b/tlvccmd/sys_utils/meminfo.c @@ -9,6 +9,8 @@ * This file may be distributed under the terms of the GNU General Public * License v2, or at your option any later version. */ + +#define __LIBC__ /* get all typedefs */ #include #include #include @@ -24,16 +26,20 @@ int aflag; /* show application memory*/ int fflag; /* show free memory*/ -int tflag; /* show tty memory*/ +int tflag; /* show tty and driver memory*/ int bflag; /* show buffer memory*/ -int allflag; /* show all memory*/ +int mflag; /* show main memory */ +int sflag; /* show system memory */ +int allflag; /* show all memory*/ unsigned int ds; unsigned int heap_all; +unsigned int seg_all; unsigned int taskoff; int maxtasks; struct task_struct task_table; + int memread(int fd, word_t off, word_t seg, void *buf, int size) { if (lseek(fd, LINEARADDRESS(off, seg), SEEK_SET) == -1) @@ -81,8 +87,8 @@ struct task_struct *find_process(int fd, unsigned int seg) perror("taskinfo"); exit(1); } - if ((unsigned)task_table.mm.seg_code == seg || - (unsigned)task_table.mm.seg_data == seg) { + if ((unsigned)task_table.mm[SEG_CODE] == seg || + (unsigned)task_table.mm[SEG_DATA] == seg) { return &task_table; } off += sizeof(struct task_struct); @@ -90,16 +96,54 @@ struct task_struct *find_process(int fd, unsigned int seg) return NULL; } +static long total_segsize = 0; +static char *segtype[] = + { "free", "CSEG", "DSEG", "DDAT", "FDAT", "BUF ", "RDSK" }; + +void display_seg(int fd, word_t mem) +{ + seg_t segbase = getword(fd, mem + offsetof(segment_s, base), ds); + segext_t segsize = getword(fd, mem + offsetof(segment_s, size), ds); + word_t segflags = getword(fd, mem + offsetof(segment_s, flags), ds) & SEG_FLAG_TYPE; + byte_t ref_count = getword(fd, mem + offsetof(segment_s, ref_count), ds); + struct task_struct *t; + + printf(" %04x %s %7ld %4d ", + segbase, segtype[segflags], (long)segsize << 4, ref_count); + if (segflags == SEG_FLAG_CSEG || segflags == SEG_FLAG_DSEG) { + if ((t = find_process(fd, mem)) != NULL) { + process_name(fd, t->t_begstack, t->t_regs.ss); + } + } + total_segsize += (long)segsize << 4; +} + +void dump_segs(int fd) +{ + word_t n, mem; + seg_t segbase, oldbase = 0; + printf(" SEG TYPE SIZE CNT NAME\n"); + n = getword(fd, seg_all + offsetof(list_s, next), ds); + while (n != seg_all) { + mem = n - offsetof(segment_s, all); + segbase = getword(fd, mem + offsetof(segment_s, base), ds); + if (segbase < oldbase) printf("\n"); + oldbase = segbase; + display_seg(fd, mem); + printf("\n"); + /* next in list */ + n = getword(fd, n + offsetof(list_s, next), ds); + } +} + void dump_heap(int fd) { word_t total_size = 0; word_t total_free = 0; - long total_segsize = 0; - static char *heaptype[] = { "free", "SEG ", "DRVR", "TTY ", "TASK", "BUFH", "PIPE", - "NETB", "INOD", "CACH", "FILE" }; - static char *segtype[] = { "free", "CSEG", "DSEG", "BUF ", "RDSK", "PROG" }; + static char *heaptype[] = { "free", "MEM ", "DRVR", "TTY ", "TASK", "BUFH", "PIPE", + "INOD", "FILE", "CACH", "NETB" }; - printf(" HEAP TYPE SIZE SEG TYPE SIZE CNT NAME\n"); + printf(" HEAP TYPE SIZE SEG STYPE SSIZE CNT NAME\n"); word_t n = getword (fd, heap_all + offsetof(list_s, next), ds); while (n != heap_all) { @@ -107,56 +151,47 @@ void dump_heap(int fd) word_t size = getword(fd, h + offsetof(heap_s, size), ds); byte_t tag = getword(fd, h + offsetof(heap_s, tag), ds) & HEAP_TAG_TYPE; word_t mem = h + sizeof(heap_s); - seg_t segbase; - segext_t segsize; - word_t segflags, ref_count; - int free, used, tty, buffer; - struct task_struct *t; + word_t segflags; + int free, app, tty, buffer, system; if (tag == HEAP_TAG_SEG) segflags = getword(fd, mem + offsetof(segment_s, flags), ds) & SEG_FLAG_TYPE; else segflags = -1; free = (tag == HEAP_TAG_FREE || segflags == SEG_FLAG_FREE); - used = ((tag == HEAP_TAG_SEG) && (segflags == SEG_FLAG_CSEG || segflags == SEG_FLAG_DSEG)); - tty = (tag == HEAP_TAG_TTY); - buffer = ((tag == HEAP_TAG_SEG) && (segflags == SEG_FLAG_EXTBUF)); + app = ((tag == HEAP_TAG_SEG) + && (segflags == SEG_FLAG_CSEG || segflags == SEG_FLAG_DSEG || + segflags == SEG_FLAG_DDAT || segflags == SEG_FLAG_FDAT)); + tty = (tag == HEAP_TAG_TTY || tag == HEAP_TAG_DRVR); + buffer = ((tag == HEAP_TAG_SEG) && (segflags == SEG_FLAG_EXTBUF)) + || tag == HEAP_TAG_BUFHEAD || tag == HEAP_TAG_CACHE + || tag == HEAP_TAG_PIPE || tag == HEAP_TAG_NETWORK; + system = (tag == HEAP_TAG_TASK || tag == HEAP_TAG_INODE || tag == HEAP_TAG_FILE); if (allflag || - (fflag && free) || (aflag && used) || (tflag && tty) || (bflag && buffer)) { - printf(" %4x %s %5d", mem, heaptype[tag], size); + (fflag && free) || (aflag && app) || (tflag && tty) || (bflag && buffer) + || (sflag && system)) { + printf(" %04x %s %5d", mem, heaptype[tag], size); total_size += size + sizeof(heap_s); if (tag == HEAP_TAG_FREE) total_free += size; switch (tag) { case HEAP_TAG_SEG: - segbase = getword(fd, mem + offsetof(segment_s, base), ds); - segsize = getword(fd, mem + offsetof(segment_s, size), ds); - ref_count = getword(fd, mem + offsetof(segment_s, ref_count), ds); - printf(" %4x %s %7ld %4d ", - segbase, segtype[segflags], (long)segsize << 4, ref_count); - if (segflags == SEG_FLAG_CSEG || segflags == SEG_FLAG_DSEG) { - if ((t = find_process(fd, mem)) != NULL) { - process_name(fd, t->t_begstack, t->t_regs.ss); - } - } - - total_segsize += (long)segsize << 4; + display_seg(fd, mem); break; } printf("\n"); } - /* next in heap*/ + /* next in heap */ n = getword(fd, n + offsetof(list_s, next), ds); } - - printf(" Heap/free %5u/%5u Total mem %7ld\n", total_size, total_free, total_segsize); + printf(" Heap/free %5u/%u, Total mem %lu\n", total_size, total_free, total_segsize); } void usage(void) { - printf("usage: meminfo [-a][-f][-t][-b]\n"); + printf("usage: meminfo [-amftbsh]\n"); } int main(int argc, char **argv) @@ -166,7 +201,7 @@ int main(int argc, char **argv) if (argc < 2) allflag = 1; - else while ((c = getopt(argc, argv, "aftbh")) != -1) { + else while ((c = getopt(argc, argv, "aftbsmh")) != -1) { switch (c) { case 'a': aflag = 1; @@ -180,6 +215,12 @@ int main(int argc, char **argv) case 'b': bflag = 1; break; + case 's': + sflag = 1; + break; + case 'm': + mflag = 1; + break; case 'h': usage(); return 0; @@ -195,19 +236,21 @@ int main(int argc, char **argv) } if (ioctl(fd, MEM_GETDS, &ds) || ioctl(fd, MEM_GETHEAP, &heap_all) || + ioctl(fd, MEM_GETSEGALL, &seg_all) || ioctl(fd, MEM_GETTASK, &taskoff) || ioctl(fd, MEM_GETMAXTASKS, &maxtasks)) { - perror("meminfo"); - return 1; + perror("meminfo"); + return 1; } if (!memread(fd, taskoff, ds, &task_table, sizeof(task_table))) { perror("taskinfo"); } - dump_heap(fd); + if (mflag) dump_segs(fd); + else dump_heap(fd); if (!ioctl(fd, MEM_GETUSAGE, &mu)) { /* note MEM_GETUSAGE amounts are floors, so total may display less by 1k than actual*/ - printf(" Memory usage %4dKB total, %4dKB used, %4dKB free\n", + printf(" Memory: %4dKB total, %4dKB used, %4dKB free\n", mu.used_memory + mu.free_memory, mu.used_memory, mu.free_memory); } From 57ce428ed1ff6b2d3467cfa7319be96b7e23fd0d Mon Sep 17 00:00:00 2001 From: mellvik Date: Tue, 19 Nov 2024 17:08:20 +0100 Subject: [PATCH 2/4] [heap,meminfo] additional files w/small changes --- tlvc/arch/i86/drivers/char/mem.c | 27 ++++-------- tlvc/arch/i86/drivers/net/ne2k.c | 1 + tlvc/arch/i86/kernel/system.c | 76 ++++++++++++++++++-------------- tlvc/include/linuxmt/mem.h | 1 + 4 files changed, 54 insertions(+), 51 deletions(-) diff --git a/tlvc/arch/i86/drivers/char/mem.c b/tlvc/arch/i86/drivers/char/mem.c index ab7a2160d..5db52a5d3 100644 --- a/tlvc/arch/i86/drivers/char/mem.c +++ b/tlvc/arch/i86/drivers/char/mem.c @@ -1,5 +1,5 @@ /* - * ELKS implmentation of memory devices + * TLVC implmentation of memory devices * /dev/null, /dev/ports, /dev/zero, /dev/mem, /dev/kmem, etc... * * Heavily inspired by linux/drivers/char/mem.c @@ -9,8 +9,6 @@ * /dev/mem refers to physical memory * /dev/kmem refers to _virtual_ address space * /dev/port refers to hardware ports - * Currently these will be the same, but eventually, once ELKS has - * EMS, etc, we'll want to change these. */ #include @@ -38,12 +36,6 @@ #define DEV_PORT_MINOR 4 #define DEV_ZERO_MINOR 5 -#define DEV_FULL_MINOR 7 -#define DEV_RANDOM_MINOR 8 -#define DEV_URANDOM_MINOR 9 - -//#define debugmem printk -//#define DEBUG /* * generally useful code... */ @@ -62,12 +54,6 @@ int memory_lseek(struct inode *inode, register struct file *filp, } if (offset != filp->f_pos) { filp->f_pos = offset; - -#ifdef BLOAT_FS - filp->f_reada = 0; - filp->f_version = ++event; -#endif - } return 0; } @@ -269,7 +255,7 @@ int kmem_ioctl(struct inode *inode, struct file *file, int cmd, char *arg) retword = kernel_ds; break; case MEM_GETFARTEXT: - retword = (unsigned)((long)kernel_init >> 16); + retword = (unsigned)((long)buffer_init >> 16); break; case MEM_GETUSAGE: mm_get_usage (&(mu.free_memory), &(mu.used_memory)); @@ -281,14 +267,17 @@ int kmem_ioctl(struct inode *inode, struct file *file, int cmd, char *arg) case MEM_GETHEAP: retword = (unsigned short) &_heap_all; break; + case MEM_GETJIFFADDR: + retword = (unsigned) &jiffies; + break; + case MEM_GETSEGALL: + retword = (unsigned short) &_seg_all; + break; case MEM_GETUPTIME: #ifdef CONFIG_CPU_USAGE retword = (unsigned short) &uptime; break; #endif - case MEM_GETJIFFADDR: - retword = (unsigned) &jiffies; - break; default: return -EINVAL; } diff --git a/tlvc/arch/i86/drivers/net/ne2k.c b/tlvc/arch/i86/drivers/net/ne2k.c index e08769908..b11cd9a6d 100644 --- a/tlvc/arch/i86/drivers/net/ne2k.c +++ b/tlvc/arch/i86/drivers/net/ne2k.c @@ -435,6 +435,7 @@ static int ne2k_open(struct inode *inode, struct file *file) ne2k_reset(); ne2k_init(); #if NET_BUF_STRAT == HEAP_BUFS + /* allocate buffer control headers from the heap */ net_ibuf = (struct netbuf *)heap_alloc(sizeof(struct netbuf) * (netbufs[NET_RXBUFS] + netbufs[NET_TXBUFS]), HEAP_TAG_NETWORK); net_obuf = net_ibuf + netbufs[NET_RXBUFS]; diff --git a/tlvc/arch/i86/kernel/system.c b/tlvc/arch/i86/kernel/system.c index fd839ce03..de555b78a 100644 --- a/tlvc/arch/i86/kernel/system.c +++ b/tlvc/arch/i86/kernel/system.c @@ -8,76 +8,88 @@ #include #include +#include +#include - -byte_t sys_caps; /* system capabilities bits */ +seg_t membase, memend; /* start and end segment of available main memory */ unsigned int heapsize; /* max size of kernel near heap */ +byte_t sys_caps; /* system capabilities bits */ +unsigned char arch_cpu; /* CPU type from cputype.S */ -void INITPROC setup_arch(seg_t *start, seg_t *end) +unsigned int INITPROC setup_arch(void) { + unsigned int endbss, heapsegs; + #ifdef CONFIG_HW_COMPAQFAST outb_p(1,0xcf); /* Switch COMPAQ Deskpro to high speed */ #endif /* - * Extend kernel data segment to maximum of 64K to make room - * for local heap. + * Extend kernel data segment to maximum of 64K to make room for local heap. * - * Set start to beginning of available main memory, which + * Set membase to beginning of available main memory, which * is directly after end of the kernel data segment. * - * Set end to end of available main memory. - * + * Set memend to end of available main memory. * If ramdisk configured, subtract space for it from end of memory. + * + * Calculate heapsize for near heap allocator. + * Return start address for near heap allocator. */ - /* Heap allocations at even addresses, important for performance */ - unsigned int endbss = (unsigned int)(_endbss + 1) & ~1; + /* Heap allocations at even addresses */ + endbss = (unsigned int)(_endbss + 1) & ~1; - /* - * Calculate size of heap, which extends end of kernel data segment - */ + /* Calculate size of heap, which extends end of kernel data segment */ #ifdef SETUP_HEAPSIZE - unsigned int heapsegs = (1 + ~endbss) >> 4; /* max possible heap in segments*/ - if ((SETUP_HEAPSIZE >> 4) < heapsegs) /* allow if less than max*/ - heapsegs = SETUP_HEAPSIZE >> 4; - *start = kernel_ds + heapsegs + (((unsigned int) (_endbss+15)) >> 4); - heapsize = heapsegs << 4; -#else - *start = kernel_ds + 0x1000; - heapsize = 1 + ~endbss; + heapsize = SETUP_HEAPSIZE; /* may also be set via heap= in /bootopts */ #endif + if (heapsize) { + heapsegs = (1 + ~endbss) >> 4; /* max possible heap in segments */ + if ((heapsize >> 4) < heapsegs) /* allow if less than max */ + heapsegs = heapsize >> 4; + membase = kernel_ds + heapsegs + (((unsigned int) (_endbss+15)) >> 4); + heapsize = heapsegs << 4; + } else { + membase = kernel_ds + 0x1000; + heapsize = 1 + ~endbss; + } + //debug("endbss %x heap %x kdata size %x\n", endbss, heapsize, (membase-kernel_ds)<<4); - *end = (seg_t)SETUP_MEM_KBYTES << 6; + memend = SETUP_MEM_KBYTES << 6; #if defined(CONFIG_RAMDISK_SEGMENT) && (CONFIG_RAMDISK_SEGMENT > 0) if (CONFIG_RAMDISK_SEGMENT <= *end) { - /* reduce top of memory by size of ram disk*/ - *end -= CONFIG_RAMDISK_SECTORS << 5; + /* reduce top of memory by size of ram disk */ + memend -= CONFIG_RAMDISK_SECTORS << 5; } #endif - /* Now insert local heap at end of kernel data segment */ - heap_init (); - heap_add ((void *)endbss, heapsize); - - /* Misc */ - ROOT_DEV = SETUP_ROOT_DEV; - + arch_cpu = SETUP_CPU_TYPE; #ifdef SYS_CAPS sys_caps = SYS_CAPS; /* custom system capabilities */ #else - byte_t arch_cpu = SETUP_CPU_TYPE; if (arch_cpu > 5) /* 80286+ IBM PC/AT capabilities or Unknown CPU */ sys_caps = CAP_ALL; #endif + return endbss; /* used as start address in near heap init */ + } /* * The following routines may need porting on non-IBM PC architectures */ +/* + * This function gets called by the keyboard interrupt handler. + * As it's called within an interrupt, it may NOT sync. + */ +void ctrl_alt_del(void) +{ + hard_reset_now(); +} + void hard_reset_now(void) { #ifdef CONFIG_ARCH_IBMPC diff --git a/tlvc/include/linuxmt/mem.h b/tlvc/include/linuxmt/mem.h index 1051cc623..0cd4934a9 100644 --- a/tlvc/include/linuxmt/mem.h +++ b/tlvc/include/linuxmt/mem.h @@ -11,6 +11,7 @@ #define MEM_GETFARTEXT 9 #define MEM_GETMAXTASKS 10 #define MEM_GETJIFFADDR 11 +#define MEM_GETSEGALL 12 struct mem_usage { unsigned int free_memory; From faea33b232bf0d7a44fdfaec0691b0b97150c017 Mon Sep 17 00:00:00 2001 From: mellvik Date: Wed, 20 Nov 2024 17:32:14 +0100 Subject: [PATCH 3/4] [kernel,libs] New version of tiny_printf, updated meminfo --- libc/include/sys/cdefs.h | 28 ++-------- libc/include/sys/features.h | 12 +++++ libc/system/signalcb.S | 4 +- tlvc/include/arch/cdefs.h | 45 ++++++++++++++++ tlvc/include/linuxmt/signal.h | 18 ++----- tlvccmd/Make.rules | 3 -- tlvccmd/Makefile | 4 +- tlvccmd/Makefile-rules | 99 +++++++++++++++++++++++++++++++++++ tlvccmd/lib/tiny_vfprintf.c | 57 ++++++++++++-------- tlvccmd/sys_utils/Makefile | 4 +- tlvccmd/sys_utils/meminfo.c | 72 ++++++++++++------------- 11 files changed, 240 insertions(+), 106 deletions(-) create mode 100644 libc/include/sys/features.h create mode 100644 tlvc/include/arch/cdefs.h delete mode 100644 tlvccmd/Make.rules create mode 100644 tlvccmd/Makefile-rules diff --git a/libc/include/sys/cdefs.h b/libc/include/sys/cdefs.h index 2a7a65364..6474ac3b6 100644 --- a/libc/include/sys/cdefs.h +++ b/libc/include/sys/cdefs.h @@ -1,31 +1,9 @@ - #ifndef __SYS_CDEFS_H #define __SYS_CDEFS_H -#include - -#if __STDC__ - -#define __CONCAT(x,y) x ## y -#define __STRING(x) #x - -/* This is not a typedef so `const __ptr_t' does the right thing. */ -#define __ptr_t void * -#ifndef __HAS_NO_FLOATS__ -typedef long double __long_double_t; -#endif - -#else +/* compiler-specific definitions for userspace */ -#define __CONCAT(x,y) x/**/y -#define __STRING(x) "x" - -#define __ptr_t char * - -#ifndef __HAS_NO_FLOATS__ -typedef double __long_double_t; -#endif - -#endif +#include +#include __SYSARCHINC__(cdefs.h) /* No C++ */ #define __BEGIN_DECLS diff --git a/libc/include/sys/features.h b/libc/include/sys/features.h new file mode 100644 index 000000000..fe8eb3b48 --- /dev/null +++ b/libc/include/sys/features.h @@ -0,0 +1,12 @@ +#ifndef __FEATURES_H +#define __FEATURES_H + +/* Pick an OS sysinclude directory */ +/* Use with #include __SYSINC__(errno.h) */ + +#define __SYSINC__(_h_file_) +#define __SYSARCHINC__(_h_file_) + +#include + +#endif diff --git a/libc/system/signalcb.S b/libc/system/signalcb.S index fdf2ab891..3ddb1dbc3 100644 --- a/libc/system/signalcb.S +++ b/libc/system/signalcb.S @@ -7,9 +7,9 @@ .text - .global _syscall_signal + .global _signal_cbhandler -_syscall_signal: +_signal_cbhandler: push %bp mov %sp,%bp diff --git a/tlvc/include/arch/cdefs.h b/tlvc/include/arch/cdefs.h new file mode 100644 index 000000000..5eb94d11b --- /dev/null +++ b/tlvc/include/arch/cdefs.h @@ -0,0 +1,45 @@ +#ifndef __ARCH_8086_CDEFS_H +#define __ARCH_8086_CDEFS_H +/* compiler-specific definitions for kernel and userspace */ + +#if __STDC__ +#define __CONCAT(x,y) x ## y +#define __STRING(x) #x +#else +#define __CONCAT(x,y) x/**/y +#define __STRING(x) "x" +#endif + +#define __P(x) x /* always ANSI C */ + +#ifdef __GNUC__ +#define noreturn __attribute__((__noreturn__)) /* don't require */ +#define stdcall __attribute__((__stdcall__)) +#define restrict __restrict +#define printfesque(n) __attribute__((__format__(__gnu_printf__, n, n + 1))) +#define noinstrument __attribute__((no_instrument_function)) +#define CONSTRUCTOR(fn,pri) void fn(void) __attribute__((constructor(pri))) +#define DESTRUCTOR(fn,pri) void fn(void) __attribute__((destructor(pri))) +#define __wcfar +#define __wcnear +#endif + +#ifdef __WATCOMC__ +#define noreturn __declspec(aborts) +#define stdcall __stdcall +#define restrict __restrict +#define printfesque(n) +#define noinstrument +#define CONSTRUCTOR(fn,pri) void fn(void); \ + static struct _rt_init __based(__segname("XI")) \ + __CONCAT(_ctor,fn) = { fn, pri, 0} +#define DESTRUCTOR(fn,pri) void fn(void); \ + static struct _rt_init __based(__segname("YI")) \ + __CONCAT(_dtor,fn) = { fn, pri, 0} +#define __attribute__(n) +#define __wcfar __far +#define __wcnear __near +#endif + + +#endif diff --git a/tlvc/include/linuxmt/signal.h b/tlvc/include/linuxmt/signal.h index 1b44cfdc0..b986c9be0 100644 --- a/tlvc/include/linuxmt/signal.h +++ b/tlvc/include/linuxmt/signal.h @@ -10,6 +10,7 @@ * mask by losing all these unused signals. */ #include +#include #define __SMALLSIG /* 16-bit sigset_t*/ @@ -17,8 +18,6 @@ typedef unsigned short sigset_t; /* at least 16 bits */ -/*@-namechecks@*/ - #define SIGHUP 1 #define SIGINT 2 #define SIGQUIT 3 @@ -40,14 +39,10 @@ typedef unsigned short sigset_t; /* at least 16 bits */ #define _NSIG 16 -/*@+namechecks@*/ - #else typedef unsigned long sigset_t; /* at least 32 bits */ -/*@-namechecks@*/ - #define SIGHUP 1 #define SIGINT 2 #define SIGQUIT 3 @@ -84,8 +79,6 @@ typedef unsigned long sigset_t; /* at least 32 bits */ #define _NSIG 32 -/*@+naamechecks@*/ - #endif #define NSIG _NSIG @@ -178,8 +171,6 @@ typedef unsigned long sigset_t; /* at least 32 bits */ #endif /* __KERNEL__*/ -/*@-namechecks@*/ - #define SIG_BLOCK 0 /* for blocking signals */ #define SIG_UNBLOCK 1 /* for unblocking signals */ #define SIG_SETMASK 2 /* for setting the signal mask */ @@ -189,12 +180,12 @@ typedef void (*sighandler_t)(int); /* Type of a signal handler which interfaces with the kernel. This is always a far function that uses the `stdcall' calling convention, even for a user program that is being compiled for a different calling convention. */ +#ifdef __GNUC__ #pragma GCC diagnostic push #pragma GCC diagnostic ignored "-Wpedantic" typedef __attribute__((__stdcall__)) __far void (*__kern_sighandler_t)(int); #pragma GCC diagnostic pop - -/*@+namechecks@*/ /*@ignore@*/ +#endif /* * Because this stuff can get pretty confusing: @@ -226,8 +217,6 @@ typedef unsigned char __sigdisposition_t; #define SIGDISP_CUSTOM ((__sigdisposition_t) 2) #endif -/*@end@*/ - struct __kern_sigaction_struct { __sigdisposition_t sa_dispose; #if 0 @@ -242,7 +231,6 @@ struct task_struct; extern int send_sig(sig_t,struct task_struct *,int); extern void arch_setup_sighandler_stack(register struct task_struct *, __kern_sighandler_t,unsigned); -extern void ctrl_alt_del(void); extern int sys_kill(pid_t, sig_t); #endif /* __KERNEL__*/ diff --git a/tlvccmd/Make.rules b/tlvccmd/Make.rules deleted file mode 100644 index 3f0744018..000000000 --- a/tlvccmd/Make.rules +++ /dev/null @@ -1,3 +0,0 @@ -# Commands common rules - -.PHONY: all clean install diff --git a/tlvccmd/Makefile b/tlvccmd/Makefile index 68ce3bca6..bde7346fb 100644 --- a/tlvccmd/Makefile +++ b/tlvccmd/Makefile @@ -6,7 +6,7 @@ BASEDIR = . -include $(BASEDIR)/Make.defs +include $(BASEDIR)/Makefile-rules ############################################################################### # @@ -50,7 +50,7 @@ include $(BASEDIR)/Make.rules all: @if [ ! -e $(TOPDIR)/include/autoconf.h ]; \ - then echo -e "\n*** ERROR: You must configure ELKS first ***\n" >&2; exit 1; fi + then echo -e "\n*** ERROR: You must configure TLVC first ***\n" >&2; exit 1; fi for DIR in $(SUBDIRS); do $(MAKE) -C $$DIR all || exit 1; done ifdef CONFIG_APP_CGATEXT) $(MAKE) -C cgatext diff --git a/tlvccmd/Makefile-rules b/tlvccmd/Makefile-rules new file mode 100644 index 000000000..4a888e132 --- /dev/null +++ b/tlvccmd/Makefile-rules @@ -0,0 +1,99 @@ +############################################################################## +# # +# Standard rulesets for use when compiling TLVC applications. # +# # +# This file should be included in every Makefile below tlvccmd/ via e.g.: # +# BASEDIR=.. # +# include $(BASEDIR)/Makefile-rules # +# # +############################################################################## + +ifndef TOPDIR +$(error TOPDIR is not defined) +endif + +include $(TOPDIR)/Make.defs + +############################################################################## +# +# It is not normally necessary to make changes below this line. +# +# Specify directories. + +TLVC_DIR=$(TOPDIR)/tlvc +TLVCCMD_DIR=$(TOPDIR)/tlvccmd + +INCLUDES=-I$(TOPDIR)/include -I$(TOPDIR)/libc/include -I$(TLVC_DIR)/include + +############################################################################## +# +# Determine the TLVC kernel version. + +T_V=$(shell if [ -f $(TLVC_DIR)/Makefile-rules ]; then \ + grep -v '^\#' $(TLVC_DIR)/Makefile-rules \ + | fgrep = | head -4 | tr '\#' = | cut -d = -f 2 ;\ + else echo Version not known ; fi) + +TLVC_VSN=$(shell printf '%s.%s.%s%s' $(T_V)) + +############################################################################## +# +# Compiler variables for programs to be compiled as host applications. +HOSTCC = gcc +HOSTCFLAGS = -O3 + +############################################################################## +# +# Compiler variables for programs cross-compiled for ELKS. + +CLBASE = -mcmodel=small -melks-libc -mtune=i8086 -Wall -Os +CLBASE += -mno-segment-relocation-stuff +CLBASE += -fno-inline -fno-builtin-printf -fno-builtin-fprintf +#CLBASE += -mregparmcall +ifeq ($(CONFIG_APPS_FTRACE), y) + CLBASE += -fno-omit-frame-pointer -fno-optimize-sibling-calls + CLBASE += -finstrument-functions-simple -maout-symtab +endif + +# temporarily turn off typical non-K&R warnings for now +WARNINGS = -Wno-implicit-int +# temporarily turn off suggesting parenthesis around assignment used as truth value +WARNINGS += -Wno-parentheses + +CC=ia16-elf-gcc +AS=ia16-elf-as +LD=ia16-elf-gcc + +CFLAGS = $(CLBASE) $(WARNINGS) $(LOCALFLAGS) $(INCLUDES) +CFLAGS += -Wextra -Wtype-limits -Wno-unused-parameter -Wno-sign-compare -Wno-empty-body +CFLAGS += -D__ELKS__ -DTLVC_VERSION=\"$(TLVC_VSN)\" +ASFLAGS = -mtune=i8086 --32-segelf +LDFLAGS = $(CLBASE) + + +############################################################################### +# +# Special libraries for some programs +TINYPRINTF=$(TLVCCMD_DIR)/lib/tiny_vfprintf.o + +############################################################################### +# +# Standard compilation rules. + +.PHONY: all clean install + +.S.s: + $(CC) -E -traditional $(INCLUDES) $(CCDEFS) -o $*.s $< + +.S.o: + $(CC) -E -traditional $(INCLUDES) $(CCDEFS) -o $*.tmp $< + $(AS) $(ASFLAGS) -o $*.o $*.tmp + $(RM) $*.tmp + +.s.o: + $(AS) $(ASFLAGS) -o $*.o $< + +.c.o: + $(CC) $(CFLAGS) -c -o $*.o $< + +############################################################################### diff --git a/tlvccmd/lib/tiny_vfprintf.c b/tlvccmd/lib/tiny_vfprintf.c index 00d78e12d..32d843bd8 100644 --- a/tlvccmd/lib/tiny_vfprintf.c +++ b/tlvccmd/lib/tiny_vfprintf.c @@ -4,72 +4,86 @@ * Reduces executable size when linked with app for programs requiring * output to terminal only (stdout, stderr) and no file I/O. * Automatically usable with: - * printf, fprintf, sprintf + * printf, fprintf, sprintf, fputc, fflush * * Limitations: * %s, %c, %d, %u, %x, %o, %ld, %lu, %lx, %lo only w/field width & precision * Don't use with fopen (stdout, stderr only) - * Replaces stdout and stderr buffers with single buffer + * Always line buffered * * Mar 2020 Greg Haerr */ #include +#include #include #include #include +#include static unsigned char bufout[80]; +static unsigned char buferr[80]; FILE stdout[1] = { { bufout, bufout, - bufout, + bufout + sizeof(bufout), /* putc is full buffered */ bufout, bufout + sizeof(bufout), 1, - _IOFBF | __MODE_WRITE | __MODE_IOTRAN + _IOLBF | __MODE_WRITE | __MODE_IOTRAN } }; FILE stderr[1] = { { - bufout, - bufout, - bufout, - bufout, - bufout + sizeof(bufout), + buferr, + buferr, + buferr + sizeof(buferr), /* putc is full buffered */ + buferr, + buferr + sizeof(buferr), 2, - _IOFBF | __MODE_WRITE | __MODE_IOTRAN + _IOLBF | __MODE_WRITE | __MODE_IOTRAN } }; -static void __fflush(FILE *fp) +/* name clash with stdio/init.c if __stdio_fini name used */ +#pragma GCC diagnostic ignored "-Wprio-ctor-dtor" +DESTRUCTOR(__exit_flush, _INIT_PRI_STDIO); +void __exit_flush(void) +{ + fflush(stdout); + fflush(stderr); +} + +int fflush(FILE *fp) { int len; - /* Return if this is a fake FILE from sprintf */ - if (fp->fd < 0) - return; + if (fp->fd < 0) /* Return if this is a fake FILE from sprintf */ + return EOF; len = fp->bufpos - fp->bufstart; if (len) write(fp->fd, fp->bufstart, len); - fp->bufwrite = fp->bufpos = fp->bufstart; + fp->bufpos = fp->bufstart; + return 0; } -static void __fputc(int ch, FILE *fp) +int fputc(int ch, FILE *fp) { if (fp->bufpos >= fp->bufend) - __fflush(fp); + fflush(fp); *(fp->bufpos++) = ch; - fp->bufwrite = fp->bufend; + if (ch == '\n') /* fputc is always line buffered */ + fflush(fp); + return ch; } /* @@ -107,7 +121,7 @@ __fmt(FILE *op, unsigned char *buf, int ljustf, int width, int preci, char pad, { if (!ljustf && width) /* left padding */ { - if (len && sign && (pad == '0')) + if (len && sign && pad == '0') goto showsign; ch = pad; --width; @@ -129,7 +143,7 @@ __fmt(FILE *op, unsigned char *buf, int ljustf, int width, int preci, char pad, ch = pad; /* right padding */ --width; } - __fputc(ch, op); + fputc(ch, op); } return cnt; @@ -240,11 +254,10 @@ vfprintf(FILE *op, const char *fmt, va_list ap) } } else { charout: - __fputc(*fmt, op); /* normal char out */ + fputc(*fmt, op); /* normal char out */ ++cnt; } ++fmt; } - __fflush(op); return cnt; } diff --git a/tlvccmd/sys_utils/Makefile b/tlvccmd/sys_utils/Makefile index c20b11a25..2272a88dd 100644 --- a/tlvccmd/sys_utils/Makefile +++ b/tlvccmd/sys_utils/Makefile @@ -69,8 +69,8 @@ shutdown: shutdown.o ps: ps.o $(TINYPRINTF) $(LD) $(LDFLAGS) -maout-heap=1024 -maout-stack=2048 -o ps ps.o $(TINYPRINTF) $(LDLIBS) -meminfo: meminfo.o - $(LD) $(LDFLAGS) -maout-heap=1 -maout-stack=512 -o meminfo meminfo.o $(LDLIBS) +meminfo: meminfo.o $(TINYPRINTF) + $(LD) $(LDFLAGS) -maout-heap=1 -maout-stack=512 -o meminfo meminfo.o $(TINYPRINTF) $(LDLIBS) who: who.o $(LD) $(LDFLAGS) -o who who.o $(LDLIBS) diff --git a/tlvccmd/sys_utils/meminfo.c b/tlvccmd/sys_utils/meminfo.c index 10626e87a..efc583164 100644 --- a/tlvccmd/sys_utils/meminfo.c +++ b/tlvccmd/sys_utils/meminfo.c @@ -32,6 +32,7 @@ int mflag; /* show main memory */ int sflag; /* show system memory */ int allflag; /* show all memory*/ +int fd; unsigned int ds; unsigned int heap_all; unsigned int seg_all; @@ -40,7 +41,7 @@ int maxtasks; struct task_struct task_table; -int memread(int fd, word_t off, word_t seg, void *buf, int size) +int memread(word_t off, word_t seg, void *buf, int size) { if (lseek(fd, LINEARADDRESS(off, seg), SEEK_SET) == -1) return 0; @@ -51,39 +52,39 @@ int memread(int fd, word_t off, word_t seg, void *buf, int size) return 1; } -word_t getword(int fd, word_t off, word_t seg) +word_t getword(word_t off, word_t seg) { word_t word; - if (!memread(fd, off, seg, &word, sizeof(word))) + if (!memread(off, seg, &word, sizeof(word))) return 0; return word; } -void process_name(int fd, unsigned int off, unsigned int seg) +void process_name(unsigned int off, unsigned int seg) { word_t argc, argv; char buf[80]; - argc = getword(fd, off, seg); + argc = getword(off, seg); while (argc-- > 0) { off += 2; - argv = getword(fd, off, seg); - if (!memread(fd, argv, seg, buf, sizeof(buf))) + argv = getword(off, seg); + if (!memread(argv, seg, buf, sizeof(buf))) return; printf("%s ",buf); break; /* display only executable name for now */ } } -struct task_struct *find_process(int fd, unsigned int seg) +struct task_struct *find_process(unsigned int seg) { int i; int off = taskoff; for (i = 0; i < maxtasks; i++) { - if (!memread(fd, off, ds, &task_table, sizeof(task_table))) { + if (!memread(off, ds, &task_table, sizeof(task_table))) { perror("taskinfo"); exit(1); } @@ -100,43 +101,44 @@ static long total_segsize = 0; static char *segtype[] = { "free", "CSEG", "DSEG", "DDAT", "FDAT", "BUF ", "RDSK" }; -void display_seg(int fd, word_t mem) +void display_seg(word_t mem) { - seg_t segbase = getword(fd, mem + offsetof(segment_s, base), ds); - segext_t segsize = getword(fd, mem + offsetof(segment_s, size), ds); - word_t segflags = getword(fd, mem + offsetof(segment_s, flags), ds) & SEG_FLAG_TYPE; - byte_t ref_count = getword(fd, mem + offsetof(segment_s, ref_count), ds); + seg_t segbase = getword(mem + offsetof(segment_s, base), ds); + segext_t segsize = getword(mem + offsetof(segment_s, size), ds); + word_t segflags = getword(mem + offsetof(segment_s, flags), ds) & SEG_FLAG_TYPE; + byte_t ref_count = getword(mem + offsetof(segment_s, ref_count), ds); struct task_struct *t; printf(" %04x %s %7ld %4d ", segbase, segtype[segflags], (long)segsize << 4, ref_count); if (segflags == SEG_FLAG_CSEG || segflags == SEG_FLAG_DSEG) { - if ((t = find_process(fd, mem)) != NULL) { - process_name(fd, t->t_begstack, t->t_regs.ss); + if ((t = find_process(mem)) != NULL) { + process_name(t->t_begstack, t->t_regs.ss); } } total_segsize += (long)segsize << 4; } -void dump_segs(int fd) +void dump_segs(void) { - word_t n, mem; + word_t n, mem, arena = 2; seg_t segbase, oldbase = 0; printf(" SEG TYPE SIZE CNT NAME\n"); - n = getword(fd, seg_all + offsetof(list_s, next), ds); + n = getword(seg_all + offsetof(list_s, next), ds); while (n != seg_all) { mem = n - offsetof(segment_s, all); - segbase = getword(fd, mem + offsetof(segment_s, base), ds); - if (segbase < oldbase) printf("\n"); + segbase = getword(mem + offsetof(segment_s, base), ds); + if (segbase < oldbase) + printf("[Arena %d]\n", arena++); oldbase = segbase; - display_seg(fd, mem); + display_seg(mem); printf("\n"); /* next in list */ - n = getword(fd, n + offsetof(list_s, next), ds); + n = getword(n + offsetof(list_s, next), ds); } } -void dump_heap(int fd) +void dump_heap(void) { word_t total_size = 0; word_t total_free = 0; @@ -145,17 +147,17 @@ void dump_heap(int fd) printf(" HEAP TYPE SIZE SEG STYPE SSIZE CNT NAME\n"); - word_t n = getword (fd, heap_all + offsetof(list_s, next), ds); + word_t n = getword(heap_all + offsetof(list_s, next), ds); while (n != heap_all) { word_t h = n - offsetof(heap_s, all); - word_t size = getword(fd, h + offsetof(heap_s, size), ds); - byte_t tag = getword(fd, h + offsetof(heap_s, tag), ds) & HEAP_TAG_TYPE; + word_t size = getword(h + offsetof(heap_s, size), ds); + byte_t tag = getword(h + offsetof(heap_s, tag), ds) & HEAP_TAG_TYPE; word_t mem = h + sizeof(heap_s); word_t segflags; int free, app, tty, buffer, system; if (tag == HEAP_TAG_SEG) - segflags = getword(fd, mem + offsetof(segment_s, flags), ds) & SEG_FLAG_TYPE; + segflags = getword(mem + offsetof(segment_s, flags), ds) & SEG_FLAG_TYPE; else segflags = -1; free = (tag == HEAP_TAG_FREE || segflags == SEG_FLAG_FREE); app = ((tag == HEAP_TAG_SEG) @@ -177,14 +179,14 @@ void dump_heap(int fd) switch (tag) { case HEAP_TAG_SEG: - display_seg(fd, mem); + display_seg(mem); break; } printf("\n"); } /* next in heap */ - n = getword(fd, n + offsetof(list_s, next), ds); + n = getword(n + offsetof(list_s, next), ds); } printf(" Heap/free %5u/%u, Total mem %lu\n", total_size, total_free, total_segsize); } @@ -196,7 +198,7 @@ void usage(void) int main(int argc, char **argv) { - int fd, c; + int c; struct mem_usage mu; if (argc < 2) @@ -231,7 +233,7 @@ int main(int argc, char **argv) } if ((fd = open("/dev/kmem", O_RDONLY)) < 0) { - perror("meminfo"); + perror(argv[0]); return 1; } if (ioctl(fd, MEM_GETDS, &ds) || @@ -242,11 +244,11 @@ int main(int argc, char **argv) perror("meminfo"); return 1; } - if (!memread(fd, taskoff, ds, &task_table, sizeof(task_table))) { + if (!memread(taskoff, ds, &task_table, sizeof(task_table))) { perror("taskinfo"); } - if (mflag) dump_segs(fd); - else dump_heap(fd); + if (mflag) dump_segs(); + else dump_heap(); if (!ioctl(fd, MEM_GETUSAGE, &mu)) { /* note MEM_GETUSAGE amounts are floors, so total may display less by 1k than actual*/ From 99002a83343933716e0d4cdfe09b528332e53071 Mon Sep 17 00:00:00 2001 From: mellvik Date: Thu, 21 Nov 2024 11:08:38 +0100 Subject: [PATCH 4/4] [cleanup] Makefile updates in tlvccmd --- tlvccmd/Makefile | 11 +- tlvccmd/ash/Makefile | 12 +- tlvccmd/basic/Makefile | 8 +- tlvccmd/bc/Makefile | 10 +- tlvccmd/byacc/Makefile | 8 +- tlvccmd/cgatext/.gitignore | 2 - tlvccmd/cgatext/main.c | 207 ------ tlvccmd/cgatext/makefile | 30 - tlvccmd/cron/Makefile | 10 +- tlvccmd/debug/Makefile | 11 +- tlvccmd/disk_utils/Makefile | 8 +- tlvccmd/elvis/Makefile | 3 +- tlvccmd/file_utils/Makefile | 9 +- tlvccmd/inet/Makefile | 8 +- tlvccmd/inet/ftp/Makefile | 8 +- tlvccmd/inet/httpd/Makefile | 8 +- tlvccmd/inet/nettools/Makefile | 8 +- tlvccmd/inet/telnet/Makefile | 8 +- tlvccmd/inet/telnetd/Makefile | 12 +- tlvccmd/inet/tinyirc/Makefile | 42 +- tlvccmd/inet/urlget/Makefile | 8 +- tlvccmd/ktcp/Makefile | 9 +- tlvccmd/lib/Makefile | 8 +- tlvccmd/minix1/Makefile | 8 +- tlvccmd/minix2/Makefile | 8 +- tlvccmd/minix3/Makefile | 20 +- tlvccmd/misc_utils/Makefile | 10 +- tlvccmd/nano/Makefile | 8 +- tlvccmd/sash/Makefile | 8 +- tlvccmd/sh_utils/Makefile | 8 +- tlvccmd/sys_utils/Makefile | 10 +- tlvccmd/sys_utils/exitemu.s | 8 - tlvccmd/sys_utils/insmod.c | 115 --- tlvccmd/sys_utils/knl.8 | 298 -------- tlvccmd/sys_utils/knl.c | 1275 -------------------------------- tlvccmd/sys_utils/rdev.8 | 153 ---- tlvccmd/sys_utils/rdev.c | 281 ------- tlvccmd/test/libc/Makefile | 6 +- 38 files changed, 48 insertions(+), 2616 deletions(-) delete mode 100644 tlvccmd/cgatext/.gitignore delete mode 100644 tlvccmd/cgatext/main.c delete mode 100644 tlvccmd/cgatext/makefile delete mode 100644 tlvccmd/sys_utils/exitemu.s delete mode 100644 tlvccmd/sys_utils/insmod.c delete mode 100644 tlvccmd/sys_utils/knl.8 delete mode 100644 tlvccmd/sys_utils/knl.c delete mode 100644 tlvccmd/sys_utils/rdev.8 delete mode 100644 tlvccmd/sys_utils/rdev.c diff --git a/tlvccmd/Makefile b/tlvccmd/Makefile index bde7346fb..e4931de7c 100644 --- a/tlvccmd/Makefile +++ b/tlvccmd/Makefile @@ -15,39 +15,32 @@ include $(BASEDIR)/Makefile-rules # All subdirectories to build & clean # TODO: broken command compilations: byacc m4 xvi -# unused commands but working compilations: mtools nano prems +# TLVC removed because of nonuse: busyelks, levee, nano-X, screen, tui +# test SUBDIRS = \ lib \ ash \ basic \ bc \ - busyelks \ disk_utils \ elvis \ file_utils \ inet \ ktcp \ - levee \ minix1 \ minix2 \ minix3 \ misc_utils \ - nano-X \ sash \ - screen \ cron \ sh_utils \ sys_utils \ - tui \ - test \ # EOL ############################################################################### # # Compile everything. -include $(BASEDIR)/Make.rules - all: @if [ ! -e $(TOPDIR)/include/autoconf.h ]; \ then echo -e "\n*** ERROR: You must configure TLVC first ***\n" >&2; exit 1; fi diff --git a/tlvccmd/ash/Makefile b/tlvccmd/ash/Makefile index 838e4ba26..b1a8c695e 100644 --- a/tlvccmd/ash/Makefile +++ b/tlvccmd/ash/Makefile @@ -1,20 +1,12 @@ -# Makefile for ash. +# Makefile for ash # -# 19980209 Claudio Matsuoka -# Modified for ELKS and bcc BASEDIR = .. -include $(BASEDIR)/Make.defs - LOCALFLAGS = -DSHELL -I. -D_MINIX -D_POSIX_SOURCE -Dlint LOCALFLAGS += -Wno-implicit-int -############################################################################### -# -# Include standard packaging commands. - -include $(BASEDIR)/Make.rules +include $(BASEDIR)/Makefile-rules ############################################################################### diff --git a/tlvccmd/basic/Makefile b/tlvccmd/basic/Makefile index 6705c6eb0..fb1a69a7d 100644 --- a/tlvccmd/basic/Makefile +++ b/tlvccmd/basic/Makefile @@ -1,12 +1,6 @@ BASEDIR=.. -include $(BASEDIR)/Make.defs - -############################################################################### -# -# Include standard packaging commands. - -include $(BASEDIR)/Make.rules +include $(BASEDIR)/Makefile-rules CFLAGS += -Wno-maybe-uninitialized diff --git a/tlvccmd/bc/Makefile b/tlvccmd/bc/Makefile index 1090122e9..f3af394de 100644 --- a/tlvccmd/bc/Makefile +++ b/tlvccmd/bc/Makefile @@ -1,14 +1,8 @@ # Makefile for bc # -# A makefile for bc. This is part of the bc/sbc distribution. -# -# $Id$ -############################################################################### -# -# Include standard packaging commands. -BASEDIR = .. -include $(BASEDIR)/Make.defs +BASEDIR = .. +include $(BASEDIR)/Makefile-rules ############################################################################### # diff --git a/tlvccmd/byacc/Makefile b/tlvccmd/byacc/Makefile index 9f2dedc8c..8126c9860 100644 --- a/tlvccmd/byacc/Makefile +++ b/tlvccmd/byacc/Makefile @@ -1,14 +1,8 @@ # Makefile for Berkeley yacc. BASEDIR = .. - -include ../Make.defs -############################################################################### -# -# Include standard packaging commands. - -include $(BASEDIR)/Make.rules +include $(BASEDIR)/Makefile-rules ############################################################################### diff --git a/tlvccmd/cgatext/.gitignore b/tlvccmd/cgatext/.gitignore deleted file mode 100644 index c8190fbd5..000000000 --- a/tlvccmd/cgatext/.gitignore +++ /dev/null @@ -1,2 +0,0 @@ -cgatext -*~ diff --git a/tlvccmd/cgatext/main.c b/tlvccmd/cgatext/main.c deleted file mode 100644 index 5b13d841c..000000000 --- a/tlvccmd/cgatext/main.c +++ /dev/null @@ -1,207 +0,0 @@ -/* -2020.04.13 Marcin.Laszewski@gmail.com CGATEXT Demo -*/ - -#include -#include -#include -#include -#include - -#include - -void cgatext_puts(unsigned addr, unsigned short attr, char const *str) -{ - while (*str) { - cgatext_put_cell(addr, cgatext_cell_attr_c(attr, *str)); - str++; - addr += cgatext_cell_SIZE; - } -} - -#define cgatext_puts_center(attr, str) \ - cgatext_puts(cgatext_offset((cgatext_COLS - strlen(str)) >> 1, cgatext_ROWS >> 1), attr, str) - -#define rand_c(first_c, last_c) ((first_c) + (rand() % ((last_c) - (first_c) + 1))) - -static unsigned -buf_puts(unsigned short * buf, unsigned char fg, unsigned char bg, char const * text) -{ - unsigned n = 0; - - while(*text) - { - *buf++ = cgatext_cell(fg, bg, *text++); - n += cgatext_cell_SIZE; - } - - return n; -} - -int main(void) -{ - cgatext_clear(); - cgatext_puts_center(cgatext_cell_color(cgatext_color_WHITE, cgatext_color_BLACK), - "<<< CGATEXT Demo >>>"); - sleep(2); - - { - char c; - - for (c = 0; c < cgatext_attr_MAX; c++) - { - cgatext_fill(cgatext_cell(c, cgatext_color_BLACK, c < 10 ? c + '0' : (c - 10) + 'A')); - sleep(1); - } - } - - { - struct - { - char first; - char last; - unsigned char fg; - unsigned char bg; - } chtab[] = { - {' ', ' ', cgatext_color_MAX, cgatext_color_MAX }, - {'0', '9', cgatext_attr_MAX, cgatext_color_BLACK + 1 }, - {'A', 'Z', cgatext_attr_MAX, cgatext_color_MAX }, - }; - - unsigned i; - unsigned long j; - - for (i = 0; i < 3; i++) - for (j = 0; j < 2000000; j++) - cgatext_put_cell_xy( - rand() % cgatext_COLS, - rand() % cgatext_ROWS, - cgatext_cell( - rand() % chtab[i].fg, - rand() % chtab[i].bg, - rand_c(chtab[i].first, chtab[i].last) - ) - ); - } - - { - unsigned x, y; - - char const *color[cgatext_color_MAX] = { - [cgatext_color_BLACK] = "Black", - [cgatext_color_RED] = "Red", - [cgatext_color_GREEN] = "Green", - [cgatext_color_YELLOW] = "Yellow", - [cgatext_color_BLUE] = "Blue", - [cgatext_color_CYAN] = "Cyan", - [cgatext_color_MAGENTA] = "Magenta", - [cgatext_color_WHITE] = "White", - }; - - for (y = 0; y < cgatext_attr_MAX; y++) - for (x = 0; x < cgatext_color_MAX; x++) - { - char text[11]; - - sprintf(text, "%-10s", - (x && y) - ? "ELKS" - : color[(x ? x : y) % cgatext_color_MAX]); - cgatext_puts(cgatext_offset(10 * x, y), cgatext_cell_color(y, x), text); - } - } - - sleep(1); - - { - char const * devname = "/dev/cgatext"; - - int f = open(devname, O_RDWR); - - if(f < 0) - { - perror(devname); - return 1; - } - - { - unsigned short buf[50]; - off_t i; - - /* Clear screen */ - *buf = cgatext_cell(cgatext_color_YELLOW | cgatext_attr_BOLD, cgatext_color_BLUE, ' '); - while(write(f, buf, sizeof *buf) > 0); - - { - unsigned n; - - n = buf_puts(buf, - cgatext_color_CYAN | cgatext_attr_BOLD, - cgatext_color_BLUE, - "--- /dev/cgatext ---"); - lseek(f, cgatext_offset((cgatext_COLS - 19) >> 1, cgatext_ROWS >> 1), SEEK_SET); - write(f, buf, n); - } - - sleep(3); - - { - unsigned short c; - - for(i = 0; i < 2000000; i++) - { - c = cgatext_cell( - rand() % cgatext_attr_MAX, - rand() % cgatext_color_MAX, - '0' + (rand() % 10)); - lseek(f, - cgatext_offset(rand() % cgatext_COLS, rand() % cgatext_ROWS), - SEEK_SET); - write(f, &c, sizeof c); - } - } - - lseek(f, 0, SEEK_SET); - memset(buf, 0, sizeof(buf)); - while(write(f, buf, sizeof buf) > 0); - - lseek(f, 0, SEEK_SET); - - { - unsigned char fg = cgatext_color_BLACK; - - for(;;) - { - unsigned n = buf_puts(buf, fg, cgatext_color_BLACK, "ELKS"); - - if(write(f, buf, n) != n) - break; - - if(++fg >= cgatext_attr_MAX) - fg = cgatext_color_BLACK; - - lseek(f, cgatext_cell_SIZE, SEEK_CUR); - } - } - - { - unsigned n; - - n = buf_puts(buf, - cgatext_color_GREEN | cgatext_attr_BOLD, - cgatext_color_BLACK, - " -THE END- "); - lseek(f, n, SEEK_END); - write(f, buf, n); - } - } - - if(close(f) < 0) - { - perror("close(cgatext)"); - return 2; - } - } - - return 0; -} diff --git a/tlvccmd/cgatext/makefile b/tlvccmd/cgatext/makefile deleted file mode 100644 index efd382546..000000000 --- a/tlvccmd/cgatext/makefile +++ /dev/null @@ -1,30 +0,0 @@ -ELKS = ../.. -BASEDIR = ../ -include $(BASEDIR)/Make.defs -include $(BASEDIR)/Make.rules - -# Install destination -DESTDIR = $(TOPDIR)/target -ELKS_LIB86 = $(ELKS)/elks/arch/i86/lib/ - -NAME = cgatext - -OUT = $(NAME) -CFLAGS += -I$(ELKS)/elks/include/arch -OBJS += main.o -LIBS = $(ELKS_LIB86)/lib86.a - -all: $(OUT) - -$(OUT): $(OBJS) $(LIBS) - echo '[LD] $@' - $(LD) $(LDFLAGS) -o $@ $^ - -distclean: clean - $(RM) *~ $(OUT) - -clean:: - $(RM) $(OBJS) - -install: $(OUT) - cp $(OUT) $(DESTDIR)/bin diff --git a/tlvccmd/cron/Makefile b/tlvccmd/cron/Makefile index 1f93db851..388000a5a 100644 --- a/tlvccmd/cron/Makefile +++ b/tlvccmd/cron/Makefile @@ -1,18 +1,10 @@ -################################################################################## - # Makefile for cron BASEDIR=.. -include $(BASEDIR)/Make.defs - LOCALFLAGS = -Wno-implicit-int -Wno-return-type $(OPTIONS) -############################################################################### -# -# Include standard packaging commands. - -include $(BASEDIR)/Make.rules +include $(BASEDIR)/Makefile-rules ############################################################################### diff --git a/tlvccmd/debug/Makefile b/tlvccmd/debug/Makefile index 43ad1d041..b1eb97536 100644 --- a/tlvccmd/debug/Makefile +++ b/tlvccmd/debug/Makefile @@ -1,15 +1,6 @@ BASEDIR=.. -include $(BASEDIR)/Make.defs - -############################################################################### -# -# Include standard packaging commands. - -include $(BASEDIR)/Make.rules - -HOSTCC = gcc -HOSTCFLAGS = -O3 +include $(BASEDIR)/Makefile-rules ############################################################################### diff --git a/tlvccmd/disk_utils/Makefile b/tlvccmd/disk_utils/Makefile index 856610919..838838f17 100644 --- a/tlvccmd/disk_utils/Makefile +++ b/tlvccmd/disk_utils/Makefile @@ -1,12 +1,6 @@ BASEDIR=.. -include $(BASEDIR)/Make.defs - -############################################################################### -# -# Include standard packaging commands. - -include $(BASEDIR)/Make.rules +include $(BASEDIR)/Makefile-rules ############################################################################### diff --git a/tlvccmd/elvis/Makefile b/tlvccmd/elvis/Makefile index 86890510e..61881d7e4 100644 --- a/tlvccmd/elvis/Makefile +++ b/tlvccmd/elvis/Makefile @@ -3,8 +3,7 @@ ############################################################################### BASEDIR = .. - -include $(BASEDIR)/Make.defs +include $(BASEDIR)/Makefile-rules LOCALFLAGS=-O -DM_SYSV -DCRUNCH -DNO_MKEXRC -DNO_CURSORSHAPE -DNO_CHARATTR \ -DNO_SHOWMODE -DNO_MODELINE -DNO_OPTCOLS -DNO_DIGRAPH -DNO_ABBR \ diff --git a/tlvccmd/file_utils/Makefile b/tlvccmd/file_utils/Makefile index 77a3bf1f1..27b53e801 100644 --- a/tlvccmd/file_utils/Makefile +++ b/tlvccmd/file_utils/Makefile @@ -1,16 +1,9 @@ BASEDIR=.. -include $(BASEDIR)/Make.defs +include $(BASEDIR)/Makefile-rules ############################################################################### -# -# Include standard packaging commands. -include $(BASEDIR)/Make.rules - -############################################################################### - -# note: grep doesn't read stdin, replaced with minix1/grep # removed: l PRGS = ln ls mkdir mkfifo mknod more mv rm rmdir sync touch \ cat chgrp chmod chown cmp cp dd grep split diff --git a/tlvccmd/inet/Makefile b/tlvccmd/inet/Makefile index 78ae07fd0..f0a4614db 100644 --- a/tlvccmd/inet/Makefile +++ b/tlvccmd/inet/Makefile @@ -1,12 +1,6 @@ BASEDIR=.. -include $(BASEDIR)/Make.defs - -############################################################################### -# -# Include standard packaging commands. - -include $(BASEDIR)/Make.rules +include $(BASEDIR)/Makefile-rules ############################################################################### diff --git a/tlvccmd/inet/ftp/Makefile b/tlvccmd/inet/ftp/Makefile index b1d3b517f..b0a3c722b 100644 --- a/tlvccmd/inet/ftp/Makefile +++ b/tlvccmd/inet/ftp/Makefile @@ -2,13 +2,7 @@ BASEDIR=../.. -include $(BASEDIR)/Make.defs - -############################################################################### -# -# Include standard packaging commands. - -include $(BASEDIR)/Make.rules +include $(BASEDIR)/Makefile-rules ############################################################################### diff --git a/tlvccmd/inet/httpd/Makefile b/tlvccmd/inet/httpd/Makefile index cb2acf4b5..beb0a3ad1 100644 --- a/tlvccmd/inet/httpd/Makefile +++ b/tlvccmd/inet/httpd/Makefile @@ -1,12 +1,6 @@ BASEDIR=../.. -include $(BASEDIR)/Make.defs - -############################################################################### -# -# Include standard packaging commands. - -include $(BASEDIR)/Make.rules +include $(BASEDIR)/Makefile-rules ############################################################################### diff --git a/tlvccmd/inet/nettools/Makefile b/tlvccmd/inet/nettools/Makefile index b33f6cfa5..b3b766e5a 100644 --- a/tlvccmd/inet/nettools/Makefile +++ b/tlvccmd/inet/nettools/Makefile @@ -1,12 +1,6 @@ BASEDIR=../.. -include $(BASEDIR)/Make.defs - -############################################################################### -# -# Include standard packaging commands. - -include $(BASEDIR)/Make.rules +include $(BASEDIR)/Makefile-rules ############################################################################### diff --git a/tlvccmd/inet/telnet/Makefile b/tlvccmd/inet/telnet/Makefile index b71c83d9d..ca4af516c 100644 --- a/tlvccmd/inet/telnet/Makefile +++ b/tlvccmd/inet/telnet/Makefile @@ -2,13 +2,7 @@ BASEDIR=../.. -include $(BASEDIR)/Make.defs - -############################################################################### -# -# Include standard packaging commands. - -include $(BASEDIR)/Make.rules +include $(BASEDIR)/Makefile-rules ############################################################################### diff --git a/tlvccmd/inet/telnetd/Makefile b/tlvccmd/inet/telnetd/Makefile index 606823727..79aa44ecc 100644 --- a/tlvccmd/inet/telnetd/Makefile +++ b/tlvccmd/inet/telnetd/Makefile @@ -1,18 +1,12 @@ -# Makefile for telnet +# Makefile for telnetd BASEDIR=../.. -include $(BASEDIR)/Make.defs +include $(BASEDIR)/Makefile-rules ############################################################################### -# -# Include standard packaging commands. -include $(BASEDIR)/Make.rules - -############################################################################### - -SRCS = telnetd.c telnet.c +SRCS = telnetd.c OBJS = $(SRCS:.c=.o) LDFLAGS += -maout-heap=1024 -maout-stack=1024 diff --git a/tlvccmd/inet/tinyirc/Makefile b/tlvccmd/inet/tinyirc/Makefile index 1a0e8354c..909bf2408 100644 --- a/tlvccmd/inet/tinyirc/Makefile +++ b/tlvccmd/inet/tinyirc/Makefile @@ -1,46 +1,30 @@ -# tinyirc makefile -# by Nathan Laredo -# -# I don't wish to assert any rights (copyright) over this makefile -# but please give me credit if you use my code. -# -# chat.freenode.net= -SERVER = 162.213.39.42 -PORT = 8000 -# +# Makefile for tinyirc BASEDIR=../.. -include $(BASEDIR)/Make.defs -LOCALFLAGS=-DPOSIX -DELKS +include $(BASEDIR)/Makefile-rules -# -# Rules -# +############################################################################### + +# configurable options +# chat.freenode.net= +SERVER = 162.213.39.42 +PORT = 8000 -include $(BASEDIR)/Make.rules +############################################################################### all: tinyirc -LOCALDEFS = -DDEFAULTSERVER=\"$(SERVER)\" -DDEFAULTPORT=$(PORT) +LOCALFLAGS = -DPOSIX -DELKS -DDEFAULTSERVER=\"$(SERVER)\" -DDEFAULTPORT=$(PORT) tinyirc: tinyirc.o - $(LD) $(LDFLAGS) -o tinyirc tinyirc.o $(LDLIBS) + $(LD) $(LDFLAGS) -o $@ -maout-heap=8192 $^ $(LDLIBS) tinyircd: tinyircd.o - $(LD) $(LDFLAGS) -o tinyircd tinyircd.o $(LDLIBS) - -tinyirccv: tinyirccv.o - $(CC) $(LDFLAGS) -o tinyirc tinyirccv.o $(LIBS) - -tinyirc.o: tinyirc.c Makefile - $(CC) $(CFLAGS) $(LOCALDEFS) -c tinyirc.c -o tinyirc.o - -tinyirccv.o: tinyirccv.c Makefile - $(CC) $(CFLAGS) $(LOCALDEFS) -c tinyirccv.c -o tinyirccv.o + $(LD) $(LDFLAGS) -o $@ $^ $(LDLIBS) install: tinyirc $(INSTALL) tinyirc $(DESTDIR)/bin clean: - rm -f core *.o tinyirc + $(RM) *.o tinyirc diff --git a/tlvccmd/inet/urlget/Makefile b/tlvccmd/inet/urlget/Makefile index 7d2e5e9dd..4c14ecf33 100644 --- a/tlvccmd/inet/urlget/Makefile +++ b/tlvccmd/inet/urlget/Makefile @@ -2,13 +2,7 @@ BASEDIR=../.. -include $(BASEDIR)/Make.defs - -############################################################################### -# -# Include standard packaging commands. - -include $(BASEDIR)/Make.rules +include $(BASEDIR)/Makefile-rules ############################################################################### diff --git a/tlvccmd/ktcp/Makefile b/tlvccmd/ktcp/Makefile index c8c0fcf9a..824de8d4c 100644 --- a/tlvccmd/ktcp/Makefile +++ b/tlvccmd/ktcp/Makefile @@ -1,6 +1,6 @@ # Makefile for ktcp BASEDIR=.. -include $(BASEDIR)/Make.defs +include $(BASEDIR)/Makefile-rules SHELL = /bin/sh @@ -16,13 +16,6 @@ all: ktcp ktcp: $(OBJS) $(LD) $(LDFLAGS) -maout-heap=33772 -maout-stack=3072 -o ktcp $(OBJS) $(LDLIBS) -lint: - @for FILE in *.c ; do \ - echo '===>' "$${FILE}" ; \ - splint -weak -D__KERNEL__ $(LOCALFLAGS) "$${FILE}" \ - 2>&1 > "$${FILE}.lint" ; \ - done - install: ktcp $(INSTALL) ktcp $(DESTDIR)/bin diff --git a/tlvccmd/lib/Makefile b/tlvccmd/lib/Makefile index 648294f81..7cafedcf2 100644 --- a/tlvccmd/lib/Makefile +++ b/tlvccmd/lib/Makefile @@ -1,12 +1,6 @@ BASEDIR=.. -include $(BASEDIR)/Make.defs - -############################################################################### -# -# Include standard packaging commands. - -include $(BASEDIR)/Make.rules +include $(BASEDIR)/Makefile-rules ############################################################################### diff --git a/tlvccmd/minix1/Makefile b/tlvccmd/minix1/Makefile index c13e75006..94d70499f 100644 --- a/tlvccmd/minix1/Makefile +++ b/tlvccmd/minix1/Makefile @@ -1,12 +1,6 @@ BASEDIR=.. -include $(BASEDIR)/Make.defs - -############################################################################### -# -# Include standard packaging commands. - -include $(BASEDIR)/Make.rules +include $(BASEDIR)/Makefile-rules ############################################################################### diff --git a/tlvccmd/minix2/Makefile b/tlvccmd/minix2/Makefile index aab15d7e1..5db1bf94c 100644 --- a/tlvccmd/minix2/Makefile +++ b/tlvccmd/minix2/Makefile @@ -2,13 +2,7 @@ BASEDIR=.. LOCALFLAGS=-D_POSIX_SOURCE -include $(BASEDIR)/Make.defs - -############################################################################### -# -# Include standard packaging commands. - -include $(BASEDIR)/Make.rules +include $(BASEDIR)/Makefile-rules ############################################################################### diff --git a/tlvccmd/minix3/Makefile b/tlvccmd/minix3/Makefile index 23454cf7f..e8f2cda97 100644 --- a/tlvccmd/minix3/Makefile +++ b/tlvccmd/minix3/Makefile @@ -1,23 +1,11 @@ BASEDIR=.. -LOCALFLAGS= - -include $(BASEDIR)/Make.defs - -############################################################################### -# -# Include standard packaging commands. - -include $(BASEDIR)/Make.rules +include $(BASEDIR)/Makefile-rules ############################################################################### PRGS = file head sed sort tail tee cal diff find -# -# Rules -# - cal: cal.o $(TINYPRINTF) $(LD) $(LDFLAGS) -o cal cal.o $(TINYPRINTF) $(LDLIBS) @@ -36,9 +24,7 @@ head: head.o sed: sed.o $(LD) $(LDFLAGS) -o sed sed.o $(LDLIBS) -# For ELKS, sort needs more data segment space than the kernel-given default. -# Use gcc-ia16's -maout-chmem= option so that the a.out header will ask the -# kernel for more non-static memory. +# For TLVC, sort needs more data segment space than the kernel-given default. sort: sort.o $(LD) $(LDFLAGS) -maout-heap=0xb000 -o sort sort.o $(LDLIBS) @@ -49,8 +35,6 @@ tee: tee.o $(LD) $(LDFLAGS) -o tee tee.o $(LDLIBS) -include $(BASEDIR)/Make.rules - all: $(PRGS) diff --git a/tlvccmd/misc_utils/Makefile b/tlvccmd/misc_utils/Makefile index d366620a1..450bb4f13 100644 --- a/tlvccmd/misc_utils/Makefile +++ b/tlvccmd/misc_utils/Makefile @@ -1,16 +1,8 @@ BASEDIR=.. -include $(BASEDIR)/Make.defs - ############################################################################### -# -# Include standard packaging commands. - -include $(BASEDIR)/Make.rules -HOSTCC = gcc -HOST_CFLAGS = -O2 -KERNEL_LIBS = $(TOPDIR)/tlvc/arch/i86/lib/lib86.a +include $(BASEDIR)/Makefile-rules ############################################################################### diff --git a/tlvccmd/nano/Makefile b/tlvccmd/nano/Makefile index 316580043..5ac699411 100644 --- a/tlvccmd/nano/Makefile +++ b/tlvccmd/nano/Makefile @@ -1,12 +1,6 @@ BASEDIR=.. -include $(BASEDIR)/Make.defs - -############################################################################### -# -# Include standard packaging commands. - -include $(BASEDIR)/Make.rules +include $(BASEDIR)/Makefile-rules ############################################################################### diff --git a/tlvccmd/sash/Makefile b/tlvccmd/sash/Makefile index 21283700b..b706058be 100644 --- a/tlvccmd/sash/Makefile +++ b/tlvccmd/sash/Makefile @@ -2,15 +2,9 @@ BASEDIR=.. -include $(BASEDIR)/Make.defs - LOCALFLAGS = -Wno-implicit-int -############################################################################### -# -# Include standard packaging commands. - -include $(BASEDIR)/Make.rules +include $(BASEDIR)/Makefile-rules ############################################################################### diff --git a/tlvccmd/sh_utils/Makefile b/tlvccmd/sh_utils/Makefile index 2a6da4cb0..64f132fef 100644 --- a/tlvccmd/sh_utils/Makefile +++ b/tlvccmd/sh_utils/Makefile @@ -1,12 +1,6 @@ BASEDIR=.. -include $(BASEDIR)/Make.defs - -############################################################################### -# -# Include standard packaging commands. - -include $(BASEDIR)/Make.rules +include $(BASEDIR)/Makefile-rules ############################################################################### diff --git a/tlvccmd/sys_utils/Makefile b/tlvccmd/sys_utils/Makefile index 2272a88dd..0f5a94986 100644 --- a/tlvccmd/sys_utils/Makefile +++ b/tlvccmd/sys_utils/Makefile @@ -1,20 +1,12 @@ BASEDIR=.. -include $(BASEDIR)/Make.defs - -############################################################################### -# -# Include standard packaging commands. - -include $(BASEDIR)/Make.rules +include $(BASEDIR)/Makefile-rules ############################################################################### TLVC_LIB=$(TLVC_DIR)/arch/i86/lib # clock enabled and has direct I/O port access -# knl, insmod removed as useless -# exitemu disabled because it calls INT directly to DOSEMU PRGS = \ init \ getty \ diff --git a/tlvccmd/sys_utils/exitemu.s b/tlvccmd/sys_utils/exitemu.s deleted file mode 100644 index 01d031964..000000000 --- a/tlvccmd/sys_utils/exitemu.s +++ /dev/null @@ -1,8 +0,0 @@ -# Program to exit dosemu when it is running ELKS. -# by David Murn -export _main -_main: - mov ax,#0xffff - int 0xe6 -.data -.bss diff --git a/tlvccmd/sys_utils/insmod.c b/tlvccmd/sys_utils/insmod.c deleted file mode 100644 index 0ab3cffb8..000000000 --- a/tlvccmd/sys_utils/insmod.c +++ /dev/null @@ -1,115 +0,0 @@ -#include -/* #include */ -#include -#include -#include -#include -#include -#include - -char *failed = "insmod: failed\n"; -#define F_LEN 15 -#define STDERR_FILENO 2 - -static char modbuf[DATASIZE < TEXTSIZE ? TEXTSIZE : DATASIZE]; - -int main(argc,argv) -int argc; -char **argv; -{ - int od,md,i; - char fname[20]; - unsigned int data, text, len, doff, coff; - off_t datap, textp; - struct stat buf; - - if (argc != 2) { - write(STDERR_FILENO, "usage: insmod \n",23); - exit(1); - } - /* Clean up the old module */ - insmod(MOD_TERM); - /* Open the mem device to access kernel space */ - if ((md = open("/dev/mem",O_WRONLY)) == -1) { - write(STDERR_FILENO, failed, F_LEN); - write(STDERR_FILENO, "Could not open /dev/mem.\n",25); - exit(errno); - } - /* Get the addresses in kernel space to copy the module to */ - if (((ioctl(md, MEM_GETMODTEXT, &text)) == -1) || - ((ioctl(md, MEM_GETMODDATA, &data)) == -1) || - ((ioctl(md, MEM_GETDS, &doff)) == -1) || - ((ioctl(md, MEM_GETCS, &coff)) == -1)) { - write(STDERR_FILENO, failed, F_LEN); - write(STDERR_FILENO, "Kernel does not support modules.\n",33); - exit(errno); - } - /* Calculate /dev/mem seek points */ - datap = ((long)doff << 4) + (long)data; - textp = ((long)coff << 4) + (long)text; - /* Open .T */ - strcpy(fname, argv[1], 15); - strcat(fname, ".T"); - if ((od = open(fname,O_RDONLY)) == -1) { - write(STDERR_FILENO, failed, F_LEN); - write(STDERR_FILENO, "Could not open module ",22); - write(STDERR_FILENO, argv[1], strlen(argv[1])); - exit(errno); - } - if ((fstat(od, &buf)) == -1) { - write(STDERR_FILENO, failed, F_LEN); - exit(errno); - } - if ((len = buf.st_size) > TEXTSIZE) { - write(STDERR_FILENO, failed, F_LEN); - write(STDERR_FILENO, "Module too big.\n",16); - exit(errno); - } - if ((lseek(md, textp, SEEK_SET)) == -1) { - write(STDERR_FILENO, failed, F_LEN); - exit(errno); - } - /* Copy .T into the kernel */ - if ((read(od, modbuf, len)) != len) { - write(STDERR_FILENO, failed, F_LEN); - exit(errno); - } - if ((write(md, modbuf, len)) != len) { - write(STDERR_FILENO, failed, F_LEN); - exit(errno); - } - /* Open .D */ - strcpy(fname, argv[1], 15); - strcat(fname, ".D"); - if ((od = open(fname,O_RDONLY)) == -1) { - write(STDERR_FILENO, failed, F_LEN); - write(STDERR_FILENO, "Could not open module ",22); - write(STDERR_FILENO, argv[1], strlen(argv[1])); - exit(errno); - } - if ((fstat(od, &buf)) == -1) { - write(STDERR_FILENO, failed, F_LEN); - exit(errno); - } - if ((len = buf.st_size) > TEXTSIZE) { - write(STDERR_FILENO, failed, F_LEN); - write(STDERR_FILENO, "Module too big.\n",16); - exit(errno); - } - if ((lseek(md, datap, SEEK_SET)) == -1) { - write(STDERR_FILENO, failed, F_LEN); - exit(errno); - } - /* Copy .D into the kernel */ - if ((read(od, modbuf, len)) != len) { - write(STDERR_FILENO, failed, F_LEN); - exit(errno); - } - if ((write(md, modbuf, len)) != len) { - write(STDERR_FILENO, failed, F_LEN); - exit(errno); - } - fflush(stdout); - /* Initialise the module. */ - insmod(MOD_INIT); -} diff --git a/tlvccmd/sys_utils/knl.8 b/tlvccmd/sys_utils/knl.8 deleted file mode 100644 index 2e7ba4428..000000000 --- a/tlvccmd/sys_utils/knl.8 +++ /dev/null @@ -1,298 +0,0 @@ -.\" Copyright 1998-2002 Riley H. Williams . -.\" May be distributed under the GNU General Public License. -. -.TH KNL 8 "10 June 2002" "Linux 2.0" "Linux Programmer's Manual" -. -.SH NAME -knl \- query/set kernel configuration parameters -. -.SH SYNOPSIS -.TP -.B knl -.B [--kernel=]image -.B [-f=flaglist] -.B [--flags=flaglist] -.B [--noram] -.B [-p] -.B [--prompt] -.B [--ram=offset] -.B [-r=device] -.B [--root=device] -.B [-v=mode] -.B [--video=mode] -.B [--help] -.B [--version] -. -.SH OPTIONS -.TP -.B [--kernel=]image -Selects the kernel image file of interest. -.TP -.B -f=flaglist --flags=flaglist -Specifies the kernel flags to be set. Currently, only -.B RO -is implemented, which specifies that the root file system is to be mounted -.B read-only -by default. However, for compatibility with future additions, flags of the -format -.B Xn -are also accepted, where -.B n -is in the range from -.B 0 -to -.B 15 -inclusive, and these will set the appropriate flag. -.TP -.B \ -An option of -.B None -is also implemented to indicate that no flags should be set, but if used, -the -.B None -option must be the only option specified. -.TP -.B --help\ \ \ \ -Displays a help screen, then exits. -.TP -.B --noram\ \ \ -Specifies that no ramdisk should be created by default. -.TP -.B \ -This option is incompatible with the -.B --prompt -and -.B --ram -parameters. -.TP -.B -p --prompt -Specifies that a ramdisk should be created by default, and that the -kernel should prompt for the relevant disk before loading the ramdisk -image from disk. -.TP -.B \ -This option is incompatible with the -.B --noram -option. -.TP -.B --ram=offset -Specifies that a ramdisk should be created by default, and the offset in -the disk to the start of the ramdisk image. This offset may not exceed -.B 8191 -blocks. -.TP -.B \ -This option is incompatible with the -.B --noram -option. -.TP -.B -r=device --root=device -Specifies the default device to mount as the file system root. The device -can be specified as described in the -.I DEVICES -section (below), or can be specified as -.B NFS -to indicate that the file system root is remote NFS mounted. -.TP -.B --version -Displays the program version, then exits. -.TP -.B -v=mode --video=mode -Specifies the default video mode. See the -.I VIDEO MODES -section (below) for further details. -. -.SH DESCRIPTION -In a bootable image for the -.B Linux -kernel, there are several pairs of bytes which specify various kernel -options, located at the following offsets: -.nf -.RS - - 498 1F2 Root flags - 500 1F4 Reserved - 502 1F6 Unused (was Swap Device) - 504 1F8 RAM Disk Parameters - 506 1FA VGA Mode - 508 1FC Root Device - 510 1FE Boot Signature - -.RE -.fi -.B knl -will change or display these values. -. -.SH DEVICES -Valid values for the -.B device -specification in the -.B --root -options are as follows: -.PP -.nf -.RS - -/dev/aztcd /dev/aztcd[1-255] -/dev/bd[ab] /dev/bd[ab][1-4] (ELKS) - /dev/cdouble[0-127] - /dev/double[0-127] - /dev/fd[0-3] -/dev/flash /dev/flash[1-7] -/dev/gscd /dev/gscd[1-255] -/dev/hd[a-h] /dev/hd[a-h][1-63] -/dev/hitcd /dev/hitcd[1-255] -/dev/mcd /dev/mcd[1-255] -/dev/optcd /dev/optcd[1-255] -/dev/ram /dev/ram[0-7] -/dev/rflash /dev/rflash[1-7] -/dev/rom /dev/rom[1-7] -/dev/rrom /dev/rrom[1-7] -/dev/scd /dev/scd[1-255] -/dev/sd[a-g] /dev/sd[a-g][1-15] -/dev/sjcd /dev/sjcd[1-255] -/dev/sonycd /dev/sonycd[1-255] -/dev/xda /dev/xda[1-63] -/dev/xdb /dev/xdb[1-63] - -.RE -.fi -.PP -In addition to the options listed above, -.B /dev/ramdisc -and -.B /dev/ramdisk -are synonyms for -.B /dev/ram0 -and, additionally, -.B Boot -can be used to specify the boot device, and -.B NFS -can be used to specify that the root device is on the Network File System -(NFS). The -.B /dev/ -part is optional in each case (but must -.B NOT -be prefixed to the -.B Boot -or -.B NFS -options). -.PP -In addition to the above, a general method of specifying -.B ANY -block device by its major and minor numbers has been implemented. To -specify a device that is not specifically supported (or indeed one that -is supported, if it comes to that), specify -.B Mode-X.Y -where X is the relevant -.B major -number, and Y is the appropriate -.B minor -number. -. -.SH KERNEL IMAGE SELECTION -Typical values for the -.B --kernel -option, which specifies a bootable Linux kernel image, are as follows: -.PP -.nf -.RS - -/boot/vmlinuz -/boot/vmlinuz.test -/vmlinux -/vmlinux.test -/vmunix -/vmunix.test -/dev/fd0 -/dev/fd1 - -.RE -.fi -.PP -Any other file on the disk can be specified and, providing it satisfies -the (admittedly rather basic) criteria for being a kernel image file, it -will be accepted as such. -. -.SH VIDEO MODES -Valid values for the -.B --video -option are as follows: -.nf -.RS - -Ask = Prompt for the video mode to use -EVGA = Extended VGA (80x50) -VGA = Standard VGA (80x25) - - 0 = Mode selected by choosing '0' at the prompt. - 1 = Mode selected by choosing '1' at the prompt. - 2 = Mode selected by choosing '2' at the prompt. - n = Mode selected by choosing 'n' at the prompt. - -.RE -.fi -Valid numeric arguments are in the range from -.B 0 -to -.B 65499 -inclusive, as supported by the video hardware in the system in question. -. -.SH ERRORS -The following errorlevels may be reported: -.PP -.TP -\ \ 0 -Successful completion of task. -.TP -\ \ 1 -Kernel image file not specified. -.TP -\ \ 2 -Kernel image file not found. -.TP -\ \ 3 -Specified file is not a kernel image. -.TP -\ \ 4 -Kernel image file can't be updated. -.TP -\ \ 5 -Kernel image file not updated correctly. -.TP -\ 255 -.B --help -or -.B --version -specified. -. -.SH WHEN USING LILO -If -.B LILO -is used, -.B knl -is no longer needed for setting the root device and the video mode -since these parameters that -.B knl -modifies can be set from the -.B LILO -prompt during a boot. However, -.B knl -is still needed at this time for setting the RAM disk parameters. -Users are encouraged to find the -.B LILO -documentation for more information, and to use -.B LILO -when booting their systems. -. -.SH AUTHORS -The -.B knl -program and documentation was written by Riley Williams -. It was inspired by the -.B rdev -program and documentation originally written by Werner Almesberger -, and modified by Peter MacDonald -, with root flags support added by Stephen -C. Tweedie . diff --git a/tlvccmd/sys_utils/knl.c b/tlvccmd/sys_utils/knl.c deleted file mode 100644 index f5209fe93..000000000 --- a/tlvccmd/sys_utils/knl.c +++ /dev/null @@ -1,1275 +0,0 @@ -/* KNL v1.1.0 Program to configure the initial kernel settings. - * Copyright (C) 1998-2002, Riley Williams - * - * This program and the associated documentation are distributed under - * the GNU General Public Licence (GPL), version 2 only. - * - ************************************************************************** - * - * CHANGELOG: - * ~~~~~~~~~ - * - * 1.1.0 Riley Williams - * - * * Rewrote knl to work when compiled with K&R C compilers that - * do not handle pointers as parameters correctly. - * * Ensured knl.c source code is clean to `splint -weak` so as - * to minimise the number of future problems. - * * Ensured knl.c source code is clean to `splint` with the - * default verification level so as to minimise the number of - * future problems. - * * Make DEBUG and TRACE facilities independent. - * - * 1.0.4 Riley Williams - * - * * Added ability to select NFS root device. - * * Added debugging code to trace execution. - * - * 1.0.3 Riley Williams - * - * * Bugfix - Video selection display routine did not handle - * negative values correctly. - * - * 1.0.2 Riley Williams - * - * * Implemented tweaks suggested by Debian Linux maintainers. - * - * 1.0.1 Riley Williams - * - * * Added option to allow program to run silently. - * - * 1.0.0 Riley Williams - * - * * Initial public release. - */ - -/* The following flags can be defined here for debugging purposes. - * - * DEBUG Display selected items to stderr. - * TRACE Display a trace of program execution to stderr. - */ - -/* -#define DEBUG -#define TRACE -*/ - -/* Settings for splint to ignore problems that don't apply here - */ - - /*@-boolint@*/ - /*@-exitarg@*/ - /*@-globstate@*/ - /*@-mustfreefresh@*/ - /*@-temptrans@*/ - -#define VERSION "1.1.0" - -/*@ignore@*/ - -#include -#include -#include - -/*@end@*/ - -#ifdef __BCC__ -#define signed -#endif - -#ifdef DEBUG - -#define MKDELAY - -#define debug(_s) do { delay() ; fprintf(stderr,_s); } while (0) -#define debug1(_s,_a) do { delay() ; fprintf(stderr,_s,_a); } while (0) -#define debug2(_s,_a,_b) do { delay() ; fprintf(stderr,_s,_a,_b); } while (0) -#define debug3(_s,_a,_b,_c) do { delay() ; fprintf(stderr,_s,_a,_b,_c); } while (0) -#define debug4(_s,_a,_b,_c,_d) do { delay() ; fprintf(stderr,_s,_a,_b,_c,_d); } while (0) - -#else - -#define debug(_s) -#define debug1(_s,_a) -#define debug2(_s,_a,_b) -#define debug3(_s,_a,_b,_c) -#define debug4(_s,_a,_b,_c,_d) - -#endif - -#ifdef TRACE - -#define MKDELAY - -#define trace(_s) do { delay() ; fprintf(stderr,_s); } while (0) -#define trace1(_s,_a) do { delay() ; fprintf(stderr,_s,_a); } while (0) -#define trace2(_s,_a,_b) do { delay() ; fprintf(stderr,_s,_a,_b); } while (0) -#define trace3(_s,_a,_b,_c) do { delay() ; fprintf(stderr,_s,_a,_b,_c); } while (0) -#define trace4(_s,_a,_b,_c,_d) do { delay() ; fprintf(stderr,_s,_a,_b,_c,_d); } while (0) - -#else - -#define trace(_s) -#define trace1(_s,_a) -#define trace2(_s,_a,_b) -#define trace3(_s,_a,_b,_c) -#define trace4(_s,_a,_b,_c,_d) - -#endif - -/* Standard functions used in this program - */ - -#define bit(N) (((WORD) 1) << (N)) -#define same(a,b) (strcasecmp(a,b) == 0) -#define samen(a,b,c) (strncasecmp(a,b,c) == 0) - -/* Standard types used in this program - */ - -typedef unsigned char BYTE; - -typedef unsigned short int WORD; -typedef unsigned long int DWORD; - -typedef signed short int SWORD; -typedef signed long int SDWORD; - -/* Routine to display help text. - */ - -static void help(void) -{ - fprintf(stderr, - "knl " VERSION " Program to configure initial kernel settings\n" - "Copyright (C) 1998-2002, Riley Williams \n\n" - "This program and the associated documentation are distributed under the\n" - "GNU General Public Licence (GPL), version 2 only. See the file COPYING\n" - "for details.\n\n" - "Syntax: knl [--kernel=]image [-f=flaglist] [--flags=flaglist]\n" - " [--noram] [-p] [--prompt] [--ram=offset] [-r=device]\n" - " [--root=device] [--help]\n" - " [-v=mode] [--video=mode] [--version]\n"); - exit(255); -} - -#ifdef MKDELAY - -/* Routine to pause during the display of debugging statements when - * compiled with BCC. This is included because ELKS does not currently - * support XON/XOFF on its virtual consoles, and the display scrolls - * far too fast without this delay on my 286 based laptop. It uses a - * busy loop so is very dependent on processor speed. - */ - -#ifdef __BCC__ - -static void delay(void) -{ - volatile DWORD count = (DWORD) 0; - static BYTE mark = (BYTE) 0; - - if ((++mark & 3) == 0) - while (++count < 1048576UL) - /* Do nothing */; -} - -#else - -#define delay() - -#endif /* __BCC__ */ - -#endif /* MKDELAY */ - -static int posn(char *s, char c) -{ - char *p = s; - - trace2("TRACE: posn(\"%s\",'%c')\n",s,c); - while ((*s != '\0') && (*s != c)) { - trace2("TRACE: Checking: '%c' != '%c'\n",*s,c); - s++; - } - if (*s != '\0') { - trace2("TRACE: Found '%c' at offset %u\n",c,(WORD) (s-p)); - return s - p; - } else { - trace1("TRACE: '%c' not found.\n",c); - return -1; - } -} - -static int strcasecmp(char *s, char *d) -{ - trace2("TRACE: strcasecmp(\"%s\",\"%s\")\n",s,d); - while (*s != '\0') { - trace2("TRACE: Checking '%c' against '%c'\n", - tolower(*s), tolower(*d)); - if (tolower(*s) != tolower(*d)) - break; - else { - s++; - d++; - } - } - trace2("TRACE: strcasecmp returning '%c' - '%c'\n", - tolower(*s), tolower(*d)); - return (int) (tolower(*s) - tolower(*d)); -} - -static int strncasecmp(char *s, char *d, size_t n) -{ - trace3("TRACE: strncasecmp(\"%s\",\"%s\",%u)\n",s,d,(WORD) n); - while ((n > 0) && (*s != '\0')) { - trace3("TRACE: strncasecmp: %u = '%c' <=> %c'\n", - (WORD) n, tolower(*s), tolower(*d)); - if (tolower(*s) != tolower(*d)) - break; - else { - s++; - d++; - n--; - } - } - if (n > 0) { - trace3("TRACE: strncasecmp returning %u = '%c' <=> '%c'\n", - (WORD) n, tolower(*s), tolower(*d)); - return (int) (tolower(*s) - tolower(*d)); - } else { - trace("TRACE: strncasecmp returning 0 due to length matching.\n"); - return 0; - } -} - -/* Routine to decode a value. - */ - -static char Valid = 'N'; - -static DWORD GetValue(char *Ptr, DWORD Max, char OmitOK) -{ - DWORD Value = 0; - - trace3("TRACE: GetValue(\"%s\", %lu, '%c')\n", Ptr, (DWORD) Max, OmitOK); - while ((*Ptr >= '0') && (*Ptr <= '9')) { - if (Value <= Max) - Value = (10 * Value) + (*Ptr - '0'); - trace2("TRACE: GetValue: '%c' => %lu\n", *Ptr, Value); - Ptr++; - } - if (*Ptr != '\0') - Valid = 'N'; - else if (Value > Max) - Valid = 'N'; - else if (Value > 0) - Valid = 'Y'; - else - Valid = OmitOK; - trace3("TRACE: GetValue returning %ld as %lu with Valid = '%c'\n", - (long) Value, Value, Valid); - return Value; -} - -#define GetByte(Ptr,Max,OK) (BYTE) GetValue(Ptr,(DWORD) Max,OK) -#define GetWord(Ptr,Max,OK) (WORD) GetValue(Ptr,(DWORD) Max,OK) - -/* Routine to get arbitrary major and minor numbers. It expects to be - * presented with a string in the form ${MAJOR}.${MINOR} where ${MAJOR} - * and ${MINOR} are integral decimal numbers in the range from 0 to - * 255 inclusive. It returns 256 * Major + Minor. - */ - -static char ResultBuffer[1024], *ResultPtr = ResultBuffer; - -static WORD GetMajorMinor(char *Ptr) -{ - char *Gap = Ptr, Sep; - int n; - WORD Result = (WORD) 0; - BYTE Major = (BYTE) 0, Minor = (BYTE) 0; - - trace1("TRACE: GetMajorMinor(\"%s\")\n", Ptr); - if (*Ptr != '\0') { - n = posn(Ptr,'.'); - if (n >= 0) { - Gap += n; - Sep = *Gap; - *Gap++ = '\0'; - Major = GetByte(Ptr,255,'N'); - if (Valid == 'Y') - Minor = GetByte(Gap,255,'N'); - *--Gap = Sep; - } else - Valid = 'N'; - } else - Valid = 'N'; - if (Valid == 'Y') - Result = (((WORD) Major) << 8) + ((WORD) Minor); - trace4("TRACE: GetMajorMinor returned %u (%u,%u) with Valid = '%c'\n", - Result, (WORD) Major, (WORD) Minor, Valid); - return Result; -} - -/* Routine to convert a disk reference into the relevant node numbers. - * Conversion map: - * - * Given name Major Minor Notes - * ~~~~~~~~~~ ~~~~~ ~~~~~ ~~~~~ - * Boot 0 0 Use system boot device. - * NFS 0 255 Select NFS Boot. - * - * /dev/? name Major Minor Notes - * ~~~~~~~~~~~ ~~~~~ ~~~~~ ~~~~~ - * aztcdX 29 X - * bdaX 3 X X < 64 (ELKS) - * cdoubleX 19 Y *, X < 128, Y = X + 128 - * doubleX 19 X *, X < 128 - * fdX 2 X *, X < 4 - * flashX 31 Y X < 8, Y = X + 16 - * gscdX 16 X - * hdaX 3 X X < 64 (Not ELKS) - * hdaX 5 X X < 64 (ELKS) - * hdbX 3 Y X < 64, Y = X + 64 (Not ELKS) - * hdbX 5 Y X < 64, Y = X + 64 (ELKS) - * hdcX 22 X X < 64 (Not ELKS) - * hdcX 5 Y X < 64, Y = X + 128 (ELKS) - * hddX 22 Y X < 64, Y = X + 64 (Not ELKS) - * hddX 5 Y X < 64, Y = X + 192 (ELKS) - * hdeX 33 X X < 64 - * hdfX 33 Y X < 64, Y = X + 64 - * hdgX 34 X X < 64 - * hdhX 34 Y X < 64, Y = X + 64 - * hitcdX 20 X - * mcdX 23 X - * optcdX 17 X - * ramX 1 X X < 8 - * rflashX 31 Y X < 8, Y = X + 24 - * romX 31 X X < 8 - * rromX 31 Y X < 8, Y = X + 8 - * scdX 11 X - * sdXY 8 Z 'a' <= X <= 'h', Y < 16, - * Z = 16 * (asc(X) - asc('a')) + Y - * sjcdX 18 X - * sonycdX 15 X - * xdaX 13 X X < 64 - * xdbX 13 Y X < 64, Y = X + 64 - * - * NOTE 1: With items marked *, X may NOT be omitted. - * - * NOTE 2: Anything not shown in the above list is converted to - * or from the form "Mode-X.Y" where X is the Major and - * Y the Minor associated with the device. - */ - -static WORD GetDisk(char *Name) -{ - char *Alpha = "abcdefghijklmnopqrstuvwxyz", *Ptr = NULL; - WORD Disk = (WORD) 0; - BYTE Major = (BYTE) 0, Minor = (BYTE) 0, Partition = (BYTE) 0; - - trace1("TRACE: GetDisk(\"%s\")\n", Name); - if (same(Name,"Boot")) { - trace("TRACE: Found Boot\n"); - Valid = 'Y'; - } else if (same(Name,"NFS")) { - trace("TRACE: Found NFS\n"); - Minor = (BYTE) 255; - Valid = 'Y'; - } else { - if (samen(Name,"/dev/",5)) { - Name += 5; - trace("TRACE: Skipping leading /dev/\n"); - } - Valid = 'N'; - switch (tolower(*Name)) { - case 'a': - if (samen(Name,"aztcd",5)) { - trace("TRACE: Found /dev/aztcd...\n"); - Major = (BYTE) 29; - Minor = GetByte(Name+5,255,'Y'); - } - break; -#ifdef __BCC__ - case 'b': - switch (tolower(Name[1])) { - case 'd': - Partition = (BYTE) posn("ab",tolower(Name[2])); - if (Partition < 4) { - trace("TRACE: Found /dev/bd...\n"); - Partition *= (BYTE) 64; - Major = (BYTE) 3; - Minor = GetByte(Name+3,63,'Y') + Partition; - } - break; - default: - break; - } - break; -#endif - case 'c': - if (samen(Name,"cdouble",7) != 0) { - trace("TRACE: Found /dev/cdouble...\n"); - Major = (BYTE) 19; - Minor = GetByte(Name+7,127,'N') + (BYTE) 128; - } - break; - case 'd': - if (samen(Name,"double",6)) { - trace("TRACE: Found /dev/double...\n"); - Major = (BYTE) 19; - Minor = GetByte(Name+6,127,'N'); - } - break; - case 'f': - switch (tolower(Name[1])) { - case 'd': - trace("TRACE: Found /dev/fd...\n"); - if (Name[2] == '\0') { - Major = (BYTE) 2; - Minor = GetByte(Name+2,3,'N'); - } - break; - case 'l': - if (samen(Name,"flash",5)) { - trace("TRACE: Found /dev/flash...\n"); - Major = (BYTE) 31; - Minor = GetByte(Name+5,7,'N') + (BYTE) 16; - } - break; - default: - trace("TRACE: Found unknown /dev/f...\n"); - break; - } - break; - case 'g': - if (samen(Name,"gscd",4)) { - trace("TRACE: Found /dev/gscd...\n"); - Major = (BYTE) 16; - Minor = GetByte(Name+4,255,'Y'); - } - break; - case 'h': - switch (tolower(Name[1])) { - case 'd': - if (Name[2] != '\0') { - trace("TRACE: Found /dev/hd...\n"); - Minor = GetByte(Name+3,63,'Y'); - if ((Name[2] & '\1') == '\0') - Minor += (BYTE) 64; - switch (tolower(Name[2] - '\1') | '\1') { - case 'a': -#ifdef __BCC__ - Major = (BYTE) 5; -#else - Major = (BYTE) 3; -#endif - break; - case 'c': -#ifdef __BCC__ - Major = (BYTE) 5; - Minor += (BYTE) 128; -#else - Major = (BYTE) 22; -#endif - break; - case 'e': - Major = (BYTE) 33; - break; - case 'g': - Major = (BYTE) 34; - break; - default: - Valid = 'N'; - break; - } - } else { - trace("TRACE: Found unknown /dev/hd\n"); - } - break; - case 'i': - if (samen(Name,"hitcd",5)) { - trace("TRACE: Found /dev/hitcd...\n"); - Major = (BYTE) 20; - Minor = GetByte(Name+5,255,'Y'); - } - break; - default: - break; - } - break; - case 'm': - switch (tolower(Name[1])) { - case 'c': - if (samen(Name,"mcd",3)) { - trace("TRACE: Found /dev/mcd...\n"); - Major = (BYTE) 23; - Minor = GetByte(Name+3,255,'Y'); - } - break; - case 'o': - if (samen(Name,"Mode-",5)) { - trace("TRACE: Found Mode-...\n"); - Disk = GetMajorMinor(Name+5); - Major = (BYTE) (Disk >> 8); - Minor = (BYTE) (Disk & 255); - } - break; - default: - break; - } - break; - case 'o': - if (samen(Name,"optcd",5)) { - trace("TRACE: Found /dev/optcd...\n"); - Major = (BYTE) 17; - Minor = GetByte(Name+5,255,'Y'); - } - break; - case 'r': - switch (tolower(Name[1])) { - case 'a': - if (samen(Name,"ram",3)) { - trace("TRACE: Found /dev/ram...\n"); - Major = (BYTE) 1; - if (samen(Name+3,"dis",3)) { - trace("TRACE: Found /dev/ramdis...\n"); - if (Name[7]=='\0') { - if (posn("ck",tolower(Name[6])) >= 0) { - Valid = 'Y'; - Minor = (BYTE) 0; - } else - Valid = 'N'; - } else - Valid = 'N'; - } else - Minor = GetByte(Name+3,7,'M'); - } - break; - case 'f': - if (samen(Name,"rflash",6)) { - trace("TRACE: Found /dev/rflash...\n"); - Major = (BYTE) 31; - Minor = GetByte(Name+6,7,'N') + (BYTE) 24; - } - break; - case 'o': - if (samen(Name,"rom",3)) { - trace("TRACE: Found /dev/rom...\n"); - Major = (BYTE) 31; - Minor = GetByte(Name+3,7,'N'); - } - break; - case 'r': - if (samen(Name,"rrom",4)) { - trace("TRACE: Found /dev/rrom...\n"); - Major = (BYTE) 31; - Minor = GetByte(Name+4,7,'N') + (BYTE) 8; - } - break; - default: - break; - } - break; - case 's': - switch (tolower(Name[1])) { - case 'c': - if (samen(Name,"scd",3)) { - trace("TRACE: Found /dev/scd...\n"); - Major = (BYTE) 11; - Minor = GetByte(Name+3,255,'Y'); - } - break; - case 'd': - trace("TRACE: Found /dev/sd...\n"); - Ptr = Alpha + posn(Alpha,tolower(Name[2])); - if ((Ptr >= Alpha) && ((Ptr - Alpha) < 16)) { - Major = (BYTE) 8; - Minor = (BYTE) (16 * (Ptr - Alpha)); - Minor += GetByte(Name+3,15,'Y'); - } else - Valid = 'N'; - break; - case 'j': - if (samen(Name,"sjcd",4)) { - trace("TRACE: Found /dev/sjcd...\n"); - Major = (BYTE) 18; - Minor = GetByte(Name+4,255,'Y'); - } - break; - case 'o': - if (samen(Name,"sonycd",6)) { - trace("TRACE: Found /dev/sonycd...\n"); - Major = (BYTE) 15; - Minor = GetByte(Name+6,255,'Y'); - } - break; - default: - break; - } - break; - case 'x': - switch (tolower(Name[1])) { - case 'd': - trace("TRACE: Found /dev/xd...\n"); - Partition = (BYTE) posn("ab",tolower(Name[2])); - if (Partition < 2) { - Partition *= (BYTE) 64; - Major = (BYTE) 13; - Minor = GetByte(Name+3,63,'Y') + Partition; - } - break; - default: - break; - } - break; - default: - break; - } - } - if (Valid == 'Y') - Disk = (((WORD) Major) << 8) + (WORD) Minor; - trace2("TRACE: GetDisk returning 0x%04X with Valid = '%c'\n", - Disk, Valid); - return Disk; -} - -/* Routine to analyse the parameters to the "-f=" and "--flags=" options - * and set the flags accordingly. - * - * Flag mapping is as follows: - * - * Bits Name Definition - * ==== ==== ========== - * 0 RO Mount root file system read-only. - * 15-1 Xn Reserved. - * - * All other bits are undefined, and set to zero. - */ - -static WORD GetFlags(char *Ptr) -{ - char *Next; - WORD Value = (WORD) 0; - BYTE Result = (BYTE) 0; - - trace1("TRACE: GetFlags(\"%s\")\n", Ptr); - Valid = 'Y'; - if (same(Ptr,"None")) - while (Ptr != NULL) { - Next = Ptr + posn(Ptr,','); - if (Next != NULL) - *Next++ = '\0'; - switch (toupper(*Ptr)) { - case 'R': - if (!same(Ptr,"RO")) - Value |= 1; - else - Valid = 'N'; - break; - case 'X': - Result = GetByte(Ptr+1,15,'N'); - if (Valid == 'Y') - Value |= bit(Result); - break; - default: - Valid = 'N'; - } - Ptr = Next; - } - trace2("TRACE: GetFlags returned %u with Valid = '%c'\n", Value, Valid); - return Value; -} - -/* Routine to analyse the "--ram=" option and set the offset to the start - * of the ramdisk image. A maximum of 8,191 blocks is enforced. - */ - -static WORD GetRAM(char *Ptr) -{ - WORD Result; - - trace1("TRACE: GetRAM(\"%s\")\n", Ptr); - Result = GetWord(Ptr,8191,'N'); - trace2("TRACE: GetRAM returned %u with Valid = '%c'\n", Result, Valid); - return Result; -} - -/* Routine to analyse the "--video=" option and set the relevant - * initial video mode depending on the parameter supplied. - * - * Valid options are: - * - * 1. The keyword "ASK" which returns a value of -3. - * - * 2. The keyword "EVGA" which returns a value of -2. - * - * 3. The keyword "VGA" which returns a value of -1. - * - * 4. A number in the range 0 to 65,499 which sets the appropriate - * video mode. '0' normally corresponds to an 80x25 display and - * '1' to an 80x50 display. - * - * Options 1 through 3 are NOT case sensitive. - */ - -static WORD GetVideo(char *Ptr) -{ - WORD Result = 0; - - trace1("TRACE: GetVideo(\"%s\")\n", Ptr); - switch (toupper(*Ptr)) { - case 'A': - if (!same(Ptr,"Ask")) { - Result = (WORD) (-3); - Valid = 'Y'; - } - break; - case 'E': - if (!same(Ptr,"EVGA")) { - Result = (WORD) (-2); - Valid = 'Y'; - } - break; - case 'V': - if (!same(Ptr,"VGA")) { - Result = (WORD) (-1); - Valid = 'Y'; - } - break; - default: - Result = GetWord(Ptr,65549,'N'); - break; - } - trace2("TRACE: GetVideo returned %u with Valid = '%c'\n", Result, Valid); - return Result; -} - -/* Routine to decode a disk number into a disk name. - */ - -static char *SetDisk(WORD Value) -{ - char *Result = ResultPtr; - BYTE Major = (BYTE) (Value >> 8); - BYTE Minor = (BYTE) (Value & 255); - - trace3("TRACE: SetDisk(%X) = (%u,%u)\n", - Value, (WORD) Major, (WORD) Minor); - ResultPtr += 32; - sprintf(Result, "Mode-%u.%u", (WORD) Major, (WORD) Minor); - switch (Major) { - case 0: - switch (Minor) { - case 0: - sprintf(Result, "Boot"); - break; - case 255: - sprintf(Result, "NFS"); - break; - default: - break; - } - break; - case 1: - if (Minor < (BYTE) 8) - sprintf(Result, "/dev/ram%u", (WORD) Minor); - break; - case 2: - strcpy(Result, "/dev/fd0"); - Result[7] += (char) (Minor % 4); - if (Minor > (BYTE) 4) - sprintf(Result+8, "* (Mode-4.%u)", (WORD) Minor); - break; - case 3: - if (Minor < (BYTE) 128) { -#ifdef __BCC__ - sprintf(Result, "/dev/bda%u", (WORD) (Minor % 64)); -#else - sprintf(Result, "/dev/hda%u", (WORD) (Minor % 64)); -#endif - if ((Minor & (BYTE) 64) != (BYTE) 0) - Result[7] += (char) 1; -#ifdef __BCC__ - if ((Minor & (BYTE) 128) != (BYTE) 0) - Result[7] += (char) 2; -#endif - if ((Minor % (BYTE) 64) == (BYTE) 0) - Result[8] = '\0'; - } - break; - case 8: - sprintf(Result, "/dev/sda%u", (WORD) (Minor % 16)); - Result[7] += (char) (Minor / (BYTE) 16); - if ((Minor % (BYTE) 16) == (BYTE) 0) - Result[8] = '\0'; - break; - case 11: - sprintf(Result, "/dev/scd%u", (WORD) Minor); - if (Minor != (BYTE) 0) - Result[8] = '\0'; - break; - case 13: - if (Minor < (BYTE) 128) { - sprintf(Result, "/dev/xda%u", (WORD) (Minor % (BYTE) 64)); - if ((Minor & (BYTE) 64) != (BYTE) 0) - Result[7] += (char) 1; - if ((Minor % (BYTE) 64) == (BYTE) 0) - Result[8] = '\0'; - } - break; - case 15: - sprintf(Result, "/dev/sonycd%u", (WORD) Minor); - if (Minor != (BYTE) 0) - Result[11] = '\0'; - break; - case 16: - sprintf(Result, "/dev/gscd%u", (WORD) Minor); - if (Minor != (BYTE) 0) - Result[9] = '\0'; - break; - case 17: - sprintf(Result, "/dev/optcd%u", (WORD) Minor); - if (Minor != (BYTE) 0) - Result[10] = '\0'; - break; - case 18: - sprintf(Result, "/dev/sjcd%u", (WORD) Minor); - if (Minor != (BYTE) 0) - Result[9] = '\0'; - break; - case 19: - if (Minor > (BYTE) 128) - sprintf(Result, "/dev/cdouble%u", (WORD) (Minor - (BYTE) 128)); - else - sprintf(Result, "/dev/double%u", (WORD) Minor); - break; - case 20: - sprintf(Result, "/dev/hitcd%u", (WORD) Minor); - if (Minor != (BYTE) 0) - Result[10] = '\0'; - break; -#ifndef __BCC__ - case 22: - if (Minor < (BYTE) 128) { - sprintf(Result, "/dev/hdc%u", (WORD) (Minor % (BYTE) 64)); - if ((Minor & (BYTE) 64) != (BYTE) 0) - Result[7] += (char) 1; - if ((Minor % (BYTE) 64) == (BYTE) 0) - Result[8] = '\0'; - } - break; -#endif - case 23: - sprintf(Result, "/dev/mcd%u", (WORD) Minor); - if (Minor != (BYTE) 0) - Result[8] = '\0'; - break; - case 29: - sprintf(Result, "/dev/aztcd%u", (WORD) Minor); - if (Minor != (BYTE) 0) - Result[10] = '\0'; - break; - case 31: - switch (Minor >> 3) { - case 0: - sprintf(Result, "/dev/rom%u", (WORD) Minor); - break; - case 1: - sprintf(Result, "/dev/rrom%u", (WORD) Minor); - break; - case 2: - sprintf(Result, "/dev/flash%u", (WORD) Minor); - break; - case 3: - sprintf(Result, "/dev/rflash%u", (WORD) Minor); - break; - default: - break; - } - break; - case 33: - if (Minor < (BYTE) 128) { - sprintf(Result, "/dev/hde%u", (WORD) (Minor % 64)); - if ((Minor & (BYTE) 64) != (BYTE) 0) - Result[7] += (char) 1; - if ((Minor % (BYTE) 64) == (BYTE) 0) - Result[8] = '\0'; - } - break; - case 34: - if (Minor < (BYTE) 128) { - sprintf(Result, "/dev/hdg%u", (WORD) (Minor % (BYTE) 64)); - if ((Minor & (BYTE) 64) != (BYTE) 0) - Result[7] += (char) 1; - if ((Minor % (BYTE) 64) == (BYTE) 0) - Result[8] = '\0'; - } - break; - default: - break; - } - trace1("TRACE: SetDisk returned \"%s\"\n", Result); - return Result; -} - -/* Routine to decode the flag word into a string. - */ - -static char *SetFlags(WORD Flags) -{ - char *Result = ResultPtr; - unsigned int i; - - trace1("TRACE: SetFlags(%X)\n", Flags); - ResultPtr += 32; - *Result = '\0'; - for (i=16; i>0; i--) - if ((Flags & bit(i)) != 0) - switch (i) { - case 0: - sprintf(Result, "%s,RO", Result); - break; - default: - sprintf(Result, "%s,X%u", Result, i); - break; - } - if (*Result == '\0') - strcpy(Result, " None"); - trace1("TRACE: SetFlags returned \"%s\"\n", Result+1); - return Result + 1; -} - -/* Routine to decode a video mode into a string. - */ - -static char *SetVideo(WORD Value) -{ - char *Result = ResultPtr; - - trace1("TRACE: SetVideo(%d)\n", (int) Value); - ResultPtr += 32; - if (Value > 65499) { - Value -= 32768; - Value = 32768 - Value; - switch (Value) { - case 0: - sprintf(Result, "0 (Normally 80x25)"); - break; - case 1: - sprintf(Result, "VGA"); - break; - case 2: - sprintf(Result, "XVGA"); - break; - case 3: - sprintf(Result, "Ask"); - break; - default: - sprintf(Result, "Undefined (-%u)", Value); - break; - } - } else if (Value == 1) - sprintf(Result, "1 (Normally 80x50)"); - else - sprintf(Result, "%u (Unknown)", Value); - trace1("TRACE: SetVideo returned \"%s\"\n", Result); - return Result; -} - -/* File buffer - */ - -#define BufStart 0x1F0 -#define BufSize 8 - -static WORD Buffer[BufSize] = { 0, 1, 2, 3, 4, 5, 6, 7 }; - -#define BufFlags Buffer[1] /* 0x01F2 - 0x01F3 */ -#define SysSize Buffer[2] /* 0x01F4 - 0x01F5 */ -#define Unused Buffer[3] /* 0x01F6 - 0x01F7 */ -#define BufRAM Buffer[4] /* 0x01F8 - 0x01F9 */ -#define BufVideo Buffer[5] /* 0x01FA - 0x01FB */ -#define BufRoot Buffer[6] /* 0x01FC - 0x01FD */ -#define BufSignature Buffer[7] /* 0x01FE - 0x01FF */ - -#define FlagsOK bit(1) -#define RamOK bit(4) -#define VideoOK bit(5) -#define RootOK bit(6) - -/****************/ -/* Main program */ -/****************/ - -int main(int c, char **v) -{ - char *Image, *Ptr, *Value; - FILE *fp; - int i = 0; - WORD Accept = 0; - WORD Flags = 0; - WORD RamOffset = 0; - WORD RootDev = 0; - WORD VideoMode = 0; - char RamPrompt = 'N'; - char UseRAM = 'N'; - - if (c == 1) - help(); - else { - Image = NULL; - for (i=1; i - -There are quite a few versions of rdev: - - - the original rootdev that only printed the current root device, by - Linus. - - rdev that does what rootdev did and that also allows you to change - the root device, by me. - - rdev got renamed to setroot and I think even to rootdev on various - distributions. - - Peter MacDonald added video mode and RAM disk setting and included - this version on SLS, called rdev again. I've attached his rdev.c to - this mail. - -------------------------------------------------------------------------- - -Date: 11 Mar 92 21:37:37 GMT -Subject: rdev - query/set root device -From: almesber@nessie.cs.id.ethz.ch (Werner Almesberger) -Organization: Swiss Federal Institute of Technology (ETH), Zurich, CH - -With all that socket, X11, disk driver and FS hacking going on, apparently -nobody has found time to address one of the minor nuisances of life: set- -ting the root FS device is still somewhat cumbersome. I've written a little -utility which can read and set the root device in boot images: - -rdev accepts an optional offset argument, just in case the address should -ever move from 508. If called without arguments, rdev outputs an mtab line -for the current root FS, just like /etc/rootdev does. - -ramsize sets the size of the ramdisk. If size is zero, no ramdisk is used. - -vidmode sets the default video mode at bootup time. -1 uses default video -mode, -2 uses menu. - -------------------------------------------------------------------------- - -Sun Dec 27 10:42:16 1992: Minor usage changes, faith@cs.unc.edu. -Tue Mar 30 09:31:52 1993: rdev -Rn to set root readonly flag, sct@dcs.ed.ac.uk -Wed Jun 22 21:12:29 1994: Applied patches from Dave - (gentzel@nova.enet.dec.com) to prevent dereferencing - the NULL pointer, faith@cs.unc.edu -1999-02-22 Arkadiusz Mi¶kiewicz -- added Native Language Support - -Sat Jul 13 2002 : Ported to ELKS(by removing native language support) - Harry Kalogirou - -------------------------------------------------------------------------- - -*/ - -#include -#include -#include - -/* rdev.c - query/set root device. */ - -# undef bindtextdomain -# define bindtextdomain(Domain, Directory) /* empty */ -# undef textdomain -# define textdomain(Domain) /* empty */ -# define _(Text) (Text) -# define N_(Text) (Text) - -static void usage(void) { - - puts(_("usage: rdev [ -rv ] [ -o OFFSET ] [ IMAGE [ VALUE [ OFFSET ] ] ]")); - puts(_(" rdev /dev/fd0 (or rdev /linux, etc.) displays the current ROOT device")); - puts(_(" rdev /dev/fd0 /dev/hda2 sets ROOT to /dev/hda2")); - puts(_(" rdev -R /dev/fd0 1 set the ROOTFLAGS (readonly status)")); - puts(_(" rdev -r /dev/fd0 627 set the RAMDISK size")); - puts(_(" rdev -v /dev/fd0 1 set the bootup VIDEOMODE")); - puts(_(" rdev -o N ... use the byte offset N")); - puts(_(" rootflags ... same as rdev -R")); - puts(_(" ramsize ... same as rdev -r")); - puts(_(" vidmode ... same as rdev -v")); - puts(_("Note: video modes are: -3=Ask, -2=Extended, -1=NormalVga, 1=key1, 2=key2,...")); - puts(_(" use -R 1 to mount root readonly, -R 0 for read/write.")); - exit(-1); -} - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#define DEFAULT_OFFSET 508 -#define PATH_MAX 128 - -static void die(char *msg) -{ - perror(msg); - exit(1); -} - -/* Earlier rdev fails on /dev/ida/c0d0p1 so we allow for - recursion in /dev. -- Paul Clements */ -/* In fact devfs needs deep recursion. */ - -static int find_dev_recursive(char *dirnamebuf, int number) -{ - DIR *dp; - struct dirent *dir; - struct stat s; - int dirnamelen = 0; - - if ((dp = opendir(dirnamebuf)) == NULL) - die("opendir"); - dirnamelen = strlen(dirnamebuf); - while ((dir = readdir(dp)) != NULL) { - if (!strcmp(dir->d_name, ".") || !strcmp(dir->d_name, "..")) - continue; - if (dirnamelen + 1 + strlen(dir->d_name) > PATH_MAX) - continue; - dirnamebuf[dirnamelen] = '/'; - strcpy(dirnamebuf+dirnamelen+1, dir->d_name); - if (lstat(dirnamebuf, &s) < 0) - continue; - if ((s.st_mode & S_IFMT) == S_IFBLK && s.st_rdev == number) - return 1; - if ((s.st_mode & S_IFMT) == S_IFDIR && - find_dev_recursive(dirnamebuf, number)) - return 1; - } - dirnamebuf[dirnamelen] = 0; - closedir(dp); - return 0; -} - -static char *find_dev(int number) -{ - static char name[PATH_MAX+1]; - - if (!number) - return "Boot device"; - strcpy(name, "/dev"); - if (find_dev_recursive(name, number)) - return name; - sprintf(name, "0x%04x", number); - return name; -} - -/* The enum values are significant, things are stored in this order, - see bootsect.S */ -enum { RDEV, VIDMODE, RAMSIZE, __unused__, __syssize__, ROOTFLAGS }; -char *cmdnames[6] = { "rdev", "vidmode", "ramsize", "", - "", "rootflags"}; -char *desc[6] = { "Root device", "Video mode", "Ramsize", "", - "", "Root flags"}; -#define shift(n) argv+=n,argc-=n - -int main(int argc, char **argv) -{ - int image, offset, dev_nr, i, newoffset=-1; - char *ptr; - unsigned short val, have_val; - struct stat s; - int cmd; - - /* use the command name to figure out what we have to do - ugly */ - cmd = RDEV; - if ((ptr = strrchr(argv[0],'/')) != NULL) ptr++; - else ptr = argv[0]; - - for (i=0; i<=5; i++) { - if (!strcmp(ptr,cmdnames[i])) { - cmd = i; - break; - } - } - - while (argc > 1) { - if (argv[1][0] != '-') - break; - switch (argv[1][1]) { - case 'R': - cmd = ROOTFLAGS; - shift(1); - break; - case 'r': - cmd = RAMSIZE; - shift(1); - break; - case 'v': - cmd = VIDMODE; - shift(1); - break; - case 'o': - if (argv[1][2]) { - newoffset = atoi(argv[1]+2); - shift(1); - break; - } else if (argc > 2) { - newoffset = atoi(argv[2]); - shift(2); - break; - } - /* Fall through. . . */ - default: - usage(); - } - } - - /* Here the only sensible way of using rdev */ - if (argc == 1) { - if (cmd == RDEV) { - if (stat("/",&s) < 0) die("/"); - printf("%s /\n", find_dev(s.st_dev)); - exit(0); - } - usage(); - } - - if (argc > 4) usage(); - - /* Ancient garbage.. */ - offset = DEFAULT_OFFSET-cmd*2; - if (newoffset >= 0) offset = newoffset; - if (argc == 4) offset = atoi(argv[3]); - - have_val = 0; - - if (argc >= 3) { - if (cmd == RDEV) { - if (isdigit(*argv[2])) { - /* earlier: specify offset */ - /* now: specify major,minor */ - char *p; - unsigned int ma,mi; - if ((p = strchr(argv[2], ',')) == NULL) - die(_("missing comma")); - ma = atoi(argv[2]); - mi = atoi(p+1); - val = ((ma<<8) | mi); - } else { - char *device = argv[2]; - if (stat(device,&s) < 0) - die(device); - val = s.st_rdev; - } - } else { - val = atoi(argv[2]); - } - have_val = 1; - } - - if (have_val) { - if ((image = open(argv[1],O_WRONLY)) < 0) die(argv[1]); - if (lseek(image,offset,0) < 0) die("lseek"); - if (write(image,(char *)&val,2) != 2) die(argv[1]); - if (close(image) < 0) die("close"); - } else { - if ((image = open(argv[1],O_RDONLY)) < 0) die(argv[1]); - if (lseek(image,offset,0) < 0) die("lseek"); - dev_nr = 0; - if (read(image,(char *)&dev_nr,2) != 2) die(argv[1]); - if (close(image) < 0) die("close"); - fputs(desc[cmd], stdout); - if (cmd == RDEV) - printf(" %s\n", find_dev(dev_nr)); - else - printf(" %d\n", dev_nr); - } - return 0; -} diff --git a/tlvccmd/test/libc/Makefile b/tlvccmd/test/libc/Makefile index 61264e3f7..d7b661510 100644 --- a/tlvccmd/test/libc/Makefile +++ b/tlvccmd/test/libc/Makefile @@ -1,8 +1,8 @@ # Makefile for libc tests -BASEDIR=../.. +BASEDIR=../../.. -include $(BASEDIR)/Make.defs +include $(BASEDIR)/Makefile-rules PGM = test_libc @@ -22,8 +22,6 @@ SRCS = \ OBJS = $(SRCS:.c=.o) -include $(BASEDIR)/Make.rules - all: $(PGM) $(PGM): $(OBJS)