Don't use -mregparm=3 in userspace.

It's pretty comfy having arguments in registers in the kernel for now though.
This commit is contained in:
Andreas Kling 2019-02-08 01:24:52 +01:00
parent 04378d9063
commit 5158bee08c
Notes: sideshowbarker 2024-07-19 15:49:55 +09:00
11 changed files with 50 additions and 47 deletions

View file

@ -8,7 +8,7 @@ ARCH_FLAGS =
STANDARD_FLAGS = -std=c++17 -nostdinc++ -nostdlib -nostdinc
USERLAND_FLAGS = -ffreestanding -fno-stack-protector -fno-ident
WARNING_FLAGS = -Wextra -Wall -Wundef -Wcast-qual -Wwrite-strings
FLAVOR_FLAGS = -march=i386 -mregparm=3 -m32 -fno-exceptions -fno-rtti -fmerge-all-constants -fno-unroll-loops -fno-pie -fno-pic
FLAVOR_FLAGS = -march=i386 -m32 -fno-exceptions -fno-rtti -fmerge-all-constants -fno-unroll-loops -fno-pie -fno-pic
OPTIMIZATION_FLAGS = -Oz -fno-asynchronous-unwind-tables
INCLUDE_FLAGS = -I.. -I. -I../LibC

View file

@ -8,7 +8,7 @@ ARCH_FLAGS =
STANDARD_FLAGS = -std=c++17 -nostdinc++ -nostdlib -nostdinc
USERLAND_FLAGS = -ffreestanding -fno-stack-protector -fno-ident
WARNING_FLAGS = -Wextra -Wall -Wundef -Wcast-qual -Wwrite-strings
FLAVOR_FLAGS = -march=i386 -mregparm=3 -m32 -fno-exceptions -fno-rtti -fmerge-all-constants -fno-unroll-loops -fno-pie -fno-pic
FLAVOR_FLAGS = -march=i386 -m32 -fno-exceptions -fno-rtti -fmerge-all-constants -fno-unroll-loops -fno-pie -fno-pic
OPTIMIZATION_FLAGS = -Oz -fno-asynchronous-unwind-tables
INCLUDE_FLAGS = -I.. -I. -I../LibC

Binary file not shown.

View file

@ -7,7 +7,7 @@ ARCH_FLAGS =
STANDARD_FLAGS = -std=c++17 -nostdinc++ -nostdlib -nostdinc
USERLAND_FLAGS = -ffreestanding -fno-stack-protector -fno-ident
WARNING_FLAGS = -Wextra -Wall -Wundef -Wcast-qual -Wwrite-strings
FLAVOR_FLAGS = -march=i386 -mregparm=3 -m32 -fno-exceptions -fno-rtti -fmerge-all-constants -fno-unroll-loops -fno-pie -fno-pic
FLAVOR_FLAGS = -march=i386 -m32 -fno-exceptions -fno-rtti -fmerge-all-constants -fno-unroll-loops -fno-pie -fno-pic
OPTIMIZATION_FLAGS = -Oz -fno-asynchronous-unwind-tables
INCLUDE_FLAGS = -I.. -I. -I../LibC

1
LibC/.gitignore vendored
View file

@ -1,3 +1,4 @@
*.o
*.no
*.d
LibC.a

View file

@ -31,7 +31,6 @@ LIBC_OBJS = \
grp.o \
times.o \
termcap.o \
setjmp.o \
stat.o \
mntent.o \
ctype.o \
@ -47,14 +46,16 @@ LIBC_OBJS = \
poll.o \
entry.o
OBJS = $(AK_OBJS) $(WIDGETS_OBJS) $(LIBC_OBJS) $(SHAREDGRAPHICS_OBJS)
ASM_OBJS = setjmp.no
CPP_OBJS = $(AK_OBJS) $(WIDGETS_OBJS) $(LIBC_OBJS) $(SHAREDGRAPHICS_OBJS)
LIBRARY = LibC.a
ARCH_FLAGS =
STANDARD_FLAGS = -std=c++17 -nostdinc++ -nostdlib -nostdinc
LIBC_FLAGS = -ffreestanding -fno-stack-protector -fno-ident
WARNING_FLAGS = -Wextra -Wall -Wundef -Wcast-qual -Wwrite-strings
FLAVOR_FLAGS = -fomit-frame-pointer -mregparm=3 -march=i386 -m32 -fno-exceptions -fno-rtti -ffunction-sections -fdata-sections -fmerge-all-constants -fno-unroll-loops -fno-pie -fno-pic
FLAVOR_FLAGS = -fomit-frame-pointer -march=i386 -m32 -fno-exceptions -fno-rtti -ffunction-sections -fdata-sections -fmerge-all-constants -fno-unroll-loops -fno-pie -fno-pic
OPTIMIZATION_FLAGS = -O2 -fno-asynchronous-unwind-tables
INCLUDE_FLAGS = -I.. -I.
@ -68,14 +69,17 @@ LDFLAGS = -T linker.ld --strip-debug -melf_i386 --gc-sections
all: $(LIBRARY)
$(LIBRARY): $(OBJS)
@echo "LIB $@"; $(AR) rcs $@ $(OBJS)
$(LIBRARY): $(CPP_OBJS) $(ASM_OBJS)
@echo "LIB $@"; $(AR) rcs $@ $(CPP_OBJS) $(ASM_OBJS)
.cpp.o:
@echo "CXX $<"; $(CXX) $(CXXFLAGS) -o $@ -c $<
%.no: %.asm
@echo "NASM $@"; nasm -f elf -o $@ $<
-include $(OBJS:%.o=%.d)
clean:
@echo "CLEAN"; rm -f $(LIBRARY) $(OBJS) *.d
@echo "CLEAN"; rm -f $(LIBRARY) $(CPP_OBJS) $(ASM_OBJS) *.d

33
LibC/setjmp.asm Normal file
View file

@ -0,0 +1,33 @@
; asmsyntax=nasm
global setjmp
setjmp:
mov eax, [esp + 4]
mov [eax * 4], ebx
mov [eax + 1 * 4], esi
mov [eax + 2 * 4], edi
mov [eax + 3 * 4], ebp
lea ecx, [esp + 4]
mov [eax + 4 * 4], ecx
mov ecx, [esp]
mov [eax + 5 * 4], ecx
xor eax, eax
ret
global longjmp
longjmp:
mov edx, [esp + 4]
mov eax, [esp + 8]
mov ebx, [edx * 4]
mov esi, [edx + 1 * 4]
mov edi, [edx + 2 * 4]
mov ebp, [edx + 3 * 4]
mov ecx, [edx + 4 * 4]
mov esp, ecx
mov ecx, [edx + 5 * 4]
test eax, eax
jnz .nonzero
mov eax, 1
.nonzero:
jmp ecx

View file

@ -1,35 +0,0 @@
#include <setjmp.h>
#include <assert.h>
#include <Kernel/Syscall.h>
asm(
".globl setjmp\n\
setjmp:\n\
movl %ebx, 0(%eax)\n\
movl %esi, 4(%eax)\n\
movl %edi, 8(%eax)\n\
movl %ebp, 12(%eax)\n\
movl %esp, 16(%eax)\n\
movl (%esp), %ecx\n\
movl %ecx, 20(%eax)\n\
xorl %eax, %eax\n\
ret\n\
");
asm(
".globl longjmp\n\
longjmp:\n\
xchgl %edx, %eax\n\
test %eax, %eax\n\
jnz 1f\n\
incl %eax\n\
1:\n\
mov 0(%edx), %ebx\n\
mov 4(%edx), %esi\n\
mov 8(%edx), %edi\n\
mov 12(%edx), %ebp\n\
mov 16(%edx), %ecx\n\
mov %ecx, %esp\n\
mov 20(%edx), %ecx\n\
jmp *%ecx\n\
");

View file

@ -26,7 +26,7 @@ ARCH_FLAGS =
STANDARD_FLAGS = -std=c++17 -nostdinc++ -nostdlib -nostdinc
LIBC_FLAGS = -ffreestanding -fno-stack-protector -fno-ident
WARNING_FLAGS = -Wextra -Wall -Wundef -Wcast-qual -Wwrite-strings
FLAVOR_FLAGS = -fomit-frame-pointer -mregparm=3 -march=i386 -m32 -fno-exceptions -fno-rtti -ffunction-sections -fdata-sections -fmerge-all-constants -fno-unroll-loops -fno-pie -fno-pic
FLAVOR_FLAGS = -fomit-frame-pointer -march=i386 -m32 -fno-exceptions -fno-rtti -ffunction-sections -fdata-sections -fmerge-all-constants -fno-unroll-loops -fno-pie -fno-pic
OPTIMIZATION_FLAGS = -Oz -fno-asynchronous-unwind-tables
INCLUDE_FLAGS = -I../LibC -I.. -I.

View file

@ -8,7 +8,7 @@ ARCH_FLAGS =
STANDARD_FLAGS = -std=c++17 -nostdinc++ -nostdlib -nostdinc
USERLAND_FLAGS = -ffreestanding -fno-stack-protector -fno-ident
WARNING_FLAGS = -Wextra -Wall -Wundef -Wcast-qual -Wwrite-strings
FLAVOR_FLAGS = -march=i386 -mregparm=3 -m32 -fno-exceptions -fno-rtti -fmerge-all-constants -fno-unroll-loops -fno-pie -fno-pic
FLAVOR_FLAGS = -march=i386 -m32 -fno-exceptions -fno-rtti -fmerge-all-constants -fno-unroll-loops -fno-pie -fno-pic
OPTIMIZATION_FLAGS = -Oz -fno-asynchronous-unwind-tables
INCLUDE_FLAGS = -I.. -I. -I../LibC

View file

@ -65,7 +65,7 @@ ARCH_FLAGS =
STANDARD_FLAGS = -std=c++17 -nostdinc++ -nostdlib -nostdinc
USERLAND_FLAGS = -ffreestanding -fno-stack-protector -fno-ident
WARNING_FLAGS = -Wextra -Wall -Wundef -Wcast-qual -Wwrite-strings
FLAVOR_FLAGS = -march=i386 -mregparm=3 -m32 -fno-exceptions -fno-rtti -fmerge-all-constants -fno-unroll-loops -fno-pie -fno-pic
FLAVOR_FLAGS = -march=i386 -m32 -fno-exceptions -fno-rtti -fmerge-all-constants -fno-unroll-loops -fno-pie -fno-pic
OPTIMIZATION_FLAGS = -Oz -fno-asynchronous-unwind-tables
INCLUDE_FLAGS = -I.. -I. -I../LibC