chore: Update makefiles & macros

This commit is contained in:
EnderIce2 2024-11-29 04:24:27 +02:00
parent ce3cf8162a
commit 7948d0c6e5
Signed by untrusted user who does not match committer: enderice2
GPG Key ID: EACC3AD603BAB4DD
116 changed files with 682 additions and 740 deletions

2
.github/FUNDING.yml vendored
View File

@ -3,7 +3,7 @@
github: # Replace with up to 4 GitHub Sponsors-enabled usernames e.g., [user1, user2]
patreon: # Replace with a single Patreon username
open_collective: # Replace with a single Open Collective username
ko_fi: EnderIce2 # Replace with a single Ko-fi username
ko_fi: # Replace with a single Ko-fi username
tidelift: # Replace with a single Tidelift platform-name/package-name e.g., npm/babel
community_bridge: # Replace with a single Community Bridge project-name e.g., cloud-foundry
liberapay: # Replace with a single Liberapay username

View File

@ -9,7 +9,7 @@ on:
jobs:
deploydoc:
name: Deploy Documentation to GitHub Pages
runs-on: ubuntu-22.04
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v3
@ -32,7 +32,7 @@ jobs:
buildcompiler:
name: Build Cross-Compiler & Toolchain
runs-on: ubuntu-22.04
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
with:
@ -73,7 +73,7 @@ jobs:
analyze:
name: Analyze with CodeQL
runs-on: ubuntu-22.04
runs-on: ubuntu-latest
needs: [buildcompiler]
permissions:
actions: read
@ -122,9 +122,31 @@ jobs:
- name: Perform CodeQL Analysis
uses: github/codeql-action/analyze@v2
flawfinder:
name: Flawfinder
runs-on: ubuntu-latest
permissions:
actions: read
contents: read
security-events: write
steps:
- name: Checkout code
uses: actions/checkout@v3
- name: flawfinder_scan
uses: david-a-wheeler/flawfinder@2.0.19
with:
arguments: '--sarif ./ --minlevel 4'
output: 'flawfinder_results.sarif'
- name: Upload analysis results to GitHub Security tab
uses: github/codeql-action/upload-sarif@v2
with:
sarif_file: ${{github.workspace}}/flawfinder_results.sarif
compile64:
name: Build amd64
runs-on: ubuntu-22.04
runs-on: ubuntu-latest
needs: [buildcompiler]
steps:
- uses: actions/checkout@v3
@ -147,15 +169,15 @@ jobs:
path: tools/cross
key: ${{ runner.os }}-cross-${{ hashFiles('tools/Makefile') }}
- name: Configure Makefile.conf
run: sed -i 's/.*OSARCH = .*/OSARCH = amd64/' ./Makefile.conf && cat Makefile.conf | grep OSARCH
- name: Configure config.mk
run: sed -i 's/.*OSARCH = .*/OSARCH = amd64/' ./config.mk && cat config.mk | grep OSARCH
- name: Compile Debug and Release ISO
run: |
make build
mv Fennix.iso Fennix-debug.iso
make clean
sed -i 's/.*DEBUG = .*/DEBUG = 0/' ./Makefile.conf && cat Makefile.conf | grep DEBUG
sed -i 's/.*DEBUG = .*/DEBUG = 0/' ./config.mk && cat config.mk | grep DEBUG
make build
mv Fennix.iso Fennix-release.iso
@ -173,7 +195,7 @@ jobs:
compile32:
name: Build i386
runs-on: ubuntu-22.04
runs-on: ubuntu-latest
needs: [buildcompiler]
steps:
- uses: actions/checkout@v3
@ -196,15 +218,15 @@ jobs:
path: tools/cross
key: ${{ runner.os }}-cross-${{ hashFiles('tools/Makefile') }}
- name: Configure Makefile.conf
run: sed -i 's/.*OSARCH = .*/OSARCH = i386/' ./Makefile.conf && cat Makefile.conf | grep OSARCH
- name: Configure config.mk
run: sed -i 's/.*OSARCH = .*/OSARCH = i386/' ./config.mk && cat config.mk | grep OSARCH
- name: Compile Debug and Release ISO
run: |
make build
mv Fennix.iso Fennix-debug.iso
make clean
sed -i 's/.*DEBUG = .*/DEBUG = 0/' ./Makefile.conf && cat Makefile.conf | grep DEBUG
sed -i 's/.*DEBUG = .*/DEBUG = 0/' ./config.mk && cat config.mk | grep DEBUG
make build
mv Fennix.iso Fennix-release.iso
@ -223,7 +245,7 @@ jobs:
compilearm64:
if: ${{ false }} # Disabled until we can get it to work
name: Build aarch64
runs-on: ubuntu-22.04
runs-on: ubuntu-latest
needs: [buildcompiler]
steps:
- uses: actions/checkout@v3
@ -246,15 +268,15 @@ jobs:
path: tools/cross
key: ${{ runner.os }}-cross-${{ hashFiles('tools/Makefile') }}
- name: Configure Makefile.conf
run: sed -i 's/.*OSARCH = .*/OSARCH = aarch64/' ./Makefile.conf && cat Makefile.conf | grep OSARCH
- name: Configure config.mk
run: sed -i 's/.*OSARCH = .*/OSARCH = aarch64/' ./config.mk && cat config.mk | grep OSARCH
- name: Compile Debug and Release ISO
run: |
make build
mv Fennix.iso Fennix-debug.iso
make clean
sed -i 's/.*DEBUG = .*/DEBUG = 0/' ./Makefile.conf && cat Makefile.conf | grep DEBUG
sed -i 's/.*DEBUG = .*/DEBUG = 0/' ./config.mk && cat config.mk | grep DEBUG
make build
mv Fennix.iso Fennix-release.iso

View File

@ -87,11 +87,11 @@ build64:
- make --quiet -C Userspace prepare
- make --quiet -C Lynx prepare
- make --quiet -C Kernel prepare
- sed -i 's/.*OSARCH = .*/OSARCH = amd64/' ./Makefile.conf && cat Makefile.conf | grep OSARCH
- sed -i 's/.*OSARCH = .*/OSARCH = amd64/' ./config.mk && cat config.mk | grep OSARCH
- make build
- mv Fennix.iso Fennix-debug.iso
- make clean
- sed -i 's/.*DEBUG = .*/DEBUG = 0/' ./Makefile.conf && cat Makefile.conf | grep DEBUG
- sed -i 's/.*DEBUG = .*/DEBUG = 0/' ./config.mk && cat config.mk | grep DEBUG
- make build
- mv Fennix.iso Fennix-release.iso
artifacts:
@ -111,11 +111,11 @@ build32:
- make --quiet -C Userspace prepare
- make --quiet -C Lynx prepare
- make --quiet -C Kernel prepare
- sed -i 's/.*OSARCH = .*/OSARCH = i386/' ./Makefile.conf && cat Makefile.conf | grep OSARCH
- sed -i 's/.*OSARCH = .*/OSARCH = i386/' ./config.mk && cat config.mk | grep OSARCH
- make build
- mv Fennix.iso Fennix-debug.iso
- make clean
- sed -i 's/.*DEBUG = .*/DEBUG = 0/' ./Makefile.conf && cat Makefile.conf | grep DEBUG
- sed -i 's/.*DEBUG = .*/DEBUG = 0/' ./config.mk && cat config.mk | grep DEBUG
- make build
- mv Fennix.iso Fennix-release.iso
artifacts:
@ -134,11 +134,11 @@ buildarm64:
- make --quiet -C Userspace prepare
- make --quiet -C Lynx prepare
- make --quiet -C Kernel prepare
- sed -i 's/.*OSARCH = .*/OSARCH = arm64/' ./Makefile.conf && cat Makefile.conf | grep OSARCH
- sed -i 's/.*OSARCH = .*/OSARCH = arm64/' ./config.mk && cat config.mk | grep OSARCH
- make build
- mv Fennix.iso Fennix-debug.iso
- make clean
- sed -i 's/.*DEBUG = .*/DEBUG = 0/' ./Makefile.conf && cat Makefile.conf | grep DEBUG
- sed -i 's/.*DEBUG = .*/DEBUG = 0/' ./config.mk && cat config.mk | grep DEBUG
- make build
- mv Fennix.iso Fennix-release.iso
artifacts:

View File

@ -1,20 +0,0 @@
{
"Fennix Kernel Header": {
"scope": "c",
"prefix": [
"head",
],
"body": [
"#ifndef __FENNIX_KERNEL_${2:header}_H__",
"#define __FENNIX_KERNEL_${2:header}_H__",
"",
"#include <types.h>",
"",
"$0",
"",
"#endif // !__FENNIX_KERNEL_${2:header}_H__",
""
],
"description": "Create kernel header."
}
}

View File

@ -11,16 +11,10 @@
"editor.cursorSmoothCaretAnimation": "on",
"files.watcherExclude": {
"**/tools/binutils-gdb/**": true,
"**/tools/build-binutilsamd64/**": true,
"**/tools/build-binutilsarm64/**": true,
"**/tools/build-binutilsi386/**": true,
"**/tools/build-gccamd64/**": true,
"**/tools/build-gccarm64/**": true,
"**/tools/build-gcci386/**": true,
"**/tools/cross/**": true,
"**/tools/gcc/**": true,
"**/tools/limine/**": true,
"**/tools/qemu/**": true,
"**/tools/cross/**": true,
"**/doxygen-doc/**": true,
}
}

View File

@ -12,7 +12,6 @@
"KERNEL_VERSION=\"1.0\"",
"GIT_COMMIT=\"0000000000000000000000000000000000000000\"",
"GIT_COMMIT_SHORT=\"0000000\"",
"a64",
"DEBUG=\"1\""
],
"compilerPath": "${workspaceFolder}/../tools/cross/bin/x86_64-fennix-gcc",
@ -69,7 +68,6 @@
"KERNEL_VERSION=\"1.0\"",
"GIT_COMMIT=\"0000000000000000000000000000000000000000\"",
"GIT_COMMIT_SHORT=\"0000000\"",
"a32",
"DEBUG=\"1\""
],
"compilerPath": "${workspaceFolder}/../tools/cross/bin/i386-elf-gcc",

View File

@ -1,5 +1,5 @@
# Config files
include ../../../Makefile.conf
include ../../../config.mk
include ../../config.mk
S_SOURCES = $(shell find ./ -type f -name '*.S')

View File

@ -1,5 +1,5 @@
# Config files
include ../../../Makefile.conf
include ../../../config.mk
include ../../config.mk
S_SOURCES = $(shell find ./ -type f -name '*.S')

View File

@ -1,5 +1,5 @@
# Config files
include ../../../Makefile.conf
include ../../../config.mk
include ../../config.mk
S_SOURCES = $(shell find ./ -type f -name '*.S')

View File

@ -1,5 +1,5 @@
# Config files
include ../../../Makefile.conf
include ../../../config.mk
include ../../config.mk
S_SOURCES = $(shell find ./ -type f -name '*.S')

View File

@ -1,5 +1,5 @@
# Config file
include ../../Makefile.conf
include ../../config.mk
FILENAME = libkernel.so

View File

@ -1,5 +1,5 @@
# Config files
include ../../../Makefile.conf
include ../../../config.mk
include ../../config.mk
S_SOURCES = $(shell find ./ -type f -name '*.S')

View File

@ -66,15 +66,14 @@ int DriverProbe()
* This function is to test if the driver is compatible
* with the hardware.
* Example: Like if there is a PCI device that the driver
* is for, or a CPU feature that etc.
* is for, or a CPU feature etc.
*
* Return 0 if the driver is compatible with the hardware.
* Otherwise, return a value that is not 0.
*
* Note: In this function you cannot use variables that
* have constructors or destructors. Before DriverEntry,
* the constructors are called and after DriverFinalize,
* the destructors are called.
* the destructors.
*/
return 0;

View File

@ -1,5 +1,5 @@
# Config files
include ../../../Makefile.conf
include ../../../config.mk
include ../../config.mk
S_SOURCES = $(shell find ./ -type f -name '*.S')

View File

@ -1,5 +1,5 @@
# Config files
include ../../../Makefile.conf
include ../../../config.mk
include ../../config.mk
S_SOURCES = $(shell find ./ -type f -name '*.S')

View File

@ -1,5 +1,5 @@
# Config files
include ../../../Makefile.conf
include ../../../config.mk
include ../../config.mk
S_SOURCES = $(shell find ./ -type f -name '*.S')

View File

@ -1,5 +1,5 @@
# Config files
include ../../../Makefile.conf
include ../../../config.mk
include ../../config.mk
S_SOURCES = $(shell find ./ -type f -name '*.S')

View File

@ -1,5 +1,5 @@
# Config files
include ../../../Makefile.conf
include ../../../config.mk
include ../../config.mk
S_SOURCES = $(shell find ./ -type f -name '*.S')

View File

@ -1,36 +0,0 @@
# This workflow uses actions that are not certified by GitHub.
# They are provided by a third-party and are governed by
# separate terms of service, privacy policy, and support
# documentation.
name: flawfinder
on:
push:
branches: [ "master" ]
pull_request:
# The branches below must be a subset of the branches above
branches: [ "master" ]
jobs:
flawfinder:
name: Flawfinder
runs-on: ubuntu-latest
permissions:
actions: read
contents: read
security-events: write
steps:
- name: Checkout code
uses: actions/checkout@v3
- name: flawfinder_scan
uses: david-a-wheeler/flawfinder@8e4a779ad59dbfaee5da586aa9210853b701959c
with:
arguments: '--sarif ./'
output: 'flawfinder_results.sarif'
- name: Upload analysis results to GitHub Security tab
uses: github/codeql-action/upload-sarif@v2
with:
sarif_file: ${{github.workspace}}/flawfinder_results.sarif

View File

@ -10,8 +10,6 @@
"${workspaceFolder}/arch/amd64/include"
],
"defines": [
"a64",
"a86",
"DEBUG=\"1\""
],
"forcedInclude": [
@ -82,8 +80,6 @@
"${workspaceFolder}/.vscode/preinclude.h"
],
"defines": [
"a32",
"a86",
"DEBUG=\"1\""
],
"compilerPath": "${workspaceFolder}/../tools/cross/bin/i386-fennix-gcc",
@ -154,7 +150,6 @@
"${workspaceFolder}/.vscode/preinclude.h"
],
"defines": [
"aa64",
"DEBUG=\"1\""
],
"compilerPath": "${workspaceFolder}/../tools/cross/bin/aarch64-fennix-gcc",

View File

@ -1,54 +1,38 @@
# Config file
include ../Makefile.conf
KERNEL_FILENAME = fennix.elf
CC = ../$(COMPILER_PATH)/$(COMPILER_ARCH)gcc
CPP = ../$(COMPILER_PATH)/$(COMPILER_ARCH)g++
LD = ../$(COMPILER_PATH)/$(COMPILER_ARCH)ld
AS = ../$(COMPILER_PATH)/$(COMPILER_ARCH)as
NM = ../$(COMPILER_PATH)/$(COMPILER_ARCH)nm
OBJCOPY = ../$(COMPILER_PATH)/$(COMPILER_ARCH)objcopy
OBJDUMP = ../$(COMPILER_PATH)/$(COMPILER_ARCH)objdump
GDB = ../$(COMPILER_PATH)/$(COMPILER_ARCH)gdb
RUST_TARGET_PATH = arch/$(OSARCH)/rust-target.json
GIT_COMMIT = $(shell git rev-parse HEAD)
GIT_COMMIT_SHORT = $(shell git rev-parse --short HEAD)
HEADERS = $(sort $(dir $(wildcard ./include/*))) $(sort $(dir $(wildcard ./include_std/*)))
HEADERS := $(sort $(dir $(wildcard ./include/*))) $(sort $(dir $(wildcard ./include_std/*)))
INCLUDE_DIR = -I./include -I./include_std
BMP_SOURCES = $(shell find ./ -type f -name '*.bmp')
PSF_SOURCES = $(shell find ./ -type f -name '*.psf')
BMP_SOURCES := $(shell find ./ -type f -name '*.bmp')
PSF_SOURCES := $(shell find ./ -type f -name '*.psf')
ifeq ($(OSARCH), amd64)
S_SOURCES = $(shell find ./ -type f -name '*.S' -not -path "./arch/i386/*" -not -path "./arch/aarch64/*")
s_SOURCES = $(shell find ./ -type f -name '*.s' -not -path "./arch/i386/*" -not -path "./arch/aarch64/*")
C_SOURCES = $(shell find ./ -type f -name '*.c' -not -path "./arch/i386/*" -not -path "./arch/aarch64/*")
CPP_SOURCES = $(shell find ./ -type f -name '*.cpp' -not -path "./arch/i386/*" -not -path "./arch/aarch64/*")
HEADERS += $(sort $(dir $(wildcard ./arch/amd64/include/*)))
INCLUDE_DIR += -I./arch/amd64/include
S_SOURCES := $(shell find ./ -type f -name '*.S' -not -path "./arch/i386/*" -not -path "./arch/aarch64/*")
s_SOURCES := $(shell find ./ -type f -name '*.s' -not -path "./arch/i386/*" -not -path "./arch/aarch64/*")
C_SOURCES := $(shell find ./ -type f -name '*.c' -not -path "./arch/i386/*" -not -path "./arch/aarch64/*")
CPP_SOURCES := $(shell find ./ -type f -name '*.cpp' -not -path "./arch/i386/*" -not -path "./arch/aarch64/*")
else ifeq ($(OSARCH), i386)
S_SOURCES = $(shell find ./ -type f -name '*.S' -not -path "./arch/amd64/*" -not -path "./arch/aarch64/*")
s_SOURCES = $(shell find ./ -type f -name '*.s' -not -path "./arch/amd64/*" -not -path "./arch/aarch64/*")
C_SOURCES = $(shell find ./ -type f -name '*.c' -not -path "./arch/amd64/*" -not -path "./arch/aarch64/*")
CPP_SOURCES = $(shell find ./ -type f -name '*.cpp' -not -path "./arch/amd64/*" -not -path "./arch/aarch64/*")
HEADERS += $(sort $(dir $(wildcard ./arch/i386/include/*)))
INCLUDE_DIR += -I./arch/i386/include
S_SOURCES := $(shell find ./ -type f -name '*.S' -not -path "./arch/amd64/*" -not -path "./arch/aarch64/*")
s_SOURCES := $(shell find ./ -type f -name '*.s' -not -path "./arch/amd64/*" -not -path "./arch/aarch64/*")
C_SOURCES := $(shell find ./ -type f -name '*.c' -not -path "./arch/amd64/*" -not -path "./arch/aarch64/*")
CPP_SOURCES := $(shell find ./ -type f -name '*.cpp' -not -path "./arch/amd64/*" -not -path "./arch/aarch64/*")
else ifeq ($(OSARCH), aarch64)
S_SOURCES = $(shell find ./ -type f -name '*.S' -not -path "./arch/amd64/*" -not -path "./arch/i386/*")
s_SOURCES = $(shell find ./ -type f -name '*.s' -not -path "./arch/amd64/*" -not -path "./arch/i386/*")
C_SOURCES = $(shell find ./ -type f -name '*.c' -not -path "./arch/amd64/*" -not -path "./arch/i386/*")
CPP_SOURCES = $(shell find ./ -type f -name '*.cpp' -not -path "./arch/amd64/*" -not -path "./arch/i386/*")
HEADERS += $(sort $(dir $(wildcard ./arch/aarch64/include/*)))
INCLUDE_DIR += -I./arch/aarch64/include
endif
OBJ = $(C_SOURCES:.c=.o) $(CPP_SOURCES:.cpp=.o) $(ASM_SOURCES:.asm=.o) $(S_SOURCES:.S=.o) $(s_SOURCES:.s=.o) $(PSF_SOURCES:.psf=.o) $(BMP_SOURCES:.bmp=.o)
S_SOURCES := $(shell find ./ -type f -name '*.S' -not -path "./arch/amd64/*" -not -path "./arch/i386/*")
s_SOURCES := $(shell find ./ -type f -name '*.s' -not -path "./arch/amd64/*" -not -path "./arch/i386/*")
C_SOURCES := $(shell find ./ -type f -name '*.c' -not -path "./arch/amd64/*" -not -path "./arch/i386/*")
CPP_SOURCES := $(shell find ./ -type f -name '*.cpp' -not -path "./arch/amd64/*" -not -path "./arch/i386/*")
endif # OSARCH
OBJ = $(BMP_SOURCES:.bmp=.o) $(PSF_SOURCES:.psf=.o) $(s_SOURCES:.s=.o) $(S_SOURCES:.S=.o) $(C_SOURCES:.c=.o) $(CPP_SOURCES:.cpp=.o)
STACK_USAGE_OBJ = $(C_SOURCES:.c=.su) $(CPP_SOURCES:.cpp=.su)
GCNO_OBJ = $(C_SOURCES:.c=.gcno) $(CPP_SOURCES:.cpp=.gcno)
LDFLAGS := -Wl,-Map kernel.map -static -nostdlib -nodefaultlibs -nolibc
LDFLAGS = -static -nostdlib -nodefaultlibs -nolibc \
-Wl,-static,--no-dynamic-linker,-ztext \
-zmax-page-size=0x1000 \
-Wl,-Map kernel.map -fno-pic -fno-pie
# Disable all warnings by adding "-w" in WARNCFLAG and if you want to treat the warnings as errors, add "-Werror"
# -Wconversion this may be re-added later
@ -58,6 +42,8 @@ WARNCFLAG = -Wall -Wextra \
-Wstrict-overflow=5 -Wno-error=cpp -Werror \
-Wno-unused-parameter
CFLAG_STACK_PROTECTOR := -fstack-protector-all
# https://gcc.gnu.org/onlinedocs/gcc/x86-Options.html
CFLAGS := \
$(INCLUDE_DIR) \
@ -66,40 +52,19 @@ CFLAGS := \
-DKERNEL_ARCH='"$(OSARCH)"' \
-DKERNEL_VERSION='"$(KERNEL_VERSION)"' \
-DGIT_COMMIT='"$(GIT_COMMIT)"' \
-DGIT_COMMIT_SHORT='"$(GIT_COMMIT_SHORT)"'
-DGIT_COMMIT_SHORT='"$(GIT_COMMIT_SHORT)"' \
-fno-pic -fno-pie -mno-red-zone -fno-builtin
ifeq ($(OSARCH), amd64)
CFLAGS += -fno-pic -fno-pie -mno-red-zone -march=core2 \
-mcmodel=kernel -fno-builtin -Da64 -Da86 -m64
CFLAG_STACK_PROTECTOR := -fstack-protector-all
LDFLAGS += -Tarch/amd64/linker.ld \
-fno-pic -fno-pie \
-Wl,-static,--no-dynamic-linker,-ztext \
-zmax-page-size=0x1000 \
-Wl,-Map kernel.map
CFLAGS += -march=core2 -mcmodel=kernel -m64
LDFLAGS += -Tarch/amd64/linker.ld
else ifeq ($(OSARCH), i386)
CFLAGS += -fno-pic -fno-pie -mno-red-zone -march=pentium \
-fno-builtin -Da32 -Da86 -m32
CFLAG_STACK_PROTECTOR := -fstack-protector-all
LDFLAGS += -Tarch/i386/linker.ld \
-fno-pic -fno-pie \
-Wl,-static,--no-dynamic-linker,-ztext \
-zmax-page-size=0x1000 \
-Wl,-Map kernel.map
CFLAGS += -march=pentium -m32
LDFLAGS += -Tarch/i386/linker.ld
else ifeq ($(OSARCH), aarch64)
CFLAGS += -fno-builtin -Wstack-protector -Daa64 -fPIC -mno-outline-atomics
CFLAG_STACK_PROTECTOR := -fstack-protector-all
LDFLAGS += -Tarch/aarch64/linker.ld -fPIC -pie \
-Wl,-static,--no-dynamic-linker,-ztext \
-zmax-page-size=0x1000 \
-Wl,-Map kernel.map
endif
CFLAGS +=
LDFLAGS += -Tarch/aarch64/linker.ld
endif # OSARCH
# -finstrument-functions for __cyg_profile_func_enter & __cyg_profile_func_exit. Used for profiling and debugging.
ifeq ($(DEBUG), 1)
@ -109,14 +74,14 @@ ifeq ($(DEBUG), 1)
CFLAGS += -DDEBUG -ggdb3 -O0 -fdiagnostics-color=always -fstack-usage -fsanitize=undefined
ifeq ($(OSARCH), amd64)
CFLAGS += -fverbose-asm
endif
endif # amd64
ifneq ($(OSARCH), aarch64)
CFLAGS += -fstack-check
endif
endif # aarch64
LDFLAGS += -ggdb3 -O0
ASFLAGS += -g --gstabs+ --gdwarf-5 -D
WARNCFLAG += -Wno-unused-function -Wno-maybe-uninitialized -Wno-builtin-declaration-mismatch -Wno-unknown-pragmas -Wno-unused-parameter -Wno-unused-variable
endif
endif # DEBUG
default:
$(error Please specify a target)
@ -131,51 +96,51 @@ ifeq (,$(wildcard $(KERNEL_FILENAME)))
$(error $(KERNEL_FILENAME) does not exist)
endif
$(info Dumping $(KERNEL_FILENAME) in AT T syntax...)
$(OBJDUMP) -D -g -s -d $(KERNEL_FILENAME) > kernel_dump.map
$(__CONF_OBJDUMP) -D -g -s -d $(KERNEL_FILENAME) > kernel_dump.map
$(info Dumping $(KERNEL_FILENAME) in Intel syntax...)
$(OBJDUMP) -M intel -D -g -s -d $(KERNEL_FILENAME) > kernel_dump_intel.map
$(__CONF_OBJDUMP) -M intel -D -g -s -d $(KERNEL_FILENAME) > kernel_dump_intel.map
$(KERNEL_FILENAME): $(OBJ)
$(info Linking $@)
$(CC) $(LDFLAGS) $(OBJ) -o $@
# $(CC) $(LDFLAGS) $(OBJ) -mno-red-zone -lgcc -o $@
$(__CONF_CC) $(LDFLAGS) $(OBJ) -o $@
# $(__CONF_CC) $(LDFLAGS) $(OBJ) -mno-red-zone -lgcc -o $@
%.o: %.c $(HEADERS)
$(info Compiling $<)
$(CC) $(CFLAGS) $(CFLAG_STACK_PROTECTOR) $(WARNCFLAG) -std=c17 -c $< -o $@
$(__CONF_CC) $(CFLAGS) $(CFLAG_STACK_PROTECTOR) $(WARNCFLAG) -std=c17 -c $< -o $@
# https://gcc.gnu.org/projects/cxx-status.html
%.o: %.cpp $(HEADERS)
$(info Compiling $<)
$(CPP) $(CFLAGS) -fcoroutines $(CFLAG_STACK_PROTECTOR) $(WARNCFLAG) -std=c++20 -c $< -o $@ -fno-rtti
$(__CONF_CPP) $(CFLAGS) -fcoroutines $(CFLAG_STACK_PROTECTOR) $(WARNCFLAG) -std=c++20 -c $< -o $@ -fno-rtti
%.o: %.S
$(info Compiling $<)
$(AS) $(ASFLAGS) -c $< -o $@
$(__CONF_AS) $(ASFLAGS) -c $< -o $@
%.o: %.s
$(info Compiling $<)
$(AS) $(ASFLAGS) -c $< -o $@
$(__CONF_AS) $(ASFLAGS) -c $< -o $@
%.o: %.psf
ifeq ($(OSARCH), amd64)
$(OBJCOPY) -O elf64-x86-64 -I binary $< $@
$(__CONF_OBJCOPY) -O elf64-x86-64 -I binary $< $@
else ifeq ($(OSARCH), i386)
$(OBJCOPY) -O elf32-i386 -I binary $< $@
$(__CONF_OBJCOPY) -O elf32-i386 -I binary $< $@
else ifeq ($(OSARCH), aarch64)
$(OBJCOPY) -O elf64-littleaarch64 -I binary $< $@
$(__CONF_OBJCOPY) -O elf64-littleaarch64 -I binary $< $@
endif
$(NM) $@
$(__CONF_NM) $@
%.o: %.bmp
ifeq ($(OSARCH), amd64)
$(OBJCOPY) -O elf64-x86-64 -I binary $< $@
$(__CONF_OBJCOPY) -O elf64-x86-64 -I binary $< $@
else ifeq ($(OSARCH), i386)
$(OBJCOPY) -O elf32-i386 -I binary $< $@
$(__CONF_OBJCOPY) -O elf32-i386 -I binary $< $@
else ifeq ($(OSARCH), aarch64)
$(OBJCOPY) -O elf64-littlearch64 -I binary $< $@
$(__CONF_OBJCOPY) -O elf64-littlearch64 -I binary $< $@
endif
$(NM) $@
$(__CONF_NM) $@
clean:
rm -f kernel.map kernel_dump.map kernel_dump_intel.map $(OBJ) $(STACK_USAGE_OBJ) $(GCNO_OBJ) $(KERNEL_FILENAME)

View File

@ -24,11 +24,11 @@
#include "../kernel.h"
#if defined(a64)
#if defined(__amd64__)
using namespace CPU::x64;
#elif defined(a32)
#elif defined(__i386__)
using namespace CPU::x32;
#elif defined(aa64)
#elif defined(__aarch64__)
#endif
namespace CPU
@ -40,19 +40,19 @@ namespace CPU
static char Vendor[13] = {0};
if (Vendor[0] != 0)
return Vendor;
#if defined(a64)
#if defined(__amd64__)
uint32_t eax, ebx, ecx, edx;
x64::cpuid(0x0, &eax, &ebx, &ecx, &edx);
memcpy(Vendor + 0, &ebx, 4);
memcpy(Vendor + 4, &edx, 4);
memcpy(Vendor + 8, &ecx, 4);
#elif defined(a32)
#elif defined(__i386__)
uint32_t eax, ebx, ecx, edx;
x32::cpuid(0x0, &eax, &ebx, &ecx, &edx);
memcpy(Vendor + 0, &ebx, 4);
memcpy(Vendor + 4, &edx, 4);
memcpy(Vendor + 8, &ecx, 4);
#elif defined(aa64)
#elif defined(__aarch64__)
#error "Not implemented"
#endif
return Vendor;
@ -63,7 +63,7 @@ namespace CPU
static char Name[49] = {0};
if (Name[0] != 0)
return Name;
#if defined(a64)
#if defined(__amd64__)
uint32_t eax, ebx, ecx, edx;
x64::cpuid(0x80000002, &eax, &ebx, &ecx, &edx);
memcpy(Name + 0, &eax, 4);
@ -80,7 +80,7 @@ namespace CPU
memcpy(Name + 36, &ebx, 4);
memcpy(Name + 40, &ecx, 4);
memcpy(Name + 44, &edx, 4);
#elif defined(a32)
#elif defined(__i386__)
uint32_t eax, ebx, ecx, edx;
x32::cpuid(0x80000002, &eax, &ebx, &ecx, &edx);
memcpy(Name + 0, &eax, 4);
@ -97,7 +97,7 @@ namespace CPU
memcpy(Name + 36, &ebx, 4);
memcpy(Name + 40, &ecx, 4);
memcpy(Name + 44, &edx, 4);
#elif defined(aa64)
#elif defined(__aarch64__)
#error "Not implemented"
#endif
return Name;
@ -108,7 +108,7 @@ namespace CPU
static char Hypervisor[13] = {0};
if (Hypervisor[0] != 0)
return Hypervisor;
#if defined(a64)
#if defined(__amd64__)
uint32_t eax, ebx, ecx, edx;
x64::cpuid(0x1, &eax, &ebx, &ecx, &edx);
if (!(ecx & (1 << 31))) /* Intel & AMD are the same */
@ -124,7 +124,7 @@ namespace CPU
memcpy(Hypervisor + 0, &ebx, 4);
memcpy(Hypervisor + 4, &ecx, 4);
memcpy(Hypervisor + 8, &edx, 4);
#elif defined(a32)
#elif defined(__i386__)
uint32_t eax, ebx, ecx, edx;
x32::cpuid(0x1, &eax, &ebx, &ecx, &edx);
if (!(ecx & (1 << 31))) /* Intel & AMD are the same */
@ -140,7 +140,7 @@ namespace CPU
memcpy(Hypervisor + 0, &ebx, 4);
memcpy(Hypervisor + 4, &ecx, 4);
memcpy(Hypervisor + 8, &edx, 4);
#elif defined(aa64)
#elif defined(__aarch64__)
#error "Not implemented"
#endif
return Hypervisor;
@ -153,17 +153,17 @@ namespace CPU
case Check:
{
uintptr_t Flags;
#if defined(a64)
#if defined(__amd64__)
asmv("pushfq");
asmv("popq %0"
: "=r"(Flags));
return Flags & (1 << 9);
#elif defined(a32)
#elif defined(__i386__)
asmv("pushfl");
asmv("popl %0"
: "=r"(Flags));
return Flags & (1 << 9);
#elif defined(aa64)
#elif defined(__aarch64__)
asmv("mrs %0, cpsr"
: "=r"(Flags));
return Flags & (1 << 7);
@ -171,18 +171,18 @@ namespace CPU
}
case Enable:
{
#if defined(a86)
#if defined(__amd64__) || defined(__i386__)
asmv("sti");
#elif defined(aa64)
#elif defined(__aarch64__)
asmv("cpsie i");
#endif
return true;
}
case Disable:
{
#if defined(a86)
#if defined(__amd64__) || defined(__i386__)
asmv("cli");
#elif defined(aa64)
#elif defined(__aarch64__)
asmv("cpsid i");
#endif
return true;
@ -197,7 +197,7 @@ namespace CPU
void *PageTable(void *PT)
{
void *ret;
#if defined(a64)
#if defined(__amd64__)
asmv("movq %%cr3, %0"
: "=r"(ret));
@ -208,7 +208,7 @@ namespace CPU
: "r"(PT)
: "memory");
}
#elif defined(a32)
#elif defined(__i386__)
asmv("movl %%cr3, %0"
: "=r"(ret));
@ -219,7 +219,7 @@ namespace CPU
: "r"(PT)
: "memory");
}
#elif defined(aa64)
#elif defined(__aarch64__)
asmv("mrs %0, ttbr0_el1"
: "=r"(ret));
@ -392,13 +392,13 @@ namespace CPU
{
// TODO: Get the counter from the x2APIC or any other timer that is available. (TSC is not available on all CPUs)
uint64_t Counter;
#if defined(a86)
#if defined(__amd64__) || defined(__i386__)
uint32_t eax, edx;
asmv("rdtsc"
: "=a"(eax),
"=d"(edx));
Counter = ((uint64_t)eax) | (((uint64_t)edx) << 32);
#elif defined(aa64)
#elif defined(__aarch64__)
asmv("mrs %0, cntvct_el0"
: "=r"(Counter));
#endif
@ -413,7 +413,7 @@ namespace CPU
#warning "TODO: Proper SIMD support"
return SIMD_NONE;
#if defined(a86)
#if defined(__amd64__) || defined(__i386__)
static uint64_t SIMDType = SIMD_NONE;
if (likely(SIMDType != SIMD_NONE))
@ -495,7 +495,7 @@ namespace CPU
}
debug("No SIMD support.");
#endif // a64 || a32
#endif // __amd64__ || __i386__
return SIMD_NONE;
}
@ -504,7 +504,7 @@ namespace CPU
if (unlikely(!SSEEnabled))
return false;
#if defined(a86)
#if defined(__amd64__) || defined(__i386__)
if (strcmp(CPU::Vendor(), x86_CPUID_VENDOR_AMD) == 0)
{
CPU::x86::AMD::CPUID0x00000001 cpuid;
@ -545,7 +545,7 @@ namespace CPU
else if (Type == SIMD_SSE)
return cpuid.EDX.SSE;
}
#endif // a64 || a32
#endif // __amd64__ || __i386__
return false;
}
}

View File

@ -22,9 +22,9 @@
#include <smp.hpp>
#include <io.h>
#if defined(a64)
#if defined(__amd64__)
#include "../arch/amd64/cpu/apic.hpp"
#elif defined(a32)
#elif defined(__i386__)
#include "../arch/i386/cpu/apic.hpp"
#endif
#include "../kernel.h"

View File

@ -23,15 +23,15 @@
#include <vector>
#include <io.h>
#if defined(a64)
#if defined(__amd64__)
#include "../arch/amd64/cpu/apic.hpp"
#include "../arch/amd64/cpu/gdt.hpp"
#include "../arch/amd64/cpu/idt.hpp"
#elif defined(a32)
#elif defined(__i386__)
#include "../arch/i386/cpu/apic.hpp"
#include "../arch/i386/cpu/gdt.hpp"
#include "../arch/i386/cpu/idt.hpp"
#elif defined(aa64)
#elif defined(__aarch64__)
#endif
#include "../kernel.h"
@ -106,15 +106,15 @@ namespace Interrupts
std::atomic_uint SortEvents = SORT_START / SORT_DIVIDER;
constexpr uint32_t SORT_ITR = (SORT_START * 100) / SORT_DIVIDER;
#if defined(a86)
#if defined(__amd64__) || defined(__i386__)
/* APIC::APIC */ void *apic[MAX_CPU] = {nullptr};
/* APIC::Timer */ void *apicTimer[MAX_CPU] = {nullptr};
#elif defined(aa64)
#elif defined(__aarch64__)
#endif
void Initialize(int Core)
{
#if defined(a64)
#if defined(__amd64__)
GlobalDescriptorTable::Init(Core);
InterruptDescriptorTable::Init(Core);
CPUData *CoreData = GetCPU(Core);
@ -133,7 +133,7 @@ namespace Interrupts
debug("Stack for core %d is %#lx (Address: %#lx)",
Core, CoreData->Stack, CoreData->Stack - STACK_SIZE);
InitializeSystemCalls();
#elif defined(a32)
#elif defined(__i386__)
GlobalDescriptorTable::Init(Core);
InterruptDescriptorTable::Init(Core);
CPUData *CoreData = GetCPU(Core);
@ -151,14 +151,14 @@ namespace Interrupts
}
debug("Stack for core %d is %#lx (Address: %#lx)",
Core, CoreData->Stack, CoreData->Stack - STACK_SIZE);
#elif defined(aa64)
#elif defined(__aarch64__)
warn("aarch64 is not supported yet");
#endif
}
void Enable(int Core)
{
#if defined(a86)
#if defined(__amd64__) || defined(__i386__)
if (((ACPI::MADT *)PowerManager->GetMADT())->LAPICAddress != nullptr)
{
// TODO: This function is called by SMP too. Do not initialize timers that doesn't support multiple cores.
@ -171,7 +171,7 @@ namespace Interrupts
error("LAPIC not found");
// TODO: PIC
}
#elif defined(aa64)
#elif defined(__aarch64__)
warn("aarch64 is not supported yet");
#endif
CPU::Interrupts(CPU::Enable);
@ -180,14 +180,14 @@ namespace Interrupts
void InitializeTimer(int Core)
{
// TODO: This function is called by SMP too. Do not initialize timers that doesn't support multiple cores.
#if defined(a86)
#if defined(__amd64__) || defined(__i386__)
if (apic[Core] != nullptr)
apicTimer[Core] = new APIC::Timer((APIC::APIC *)apic[Core]);
else
{
fixme("apic not found");
}
#elif defined(aa64)
#elif defined(__aarch64__)
warn("aarch64 is not supported yet");
#endif
}
@ -333,12 +333,12 @@ namespace Interrupts
public:
AutoSwitchPageTable()
{
#if defined(a86)
#if defined(__amd64__) || defined(__i386__)
asmv("mov %%cr3, %0" : "=r"(Original));
#endif
if (likely(Original == KernelPageTable))
return;
#if defined(a86)
#if defined(__amd64__) || defined(__i386__)
asmv("mov %0, %%cr3" : : "r"(KernelPageTable));
#endif
}
@ -347,7 +347,7 @@ namespace Interrupts
{
if (likely(Original == KernelPageTable))
return;
#if defined(a86)
#if defined(__amd64__) || defined(__i386__)
asmv("mov %0, %%cr3" : : "r"(Original));
#endif
}
@ -365,7 +365,7 @@ namespace Interrupts
while (it != RegisteredEvents.end())
{
int iEvNum = it->IRQ;
#if defined(a86)
#if defined(__amd64__) || defined(__i386__)
iEvNum += CPU::x86::IRQ0;
#endif
if (iEvNum == s_cst(int, Frame->InterruptNumber))
@ -402,7 +402,7 @@ namespace Interrupts
{
KernelPageTable->Update();
CPU::SchedulerFrame *Frame = (CPU::SchedulerFrame *)Data;
#if defined(a86)
#if defined(__amd64__) || defined(__i386__)
assert(Frame->InterruptNumber == CPU::x86::IRQ16);
#else
assert(Frame->InterruptNumber == 16);

View File

@ -75,7 +75,7 @@ namespace Memory
}
}
#if defined(a86)
#if defined(__amd64__) || defined(__i386__)
if (bInfo.RSDP)
{
RSDPStart = (uintptr_t)bInfo.RSDP;
@ -101,7 +101,7 @@ namespace Memory
}
#endif
}
#elif defined(aa64)
#elif defined(__aarch64__)
#endif
for (uint64_t i = 0; i < bInfo.Memory.Entries; i++)

View File

@ -121,7 +121,7 @@ namespace Xalloc
{
if (this->SMAPUsed)
{
#if defined(a86)
#if defined(__amd64__) || defined(__i386__)
asm volatile("stac" ::
: "cc");
#endif
@ -132,7 +132,7 @@ namespace Xalloc
{
if (this->SMAPUsed)
{
#if defined(a86)
#if defined(__amd64__) || defined(__i386__)
asm volatile("clac" ::
: "cc");
#endif

View File

@ -56,7 +56,7 @@ NIF void tracepagetable(PageTable *pt)
{
for (int i = 0; i < 512; i++)
{
#if defined(a64)
#if defined(__amd64__)
if (pt->Entries[i].Present)
debug("Entry %03d: %x %x %x %x %x %x %x %p-%#llx", i,
pt->Entries[i].Present, pt->Entries[i].ReadWrite,
@ -64,8 +64,8 @@ NIF void tracepagetable(PageTable *pt)
pt->Entries[i].CacheDisable, pt->Entries[i].Accessed,
pt->Entries[i].ExecuteDisable, pt->Entries[i].Address << 12,
pt->Entries[i]);
#elif defined(a32)
#elif defined(aa64)
#elif defined(__i386__)
#elif defined(__aarch64__)
#endif
}
}
@ -257,15 +257,15 @@ NIF void CreatePageTable(PageTable *pt)
if (PSESupport)
{
#if defined(a64)
#if defined(__amd64__)
CPU::x64::CR4 cr4 = CPU::x64::readcr4();
cr4.PSE = 1;
CPU::x64::writecr4(cr4);
#elif defined(a32)
#elif defined(__i386__)
CPU::x32::CR4 cr4 = CPU::x32::readcr4();
cr4.PSE = 1;
CPU::x32::writecr4(cr4);
#elif defined(aa64)
#elif defined(__aarch64__)
#endif
trace("PSE Support Enabled");
}
@ -289,7 +289,7 @@ NIF void CreatePageTable(PageTable *pt)
NIF void InitializeMemoryManagement()
{
#ifdef DEBUG
#ifndef a32
#ifndef __i386__
for (uint64_t i = 0; i < bInfo.Memory.Entries; i++)
{
uintptr_t Base = r_cst(uintptr_t, bInfo.Memory.Entry[i].BaseAddress);
@ -333,7 +333,7 @@ NIF void InitializeMemoryManagement()
End,
Type);
}
#endif // a32
#endif // __i386__
#endif // DEBUG
trace("Initializing Physical Memory Manager");
// KernelAllocator = Physical(); <- Already called in the constructor

View File

@ -9,9 +9,9 @@ namespace Memory
{
void PageTable::Update()
{
#if defined(a86)
#if defined(__amd64__) || defined(__i386__)
asmv("mov %0, %%cr3" ::"r"(this));
#elif defined(aa64)
#elif defined(__aarch64__)
asmv("msr ttbr0_el1, %0" ::"r"(this));
#endif
}
@ -24,7 +24,7 @@ namespace Memory
memcpy(NewTable, this, sizeof(PageTable));
debug("Forking page table %#lx to %#lx", this, NewTable);
#if defined(a64)
#if defined(__amd64__)
for (size_t i = 0; i < sizeof(Entries) / sizeof(Entries[0]); i++)
{
PageMapLevel4 *PML4 = &Entries[i];

View File

@ -22,7 +22,7 @@ namespace Memory
Virtual::PageMapIndexer::PageMapIndexer(uintptr_t VirtualAddress)
{
uintptr_t Address = VirtualAddress;
#if defined(a64)
#if defined(__amd64__)
Address >>= 12;
this->PTEIndex = Address & 0x1FF;
Address >>= 9;
@ -31,12 +31,12 @@ namespace Memory
this->PDPTEIndex = Address & 0x1FF;
Address >>= 9;
this->PMLIndex = Address & 0x1FF;
#elif defined(a32)
#elif defined(__i386__)
Address >>= 12;
this->PTEIndex = Address & 0x3FF;
Address >>= 10;
this->PDEIndex = Address & 0x3FF;
#elif defined(aa64)
#elif defined(__aarch64__)
#endif
if (VirtualAddress > PAGE_SIZE)
@ -44,7 +44,7 @@ namespace Memory
assert(
this->PTEIndex != 0 ||
this->PDEIndex != 0
#if defined(a64)
#if defined(__amd64__)
|| this->PDPTEIndex != 0 ||
this->PMLIndex != 0
#endif

View File

@ -90,10 +90,10 @@ namespace Memory
Elf_Sym *Symbols = nullptr;
uint8_t *StringAddress = nullptr;
#if defined(a64) || defined(aa64)
#if defined(__amd64__) || defined(__aarch64__)
Elf64_Xword SymbolSize = 0;
Elf64_Xword StringSize = 0;
#elif defined(a32)
#elif defined(__i386__)
Elf32_Word SymbolSize = 0;
Elf32_Word StringSize = 0;
#endif
@ -149,7 +149,7 @@ namespace Memory
TO_PAGES(bInfo.Modules[i].Size));
}
#if defined(a86)
#if defined(__amd64__) || defined(__i386__)
if (bInfo.RSDP)
{
debug("Reserving RSDT region %#lx-%#lx...", bInfo.RSDP,
@ -201,7 +201,7 @@ namespace Memory
this->ReservePages(SDTHdr, TO_PAGES(SDTHdr->Length));
}
}
#elif defined(aa64)
#elif defined(__aarch64__)
#endif
}
}

View File

@ -241,9 +241,9 @@ namespace Memory
pte->CopyOnWrite = false;
debug("PFA %#lx is CoW (pt %#lx, flags %#lx)",
PFA, this->Table, pte->raw);
#if defined(a64)
#if defined(__amd64__)
CPU::x64::invlpg((void *)PFA);
#elif defined(a32)
#elif defined(__i386__)
CPU::x32::invlpg((void *)PFA);
#endif
return true;
@ -303,7 +303,7 @@ namespace Memory
void *AddressToMap = (void *)((uintptr_t)ap.Address + (i * PAGE_SIZE));
void *RealAddress = (void *)((uintptr_t)Address + (i * PAGE_SIZE));
#if defined(a86)
#if defined(__amd64__) || defined(__i386__)
PageTableEntry *pte = vmm.GetPTE(AddressToMap);
uintptr_t Flags = 0;
Flags |= pte->Present ? (uintptr_t)PTFlag::P : 0;

View File

@ -28,13 +28,13 @@
#include <cpu.hpp>
#include <io.h>
#if defined(a64)
#if defined(__amd64__)
#include "../../arch/amd64/cpu/gdt.hpp"
#include "../arch/amd64/cpu/apic.hpp"
#elif defined(a32)
#elif defined(__i386__)
#include "../../arch/i386/cpu/gdt.hpp"
#include "../arch/i386/cpu/apic.hpp"
#elif defined(aa64)
#elif defined(__aarch64__)
#endif
#include "../../kernel.h"

View File

@ -28,13 +28,13 @@
#include <cpu.hpp>
#include <io.h>
#if defined(a64)
#if defined(__amd64__)
#include "../../arch/amd64/cpu/gdt.hpp"
#include "../arch/amd64/cpu/apic.hpp"
#elif defined(a32)
#elif defined(__i386__)
#include "../../arch/i386/cpu/gdt.hpp"
#include "../arch/i386/cpu/apic.hpp"
#elif defined(aa64)
#elif defined(__aarch64__)
#endif
#include "../../kernel.h"
@ -100,7 +100,7 @@ nsa void HaltAllCores()
if (SMP::CPUCores <= 1)
return;
#if defined(a86)
#if defined(__amd64__) || defined(__i386__)
if (Interrupts::apic[0] == nullptr)
return;
@ -131,7 +131,7 @@ nsa void HaltAllCores()
((APIC::APIC *)Interrupts::apic[i])->ICR(icr);
}
}
#elif defined(aa64)
#elif defined(__aarch64__)
#endif
}
@ -187,7 +187,7 @@ nsa __noreturn void HandleUnrecoverableException(CPU::ExceptionFrame *Frame)
ExPrint("\x1b[0m-----------------------------------------------\n");
ExPrint("\x1b[30;41mUnrecoverable exception %#lx on CPU %d\n",
Frame->InterruptNumber, core->ID);
#if defined(a86)
#if defined(__amd64__) || defined(__i386__)
ExPrint("CR0=%#lx CR2=%#lx CR3=%#lx CR4=%#lx CR8=%#lx\n",
Frame->cr0, Frame->cr2, Frame->cr3, Frame->cr4, Frame->cr8);
ExPrint("DR0=%#lx DR1=%#lx DR2=%#lx DR3=%#lx DR6=%#lx DR7=%#lx\n",
@ -195,29 +195,29 @@ nsa __noreturn void HandleUnrecoverableException(CPU::ExceptionFrame *Frame)
ExPrint("GS=%#lx FS=%#lx ES=%#lx DS=%#lx SS=%#lx CS=%#lx\n",
Frame->gs, Frame->fs, Frame->es, Frame->ds, Frame->ss, Frame->cs);
#endif
#if defined(a64)
#if defined(__amd64__)
ExPrint("R8=%#lx R9=%#lx R10=%#lx R11=%#lx R12=%#lx R13=%#lx R14=%#lx R15=%#lx\n",
Frame->r8, Frame->r9, Frame->r10, Frame->r11, Frame->r12, Frame->r13,
Frame->r14, Frame->r15);
#endif
#if defined(a86)
#if defined(__amd64__) || defined(__i386__)
ExPrint("AX=%#lx BX=%#lx CX=%#lx DX=%#lx SI=%#lx DI=%#lx BP=%#lx SP=%#lx\n",
#ifdef a64
#ifdef __amd64__
Frame->rax, Frame->rbx, Frame->rcx, Frame->rdx, Frame->rsi, Frame->rdi,
Frame->rbp, Frame->rsp);
#else
Frame->eax, Frame->ebx, Frame->ecx, Frame->edx, Frame->esi, Frame->edi,
Frame->ebp, Frame->esp);
#endif /* a64 */
#endif /* __amd64__ */
ExPrint("IP=%#lx FL=%#lx INT=%#lx ERR=%#lx\n",
#ifdef a64
#ifdef __amd64__
Frame->rip, Frame->rflags.raw,
#else
Frame->eip, Frame->eflags.raw,
#endif /* a64 */
#endif /* __amd64__ */
Frame->InterruptNumber, Frame->ErrorCode);
#endif /* a86 */
@ -233,14 +233,14 @@ nsa __noreturn void HandleExceptionInsideException(CPU::ExceptionFrame *Frame)
ExPrint("\x1b[0m-----------------------------------------------\n");
ExPrint("Exception inside exception: %#lx at %#lx\n",
Frame->InterruptNumber,
#if defined(a64)
#if defined(__amd64__)
Frame->rip);
#elif defined(a32)
#elif defined(__i386__)
Frame->eip);
#elif defined(aa64)
#elif defined(__aarch64__)
Frame->pc);
#endif
#if defined(a86)
#if defined(__amd64__) || defined(__i386__)
ExPrint("CR0=%#lx CR2=%#lx CR3=%#lx CR4=%#lx CR8=%#lx\n",
Frame->cr0, Frame->cr2, Frame->cr3, Frame->cr4, Frame->cr8);
ExPrint("DR0=%#lx DR1=%#lx DR2=%#lx DR3=%#lx DR6=%#lx DR7=%#lx\n",
@ -248,29 +248,29 @@ nsa __noreturn void HandleExceptionInsideException(CPU::ExceptionFrame *Frame)
ExPrint("GS=%#lx FS=%#lx ES=%#lx DS=%#lx SS=%#lx CS=%#lx\n",
Frame->gs, Frame->fs, Frame->es, Frame->ds, Frame->ss, Frame->cs);
#endif
#if defined(a64)
#if defined(__amd64__)
ExPrint("R8=%#lx R9=%#lx R10=%#lx R11=%#lx R12=%#lx R13=%#lx R14=%#lx R15=%#lx\n",
Frame->r8, Frame->r9, Frame->r10, Frame->r11, Frame->r12, Frame->r13,
Frame->r14, Frame->r15);
#endif
#if defined(a86)
#if defined(__amd64__) || defined(__i386__)
ExPrint("AX=%#lx BX=%#lx CX=%#lx DX=%#lx SI=%#lx DI=%#lx BP=%#lx SP=%#lx\n",
#ifdef a64
#ifdef __amd64__
Frame->rax, Frame->rbx, Frame->rcx, Frame->rdx, Frame->rsi, Frame->rdi,
Frame->rbp, Frame->rsp);
#else
Frame->eax, Frame->ebx, Frame->ecx, Frame->edx, Frame->esi, Frame->edi,
Frame->ebp, Frame->esp);
#endif /* a64 */
#endif /* __amd64__ */
ExPrint("IP=%#lx FL=%#lx INT=%#lx ERR=%#lx\n",
#ifdef a64
#ifdef __amd64__
Frame->rip, Frame->rflags.raw,
#else
Frame->eip, Frame->eflags.raw,
#endif /* a64 */
#endif /* __amd64__ */
Frame->InterruptNumber, Frame->ErrorCode);
#endif /* a86 */
Display->UpdateBuffer();

View File

@ -27,10 +27,10 @@
#include <cpu.hpp>
#include <io.h>
#if defined(a64)
#if defined(__amd64__)
#include "../../../arch/amd64/cpu/gdt.hpp"
#elif defined(a32)
#elif defined(aa64)
#elif defined(__i386__)
#elif defined(__aarch64__)
#endif
#include "../../../kernel.h"

View File

@ -31,10 +31,10 @@
#include <cpu.hpp>
#include <io.h>
#if defined(a64)
#if defined(__amd64__)
#include "../../../arch/amd64/cpu/gdt.hpp"
#elif defined(a32)
#elif defined(aa64)
#elif defined(__i386__)
#elif defined(__aarch64__)
#endif
#include "../../../kernel.h"

View File

@ -28,10 +28,10 @@
#include <cpu.hpp>
#include <io.h>
#if defined(a64)
#if defined(__amd64__)
#include "../../../arch/amd64/cpu/gdt.hpp"
#elif defined(a32)
#elif defined(aa64)
#elif defined(__i386__)
#elif defined(__aarch64__)
#endif
#include "../../../kernel.h"
@ -107,7 +107,7 @@ nsa static inline int GetLetterFromScanCode(uint8_t ScanCode)
nsa void CrashPS2KeyboardDriver::PS2Wait(bool Output)
{
#if defined(a86)
#if defined(__amd64__) || defined(__i386__)
TimeoutCallNumber++;
int timeout = 100000;
PS2_STATUSES status = {.Raw = inb(PS2_STATUS)};
@ -153,7 +153,7 @@ nsa CrashPS2KeyboardDriver::CrashPS2KeyboardDriver() : Interrupts::Handler(1) /*
/* Dots will be printed at the bottom of the screen as a progress bar. */
ExPrint("\x1b[%d;%dH", (Display->GetWidth / CrashFontRenderer.CurrentFont->GetInfo().Width) - 2, 0);
#if defined(a86)
#if defined(__amd64__) || defined(__i386__)
/* Disable port 1 & 2 */
{
@ -355,14 +355,14 @@ nsa CrashPS2KeyboardDriver::CrashPS2KeyboardDriver() : Interrupts::Handler(1) /*
ExPrint(".");
#endif // defined(a86)
#endif // defined(__amd64__) || defined(__i386__)
CPU::Interrupts(CPU::Enable);
}
nsa void CrashPS2KeyboardDriver::OnInterruptReceived(CPU::TrapFrame *)
{
#if defined(a86)
#if defined(__amd64__) || defined(__i386__)
uint8_t scanCode = inb(PS2_DATA);
if (scanCode == KEY_D_TAB ||
@ -412,5 +412,5 @@ nsa void CrashPS2KeyboardDriver::OnInterruptReceived(CPU::TrapFrame *)
}
Display->UpdateBuffer(); /* Update as we type. */
}
#endif // a64 || a32
#endif // __amd64__ || __i386__
}

View File

@ -27,10 +27,10 @@
#include <cpu.hpp>
#include <io.h>
#if defined(a64)
#if defined(__amd64__)
#include "../../../arch/amd64/cpu/gdt.hpp"
#elif defined(a32)
#elif defined(aa64)
#elif defined(__i386__)
#elif defined(__aarch64__)
#endif
#include "../../../kernel.h"

View File

@ -27,10 +27,10 @@
#include <cpu.hpp>
#include <io.h>
#if defined(a64)
#if defined(__amd64__)
#include "../../../arch/amd64/cpu/gdt.hpp"
#elif defined(a32)
#elif defined(aa64)
#elif defined(__i386__)
#elif defined(__aarch64__)
#endif
#include "../../../kernel.h"

View File

@ -27,13 +27,13 @@
#include <cpu.hpp>
#include <io.h>
#if defined(a64)
#if defined(__amd64__)
#include "../../arch/amd64/cpu/gdt.hpp"
#include "../arch/amd64/cpu/apic.hpp"
#elif defined(a32)
#elif defined(__i386__)
#include "../../arch/i386/cpu/gdt.hpp"
#include "../arch/i386/cpu/apic.hpp"
#elif defined(aa64)
#elif defined(__aarch64__)
#endif
#include "../../kernel.h"
@ -143,11 +143,11 @@ nsa const char *ExGetKSymbol(CPU::ExceptionFrame *Frame)
Frame->rip > (uintptr_t)&_kernel_end)
return "<OUTSIDE KERNEL>";
#if defined(a64)
#if defined(__amd64__)
return ExGetKSymbolByAddress(Frame->rip);
#elif defined(a32)
#elif defined(__i386__)
return ExGetKSymbolByAddress(Frame->eip);
#elif defined(aa64)
#elif defined(__aarch64__)
return ExGetKSymbolByAddress(Frame->pc);
#endif
}
@ -299,23 +299,23 @@ nsa void DisplayMainScreen(CPU::ExceptionFrame *Frame)
ExPrint("\nWe're sorry, but the system has encountered a critical error and needs to restart.\n");
ExPrint("\nError: %s (%s 0x%x)\n",
#if defined(a86)
#if defined(__amd64__) || defined(__i386__)
x86Exceptions[Frame->InterruptNumber].Name,
x86Exceptions[Frame->InterruptNumber].Mnemonic,
#elif defined(aa64)
#elif defined(__aarch64__)
#error "AA64 not implemented"
#endif
Frame->InterruptNumber);
#if defined(a86)
#if defined(__amd64__) || defined(__i386__)
ExPrint("Cause: %s\n", x86Exceptions[Frame->InterruptNumber].Cause);
#endif
ExPrint("Exception occurred in function %s (%#lx)\n",
ExGetKSymbol(Frame),
#if defined(a64)
#if defined(__amd64__)
Frame->rip);
#elif defined(a32)
#elif defined(__i386__)
Frame->eip);
#elif defined(aa64)
#elif defined(__aarch64__)
Frame->pc);
#endif
@ -431,9 +431,9 @@ nsa void DisplayStackScreen(CPU::ExceptionFrame *Frame)
{
Memory::Virtual vmm;
struct StackFrame *sf;
#if defined(a64)
#if defined(__amd64__)
sf = (struct StackFrame *)Frame->rbp;
#elif defined(a32)
#elif defined(__i386__)
sf = (struct StackFrame *)Frame->ebp;
#endif
@ -455,11 +455,11 @@ nsa void DisplayStackScreen(CPU::ExceptionFrame *Frame)
/* FIXME: Get symbol offset more efficiently */
uintptr_t fIP;
#if defined(a64)
#if defined(__amd64__)
fIP = Frame->rip;
#elif defined(a32)
#elif defined(__i386__)
fIP = Frame->eip;
#elif defined(aa64)
#elif defined(__aarch64__)
fIP = Frame->pc;
#endif

View File

@ -21,10 +21,10 @@
#include <smp.hpp>
#include <cpu.hpp>
#if defined(a64)
#if defined(__amd64__)
#include "../../arch/amd64/cpu/gdt.hpp"
#elif defined(a32)
#elif defined(aa64)
#elif defined(__i386__)
#elif defined(__aarch64__)
#endif
#include "../../kernel.h"
@ -32,26 +32,26 @@
#ifdef DEBUG
nsa void dbgPrint(CPU::ExceptionFrame *Frame)
{
#if defined(a64)
#if defined(__amd64__)
debug("FS=%#lx GS=%#lx SS=%#lx CS=%#lx DS=%#lx", Frame->fs, Frame->gs, Frame->ss, Frame->cs, Frame->ds);
debug("R8=%#lx R9=%#lx R10=%#lx R11=%#lx", Frame->r8, Frame->r9, Frame->r10, Frame->r11);
debug("R12=%#lx R13=%#lx R14=%#lx R15=%#lx", Frame->r12, Frame->r13, Frame->r14, Frame->r15);
debug("RAX=%#lx RBX=%#lx RCX=%#lx RDX=%#lx", Frame->rax, Frame->rbx, Frame->rcx, Frame->rdx);
debug("RSI=%#lx RDI=%#lx RBP=%#lx RSP=%#lx", Frame->rsi, Frame->rdi, Frame->rbp, Frame->rsp);
debug("RIP=%#lx RFL=%#lx INT=%#lx ERR=%#lx", Frame->rip, Frame->rflags.raw, Frame->InterruptNumber, Frame->ErrorCode);
#elif defined(a32)
#elif defined(__i386__)
debug("FS=%#x GS=%#x CS=%#x DS=%#x", Frame->fs, Frame->gs, Frame->cs, Frame->ds);
debug("EAX=%#x EBX=%#x ECX=%#x EDX=%#x", Frame->eax, Frame->ebx, Frame->ecx, Frame->edx);
debug("ESI=%#x EDI=%#x EBP=%#x ESP=%#x", Frame->esi, Frame->edi, Frame->ebp, Frame->esp);
debug("EIP=%#x EFL=%#x INT=%#x ERR=%#x", Frame->eip, Frame->eflags.raw, Frame->InterruptNumber, Frame->ErrorCode);
#elif defined(aa64)
#elif defined(__aarch64__)
#endif
#if defined(a86)
#if defined(__amd64__) || defined(__i386__)
debug("CR2=%#lx CR3=%#lx", Frame->cr2, Frame->cr3);
#endif // defined(a86)
#endif // defined(__amd64__) || defined(__i386__)
#if defined(a64)
#if defined(__amd64__)
debug("RFL: CF:%s PF:%s AF:%s ZF:%s SF:%s TF:%s IF:%s DF:%s OF:%s IOPL:%s NT:%s RF:%s VM:%s AC:%s VIF:%s VIP:%s ID:%s AlwaysOne:%d R0:%#x R1:%#x R2:%#x R3:%#x",
Frame->rflags.CF ? "True " : "False", Frame->rflags.PF ? "True " : "False", Frame->rflags.AF ? "True " : "False", Frame->rflags.ZF ? "True " : "False",
Frame->rflags.SF ? "True " : "False", Frame->rflags.TF ? "True " : "False", Frame->rflags.IF ? "True " : "False", Frame->rflags.DF ? "True " : "False",
@ -59,7 +59,7 @@ nsa void dbgPrint(CPU::ExceptionFrame *Frame)
Frame->rflags.VM ? "True " : "False", Frame->rflags.AC ? "True " : "False", Frame->rflags.VIF ? "True " : "False", Frame->rflags.VIP ? "True " : "False",
Frame->rflags.ID ? "True " : "False", Frame->rflags.AlwaysOne,
Frame->rflags.Reserved0, Frame->rflags.Reserved1, Frame->rflags.Reserved2, Frame->rflags.Reserved3);
#elif defined(a32)
#elif defined(__i386__)
debug("EFL: CF:%s PF:%s AF:%s ZF:%s SF:%s TF:%s IF:%s DF:%s OF:%s IOPL:%s NT:%s RF:%s VM:%s AC:%s VIF:%s VIP:%s ID:%s AlwaysOne:%d R0:%#x R1:%#x R2:%#x",
Frame->eflags.CF ? "True " : "False", Frame->eflags.PF ? "True " : "False", Frame->eflags.AF ? "True " : "False", Frame->eflags.ZF ? "True " : "False",
Frame->eflags.SF ? "True " : "False", Frame->eflags.TF ? "True " : "False", Frame->eflags.IF ? "True " : "False", Frame->eflags.DF ? "True " : "False",
@ -67,7 +67,7 @@ nsa void dbgPrint(CPU::ExceptionFrame *Frame)
Frame->eflags.VM ? "True " : "False", Frame->eflags.AC ? "True " : "False", Frame->eflags.VIF ? "True " : "False", Frame->eflags.VIP ? "True " : "False",
Frame->eflags.ID ? "True " : "False", Frame->eflags.AlwaysOne,
Frame->eflags.Reserved0, Frame->eflags.Reserved1, Frame->eflags.Reserved2);
#elif defined(aa64)
#elif defined(__aarch64__)
#endif
}
#endif

View File

@ -1100,7 +1100,7 @@ namespace PCI
Manager::Manager()
{
#if defined(a86)
#if defined(__amd64__) || defined(__i386__)
if (!PowerManager->GetACPI())
{
error("ACPI not found");
@ -1127,7 +1127,7 @@ namespace PCI
for (uint32_t Bus = NewDeviceConfig->StartBus; Bus < NewDeviceConfig->EndBus; Bus++)
EnumerateBus(NewDeviceConfig->BaseAddress, Bus, dev);
}
#elif defined(aa64)
#elif defined(__aarch64__)
error("PCI not implemented on aarch64");
#endif
}

View File

@ -63,7 +63,7 @@ namespace Random
uint16_t rand16()
{
#if defined(a86)
#if defined(__amd64__) || defined(__i386__)
if (RDRANDFlag)
{
uint16_t RDRANDValue = 0;
@ -80,7 +80,7 @@ namespace Random
uint32_t rand32()
{
#if defined(a86)
#if defined(__amd64__) || defined(__i386__)
if (RDRANDFlag)
{
uint32_t RDRANDValue = 0;
@ -97,7 +97,7 @@ namespace Random
uint64_t rand64()
{
#if defined(a86)
#if defined(__amd64__) || defined(__i386__)
if (RDRANDFlag)
{
uintptr_t RDRANDValue = 0;

View File

@ -60,13 +60,13 @@ EXTERNC __noreturn __no_stack_protector void __stack_chk_fail(void)
CPU::PageTable(KernelPageTable);
void *Stack = nullptr;
#if defined(a64)
#if defined(__amd64__)
asmv("movq %%rsp, %0"
: "=r"(Stack));
#elif defined(a32)
#elif defined(__i386__)
asmv("movl %%esp, %0"
: "=r"(Stack));
#elif defined(aa64)
#elif defined(__aarch64__)
asmv("mov %%sp, %0"
: "=r"(Stack));
#endif

View File

@ -101,10 +101,10 @@ namespace SymbolResolver
Elf_Sym *Symbols = nullptr;
uint8_t *StringAddress = nullptr;
#if defined(a64) || defined(aa64)
#if defined(__amd64__) || defined(__aarch64__)
Elf64_Xword SymbolSize = 0;
// Elf64_Xword StringSize = 0;
#elif defined(a32)
#elif defined(__i386__)
Elf32_Word SymbolSize = 0;
// Elf32_Word StringSize = 0;
#endif
@ -218,9 +218,9 @@ namespace SymbolResolver
}
debug("Solving symbols for address: %#llx", ImageAddress);
#if defined(a64) || defined(aa64)
#if defined(__amd64__) || defined(__aarch64__)
Elf64_Ehdr *Header = (Elf64_Ehdr *)ImageAddress;
#elif defined(a32)
#elif defined(__i386__)
Elf32_Ehdr *Header = (Elf32_Ehdr *)ImageAddress;
#endif
if (Header->e_ident[0] != 0x7F &&

View File

@ -28,12 +28,12 @@ namespace Time
{
bool HighPrecisionEventTimer::Sleep(size_t Duration, Units Unit)
{
#if defined(a64)
#if defined(__amd64__)
uint64_t Target = mminq(&hpet->MainCounterValue) + (Duration * ConvertUnit(Unit)) / clk;
while (mminq(&hpet->MainCounterValue) < Target)
CPU::Pause();
return true;
#elif defined(a32)
#elif defined(__i386__)
uint64_t Target = mminl(&hpet->MainCounterValue) + (Duration * ConvertUnit(Unit)) / clk;
while (mminl(&hpet->MainCounterValue) < Target)
CPU::Pause();
@ -44,25 +44,25 @@ namespace Time
uint64_t HighPrecisionEventTimer::GetCounter()
{
#if defined(a64)
#if defined(__amd64__)
return mminq(&hpet->MainCounterValue);
#elif defined(a32)
#elif defined(__i386__)
return mminl(&hpet->MainCounterValue);
#endif
}
uint64_t HighPrecisionEventTimer::CalculateTarget(uint64_t Target, Units Unit)
{
#if defined(a64)
#if defined(__amd64__)
return mminq(&hpet->MainCounterValue) + (Target * ConvertUnit(Unit)) / clk;
#elif defined(a32)
#elif defined(__i386__)
return mminl(&hpet->MainCounterValue) + (Target * ConvertUnit(Unit)) / clk;
#endif
}
uint64_t HighPrecisionEventTimer::GetNanosecondsSinceClassCreation()
{
#if defined(a86)
#if defined(__amd64__) || defined(__i386__)
uint64_t Subtraction = this->GetCounter() - this->ClassCreationTime;
if (Subtraction <= 0 || this->clk <= 0)
return 0;
@ -74,7 +74,7 @@ namespace Time
HighPrecisionEventTimer::HighPrecisionEventTimer(void *hpet)
{
#if defined(a86)
#if defined(__amd64__) || defined(__i386__)
ACPI::ACPI::HPETHeader *HPET_HDR = (ACPI::ACPI::HPETHeader *)hpet;
Memory::Virtual vmm;
vmm.Map((void *)HPET_HDR->Address.Address,
@ -86,7 +86,7 @@ namespace Time
(void *)HPET_HDR->Address.Address);
clk = s_cst(uint32_t, (uint64_t)this->hpet->GeneralCapabilities >> 32);
KPrint("HPET clock is %u Hz", clk);
#ifdef a64
#ifdef __amd64__
mmoutq(&this->hpet->GeneralConfiguration, 0);
mmoutq(&this->hpet->MainCounterValue, 0);
mmoutq(&this->hpet->GeneralConfiguration, 1);

View File

@ -24,7 +24,7 @@ namespace Time
Clock ReadClock()
{
Clock tm;
#if defined(a86)
#if defined(__amd64__) || defined(__i386__)
uint32_t t = 0;
outb(0x70, 0x00);
t = inb(0x71);
@ -45,7 +45,7 @@ namespace Time
t = inb(0x71);
tm.Year = ((t & 0x0F) + ((t >> 4) * 10));
tm.Counter = 0;
#elif defined(aa64)
#elif defined(__aarch64__)
tm.Year = 0;
tm.Month = 0;
tm.Day = 0;

View File

@ -145,7 +145,7 @@ namespace Time
void time::FindTimers(void *acpi)
{
#if defined(a86)
#if defined(__amd64__) || defined(__i386__)
/* TODO: RTC check */
/* TODO: PIT check */

View File

@ -28,7 +28,7 @@ namespace Time
{
bool TimeStampCounter::Sleep(size_t Duration, Units Unit)
{
#if defined(a86)
#if defined(__amd64__) || defined(__i386__)
uint64_t Target = this->GetCounter() + (Duration * ConvertUnit(Unit)) / this->clk;
while (this->GetCounter() < Target)
CPU::Pause();
@ -38,28 +38,28 @@ namespace Time
uint64_t TimeStampCounter::GetCounter()
{
#if defined(a86)
#if defined(__amd64__) || defined(__i386__)
return CPU::Counter();
#endif
}
uint64_t TimeStampCounter::CalculateTarget(uint64_t Target, Units Unit)
{
#if defined(a86)
#if defined(__amd64__) || defined(__i386__)
return uint64_t((this->GetCounter() + (Target * ConvertUnit(Unit))) / this->clk);
#endif
}
uint64_t TimeStampCounter::GetNanosecondsSinceClassCreation()
{
#if defined(a86)
#if defined(__amd64__) || defined(__i386__)
return uint64_t((this->GetCounter() - this->ClassCreationTime) / this->clk);
#endif
}
TimeStampCounter::TimeStampCounter()
{
#if defined(a86)
#if defined(__amd64__) || defined(__i386__)
stub; // FIXME: This is not a good way to measure the clock speed
uint64_t Start = CPU::Counter();
TimeManager->Sleep(1, Units::Milliseconds);

View File

@ -23,7 +23,7 @@
bool serialports[8] = {false, false, false, false, false, false, false, false};
std::vector<UniversalAsynchronousReceiverTransmitter::Events *> RegisteredEvents;
#if defined(a86)
#if defined(__amd64__) || defined(__i386__)
NIF __always_inline inline uint8_t NoProfiler_inportb(uint16_t Port)
{
uint8_t Result;
@ -56,7 +56,7 @@ namespace UniversalAsynchronousReceiverTransmitter
nsa NIF UART::UART(SerialPorts Port)
{
#if defined(a86)
#if defined(__amd64__) || defined(__i386__)
if (Port == COMNULL)
return;
@ -138,7 +138,7 @@ namespace UniversalAsynchronousReceiverTransmitter
{
if (!this->IsAvailable)
return;
#if defined(a86)
#if defined(__amd64__) || defined(__i386__)
while ((NoProfiler_inportb(s_cst(uint16_t, Port + 5)) & SERIAL_BUFFER_EMPTY) == 0)
;
NoProfiler_outportb(Port, Char);
@ -152,7 +152,7 @@ namespace UniversalAsynchronousReceiverTransmitter
{
if (!this->IsAvailable)
return 0;
#if defined(a86)
#if defined(__amd64__) || defined(__i386__)
while ((NoProfiler_inportb(s_cst(uint16_t, Port + 5)) & 1) == 0)
;
return NoProfiler_inportb(Port);
@ -161,7 +161,7 @@ namespace UniversalAsynchronousReceiverTransmitter
{
if (e->GetRegisteredPort() == Port || e->GetRegisteredPort() == COMNULL)
{
#if defined(a86)
#if defined(__amd64__) || defined(__i386__)
e->OnReceived(NoProfiler_inportb(Port));
#endif
}

View File

@ -47,7 +47,7 @@ namespace Execute
uint64_t EntryPoint,
uint64_t BaseAddress)
{
#if defined(a64)
#if defined(__amd64__)
char *aux_platform = (char *)vma->RequestPages(1, true); /* TODO: 4KiB is too much for this */
strcpy(aux_platform, "x86_64");
@ -101,7 +101,7 @@ namespace Execute
void ELFObject::LoadExec_x86_64(FileNode *fd, PCB *TargetProcess)
{
#if defined(a64)
#if defined(__amd64__)
std::vector<Elf64_Phdr> PhdrINTERP = ELFGetSymbolType_x86_64(fd, PT_INTERP);
foreach (auto Interp in PhdrINTERP)
{
@ -318,7 +318,7 @@ namespace Execute
void ELFObject::LoadDyn_x86_64(FileNode *fd, PCB *TargetProcess)
{
#if defined(a64)
#if defined(__amd64__)
std::vector<Elf64_Phdr> PhdrINTERP = ELFGetSymbolType_x86_64(fd, PT_INTERP);
foreach (auto Interp in PhdrINTERP)
{

View File

@ -94,7 +94,7 @@ namespace Execute
Elf64_Sym ELFLookupSymbol(FileNode *fd, std::string Name)
{
#if defined(a64)
#if defined(__amd64__)
Elf64_Ehdr Header{};
fd->Read(&Header, sizeof(Elf64_Ehdr), 0);
@ -145,7 +145,7 @@ namespace Execute
uintptr_t ELFGetSymbolValue(Elf64_Ehdr *Header, uint64_t Table, uint64_t Index)
{
#if defined(a64)
#if defined(__amd64__)
if (Table == SHN_UNDEF || Index == SHN_UNDEF)
return 0;
Elf64_Shdr *SymbolTable = GetELFSection(Header, Table);
@ -186,7 +186,7 @@ namespace Execute
Elf64_Shdr *Target = GetELFSection(Header, Symbol->st_shndx);
return (uintptr_t)Header + Symbol->st_value + Target->sh_offset;
}
#elif defined(a32)
#elif defined(__i386__)
return 0xdead;
#endif
}

View File

@ -29,7 +29,7 @@ namespace Execute
const char *Name,
Tasking::PCB *Process)
{
#if defined(a64)
#if defined(__amd64__)
UNUSED(Name);
debug("Relocatable");
/* TODO: I have to fully implement this, but for now I will leave it as it is now. */
@ -95,7 +95,7 @@ namespace Execute
}
}
}
#elif defined(a32)
#elif defined(__i386__)
#endif
}
}

View File

@ -24,7 +24,7 @@ namespace Execute
std::vector<Elf64_Dyn> ELFGetDynamicTag_x86_64(FileNode *fd,
DynamicArrayTags Tag)
{
#if defined(a64) || defined(aa64)
#if defined(__amd64__) || defined(__aarch64__)
std::vector<Elf64_Dyn> Ret;
Elf64_Ehdr ELFHeader{};
@ -55,7 +55,7 @@ namespace Execute
}
return Ret;
#elif defined(a32)
#elif defined(__i386__)
return {};
#endif
}

View File

@ -24,7 +24,7 @@ namespace Execute
std::vector<Elf64_Shdr> ELFGetSections_x86_64(FileNode *fd,
const char *SectionName)
{
#if defined(a64) || defined(aa64)
#if defined(__amd64__) || defined(__aarch64__)
std::vector<Elf64_Shdr> Ret;
Elf64_Ehdr ELFHeader{};
@ -46,7 +46,7 @@ namespace Execute
delete[] SectionHeaders;
delete[] SectionNames;
return Ret;
#elif defined(a32)
#elif defined(__i386__)
return {};
#endif
}

View File

@ -24,7 +24,7 @@ namespace Execute
std::vector<Elf64_Phdr> ELFGetSymbolType_x86_64(FileNode *fd,
SegmentTypes Tag)
{
#if defined(a64) || defined(aa64)
#if defined(__amd64__) || defined(__aarch64__)
std::vector<Elf64_Phdr> Ret;
Elf64_Ehdr ELFHeader{};
@ -44,7 +44,7 @@ namespace Execute
}
return Ret;
#elif defined(a32)
#elif defined(__i386__)
return {};
#endif
}

View File

@ -77,11 +77,11 @@ typedef struct
} a_un;
} Elf64_auxv_t;
#if defined(a64)
#if defined(__amd64__)
typedef Elf64_auxv_t Elf_auxv_t;
#elif defined(a32)
#elif defined(__i386__)
typedef Elf64_auxv_t Elf_auxv_t;
#elif defined(aa64)
#elif defined(__aarch64__)
typedef Elf64_auxv_t Elf_auxv_t;
#endif

View File

@ -143,9 +143,9 @@ namespace CPU
{
do
{
#if defined(a86)
#if defined(__amd64__) || defined(__i386__)
asmv("pause");
#elif defined(aa64)
#elif defined(__aarch64__)
asmv("yield");
#endif
} while (Loop);
@ -156,12 +156,12 @@ namespace CPU
*/
nsa __noreturn __used inline void Stop()
{
#if defined(a86)
#if defined(__amd64__) || defined(__i386__)
asmv("CPUStopLoop:\n"
"cli\n"
"hlt\n"
"jmp CPUStopLoop");
#elif defined(aa64)
#elif defined(__aarch64__)
asmv("CPUStopLoop:\n"
"cpsid i\n"
"wfe\n"
@ -178,9 +178,9 @@ namespace CPU
{
do
{
#if defined(a86)
#if defined(__amd64__) || defined(__i386__)
asmv("hlt");
#elif defined(aa64)
#elif defined(__aarch64__)
asmv("wfe");
#endif
} while (Loop);
@ -431,7 +431,7 @@ namespace CPU
*/
static inline void cpuid(uint32_t Function, uint32_t *eax, uint32_t *ebx, uint32_t *ecx, uint32_t *edx)
{
#ifdef a32
#ifdef __i386__
asmv("cpuid"
: "=a"(*eax), "=b"(*ebx), "=c"(*ecx), "=d"(*edx)
: "a"(Function));
@ -446,7 +446,7 @@ namespace CPU
nsa static inline void lgdt(void *gdt)
{
#ifdef a32
#ifdef __i386__
asmv("lgdt (%0)"
:
: "r"(gdt));
@ -457,7 +457,7 @@ namespace CPU
nsa static inline void lidt(void *idt)
{
#ifdef a32
#ifdef __i386__
asmv("lidt (%0)"
:
: "r"(idt));
@ -468,7 +468,7 @@ namespace CPU
nsa static inline void ltr(uint16_t Segment)
{
#ifdef a32
#ifdef __i386__
asmv("ltr %0"
:
: "r"(Segment));
@ -479,7 +479,7 @@ namespace CPU
nsa static inline void invlpg(void *Address)
{
#ifdef a32
#ifdef __i386__
asmv("invlpg (%0)"
:
: "r"(Address)
@ -491,7 +491,7 @@ namespace CPU
nsa static inline void fxsave(void *FXSaveArea)
{
#ifdef a32
#ifdef __i386__
if (!FXSaveArea)
return;
@ -506,7 +506,7 @@ namespace CPU
nsa static inline void fxrstor(void *FXRstorArea)
{
#ifdef a32
#ifdef __i386__
if (!FXRstorArea)
return;
@ -912,7 +912,7 @@ namespace CPU
nsa static inline void lgdt(void *gdt)
{
#ifdef a64
#ifdef __amd64__
asmv("lgdt (%0)"
:
: "r"(gdt));
@ -921,7 +921,7 @@ namespace CPU
nsa static inline void lidt(void *idt)
{
#ifdef a64
#ifdef __amd64__
asmv("lidt (%0)"
:
: "r"(idt));
@ -930,7 +930,7 @@ namespace CPU
nsa static inline void ltr(uint16_t Segment)
{
#ifdef a64
#ifdef __amd64__
asmv("ltr %0"
:
: "r"(Segment));
@ -939,7 +939,7 @@ namespace CPU
nsa static inline void invlpg(void *Address)
{
#ifdef a64
#ifdef __amd64__
asmv("invlpg (%0)"
:
: "r"(Address)
@ -958,7 +958,7 @@ namespace CPU
*/
nsa static inline void cpuid(uint32_t Function, uint32_t *eax, uint32_t *ebx, uint32_t *ecx, uint32_t *edx)
{
#ifdef a64
#ifdef __amd64__
asmv("cpuid"
: "=a"(*eax), "=b"(*ebx), "=c"(*ecx), "=d"(*edx)
: "a"(Function));
@ -981,7 +981,7 @@ namespace CPU
nsa static inline void fxsave(void *FXSaveArea)
{
#ifdef a64
#ifdef __amd64__
if (!FXSaveArea || FXSaveArea >= (char *)0xfffffffffffff000)
return;
@ -994,7 +994,7 @@ namespace CPU
nsa static inline void fxrstor(void *FXRstorArea)
{
#ifdef a64
#ifdef __amd64__
if (!FXRstorArea || FXRstorArea >= (char *)0xfffffffffffff000)
return;
@ -1051,7 +1051,7 @@ namespace CPU
};
}
#if defined(a64)
#if defined(__amd64__)
/**
* CPU trap frame for the current architecture
*
@ -1060,7 +1060,7 @@ namespace CPU
typedef x64::TrapFrame TrapFrame;
typedef x64::SchedulerFrame SchedulerFrame;
typedef x64::ExceptionFrame ExceptionFrame;
#elif defined(a32)
#elif defined(__i386__)
/**
* CPU trap frame for the current architecture
*
@ -1069,7 +1069,7 @@ namespace CPU
typedef x32::TrapFrame TrapFrame;
typedef x32::SchedulerFrame SchedulerFrame;
typedef x32::ExceptionFrame ExceptionFrame;
#elif defined(aa64)
#elif defined(__aarch64__)
/**
* CPU trap frame for the current architecture
*

View File

@ -26,10 +26,10 @@ namespace CPU
{
nsa static inline void Barrier()
{
#if defined(a86)
#if defined(__amd64__) || defined(__i386__)
asmv("" ::
: "memory");
#elif defined(aa64)
#elif defined(__aarch64__)
asmv("dmb ish" ::
: "memory");
#endif
@ -37,10 +37,10 @@ namespace CPU
nsa static inline void Fence()
{
#if defined(a86)
#if defined(__amd64__) || defined(__i386__)
asmv("mfence" ::
: "memory");
#elif defined(aa64)
#elif defined(__aarch64__)
asmv("dmb ish" ::
: "memory");
#endif
@ -48,10 +48,10 @@ namespace CPU
nsa static inline void StoreFence()
{
#if defined(a86)
#if defined(__amd64__) || defined(__i386__)
asmv("sfence" ::
: "memory");
#elif defined(aa64)
#elif defined(__aarch64__)
asmv("dmb ishst" ::
: "memory");
#endif
@ -59,10 +59,10 @@ namespace CPU
nsa static inline void LoadFence()
{
#if defined(a86)
#if defined(__amd64__) || defined(__i386__)
asmv("lfence" ::
: "memory");
#elif defined(aa64)
#elif defined(__aarch64__)
asmv("dmb ishld" ::
: "memory");
#endif

View File

@ -21,15 +21,15 @@
#include <types.h>
#include <debug.h>
#if defined(a64)
#if defined(__amd64__)
typedef uint64_t cpuid_t;
#elif defined(a32)
#elif defined(__i386__)
typedef uint32_t cpuid_t;
#else
typedef uint64_t cpuid_t;
#endif // a64 || a32
#endif // __amd64__ || __i386__
#if defined(a86)
#if defined(__amd64__) || defined(__i386__)
#define __amd_cpuid_init(leaf) \
CPUID##leaf() \
{ \

View File

@ -21,15 +21,15 @@
#include <types.h>
#include <debug.h>
#if defined(a64)
#if defined(__amd64__)
typedef uint64_t cpuid_t;
#elif defined(a32)
#elif defined(__i386__)
typedef uint32_t cpuid_t;
#else
typedef uint64_t cpuid_t;
#endif // a64 || a32
#endif // __amd64__ || __i386__
#if defined(a86)
#if defined(__amd64__) || defined(__i386__)
#define __intel_cpuid_init(leaf) \
CPUID##leaf() \
{ \

View File

@ -141,7 +141,7 @@ namespace CPU
};
uint32_t raw;
} CR4;
#if defined(a32)
#if defined(__i386__)
nsa static inline CR0 readcr0()
{
uint32_t Result = 0;

View File

@ -400,7 +400,7 @@ namespace CPU
MSR_CR_PAT = 0x00000277,
};
#if defined(a32)
#if defined(__i386__)
nsa static inline uint64_t rdmsr(uint32_t msr)
{
uint32_t Low, High;

View File

@ -191,7 +191,7 @@ namespace CPU
uint64_t raw;
} XCR0;
#if defined(a64)
#if defined(__amd64__)
nsa static inline CR0 readcr0()
{
uint64_t Result = 0;

View File

@ -401,7 +401,7 @@ namespace CPU
MSR_CR_PAT_RESET = 0x0007040600070406ULL
};
#if defined(a64)
#if defined(__amd64__)
nsa static inline uint64_t rdmsr(uint32_t msr)
{
uint32_t Low, High;

View File

@ -946,7 +946,7 @@ typedef struct
char pr_psargs[ELF_PRARGSZ];
} Elf64_Prpsinfo;
#if defined(a64) || defined(aa64)
#if defined(__amd64__) || defined(__aarch64__)
typedef Elf64_Addr Elf_Addr;
typedef Elf64_Half Elf_Half;
typedef Elf64_Off Elf_Off;
@ -960,7 +960,7 @@ typedef Elf64_Rel Elf_Rel;
typedef Elf64_Sym Elf_Sym;
typedef Elf64_Dyn Elf_Dyn;
typedef Elf64_Rela Elf_Rela;
#elif defined(a32)
#elif defined(__i386__)
typedef Elf32_Addr Elf_Addr;
typedef Elf32_Half Elf_Half;
typedef Elf32_Off Elf_Off;

View File

@ -25,21 +25,21 @@ namespace FXSR
{
void _fxsave(void *mem_addr)
{
#ifdef a64
#ifdef __amd64__
__builtin_ia32_fxsave(mem_addr);
#endif
}
void _fxrstor(void *mem_addr)
{
#ifdef a64
#ifdef __amd64__
__builtin_ia32_fxrstor(mem_addr);
#endif
}
void _fxsave64(void *mem_addr)
{
#ifdef a64
#ifdef __amd64__
asmv("fxsaveq (%0)"
:
: "r"(mem_addr)
@ -49,7 +49,7 @@ namespace FXSR
void _fxrstor64(void *mem_addr)
{
#ifdef a64
#ifdef __amd64__
asmv("fxrstorq (%0)"
:
: "r"(mem_addr)
@ -62,18 +62,18 @@ namespace SMAP
{
void _clac(void)
{
#if defined(a86)
#if defined(__amd64__) || defined(__i386__)
asmv("clac" ::
: "cc");
#endif // a64 || a32
#endif // __amd64__ || __i386__
}
void _stac(void)
{
#if defined(a86)
#if defined(__amd64__) || defined(__i386__)
asmv("stac" ::
: "cc");
#endif // a64 || a32
#endif // __amd64__ || __i386__
}
}

View File

@ -30,13 +30,13 @@ namespace Interrupts
#define INT_FRAMES_MAX 8
#endif
#if defined(a64)
#if defined(__amd64__)
/* APIC::APIC */ extern void *apic[255]; // MAX_CPU
/* APIC::Timer */ extern void *apicTimer[255]; // MAX_CPU
#elif defined(a32)
#elif defined(__i386__)
/* APIC::APIC */ extern void *apic[255]; // MAX_CPU
/* APIC::Timer */ extern void *apicTimer[255]; // MAX_CPU
#elif defined(aa64)
#elif defined(__aarch64__)
#endif
void Initialize(int Core);

View File

@ -20,7 +20,7 @@
#include <types.h>
#if defined(a86)
#if defined(__amd64__) || defined(__i386__)
#ifdef __cplusplus
extern "C"
@ -98,7 +98,7 @@ extern "C"
: "memory");
}
#if defined(a64)
#if defined(__amd64__)
static inline void mmoutq(void *Address, uint64_t Value)
{
asmv("mov %1, %0"
@ -138,7 +138,7 @@ extern "C"
return Result;
}
#if defined(a64)
#if defined(__amd64__)
static inline uint64_t mminq(void *Address)
{
uint64_t Result;
@ -154,5 +154,5 @@ extern "C"
}
#endif
#endif // defined(a86)
#endif // defined(__amd64__) || defined(__i386__)
#endif // !__FENNIX_KERNEL_IO_H__

View File

@ -48,7 +48,7 @@
/* From pages */
#define FROM_PAGES(d) ((d) * PAGE_SIZE)
#if defined(a64) || defined(aa64)
#if defined(__amd64__) || defined(__aarch64__)
#define KERNEL_VMA_OFFSET 0xFFFFFFFF80000000
#define USER_ALLOC_BASE 0xFFFFA00000000000 /* 256 GiB */
@ -59,7 +59,7 @@
#define USER_STACK_END 0xFFFFEFFF00000000 /* 256 MiB */
#define USER_STACK_BASE 0xFFFFEFFFFFFF0000
#elif defined(a32)
#elif defined(__i386__)
#define KERNEL_VMA_OFFSET 0xC0000000
#define USER_ALLOC_BASE 0x80000000

View File

@ -108,7 +108,7 @@ namespace Memory
{
struct
{
#if defined(a64)
#if defined(__amd64__)
uintptr_t Present : 1; // 0
uintptr_t ReadWrite : 1; // 1
uintptr_t UserSupervisor : 1; // 2
@ -131,7 +131,7 @@ namespace Memory
uintptr_t Available9 : 1; // 58
uintptr_t ProtectionKey : 4; // 59-62
uintptr_t ExecuteDisable : 1; // 63
#elif defined(a32)
#elif defined(__i386__)
uintptr_t Present : 1; // 0
uintptr_t ReadWrite : 1; // 1
uintptr_t UserSupervisor : 1; // 2
@ -145,7 +145,7 @@ namespace Memory
uintptr_t KernelReserve : 1; // 10
uintptr_t Available2 : 1; // 11
uintptr_t Address : 20; // 12-31
#elif defined(aa64)
#elif defined(__aarch64__)
#endif
};
uintptr_t raw = 0;
@ -153,15 +153,15 @@ namespace Memory
/** @brief Set Address */
void SetAddress(uintptr_t _Address)
{
#if defined(a64)
#if defined(__amd64__)
_Address &= 0x000000FFFFFFFFFF;
this->raw &= 0xFFF0000000000FFF;
this->raw |= (_Address << 12);
#elif defined(a32)
#elif defined(__i386__)
_Address &= 0x000FFFFF;
this->raw &= 0xFFC00003;
this->raw |= (_Address << 12);
#elif defined(aa64)
#elif defined(__aarch64__)
_Address &= 0x000000FFFFFFFFFF;
this->raw &= 0xFFF0000000000FFF;
this->raw |= (_Address << 12);
@ -171,11 +171,11 @@ namespace Memory
/** @brief Get Address */
uintptr_t GetAddress()
{
#if defined(a64)
#if defined(__amd64__)
return (this->raw & 0x000FFFFFFFFFF000) >> 12;
#elif defined(a32)
#elif defined(__i386__)
return ((uintptr_t)(this->raw & 0x003FFFFF000) >> 12);
#elif defined(aa64)
#elif defined(__aarch64__)
return (this->raw & 0x000FFFFFFFFFF000) >> 12;
#endif
}
@ -183,17 +183,17 @@ namespace Memory
struct __packed PageTableEntryPtr
{
#if defined(a64)
#if defined(__amd64__)
PageTableEntry Entries[512];
#elif defined(a32)
#elif defined(__i386__)
PageTableEntry Entries[1024];
#elif defined(aa64)
#elif defined(__aarch64__)
#endif
};
union __packed PageDirectoryEntry
{
#if defined(a64)
#if defined(__amd64__)
struct
{
uintptr_t Present : 1; // 0
@ -250,7 +250,7 @@ namespace Memory
uintptr_t ProtectionKey : 4; // 59-62
uintptr_t ExecuteDisable : 1; // 63
} TwoMiB;
#elif defined(a32)
#elif defined(__i386__)
struct
{
uintptr_t Present : 1; // 0
@ -287,22 +287,22 @@ namespace Memory
uintptr_t Reserved0 : 1; // 21
uintptr_t Address1 : 10; // 22-31
} FourMiB;
#elif defined(aa64)
#elif defined(__aarch64__)
#endif
uintptr_t raw = 0;
/** @brief Set PageTableEntryPtr address */
void SetAddress(uintptr_t _Address)
{
#if defined(a64)
#if defined(__amd64__)
_Address &= 0x000000FFFFFFFFFF;
this->raw &= 0xFFF0000000000FFF;
this->raw |= (_Address << 12);
#elif defined(a32)
#elif defined(__i386__)
_Address &= 0x000FFFFF;
this->raw &= 0xFFC00003;
this->raw |= (_Address << 12);
#elif defined(aa64)
#elif defined(__aarch64__)
_Address &= 0x000000FFFFFFFFFF;
this->raw &= 0xFFF0000000000FFF;
this->raw |= (_Address << 12);
@ -312,11 +312,11 @@ namespace Memory
/** @brief Get PageTableEntryPtr address */
uintptr_t GetAddress()
{
#if defined(a64)
#if defined(__amd64__)
return (this->raw & 0x000FFFFFFFFFF000) >> 12;
#elif defined(a32)
#elif defined(__i386__)
return ((uintptr_t)(this->raw & 0x003FFFFF000) >> 12);
#elif defined(aa64)
#elif defined(__aarch64__)
return (this->raw & 0x000FFFFFFFFFF000) >> 12;
#endif
}
@ -329,7 +329,7 @@ namespace Memory
union __packed PageDirectoryPointerTableEntry
{
#if defined(a64)
#if defined(__amd64__)
struct
{
uintptr_t Present : 1; // 0
@ -386,18 +386,18 @@ namespace Memory
uintptr_t ProtectionKey : 4; // 59-62
uintptr_t ExecuteDisable : 1; // 63
} OneGiB;
#elif defined(aa64)
#elif defined(__aarch64__)
#endif
uintptr_t raw = 0;
/** @brief Set PageDirectoryEntryPtr address */
void SetAddress(uintptr_t _Address)
{
#if defined(a64)
#if defined(__amd64__)
_Address &= 0x000000FFFFFFFFFF;
this->raw &= 0xFFF0000000000FFF;
this->raw |= (_Address << 12);
#elif defined(aa64)
#elif defined(__aarch64__)
_Address &= 0x000000FFFFFFFFFF;
this->raw &= 0xFFF0000000000FFF;
this->raw |= (_Address << 12);
@ -407,11 +407,11 @@ namespace Memory
/** @brief Get PageDirectoryEntryPtr address */
uintptr_t GetAddress()
{
#if defined(a64)
#if defined(__amd64__)
return (this->raw & 0x000FFFFFFFFFF000) >> 12;
#elif defined(a32)
#elif defined(__i386__)
return 0;
#elif defined(aa64)
#elif defined(__aarch64__)
return (this->raw & 0x000FFFFFFFFFF000) >> 12;
#endif
}
@ -424,7 +424,7 @@ namespace Memory
union __packed PageMapLevel4
{
#if defined(a64)
#if defined(__amd64__)
struct
{
uintptr_t Present : 1; // 0
@ -453,18 +453,18 @@ namespace Memory
uintptr_t Available15 : 1; // 62
uintptr_t ExecuteDisable : 1; // 63
};
#elif defined(aa64)
#elif defined(__aarch64__)
#endif
uintptr_t raw = 0;
/** @brief Set PageDirectoryPointerTableEntryPtr address */
void SetAddress(uintptr_t _Address)
{
#if defined(a64)
#if defined(__amd64__)
_Address &= 0x000000FFFFFFFFFF;
this->raw &= 0xFFF0000000000FFF;
this->raw |= (_Address << 12);
#elif defined(aa64)
#elif defined(__aarch64__)
_Address &= 0x000000FFFFFFFFFF;
this->raw &= 0xFFF0000000000FFF;
this->raw |= (_Address << 12);
@ -474,11 +474,11 @@ namespace Memory
/** @brief Get PageDirectoryPointerTableEntryPtr address */
uintptr_t GetAddress()
{
#if defined(a64)
#if defined(__amd64__)
return (this->raw & 0x000FFFFFFFFFF000) >> 12;
#elif defined(a32)
#elif defined(__i386__)
return 0;
#elif defined(aa64)
#elif defined(__aarch64__)
return (this->raw & 0x000FFFFFFFFFF000) >> 12;
#endif
}
@ -491,7 +491,7 @@ namespace Memory
union __packed PageMapLevel5
{
#if defined(a64)
#if defined(__amd64__)
struct
{
uintptr_t Present : 1; // 0
@ -520,18 +520,18 @@ namespace Memory
uintptr_t Available14 : 1; // 62
uintptr_t ExecuteDisable : 1; // 63
};
#elif defined(aa64)
#elif defined(__aarch64__)
#endif
uintptr_t raw = 0;
/** @brief Set PageMapLevel4Ptr address */
void SetAddress(uintptr_t _Address)
{
#if defined(a64)
#if defined(__amd64__)
_Address &= 0x000000FFFFFFFFFF;
this->raw &= 0xFFF0000000000FFF;
this->raw |= (_Address << 12);
#elif defined(aa64)
#elif defined(__aarch64__)
_Address &= 0x000000FFFFFFFFFF;
this->raw &= 0xFFF0000000000FFF;
this->raw |= (_Address << 12);
@ -541,11 +541,11 @@ namespace Memory
/** @brief Get PageMapLevel4Ptr address */
uintptr_t GetAddress()
{
#if defined(a64)
#if defined(__amd64__)
return (this->raw & 0x000FFFFFFFFFF000) >> 12;
#elif defined(a32)
#elif defined(__i386__)
return 0;
#elif defined(aa64)
#elif defined(__aarch64__)
return (this->raw & 0x000FFFFFFFFFF000) >> 12;
#endif
}
@ -554,11 +554,11 @@ namespace Memory
class PageTable
{
public:
#if defined(a64)
#if defined(__amd64__)
PageMapLevel4 Entries[512];
#elif defined(a32)
#elif defined(__i386__)
PageDirectoryEntry Entries[1024];
#elif defined(aa64)
#elif defined(__aarch64__)
#endif
/**

View File

@ -45,7 +45,7 @@ namespace Memory
class PageMapIndexer
{
public:
#if defined(a64)
#if defined(__amd64__)
uintptr_t PMLIndex = 0;
uintptr_t PDPTEIndex = 0;
#endif
@ -100,11 +100,11 @@ namespace Memory
*/
MapType GetMapType(void *VirtualAddress);
#ifdef a64
#ifdef __amd64__
PageMapLevel5 *GetPML5(void *VirtualAddress, MapType Type = MapType::FourKiB);
PageMapLevel4 *GetPML4(void *VirtualAddress, MapType Type = MapType::FourKiB);
PageDirectoryPointerTableEntry *GetPDPTE(void *VirtualAddress, MapType Type = MapType::FourKiB);
#endif /* a64 */
#endif /* __amd64__ */
PageDirectoryEntry *GetPDE(void *VirtualAddress, MapType Type = MapType::FourKiB);
PageTableEntry *GetPTE(void *VirtualAddress, MapType Type = MapType::FourKiB);

View File

@ -310,7 +310,7 @@ namespace Tasking
struct StackInfo
{
#ifdef a64
#ifdef __amd64__
CPU::x64::FXState fx;
CPU::x64::SchedulerFrame tf;
uintptr_t GSBase, FSBase, ShadowGSBase;

View File

@ -29,11 +29,11 @@
struct CPUArchData
{
#if defined(a64)
#if defined(__amd64__)
__aligned(16) CPU::x64::FXState FPU{};
#elif defined(a32)
#elif defined(__i386__)
__aligned(16) CPU::x32::FXState FPU{};
#elif defined(aa64)
#elif defined(__aarch64__)
#endif
};

View File

@ -22,7 +22,7 @@
typedef struct SyscallsFrame
{
#if defined(a64)
#if defined(__amd64__)
uint64_t r15;
uint64_t r14;
uint64_t r13;
@ -44,7 +44,7 @@ typedef struct SyscallsFrame
uint64_t Flags;
uint64_t StackPointer;
uint64_t StackSegment;
#elif defined(a32)
#elif defined(__i386__)
uint32_t ebp;
uint32_t edi;
uint32_t esi;
@ -58,7 +58,7 @@ typedef struct SyscallsFrame
uint32_t Flags;
uint32_t StackPointer;
uint32_t StackSegment;
#elif defined(aa64)
#elif defined(__aarch64__)
uint32_t ReturnAddress;
uint32_t StackPointer;
#endif

View File

@ -355,13 +355,13 @@ namespace Tasking
ThreadSignal Signals;
/* CPU state */
#if defined(a64)
#if defined(__amd64__)
CPU::x64::SchedulerFrame Registers{};
uintptr_t ShadowGSBase, GSBase, FSBase;
#elif defined(a32)
#elif defined(__i386__)
CPU::x32::SchedulerFrame Registers{};
uintptr_t ShadowGSBase, GSBase, FSBase;
#elif defined(aa64)
#elif defined(__aarch64__)
uintptr_t Registers; // TODO
#endif
__aligned(16) CPU::x64::FXState FPU;
@ -549,11 +549,11 @@ namespace Tasking
constexpr TaskArchitecture GetKArch()
{
#if defined(a64)
#if defined(__amd64__)
return x64;
#elif defined(a32)
#elif defined(__i386__)
return x32;
#elif defined(aa64)
#elif defined(__aarch64__)
return ARM64;
#endif
}

View File

@ -147,7 +147,7 @@ typedef __SIG_ATOMIC_TYPE__ sig_atomic_t;
// TODO: ssize_t
typedef intptr_t ssize_t;
#if defined(a64) || defined(aa64)
#if defined(__amd64__) || defined(__aarch64__)
typedef int64_t off_t;
typedef int64_t off64_t;
typedef uint32_t mode_t;
@ -163,7 +163,7 @@ typedef uint32_t uid_t;
typedef uint32_t gid_t;
typedef int64_t clock_t;
typedef int32_t pid_t;
#elif defined(a32)
#elif defined(__i386__)
typedef int32_t off_t;
typedef long long off64_t;
typedef __INT32_TYPE__ mode_t;
@ -303,17 +303,17 @@ public:
#define WINT_MAX __WINT_MAX__
#define WINT_MIN __WINT_MIN__
#if defined(a64)
#if defined(__amd64__)
#define BREAK __asm__ __volatile__("int $0x3" \
: \
: \
: "memory");
#elif defined(a32)
#elif defined(__i386__)
#define BREAK __asm__ __volatile__("int $0x3" \
: \
: \
: "memory");
#elif defined(aa64)
#elif defined(__aarch64__)
#define BREAK __asm__ __volatile__("brk #0" \
: \
: \

View File

@ -19,11 +19,11 @@
/* Stubs */
#define FLT_RADIX 2
#if a64
#if __amd64__
#define DBL_MANT_DIG 53
#define DBL_MAX_10_EXP 308
#define DBL_MAX 1.7976931348623157e+308
#elif a32
#elif __i386__
#define DBL_MANT_DIG 24
#define DBL_MAX_10_EXP 38
#define DBL_MAX 3.4028234663852886e+38

View File

@ -37,11 +37,11 @@ namespace std
{
size_t operator()(const Key &key) const
{
#if defined(a64)
#if defined(__amd64__)
static_assert(sizeof(uintptr_t) == sizeof(uint64_t));
const uint64_t FNV_OFFSET_BASIS = 14695981039346656037ull;
const uint64_t FNV_PRIME = 1099511628211ull;
#elif defined(a32)
#elif defined(__i386__)
static_assert(sizeof(uintptr_t) == sizeof(uint32_t));
const uint32_t FNV_OFFSET_BASIS = 2166136261u;
const uint32_t FNV_PRIME = 16777619u;

View File

@ -79,13 +79,13 @@ EXTERNC void _KPrint(const char *Format, va_list Args)
uint64_t Nanoseconds = TimeManager->GetNanosecondsSinceClassCreation();
if (Nanoseconds != 0)
{
#if defined(a64)
#if defined(__amd64__)
printf("\x1b[1;30m[\x1b[1;34m%lu.%07lu\x1b[1;30m]\x1b[0m ",
Nanoseconds / 10000000, Nanoseconds % 10000000);
#elif defined(a32)
#elif defined(__i386__)
printf("\x1b[1;30m[\x1b[1;34m%llu.%07llu\x1b[1;30m]\x1b[0m ",
Nanoseconds / 10000000, Nanoseconds % 10000000);
#elif defined(aa64)
#elif defined(__aarch64__)
printf("\x1b[1;30m[\x1b[1;34m%lu.%07lu\x1b[1;30m]\x1b[0m ",
Nanoseconds / 10000000, Nanoseconds % 10000000);
#endif
@ -143,7 +143,7 @@ EXTERNC NIF void Main()
if (DebuggerIsAttached)
KPrint("Kernel debugger detected.");
#if defined(a86) && defined(DEBUG)
#if defined(__amd64__) || defined(__i386__) && defined(DEBUG)
uint8_t lpt1 = inb(0x378);
uint8_t lpt2 = inb(0x278);
uint8_t lpt3 = inb(0x3BC);
@ -218,9 +218,9 @@ EXTERNC NIF void Main()
KPrint("Enabling Interrupts on Bootstrap Processor");
Interrupts::Enable(0);
#if defined(a86)
#if defined(__amd64__) || defined(__i386__)
PowerManager->InitDSDT();
#elif defined(aa64)
#elif defined(__aarch64__)
#endif
KPrint("Initializing Timers");
@ -268,7 +268,7 @@ EXTERNC __no_stack_protector NIF void Entry(BootInfo *Info)
for (CallPtr *fct = __init_array_start; fct != __init_array_end; fct++)
(*fct)();
#ifdef a86
#if defined(__amd64__) || defined(__i386__)
if (!bInfo.SMBIOSPtr)
{
trace("SMBIOS was not provided by the bootloader. Trying to find it manually.");
@ -327,19 +327,19 @@ EXTERNC __no_stack_protector NIF void Entry(BootInfo *Info)
// void *KernelStackAddress = StackManager.Allocate(STACK_SIZE); /* FIXME: This breaks stl tests, how? */
uintptr_t KernelStack = (uintptr_t)KernelStackAddress + STACK_SIZE - 0x10;
debug("Kernel stack: %#lx-%#lx", KernelStackAddress, KernelStack);
#if defined(a64)
#if defined(__amd64__)
asmv("mov %0, %%rsp"
:
: "r"(KernelStack)
: "memory");
asmv("mov $0, %rbp");
#elif defined(a32)
#elif defined(__i386__)
asmv("mov %0, %%esp"
:
: "r"(KernelStack)
: "memory");
asmv("mov $0, %ebp");
#elif defined(aa64)
#elif defined(__aarch64__)
#warning "Kernel stack is not set!"
#endif

View File

@ -45,12 +45,12 @@ void cmd_top(const char *)
printf("PID Name State Priority Memory Usage CPU Usage\n");
foreach (auto Proc in TaskManager->GetProcessList())
{
#if defined(a64)
#if defined(__amd64__)
printf("%-4d %-20s %s %d %ld KiB %ld\n",
Proc->ID, Proc->Name, TaskStateStrings[Proc->State.load()],
Proc->Info.Priority, TO_KiB(Proc->GetSize()),
Proc->Info.UserTime + Proc->Info.KernelTime);
#elif defined(a32)
#elif defined(__i386__)
printf("%-4d %-20s %s %d %lld KiB %lld\n",
Proc->ID, Proc->Name, TaskStateStrings[Proc->State.load()],
Proc->Info.Priority, TO_KiB(Proc->GetSize()),
@ -59,12 +59,12 @@ void cmd_top(const char *)
foreach (auto Thrd in Proc->Threads)
{
#if defined(a64)
#if defined(__amd64__)
printf(" %-4d %-20s %s %d %ld KiB %ld\n",
Thrd->ID, Thrd->Name, TaskStateStrings[Thrd->State.load()],
Thrd->Info.Priority, TO_KiB(Thrd->GetSize()),
Thrd->Info.UserTime + Thrd->Info.KernelTime);
#elif defined(a32)
#elif defined(__i386__)
printf(" %-4d %-20s %s %d %lld KiB %lld\n",
Thrd->ID, Thrd->Name, TaskStateStrings[Thrd->State.load()],
Thrd->Info.Priority, TO_KiB(Thrd->GetSize()),

View File

@ -40,11 +40,11 @@ void cmd_uptime(const char *)
Minutes %= 60;
Hours %= 24;
#if defined(a64)
#if defined(__amd64__)
printf("%ld days, %ld hours, %ld minutes, %ld %s\n",
Days, Hours, Minutes, Seconds,
Seconds == 1 ? "second" : "seconds");
#elif defined(a32)
#elif defined(__i386__)
printf("%lld days, %lld hours, %lld minutes, %lld %s\n",
Days, Hours, Minutes, Seconds,
Seconds == 1 ? "second" : "seconds");

View File

@ -803,7 +803,7 @@ EXTERNC void __chk_fail(void) __noreturn;
__noreturn __always_inline static inline void __convert_chk_fail(void)
{
#if defined(a86)
#if defined(__amd64__) || defined(__i386__)
asmv("int3");
#else
#warning "Not implemented!"

View File

@ -134,7 +134,7 @@ void md5Finalize(MD5Context *ctx)
(uint32_t)(ctx->input[(j * 4)]);
}
input[14] = (uint32_t)(ctx->size * 8);
#ifdef a32
#ifdef __i386__
input[15] = (uint32_t)((uint64_t)(((uint64_t)ctx->size >> 32) | ((uint64_t)ctx->size << 32)) >> 32);
#else
input[15] = (uint32_t)((ctx->size * 8) >> 32);

View File

@ -29,7 +29,7 @@ TODO: Replace these functions with even more optimized versions.
EXTERNC void *memcpy_sse(void *dest, const void *src, size_t n)
{
#if defined(a64)
#if defined(__amd64__)
char *d = (char *)dest;
const char *s = (const char *)src;
@ -65,13 +65,13 @@ EXTERNC void *memcpy_sse(void *dest, const void *src, size_t n)
}
memcpy_unsafe(d, s, n);
#endif // defined(a64)
#endif // defined(__amd64__)
return dest;
}
EXTERNC void *memcpy_sse2(void *dest, const void *src, size_t n)
{
#if defined(a64)
#if defined(__amd64__)
char *d = (char *)dest;
const char *s = (const char *)src;
@ -107,13 +107,13 @@ EXTERNC void *memcpy_sse2(void *dest, const void *src, size_t n)
}
memcpy_unsafe(d, s, n);
#endif // defined(a64)
#endif // defined(__amd64__)
return dest;
}
EXTERNC void *memcpy_sse3(void *dest, const void *src, size_t n)
{
#if defined(a64)
#if defined(__amd64__)
char *d = (char *)dest;
const char *s = (const char *)src;
@ -149,13 +149,13 @@ EXTERNC void *memcpy_sse3(void *dest, const void *src, size_t n)
}
memcpy_unsafe(d, s, n);
#endif // defined(a64)
#endif // defined(__amd64__)
return dest;
}
EXTERNC void *memcpy_ssse3(void *dest, const void *src, size_t n)
{
#if defined(a64)
#if defined(__amd64__)
char *d = (char *)dest;
const char *s = (const char *)src;
@ -191,13 +191,13 @@ EXTERNC void *memcpy_ssse3(void *dest, const void *src, size_t n)
}
memcpy_unsafe(d, s, n);
#endif // defined(a64)
#endif // defined(__amd64__)
return dest;
}
EXTERNC void *memcpy_sse4_1(void *dest, const void *src, size_t n)
{
#if defined(a64)
#if defined(__amd64__)
char *d = (char *)dest;
const char *s = (const char *)src;
@ -233,13 +233,13 @@ EXTERNC void *memcpy_sse4_1(void *dest, const void *src, size_t n)
}
memcpy_unsafe(d, s, n);
#endif // defined(a64)
#endif // defined(__amd64__)
return dest;
}
EXTERNC void *memcpy_sse4_2(void *dest, const void *src, size_t n)
{
#if defined(a64)
#if defined(__amd64__)
char *d = (char *)dest;
const char *s = (const char *)src;
@ -275,6 +275,6 @@ EXTERNC void *memcpy_sse4_2(void *dest, const void *src, size_t n)
}
memcpy_unsafe(d, s, n);
#endif // defined(a64)
#endif // defined(__amd64__)
return dest;
}

View File

@ -89,7 +89,7 @@ EXTERNC void *memset_sse4_1(void *dest, int c, size_t n)
EXTERNC void *memset_sse4_2(void *dest, int c, size_t n)
{
#if defined(a64)
#if defined(__amd64__)
char *d = (char *)dest;
if (((uintptr_t)d & 0xF) == 0)

View File

@ -44,9 +44,9 @@ EXTERNC nsa NIF void __cyg_profile_func_enter(void *Function, void *CallSite)
return;
while (Wait)
#if defined(a86)
#if defined(__amd64__) || defined(__i386__)
asmv("pause");
#elif defined(aa64)
#elif defined(__aarch64__)
asmv("yield");
#endif
Wait = true;
@ -81,9 +81,9 @@ EXTERNC nsa NIF void __cyg_profile_func_exit(void *Function, void *CallSite)
return;
while (Wait)
#if defined(a86)
#if defined(__amd64__) || defined(__i386__)
asmv("pause");
#elif defined(aa64)
#elif defined(__aarch64__)
asmv("yield");
#endif
Wait = true;

View File

@ -275,7 +275,7 @@ struct linux_dirent64
struct linux_kstat
{
#if defined(a64)
#if defined(__amd64__)
__kernel_ulong_t st_dev;
__kernel_ulong_t st_ino;
__kernel_ulong_t st_nlink;
@ -295,7 +295,7 @@ struct linux_kstat
__kernel_ulong_t st_ctime_nsec;
#undef __unused
__kernel_long_t __unused[3];
#elif defined(a32)
#elif defined(__i386__)
unsigned long st_dev;
unsigned long st_ino;
unsigned short st_mode;

View File

@ -733,7 +733,7 @@ struct __old_kernel_stat StatToOKStat(struct kstat stat)
__no_stack_protector void __LinuxForkReturn(void *tableAddr)
{
#if defined(a64)
#if defined(__amd64__)
asmv("movq %0, %%cr3" ::"r"(tableAddr)); /* Load process page table */
asmv("movq $0, %rax\n"); /* Return 0 */
asmv("movq %r8, %rsp\n"); /* Restore stack pointer */
@ -741,7 +741,7 @@ __no_stack_protector void __LinuxForkReturn(void *tableAddr)
asmv("swapgs\n"); /* Swap GS back to the user GS */
asmv("sti\n"); /* Enable interrupts */
asmv("sysretq\n"); /* Return to rcx address in user mode */
#elif defined(a32)
#elif defined(__i386__)
#warning "__LinuxForkReturn not implemented for i386"
#endif
__builtin_unreachable();
@ -1086,11 +1086,11 @@ static int linux_mprotect(SysFrm *, void *addr, size_t len, int prot)
p_Write ? "Write" : "",
(prot & linux_PROT_EXEC) ? "Exec" : "");
#if defined(a64)
#if defined(__amd64__)
CPU::x64::invlpg(addr);
#elif defined(a32)
#elif defined(__i386__)
CPU::x32::invlpg(addr);
#elif defined(aa64)
#elif defined(__aarch64__)
asmv("dsb sy");
asmv("tlbi vae1is, %0"
:
@ -1478,7 +1478,7 @@ static pid_t linux_fork(SysFrm *sf)
NewThread->Info.Compatibility = Thread->Info.Compatibility;
NewThread->Security.IsCritical = Thread->Security.IsCritical;
NewThread->Registers = Thread->Registers;
#if defined(a64)
#if defined(__amd64__)
NewThread->Registers.rip = (uintptr_t)__LinuxForkReturn;
/* For sysretq */
NewThread->Registers.rdi = (uintptr_t)NewProcess->PageTable;
@ -1488,7 +1488,7 @@ static pid_t linux_fork(SysFrm *sf)
#warning "sys_fork not implemented for other platforms"
#endif
#ifdef a86
#if defined(__amd64__) || defined(__i386__)
NewThread->GSBase = NewThread->ShadowGSBase;
NewThread->ShadowGSBase = Thread->ShadowGSBase;
NewThread->FSBase = Thread->FSBase;
@ -1559,7 +1559,7 @@ static pid_t linux_vfork(SysFrm *sf)
NewThread->Info.Compatibility = Thread->Info.Compatibility;
NewThread->Security.IsCritical = Thread->Security.IsCritical;
NewThread->Registers = Thread->Registers;
#if defined(a64)
#if defined(__amd64__)
NewThread->Registers.rip = (uintptr_t)__LinuxForkReturn;
/* For sysretq */
NewThread->Registers.rdi = (uintptr_t)NewProcess->PageTable;
@ -1569,7 +1569,7 @@ static pid_t linux_vfork(SysFrm *sf)
#warning "sys_fork not implemented for other platforms"
#endif
#ifdef a86
#if defined(__amd64__) || defined(__i386__)
NewThread->GSBase = NewThread->ShadowGSBase;
NewThread->ShadowGSBase = Thread->ShadowGSBase;
NewThread->FSBase = Thread->FSBase;
@ -2101,11 +2101,11 @@ static int linux_uname(SysFrm *, struct utsname *buf)
.nodename = "fennix",
.release = KERNEL_VERSION,
.version = KERNEL_VERSION,
#if defined(a64)
#if defined(__amd64__)
.machine = "x86_64",
#elif defined(a32)
#elif defined(__i386__)
.machine = "i386",
#elif defined(aa64)
#elif defined(__aarch64__)
.machine = "arm64",
#elif defined(aa32)
.machine = "arm",
@ -2501,28 +2501,28 @@ static int linux_arch_prctl(SysFrm *, int code, unsigned long addr)
{
case linux_ARCH_SET_GS:
{
#if defined(a64)
#if defined(__amd64__)
CPU::x64::wrmsr(CPU::x64::MSRID::MSR_GS_BASE, addr);
#elif defined(a32)
#elif defined(__i386__)
CPU::x32::wrmsr(CPU::x32::MSRID::MSR_GS_BASE, addr);
#endif
return 0;
}
case linux_ARCH_SET_FS:
{
#if defined(a64)
#if defined(__amd64__)
CPU::x64::wrmsr(CPU::x64::MSRID::MSR_FS_BASE, addr);
#elif defined(a32)
#elif defined(__i386__)
CPU::x32::wrmsr(CPU::x32::MSRID::MSR_FS_BASE, addr);
#endif
return 0;
}
case linux_ARCH_GET_FS:
{
#if defined(a64)
#if defined(__amd64__)
*r_cst(uint64_t *, addr) =
CPU::x64::rdmsr(CPU::x64::MSRID::MSR_FS_BASE);
#elif defined(a32)
#elif defined(__i386__)
*r_cst(uint64_t *, addr) =
CPU::x32::rdmsr(CPU::x32::MSRID::MSR_FS_BASE);
#endif
@ -2530,10 +2530,10 @@ static int linux_arch_prctl(SysFrm *, int code, unsigned long addr)
}
case linux_ARCH_GET_GS:
{
#if defined(a64)
#if defined(__amd64__)
*r_cst(uint64_t *, addr) =
CPU::x64::rdmsr(CPU::x64::MSRID::MSR_GS_BASE);
#elif defined(a32)
#elif defined(__i386__)
*r_cst(uint64_t *, addr) =
CPU::x32::rdmsr(CPU::x32::MSRID::MSR_GS_BASE);
#endif
@ -4258,7 +4258,7 @@ static SyscallData LinuxSyscallsTableI386[] = {
uintptr_t HandleLinuxSyscalls(SyscallsFrame *Frame)
{
#if defined(a64)
#if defined(__amd64__)
if (Frame->rax > sizeof(LinuxSyscallsTableAMD64) / sizeof(SyscallData))
{
fixme("Syscall %d not implemented",
@ -4289,7 +4289,7 @@ uintptr_t HandleLinuxSyscalls(SyscallsFrame *Frame)
debug("< [%ld:\"%s\"] = %ld", Frame->rax, Syscall.Name, sc_ret);
return sc_ret;
#elif defined(a32)
#elif defined(__i386__)
if (Frame->eax > sizeof(LinuxSyscallsTableI386) / sizeof(SyscallData))
{
fixme("Syscall %d not implemented",
@ -4320,13 +4320,13 @@ uintptr_t HandleLinuxSyscalls(SyscallsFrame *Frame)
debug("< [%d:\"%s\"] = %d", Frame->eax, Syscall.Name, sc_ret);
return sc_ret;
#elif defined(aa64)
#elif defined(__aarch64__)
return -linux_ENOSYS;
#endif
#if defined(a64)
#if defined(__amd64__)
UNUSED(LinuxSyscallsTableI386);
#elif defined(a32)
#elif defined(__i386__)
UNUSED(LinuxSyscallsTableAMD64);
#endif
}

View File

@ -35,9 +35,9 @@ struct SyscallData
using namespace Memory;
#if defined(a64)
#if defined(__amd64__)
typedef long arch_t;
#elif defined(a32)
#elif defined(__i386__)
typedef int arch_t;
#endif
@ -60,7 +60,7 @@ static SyscallData NativeSyscallsTable[sc_MaxSyscall] = {
uintptr_t HandleNativeSyscalls(SysFrm *Frame)
{
#if defined(a64)
#if defined(__amd64__)
if (unlikely(Frame->rax > sc_MaxSyscall))
{
fixme("Syscall %ld not implemented.", Frame->rax);
@ -103,7 +103,7 @@ uintptr_t HandleNativeSyscalls(SysFrm *Frame)
debug("< [%d:\"%s\"] = %d",
Frame->rax, Syscall.Name, sc_ret);
return sc_ret;
#elif defined(a32)
#elif defined(__i386__)
if (unlikely(Frame->eax > sc_MaxSyscall))
{
fixme("Syscall %ld not implemented.", Frame->eax);
@ -146,7 +146,7 @@ uintptr_t HandleNativeSyscalls(SysFrm *Frame)
debug("< [%d:\"%s\"] = %d",
Frame->eax, Syscall.Name, sc_ret);
return sc_ret;
#elif defined(aa64)
#elif defined(__aarch64__)
return -ENOSYS;
#endif
}

View File

@ -29,7 +29,7 @@ private:
public:
AutoSwitchPageTable()
{
#if defined(a86)
#if defined(__amd64__) || defined(__i386__)
asmv("mov %%cr3, %0"
: "=r"(Original));
@ -45,7 +45,7 @@ public:
{
debug("- %#lx %s(%d)", Original,
thisProcess->Name, thisProcess->ID);
#if defined(a86)
#if defined(__amd64__) || defined(__i386__)
asmv("mov %0, %%cr3"
:
: "r"(Original));

View File

@ -27,12 +27,12 @@
#include "../kernel.h"
#if defined(a64)
#if defined(__amd64__)
#include "../arch/amd64/cpu/apic.hpp"
#include "../arch/amd64/cpu/gdt.hpp"
#elif defined(a32)
#elif defined(__i386__)
#include "../arch/i386/cpu/apic.hpp"
#elif defined(aa64)
#elif defined(__aarch64__)
#endif
// #define DEBUG_TASKING 1

View File

@ -26,13 +26,13 @@
#include "../kernel.h"
#if defined(a64)
#if defined(__amd64__)
#include "../arch/amd64/cpu/apic.hpp"
#include "../arch/amd64/cpu/gdt.hpp"
#elif defined(a32)
#elif defined(__i386__)
#include "../arch/i386/cpu/apic.hpp"
#include "../arch/i386/cpu/gdt.hpp"
#elif defined(aa64)
#elif defined(__aarch64__)
#endif
// #define DEBUG_SCHEDULER 1
@ -105,11 +105,11 @@
__naked __used nsa void __custom_sched_idle_loop()
{
#if defined(a86)
#if defined(__amd64__) || defined(__i386__)
asmv("IdleLoop:");
asmv("hlt");
asmv("jmp IdleLoop");
#elif defined(aa64)
#elif defined(__aarch64__)
asmv("IdleLoop:");
asmv("wfe");
asmv("b IdleLoop");
@ -195,7 +195,7 @@ namespace Tasking::Scheduler
void Custom::StartScheduler()
{
#if defined(a86)
#if defined(__amd64__) || defined(__i386__)
if (Interrupts::apicTimer[0])
{
((APIC::Timer *)Interrupts::apicTimer[0])->OneShot(CPU::x86::IRQ16, 100);
@ -235,9 +235,9 @@ namespace Tasking::Scheduler
/* This will trigger the IRQ16
instantly so we won't execute
the next instruction */
#if defined(a86)
#if defined(__amd64__) || defined(__i386__)
asmv("int $0x30");
#elif defined(aa64)
#elif defined(__aarch64__)
asmv("svc #0x30");
#endif
}
@ -278,9 +278,9 @@ namespace Tasking::Scheduler
TimeSlice += 10;
#endif
#if defined(a86)
#if defined(__amd64__) || defined(__i386__)
((APIC::Timer *)Interrupts::apicTimer[GetCurrentCPU()->ID])->OneShot(CPU::x86::IRQ16, TimeSlice);
#elif defined(aa64)
#elif defined(__aarch64__)
#endif
}
@ -588,7 +588,7 @@ namespace Tasking::Scheduler
{
CurrentCPU->CurrentThread->Registers = *Frame;
CPU::x64::fxsave(&CurrentCPU->CurrentThread->FPU);
#ifdef a64
#ifdef __amd64__
CurrentCPU->CurrentThread->ShadowGSBase = CPU::x64::rdmsr(CPU::x64::MSR_SHADOW_GS_BASE);
CurrentCPU->CurrentThread->GSBase = CPU::x64::rdmsr(CPU::x64::MSR_GS_BASE);
CurrentCPU->CurrentThread->FSBase = CPU::x64::rdmsr(CPU::x64::MSR_FS_BASE);
@ -681,7 +681,7 @@ namespace Tasking::Scheduler
*Frame = CurrentCPU->CurrentThread->Registers;
#ifdef a64
#ifdef __amd64__
GlobalDescriptorTable::SetKernelStack((void *)((uintptr_t)CurrentCPU->CurrentThread->Stack->GetStackTop()));
CPU::x64::fxrstor(&CurrentCPU->CurrentThread->FPU);
CPU::x64::wrmsr(CPU::x64::MSR_SHADOW_GS_BASE, CurrentCPU->CurrentThread->ShadowGSBase);
@ -705,7 +705,7 @@ namespace Tasking::Scheduler
if (CurrentCPU->CurrentThread->Security.IsDebugEnabled &&
CurrentCPU->CurrentThread->Security.IsKernelDebugEnabled)
{
#ifdef a64
#ifdef __amd64__
trace("%s[%ld]: RIP=%#lx RBP=%#lx RSP=%#lx",
CurrentCPU->CurrentThread->Name, CurrentCPU->CurrentThread->ID,
CurrentCPU->CurrentThread->Registers.rip,
@ -731,7 +731,7 @@ namespace Tasking::Scheduler
Custom::Custom(Task *ctx) : Base(ctx), Interrupts::Handler(16) /* IRQ16 */
{
#if defined(a86)
#if defined(__amd64__) || defined(__i386__)
// Map the IRQ16 to the first CPU.
((APIC::APIC *)Interrupts::apic[0])->RedirectIRQ(0, CPU::x86::IRQ16 - CPU::x86::IRQ0, 1);
#endif

View File

@ -20,11 +20,11 @@
#include <task.hpp>
#include <errno.h>
#if defined(a64)
#if defined(__amd64__)
#include "../arch/amd64/cpu/gdt.hpp"
#elif defined(a32)
#elif defined(__i386__)
#include "../arch/i386/cpu/gdt.hpp"
#elif defined(aa64)
#elif defined(__aarch64__)
#endif
#include "../kernel.h"

View File

@ -27,12 +27,12 @@
#include "../kernel.h"
#if defined(a64)
#if defined(__amd64__)
#include "../arch/amd64/cpu/apic.hpp"
#include "../arch/amd64/cpu/gdt.hpp"
#elif defined(a32)
#elif defined(__i386__)
#include "../arch/i386/cpu/apic.hpp"
#elif defined(aa64)
#elif defined(__aarch64__)
#endif
// #define DEBUG_TASKING 1

View File

@ -27,13 +27,13 @@
#include "../kernel.h"
#if defined(a64)
#if defined(__amd64__)
#include "../arch/amd64/cpu/apic.hpp"
#include "../arch/amd64/cpu/gdt.hpp"
#elif defined(a32)
#elif defined(__i386__)
#include "../arch/i386/cpu/apic.hpp"
#include "../arch/i386/cpu/gdt.hpp"
#elif defined(aa64)
#elif defined(__aarch64__)
#endif
// #define DEBUG_TASKING 1
@ -157,7 +157,7 @@ namespace Tasking
uintptr_t Arg5, uintptr_t Arg6,
void *Function)
{
#if defined(a64)
#if defined(__amd64__)
this->Registers.rdi = Arg1;
this->Registers.rsi = Arg2;
this->Registers.rdx = Arg3;
@ -166,7 +166,7 @@ namespace Tasking
this->Registers.r9 = Arg6;
if (Function != nullptr)
this->Registers.rip = (uint64_t)Function;
#elif defined(a32)
#elif defined(__i386__)
this->Registers.eax = Arg1;
this->Registers.ebx = Arg2;
this->Registers.ecx = Arg3;
@ -316,11 +316,11 @@ namespace Tasking
uintptr_t StackPointerReg = ((uintptr_t)this->Stack->GetStackTop() - SubtractStack);
// assert(!(StackPointerReg & 0xF));
#if defined(a64)
#if defined(__amd64__)
this->Registers.rsp = StackPointerReg;
#elif defined(a32)
#elif defined(__i386__)
this->Registers.esp = StackPointerReg;
#elif defined(aa64)
#elif defined(__aarch64__)
this->Registers.sp = StackPointerReg;
#endif
@ -338,17 +338,17 @@ namespace Tasking
if (Compatibility != Native)
return;
#if defined(a64)
#if defined(__amd64__)
this->Registers.rdi = (uintptr_t)argvLen; // argc
this->Registers.rsi = (uintptr_t)(this->Registers.rsp + 8); // argv
this->Registers.rcx = (uintptr_t)envpLen; // envc
this->Registers.rdx = (uintptr_t)(this->Registers.rsp + 8 + (8 * argvLen) + 8); // envp
#elif defined(a32)
#elif defined(__i386__)
this->Registers.eax = (uintptr_t)argvLen; // argc
this->Registers.ebx = (uintptr_t)(this->Registers.esp + 4); // argv
this->Registers.ecx = (uintptr_t)envpLen; // envc
this->Registers.edx = (uintptr_t)(this->Registers.esp + 4 + (4 * argvLen) + 4); // envp
#elif defined(aa64)
#elif defined(__aarch64__)
this->Registers.x0 = (uintptr_t)argvLen; // argc
this->Registers.x1 = (uintptr_t)(this->Registers.sp + 8); // argv
this->Registers.x2 = (uintptr_t)envpLen; // envc
@ -465,11 +465,11 @@ namespace Tasking
this->vma = this->Parent->vma;
#if defined(a64)
#if defined(__amd64__)
this->Registers.rip = EntryPoint;
#elif defined(a32)
#elif defined(__i386__)
this->Registers.eip = EntryPoint;
#elif defined(aa64)
#elif defined(__aarch64__)
this->Registers.pc = EntryPoint;
#endif
@ -483,7 +483,7 @@ namespace Tasking
this->Security.IsCritical = true;
this->Stack = new Memory::StackGuard(false, this->vma);
#if defined(a64)
#if defined(__amd64__)
this->ShadowGSBase =
CPU::x64::rdmsr(CPU::x64::MSRID::MSR_SHADOW_GS_BASE);
this->GSBase = CPU::x64::rdmsr(CPU::x64::MSRID::MSR_GS_BASE);
@ -496,7 +496,7 @@ namespace Tasking
this->Registers.rflags.AC = 0;
this->Registers.rsp = ((uintptr_t)this->Stack->GetStackTop());
POKE(uintptr_t, this->Registers.rsp) = (uintptr_t)ThreadDoExit;
#elif defined(a32)
#elif defined(__i386__)
this->Registers.cs = GDT_KERNEL_CODE;
this->Registers.r3_ss = GDT_KERNEL_DATA;
this->Registers.eflags.AlwaysOne = 1;
@ -505,7 +505,7 @@ namespace Tasking
this->Registers.eflags.AC = 0;
this->Registers.esp = ((uintptr_t)this->Stack->GetStackTop());
POKE(uintptr_t, this->Registers.esp) = (uintptr_t)ThreadDoExit;
#elif defined(aa64)
#elif defined(__aarch64__)
this->Registers.pc = EntryPoint;
this->Registers.sp = ((uintptr_t)this->Stack->GetStackTop());
POKE(uintptr_t, this->Registers.sp) = (uintptr_t)ThreadDoExit;
@ -534,7 +534,7 @@ namespace Tasking
gsT->TempStack = 0x0;
gsT->t = this;
#if defined(a64)
#if defined(__amd64__)
this->ShadowGSBase = (uintptr_t)gst.VirtualAddress;
this->GSBase = 0;
this->FSBase = 0;
@ -550,7 +550,7 @@ namespace Tasking
an exception. */
this->SetupUserStack_x86_64(argv, envp, auxv, Compatibility);
#elif defined(a32)
#elif defined(__i386__)
this->Registers.cs = GDT_USER_CODE;
this->Registers.r3_ss = GDT_USER_DATA;
this->Registers.eflags.AlwaysOne = 1;
@ -563,7 +563,7 @@ namespace Tasking
an exception. */
this->SetupUserStack_x86_32(argv, envp, auxv);
#elif defined(aa64)
#elif defined(__aarch64__)
this->SetupUserStack_aarch64(argv, envp, auxv);
#endif
#ifdef DEBUG_TASKING
@ -612,7 +612,7 @@ namespace Tasking
this->FPU.fcw = 0b0000001100111111;
#ifdef DEBUG
#ifdef a64
#ifdef __amd64__
debug("Thread EntryPoint: %#lx => RIP: %#lx",
this->EntryPoint, this->Registers.rip);
if (this->Parent->Security.ExecutionMode == TaskExecutionMode::User)
@ -623,7 +623,7 @@ namespace Tasking
debug("Thread stack region is %#lx-%#lx (K) and rsp is %#lx",
this->Stack->GetStackBottom(), this->Stack->GetStackTop(),
this->Registers.rsp);
#elif defined(a32)
#elif defined(__i386__)
debug("Thread EntryPoint: %#lx => RIP: %#lx",
this->EntryPoint, this->Registers.eip);
if (Parent->Security.ExecutionMode == TaskExecutionMode::User)
@ -634,7 +634,7 @@ namespace Tasking
debug("Thread stack region is %#lx-%#lx (K) and rsp is %#lx",
this->Stack->GetStackBottom(), this->Stack->GetStackTop(),
this->Registers.esp);
#elif defined(aa64)
#elif defined(__aarch64__)
#endif
debug("Created %s thread \"%s\"(%d) in process \"%s\"(%d)",
this->Security.ExecutionMode == TaskExecutionMode::User ? "user" : "kernel",

View File

@ -28,23 +28,23 @@
/* static assert, no constructor needed */
#ifdef a64
#ifdef __amd64__
#if UINTPTR_MAX != UINT64_MAX
#error "uintptr_t is not 64-bit!"
#endif // UINTPTR_MAX != UINT64_MAX
#endif // a64
#endif // __amd64__
#ifdef a32
#ifdef __i386__
#if UINTPTR_MAX != UINT32_MAX
#error "uintptr_t is not 32-bit!"
#endif // UINTPTR_MAX != UINT32_MAX
#endif // a32
#endif // __i386__
#ifdef aa64
#ifdef __aarch64__
#if UINTPTR_MAX != UINT64_MAX
#error "uintptr_t is not 64-bit!"
#endif // UINTPTR_MAX != UINT64_MAX
#endif // aa64
#endif // __aarch64__
#ifndef __fennix__
#error "This compiler is not supported!"

View File

@ -126,7 +126,7 @@ extern bool DebuggerIsAttached;
void TestMemoryAllocation()
{
return; /* Bit annoying to have to wait for this to finish */
#ifdef a32
#ifdef __i386__
return; /* Not ready for now. */
#endif
if (DebuggerIsAttached)

View File

@ -38,7 +38,7 @@ __constructor void TestRandom()
if (strcmp(CPU::Hypervisor(), x86_CPUID_VENDOR_TCG) == 0)
RDRANDFlag = 0;
#if defined(a86)
#if defined(__amd64__) || defined(__i386__)
if (RDRANDFlag)
{
uintptr_t RDSEEDValue = 0;

View File

@ -137,15 +137,15 @@ void TaskMgr()
continue;
int State = Proc->State.load();
uint64_t ProcessCpuUsage = GetUsage(OldSystemTime, &Proc->Info);
#if defined(a64)
#if defined(__amd64__)
printf("\e%s-> \eAABBCC%s \e00AAAA%s %ld%% (KT: %ld UT: %ld)\n",
Statuses[State], Proc->Name, StatusesSign[State],
ProcessCpuUsage, Proc->Info.KernelTime, Proc->Info.UserTime);
#elif defined(a32)
#elif defined(__i386__)
printf("\e%s-> \eAABBCC%s \e00AAAA%s %lld%% (KT: %lld UT: %lld)\n",
Statuses[State], Proc->Name, StatusesSign[State],
ProcessCpuUsage, Proc->Info.KernelTime, Proc->Info.UserTime);
#elif defined(aa64)
#elif defined(__aarch64__)
#endif
foreach (auto Thd in Proc->Threads)
@ -154,26 +154,26 @@ void TaskMgr()
continue;
State = Thd->State.load();
uint64_t ThreadCpuUsage = GetUsage(OldSystemTime, &Thd->Info);
#if defined(a64)
#if defined(__amd64__)
printf(" \e%s-> \eAABBCC%s \e00AAAA%s %ld%% (KT: %ld UT: %ld, IP: \e24FF2B%#lx \eEDFF24%s\e00AAAA)\n\eAABBCC",
Statuses[State], Thd->Name, StatusesSign[State], ThreadCpuUsage, Thd->Info.KernelTime,
Thd->Info.UserTime, Thd->Registers.rip, "unknown");
#elif defined(a32)
#elif defined(__i386__)
printf(" \e%s-> \eAABBCC%s \e00AAAA%s %lld%% (KT: %lld UT: %lld, IP: \e24FF2B%#x \eEDFF24%s\e00AAAA)\n\eAABBCC",
Statuses[State], Thd->Name, StatusesSign[State], ThreadCpuUsage, Thd->Info.KernelTime,
Thd->Info.UserTime, Thd->Registers.eip, "unknown");
#elif defined(aa64)
#elif defined(__aarch64__)
#endif
}
}
OldSystemTime = TimeManager->GetCounter();
#if defined(a64)
#if defined(__amd64__)
register uintptr_t CurrentStackAddress asm("rsp");
printf("Sanity: %d, Stack: %#lx", sanity++, CurrentStackAddress);
#elif defined(a32)
#elif defined(__i386__)
register uintptr_t CurrentStackAddress asm("esp");
printf("Sanity: %d, Stack: %#x", sanity++, CurrentStackAddress);
#elif defined(aa64)
#elif defined(__aarch64__)
register uintptr_t CurrentStackAddress asm("sp");
printf("Sanity: %d, Stack: %#lx", sanity++, CurrentStackAddress);
#endif

View File

@ -1,5 +1,5 @@
include Makefile.conf
include config.mk
.PHONY: default tools clean
@ -9,7 +9,7 @@ default:
# For tap0
# -netdev tap,id=usernet0,ifname=tap0,script=no,downscript=no
QEMU = ./$(QEMU_PATH)$(QEMU_ARCH)
QEMU = $(__CONF_QEMU_PATH)
QEMUFLAGS := -display gtk
ifeq ($(OSARCH), amd64)
@ -205,7 +205,7 @@ vscode_debug: build_kernel build_userspace build_drivers build_image vscode_debu
qemu: qemu_vdisk clean_logs
touch serial.log parallel.log
# x-terminal-emulator -e tail -f serial.log &
# x-terminal-emulator -e tail -f serial.log &
# x-terminal-emulator -e tail -f parallel.log &
$(QEMU) $(QEMU_UEFI_BIOS) -cpu host $(QEMUFLAGS) $(QEMUHWACCELERATION) $(QEMUMEMORY) $(QEMU_SMP)

Some files were not shown because too many files have changed in this diff Show More