sortix-mirror/kernel/Makefile
Jonas 'Sortie' Termansen 2ef6804ead Add networking stack.
This change adds all the kernel parts of a network stack. The network stack
is partial but implements many of the important parts.

Add if(4) network interface abstraction. Network interfaces are registered
in a global list that can be iterated and each assigned an unique integer
identifier.

Add reference counted packets with a cache that recycles recent packets.

Add support for lo(4) loopback and ether(4) ethernet network interfaces.
The /dev/lo0 loopback device is created automatically on boot.

Add arp(4) address resolution protocol driver for translation of inet(4)
network layer addresses into ether(4) link layer addresses. arp(4) entries
are cached and evicted from the cache when needed or when the entry has not
been used for a while. The cache is limited to 256 entries for now.

Add ip(4) internet protocol version 4 support. IP fragmentation and options
are not implemented yet.

Add tcp(4) transmission control protocol sockets for a reliable transport
layer protocol that provides a reliable byte stream connection between two
hosts. The implementation is incomplete and does not yet implement out of
band data, options, and high performance extensions.

Add udp(4) user datagram protocol sockets for a connectionless transport
layer that provides best-effort delivery of datagrams.

Add ping(4) sockets for a best-effort delivery of echo datagrams.

Change type of sa_family_t from unsigned short to uint16_t.

Add --disable-network-drivers to the kernel(7) options and expose it with a
bootloader menu. tix-iso-bootconfig can set this option by default.

Import CRC32 code from libz for the Ethernet checksum.

This is a compatible ABI change that adds features to socket(2) (AF_INET,
IPPROTO_TCP, IPPROTO_UDP, IPPROTO_PING), the ioctls for if(4), socket
options, and the lo0 loopback interface.

This commit is based on work by Meisaka Yukara contributed as the commit
bbf7f1e8a5238a2bd1fe8eb1d2cc5c9c2421e2c4. Almost no lines of this work
remains in this final commit as it has been rewritten or refactored away
over the years, see the individual file headers for which files contain
remnants of this work.

Co-authored-by: Meisaka Yukara <Meisaka.Yukara@gmail.com>
2022-12-11 13:40:34 +01:00

256 lines
5 KiB
Makefile

SOFTWARE_MEANT_FOR_SORTIX=1
include ../build-aux/platform.mak
include ../build-aux/compiler.mak
include ../build-aux/version.mak
include ../build-aux/dirs.mak
# Default values in case the user doesn't override these variables.
OPTLEVEL?=$(DEFAULT_OPTLEVEL)
CPPFLAGS?=
CXXFLAGS?=$(OPTLEVEL)
# Base compiler options and definitions.
CPPFLAGS:=$(CPPFLAGS) -I. -Iinclude -D__is_sortix_kernel
CXXFLAGS:=$(CXXFLAGS) -Wall -Wextra -ffreestanding -fbuiltin -std=gnu++11 \
-fno-exceptions -fno-rtti -fcheck-new
ifeq ($(PANIC_SHORT),1)
CPPFLAGS:=$(CPPFLAGS) -DPANIC_SHORT
endif
ifdef VERSION
CPPFLAGS:=$(CPPFLAGS) -DVERSIONSTR=\"$(VERSION)\"
endif
# Architecture-dependent options and definitions.
BOOTOBJS:=
ifeq ($(CPU),x86)
X86FAMILY:=1
CPUDIR:=$(CPU)
CPUOBJS:=$(CPUDIR)/boot.o
endif
ifeq ($(CPU),x64)
X86FAMILY:=1
CPUDIR:=$(CPU)
CXXFLAGS:=$(CXXFLAGS) -mno-red-zone -mno-mmx -mno-sse -mno-sse2
CPUOBJS:=$(CPUDIR)/boot.o
endif
ifndef CPUDIR
CPUDIR=.
endif
ifdef X86FAMILY
CPUOBJS:=$(CPUOBJS) \
$(CPUDIR)/memorymanagement.o \
x86-family/memorymanagement.o \
$(CPUDIR)/interrupt.o \
x86-family/interrupt.o \
x86-family/ioport.o \
x86-family/pic.o \
x86-family/gdt.o \
x86-family/idt.o \
$(CPUDIR)/syscall.o \
x86-family/cmos.o \
x86-family/time.o \
x86-family/pat.o \
x86-family/float.o \
x86-family/ps2.o \
x86-family/vbox.o \
x86-family/x86-family.o
endif
# Object files that constitute the kernel.
CRTI_OBJ=$(CPUDIR)/crti.o
CRTBEGIN_OBJ=$(shell $(CXX) $(CXXFLAGS) -print-file-name=crtbegin.o)
CRTEND_OBJ=$(shell $(CXX) $(CXXFLAGS) -print-file-name=crtend.o)
CRTN_OBJ=$(CPUDIR)/crtn.o
LIBS=\
-nostdlib \
-lk \
-lgcc \
OBJS=\
$(CPUOBJS) \
addralloc.o \
alarm.o \
clock.o \
com.o \
copy.o \
crc32.o \
descriptor.o \
disk/ahci/ahci.o \
disk/ahci/hba.o \
disk/ahci/port.o \
disk/ata/ata.o \
disk/ata/hba.o \
disk/ata/port.o \
disk/node.o \
dnsconfig.o \
dtable.o \
elf.o \
fcache.o \
fs/full.o \
fsfunc.o \
fs/kram.o \
fs/null.o \
fs/random.o \
fs/user.o \
fs/util.o \
fs/zero.o \
gpu/bga/bga.o \
hostname.o \
identity.o \
initrd.o \
inode.o \
interlock.o \
interrupt.o \
ioctx.o \
io.o \
kb/kblayout.o \
kb/ps2.o \
kernelinfo.o \
kernel.o \
kthread.o \
lfbtextbuffer.o \
libk.o \
linebuffer.o \
log.o \
logterminal.o \
memorymanagement.o \
mouse/ps2.o \
mtable.o \
net/arp.o \
net/ether.o \
net/fs.o \
net/if.o \
net/ip.o \
net/lo/lo.o \
net/packet.o \
net/ping.o \
net/socket.o \
net/tcp.o \
net/udp.o \
op-new.o \
panic.o \
partition.o \
pci-mmio.o \
pci.o \
pipe.o \
poll.o \
process.o \
psctl.o \
ptable.o \
pty.o \
random.o \
refcount.o \
registers.o \
resource.o \
scheduler.o \
segment.o \
signal.o \
sockopt.o \
string.o \
syscall.o \
textbuffer.o \
textterminal.o \
thread.o \
time.o \
timer.o \
tty.o \
uart.o \
user-timer.o \
vga.o \
vgatextbuffer.o \
video.o \
vnode.o \
worker.o \
ALLOBJS=\
$(CRTI_OBJ) \
$(OBJS) \
$(CRTN_OBJ) \
end.o
# TODO: The .init section is linked at 128 MiB on i686 and at 4 MiB on x86_64
# which increases the memory requirement (and isn't mapped) and the _init
# function isn't invoked yet in the kernel anyway.
#LINK_OBJECTS=\
#$(CRTI_OBJ) $(CRTBEGIN_OBJ) $(OBJS) $(LIBS) $(CRTN_OBJ) $(CRTEND_OBJ) end.o
LINK_OBJECTS=$(OBJS) $(LIBS) end.o
# Rules and recipes for building the kernel.
all: kernel
kernel: sortix.bin
.PHONY: all kernel headers clean install install-include-dirs install-headers \
install-kernel install-kernel-binary
headers:
# x64 compilation
ifeq ($(CPU),x64)
sortix-x86_64.bin: $(ALLOBJS)
$(CXX) $(CXXFLAGS) -Wl,-Ttext -Wl,100000 -Wl,-z -Wl,max-page-size=0x1000 $(LINK_OBJECTS) -o $@
sortix.bin: sortix-x86_64.bin
$(OBJCOPY) $< -O elf32-i386-sortix $@
endif
# x86 compilation
ifeq ($(CPU),x86)
sortix.bin: $(ALLOBJS)
$(CXX) $(CXXFLAGS) -Wl,-Ttext -Wl,100000 $(LINK_OBJECTS) -o $@
endif
%: %.kblayout
kblayout-compiler --format=sortix-kblayout-1 --compression=none $< -o $@
# TODO: After releasing Sortix 1.1, change --identifier to -i.
kb/default-kblayout.h: kb/default-kblayout
carray -cgHs -t uint8_t -G SORTIX_KB_DEFAULT_KBLAYOUT_H --identifier=default_kblayout $< -o $@
vgafont.h: vgafont.f16
carray -gHs -t uint8_t -G VGAFONT_H --identifier=vgafont $< -o $@
*.cpp */*.cpp */*/*.cpp: | kb/default-kblayout.h vgafont.h
%.o: %.cpp
$(CXX) -c $< -o $@ $(CPPFLAGS) $(CXXFLAGS)
%.o: %.S
$(CXX) -c $< -o $@ $(CPPFLAGS) $(CXXFLAGS)
clean:
rm -f $(ALLOBJS) sortix.bin
rm -f *.bin *.out *.tmp
rm -f *.o */*.o */*/*.o
rm -f kb/default-kblayout kb/default-kblayout.h
rm -f vgafont.h
# Installation into sysroot
install: install-headers install-kernel
install-include-dirs: headers
mkdir -p $(DESTDIR)$(INCLUDEDIR)
install-headers: install-include-dirs headers
cp -RTv include $(DESTDIR)$(INCLUDEDIR)
install-kernel: install-kernel-binary
install-kernel-binary: sortix.bin
mkdir -p $(DESTDIR)$(BOOTDIR)
cp sortix.bin $(DESTDIR)$(BOOTDIR)/sortix.bin