usr: add first userspace program
This commit is contained in:
parent
39bb50a992
commit
bcf6906e72
6 changed files with 88 additions and 3 deletions
2
.gitignore
vendored
2
.gitignore
vendored
|
|
@ -1,5 +1,5 @@
|
||||||
.cache
|
.cache
|
||||||
*.o
|
*.o
|
||||||
*.d
|
*.d
|
||||||
kernel.elf
|
*.elf
|
||||||
compile_commands.json
|
compile_commands.json
|
||||||
|
|
|
||||||
10
Makefile
10
Makefile
|
|
@ -66,7 +66,7 @@ override HEADER_DEPS := $(CFILES:.c=.d) $(ASFILES:.S=.d)
|
||||||
|
|
||||||
# Default target.
|
# Default target.
|
||||||
.PHONY: all
|
.PHONY: all
|
||||||
all: $(KERNEL)
|
all: $(KERNEL) uprg
|
||||||
|
|
||||||
# Link rules for the final kernel executable.
|
# Link rules for the final kernel executable.
|
||||||
$(KERNEL): $(OBJ) linker.ld
|
$(KERNEL): $(OBJ) linker.ld
|
||||||
|
|
@ -86,10 +86,16 @@ $(KERNEL): $(OBJ) linker.ld
|
||||||
@$(CC) $(CFLAGS) -c $< -o $@
|
@$(CC) $(CFLAGS) -c $< -o $@
|
||||||
@echo " CC $@"
|
@echo " CC $@"
|
||||||
|
|
||||||
|
.PHONY: uprg
|
||||||
|
uprg:
|
||||||
|
@$(MAKE) --no-print-directory -C usr.bin
|
||||||
|
|
||||||
# Remove object files and the final executable.
|
# Remove object files and the final executable.
|
||||||
.PHONY: clean
|
.PHONY: clean
|
||||||
clean:
|
clean:
|
||||||
rm -rf $(KERNEL) $(OBJ) $(HEADER_DEPS)
|
@rm -rf $(KERNEL) $(OBJ) $(HEADER_DEPS)
|
||||||
|
@echo " CLEAN kernel"
|
||||||
|
@make --no-print-directory -C usr.bin clean
|
||||||
|
|
||||||
.PHONY: distclean
|
.PHONY: distclean
|
||||||
distclean: clean
|
distclean: clean
|
||||||
|
|
|
||||||
21
usr.bin/Makefile
Normal file
21
usr.bin/Makefile
Normal file
|
|
@ -0,0 +1,21 @@
|
||||||
|
# SPDX-License-Identifier: GPL-2.0-only
|
||||||
|
|
||||||
|
# usr.bin/Makefile
|
||||||
|
#
|
||||||
|
# Compile all user programs.
|
||||||
|
|
||||||
|
UPRG := test1
|
||||||
|
UPRGCLEAN := $(addsuffix clean,$(UPRG))
|
||||||
|
UPRGBUILD := $(addsuffix build,$(UPRG))
|
||||||
|
|
||||||
|
|
||||||
|
.PHONY: all
|
||||||
|
all: $(UPRGBUILD)
|
||||||
|
|
||||||
|
%build: %
|
||||||
|
@$(MAKE) --no-print-directory -C $<
|
||||||
|
|
||||||
|
clean: $(UPRGCLEAN)
|
||||||
|
%clean: %
|
||||||
|
@$(MAKE) -C $< clean
|
||||||
|
@echo " CLEAN usr.bin/$<"
|
||||||
38
usr.bin/test1/Makefile
Normal file
38
usr.bin/test1/Makefile
Normal file
|
|
@ -0,0 +1,38 @@
|
||||||
|
# SPDX-License-Identifier: GPL-2.0-only
|
||||||
|
|
||||||
|
# usr.bin/test1/Makefile
|
||||||
|
#
|
||||||
|
# test1 is the first test program, to be removed later.
|
||||||
|
#
|
||||||
|
# This Makefile also serves as a template for other user programs.
|
||||||
|
|
||||||
|
CC := x86_64-elf-gcc
|
||||||
|
LD := x86_64-elf-ld
|
||||||
|
|
||||||
|
OUT := test1.elf
|
||||||
|
CSRC := test.c
|
||||||
|
SSRC := start.S
|
||||||
|
OBJ := $(CSRC:.c=.o) $(SSRC:.S=.o)
|
||||||
|
DEP := $(OBJ:.o=.d)
|
||||||
|
|
||||||
|
CFLAGS := -Wall -ffreestanding -mno-mmx -mno-sse2 -mno-sse -m64 -MMD
|
||||||
|
LDFLAGS := -nostdlib -static -m elf_x86_64
|
||||||
|
|
||||||
|
CURDIR := $(shell pwd | awk -F '/' '{print $$(NF-1),"/",$$NF}' | sed 's/ //g')
|
||||||
|
|
||||||
|
$(OUT): $(OBJ)
|
||||||
|
@$(LD) $^ $(LDFLAGS) -o $@
|
||||||
|
@echo " USR.LD $(CURDIR)/$@"
|
||||||
|
|
||||||
|
-include $(DEP)
|
||||||
|
|
||||||
|
%.o: %.S
|
||||||
|
@$(CC) $(CFLAGS) -c $< -o $@
|
||||||
|
@echo " USR.CC $(CURDIR)/$@"
|
||||||
|
|
||||||
|
%.o: %.c
|
||||||
|
@$(CC) $(CFLAGS) -c $< -o $@
|
||||||
|
@echo " USR.CC $(CURDIR)/$@"
|
||||||
|
|
||||||
|
clean:
|
||||||
|
@rm -rf $(OUT) $(OBJ) $(DEP)
|
||||||
15
usr.bin/test1/start.S
Normal file
15
usr.bin/test1/start.S
Normal file
|
|
@ -0,0 +1,15 @@
|
||||||
|
/* SPDX-License-Identifier: GPL-2.0-only */
|
||||||
|
|
||||||
|
/* test1/start.S
|
||||||
|
*
|
||||||
|
* Test the basic functionality of the kernel loader
|
||||||
|
*/
|
||||||
|
|
||||||
|
sys_exit = 60
|
||||||
|
|
||||||
|
.global _start
|
||||||
|
_start:
|
||||||
|
call main
|
||||||
|
movq %rax, %rdi
|
||||||
|
movq sys_exit, %rax
|
||||||
|
int $0x80
|
||||||
5
usr.bin/test1/test.c
Normal file
5
usr.bin/test1/test.c
Normal file
|
|
@ -0,0 +1,5 @@
|
||||||
|
/* SPDX-License-Identifier: GPL-2.0-only */
|
||||||
|
int main()
|
||||||
|
{
|
||||||
|
return 0x123456;
|
||||||
|
}
|
||||||
Loading…
Reference in a new issue