Skip to content

Commit

Permalink
Merge pull request #2201 from ghaerr/copyc86
Browse files Browse the repository at this point in the history
[build] Create full development disk from 8086 toolchain on /usr
  • Loading branch information
ghaerr authored Jan 27, 2025
2 parents 17e73b5 + 64c84cb commit dccc295
Show file tree
Hide file tree
Showing 8 changed files with 119 additions and 26 deletions.
75 changes: 61 additions & 14 deletions copyc86.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/usr/bin/env bash
#
# copyc86.sh - copy native ELKS C86 toolchain, header files and examples to ELKS /root
# copyc86.sh - copy native ELKS C86 toolchain, header files and examples to ELKS /usr
#
# Usage: ./copyc86.sh
#
Expand All @@ -18,21 +18,68 @@ if [ -z "$C86" ]
exit
fi

DEST=$TOPDIR/elkscmd/rootfs_template/root
# create and copy to /usr/bin, /usr/lib, /usr/include, /usr/src on destination
DEST=$TOPDIR/elkscmd/rootfs_template/usr
mkdir -p $DEST
mkdir -p $DEST/bin
mkdir -p $DEST/lib
mkdir -p $DEST/include
mkdir -p $DEST/include/sys
mkdir -p $DEST/include/linuxmt
mkdir -p $DEST/include/arch
mkdir -p $DEST/include/c86
mkdir -p $DEST/src

cd $TOPDIR
cp -p libc/include/c86/*.h $DEST
cp -p libc/libc86.a $DEST
cp -p libc/include/alloca.h $DEST/include
cp -p libc/include/ctype.h $DEST/include
cp -p libc/include/errno.h $DEST/include
cp -p libc/include/fcntl.h $DEST/include
cp -p libc/include/features.h $DEST/include
cp -p libc/include/limits.h $DEST/include
cp -p libc/include/malloc.h $DEST/include
cp -p libc/include/signal.h $DEST/include
cp -p libc/include/stdint.h $DEST/include
cp -p libc/include/stdlib.h $DEST/include
cp -p libc/include/stdio.h $DEST/include
cp -p libc/include/string.h $DEST/include
cp -p libc/include/termios.h $DEST/include
cp -p libc/include/time.h $DEST/include
cp -p libc/include/unistd.h $DEST/include
cp -p libc/include/sys/cdefs.h $DEST/include/sys
cp -p libc/include/sys/ioctl.h $DEST/include/sys
cp -p libc/include/sys/select.h $DEST/include/sys
cp -p libc/include/sys/stat.h $DEST/include/sys
cp -p libc/include/sys/types.h $DEST/include/sys
cp -p libc/include/c86/*.h $DEST/include/c86

cp -p elks/include/linuxmt/errno.h $DEST/include/linuxmt
cp -p elks/include/linuxmt/fcntl.h $DEST/include/linuxmt
cp -p elks/include/linuxmt/ioctl.h $DEST/include/linuxmt
cp -p elks/include/linuxmt/limits.h $DEST/include/linuxmt
cp -p elks/include/linuxmt/types.h $DEST/include/linuxmt
cp -p elks/include/linuxmt/posix_types.h $DEST/include/linuxmt
cp -p elks/include/linuxmt/signal.h $DEST/include/linuxmt
cp -p elks/include/linuxmt/stat.h $DEST/include/linuxmt
cp -p elks/include/linuxmt/termios.h $DEST/include/linuxmt
cp -p elks/include/linuxmt/time.h $DEST/include/linuxmt
cp -p elks/include/arch/cdefs.h $DEST/include/arch
cp -p elks/include/arch/divmod.h $DEST/include/arch
cp -p elks/include/arch/posix_types.h $DEST/include/arch
cp -p elks/include/arch/stat.h $DEST/include/arch
cp -p elks/include/arch/types.h $DEST/include/arch

cp -p libc/libc86.a $DEST/lib

cd $C86
cp -p elks-bin/make $DEST
cp -p elks-bin/cpp86 $DEST
cp -p elks-bin/c86 $DEST
cp -p elks-bin/as86 $DEST
cp -p elks-bin/ld86 $DEST
cp -p elks-bin/ar86 $DEST
cp -p elks-bin/objdump86 $DEST
cp -p elks-bin/disasm86 $DEST
cp -p elks-bin/make $DEST/bin
cp -p elks-bin/cpp86 $DEST/bin
cp -p elks-bin/c86 $DEST/bin
cp -p elks-bin/as86 $DEST/bin
cp -p elks-bin/ld86 $DEST/bin
cp -p elks-bin/ar86 $DEST/bin
cp -p elks-bin/objdump86 $DEST/bin
cp -p elks-bin/disasm86 $DEST/bin
cd examples
cp -p *.c *.h *.s $DEST
cp -p Makefile.elks $DEST/Makefile
cp -p *.c *.h *.s $DEST/src
cp -p Makefile.elks $DEST/src/Makefile
15 changes: 15 additions & 0 deletions elks/arch/i86/mm/malloc.c
Original file line number Diff line number Diff line change
Expand Up @@ -350,6 +350,21 @@ void seg_free_pid(pid_t pid)
}
}

// verify passed address range within process-owned memory
int seg_verify_area(pid_t pid, seg_t base, segoff_t offset)
{
list_s *n;

for (n = _seg_all.next; n != &_seg_all; ) {
segment_s * seg = structof (n, segment_s, all);

if (seg->pid == pid && seg->base == base)
return offset < (seg->size << 4);
n = seg->all.next;
}
return 0;
}

void INITPROC seg_add(seg_t start, seg_t end)
{
segment_s * seg = (segment_s *) heap_alloc (sizeof (segment_s), HEAP_TAG_SEG);
Expand Down
28 changes: 23 additions & 5 deletions elks/arch/i86/mm/user.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,31 @@

int verfy_area(void *p, size_t len)
{
/*
* Kernel tasks can always access user process boundaries
*/
if ((kernel_ds == current->t_regs.ds) ||
((segoff_t)((char *)p + len) <= current->t_endseg))
int i;
segoff_t offset;

/* Kernel tasks can always access user process boundaries */
if (kernel_ds == current->t_regs.ds)
return 0;

offset = (segoff_t)((char *)p + len);

/* use fast method when DS == SS indicating default data segment request */
if (current->t_regs.ds == current->t_regs.ss)
return (offset < current->t_endseg)? 0: -EFAULT;

/* check allocated code and data segments with syscall DS segment */
for (i = 0; i < MAX_SEGS; i++) {
if (current->mm[i] && (current->mm[i]->base == current->t_regs.ds) &&
offset < (current->mm[i]->size << 4)) /* task segments never >= 64k */
return 0;
}

/* check fmemalloc allocations in main memory (slow) */
if (seg_verify_area(current->pid, current->t_regs.ds, offset))
return 0;

printk("FAULT\n");
return -EFAULT;
}

Expand Down
2 changes: 1 addition & 1 deletion elks/fs/read_write.c
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ int sys_write(unsigned int fd, char *buf, size_t count)
register struct inode *inode;
int written;

debug_file("write %d, buf, %u\n", fd, count);
debug("write %d, buf, %u\n", fd, count);
if (((written = fd_check(fd, buf, count, FMODE_WRITE, &file)) == 0) && count) {
written = -EINVAL;
fop = file->f_op;
Expand Down
1 change: 1 addition & 0 deletions elks/include/linuxmt/mm.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ int strlen_fromfs(void *,size_t);
#define verify_area(mode,point,size) verfy_area(point,size)

int verfy_area(void *,size_t);
int seg_verify_area(pid_t pid, seg_t base, segoff_t offset);
void put_user_char(unsigned char,void *);
void put_user(unsigned short,void *);
void put_user_long(unsigned long,void *);
Expand Down
2 changes: 1 addition & 1 deletion elkscmd/rootfs_template/etc/profile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export PATH=/bin
export PATH=/bin:/usr/bin
PS1="$HOSTNAME$PS1"
umask 022
#FAT permissions fix
Expand Down
1 change: 0 additions & 1 deletion libc/include/c86/stdint.h
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,6 @@

#define UINT_FAST8_MAX 65535U
#define UINT_FAST16_MAX 65535U
#define UINT_FAST16_MAX 4294967295U
#define UINT_FAST32_MAX 4294967295UL
#define UINT_FAST64_MAX 18446744073709551615ULL

Expand Down
21 changes: 17 additions & 4 deletions libc/malloc/fmalloc.c
Original file line number Diff line number Diff line change
Expand Up @@ -134,8 +134,18 @@ _fmalloc(size_t nbytes)

ASSERT(allocp>=(NPTR)allocs && allocp<=alloct);
ASSERT(malloc_check_heap());
/* combine free areas at heap start before allocating from free area past allocp */
//allocp = (NPTR)allocs; /* NOTE: start at last allocation for speed */
/*
* Start search at heap start to combine free areas before allocating
* from free area past allocp. Slower but required for best fit and
* least heap fragmentation, resulting in maximum use of heap area.
*
* Comment out following line to start at last allocation for speed,
* but this will not combine any free space until alloc top reached,
* usually resulting in highly fragmented heap without large spaces
* available.
*/
allocp = (NPTR)allocs;

for(p=allocp; ; ) {
//int f = 0, nb = 0, n = 0;
for(temp=0; ; ) {
Expand Down Expand Up @@ -166,9 +176,12 @@ _fmalloc(size_t nbytes)
debug(" (corrupt) = NULL\n");
errno = ENOMEM;
return(NULL);
} else if(++temp>1)
break;
} else {
if (++temp > 1)
break;
}
}
debug_level = 2; /* force message display below unless !DEBUG */
debug("Out of fixed heap\n");
return NULL;
}
Expand Down

0 comments on commit dccc295

Please sign in to comment.