# HG changeset patch # User tobaru # Date 1501847886 -32400 # Node ID e4f49859477e9014b8fb9e6b616b2b908db00e80 # Parent 0bbeb1a284e21885159e6ff1aec913c55f8a8f9d# Parent 11870733f490159035d99b7031f0d830f1f214a7 merge diff -r 11870733f490 -r e4f49859477e src/Makefile.osx --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/Makefile.osx Fri Aug 04 20:58:06 2017 +0900 @@ -0,0 +1,75 @@ +# specify path to QEMU, installed with MacPorts +QEMU = qemu-system-arm + +include makefile-osx.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-osx.o +kernel.elf: $(addprefix build/,$(KERN_OBJS)) kernel.ld build/initcode build/fs.img + cp -f build/initcode initcode + cp -f build/fs.img fs.img + $(call LINK_BIN, kernel.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, -e start ) + $(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 diff -r 11870733f490 -r e4f49859477e src/entry-osx.S --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/entry-osx.S Fri Aug 04 20:58:06 2017 +0900 @@ -0,0 +1,33 @@ +#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 + 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 diff -r 11870733f490 -r e4f49859477e src/makefile-osx.inc --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/makefile-osx.inc Fri Aug 04 20:58:06 2017 +0900 @@ -0,0 +1,48 @@ +# Cross-compiling (e.g., on Mac OS X, install arm-none-eabi-gcc with MacPorts) +CROSSCOMPILE := + +CC = $(CROSSCOMPILE)/Users/one/src/cbclang-arm/build/bin/clang +AS = $(CROSSCOMPILE)as +LD = $(CROSSCOMPILE)ld +OBJCOPY = $(CROSSCOMPILE)objcopy +OBJDUMP = $(CROSSCOMPILE)objdump + +CFLAGS = -arch arm -fno-pic -static -fno-builtin -fno-strict-aliasing -Wall -Werror -I. -g -O0 \ + -Wno-macro-redefined -Wno-gnu-designator -Wno-sometimes-uninitialized -Wno-tautological-compare \ + -I/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS.sdk/usr/include +LDFLAGS = -L. -arch armv7 +ASFLAGS = -arch arm + +LIBGCC = $(shell $(CC) -print-libgcc-file-name) + +# host compiler +HOSTCC_preferred = clang +define get_hostcc + $(if $(shell which $(HOSTCC_preferred)),$(HOSTCC_preferred),"cc") +endef +HOSTCC := $(call get_hostcc) + +# general rules +quiet-command = $(if $(V),$1,$(if $(2),@echo $2 && $1, @$1)) + +LINK_BIN = $(call quiet-command,$(LD) $(LDFLAGS) \ + -T $(1) -o $(2) $(3) $(LIBS) -b binary $(4), " LINK $(TARGET_DIR)$@") + +LINK_INIT = $(call quiet-command,$(LD) $(LDFLAGS) \ + $(1) -o $@.out $<, " LINK $(TARGET_DIR)$@") +OBJCOPY_INIT = $(call quiet-command,$(OBJCOPY) \ + -S -O binary --prefix-symbols="_binary_$@" $@.out $@, " OBJCOPY $(TARGET_DIR)$@") + +build-directory = $(shell mkdir -p build build/device build/lib) + +build/%.o: %.c + $(call build-directory) + $(call quiet-command,$(CC) $(CFLAGS) \ + -c -o $@ $<," CC $(TARGET_DIR)$@") + +AS_WITH = $(call quiet-command,$(CC) $(ASFLAGS) \ + $(1) -c -o $@ $<," AS $(TARGET_DIR)$@") + +build/%.o: %.S + $(call build-directory) + $(call AS_WITH, )