changeset 13:f28daf1e47c1

clang-arm
author mir3636
date Fri, 16 Feb 2018 17:44:49 +0900
parents ad95e7f82f1e
children 02a1ce33746e
files src/entry-clang.S src/kernel-clang.ld src/makefile-armclang
diffstat 3 files changed, 187 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/entry-clang.S	Fri Feb 16 17:44:49 2018 +0900
@@ -0,0 +1,34 @@
+#include "arm.h"
+#include "memlayout.h"
+
+.text
+.code 32
+
+.global _start
+
+_start:
+    # clear the entry bss section, the svc stack, and kernel page table
+    LDR     r1, =edata_entry
+    LDR     r2, =end_entry
+    MOV     r3, #0x00
+
+1:
+    CMP     r1, r2
+#    STMLTIA r1!, {r3}
+    STMIALT r1!, {r3}
+    BLT     1b
+
+    # initialize stack pointers for svc modes
+    MSR     CPSR_cxsf, #(SVC_MODE|NO_INT)
+    LDR     sp, =svc_stktop
+
+    BL      start
+    B .
+
+# during startup, kernel stack uses user address, now switch it to kernel addr
+.global jump_stack
+jump_stack:
+    MOV     r0, sp
+    ADD     r0, r0, #KERNBASE
+    MOV     sp, r0
+    MOV     pc, lr
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/kernel-clang.ld	Fri Feb 16 17:44:49 2018 +0900
@@ -0,0 +1,78 @@
+OUTPUT_FORMAT("elf32-littlearm")
+OUTPUT_ARCH(arm)
+ENTRY(_start)
+
+ENTRY_SVC_STACK_SIZE = 0x1000;
+
+SECTIONS
+{
+  /* the entry point, before enabling paging. The code to enable paing
+   needs to have the same virtual/physical address. entry.S and start.c
+   run in this initial setting.*/
+  . = 0x10000;
+  .start_sec : {
+    build/entry-clang.o(.text)
+    build/start.o(.text .text.*)
+
+    build/entry-clang.o(.rodata .rodata.*)
+    build/start.o(.rodata .rodata.*)
+
+    build/entry-clang.o(.data .data.*)
+    build/start.o(.data .data.*)
+
+    PROVIDE(edata_entry = .);
+
+    build/entry-clang.o(.bss .bss.* COMMON)
+    build/start.o(.bss .bss.* COMMON)
+
+    /*define a stack for the entry*/
+    . = ALIGN(0x1000);
+    . += ENTRY_SVC_STACK_SIZE;
+
+    PROVIDE (svc_stktop = .);
+
+    /* define the kernel page table, must be 16K and 16K-aligned*/
+    . = ALIGN(0x4000);
+    PROVIDE (_kernel_pgtbl = .);
+    . += 0x4000;
+
+    /* we also need a user page table*/
+    PROVIDE (_user_pgtbl = .);
+    . += 0x1000;
+
+    PROVIDE(end_entry = .);
+  }
+
+  /*the kernel executes at the higher 2GB address space, but loaded
+   at the lower memory (0x20000)*/
+  . = 0x80020000;
+
+  .text : AT(0x20000){
+    *(.text .text.* .gnu.linkonce.t.*)
+  }
+
+  PROVIDE(etext = .);	/* Define the 'etext' symbol to this value */
+
+  .rodata : {
+    *(.rodata .rodata.* .gnu.linkonce.r.*)
+  }
+
+  /* aligned the data to a (4K) page, so it can be assigned
+   different protection than the code*/
+  . = ALIGN(0x1000);
+
+  PROVIDE (data_start = .);
+
+  .data : {
+    *(.data .data.*)
+  }
+
+  PROVIDE (edata = .);
+
+  .bss : {
+    *(.bss .bss.* COMMON)
+  }
+
+  . = ALIGN(0x1000);
+  PROVIDE (end = .);
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/makefile-armclang	Fri Feb 16 17:44:49 2018 +0900
@@ -0,0 +1,75 @@
+# specify path to QEMU, installed with MacPorts 
+QEMU = qemu-system-arm
+
+include makefile.inc
+
+# link the libgcc.a for __aeabi_idiv. ARM has no native support for div
+LIBS = $(LIBGCC)
+
+OBJS = \
+	lib/string.o \
+	\
+	arm.o\
+	asm.o\
+	bio.o\
+	buddy.o\
+	console.o\
+	exec.o\
+	file.o\
+	fs.o\
+	log.o\
+	main.o\
+	memide.o\
+	pipe.o\
+	proc.o\
+	spinlock.o\
+	start.o\
+	swtch.o\
+	syscall.o\
+	sysfile.o\
+	sysproc.o\
+	trap_asm.o\
+	trap.o\
+	vm.o \
+	\
+	device/picirq.o \
+	device/timer.o \
+	device/uart.o
+
+KERN_OBJS = $(OBJS) entry-clang.o
+kernel.elf: $(addprefix build/,$(KERN_OBJS)) kernel-clang.ld build/initcode build/fs.img
+	cp -f build/initcode initcode
+	cp -f build/fs.img fs.img
+	$(call LINK_BIN, kernel-clang.ld, kernel.elf, \
+		$(addprefix build/,$(KERN_OBJS)), \
+		initcode fs.img)
+	$(OBJDUMP) -S kernel.elf > kernel.asm
+	$(OBJDUMP) -t kernel.elf | sed '1,/SYMBOL TABLE/d; s/ .* / /; /^$$/d' > kernel.sym
+	rm -f initcode fs.img
+
+qemu: kernel.elf
+	@clear
+	@echo "Press Ctrl-A and then X to terminate QEMU session\n"
+	$(QEMU) -M versatilepb -m 128 -cpu arm1176  -nographic -kernel kernel.elf
+
+INITCODE_OBJ = initcode.o
+$(addprefix build/,$(INITCODE_OBJ)): initcode.S
+	$(call build-directory)
+	$(call AS_WITH, -nostdinc -I.)
+
+#initcode is linked into the kernel, it will be used to craft the first process
+build/initcode: $(addprefix build/,$(INITCODE_OBJ))
+	$(call LINK_INIT, -N -e start -Ttext 0)
+	$(call OBJCOPY_INIT)
+	$(OBJDUMP) -S $< > initcode.asm
+
+build/fs.img:
+	make -C tools
+	make -C usr
+
+clean: 
+	rm -rf build
+	rm -f *.o *.d *.asm *.sym vectors.S bootblock entryother \
+	initcode initcode.out kernel xv6.img fs.img kernel.elf memfs
+	make -C tools clean
+	make -C usr clean