summaryrefslogtreecommitdiff
path: root/kernel/usrbin
diff options
context:
space:
mode:
Diffstat (limited to 'kernel/usrbin')
-rw-r--r--kernel/usrbin/Makefile27
-rw-r--r--kernel/usrbin/lib.s10
-rw-r--r--kernel/usrbin/link.ld8
-rw-r--r--kernel/usrbin/main.c7
-rw-r--r--kernel/usrbin/print.c3
-rw-r--r--kernel/usrbin/usrbin.binbin59 -> 0 bytes
-rw-r--r--kernel/usrbin/usrbin.s12
7 files changed, 49 insertions, 18 deletions
diff --git a/kernel/usrbin/Makefile b/kernel/usrbin/Makefile
index dfd1b84..dd42909 100644
--- a/kernel/usrbin/Makefile
+++ b/kernel/usrbin/Makefile
@@ -1,17 +1,32 @@
-TARGET = usrbin.o
+TARGET = usrbin_blob.o
-ASM = nasm
+SRCS = $(wildcard *.c)
+ASMS = $(wildcard *.s)
+OBJS = $(SRCS:.c=.o) $(ASMS:.s=.o)
+
+CFLAGS = -m32 -I../../include -ffreestanding -nostdinc -nostdlib -fno-stack-protector -fno-pie
+LDFLAGS = -m elf_i386 -T link.ld
+ASMFLAGS = -f elf32
+
+CC = gcc $(CFLAGS)
+LD = ld $(LDFLAGS)
+ASM = nasm $(ASMFLAGS)
all: build
build: $(TARGET)
-usrbin.bin: usrbin.s
- $(ASM) -f bin -o usrbin.bin usrbin.s
+.s.o:
+ $(ASM) -o $*.o $^
+
+.c.o:
+ $(CC) -c -o $*.o $^
-$(TARGET): usrbin.bin
- objcopy -I binary -O elf32-i386 -B i386 usrbin.bin usrbin.o
+$(TARGET): $(OBJS)
+ $(LD) -o usrbin.bin $(OBJS)
+ objcopy -I binary -O elf32-i386 -B i386 usrbin.bin $(TARGET)
clean:
rm -f usrbin.bin
+ rm -f $(OBJS)
rm -f $(TARGET)
diff --git a/kernel/usrbin/lib.s b/kernel/usrbin/lib.s
new file mode 100644
index 0000000..ffe4f5f
--- /dev/null
+++ b/kernel/usrbin/lib.s
@@ -0,0 +1,10 @@
+bits 32
+
+extern main
+
+section .entry
+init:
+ call main
+.loop:
+ ; loop forever
+ jmp .loop
diff --git a/kernel/usrbin/link.ld b/kernel/usrbin/link.ld
new file mode 100644
index 0000000..c1a7a42
--- /dev/null
+++ b/kernel/usrbin/link.ld
@@ -0,0 +1,8 @@
+OUTPUT_FORMAT(binary)
+SECTIONS
+{
+ . = 0x100000;
+ .text : { *(.entry); .*(.text) }
+ .data : { *(.data) }
+ .bss : { *(.bss) }
+}
diff --git a/kernel/usrbin/main.c b/kernel/usrbin/main.c
new file mode 100644
index 0000000..5cc7567
--- /dev/null
+++ b/kernel/usrbin/main.c
@@ -0,0 +1,7 @@
+#include <stdint.h>
+
+extern int print(char*);
+
+void main(void) {
+ print("We did it ma!\n");
+}
diff --git a/kernel/usrbin/print.c b/kernel/usrbin/print.c
new file mode 100644
index 0000000..ea32cdf
--- /dev/null
+++ b/kernel/usrbin/print.c
@@ -0,0 +1,3 @@
+#include <unistd.h>
+
+_syscall1(int, print, char*, s);
diff --git a/kernel/usrbin/usrbin.bin b/kernel/usrbin/usrbin.bin
deleted file mode 100644
index bdf8c29..0000000
--- a/kernel/usrbin/usrbin.bin
+++ /dev/null
Binary files differ
diff --git a/kernel/usrbin/usrbin.s b/kernel/usrbin/usrbin.s
deleted file mode 100644
index 248d823..0000000
--- a/kernel/usrbin/usrbin.s
+++ /dev/null
@@ -1,12 +0,0 @@
-bits 32
-org 0x100000
-
-main:
- push .msg
- push byte 0
- int 0x80
- add esp, 4
-.loop:
- ; loop forever
- jmp .loop
-.msg: db "Hello World from Userspace, using syscalls!", 10, 0