Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support gcc4/5/6/7 & Windows and turn on -O #9

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
133 changes: 0 additions & 133 deletions .gdb_history

This file was deleted.

35 changes: 19 additions & 16 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
OS = Mac

# indicate the Hardware Image file
HDA_IMG = hdc-0.11.img
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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),)
Expand Down Expand Up @@ -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<[email protected]> 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 "<<<Be Happy To Play With It :-)>>>"

Expand Down
33 changes: 24 additions & 9 deletions Makefile.header
Original file line number Diff line number Diff line change
@@ -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

8 changes: 5 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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

8 changes: 4 additions & 4 deletions boot/bootsect.s
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
.code16
# rewrite with AT&T syntax by falcon <[email protected]> at 081012
# Modified by hat <[email protected]> at 2017
#
# SYS_SIZE is the number of clicks (16 bytes) to be loaded.
# 0x3000 is 0x30000 bytes = 196kB, more than enough for current
Expand Down Expand Up @@ -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
Expand Down
10 changes: 5 additions & 5 deletions boot/head.s
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down
Loading