Skip to content

Commit

Permalink
enable optimizations
Browse files Browse the repository at this point in the history
  • Loading branch information
Glowman554 committed Aug 4, 2024
1 parent eeb0d28 commit 4374224
Show file tree
Hide file tree
Showing 7 changed files with 23 additions and 16 deletions.
3 changes: 3 additions & 0 deletions .zed/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"format_on_save": "off"
}
4 changes: 3 additions & 1 deletion foxtail/build/program.mk
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
SRCS = $(shell find -name '*.[cS]')
OBJS = $(addsuffix .o,$(basename $(SRCS)))

CFLAGS = -m32 -Wall -g -fno-stack-protector -nostdinc -ffreestanding -no-pie -I include -Wno-builtin-declaration-mismatch -fno-builtin -Ires/libs/include
OPT_LVL = 2

CFLAGS = -O$(OPT_LVL) -m32 -Wall -g -fno-stack-protector -nostdinc -ffreestanding -no-pie -I include -Wno-builtin-declaration-mismatch -fno-builtin -Ires/libs/include
LDFLAGS = -m32 -ffreestanding -no-pie -nostdlib

CFLAGS += $(USER_CFLAGS)
Expand Down
2 changes: 1 addition & 1 deletion mckrnl/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ OBJS = $(addsuffix .o,$(basename $(SRCS) $(CPPSRC)))
CC = i686-linux-gnu-gcc
LD = i686-linux-gnu-gcc

OPT_LVL = 0
OPT_LVL = 2

ASFLAGS = -m32 -g
CFLAGS = -O$(OPT_LVL) -m32 -Wall -g -fno-stack-protector -Wno-builtin-declaration-mismatch -fno-builtin -nostdinc -Iinclude -ffreestanding
Expand Down
20 changes: 9 additions & 11 deletions mckrnl/utils/string.c
Original file line number Diff line number Diff line change
Expand Up @@ -68,14 +68,13 @@ void* memcpy(void* dest, const void* src, unsigned int n) {
unsigned int nn = n / 4;

__asm__ __volatile__ (
"rep movsd;" :: "D" (dest), "S" (src), "c" (nn)
"rep movsl;" : "+D" (dest), "+S" (src), "+c" (nn) :: "memory"
);

unsigned int offset = nn * 4;
unsigned int remaining = n % 4;

uint8_t* d = (uint8_t*) dest + offset;
const uint8_t* s = (const uint8_t*) src + offset;
uint8_t* d = (uint8_t*) dest;
const uint8_t* s = (const uint8_t*) src;
while (remaining--) {
*d++ = *s++;
}
Expand All @@ -88,21 +87,20 @@ void* memset(void* start, uint8_t value, unsigned int num) {
unsigned int long_value = (value << 24) | (value << 16) | (value << 8) | value;

__asm__ __volatile__ (
"rep stosl;" :: "D" (start), "a" (long_value), "c" (nn)
"rep stosl;" : "+D" (start), "+c" (nn) : "a" (long_value) : "memory"
);

unsigned int offset = nn * 4;
unsigned int remaining = num % 4;

uint8_t* s = (uint8_t*) start + offset;
uint8_t* s = (uint8_t*) start;
while (remaining--) {
*s++ = value;
}

return start;
}
#else
void* memcpy(void* dest, const void* src, int n) {
#else
void* memcpy(void* dest, const void* src, unsigned int n) {
char* d = (char*) dest;
char* s = (char*) src;
while(n--) {
Expand All @@ -112,7 +110,7 @@ void* memcpy(void* dest, const void* src, int n) {
}


void* memset(void* start, uint8_t value, int num) {
void* memset(void* start, uint8_t value, unsigned int num) {
char* s = (char*) start;
while(num--) {
*s++ = value;
Expand Down Expand Up @@ -166,4 +164,4 @@ int strcasecmp(char* str1, char* str2) {
++str2;
}
return tolower(*str1) - tolower(*str2);
}
}
2 changes: 1 addition & 1 deletion mckrnl/utils/vsprintf.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
int print_num(unsigned long x, int base, char* str) {
const char* digits = "0123456789abcdefghijklmnopqrstuvwxyz";

char buf[65];
char buf[65] = {0};

char* p;

Expand Down
4 changes: 3 additions & 1 deletion user/library.mk
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
SRCS = $(shell find -name '*.[cS]')
OBJS = $(addsuffix .o,$(basename $(SRCS)))

CFLAGS = -m32 -Wall -g -fno-stack-protector -nostdinc -I include -Wno-builtin-declaration-mismatch -fno-builtin
OPT_LVL = 2

CFLAGS = -O$(OPT_LVL) -m32 -Wall -g -fno-stack-protector -nostdinc -I include -Wno-builtin-declaration-mismatch -fno-builtin
LDFLAGS = -melf_i386

library: $(LIBRARY)
Expand Down
4 changes: 3 additions & 1 deletion user/program.mk
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
SRCS = $(shell find -name '*.[cS]')
OBJS = $(addsuffix .o,$(basename $(SRCS)))

CFLAGS = -m32 -Wall -g -fno-stack-protector -nostdinc -ffreestanding -no-pie -I include -Wno-builtin-declaration-mismatch -fno-builtin -I../libc/include
OPT_LVL = 2

CFLAGS = -O$(OPT_LVL) -m32 -Wall -g -fno-stack-protector -nostdinc -ffreestanding -no-pie -I include -Wno-builtin-declaration-mismatch -fno-builtin -I../libc/include
LDFLAGS = -m32 -ffreestanding -no-pie -nostdlib

LOAD_ADDR = 0xB0000000
Expand Down

0 comments on commit 4374224

Please sign in to comment.