Browse Source

First commit

Matteo Savatteri 4 years ago
commit
3b9eb752ea
4 changed files with 46 additions and 0 deletions
  1. 2 0
      .gitignore
  2. 29 0
      1_false/Makefile
  3. 7 0
      1_false/README
  4. 8 0
      1_false/src/false.s

+ 2 - 0
.gitignore

@@ -0,0 +1,2 @@
+**/bin
+**/obj

+ 29 - 0
1_false/Makefile

@@ -0,0 +1,29 @@
+MAIN=false
+
+AS=as
+ASFLAGS=
+LD=ld
+LDFLAGS=
+
+SDIR=src
+ODIR=obj
+BDIR=bin
+
+
+$(BDIR)/$(MAIN): $(ODIR)/$(MAIN).o $(BDIR)
+	$(LD) -o $@ $(ODIR)/$(MAIN).o $(LDFLAGS)
+$(BDIR):
+	mkdir $(BDIR)
+
+$(ODIR)/$(MAIN).o: $(SDIR)/$(MAIN).s $(ODIR)
+	$(AS) -o $@ $(SDIR)/$(MAIN).s $(ASFLAGS)
+$(ODIR):
+	mkdir $(ODIR)
+
+
+.PHONY: clean clen-all
+
+clean:
+	rm -rf $(ODIR)
+clean-all:
+	rm -rf $(ODIR) $(BDIR)

+ 7 - 0
1_false/README

@@ -0,0 +1,7 @@
+# False
+Fail successfully.
+
+## Description
+The program `false` ask the kernel to end its execution
+and free its address space by mean of the sys_exit
+system call.

+ 8 - 0
1_false/src/false.s

@@ -0,0 +1,8 @@
+
+.text				# Section for machine istructions to be executed
+	.global _start		# Needed by ld to find his default entry point
+_start:				# _start symbol
+	mov	$60, %rax	# Put "60" in %rax register. 60 = sys_exit call
+	mov	$1, %rdi	# Set %rdi register to "1". %rdi = where to put
+				# exit status argument of sys_exit
+	syscall			# Ask Linux to perform syscall indexed by %rax