# Compiler flags
# -fno-builtin is required to avoid refs to undefined functions in the kernel.
# Only optimize to -O1 to discourage inlining, which complicates backtraces.
-CFLAGS := $(CFLAGS) $(DEFS) $(LABDEFS) -O -fno-builtin -I$(TOP) -MD -Wall -Wno-format -Wno-unused -Werror -gstabs -fno-stack-protector -std=gnu99 -m32
+CFLAGS := $(CFLAGS) $(DEFS) $(LABDEFS) -O -fno-builtin -I$(TOP) -MD -Wall -Wno-format -Wno-unused -Werror -gstabs -fno-stack-protector -std=gnu99 -m32 -nostdlib
# Lists that the */Makefrag makefile fragments will add to
OBJDIRS :=
$(OBJDIR)/lib/%.o $(OBJDIR)/fs/%.o $(OBJDIR)/user/%.o
KERN_CFLAGS := $(CFLAGS) -DARCANOS_KERNEL -gstabs
-USER_CFLAGS := $(CFLAGS) -DARCANOS_USER -gstabs
+USER_CFLAGS := $(CFLAGS) -I usr/inc -DARCANOS_USER -gstabs
# Include Makefrags for subdirectories
include kern/Makefrag
-
+include usr/lib/Makefrag
+include usr/app/Makefrag
IMAGES = $(OBJDIR)/kern/bochs.img
--- /dev/null
+OBJDIRS += usr/app
+
+USRAPP_LIBFLAGS := -L obj/usr/lib -l usrlib
+
+USRAPP_SRCFILES := usr/app/try_syscall.c \
+
+# Only build files if they exist.
+USRAPP_SRCFILES := $(wildcard $(USRAPP_SRCFILES))
+
+USRAPP_OBJFILES := $(patsubst %.c, $(OBJDIR)/%.o, $(USRAPP_SRCFILES))
+USRAPP_OBJFILES := $(patsubst %.S, $(OBJDIR)/%.o, $(USRAPP_OBJFILES))
+
+# How to build app object files
+$(OBJDIR)/usr/app/%.o: usr/app/%.c
+ @echo + cc $<
+ @mkdir -p $(@D)
+ $(V)$(CC) -nostdinc $(USER_CFLAGS) -c -o $@ $<
+
+$(OBJDIR)/usr/app/%.o: usr/app/%.S
+ @echo + as $<
+ @mkdir -p $(@D)
+ $(V)$(CC) -nostdinc $(USER_CFLAGS) -c -o $@ $<
+
+# How to build the app itself
+$(OBJDIR)/usr/app/try_syscall: $(USRAPP_OBJFILES)
+ @echo + cc $@
+ $(V)$(CC) $(USER_CFLAGS) -o $@ $(USRAPP_OBJFILES) $(USRAPP_LIBFLAGS)
+ $(V)$(OBJDUMP) -S $@ > $@.asm
+ $(V)$(NM) -n $@ > $@.sym
+
+all: $(OBJDIR)/usr/app/try_syscall
+
--- /dev/null
+#include <syscall.h>
+
+int main (int argc, char **argv)
+{
+ while (1)
+ {
+ syscall();
+ }
+}
--- /dev/null
+void syscall();
--- /dev/null
+OBJDIRS += usr/lib
+
+USRLIB_LDFLAGS := $(LDFLAGS) -melf_i386 -nostdlib
+
+USRLIB_SRCFILES := usr/lib/syscall.c \
+ usr/lib/entry.S \
+
+# Only build files if they exist.
+USRLIB_SRCFILES := $(wildcard $(USRLIB_SRCFILES))
+
+USRLIB_OBJFILES := $(patsubst %.c, $(OBJDIR)/%.o, $(USRLIB_SRCFILES))
+USRLIB_OBJFILES := $(patsubst %.S, $(OBJDIR)/%.o, $(USRLIB_OBJFILES))
+
+# How to build usrlib object files
+$(OBJDIR)/usr/lib/%.o: usr/lib/%.c
+ @echo + cc $<
+ @mkdir -p $(@D)
+ $(V)$(CC) -nostdinc $(USER_CFLAGS) -c -o $@ $<
+
+$(OBJDIR)/usr/lib/%.o: usr/lib/%.S
+ @echo + as $<
+ @mkdir -p $(@D)
+ $(V)$(CC) -nostdinc $(USER_CFLAGS) -c -o $@ $<
+
+# How to build the usrlib itself
+$(OBJDIR)/usr/lib/libusrlib.a: $(USRLIB_OBJFILES)
+ @echo + ld $@
+ $(V)$(AR) rcs $@ $(USRLIB_OBJFILES)
+ $(V)$(OBJDUMP) -S $@ > $@.asm
+ $(V)$(NM) -n $@ > $@.sym
+
+all: $(OBJDIR)/usr/lib/libusrlib.a
+
--- /dev/null
+.global _start
+.extern main
+_start:
+
+## here you might want to get the argc/argv pairs somehow and then push
+## them onto the stack...
+
+## right now, though, we have no concept of a "command line" and thus no
+## args that could be pushed
+pushl $0
+pushl $0
+
+# call the user's function
+call main
+
+# once it exists, call a syscall to terminate the process
+
+# loop in case we haven't yet rescheduled
+lp:
+hlt
+jmp lp
--- /dev/null
+#include <syscall.h>
+
+void syscall() {
+ __asm__("int $0x80");
+}