Skip to content

Commit d0ffbf0

Browse files
committed
Add klib and zydis as submodules
1 parent 1756f4e commit d0ffbf0

31 files changed

Lines changed: 334 additions & 119 deletions

File tree

.gitmodules

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,16 @@
33
url = ../drivers.git
44
branch = main
55
[submodule "libc"]
6-
path = libc
7-
url = ../libc.git
6+
path = klib
7+
url = ../klib.git
88
branch = main
99
[submodule "limine"]
1010
path = limine
1111
url = https://github.com/limine-bootloader/limine/
1212
branch = v9.x-binary
13+
[submodule "klib"]
14+
path = klib
15+
url = git@github.com:slayer-os/klib.git
16+
[submodule "zydis"]
17+
path = zydis
18+
url = git@github.com:zyantific/zydis.git

Makefile

Lines changed: 28 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,15 @@ LIMINE_DIR := limine
44
LIMINE_BIN := $(LIMINE_DIR)/limine
55
LIMINE_CFG := misc/boot/limine.conf
66

7-
LIBC_DIR := libc
7+
KLIB_DIR := klib
88
DRIVERS_DIR := drivers
9+
ZYDIS_DIR := zydis
910

1011
INCLUDES := -I$(shell realpath $(LIMINE_DIR)) \
11-
-I$(LIBC_DIR)/src/include \
12+
-I$(KLIB_DIR)/src/include \
1213
-I$(DRIVERS_DIR)/src/include \
14+
-I$(ZYDIS_DIR)/include \
15+
-I$(ZYDIS_DIR)/dependencies/zycore/include \
1316
-Isrc/include
1417

1518
KERNEL_SRC := src/kernel
@@ -18,8 +21,9 @@ KERNEL_BIN := build/kernel.bin
1821

1922
OBJ_DIR := build/obj
2023

21-
LIBC_LIB := $(LIBC_DIR)/build/libc.a
24+
KLIB_LIB := $(KLIB_DIR)/build/klib.a
2225
DRIVERS_LIB := $(DRIVERS_DIR)/build/drivers.a
26+
ZYDIS_LIB := $(ZYDIS_DIR)/build/libZydis.a
2327

2428
ISO_FILE := build/slayer_$(VERSION).iso
2529
ISO_DIR := build/iso
@@ -28,11 +32,11 @@ ISO_DIR := build/iso
2832
include misc/make/base.mk
2933
override CFLAGS += -DSLAY_VERSION=\"$(VERSION)\"
3034

31-
KERN_SOURCES := $(shell find $(KERNEL_SRC) -name '*.cxx' -or -name '*.s')
32-
KERN_OBJECTS := $(patsubst $(KERNEL_SRC)/%.cxx, $(OBJ_DIR)/%.o, $(patsubst $(KERNEL_SRC)/%.s, $(OBJ_DIR)/%.o, $(KERN_SOURCES)))
35+
KERN_SOURCES := $(shell find $(KERNEL_SRC) -name '*.cc' -or -name '*.s')
36+
KERN_OBJECTS := $(patsubst $(KERNEL_SRC)/%.cc, $(OBJ_DIR)/%.o, $(patsubst $(KERNEL_SRC)/%.s, $(OBJ_DIR)/%.o, $(KERN_SOURCES)))
3337

3438
LIMINE_MAKEFILE := $(LIMINE_DIR)/Makefile
35-
LIBC_MAKEFILE := $(LIBC_DIR)/Makefile
39+
KLIB_MAKEFILE := $(KLIB_DIR)/Makefile
3640
DRIVERS_MAKEFILE := $(DRIVERS_DIR)/Makefile
3741

3842

@@ -41,39 +45,45 @@ all: $(ISO_FILE)
4145
$(LIMINE_MAKEFILE):
4246
git submodule update --init --recursive
4347

44-
$(LIBC_MAKEFILE):
48+
$(KLIB_MAKEFILE):
4549
git submodule update --init --recursive
4650

4751
$(DRIVERS_MAKEFILE):
4852
git submodule update --init --recursive
4953

50-
# LIBC
54+
# KLIB
5155

52-
$(LIBC_LIB): $(LIBC_MAKEFILE)
53-
$(MAKE) -C $(LIBC_DIR)
56+
$(KLIB_LIB): $(KLIB_MAKEFILE)
57+
$(MAKE) -C $(KLIB_DIR)
5458

5559
# Drivers
5660

5761
$(DRIVERS_LIB): $(DRIVERS_MAKEFILE)
5862
$(MAKE) -C $(DRIVERS_DIR)
5963

64+
# Zydis
65+
66+
$(ZYDIS_LIB):
67+
cmake -B $(ZYDIS_DIR)/build -S $(ZYDIS_DIR) -DCMAKE_POSITION_INDEPENDENT_CODE=ON -DCMAKE_BUILD_TYPE=Release -DCMAKE_C_FLAGS="-fno-stack-protector"
68+
cmake --build $(ZYDIS_DIR)/build -j$(nproc) --target Zydis
69+
6070
# Limine
6171

6272
$(LIMINE_BIN): $(LIMINE_MAKEFILE)
6373
$(MAKE) -C $(LIMINE_DIR)
6474

6575
# Kernel
6676

67-
$(OBJ_DIR)/%.o: $(KERNEL_SRC)/%.cxx
77+
$(OBJ_DIR)/%.o: $(KERNEL_SRC)/%.cc
6878
@mkdir -p $(@D)
69-
$(CXX) $(CFLAGS) $(INCLUDES) -c $< -o $@
79+
$(CC) $(CFLAGS) $(INCLUDES) -c $< -o $@
7080

7181
$(OBJ_DIR)/%.o: $(KERNEL_SRC)/%.s
7282
@mkdir -p $(@D)
73-
$(CXX) $(CFLAGS) -c $< -o $@
83+
$(CC) $(CFLAGS) -c $< -o $@
7484

75-
$(KERNEL_BIN): $(LIBC_LIB) $(DRIVERS_LIB) $(KERN_OBJECTS)
76-
$(LD) $(KERN_LDFLAGS) -o $(KERNEL_BIN) $(KERN_OBJECTS) $(DRIVERS_LIB) $(LIBC_LIB)
85+
$(KERNEL_BIN): $(ZYDIS_LIB) $(KLIB_LIB) $(DRIVERS_LIB) $(KERN_OBJECTS)
86+
$(LD) $(KERN_LDFLAGS) -o $(KERNEL_BIN) $(KERN_OBJECTS) $(DRIVERS_LIB) $(KLIB_LIB) $(ZYDIS_LIB)
7787

7888

7989
$(ISO_FILE): $(LIMINE_BIN) $(KERNEL_BIN)
@@ -112,7 +122,8 @@ remote:
112122

113123
clean:
114124
rm -rf build
115-
$(MAKE) -C $(LIBC_DIR) clean
125+
$(MAKE) -C $(KLIB_DIR) clean
116126
$(MAKE) -C $(DRIVERS_DIR) clean
127+
rm -r $(ZYDIS_DIR)/build
117128

118-
.PHONY: all clean run runint $(LIBC_LIB) $(DRIVERS_LIB)
129+
.PHONY: all clean run runint $(KLIB_LIB) $(DRIVERS_LIB)

klib

Submodule klib added at c49fa26

libc

Lines changed: 0 additions & 1 deletion
This file was deleted.

misc/make/base.mk

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,8 @@ override CFLAGS := -g -fno-inline-small-functions \
1919
-mno-sse2 \
2020
-Wno-missing-field-initializers \
2121
-Wno-pointer-arith \
22-
-O3
22+
-O3 \
23+
-gdwarf-4
2324

2425
override LIBC_LDFLAGS := -nostdlib -z max-page-size=0x1000
2526
override KERN_LDFLAGS += -m elf_x86_64 \

src/include/arch/cpuid.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
#pragma once
2+
3+
namespace CPUID {
4+
const char *cpu_vendor();
5+
const char *cpu_brand();
6+
}

src/include/arch/serial.h

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
1-
#ifndef SERIAL_H
2-
#define SERIAL_H
3-
#include <libc/types.h>
1+
#pragma once
2+
#include <klib/types.h>
43

54
#define COM1 0x3F8
65

@@ -16,4 +15,3 @@ namespace UART {
1615
}
1716

1817

19-
#endif

src/include/arch/sse.h

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
1-
#ifndef SSE_H
2-
#define SSE_H
1+
#pragma once
32

43
namespace SSE {
54
bool __attribute__((naked)) enable();
65
bool test();
76
}
87

9-
#endif

src/include/bootloader/limine.h

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
1-
#ifndef LIMINE_INTERFACE_H
2-
#define LIMINE_INTERFACE_H
3-
#include <libc/types.h>
1+
#pragma once
2+
#include <klib/types.h>
43
#include <limine.h>
54

65
class BootloaderCtx {
@@ -24,4 +23,3 @@ class BootloaderCtx {
2423

2524
extern BootloaderCtx boot_ctx;
2625

27-
#endif

0 commit comments

Comments
 (0)