Skip to content

Commit

Permalink
Merge pull request #2102 from ghaerr/libcasm
Browse files Browse the repository at this point in the history
[kernel,libc] Various small cleanups
  • Loading branch information
ghaerr authored Nov 16, 2024
2 parents 75aab5b + 2e6506e commit 2885524
Show file tree
Hide file tree
Showing 13 changed files with 75 additions and 173 deletions.
6 changes: 3 additions & 3 deletions elks/Makefile-rules
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@ include $(TOPDIR)/Make.defs
# extensively through these definitions, so must be
# correct.
#
# USEBCC Whether to compile using BCC or GCC. If this is
# set to 'N' it compiles using GCC, otherwise it
# compiles using BCC.
# USEBCC Whether to compile using ia16-elf-gcc or host GCC.
# If this is set to 'N' it compiles using GCC, otherwise
# it compiles using ia16-elf-gcc.
#
# CLEANDEP Any files in the current directory that the
# `make dep` command is dependent on.
Expand Down
2 changes: 1 addition & 1 deletion elks/arch/i86/drivers/char/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ BASEDIR = ../../../..
# Define the variables required by the standard rules - see the standard
# rules file (below) for details of these variables.

USEBCC =
USEBCC = Y

CLEANDEP =

Expand Down
2 changes: 1 addition & 1 deletion elks/arch/i86/kernel/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ BASEDIR = ../../..
# Define the variables required by the standard rules - see the standard
# rules file (below) for details of these variables.

USEBCC =
USEBCC = Y

CLEANDEP =

Expand Down
2 changes: 1 addition & 1 deletion elks/arch/i86/lib/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ BASEDIR = ../../..
# Define the variables required by the standard rules - see the standard
# rules file (below) for details of these variables.

USEBCC =
USEBCC = Y

CLEANDEP =

Expand Down
2 changes: 1 addition & 1 deletion elks/include/linuxmt/minix_fs.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ struct minix_inode_info {
};

/* This is the original minix inode layout on disk.
* Note the 8-bit gid and atime and ctime.
* Note the 8-bit gid and missing atime and ctime.
*/
struct minix_inode {
__u16 i_mode;
Expand Down
2 changes: 1 addition & 1 deletion elks/init/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -448,7 +448,7 @@ static int INITPROC parse_options(void)
fmemcpyb(opts.options, kernel_ds, 0, DEF_OPTSEG, sizeof(opts.options));

#pragma GCC diagnostic ignored "-Wstrict-aliasing"
/* check file starts with ##, one or two sectors, max 1023 bytes */
/* check file starts with ##, one or two sectors, max 1023 bytes or 511 one sector */
if (*(unsigned short *)opts.options != 0x2323 ||
(opts.options[511] && opts.options[OPTSEGSZ-1]))
return 0;
Expand Down
2 changes: 0 additions & 2 deletions elks/nodeps

This file was deleted.

4 changes: 2 additions & 2 deletions elkscmd/sys_utils/meminfo.c
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ void display_seg(int fd, word_t mem)
byte_t ref_count = getword(fd, mem + offsetof(segment_s, ref_count), ds);
struct task_struct *t;

printf(" %4x %s %7ld %4d ",
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) {
Expand Down Expand Up @@ -169,7 +169,7 @@ void dump_heap(int fd)

if (allflag || (fflag && free) || (aflag && app) || (tflag && tty)
|| (bflag && buffer) || (sflag && system)) {
printf(" %4x %s %5d", mem, heaptype[tag], size);
printf(" %04x %s %5d", mem, heaptype[tag], size);
total_size += size + sizeof(heap_s);
if (tag == HEAP_TAG_FREE)
total_free += size;
Expand Down
1 change: 0 additions & 1 deletion libc/string/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ OBJS = \
memmove.o \
memset-c.o \
fmemset-c.o \
movedata.o \
strcasecmp.o \
strcat.o \
strchr.o \
Expand Down
61 changes: 26 additions & 35 deletions libc/string/memchr.c
Original file line number Diff line number Diff line change
@@ -1,48 +1,39 @@
#include <string.h>

void *
memchr(const void * str, int c, size_t l)
{
#ifdef BCC_ASM
#asm
mov bx,sp
push di

#ifdef PARANOID
push es
push ds ; Im not sure if this is needed, so just in case.
pop es
mov bx,sp
push di
push es
push ds
pop es
cld
#endif

mov di,[bx+2]
mov ax,[bx+4]
mov cx,[bx+6]
test cx,cx
je is_z ! Zero length, do not find.

repne ! Scan
mov di,[bx+2]
mov ax,[bx+4]
mov cx,[bx+6]
test cx,cx
je is_z ! Zero length, do not find.
repne ! Scan
scasb
jne is_z ! Not found, ret zero
dec di ! Adjust ptr
mov ax,di ! return
jmp xit
jne is_z ! Not found, ret zero
dec di ! Adjust ptr
mov ax,di ! return
jmp xit
is_z:
xor ax,ax
xor ax,ax
xit:

#ifdef PARANOID
pop es
pop es
pop di
ret
#endif
pop di
#endasm
#else /* ifdef BCC_ASM */
register unsigned char *p=(unsigned char *)str;
while(l-- > 0)
{
if(*p == c) return p;

void *
memchr(const void * str, int c, size_t l)
{
unsigned char *p = (unsigned char *)str;
while (l-- > 0) {
if (*p == c) return p;
p++;
}
return 0;
#endif /* ifdef BCC_ASM */
}
61 changes: 0 additions & 61 deletions libc/string/movedata.c

This file was deleted.

23 changes: 6 additions & 17 deletions libc/string/strchr.c
Original file line number Diff line number Diff line change
@@ -1,25 +1,12 @@
#include <string.h>

char *
strchr (const char * s, int c)
{
#ifdef BCC_AX_ASM
#asm
#ifdef BCC_ASM
mov bx,sp
push si
#if __FIRST_ARG_IN_AX__
mov bx,[bx+2]
mov si,ax
#else
mov si,[bx+2]
mov bx,[bx+4]
#endif
xor ax,ax

#ifdef PARANOID
cld
#endif

in_loop:
lodsb
cmp al,bl
Expand All @@ -31,15 +18,17 @@ strchr (const char * s, int c)
got_it:
lea ax,[si-1]
pop si
ret
#endif

#endasm
#else /* ifdef BCC_AX_ASM */
char *
strchr(const char * s, int c)
{
for(; *s != (char)c; ++s) {
if (*s == '\0')
return NULL;
}
return (char *)s;
#endif /* ifdef BCC_AX_ASM */
}

#ifdef __GNUC__
Expand Down
80 changes: 33 additions & 47 deletions libc/string/strncmp.c
Original file line number Diff line number Diff line change
@@ -1,59 +1,45 @@
#include <string.h>

int
strncmp(const char * d, const char * s, size_t l)
{
#ifdef BCC_AX_ASM
#asm
mov bx,sp
push si
push di

#ifdef PARANOID
push es
push ds ! Im not sure if this is needed, so just in case.
pop es
#ifdef BCC_ASM
mov bx,sp
push si
push di
push es
push ds
pop es
cld
#endif

#if __FIRST_ARG_IN_AX__
mov si,ax
mov di,[bx+2]
mov cx,[bx+4]
#else
mov si,[bx+2] ! Fetch
mov di,[bx+4]
mov cx,[bx+6]
#endif

inc cx
mov si,[bx+2] ! Fetch
mov di,[bx+4]
mov cx,[bx+6]
inc cx
lp1:
dec cx
je lp2
dec cx
je lp2
lodsb
scasb
jne lp3
testb al,al
jne lp1
jne lp3
testb al,al
jne lp1
lp2:
xor ax,ax
jmp lp4
xor ax,ax
jmp lp4
lp3:
sbb ax,ax
or al,#1
sbb ax,ax
or al,#1
lp4:

#ifdef PARANOID
pop es
pop es
pop di
pop si
ret
#endif
pop di
pop si
#endasm
#else
register char c1=0, c2=0;
while(l-- >0)
if( (c1= *d++) != (c2= *s++) || c1 == '\0' )

int
strncmp(const char * d, const char * s, size_t l)
{
char c1 = 0, c2 = 0;
while (l-- > 0) {
if ((c1 = *d++) != (c2 = *s++) || c1 == '\0')
break;
return c1-c2;
#endif
}
return c1 - c2;
}

0 comments on commit 2885524

Please sign in to comment.