Skip to content

Commit

Permalink
tmp commit
Browse files Browse the repository at this point in the history
  • Loading branch information
youkaichao committed Jun 17, 2018
2 parents 503e1c8 + 8e4d8ed commit c00c262
Show file tree
Hide file tree
Showing 39 changed files with 5,399 additions and 243 deletions.
31 changes: 20 additions & 11 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,8 @@ AS = $(TOOLPREFIX)gas
LD = $(TOOLPREFIX)ld
OBJCOPY = $(TOOLPREFIX)objcopy
OBJDUMP = $(TOOLPREFIX)objdump
CFLAGS = -fno-pic -static -fno-builtin -fno-strict-aliasing -O2 -Wall -MD -ggdb -m32 -fno-omit-frame-pointer -std=gnu11
INCLDIR = ./include
CFLAGS = -fno-pic -static -fno-builtin -fno-strict-aliasing -O2 -Wall -MD -ggdb -m32 -fno-omit-frame-pointer -nostdinc -I$(INCLDIR)
#CFLAGS = -fno-pic -static -fno-builtin -fno-strict-aliasing -fvar-tracking -fvar-tracking-assignments -O0 -g -Wall -MD -gdwarf-2 -m32 -Werror -fno-omit-frame-pointer
CFLAGS += $(shell $(CC) -fno-stack-protector -E -x c /dev/null >/dev/null 2>&1 && echo -fno-stack-protector)
ASFLAGS = -m32 -gdwarf-2 -Wa,-divide
Expand Down Expand Up @@ -140,21 +141,26 @@ tags: $(OBJS) entryother.S _init
vectors.S: vectors.pl
perl vectors.pl > vectors.S

ULIB = ulib.o usys.o printf.o umalloc.o
ULIB = ulib.o usys.o printf.o
LIBC = libc/libc.a
START = start.o

_%: %.o $(ULIB)
$(LD) $(LDFLAGS) $(LDUSER) -o $@ $^
$(LIBC):
$(MAKE) -C ./libc all

_%: %.o $(ULIB) $(START) $(LIBC)
$(LD) $(LDFLAGS) -s -N -e _start -Ttext 0 -o $@ $^
$(OBJDUMP) -S $@ > $*.asm
$(OBJDUMP) -t $@ | sed '1,/SYMBOL TABLE/d; s/ .* / /; /^$$/d' > $*.sym

_forktest: forktest.o $(ULIB)
# forktest has less library code linked in - needs to be small
# in order to be able to max out the proc table.
$(LD) $(LDFLAGS) $(LDUSER) -o _forktest forktest.o ulib.o usys.o
$(OBJDUMP) -S _forktest > forktest.asm
#_forktest: forktest.o $(ULIB)
# # forktest has less library code linked in - needs to be small.
# # in order to be able to max out the proc table.
# $(LD) $(LDFLAGS) -N -e main -Ttext 0 -o _forktest forktest.o $(ULIB)
# $(OBJDUMP) -S _forktest > forktest.asm

mkfs: mkfs.c fs.h
gcc -Werror -Wall -o mkfs mkfs.c
gcc -Wall -o mkfs mkfs.c

# Prevent deletion of intermediate files, e.g. cat.o, after first build, so
# that disk image changes after first build are persistent until clean. More
Expand Down Expand Up @@ -203,7 +209,9 @@ UPROGS=\
_delete\
_refresh\
_showdeled\

_jerry\
_timetest\
_stdtests\

fs.img: mkfs README $(UPROGS)
./mkfs fs.img README $(UPROGS)
Expand All @@ -216,6 +224,7 @@ clean:
initcode initcode.out kernel xv6.img fs.img kernelmemfs mkfs \
.gdbinit \
$(UPROGS)
$(MAKE) -C ./libc clean

# make a printout
FILES = $(shell grep -v '^\#' runoff.list)
Expand Down
5 changes: 5 additions & 0 deletions file.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,3 +38,8 @@ struct devsw {
extern struct devsw devsw[];

#define CONSOLE 1

// lseek defines
#define SEEK_SET 0
#define SEEK_CUR 1
#define SEEK_END 2
6 changes: 0 additions & 6 deletions forktest.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,6 @@

#define N 1000

void
printf(int fd, char *s, ...)
{
write(fd, s, strlen(s));
}

void
forktest(void)
{
Expand Down
19 changes: 19 additions & 0 deletions include/ctype.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#ifndef _CTYPE_H_
#define _CTYPE_H_

int iscntrl(int c);
int isprint(int c);
int isspace(int c);
int isblank(int c);
int isgraph(int c);
int ispunct(int c);
int isalnum(int c);
int isalpha(int c);
int isupper(int c);
int islower(int c);
int isdigit(int c);
int isxdigit(int c);
int toupper(int c);
int tolower(int c);

#endif /* !_CTYPE_H_ */
36 changes: 36 additions & 0 deletions include/float.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
#ifndef _MACHINE_FLOAT_H_
#define _MACHINE_FLOAT_H_ 1

#define FLT_RADIX 2 /* b */
#define FLT_ROUNDS 1 /* FP addition rounds to nearest */

#define FLT_MANT_DIG 24 /* p */
#define FLT_EPSILON 1.19209290E-07F /* b**(1-p) */
#define FLT_DIG 6 /* floor((p-1)*log10(b))+(b == 10) */
#define FLT_MIN_EXP (-125) /* emin */
#define FLT_MIN 1.17549435E-38F /* b**(emin-1) */
#define FLT_MIN_10_EXP (-37) /* ceil(log10(b**(emin-1))) */
#define FLT_MAX_EXP 128 /* emax */
#define FLT_MAX 3.40282347E+38F /* (1-b**(-p))*b**emax */
#define FLT_MAX_10_EXP 38 /* floor(log10((1-b**(-p))*b**emax)) */

#define DBL_MANT_DIG 53
#define DBL_EPSILON 2.2204460492503131E-16
#define DBL_DIG 15
#define DBL_MIN_EXP (-1021)
#define DBL_MIN 2.2250738585072014E-308
#define DBL_MIN_10_EXP (-307)
#define DBL_MAX_EXP 1024
#define DBL_MAX 1.7976931348623157E+308
#define DBL_MAX_10_EXP 308

#define LDBL_MANT_DIG DBL_MANT_DIG
#define LDBL_EPSILON DBL_EPSILON
#define LDBL_DIG DBL_DIG
#define LDBL_MIN_EXP DBL_MIN_EXP
#define LDBL_MIN DBL_MIN
#define LDBL_MIN_10_EXP DBL_MIN_10_EXP
#define LDBL_MAX_EXP DBL_MAX_EXP
#define LDBL_MAX DBL_MAX
#define LDBL_MAX_10_EXP DBL_MAX_10_EXP
#endif /* _MACHINE_FLOAT_H_ */
78 changes: 78 additions & 0 deletions include/limits.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
//
// Created by freeman on 17-6-16.
//

#ifndef LIMITS_H
#define LIMITS_H

#define _POSIX_ARG_MAX 4096
#define _POSIX_CHILD_MAX 6
#define _POSIX_LINK_MAX 8
#define _POSIX_MAX_CANON 255
#define _POSIX_MAX_INPUT 255
#define _POSIX_NAME_MAX 14
#define _POSIX_NGROUPS_MAX 0
#define _POSIX_OPEN_MAX 16
#define _POSIX_PATH_MAX 255
#define _POSIX_PIPE_BUF 512

#define _POSIX2_BC_BASE_MAX 99
#define _POSIX2_BC_DIM_MAX 2048
#define _POSIX2_BC_SCALE_MAX 99
#define _POSIX2_BC_STRING_MAX 1000
#define _POSIX2_EQUIV_CLASS_MAX 2
#define _POSIX2_EXPR_NEST_MAX 32
#define _POSIX2_LINE_MAX 2048
#define _POSIX2_RE_DUP_MAX 255

#define CHAR_BIT 8 /* number of bits in a char */
#define MB_LEN_MAX 6 /* allow 21-bit UTF2 */

#define SCHAR_MIN (-0x7f-1) /* max value for a signed char */
#define SCHAR_MAX 0x7f /* min value for a signed char */

#define UCHAR_MAX 0xff /* max value for an unsigned char */
#define CHAR_MAX 0x7f /* max value for a char */
#define CHAR_MIN (-0x7f-1) /* min value for a char */

#define USHRT_MAX 0xffff /* max value for an unsigned short */
#define SHRT_MAX 0x7fff /* max value for a short */
#define SHRT_MIN (-0x7fff-1) /* min value for a short */

#define UINT_MAX 0xffffffff /* max value for an unsigned int */
#define INT_MAX 0x7fffffff /* max value for an int */
#define INT_MIN (-0x7fffffff-1) /* min value for an int */

#define ULONG_MAX 0xffffffff /* max value for an unsigned long */
#define LONG_MAX 0x7fffffff /* max value for a long */
#define LONG_MIN (-0x7fffffff-1) /* min value for a long */

#if !defined(_ANSI_SOURCE) && !defined(_POSIX_SOURCE)
#define CLK_TCK 128 /* ticks per second */
#define UQUAD_MAX 0xffffffffffffffffLL /* max unsigned quad */
#define QUAD_MAX 0x7fffffffffffffffLL /* max signed quad */
#define QUAD_MIN (-0x7fffffffffffffffLL-1) /* min signed quad */

#define ARG_MAX 20480 /* max bytes for an exec function */
#define CHILD_MAX 40 /* max simultaneous processes */
#define LINK_MAX 32767 /* max file link count */
#define MAX_CANON 255 /* max bytes in terminal canonical input line */
#define MAX_INPUT 255 /* max bytes in terminal input */
#define NAME_MAX 255 /* max number of bytes in a file name */
#define NGROUPS_MAX 16 /* max number of supplemental group id's */
#define OPEN_MAX 64 /* max open files per process */
#define PATH_MAX 1024 /* max number of bytes in pathname */
#define PIPE_BUF 512 /* max number of bytes for atomic pipe writes */

#define BC_BASE_MAX 99 /* max ibase/obase values allowed by bc(1) */
#define BC_DIM_MAX 2048 /* max array elements allowed by bc(1) */
#define BC_SCALE_MAX 99 /* max scale value allowed by bc(1) */
#define BC_STRING_MAX 1000 /* max const string length allowed by bc(1) */
#define EQUIV_CLASS_MAX 2 /* max weights for order keyword; see locale */
#define EXPR_NEST_MAX 32 /* max expressions nested in expr(1) */
#define LINE_MAX 2048 /* max length in bytes of an input line */
#define RE_DUP_MAX 255 /* max repeated RE's using interval notation */

#endif

#endif //LIMITS_H
7 changes: 7 additions & 0 deletions include/math.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#ifndef MATH_H
#define MATH_H

int isnan(double d);
int isinf(double d);

#endif
9 changes: 9 additions & 0 deletions include/setjmp.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#ifndef SETJMP_H
#define SETJMP_H

typedef int jmp_buf[10];

int setjmp(jmp_buf);
void longjmp(jmp_buf, int);

#endif
13 changes: 13 additions & 0 deletions include/stdarg.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#ifndef STDARG_H
#define STDARG_H

typedef char *va_list;
#define va_arg(ap, type) ((type *)(ap += sizeof(type)))[-1]
#define va_end(ap)
#define __va_promote(type) (((sizeof(type) + sizeof(int) - 1) / sizeof(int)) * sizeof(int))
#define va_start(ap, last) (ap = ((char *)&(last) + __va_promote(last)))

typedef unsigned char u_char;
typedef unsigned long u_long;

#endif
11 changes: 11 additions & 0 deletions include/stddef.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#ifndef STDDEF_H
#define STDDEF_H

typedef int ptrdiff_t;
typedef unsigned int size_t;

#ifndef NULL
#define NULL 0
#endif

#endif
12 changes: 12 additions & 0 deletions include/stdint.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#ifndef STDINT_H
#define STDINT_H

typedef signed char int8_t;
typedef short int16_t;
typedef int int32_t;

typedef unsigned char uint8_t;
typedef unsigned short uint16_t;
typedef unsigned int uint32_t;

#endif
58 changes: 58 additions & 0 deletions include/stdio.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
#ifndef STDIO_H
#define STDIO_H

#ifndef EOF
#define EOF (-1)
#endif

#define __SRD 0x0004 /* OK to read */
#define __SWR 0x0008 /* OK to write */
/* RD and WR are never simultaneously asserted */
#define __SRW 0x0010 /* open for reading & writing */
#define BUFSIZ 1024

typedef struct {
int fd;
int buffer_size;
int buffer_end;
int cur;
int reserve;
char *buffer;
short flags;
} FILE;

extern FILE _std_files[];
#define stdin (&_std_files[0])
#define stdout (&_std_files[1])
#define stderr (&_std_files[2])
#define __sgetc(p) __srget(p)
int __srget (FILE *);
int __sputc (int _c, FILE *_p);



#define putc(x, fp) __sputc(x, fp)
#define fputc(x, fp) __sputc(x, fp)

#define getchar() getc(stdin)

#define putchar(x) putc(x, stdout)

#define getc(fp) __sgetc(fp)
#define fgetc(fp) __sgetc(fp)

int myprintf(char const *fmt, ...);
int fprintf(FILE *fp, const char *fmt, ...);
int puts(char const *s);
int fputs(const char *s, FILE *fp);
char *mygets(char *buf);
char *fgets(char *buf, int max, FILE *fp);
FILE *fopen(const char *file, const char *mode);
int fclose(FILE *fp);
int ungetc(int ch, FILE *stream);
int scanf(const char *, ...);
int fscanf(FILE *fp, char *fmt, ...);

double strtod(const char *s00, char **se);

#endif
17 changes: 17 additions & 0 deletions include/stdlib.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#ifndef STDLIB_H
#define STDLIB_H

#include <stddef.h>

void* malloc(unsigned int);
void free(void*);
int abs(int);

#define RAND_MAX 0x7fffffff

void srand(unsigned);
int rand();

void qsort(void *, size_t, size_t, int (*)(const void *, const void *));
void abort();
#endif
23 changes: 23 additions & 0 deletions include/string.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#ifndef STRING_H
#define STRING_H

#include <stddef.h>

unsigned int strlen(const char *str);
char * strchr(register const char *p, register const char ch);
char *strrchr(register const char *p, register const char *ch);
char *strcat(register char *s, register const char *append);
char *strncat(char *dst, const char *src, register unsigned int n);
int strcmp(register const char *s1, register const char *s2);
int strncmp(register const char *s1, register const char *s2, register unsigned int n);
char* strcpy(register char *to, register const char *from);
char *strncpy(char *dst, const char *src, register unsigned int n);
char *strstr(register const char *s, register const char *find);
void *memcpy(void *dst0, const void *src0, register unsigned int length);
void *memmove(void *vdst, const void *vsrc, register unsigned int n);
void *memccpy(void *t, const void *f, int c, register unsigned int n);
void *memchr(const void *s, register unsigned char c, register unsigned int n);
int memcmp(const void *s1, const void *s2, unsigned int n);
void* memset(void*, int, unsigned int);

#endif
Loading

0 comments on commit c00c262

Please sign in to comment.