diff --git a/.gdb_history b/.gdb_history deleted file mode 100644 index 99ec2f0..0000000 --- a/.gdb_history +++ /dev/null @@ -1,133 +0,0 @@ -target remote :1234 -break s -break startup -break quit -exit -q() -quit() -exit -exit() -help -q -target remote : 1234 -b init -c -registerinfo -info registers -q -q -continue -c -target remote : 1234 -c -q -target remote : 1234 -b main -s -ls -l -q -q -target remote : 1234 -b init -c -n -n -n -n -n -l -n -n -n -n -n -n -n -n -q -target remote : 1234 -b main.c:135 -c -n -n -n -n -n -s -n -p -q -target remote : 1234 -b main:move_to_user_mode -b main:137 -b main.c:137 -c -l -n -info registers -n -set follow-fork-mode child -n -n -q -target remote : 1234 -b main.c:139 -c -n -set follow-fork-mode child -n -n -q -q -target remote : 1234 -b main.c:142 -set follow-fork-mode child -c -q -target remote : 1234 -b main.c:140 -b main.c:142 -c -n -q -q -target remote : 1234 -b main.c:141 -c -p pid -n -p pid -attach 1 -q -target remote : 1234 -b main.c:141 -b main.c:143 -set follow-fork-mode main.c:143 -set follow-fork-mode child main.c:143 -c -n -q -target remote : 1234 -quit -target remote : 1234 -b main.c:122 -c -q -target remote : 1234 -b main.c:90 -c -n -set follow-fork-mode child -n -q -target remote : 1234 -b main.c:90 -c -n -set follow-fork-mode child -n -q -target remote : 1234 -b main.c:175 -c diff --git a/Makefile b/Makefile index 928f090..8052250 100644 --- a/Makefile +++ b/Makefile @@ -1,4 +1,3 @@ -OS = Mac # indicate the Hardware Image file HDA_IMG = hdc-0.11.img @@ -8,7 +7,7 @@ CALLTREE=$(shell find tools/ -name "calltree" -perm 755 -type f) # indicate the path of the bochs #BOCHS=$(shell find tools/ -name "bochs" -perm 755 -type f) -BOCHS=bochs +BOCHS=$(shell find tools/bochs-2.6.9 -name "bochs" -perm 755 -type f) # # if you want the ram-disk device, define this to be the @@ -42,15 +41,16 @@ LIBS =lib/lib.a .c.o: @$(CC) $(CFLAGS) -c -o $*.o $< -all: Image +all: host_check Image + +host_check: +ifeq ($(HOST),$(info host: $(UNAME))) + $(error "Support only on Linux, Darwin, Cygwin, Mingw!") +endif Image: boot/bootsect boot/setup tools/system - @cp -f tools/system system.tmp - @$(STRIP) system.tmp - @$(OBJCOPY) -O binary -R .note -R .comment system.tmp tools/kernel + @$(OBJCOPY) -O binary -S -g -R .note -R .comment tools/system tools/kernel @tools/build.sh boot/bootsect boot/setup tools/kernel Image $(ROOT_DEV) - @rm system.tmp - @rm -f tools/kernel @sync disk: Image @@ -66,8 +66,9 @@ tools/system: boot/head.o init/main.o \ $(DRIVERS) \ $(MATH) \ $(LIBS) \ - -o tools/system - @nm tools/system | grep -v '\(compiled\)\|\(\.o$$\)\|\( [aU] \)\|\(\.\.ng$$\)\|\(LASH[RL]DI\)'| sort > System.map + -o tools/system + @nm tools/system | grep -v '\(compiled\)\|\(\.o$$\)\|\( [aUN] \)\|\(\.\.ng$$\)\|\(LASH[RL]DI\)'| sort > System.map + @objdump -S tools/system > System.s kernel/math/math.a: @make -C kernel/math @@ -102,8 +103,8 @@ tmp.s: boot/bootsect.s tools/system @cat boot/bootsect.s >> tmp.s clean: - @rm -f Image System.map tmp_make core boot/bootsect boot/setup - @rm -f init/*.o tools/system boot/*.o typescript* info bochsout.txt + @rm -f Image System.s System.map tmp_make core boot/bootsect boot/setup + @rm -f init/*.o tools/system tools/kernel boot/*.o typescript* info bochsout.txt @for i in mm fs kernel lib boot; do make clean -C $$i; done info: @make clean @@ -138,21 +139,20 @@ start: @qemu-system-x86_64 -m 16M -boot a -fda Image -hda $(HDA_IMG) debug: - @echo $(OS) @qemu-system-x86_64 -m 16M -boot a -fda Image -hda $(HDA_IMG) -s -S bochs-debug: - @$(BOCHS) -q -f tools/bochs/bochsrc/bochsrc-hd-dbg.bxrc + @$(BOCHS) -q -f tools/bochs-2.6.9/bochsrc-hd-gdb.bxrc bochs: ifeq ($(BOCHS),) - @(cd tools/bochs/bochs-2.3.7; \ + @(cd tools/bochs-2.6.9/bochs-2.6.9; \ ./configure --enable-plugins --enable-disasm --enable-gdb-stub;\ make) endif bochs-clean: - @make clean -C tools/bochs/bochs-2.3.7 + @make clean -C tools/bochs-2.6.9/bochs-2.6.9 calltree: ifeq ($(CALLTREE),) @@ -198,6 +198,9 @@ help: @echo " used in ubuntu|debian 32bit|64bit with gcc 4.3.2, and give some new " @echo " features for experimenting. such as this help info, boot/bootsect.s and" @echo " boot/setup.s with AT&T rewritting, porting to gcc 4.3.2 :-)" + @echo " * 2017, hat release a new version turn on -O and" + @echo " support gcc 4/5/6/7 and Cygwin/Mingw(make sure ld version ISN'T 2.25.x!!" + @echo " See at stackoverflow.com/questions/48088518/ld-ttext-0-m-i386pe-relocation-wrong-on-cygwin" @echo "" @echo "<<>>" diff --git a/Makefile.header b/Makefile.header index bac4212..465e956 100755 --- a/Makefile.header +++ b/Makefile.header @@ -1,37 +1,52 @@ UNAME := $(shell uname) +HOST := $(word 1, $(filter Linux Darwin CYGWIN MINGW, \ + $(patsubst MINGW%,MINGW,$(UNAME)) $(patsubst CYGWIN%,CYGWIN,$(UNAME)))) -ifeq ($(UNAME), Linux) +ifeq ($(HOST), Linux) AS = as --32 LD = ld #LDFLAGS = -m elf_i386 -x LDFLAGS = -m elf_i386 CC = gcc - CFLAGS = -g -m32 -fno-builtin -fno-stack-protector -fomit-frame-pointer -fstrength-reduce #-Wall - + CFLAGS = -m32 -g -O -finline-functions -nostdinc -fno-builtin -fno-stack-protector -fomit-frame-pointer -fstrength-reduce #-Wall CPP = cpp -nostdinc AR = ar STRIP = strip OBJCOPY = objcopy # we should use -fno-stack-protector with gcc 4.3 gcc_version=$(shell ls -l `which gcc` | tr '-' '\n' | tail -1) -endif - - -ifeq ($(UNAME), Darwin) +else +ifeq ($(HOST), Darwin) AS = i386-elf-as --32 LD = i386-elf-ld #LDFLAGS = -m elf_i386 -x LDFLAGS = -m elf_i386 #CC = i386-elf-gcc-4.3.2 CC = i386-elf-gcc - CFLAGS = -gdwarf-2 -g3 -m32 -fno-builtin -fno-stack-protector -fomit-frame-pointer -fstrength-reduce #-Wall + CFLAGS = -gdwarf-2 -g3 -m32 -finline-functions -nostdinc -fno-builtin -fno-stack-protector -fomit-frame-pointer -fstrength-reduce #-Wall #CPP = i386-elf-cpp-4.3.2 -nostdinc CPP = i386-elf-cpp -nostdinc AR =i386-elf-ar STRIP = i386-elf-strip OBJCOPY = i386-elf-objcopy -endif +else +ifneq ($(filter CYGWIN MINGW, $(HOST)),) + AS = as --32 + LD = ld + #LDFLAGS = -m i386pe -x + LDFLAGS = -m i386pe + CC = gcc + CFLAGS = -m32 -g -O -finline-functions -nostdinc -fno-leading-underscore -fno-builtin -fno-stack-protector -fomit-frame-pointer -fstrength-reduce #-Wall + CPP = cpp -nostdinc + AR = ar + STRIP = strip + OBJCOPY = objcopy + # we should use -fno-stack-protector with gcc 4.3 + gcc_version=$(shell ls -l `which gcc` | tr '-' '\n' | tail -1) +endif +endif +endif diff --git a/README.md b/README.md index 394d7e5..f5fb719 100644 --- a/README.md +++ b/README.md @@ -8,9 +8,9 @@ The old Linux kernel source ver 0.11 which has been tested under modern Linux, ### 1.1. Linux Setup * a linux distribution: debian , ubuntu and mint are recommended -* some tools: gcc gdb qemu +* some tools: gcc gdb qemu (or bochs) * a linux-0.11 hardware image file: hdc-0.11.img, please download it from http://www.oldlinux.org, or http://mirror.lzu.edu.cn/os/oldlinux.org/, ant put it in the root directory. -* Now, This version already support the Ubuntu 16.04, enjoy it. +* Now, This version already support gcc 4/5/6/7 series and turn on -O, enjoy it. ### 1.2. hack linux-0.11 ```bash @@ -54,4 +54,6 @@ same as section 1.2 ## 3. Build on Windows -todo... +* Support gcc 4/5/6/7 series and turn on -O on Cygwin and Mingw. BUT make sure ld version is NOT 2.25.x !! See problem description at + https://stackoverflow.com/questions/48088518/ld-ttext-0-m-i386pe-relocation-wrong-on-cygwin + diff --git a/boot/bootsect.s b/boot/bootsect.s index 1fc5ae8..6178707 100644 --- a/boot/bootsect.s +++ b/boot/bootsect.s @@ -1,5 +1,6 @@ .code16 # rewrite with AT&T syntax by falcon at 081012 +# Modified by hat at 2017 # # SYS_SIZE is the number of clicks (16 bytes) to be loaded. # 0x3000 is 0x30000 bytes = 196kB, more than enough for current @@ -44,13 +45,12 @@ # 0x301 - first partition on first drive etc # ##和源码不同,源码中是0x306 第2块硬盘的第一个分区 -# - .equ ROOT_DEV, 0x301 - ljmp $BOOTSEG, $_start +.equ ROOT_DEV, 0x301 + _start: mov $BOOTSEG, %ax #将ds段寄存器设置为0x7C0 mov %ax, %ds - mov $INITSEG, %ax #将es段寄存器设置为0x900 + mov $INITSEG, %ax #将es段寄存器设置为0x9000 mov %ax, %es mov $256, %cx #设置移动计数值256字 sub %si, %si #源地址 ds:si = 0x07C0:0x0000 diff --git a/boot/head.s b/boot/head.s index 915d66a..2b874b5 100644 --- a/boot/head.s +++ b/boot/head.s @@ -62,7 +62,7 @@ check_x87: xorl $6,%eax /* reset MP, set EM */ movl %eax,%cr0 ret -.align 2 +.align 4 1: .byte 0xDB,0xE4 /* fsetpm for 287, ignored by 387 */ ret @@ -148,7 +148,7 @@ L6: /* This is the default interrupt "handler" :-) */ int_msg: .asciz "Unknown interrupt\n\r" -.align 2 +.align 4 ignore_int: pushl %eax pushl %ecx @@ -196,7 +196,7 @@ ignore_int: * some kind of marker at them (search for "16Mb"), but I * won't guarantee that's all :-( ) */ -.align 2 +.align 4 setup_paging: movl $1024*5,%ecx /* 5 pages - pg_dir+4 page tables */ xorl %eax,%eax @@ -220,12 +220,12 @@ setup_paging: movl %eax,%cr0 /* set paging (PG) bit */ ret /* this also flushes prefetch-queue */ -.align 2 +.align 4 .word 0 idt_descr: .word 256*8-1 # idt contains 256 entries .long idt -.align 2 +.align 4 .word 0 gdt_descr: .word 256*8-1 # so does gdt (not that that's any diff --git a/boot/setup.s b/boot/setup.s index 807cd47..0ba6a9d 100644 --- a/boot/setup.s +++ b/boot/setup.s @@ -1,5 +1,12 @@ .code16 # rewrite with AT&T syntax by falcon at 081012 +# Modified by hat at 2017 +# +# SYS_SIZE is the number of clicks (16 bytes) to be loaded. +# 0x3000 is 0x30000 bytes = 196kB, more than enough for current +# versions of linux +# + .equ SYSSIZE, 0x3000 # # setup.s (C) 1991 Linus Torvalds # @@ -29,12 +36,9 @@ begbss: .text - ljmp $SETUPSEG, $_start _start: mov %cs,%ax - mov %ax,%ds mov %ax,%es -# ##print some message # mov $0x03, %ah @@ -46,14 +50,10 @@ _start: mov $msg2,%bp mov $0x1301, %ax int $0x10 -# ok, the read went well so we get current cursor position and save it for -# posterity. - mov $INITSEG, %ax # this is done in bootsect already, but... - mov %ax, %ds - mov $0x03, %ah # read cursor pos - xor %bh, %bh - int $0x10 # save it in known place, con_init fetches - mov %dx, %ds:0 # it from 0x90000. + + +# mov $INITSEG, %ax # this is done in bootsect already, but... +# mov %ax, %ds # Get memory size (extended mem, kB) mov $0x88, %ah @@ -100,26 +100,12 @@ _start: rep movsb -## modify ds +## modify ds,es mov $INITSEG,%ax mov %ax,%ds mov $SETUPSEG,%ax mov %ax,%es -##show cursor pos: - mov $0x03, %ah - xor %bh,%bh - int $0x10 - mov $11,%cx - mov $0x000c,%bx - mov $cur,%bp - mov $0x1301,%ax - int $0x10 -##show detail - mov %ds:0 ,%ax - call print_hex - call print_nl - ##show memory size mov $0x03, %ah xor %bh, %bh @@ -175,9 +161,17 @@ _start: mov %ds:0x8e, %ax call print_hex call print_nl -#l: -# jmp l -## + +# ok, the read went well so we get current cursor position and save it for +# posterity. +# mov $INITSEG, %ax # this is done in bootsect already, but... +# mov %ax, %ds + mov $0x03, %ah # read cursor pos + xor %bh, %bh + int $0x10 # save it in known place, con_init fetches + mov %dx, %ds:0 # it from 0x90000. + + # Check that there IS a hd1 :-) mov $0x01500, %ax @@ -207,7 +201,7 @@ is_disk1: do_move: mov %ax, %es # destination segment add $0x1000, %ax - cmp $0x9000, %ax + cmp $0x1000+SYSSIZE, %ax jz end_move mov %ax, %ds # source segment sub %di, %di @@ -324,10 +318,10 @@ gdt_48: .word 0x800 # gdt limit=2048, 256 GDT entries .word 512+gdt, 0x9 # gdt base = 0X9xxxx, # 512+gdt is the real gdt after setup is moved to 0x9020 * 0x10 + print_hex: mov $4,%cx mov %ax,%dx - print_digit: rol $4,%dx #循环以使低4位用上,高4位移至低4位 mov $0xe0f,%ax #ah = 请求的功能值,al = 半个字节的掩码 @@ -336,7 +330,6 @@ print_digit: cmp $0x3a,%al jl outp add $0x07,%al - outp: int $0x10 loop print_digit diff --git a/fs/bitmap.c b/fs/bitmap.c index fb0741d..9fad3d2 100644 --- a/fs/bitmap.c +++ b/fs/bitmap.c @@ -11,9 +11,11 @@ #include #define clear_block(addr) \ -__asm__ __volatile__ ("cld\n\t" \ +__asm__ __volatile__ ("push %%edi\n\t" \ + "cld\n\t" \ "rep\n\t" \ - "stosl" \ + "stosl\n\t" \ + "pop %%edi" \ ::"a" (0),"c" (BLOCK_SIZE/4),"D" ((long) (addr))) #define set_bit(nr,addr) ({\ @@ -30,7 +32,8 @@ res;}) #define find_first_zero(addr) ({ \ int __res; \ -__asm__ __volatile__ ("cld\n" \ +__asm__ __volatile__ ("push %%esi\n\t" \ + "cld\n\t" \ "1:\tlodsl\n\t" \ "notl %%eax\n\t" \ "bsfl %%eax,%%edx\n\t" \ @@ -40,8 +43,9 @@ __asm__ __volatile__ ("cld\n" \ "2:\taddl $32,%%ecx\n\t" \ "cmpl $8192,%%ecx\n\t" \ "jl 1b\n" \ - "3:" \ - :"=c" (__res):"c" (0),"S" (addr)); \ + "3:\t" \ + "pop %%esi" \ + :"=c" (__res):"c" (0),"S" (addr):"ax","dx"); \ __res;}) void free_block(int dev, int block) diff --git a/fs/buffer.c b/fs/buffer.c index 89918e8..47eef60 100644 --- a/fs/buffer.c +++ b/fs/buffer.c @@ -284,9 +284,13 @@ struct buffer_head * bread(int dev,int block) } #define COPYBLK(from,to) \ -__asm__("cld\n\t" \ +__asm__("push %%esi\n\t" \ + "push %%edi\n\t" \ + "cld\n\t" \ "rep\n\t" \ "movsl\n\t" \ + "pop %%edi\n\t" \ + "pop %%esi" \ ::"c" (BLOCK_SIZE/4),"S" (from),"D" (to) \ ) @@ -296,7 +300,7 @@ __asm__("cld\n\t" \ * all at the same time, not waiting for one to be read, and then another * etc. */ -void bread_page(unsigned long address,int dev,int b[4]) +void bread_page(volatile unsigned long address,int dev,int b[4]) { struct buffer_head * bh[4]; int i; diff --git a/fs/namei.c b/fs/namei.c index 97d0de4..33899d2 100644 --- a/fs/namei.c +++ b/fs/namei.c @@ -68,9 +68,13 @@ static int match(int len,const char * name,struct dir_entry * de) return 0; if (len < NAME_LEN && de->name[len]) return 0; - __asm__("cld\n\t" + __asm__("push %%esi\n\t" + "push %%edi\n\t" + "cld\n\t" "fs ; repe ; cmpsb\n\t" - "setz %%al" + "setz %%al\n\t" + "pop %%edi\n\t" + "pop %%esi\n\t" :"=a" (same) :"0" (0),"S" ((long) name),"D" ((long) de->name),"c" (len) ); diff --git a/hdc-0.11.img b/hdc-0.11.img deleted file mode 100644 index b991066..0000000 Binary files a/hdc-0.11.img and /dev/null differ diff --git a/hdc-0.11.img.gz b/hdc-0.11.img.gz new file mode 100644 index 0000000..af7df9b Binary files /dev/null and b/hdc-0.11.img.gz differ diff --git a/include/asm/memory.h b/include/asm/memory.h index 8aa6d52..8a81376 100644 --- a/include/asm/memory.h +++ b/include/asm/memory.h @@ -5,10 +5,10 @@ * user data space). This is NOT a bug, as any user program that changes * es deserves to die if it isn't careful. */ -//#define memcpy(dest,src,n) ({ \ -//void * _res = dest; \ -//__asm__ __volatile__ ("cld;rep;movsb" \ -// ::"D" ((long)(_res)),"S" ((long)(src)),"c" ((long) (n)) \ -// ); \ -//_res; \ -//}) +#define memcpy(dest,src,n) ({ \ +void * _res = dest; \ +__asm__ __volatile__ ("push %%esi; push %%edi;" "cld;rep;movsb" ";pop %%edi; pop %%esi" \ + ::"D" ((long)(_res)),"S" ((long)(src)),"c" ((long) (n)) \ + ); \ +_res; \ +}) diff --git a/include/asm/segment.h b/include/asm/segment.h index 94dd102..ab0c0cd 100644 --- a/include/asm/segment.h +++ b/include/asm/segment.h @@ -2,7 +2,7 @@ static inline unsigned char get_fs_byte(const char * addr) { unsigned register char _v; - __asm__ ("movb %%fs:%1,%0":"=r" (_v):"m" (*addr)); + __asm__ ("movb %%fs:%1,%0":"=q" (_v):"m" (*addr)); return _v; } @@ -10,7 +10,7 @@ static inline unsigned short get_fs_word(const unsigned short *addr) { unsigned short _v; - __asm__ ("movw %%fs:%1,%0":"=r" (_v):"m" (*addr)); + __asm__ ("movw %%fs:%1,%0":"=q" (_v):"m" (*addr)); return _v; } @@ -18,23 +18,23 @@ static inline unsigned long get_fs_long(const unsigned long *addr) { unsigned long _v; - __asm__ ("movl %%fs:%1,%0":"=r" (_v):"m" (*addr)); \ + __asm__ ("movl %%fs:%1,%0":"=q" (_v):"m" (*addr)); \ return _v; } static inline void put_fs_byte(char val,char *addr) { -__asm__ ("movb %0,%%fs:%1"::"r" (val),"m" (*addr)); +__asm__ ("movb %0,%%fs:%1"::"q" (val),"m" (*addr)); } static inline void put_fs_word(short val,short * addr) { -__asm__ ("movw %0,%%fs:%1"::"r" (val),"m" (*addr)); +__asm__ ("movw %0,%%fs:%1"::"q" (val),"m" (*addr)); } static inline void put_fs_long(unsigned long val,unsigned long * addr) { -__asm__ ("movl %0,%%fs:%1"::"r" (val),"m" (*addr)); +__asm__ ("movl %0,%%fs:%1"::"q" (val),"m" (*addr)); } /* diff --git a/include/linux/sched.h b/include/linux/sched.h index e1b35be..68b259f 100644 --- a/include/linux/sched.h +++ b/include/linux/sched.h @@ -188,58 +188,41 @@ __asm__("cmpl %%ecx,current\n\t" \ #define PAGE_ALIGN(n) (((n)+0xfff)&0xfffff000) #define _set_base(addr,base) \ -__asm__ ("push %%edx\n\t" \ - "movw %%dx,%0\n\t" \ - "rorl $16,%%edx\n\t" \ - "movb %%dl,%1\n\t" \ - "movb %%dh,%2\n\t" \ - "pop %%edx" \ +__asm__ ("movw %w3,%0\n\t" \ + "rorl $16,%3\n\t" \ + "movb %b3,%1\n\t" \ + "movb %h3,%2\n\t" \ + "rorl $16,%3\n\t" \ ::"m" (*((addr)+2)), \ "m" (*((addr)+4)), \ "m" (*((addr)+7)), \ - "d" (base) \ + "q" (base) \ ) #define _set_limit(addr,limit) \ -__asm__ ("push %%edx\n\t" \ - "movw %%dx,%0\n\t" \ - "rorl $16,%%edx\n\t" \ - "movb %1,%%dh\n\t" \ - "andb $0xf0,%%dh\n\t" \ - "orb %%dh,%%dl\n\t" \ - "movb %%dl,%1\n\t" \ - "pop %%edx" \ +__asm__ ("movw %w2,%0\n\t" \ + "rorl $16,%2\n\t" \ + "movb %1,%h2\n\t" \ + "andb $0xf0,%h2\n\t" \ + "orb %h2,%b2\n\t" \ + "movb %b2,%1\n\t" \ + "rorl $16,%2\n\t" \ ::"m" (*(addr)), \ "m" (*((addr)+6)), \ - "d" (limit) \ + "q" (limit) \ ) #define set_base(ldt,base) _set_base( ((char *)&(ldt)) , (base) ) #define set_limit(ldt,limit) _set_limit( ((char *)&(ldt)) , (limit-1)>>12 ) -/** -#define _get_base(addr) ({\ -unsigned long __base; \ -__asm__("movb %3,%%dh\n\t" \ - "movb %2,%%dl\n\t" \ - "shll $16,%%edx\n\t" \ - "movw %1,%%dx" \ - :"=d" (__base) \ - :"m" (*((addr)+2)), \ - "m" (*((addr)+4)), \ - "m" (*((addr)+7)) \ - :"memory"); \ -__base;}) -**/ - static inline unsigned long _get_base(char * addr) { unsigned long __base; - __asm__("movb %3,%%dh\n\t" - "movb %2,%%dl\n\t" - "shll $16,%%edx\n\t" - "movw %1,%%dx" - :"=&d" (__base) + __asm__("movb %3,%h0\n\t" + "movb %2,%b0\n\t" + "shll $16,%0\n\t" + "movw %1,%w0" + :"=&q" (__base) :"m" (*((addr)+2)), "m" (*((addr)+4)), "m" (*((addr)+7))); diff --git a/include/string.h b/include/string.h index be98568..7d4b3e4 100644 --- a/include/string.h +++ b/include/string.h @@ -24,24 +24,24 @@ extern char * strerror(int errno); * (C) 1991 Linus Torvalds */ -extern inline char * strcpy(char * dest,const char *src); -extern inline char * strcat(char * dest,const char * src); -extern inline int strcmp(const char * cs,const char * ct); -extern inline int strspn(const char * cs, const char * ct); -extern inline int strcspn(const char * cs, const char * ct); -extern inline char * strpbrk(const char * cs,const char * ct); -extern inline char * strstr(const char * cs,const char * ct); -extern inline int strlen(const char * s); -extern char * ___strtok; +char * strcpy(char * dest,const char *src); +char * strncpy(char * dest,const char *src,int count); +char * strcat(char * dest,const char * src); +char * strncat(char * dest,const char * src,int count); +int strcmp(const char * cs,const char * ct); +int strncmp(const char * cs,const char * ct,int count); +char * strchr(const char * s,char c); +char * strrchr(const char * s,char c); +int strspn(const char * cs, const char * ct); +int strcspn(const char * cs, const char * ct); +char * strpbrk(const char * cs,const char * ct); +char * strstr(const char * cs,const char * ct); +int strlen(const char * s); +char * strtok(char * s,const char * ct); +void * memcpy(void * dest,const void * src, int n); +void * memmove(void * dest,const void * src, int n); +int memcmp(const void * cs,const void * ct,int count); +void * memchr(const void * cs,char c,int count); +void * memset(void * s,char c,int count); -extern inline char * strtok(char * s,const char * ct); - -/* - * Changes by falcon, the original return value is static - * inline ... it can not be called by other functions in another files. - */ - -extern inline void * memcpy(void * dest,const void * src, int n); -extern inline void * memmove(void * dest,const void * src, int n); -extern inline void * memchr(const void * cs,char c,int count); #endif diff --git a/include/unistd.h b/include/unistd.h index 2131ec4..b5d324d 100644 --- a/include/unistd.h +++ b/include/unistd.h @@ -206,11 +206,10 @@ int execvp(const char * file, char ** argv); int execl(const char * pathname, char * arg0, ...); int execlp(const char * file, char * arg0, ...); int execle(const char * pathname, char * arg0, ...); -//volatile void exit(int status); -void _exit(int status); -//volatile void _exit(int status); +void exit(int status) __attribute__((noreturn)); +void _exit(int status) __attribute__((noreturn)); int fcntl(int fildes, int cmd, ...); -static int fork(void); +int fork(void); int getpid(void); int getuid(void); int geteuid(void); @@ -224,7 +223,7 @@ int mknod(const char * filename, mode_t mode, dev_t dev); int mount(const char * specialfile, const char * dir, int rwflag); int nice(int val); int open(const char * filename, int flag, ...); -static int pause(void); +int pause(void); int pipe(int * fildes); int read(int fildes, char * buf, off_t count); int setpgrp(void); @@ -235,7 +234,7 @@ void (*signal(int sig, void (*fn)(int)))(int); int stat(const char * filename, struct stat * stat_buf); int fstat(int fildes, struct stat * stat_buf); int stime(time_t * tptr); -static int sync(void); +int sync(void); time_t time(time_t * tloc); time_t times(struct tms * tbuf); int ulimit(int cmd, long limit); diff --git a/init/main.c b/init/main.c index 26cb3ba..5daaab0 100644 --- a/init/main.c +++ b/init/main.c @@ -20,12 +20,12 @@ * won't be any messing with the stack from main(), but we define * some others too. */ -static inline fork(void) __attribute__((always_inline)); -static inline pause(void) __attribute__((always_inline)); -static inline _syscall0(int,fork) -static inline _syscall0(int,pause) -static inline _syscall1(int,setup,void *,BIOS) -static inline _syscall0(int,sync) +inline _syscall0(int,fork) __attribute__((always_inline)) +inline _syscall0(int,pause) __attribute__((always_inline)) +inline _syscall1(int,setup,void *,BIOS) +inline _syscall0(int,sync) + +void __main(void) {}; //This's for Cygwin/Mingw. #include #include @@ -179,6 +179,7 @@ void init(void) printf("%d buffers = %d bytes buffer space\n\r",NR_BUFFERS, NR_BUFFERS*BLOCK_SIZE); printf("Free mem: %d bytes\n\r",memory_end-main_memory_start); + if (!(pid=fork())) { close(0); if (open("/etc/rc",O_RDONLY,0)) diff --git a/kernel/blk_drv/floppy.c b/kernel/blk_drv/floppy.c index f497906..b44e43b 100644 --- a/kernel/blk_drv/floppy.c +++ b/kernel/blk_drv/floppy.c @@ -153,7 +153,7 @@ int floppy_change(unsigned int nr) } #define copy_buffer(from,to) \ -__asm__("cld ; rep ; movsl" \ +__asm__("push %%esi; push %%edi;" "cld ; rep ; movsl" ";pop %%edi; pop %%esi" \ ::"c" (BLOCK_SIZE/4),"S" ((long)(from)),"D" ((long)(to)) \ ) diff --git a/kernel/blk_drv/hd.c b/kernel/blk_drv/hd.c index d5e1aa9..c58928a 100644 --- a/kernel/blk_drv/hd.c +++ b/kernel/blk_drv/hd.c @@ -59,10 +59,10 @@ static struct hd_struct { } hd[5*MAX_HD]={{0,0},}; #define port_read(port,buf,nr) \ -__asm__("cld;rep;insw"::"d" (port),"D" (buf),"c" (nr)) +__asm__("push %%edi;" "cld;rep;insw" ";pop %%edi"::"d" (port),"D" (buf),"c" (nr)) #define port_write(port,buf,nr) \ -__asm__("cld;rep;outsw"::"d" (port),"S" (buf),"c" (nr)) +__asm__("push %%esi;" "cld;rep;outsw" ";pop %%esi"::"d" (port),"S" (buf),"c" (nr)) extern void hd_interrupt(void); extern void rd_load(void); diff --git a/kernel/chr_drv/console.c b/kernel/chr_drv/console.c index 2529569..611a15e 100644 --- a/kernel/chr_drv/console.c +++ b/kernel/chr_drv/console.c @@ -113,12 +113,16 @@ static void scrup(void) pos += video_size_row; scr_end += video_size_row; if (scr_end > video_mem_end) { - __asm__("cld\n\t" + __asm__("push %%esi\n\t" + "push %%edi\n\t" + "cld\n\t" "rep\n\t" "movsl\n\t" "movl video_num_columns,%1\n\t" "rep\n\t" - "stosw" + "stosw\n\t" + "pop %%edi\n\t" + "pop %%esi" ::"a" (video_erase_char), "c" ((video_num_lines-1)*video_num_columns>>1), "D" (video_mem_start), @@ -128,9 +132,11 @@ static void scrup(void) pos -= origin-video_mem_start; origin = video_mem_start; } else { - __asm__("cld\n\t" + __asm__("push %%edi\n\t" + "cld\n\t" "rep\n\t" - "stosw" + "stosw\n\t" + "pop %%edi" ::"a" (video_erase_char), "c" (video_num_columns), "D" (scr_end-video_size_row) @@ -138,12 +144,16 @@ static void scrup(void) } set_origin(); } else { - __asm__("cld\n\t" + __asm__("push %%esi\n\t" + "push %%edi\n\t" + "cld\n\t" "rep\n\t" "movsl\n\t" "movl video_num_columns,%%ecx\n\t" "rep\n\t" - "stosw" + "stosw\n\t" + "pop %%edi\n\t" + "pop %%esi" ::"a" (video_erase_char), "c" ((bottom-top-1)*video_num_columns>>1), "D" (origin+video_size_row*top), @@ -153,12 +163,16 @@ static void scrup(void) } else /* Not EGA/VGA */ { - __asm__("cld\n\t" + __asm__("push %%esi\n\t" + "push %%edi\n\t" + "cld\n\t" "rep\n\t" "movsl\n\t" "movl video_num_columns,%%ecx\n\t" "rep\n\t" - "stosw" + "stosw\n\t" + "pop %%edi\n\t" + "pop %%esi" ::"a" (video_erase_char), "c" ((bottom-top-1)*video_num_columns>>1), "D" (origin+video_size_row*top), @@ -171,13 +185,17 @@ static void scrdown(void) { if (video_type == VIDEO_TYPE_EGAC || video_type == VIDEO_TYPE_EGAM) { - __asm__("std\n\t" + __asm__("push %%esi\n\t" + "push %%edi\n\t" + "std\n\t" "rep\n\t" "movsl\n\t" "addl $2,%%edi\n\t" /* %edi has been decremented by 4 */ "movl video_num_columns,%%ecx\n\t" "rep\n\t" - "stosw" + "stosw\n\t" + "pop %%edi\n\t" + "pop %%esi" ::"a" (video_erase_char), "c" ((bottom-top-1)*video_num_columns>>1), "D" (origin+video_size_row*bottom-4), @@ -186,13 +204,17 @@ static void scrdown(void) } else /* Not EGA/VGA */ { - __asm__("std\n\t" + __asm__("push %%esi\n\t" + "push %%edi\n\t" + "std\n\t" "rep\n\t" "movsl\n\t" "addl $2,%%edi\n\t" /* %edi has been decremented by 4 */ "movl video_num_columns,%%ecx\n\t" "rep\n\t" - "stosw" + "stosw\n\t" + "pop %%edi\n\t" + "pop %%esi" ::"a" (video_erase_char), "c" ((bottom-top-1)*video_num_columns>>1), "D" (origin+video_size_row*bottom-4), @@ -257,9 +279,11 @@ static void csi_J(int par) default: return; } - __asm__("cld\n\t" + __asm__("push %%edi\n\t" + "cld\n\t" "rep\n\t" "stosw\n\t" + "pop %%edi" ::"c" (count), "D" (start),"a" (video_erase_char) ); @@ -288,9 +312,11 @@ static void csi_K(int par) default: return; } - __asm__("cld\n\t" + __asm__("push %%edi\n\t" + "cld\n\t" "rep\n\t" "stosw\n\t" + "pop %%edi" ::"c" (count), "D" (start),"a" (video_erase_char) ); @@ -458,9 +484,9 @@ void con_write(struct tty_struct * tty) pos -= video_size_row; lf(); } - __asm__("movb attr,%%ah\n\t" + __asm__("movb %2,%%ah\n\t" "movw %%ax,%1\n\t" - ::"a" (c),"m" (*(short *)pos) + ::"a" (c),"m" (*(short *)pos),"m" (attr) ); pos += 2; x++; diff --git a/lib/_exit.c b/lib/_exit.c index 09e31f6..7dce285 100644 --- a/lib/_exit.c +++ b/lib/_exit.c @@ -10,4 +10,5 @@ void _exit(int exit_code) { __asm__ __volatile__ ("int $0x80"::"a" (__NR_exit),"b" (exit_code)); + while(1); } diff --git a/lib/string.c b/lib/string.c index cca9e60..9c520f0 100644 --- a/lib/string.c +++ b/lib/string.c @@ -10,383 +10,377 @@ #define extern #define inline -#define static #define __LIBRARY__ #include -inline char * strcpy(char * dest,const char *src) +char * strcpy(char * dest,const char *src) { - __asm__("cld\n" - "1:\tlodsb\n\t" - "stosb\n\t" - "testb %%al,%%al\n\t" - "jne 1b" - ::"S" (src),"D" (dest)); - return dest; +__asm__("cld\n" + "1:\tlodsb\n\t" + "stosb\n\t" + "testb %%al,%%al\n\t" + "jne 1b" + ::"S" (src),"D" (dest):"ax"); +return dest; } -static inline char * strncpy(char * dest,const char *src,int count) +char * strncpy(char * dest,const char *src,int count) { - __asm__("cld\n" - "1:\tdecl %2\n\t" - "js 2f\n\t" - "lodsb\n\t" - "stosb\n\t" - "testb %%al,%%al\n\t" - "jne 1b\n\t" - "rep\n\t" - "stosb\n" - "2:" - ::"S" (src),"D" (dest),"c" (count)); - return dest; +__asm__("cld\n" + "1:\tdecl %2\n\t" + "js 2f\n\t" + "lodsb\n\t" + "stosb\n\t" + "testb %%al,%%al\n\t" + "jne 1b\n\t" + "rep\n\t" + "stosb\n" + "2:" + ::"S" (src),"D" (dest),"c" (count):"ax"); +return dest; } -inline char * strcat(char * dest,const char * src) +char * strcat(char * dest,const char * src) { - __asm__("cld\n\t" - "repne\n\t" - "scasb\n\t" - "decl %1\n" - "1:\tlodsb\n\t" - "stosb\n\t" - "testb %%al,%%al\n\t" - "jne 1b" - ::"S" (src),"D" (dest),"a" (0),"c" (0xffffffff)); - return dest; +__asm__("cld\n\t" + "repne\n\t" + "scasb\n\t" + "decl %1\n" + "1:\tlodsb\n\t" + "stosb\n\t" + "testb %%al,%%al\n\t" + "jne 1b" + ::"S" (src),"D" (dest),"a" (0),"c" (0xffffffff)); +return dest; } -static inline char * strncat(char * dest,const char * src,int count) +char * strncat(char * dest,const char * src,int count) { - __asm__("cld\n\t" - "repne\n\t" - "scasb\n\t" - "decl %1\n\t" - "movl %4,%3\n" - "1:\tdecl %3\n\t" - "js 2f\n\t" - "lodsb\n\t" - "stosb\n\t" - "testb %%al,%%al\n\t" - "jne 1b\n" - "2:\txorl %2,%2\n\t" - "stosb" - ::"S" (src),"D" (dest),"a" (0),"c" (0xffffffff),"g" (count) - ); - return dest; +__asm__("cld\n\t" + "repne\n\t" + "scasb\n\t" + "decl %1\n\t" + "movl %4,%3\n" + "1:\tdecl %3\n\t" + "js 2f\n\t" + "lodsb\n\t" + "stosb\n\t" + "testb %%al,%%al\n\t" + "jne 1b\n" + "2:\txorl %2,%2\n\t" + "stosb" + ::"S" (src),"D" (dest),"a" (0),"c" (0xffffffff),"g" (count)); +return dest; } -inline int strcmp(const char * cs,const char * ct) +int strcmp(const char * cs,const char * ct) { - register int __res ; - __asm__("cld\n" - "1:\tlodsb\n\t" - "scasb\n\t" - "jne 2f\n\t" - "testb %%al,%%al\n\t" - "jne 1b\n\t" - "xorl %%eax,%%eax\n\t" - "jmp 3f\n" - "2:\tmovl $1,%%eax\n\t" - "jl 3f\n\t" - "negl %%eax\n" - "3:" - :"=a" (__res):"D" (cs),"S" (ct)); - return __res; +register int __res __asm__("ax"); +__asm__("cld\n" + "1:\tlodsb\n\t" + "scasb\n\t" + "jne 2f\n\t" + "testb %%al,%%al\n\t" + "jne 1b\n\t" + "xorl %%eax,%%eax\n\t" + "jmp 3f\n" + "2:\tmovl $1,%%eax\n\t" + "jl 3f\n\t" + "negl %%eax\n" + "3:" + :"=a" (__res):"D" (cs),"S" (ct)); +return __res; } - -static inline int strncmp(const char * cs,const char * ct,int count) +int strncmp(const char * cs,const char * ct,int count) { - register int __res ; - __asm__("cld\n" - "1:\tdecl %3\n\t" - "js 2f\n\t" - "lodsb\n\t" - "scasb\n\t" - "jne 3f\n\t" - "testb %%al,%%al\n\t" - "jne 1b\n" - "2:\txorl %%eax,%%eax\n\t" - "jmp 4f\n" - "3:\tmovl $1,%%eax\n\t" - "jl 4f\n\t" - "negl %%eax\n" - "4:" - :"=a" (__res):"D" (cs),"S" (ct),"c" (count)); - return __res; +register int __res __asm__("ax"); +__asm__("cld\n" + "1:\tdecl %3\n\t" + "js 2f\n\t" + "lodsb\n\t" + "scasb\n\t" + "jne 3f\n\t" + "testb %%al,%%al\n\t" + "jne 1b\n" + "2:\txorl %%eax,%%eax\n\t" + "jmp 4f\n" + "3:\tmovl $1,%%eax\n\t" + "jl 4f\n\t" + "negl %%eax\n" + "4:" + :"=a" (__res):"D" (cs),"S" (ct),"c" (count)); +return __res; } -static inline char * strchr(const char * s,char c) +char * strchr(const char * s,char c) { - register char * __res ; - __asm__("cld\n\t" - "movb %%al,%%ah\n" - "1:\tlodsb\n\t" - "cmpb %%ah,%%al\n\t" - "je 2f\n\t" - "testb %%al,%%al\n\t" - "jne 1b\n\t" - "movl $1,%1\n" - "2:\tmovl %1,%0\n\t" - "decl %0" - :"=a" (__res):"S" (s),"0" (c)); - return __res; +register char * __res __asm__("ax"); +__asm__("cld\n\t" + "movb %%al,%%ah\n" + "1:\tlodsb\n\t" + "cmpb %%ah,%%al\n\t" + "je 2f\n\t" + "testb %%al,%%al\n\t" + "jne 1b\n\t" + "movl $1,%1\n" + "2:\tmovl %1,%0\n\t" + "decl %0" + :"=a" (__res):"S" (s),"0" (c)); +return __res; } -static inline char * strrchr(const char * s,char c) +char * strrchr(const char * s,char c) { - register char * __res; - __asm__("cld\n\t" - "movb %%al,%%ah\n" - "1:\tlodsb\n\t" - "cmpb %%ah,%%al\n\t" - "jne 2f\n\t" - "movl %%esi,%0\n\t" - "decl %0\n" - "2:\ttestb %%al,%%al\n\t" - "jne 1b" - :"=d" (__res):"0" (0),"S" (s),"a" (c)); - return __res; +register char * __res __asm__("dx"); +__asm__("cld\n\t" + "movb %%al,%%ah\n" + "1:\tlodsb\n\t" + "cmpb %%ah,%%al\n\t" + "jne 2f\n\t" + "movl %%esi,%0\n\t" + "decl %0\n" + "2:\ttestb %%al,%%al\n\t" + "jne 1b" + :"=d" (__res):"0" (0),"S" (s),"a" (c)); +return __res; } -inline int strspn(const char * cs, const char * ct) +int strspn(const char * cs, const char * ct) { - register char * __res; - __asm__("cld\n\t" - "movl %4,%%edi\n\t" - "repne\n\t" - "scasb\n\t" - "notl %%ecx\n\t" - "decl %%ecx\n\t" - "movl %%ecx,%%edx\n" - "1:\tlodsb\n\t" - "testb %%al,%%al\n\t" - "je 2f\n\t" - "movl %4,%%edi\n\t" - "movl %%edx,%%ecx\n\t" - "repne\n\t" - "scasb\n\t" - "je 1b\n" - "2:\tdecl %0" - :"=S" (__res):"a" (0),"c" (0xffffffff),"0" (cs),"g" (ct) - ); - return __res-cs; +register char * __res __asm__("si"); +__asm__("cld\n\t" + "movl %4,%%edi\n\t" + "repne\n\t" + "scasb\n\t" + "notl %%ecx\n\t" + "decl %%ecx\n\t" + "movl %%ecx,%%edx\n" + "1:\tlodsb\n\t" + "testb %%al,%%al\n\t" + "je 2f\n\t" + "movl %4,%%edi\n\t" + "movl %%edx,%%ecx\n\t" + "repne\n\t" + "scasb\n\t" + "je 1b\n" + "2:\tdecl %0" + :"=S" (__res):"a" (0),"c" (0xffffffff),"0" (cs),"g" (ct) + :"dx","di"); +return __res-cs; } -inline int strcspn(const char * cs, const char * ct) +int strcspn(const char * cs, const char * ct) { - register char * __res; - __asm__("cld\n\t" - "movl %4,%%edi\n\t" - "repne\n\t" - "scasb\n\t" - "notl %%ecx\n\t" - "decl %%ecx\n\t" - "movl %%ecx,%%edx\n" - "1:\tlodsb\n\t" - "testb %%al,%%al\n\t" - "je 2f\n\t" - "movl %4,%%edi\n\t" - "movl %%edx,%%ecx\n\t" - "repne\n\t" - "scasb\n\t" - "jne 1b\n" - "2:\tdecl %0" - :"=S" (__res):"a" (0),"c" (0xffffffff),"0" (cs),"g" (ct) - ); - return __res-cs; +register char * __res __asm__("si"); +__asm__("cld\n\t" + "movl %4,%%edi\n\t" + "repne\n\t" + "scasb\n\t" + "notl %%ecx\n\t" + "decl %%ecx\n\t" + "movl %%ecx,%%edx\n" + "1:\tlodsb\n\t" + "testb %%al,%%al\n\t" + "je 2f\n\t" + "movl %4,%%edi\n\t" + "movl %%edx,%%ecx\n\t" + "repne\n\t" + "scasb\n\t" + "jne 1b\n" + "2:\tdecl %0" + :"=S" (__res):"a" (0),"c" (0xffffffff),"0" (cs),"g" (ct) + :"dx","di"); +return __res-cs; } -inline char * strpbrk(const char * cs,const char * ct) +char * strpbrk(const char * cs,const char * ct) { - register char * __res ; - __asm__("cld\n\t" - "movl %4,%%edi\n\t" - "repne\n\t" - "scasb\n\t" - "notl %%ecx\n\t" - "decl %%ecx\n\t" - "movl %%ecx,%%edx\n" - "1:\tlodsb\n\t" - "testb %%al,%%al\n\t" - "je 2f\n\t" - "movl %4,%%edi\n\t" - "movl %%edx,%%ecx\n\t" - "repne\n\t" - "scasb\n\t" - "jne 1b\n\t" - "decl %0\n\t" - "jmp 3f\n" - "2:\txorl %0,%0\n" - "3:" - :"=S" (__res):"a" (0),"c" (0xffffffff),"0" (cs),"g" (ct) - ); - return __res; +register char * __res __asm__("si"); +__asm__("cld\n\t" + "movl %4,%%edi\n\t" + "repne\n\t" + "scasb\n\t" + "notl %%ecx\n\t" + "decl %%ecx\n\t" + "movl %%ecx,%%edx\n" + "1:\tlodsb\n\t" + "testb %%al,%%al\n\t" + "je 2f\n\t" + "movl %4,%%edi\n\t" + "movl %%edx,%%ecx\n\t" + "repne\n\t" + "scasb\n\t" + "jne 1b\n\t" + "decl %0\n\t" + "jmp 3f\n" + "2:\txorl %0,%0\n" + "3:" + :"=S" (__res):"a" (0),"c" (0xffffffff),"0" (cs),"g" (ct) + :"dx","di"); +return __res; } -inline char * strstr(const char * cs,const char * ct) +char * strstr(const char * cs,const char * ct) { - register char * __res ; - __asm__("cld\n\t" \ - "movl %4,%%edi\n\t" - "repne\n\t" - "scasb\n\t" - "notl %%ecx\n\t" - "decl %%ecx\n\t" /* NOTE! This also sets Z if searchstring='' */ - "movl %%ecx,%%edx\n" - "1:\tmovl %4,%%edi\n\t" - "movl %%esi,%%eax\n\t" - "movl %%edx,%%ecx\n\t" - "repe\n\t" - "cmpsb\n\t" - "je 2f\n\t" /* also works for empty string, see above */ - "xchgl %%eax,%%esi\n\t" - "incl %%esi\n\t" - "cmpb $0,-1(%%eax)\n\t" - "jne 1b\n\t" - "xorl %%eax,%%eax\n\t" - "2:" - :"=a" (__res):"0" (0),"c" (0xffffffff),"S" (cs),"g" (ct) - ); - return __res; +register char * __res __asm__("ax"); +__asm__("cld\n\t" \ + "movl %4,%%edi\n\t" + "repne\n\t" + "scasb\n\t" + "notl %%ecx\n\t" + "decl %%ecx\n\t" /* NOTE! This also sets Z if searchstring='' */ + "movl %%ecx,%%edx\n" + "1:\tmovl %4,%%edi\n\t" + "movl %%esi,%%eax\n\t" + "movl %%edx,%%ecx\n\t" + "repe\n\t" + "cmpsb\n\t" + "je 2f\n\t" /* also works for empty string, see above */ + "xchgl %%eax,%%esi\n\t" + "incl %%esi\n\t" + "cmpb $0,-1(%%eax)\n\t" + "jne 1b\n\t" + "xorl %%eax,%%eax\n\t" + "2:" + :"=a" (__res):"0" (0),"c" (0xffffffff),"S" (cs),"g" (ct) + :"dx","di"); +return __res; } -inline int strlen(const char * s) +int strlen(const char * s) { - register int __res ; - __asm__("cld\n\t" - "repne\n\t" - "scasb\n\t" - "notl %0\n\t" - "decl %0" - :"=c" (__res):"D" (s),"a" (0),"0" (0xffffffff)); - return __res; +register int __res __asm__("cx"); +__asm__("cld\n\t" + "repne\n\t" + "scasb\n\t" + "notl %0\n\t" + "decl %0" + :"=c" (__res):"D" (s),"a" (0),"0" (0xffffffff)); +return __res; } -inline char * strtok(char * s,const char * ct) +char * ___strtok; + +char * strtok(char * s,const char * ct) { - register char * __res ; - __asm__("testl %1,%1\n\t" - "jne 1f\n\t" - "testl %0,%0\n\t" - "je 8f\n\t" - "movl %0,%1\n" - "1:\txorl %0,%0\n\t" - "movl $-1,%%ecx\n\t" - "xorl %%eax,%%eax\n\t" - "cld\n\t" - "movl %4,%%edi\n\t" - "repne\n\t" - "scasb\n\t" - "notl %%ecx\n\t" - "decl %%ecx\n\t" - "je 7f\n\t" /* empty delimeter-string */ - "movl %%ecx,%%edx\n" - "2:\tlodsb\n\t" - "testb %%al,%%al\n\t" - "je 7f\n\t" - "movl %4,%%edi\n\t" - "movl %%edx,%%ecx\n\t" - "repne\n\t" - "scasb\n\t" - "je 2b\n\t" - "decl %1\n\t" - "cmpb $0,(%1)\n\t" - "je 7f\n\t" - "movl %1,%0\n" - "3:\tlodsb\n\t" - "testb %%al,%%al\n\t" - "je 5f\n\t" - "movl %4,%%edi\n\t" - "movl %%edx,%%ecx\n\t" - "repne\n\t" - "scasb\n\t" - "jne 3b\n\t" - "decl %1\n\t" - "cmpb $0,(%1)\n\t" - "je 5f\n\t" - "movb $0,(%1)\n\t" - "incl %1\n\t" - "jmp 6f\n" - "5:\txorl %1,%1\n" - "6:\tcmpb $0,(%0)\n\t" - "jne 7f\n\t" - "xorl %0,%0\n" - "7:\ttestl %0,%0\n\t" - "jne 8f\n\t" - "movl %0,%1\n" - "8:" - :"=b" (__res),"=S" (___strtok) - :"0" (___strtok),"1" (s),"g" (ct) - ); - return __res; +register char * __res; +__asm__("testl %1,%1\n\t" + "jne 1f\n\t" + "testl %0,%0\n\t" + "je 8f\n\t" + "movl %0,%1\n" + "1:\txorl %0,%0\n\t" + "movl $-1,%%ecx\n\t" + "xorl %%eax,%%eax\n\t" + "cld\n\t" + "movl %4,%%edi\n\t" + "repne\n\t" + "scasb\n\t" + "notl %%ecx\n\t" + "decl %%ecx\n\t" + "je 7f\n\t" /* empty delimeter-string */ + "movl %%ecx,%%edx\n" + "2:\tlodsb\n\t" + "testb %%al,%%al\n\t" + "je 7f\n\t" + "movl %4,%%edi\n\t" + "movl %%edx,%%ecx\n\t" + "repne\n\t" + "scasb\n\t" + "je 2b\n\t" + "decl %1\n\t" + "cmpb $0,(%1)\n\t" + "je 7f\n\t" + "movl %1,%0\n" + "3:\tlodsb\n\t" + "testb %%al,%%al\n\t" + "je 5f\n\t" + "movl %4,%%edi\n\t" + "movl %%edx,%%ecx\n\t" + "repne\n\t" + "scasb\n\t" + "jne 3b\n\t" + "decl %1\n\t" + "cmpb $0,(%1)\n\t" + "je 5f\n\t" + "movb $0,(%1)\n\t" + "incl %1\n\t" + "jmp 6f\n" + "5:\txorl %1,%1\n" + "6:\tcmpb $0,(%0)\n\t" + "jne 7f\n\t" + "xorl %0,%0\n" + "7:\ttestl %0,%0\n\t" + "jne 8f\n\t" + "movl %0,%1\n" + "8:" + :"=b" (__res),"=S" (___strtok) + :"0" (___strtok),"1" (s),"g" (ct) + :"ax","cx","dx","di"); +return __res; } -inline void * memcpy(void * dest,const void * src, int n) +void * memcpy(void * dest,const void * src, int n) { - __asm__ ("cld\n\t" - "rep\n\t" - "movsb" - ::"c" (n),"S" (src),"D" (dest) - ); - return dest; +__asm__("cld\n\t" + "rep\n\t" + "movsb" + ::"c" (n),"S" (src),"D" (dest)); +return dest; } -inline void * memmove(void * dest,const void * src, int n) +void * memmove(void * dest,const void * src, int n) { - if (deststart_code + current->end_code) static long HIGH_MEMORY = 0; #define copy_page(from,to) \ -__asm__("cld ; rep ; movsl"::"S" (from),"D" (to),"c" (1024)) +__asm__("push %%esi; push %%edi;" "cld ; rep ; movsl" ";pop %%edi; pop %%esi"::"S" (from),"D" (to),"c" (1024)) static unsigned char mem_map [ PAGING_PAGES ] = {0,}; @@ -64,7 +64,8 @@ unsigned long get_free_page(void) { register unsigned long __res asm("ax"); -__asm__("std ; repne ; scasb\n\t" +__asm__("push %%edi\n\t" + "std ; repne ; scasb\n\t" "jne 1f\n\t" "movb $1,1(%%edi)\n\t" "sall $12,%%ecx\n\t" @@ -73,8 +74,9 @@ __asm__("std ; repne ; scasb\n\t" "movl $1024,%%ecx\n\t" "leal 4092(%%edx),%%edi\n\t" "rep ; stosl\n\t" - " movl %%edx,%%eax\n" - "1: cld" + " movl %%edx,%%eax\n\t" + "1: cld\n\t" + "pop %%edi" :"=a" (__res) :"0" (0),"i" (LOW_MEM),"c" (PAGING_PAGES), "D" (mem_map+PAGING_PAGES-1) diff --git a/tools/bochs/README b/tools/bochs-2.3.7/README similarity index 100% rename from tools/bochs/README rename to tools/bochs-2.3.7/README diff --git a/tools/bochs/bochsrc/bochsrc-hd-dbg.bxrc b/tools/bochs-2.3.7/bochsrc/bochsrc-hd-dbg.bxrc similarity index 100% rename from tools/bochs/bochsrc/bochsrc-hd-dbg.bxrc rename to tools/bochs-2.3.7/bochsrc/bochsrc-hd-dbg.bxrc diff --git a/tools/bochs/bochsrc/bochsrc-hd.bxrc b/tools/bochs-2.3.7/bochsrc/bochsrc-hd.bxrc similarity index 100% rename from tools/bochs/bochsrc/bochsrc-hd.bxrc rename to tools/bochs-2.3.7/bochsrc/bochsrc-hd.bxrc diff --git a/tools/bochs-2.6.9/README b/tools/bochs-2.6.9/README new file mode 100644 index 0000000..78e177b --- /dev/null +++ b/tools/bochs-2.6.9/README @@ -0,0 +1,44 @@ +0. download bochs 2.6.9 source code +search at sourceforge.net/projects/bochs/files/bochs/2.6.9/ and download it here, and then decompress it. + + +1. compile on Linux +a). compile with gdbstub to support GDB: +$ cd bochs-2.6.9 +************************************************************************************************************* + You may recive message "Program received Signale 0. xxx in page_fault()." frequently and GDB will pause, + then you can solve it by modifying gdbstub.cc: + 1).find all code below + if (last_stop_reason == GDBSTUB_EXECUTION_BREAKPOINT || last_stop_reason == GDBSTUB_TRACE) + { + write_signal(&buf[1], SIGTRAP); + } + 2).append the following code + else if (last_stop_reason == GDBSTUB_STOP_NO_REASON) + { + write_signal(&buf[1], SIGSEGV); + } +************************************************************************************************************* +$ ./configure --enable-debugger-gui --enable-gdb-stub --enable-plugins +$ make +$ sudo cp bochs /usr/local/bin/ +b). compile to bochs debug: +$ ./configure --enable-debugger-gui --enable-debugger --enable-x86-debugger --enable-disasm +$ make +$ sudo cp bochs /usr/local/bin/bochsdbg + + +2. start kernel in bochs +$ bochs -q -f ../bochrc-hd.bxrc + + +3. debug kernel with bochs gdbstub +$ bochs -q -f ../bochrc-hd-gdb.bxrc +and then start the gdb to connect the 1234 port +$ cd linux-0.11 +$ gdb -q ../../../tools/system +(gdb) handle SIGSEGV nostop noprint nopass +(gdb) break main +(gdb) target remote localhost:1234 +(gdb) s +(gdb) ... diff --git a/tools/bochs-2.6.9/bochsrc-hd-gdb.bxrc b/tools/bochs-2.6.9/bochsrc-hd-gdb.bxrc new file mode 100644 index 0000000..2b60d0c --- /dev/null +++ b/tools/bochs-2.6.9/bochsrc-hd-gdb.bxrc @@ -0,0 +1,10 @@ + +gdbstub: enabled=1, port=1234, text_base=0, data_base=0, bss_base=0 + +romimage: file=$BXSHARE/BIOS-bochs-latest +vgaromimage: file=$BXSHARE/VGABIOS-lgpl-latest +megs: 16 +floppya: 1_44="Image", status=inserted +ata0-master: type=disk, path="hdc-0.11.img", mode=flat, cylinders=410, heads=16, spt=38 +boot: a +cpu: ips=15000000 diff --git a/tools/bochs-2.6.9/bochsrc-hd.bxrc b/tools/bochs-2.6.9/bochsrc-hd.bxrc new file mode 100644 index 0000000..6872a9b --- /dev/null +++ b/tools/bochs-2.6.9/bochsrc-hd.bxrc @@ -0,0 +1,8 @@ + +romimage: file=$BXSHARE/BIOS-bochs-latest +vgaromimage: file=$BXSHARE/VGABIOS-lgpl-latest +megs: 16 +floppya: 1_44="Image", status=inserted +ata0-master: type=disk, path="hdc-0.11.img", mode=flat, cylinders=410, heads=16, spt=38 +boot: a +cpu: ips=15000000 diff --git a/tools/build.sh b/tools/build.sh index d542a8f..8f17678 100755 --- a/tools/build.sh +++ b/tools/build.sh @@ -34,7 +34,7 @@ dd if=$setup seek=1 bs=512 count=4 of=$IMAGE 2>&1 >/dev/null [ ! -f "$system" ] && echo "there is no system binary file there" && exit -1 system_size=`wc -c $system |cut -d" " -f1` [ $system_size -gt $SYS_SIZE ] && echo "the system binary is too big" && exit -1 -dd if=$system seek=5 bs=512 count=$((2888-1-4)) of=$IMAGE 2>&1 >/dev/null +dd if=$system seek=5 bs=512 of=$IMAGE 2>&1 >/dev/null # Set "device" for the root image file echo -ne "\x$DEFAULT_MINOR_ROOT\x$DEFAULT_MAJOR_ROOT" | dd ibs=1 obs=1 count=2 seek=508 of=$IMAGE conv=notrunc 2>&1 >/dev/null diff --git a/tools/gdb b/tools/gdb deleted file mode 100755 index 244bcba..0000000 Binary files a/tools/gdb and /dev/null differ