From b41b1718f387085c8846a5693024588bc1b666ff Mon Sep 17 00:00:00 2001 From: Greg Haerr Date: Tue, 19 Nov 2024 12:17:30 -0800 Subject: [PATCH 1/3] [cmds] Add arena numbers to meminfo -m, reduce size back to 4K --- elkscmd/sys_utils/meminfo.c | 74 +++++++++++++++++++------------------ elkscmd/tui/.gitignore | 7 ++-- 2 files changed, 43 insertions(+), 38 deletions(-) diff --git a/elkscmd/sys_utils/meminfo.c b/elkscmd/sys_utils/meminfo.c index ebe53d05e..7ad22e6db 100644 --- a/elkscmd/sys_utils/meminfo.c +++ b/elkscmd/sys_utils/meminfo.c @@ -31,6 +31,7 @@ int sflag; /* show system memory*/ int mflag; /* show main memory*/ int allflag; /* show all memory*/ +int fd; unsigned int ds; unsigned int heap_all; unsigned int seg_all; @@ -38,7 +39,7 @@ unsigned int taskoff; 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; @@ -49,39 +50,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); } @@ -98,65 +99,68 @@ 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; static char *heaptype[] = { "free", "MEM ", "DRVR", "TTY ", "TASK", "BUFH", "PIPE", "INOD", "FILE", "CACH"}; - printf(" HEAP TYPE SIZE SEG TYPE SIZE CNT NAME\n"); + /* split into two to save floppy space; linker will combine 2nd with above printf */ + printf(" HEAP TYPE SIZE"); + printf(" SEG TYPE SIZE 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) @@ -176,14 +180,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/%5u Total mem %7ld\n", total_size, total_free, total_segsize); @@ -196,7 +200,7 @@ void usage(void) int main(int argc, char **argv) { - int fd, c; + int c; struct mem_usage mu; if (argc < 2) @@ -242,12 +246,12 @@ 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); + 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*/ diff --git a/elkscmd/tui/.gitignore b/elkscmd/tui/.gitignore index 860d2b850..4ebb01ed0 100644 --- a/elkscmd/tui/.gitignore +++ b/elkscmd/tui/.gitignore @@ -1,9 +1,10 @@ *.o +cons fm +invaders matrix -cons -ttyinfo sl ttyclock -ttytetris +ttyinfo ttypong +ttytetris From 88de0cdf04e778f2ea922bb95caa46ef3d047a41 Mon Sep 17 00:00:00 2001 From: Greg Haerr Date: Tue, 19 Nov 2024 12:41:05 -0800 Subject: [PATCH 2/3] Prohibit GCC from using fputs instead of fprintf --- elkscmd/Makefile-rules | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/elkscmd/Makefile-rules b/elkscmd/Makefile-rules index 95cfe4f9a..d3554d876 100644 --- a/elkscmd/Makefile-rules +++ b/elkscmd/Makefile-rules @@ -48,7 +48,7 @@ HOSTCFLAGS = -O3 CLBASE = -mcmodel=small -melks-libc -mtune=i8086 -Wall -Os CLBASE += -mno-segment-relocation-stuff -CLBASE += -fno-inline -fno-builtin-printf +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 From acc02720cd9585e2f9ce3cd6dbce49c89578f630 Mon Sep 17 00:00:00 2001 From: Greg Haerr Date: Tue, 19 Nov 2024 12:42:19 -0800 Subject: [PATCH 3/3] Add comment clarifying reading only 1st sector of MINIX superblock at boot --- bootblocks/boot_minix.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bootblocks/boot_minix.c b/bootblocks/boot_minix.c index 210950e1e..0f3c5dcf7 100644 --- a/bootblocks/boot_minix.c +++ b/bootblocks/boot_minix.c @@ -122,7 +122,7 @@ static int strcmp (const char * s, const char * d) static void load_super () { - disk_read (2, 1, sb_block, seg_data ()); + disk_read (2, 1, sb_block, seg_data ()); /* cheat and read only first sector */ /* if (sb_data->s_log_zone_size) {