<commit_before># Copyright 2015 <NAME>
#
# licensed under the apache license, version 2.0 (the "license");
# you may not use this file except in compliance with the license.
# you may obtain a copy of the license at
#
#     http://www.apache.org/licenses/license-2.0
#
# unless required by applicable law or agreed to in writing, software
# distributed under the license is distributed on an "as is" basis,
# without warranties or conditions of any kind, either express or implied.
# see the license for the specific language governing permissions and
# limitations under the license.

MK_PATH := $(abspath $(lastword $(MAKEFILE_LIST)))
CUR_DIR := $(notdir $(patsubst %/,%,$(dir $(MK_PATH))))

CC_FLAVOR ?= x86_64
LK_FLAVOR ?= x86_64
BITNESS ?= 64

NASM=nasm
CC=$(CC_FLAVOR)-elf-gcc
LK=$(LK_FLAVOR)-elf-gcc

CFLAGS:=-m$(BITNESS) -std=c11 -ffreestanding -O2 -static -Wall -Wextra -nostdlib -nostartfiles -nodefaultlibs

.PHONY: all
all: kmain.elf kmain.gas.elf

kmain.elf: mb2.o boot.o kmain.o link.ld
	$(LK) $(CFLAGS) -Wl,-n,-T,link.ld -o $@ mb2.o boot.o kmain.o -lgcc
	objdump -x -d -s -mi386 $@ > $@.txt

kmain.gas.elf: mb2.o boot.gas.o kmain.o link.ld
	$(LK) $(CFLAGS) -Wl,-n,-T,link.ld -o $@ mb2.o boot.gas.o kmain.o -lgcc
	objdump -x -d -s -mi386 $@ > $@.txt

%.o: %.asm
	$(NASM) -felf64 $< -o $@

%.o: %.S
	$(CC) $(CFLAGS) -c $< -o $@

mb2.o: mb2.S

bootgas.o: bootgas.S

boot.o: boot.asm
<commit_msg>Add -mno-red-zone and some comments<commit_after># Copyright 2015 <NAME>
#
# licensed under the apache license, version 2.0 (the "license");
# you may not use this file except in compliance with the license.
# you may obtain a copy of the license at
#
#     http://www.apache.org/licenses/license-2.0
#
# unless required by applicable law or agreed to in writing, software
# distributed under the license is distributed on an "as is" basis,
# without warranties or conditions of any kind, either express or implied.
# see the license for the specific language governing permissions and
# limitations under the license.

MK_PATH := $(abspath $(lastword $(MAKEFILE_LIST)))
CUR_DIR := $(notdir $(patsubst %/,%,$(dir $(MK_PATH))))

CC_FLAVOR ?= x86_64
LK_FLAVOR ?= x86_64
BITNESS ?= 64

NASM=nasm
CC=$(CC_FLAVOR)-elf-gcc
LK=$(LK_FLAVOR)-elf-gcc

# See [System V ABI at OSDev.org](http://wiki.osdev.org/System_V_ABI) it says:
#
# "The solution is to build all kernel code with -mno-red-zone or by handling
# interrupts in kernel mode on another stack"
#
# Here I'm choosing to use -mno-red-zone.
# Other info at OSDev.org you do a
# [site search](https://www.google.com/search?q=site%3Aosdev.org%20%22red%20zone%22&rct=j)
# Another good article from
# [<NAME>](http://www.randomhacks.net/2015/11/11/bare-metal-rust-custom-target-kernel-space/)
# Eric also notes that Floating Point registers must be preserved properly
# for now its assumed that there is no floating.
CFLAGS:=-m$(BITNESS) -std=c11 -ffreestanding -O2 -mno-red-zone -static -Wall -Wextra -nostdlib -nostartfiles -nodefaultlibs

.PHONY: all
all: kmain.elf kmain.gas.elf

kmain.elf: mb2.o boot.o kmain.o link.ld
	$(LK) $(CFLAGS) -Wl,-n,-T,link.ld -o $@ mb2.o boot.o kmain.o -lgcc
	objdump -x -d -s -mi386 $@ > $@.txt

kmain.gas.elf: mb2.o boot.gas.o kmain.o link.ld
	$(LK) $(CFLAGS) -Wl,-n,-T,link.ld -o $@ mb2.o boot.gas.o kmain.o -lgcc
	objdump -x -d -s -mi386 $@ > $@.txt

%.o: %.asm
	$(NASM) -felf64 $< -o $@

%.o: %.S
	$(CC) $(CFLAGS) -c $< -o $@

mb2.o: mb2.S

bootgas.o: bootgas.S

boot.o: boot.asm

{'fraction_non_alphanumeric': 0.15557476231633535, 'fraction_numerical': 0.025064822817631807, 'mean_word_length': 3.7046070460704605, 'pattern_counts': {'":': 0, '<': 10, '<?xml version=': 0, '>': 10, 'https://': 1, 'lorem ipsum': 0, 'www.': 4, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '991885', 'n_tokens_mistral': 1419, 'n_tokens_neox': 1334, 'n_words': 413}