Skip to content

Commit

Permalink
Merge pull request #220 from mfld-fr/gnu
Browse files Browse the repository at this point in the history
[kernel] Move to full GNU toolchain:
- Rewrite some assembly sources to ATT syntax
- Tune GCC options: small model, no relocations...
- Add LD scripts to output ELKS a.out
- Rework build scripts for full GNU
- Add RAW option for target image
- Warnings and glitches fixes
- Wipe out some BCC related stuff
  • Loading branch information
mfld-fr authored Jun 22, 2018
2 parents bad777f + 578cb7d commit 1b6110b
Show file tree
Hide file tree
Showing 78 changed files with 2,664 additions and 3,686 deletions.
36 changes: 18 additions & 18 deletions README
Original file line number Diff line number Diff line change
@@ -1,20 +1,25 @@
ELKS, the Embeddable Linux Kernel Subset
----------------------------------------

This is a project to write a Linux-like operating system for ancient
computers running an Intel 8086-compatible processor.
This is a project to write a Linux-like operating system for systems based on
the Intel IA16 architecture (16 bits processors: i8088, i8086, i80188, i80186,
i80286, V20, V30 and compatibles).

To build ELKS, you will need a cross build chain, mainly based on DEV86, and
also on GCC-IA16 if you select that latest in place of BCC to build the kernel.
Such systems are ancient computers (IBM-PC XT/AT and clones) or more recent
embedded ones that reuse their huge hardware & software legacy.

To build ELKS, you need a cross build chain, mainly based on DEV86 (still used
for the user land) and GCC-IA16 (now used for the kernel).

A script is provided to automatically download and build that cross chain:

'tools/build.sh'

Note: all the scripts must be executed with top folder 'elks/' as the current one.
Note: all the scripts must be executed with the top folder 'elks/' as the
current one.

A script that attempts to automate the whole build process and make it easier
for ELKS newbies has been provided:
A script is provided to automate the whole build process (configuration,
kernel, user land and target image) and make it easier for ELKS newbies:

'./build.sh'

Expand All @@ -29,29 +34,24 @@ The general build procedure for ELKS is as follows:

'. tools/env.sh' (note the '.' before the script)

* Configure the build chain, the kernel, the commands and select the target
image format (the default configuration is for an IBM PC/XT/AT):
* Configure the build chain, the kernel, the user land and the target image
format:

'make menuconfig'

* Build the kernel and the commands:
* Build the kernel, the user land and the target image:

'make all'

* Build the target image as a user with the 'sudoer' privilege:

'cd elkscmd'
'make image'

The target root folder is built in 'target/', and depending on your
configuration, that folder is packed as either a floppy disk image (fd1440,
fd1680, fd1200, fd720, fd360, without MBR), a hard-disk image (hd, with MBR),
or a file image (rom, tar), into the '/image' folder.

Before writting the image on the real device, you can test it first on QEMU with
'./qemu.sh' (will configure QEMU to be close as possible to an ISA system).
Before writting the image on the real device, you can test it first on QEMU
with './qemu.sh' (will configure QEMU for an ISA system).

Questions? Problems? Patches? Open an issue in this project! You can also join
and email the 'Linux-8086' mailing list at [email protected].
and email the 'Linux-8086' list at [email protected].

More information in the Documentation folder: Documentation/index.html
101 changes: 22 additions & 79 deletions elks/Makefile-rules
Original file line number Diff line number Diff line change
Expand Up @@ -115,42 +115,26 @@ DISTDIR = $(shell $(BASEDIR)/scripts/setdir $(TOPDIR)/elks-$(DIST)/$(MYDIR))
#########################################################################
# Specify the standard definitions to be given to system programs.

ifdef USEIA16
CCDEFS_IA16= -DUSE_IA16
else
CCDEFS_IA16=
endif

CCDEFS = -DELKS_VERSION_CODE=$(VSNCODE) \
-DUTS_RELEASE=\"$(DIST)\" \
-D__KERNEL__ $(CCDEFS_IA16)
-D__KERNEL__ -DUSE_IA16

#########################################################################
# Set the target environment and the compiler to use.

ifeq ($(wildcard $(TOPDIR)/.config),)
MK_ARCH = ibmpc
MK_CPU = 8086
MK_CC = bcc
else
MK_ARCH = $(shell grep '^CONFIG_ARCH_' $(TOPDIR)/.config \
| cut -d = -f 1 | cut -d _ -f 3- | tr A-Z a-z)
MK_CPU = $(shell grep '^CONFIG_CPU_' $(TOPDIR)/.config \
| cut -d = -f 1 | cut -d _ -f 3- | tr A-Z a-z)
MK_CCN = $(shell grep '^CONFIG_COMPILER_' $(TOPDIR)/.config \
| cut -d = -f 1 | cut -d _ -f 3- )
ifeq ($(MK_CCN), 1)
MK_CC = bcc
else
ifeq ($(MK_CCN), 2)
MK_CC = ia16-elf-gcc
else
MK_CC = ia16-unknown-elks-gcc
endif
USEIA16 = y
endif
endif

CROSS_CC = ia16-elf-gcc
CROSS_CFLAGS = -fno-inline -mcmodel=small -mno-segment-relocation-stuff -ffreestanding

#########################################################################
# Define architecture-specific flags.

Expand All @@ -170,39 +154,21 @@ endif
# Define CPU-specific flags.

ifeq ($(MK_CPU), 8086)
ifeq ($(USEIA16), y)
CPU_AS = -0 -O
CPU_CC = -mtune=i8086 -fno-inline -fdata-sections -ffunction-sections -fleading-underscore -mseparate-code-segment -Wl,--gc-sections
CPU_LD = -0
else
CPU_AS = -0 -O
CPU_CC = -0
CPU_LD = -0
endif
CPU_AS = -mtune=i8086
CPU_CC = -mtune=i8086
CPU_LD =
endif

ifeq ($(MK_CPU), 80186)
ifeq ($(USEIA16), y)
CPU_AS = -1 -O
CPU_CC = -mtune=i80186 -fno-inline -fdata-sections -ffunction-sections -fleading-underscore -mseparate-code-segment -Wl,--gc-sections
CPU_LD = -0
else
CPU_AS = -1 -O
CPU_CC = -0
CPU_LD = -0
endif
CPU_AS = -mtune=i18086
CPU_CC = -mtune=i80186
CPU_LD =
endif

ifeq ($(MK_CPU), 80286)
ifeq ($(USEIA16), y)
CPU_AS = -2 -O
CPU_CC = -mtune=i80286 -fno-inline -fdata-sections -ffunction-sections -fleading-underscore -mseparate-code-segment -Wl,--gc-sections
CPU_LD = -0
else
CPU_AS = -2 -O
CPU_CC = -0
CPU_LD = -0
endif
CPU_AS = -mtune=i80286
CPU_CC = -mtune=i80286
CPU_LD =
endif

#########################################################################
Expand All @@ -216,7 +182,6 @@ endif
################################
# Common definitions

AR = ar
CC_PROTO = gcc $(INCLUDES) -M -MG $(CCDEFS)
CFLBASE = $(INCLUDES) $(CCDEFS)
CPP = $(CC) $(INCLUDES) -E $(CCDEFS) -ansi
Expand All @@ -229,41 +194,29 @@ LHFLAGS = $(LCFLAGS) -exportfcn -declundef -fcnuse -fielduse \

ifneq ($(USEBCC), N)

ifeq ($(USEIA16), y)
################################
# Definitions using ia16-unknown-elks-gcc compiler

AS = as86
ASFLAGS = $(CPU_AS) $(ARCH_AS)
CC = $(MK_CC)
CFLAGS = $(CPU_CC) $(ARCH_CC) -Os $(CFLBASE) -Wall
LD = ld86
LDFLAGS = $(CPU_LD) -s

else
################################
# Definitions using BCC compiler

AS = as86
ASFLAGS = $(CPU_AS) $(ARCH_AS)
CC = bcc
CFLAGS = $(CPU_CC) $(ARCH_CC) -O $(CFLBASE) -ansi
LD = ld86
LDFLAGS = $(CPU_LD) -s

endif
AS = ia16-elf-as
ASFLAGS = $(CPU_AS) $(ARCH_AS)
CC = $(CROSS_CC) -Os
CFLAGS = $(CROSS_CFLAGS) $(CPU_CC) $(ARCH_CC) $(CFLBASE) -Wall
LD = ia16-elf-ld
LDFLAGS = $(CPU_LD) -s
AR = ia16-elf-ar

else

################################
# Definitions using GCC compiler
# Definitions using GCC host compiler

AS = as
ASFLAGS =
CC = gcc
CFLAGS = -Wall $(CFLBASE)
LD = ld
LDFLAGS =
AR = ar

endif

Expand All @@ -279,18 +232,8 @@ endif
$(AS) $(ASFLAGS) -o $*.o $<

ifneq ($(USEBCC), N)
ifeq ($(USEIA16), y)
.c.o:
$(CC) $(CFLAGS) -S -o $*.s $<
att2as86 < $*.s > $*.asm
$(AS) $(ASFLAGS) -u -o $*.o $*.asm
rm $*.s $*.asm

else
.c.o:
$(CC) $(CFLAGS) -c -o $*.o $<

endif
endif

#########################################################################
Expand Down
64 changes: 21 additions & 43 deletions elks/arch/i86/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,6 @@ SIBOFLAGS =

endif

LDFLAGS = -0 -i $(SIBOFLAGS)

#########################################################################
# Objects to be compiled.

Expand All @@ -62,62 +60,42 @@ XINCLUDE = $(BASEDIR)/include/arch/asm-offsets.h
#########################################################################
# Things to make.

.PHONY: boot/system toolkit

boot/bootsect: boot/bootsect.o
$(LD) -0 -M $(ARCH_LD) -s -o boot/bootsect boot/bootsect.o > boot/bootsect.map

boot/bootsect.o: boot/bootsect.s
.PHONY: toolkit

boot/crt0.o: boot/crt0.s

boot/crt1.o: boot/crt1.c
boot/bootsect.o: boot/bootsect.S
boot/bootsect.o: boot/bootsect.s
boot/bootsect: boot/bootsect.o
$(LD) $(LDFLAGS) $(SIBOFLAGS) -M -T $(TOPDIR)/elks/elks-tiny.ld -o boot/bootsect boot/bootsect.o > boot/bootsect.map

boot/netbootsect: boot/netbootsect.o
$(LD) $(LDFLAGS) -M $(ARCH_LD) -s -o boot/netbootsect boot/netbootsect.o > boot/netbootsect.map
$(LD) $(LDFLAGS) $(SIBOFLAGS) -M $(ARCH_LD) -s -o boot/netbootsect boot/netbootsect.o > boot/netbootsect.map

boot/netbootsect.o: boot/netbootsect.s

boot/setup: boot/setup.o
$(LD) -0 -M $(ARCH_LD) -s -o boot/setup boot/setup.o > boot/setup.tmp
sort -k3,4 boot/setup.tmp > boot/setup.map
rm -f boot/setup.tmp
boot/setup.s: boot/setup.S
boot/setup.o: boot/setup.s
boot/setup: boot/setup.o
$(LD) $(LDFLAGS) $(SIBOFLAGS) -M -T $(TOPDIR)/elks/elks-tiny.ld -o boot/setup boot/setup.o > boot/setup.map

boot/setup.o: boot/setup.s
boot/crt0.s: boot/crt0.S
boot/crt0.o: boot/crt0.s

boot/crt1.o: boot/crt1.c

toolkit:
${MAKE} -C tools all

ifeq ($(USEIA16), y)
$(BASEDIR)/include/arch/asm-offsets.h: kernel/asm-offsets.c
echo '#ifndef ASM_OFFSETS_H' > $(BASEDIR)/include/arch/asm-offsets.h
echo '#define ASM_OFFSETS_H' >> $(BASEDIR)/include/arch/asm-offsets.h
$(CC) $(CFLAGS) -S -o asm-offsets.s kernel/asm-offsets.c
sed -e '/^\tm/ !d' \
-e "s/\(.*\t\\$$\)/\#define /" \
-e "s/\([0-9][0-9]*\),\t_\([a-zA-Z][_0-9a-zA-Z]*\)/\2 \1/" \
-e "s/\([0-9][0-9]*\),\t\([a-zA-Z][_0-9a-zA-Z]*\)/\2 \1/" \
< asm-offsets.s >> $(BASEDIR)/include/arch/asm-offsets.h
echo '#endif' >> $(BASEDIR)/include/arch/asm-offsets.h
rm asm-offsets.s

else
$(BASEDIR)/include/arch/asm-offsets.h: kernel/asm-offsets.c
echo '#ifndef ASM_OFFSETS_H' > $(BASEDIR)/include/arch/asm-offsets.h
echo '#define ASM_OFFSETS_H' >> $(BASEDIR)/include/arch/asm-offsets.h
$(CC) $(CFLAGS) -S -o asm-offsets.s kernel/asm-offsets.c
sed -e '/^[^m].*/ d' \
-e 's/\],/ /' \
-e 's/ #/ /' \
-e 's/ \*/ /' \
-e 's/ \$$/0x/' \
-e 's/^.*\[_/#define /' \
-e 's/ax/0/' \
< asm-offsets.s | grep -e define >> $(BASEDIR)/include/arch/asm-offsets.h
echo '#endif' >> $(BASEDIR)/include/arch/asm-offsets.h
rm asm-offsets.s

endif

#########################################################################
# Image selection.

Expand All @@ -126,7 +104,7 @@ ifeq ($(CONFIG_ARCH_SIBO), y)
# Begin SIBO image build

boot/system: $(XINCLUDE) $(AARCHIVES) $(ADRIVERS) sibo/crt1.o sibo/crt0.o
(cd $(BASEDIR) ; $(LD) $(LDFLAGS) -t -M $(ARCH_LD) \
(cd $(BASEDIR) ; $(LD) $(LDFLAGS) $(SIBOFLAGS) -M $(ARCH_LD) \
$(ARCH_DIR)/sibo/crt0.o $(ARCH_DIR)/sibo/crt1.o \
init/main.o $(ARCHIVES) $(DRIVERS) \
-o $(ARCH_DIR)/boot/system > $(ARCH_DIR)/boot/system.tmp ; \
Expand All @@ -143,12 +121,12 @@ else
# Begin PC image build

boot/system: $(XINCLUDE) $(AARCHIVES) $(ADRIVERS) boot/crt1.o boot/crt0.o
(cd $(BASEDIR) ; $(LD) $(LDFLAGS) -t -M $(ARCH_LD) \
(cd $(BASEDIR) ; $(LD) $(LDFLAGS) -M $(ARCH_LD) -T $(TOPDIR)/elks/elks-small.ld \
$(ARCH_DIR)/boot/crt0.o $(ARCH_DIR)/boot/crt1.o \
init/main.o $(ARCHIVES) $(DRIVERS) \
-o $(ARCH_DIR)/boot/system > $(ARCH_DIR)/boot/system.tmp ; \
sort -k3,4 $(ARCH_DIR)/boot/system.tmp > $(ARCH_DIR)/boot/system.map ; \
rm -f $(ARCH_DIR)/boot/system.tmp )
init/main.o '-(' $(ARCHIVES) $(DRIVERS) '-)' \
-o $(ARCH_DIR)/boot/system > $(ARCH_DIR)/boot/system.map)
# sort -k3,4 $(ARCH_DIR)/boot/system.tmp > $(ARCH_DIR)/boot/system.map ; \
# rm -f $(ARCH_DIR)/boot/system.tmp )

ifneq ($(CONFIG_ROMCODE), y)

Expand Down
Loading

0 comments on commit 1b6110b

Please sign in to comment.