From b50063aec430da68e12adf37f206990ce184a872 Mon Sep 17 00:00:00 2001 From: Yingshiuan Pan Date: Sat, 27 Aug 2011 11:45:55 +0800 Subject: [PATCH 1/6] Generate link map file. this patch is from curt-v1-rework by cyt93cs http://code.google.com/p/curt-v1-rework/ --- .gitignore | 1 + app/shell/Makefile | 3 ++- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index 714413f..cf8bace 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,6 @@ *.swp *.o +*.map app/shell/curt_image.bin app/shell/curt_image.elf app/shell/flash-image diff --git a/app/shell/Makefile b/app/shell/Makefile index 1a98eb2..edf07b2 100644 --- a/app/shell/Makefile +++ b/app/shell/Makefile @@ -20,7 +20,8 @@ LDSCRIPT := ld-script.lds LDFLAGS = \ -nostdlib -static -e _start \ -p --no-undefined -X \ - -T $(LDSCRIPT) + -T $(LDSCRIPT) \ + -Map $(CURT_IMAGE).map OBJCOPYFLAGS = \ -O binary \ From 56f9449840f148711f50f4052438015597f07a90 Mon Sep 17 00:00:00 2001 From: Yingshiuan Pan Date: Mon, 8 Jun 2015 23:28:23 +0800 Subject: [PATCH 2/6] stdio.c: fix compilation error due to -Werror=unused-but-set-variable ../../lib/stdio.c: In function '_PrintHex': ../../lib/stdio.c:174:6: error: variable 'cnt' set but not used [-Werror=unused-but-set-variable] ../../lib/stdio.c:170:22: error: variable 'flagl' set but not used [-Werror=unused-but-set-variable] ../../lib/stdio.c: In function 'strtoul': ../../lib/stdio.c:414:16: error: variable 'strtoul_err' set but not used [-Werror=unused-but-set-variable] cc1: all warnings being treated as errors --- lib/stdio.c | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-) diff --git a/lib/stdio.c b/lib/stdio.c index 23ef88d..7b7d4da 100644 --- a/lib/stdio.c +++ b/lib/stdio.c @@ -167,12 +167,12 @@ static void _PrintHex(char *fmt, int l) { int i, j; char c, *s = fmt, tol[10]; - bool flag0 = false, flagl = false; + bool flag0 = false; long flagcnt = 0; bool leading_zero = true; char uHex, lHex; - int cnt; /* note: the format like "% 5x" only prints - the number of 5. */ + + /* note: the format like "% 5x" only prints the number of 5. */ /* format like "%081" is interpreted for '0', '8', 'l' * individually. */ @@ -189,8 +189,6 @@ static void _PrintHex(char *fmt, int l) } else if (c == '0') flag0 = true; - else if (c == 'l') - flagl = true; else continue; } @@ -224,7 +222,7 @@ static void _PrintHex(char *fmt, int l) } /* byte-level data, the output Hex */ - for (cnt = 0, i = (8 - flagcnt) / 2; i < 4; i++) { + for (i = (8 - flagcnt) / 2; i < 4; i++) { c = s[i]; /* get upper 4 bits and lower 4 bits. */ @@ -411,7 +409,6 @@ unsigned long strtoul(const char *str, char **endptr, int requestedbase) int base = 10; int nchars = 0; int leadingZero = 0; - unsigned char strtoul_err = 0; while ((c = *str) != 0) { if (nchars == 0 && c == '0') { @@ -438,11 +435,9 @@ unsigned long strtoul(const char *str, char **endptr, int requestedbase) digit = c - 'A' + 10; } else { - strtoul_err = 3; return 0; } if (digit >= base) { - strtoul_err = 4; return 0; } num *= base; From 68519b0f72e20d55e3c1c68239869522d593fb3c Mon Sep 17 00:00:00 2001 From: Yingshiuan Pan Date: Mon, 17 Mar 2014 23:04:15 +0800 Subject: [PATCH 3/6] fix undefined reference to `__stack_chk_fail' and `__stack_chk_guard' --- app/shell/Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/shell/Makefile b/app/shell/Makefile index edf07b2..4705d90 100644 --- a/app/shell/Makefile +++ b/app/shell/Makefile @@ -7,7 +7,7 @@ LD = $(CROSS_COMPILE)ld OBJCOPY = $(CROSS_COMPILE)objcopy MACH_CFLAGS = -march=armv5te -mtune=xscale -Wa,-mcpu=xscale \ - -mabi=aapcs-linux -mno-thumb-interwork + -mabi=aapcs-linux -mno-thumb-interwork -fno-stack-protector CFLAGS = \ -I../../includes/arch/arm/mach-pxa \ From 9e02510c4ec0b1135aab186cd5c5c726b895f3d2 Mon Sep 17 00:00:00 2001 From: Yingshiuan Pan Date: Mon, 17 Mar 2014 23:25:37 +0800 Subject: [PATCH 4/6] rename includes to include --- {includes => include}/arch/arm/mach-pxa/port.h | 2 +- {includes => include}/arch/arm/mach-pxa/pxa255.h | 14 +++++++------- {includes => include}/kernel/ipc.h | 0 {includes => include}/kernel/kernel.h | 0 {includes => include}/kernel/list.h | 0 {includes => include}/kernel/sync.h | 0 {includes => include}/kernel/thread.h | 0 {includes => include}/kernel/types.h | 0 {includes => include}/lib/stdio.h | 0 9 files changed, 8 insertions(+), 8 deletions(-) rename {includes => include}/arch/arm/mach-pxa/port.h (95%) rename {includes => include}/arch/arm/mach-pxa/pxa255.h (98%) rename {includes => include}/kernel/ipc.h (100%) rename {includes => include}/kernel/kernel.h (100%) rename {includes => include}/kernel/list.h (100%) rename {includes => include}/kernel/sync.h (100%) rename {includes => include}/kernel/thread.h (100%) rename {includes => include}/kernel/types.h (100%) rename {includes => include}/lib/stdio.h (100%) diff --git a/includes/arch/arm/mach-pxa/port.h b/include/arch/arm/mach-pxa/port.h similarity index 95% rename from includes/arch/arm/mach-pxa/port.h rename to include/arch/arm/mach-pxa/port.h index 94f1ccd..e659565 100644 --- a/includes/arch/arm/mach-pxa/port.h +++ b/include/arch/arm/mach-pxa/port.h @@ -5,7 +5,7 @@ #include "kernel/types.h" #include "kernel/thread.h" -#define PXA255_TMR_CLK 3686400 +#define PXA255_TMR_CLK 3686400 #define OS_TICKS_PER_SEC 10 stk_t *init_thread_stack(THREAD_FUNC func, diff --git a/includes/arch/arm/mach-pxa/pxa255.h b/include/arch/arm/mach-pxa/pxa255.h similarity index 98% rename from includes/arch/arm/mach-pxa/pxa255.h rename to include/arch/arm/mach-pxa/pxa255.h index 8579888..e00f10f 100644 --- a/includes/arch/arm/mach-pxa/pxa255.h +++ b/include/arch/arm/mach-pxa/pxa255.h @@ -7,17 +7,17 @@ /* --------------------------------------- */ /** Memory Controller */ #define MSC_BASE 0x48000000 -#define MSC_REG(_x_) *(vulong *)(MSC_BASE + _x_) +#define MSC_REG(_x_) *(vulong *)(MSC_BASE + _x_) //--------------------------------------- /** UARTs */ #define FF_UART_BASE 0x40100000 /* Full Function UART Base Address */ -#define FF_UART_REG(_x_) *(vulong *)(FF_UART_BASE + _x_) +#define FF_UART_REG(_x_) *(vulong *)(FF_UART_BASE + _x_) #define BT_UART_BASE 0x40200000 /* Bluetooth UART Base Address */ -#define BT_UART_REG(_x_) *(vulong *)(BT_UART_BASE + _x_) +#define BT_UART_REG(_x_) *(vulong *)(BT_UART_BASE + _x_) #define STD_UART_BASE 0x40700000 /* Standard UART Base Address */ -#define STD_UART_REG(_x_) *(vulong *)(STD_UART_BASE + _x_) +#define STD_UART_REG(_x_) *(vulong *)(STD_UART_BASE + _x_) #define UART_RBR 0x00 /* Receive Buffer Register (read only) */ #define UART_THR 0x00 /* Transmit Holding Register (write only) */ @@ -35,8 +35,8 @@ /* --------------------------------------- */ /** OS Timer */ -#define TMR_BASE 0x40A00000 -#define TMR_REG(_x_) *(vulong *)(TMR_BASE + _x_) +#define TMR_BASE 0x40A00000 +#define TMR_REG(_x_) *(vulong *)(TMR_BASE + _x_) #define TMR_OSMR0 0x00 /* OS timer match registers<3:0> */ #define TMR_OSMR1 0x04 /* */ #define TMR_OSMR2 0x08 /* */ @@ -50,7 +50,7 @@ /* --------------------------------------- */ /** Interrupt Control */ #define INT_BASE 0x40D00000 /* Interrupt controller IRQ pending register */ -#define INT_REG(_x_) *(vulong *)(INT_BASE + _x_) +#define INT_REG(_x_) *(vulong *)(INT_BASE + _x_) #define INT_ICIP 0x00 /* Interrupt controller IRQ pending register */ #define INT_ICMR 0x04 /* Interrupt controller mask register */ #define INT_ICLR 0x08 /* Interrupt controller level register */ diff --git a/includes/kernel/ipc.h b/include/kernel/ipc.h similarity index 100% rename from includes/kernel/ipc.h rename to include/kernel/ipc.h diff --git a/includes/kernel/kernel.h b/include/kernel/kernel.h similarity index 100% rename from includes/kernel/kernel.h rename to include/kernel/kernel.h diff --git a/includes/kernel/list.h b/include/kernel/list.h similarity index 100% rename from includes/kernel/list.h rename to include/kernel/list.h diff --git a/includes/kernel/sync.h b/include/kernel/sync.h similarity index 100% rename from includes/kernel/sync.h rename to include/kernel/sync.h diff --git a/includes/kernel/thread.h b/include/kernel/thread.h similarity index 100% rename from includes/kernel/thread.h rename to include/kernel/thread.h diff --git a/includes/kernel/types.h b/include/kernel/types.h similarity index 100% rename from includes/kernel/types.h rename to include/kernel/types.h diff --git a/includes/lib/stdio.h b/include/lib/stdio.h similarity index 100% rename from includes/lib/stdio.h rename to include/lib/stdio.h From 6414aca6efab5edaa32bcc144fd0f5897d25bd51 Mon Sep 17 00:00:00 2001 From: Yingshiuan Pan Date: Mon, 17 Mar 2014 23:45:18 +0800 Subject: [PATCH 5/6] reoganize the files to make it more clearly move device, some scripts, and the link script to arch/arm/mach-pxa, since they should be arch-dependent files. Also, Makefile had corresponding changes to make it be more clear and easier to add another arch port --- .gitignore | 6 +- Makefile | 58 ++++++++++++++- arch/arm/mach-pxa/Makefile | 71 +++++++++++++++++++ {device => arch/arm/mach-pxa/device}/serial.c | 0 .../shell => arch/arm/mach-pxa}/ld-script.lds | 2 +- .../shell => arch/arm/mach-pxa}/prepare-flash | 0 .../shell => arch/arm/mach-pxa}/run-on-connex | 0 .../arm/mach-pxa}/run-on-connex-debug | 0 8 files changed, 131 insertions(+), 6 deletions(-) create mode 100644 arch/arm/mach-pxa/Makefile rename {device => arch/arm/mach-pxa/device}/serial.c (100%) rename {app/shell => arch/arm/mach-pxa}/ld-script.lds (88%) rename {app/shell => arch/arm/mach-pxa}/prepare-flash (100%) rename {app/shell => arch/arm/mach-pxa}/run-on-connex (100%) rename {app/shell => arch/arm/mach-pxa}/run-on-connex-debug (100%) diff --git a/.gitignore b/.gitignore index cf8bace..6a0f782 100644 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,6 @@ *.swp *.o *.map -app/shell/curt_image.bin -app/shell/curt_image.elf -app/shell/flash-image +arch/arm/mach-pxa/curt_image.bin +arch/arm/mach-pxa/curt_image.elf +arch/arm/mach-pxa/flash-image diff --git a/Makefile b/Makefile index 01a9e54..a7e5aec 100644 --- a/Makefile +++ b/Makefile @@ -1,5 +1,59 @@ +#ARCH = x86 +#ARCH_SRC_DIR = arch/x86 +ARCH = pxa255 +ARCH_SRC_DIR = arch/arm/mach-pxa + +####################################################################### +# path setting +####################################################################### +TOP_DIR = $(shell pwd) +INCLUDE_DIR = -I$(TOP_DIR)/include/$(ARCH_SRC_DIR) -I$(TOP_DIR)/include + +####################################################################### +# compiler / linker setting +####################################################################### +CFLAGS = \ + $(INCLUDE_DIR) -Wall $(DEFS)\ + -fno-builtin -O0 -g $(MACH_CFLAGS) + +LDFLAGS = \ + -nostdlib -static --no-undefined -X + +####################################################################### +# source / object file list +####################################################################### +# hardware indepedent +KERNEL_SRC = \ + $(TOP_DIR)/kernel/kernel.c \ + $(TOP_DIR)/kernel/thread.c \ + $(TOP_DIR)/kernel/list.c \ + $(TOP_DIR)/kernel/sync.c \ + $(TOP_DIR)/kernel/ipc.c + +LIB_SRC = \ + $(TOP_DIR)/lib/stdio.c + +SHELL_SRC = \ + $(TOP_DIR)/app/shell/main.c + +KERNEL_OBJ = $(KERNEL_SRC:.c=.o) +SHELL_OBJ = $(SHELL_SRC:.c=.o) +LIB_OBJ = $(LIB_SRC:.c=.o) + +export + +####################################################################### +# Make Rules +####################################################################### + +.PHONY: all run clean clean-all + all: - $(MAKE) -C app/shell + $(MAKE) -C $(ARCH_SRC_DIR) clean: - $(MAKE) -C app/shell clean + rm -f $(KERNEL_OBJ) $(SHELL_OBJ) $(LIB_OBJ) + $(MAKE) -C $(ARCH_SRC_DIR) clean + +run: all + $(MAKE) -C $(ARCH_SRC_DIR) run diff --git a/arch/arm/mach-pxa/Makefile b/arch/arm/mach-pxa/Makefile new file mode 100644 index 0000000..3e0140a --- /dev/null +++ b/arch/arm/mach-pxa/Makefile @@ -0,0 +1,71 @@ +# Tested on CodeSourcery G++ Lite 2008q1, 2010q1-202, 2011.03 +CROSS_COMPILE = arm-linux-gnueabi- +CURT_IMAGE = curt_image + +CC = $(CROSS_COMPILE)gcc +LD = $(CROSS_COMPILE)ld +OBJCOPY = $(CROSS_COMPILE)objcopy + +MACH_CFLAGS = -march=armv5te -mtune=xscale -Wa,-mcpu=xscale \ + -mabi=aapcs-linux -mno-thumb-interwork -fno-stack-protector + +CFLAGS += $(MACH_CFLAGS) + +LDSCRIPT := ld-script.lds +LDFLAGS += \ + -e _start -p \ + -T $(LDSCRIPT) \ + -Map $(CURT_IMAGE).map + +OBJCOPYFLAGS = \ + -O binary \ + -R .note -R .note.gnu.build-id -R .comment \ + -S + +####################################################################### +# architecture dependence source +####################################################################### +HW_DEP_ASM_SRC = \ + start.S \ + asm_port.S \ + +HW_DEP_C_SRC = \ + device/serial.c \ + port.c + +HW_DEP_C_OBJ = $(HW_DEP_C_SRC:.c=.o) +HW_DEP_ASM_OBJ = $(HW_DEP_ASM_SRC:.S=.o) + +ALL_OBJS = $(SHELL_OBJ) $(HW_DEP_C_OBJ) $(HW_DEP_ASM_OBJ) $(KERNEL_OBJ) $(LIB_OBJ) +####################################################################### +# Make Rules +####################################################################### +all: flash-image + +flash-image: $(CURT_IMAGE).bin + ./prepare-flash + +$(CURT_IMAGE).bin: $(CURT_IMAGE).elf + $(OBJCOPY) $(OBJCOPYFLAGS) $< $@ + +$(CURT_IMAGE).elf: $(ALL_OBJS) + $(LD) $(LDFLAGS) \ + -o $(CURT_IMAGE).elf $(ALL_OBJS) + +$(HW_DEP_C_OBJ) : %.o : %.c + $(CC) -c $(CFLAGS) $< -o $@ + +$(HW_DEP_ASM_OBJ) : %.o : %.S + $(CC) -c $(CFLAGS) $< -o $@ + +$(SHELL_OBJ) $(LIB_OBJ) $(KERNEL_OBJ) : %.o : %.c + $(CC) -c $(CFLAGS) $< -o $@ + +run: + ./run-on-connex + +clean: + rm -f ./*.o + +distclean: + rm -f $(CURT_IMAGE).bin $(CURT_IMAGE).elf flash-image diff --git a/device/serial.c b/arch/arm/mach-pxa/device/serial.c similarity index 100% rename from device/serial.c rename to arch/arm/mach-pxa/device/serial.c diff --git a/app/shell/ld-script.lds b/arch/arm/mach-pxa/ld-script.lds similarity index 88% rename from app/shell/ld-script.lds rename to arch/arm/mach-pxa/ld-script.lds index e931dc6..20cf344 100644 --- a/app/shell/ld-script.lds +++ b/arch/arm/mach-pxa/ld-script.lds @@ -7,7 +7,7 @@ SECTIONS . = ALIGN(4); .text : - { ../../arch/arm/mach-pxa/start.o (.text) + { start.o (.text) *(.text) } . = ALIGN(4); diff --git a/app/shell/prepare-flash b/arch/arm/mach-pxa/prepare-flash similarity index 100% rename from app/shell/prepare-flash rename to arch/arm/mach-pxa/prepare-flash diff --git a/app/shell/run-on-connex b/arch/arm/mach-pxa/run-on-connex similarity index 100% rename from app/shell/run-on-connex rename to arch/arm/mach-pxa/run-on-connex diff --git a/app/shell/run-on-connex-debug b/arch/arm/mach-pxa/run-on-connex-debug similarity index 100% rename from app/shell/run-on-connex-debug rename to arch/arm/mach-pxa/run-on-connex-debug From e47f16fa9d13288969a55c37d0830c5132922dc4 Mon Sep 17 00:00:00 2001 From: Yingshiuan Pan Date: Sat, 12 Apr 2014 18:43:57 +0800 Subject: [PATCH 6/6] x86: a bootloader entry testing --- .gitignore | 2 ++ Makefile | 8 ++++---- arch/x86/Makefile | 44 +++++++++++++++++++++++++++++++++++++++++++ arch/x86/boot/boot.S | 19 +++++++++++++++++++ arch/x86/boot/boot.ld | 8 ++++++++ 5 files changed, 77 insertions(+), 4 deletions(-) create mode 100644 arch/x86/Makefile create mode 100644 arch/x86/boot/boot.S create mode 100644 arch/x86/boot/boot.ld diff --git a/.gitignore b/.gitignore index 6a0f782..ec3d5c8 100644 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,8 @@ *.swp *.o *.map +*.bin arch/arm/mach-pxa/curt_image.bin arch/arm/mach-pxa/curt_image.elf arch/arm/mach-pxa/flash-image +arch/x86/CuRT-x86.img diff --git a/Makefile b/Makefile index a7e5aec..5118bbb 100644 --- a/Makefile +++ b/Makefile @@ -1,7 +1,7 @@ -#ARCH = x86 -#ARCH_SRC_DIR = arch/x86 -ARCH = pxa255 -ARCH_SRC_DIR = arch/arm/mach-pxa +ARCH = x86 +ARCH_SRC_DIR = arch/x86 +#ARCH = pxa255 +#ARCH_SRC_DIR = arch/arm/mach-pxa ####################################################################### # path setting diff --git a/arch/x86/Makefile b/arch/x86/Makefile new file mode 100644 index 0000000..f7f1a8a --- /dev/null +++ b/arch/x86/Makefile @@ -0,0 +1,44 @@ +TARGET = CuRT-x86.img + +CC = gcc +LD = ld + +.SUFFIXES:.asm .bin .c .s .o .S +.PHONY: all run clean + +HW_DEP_ASM_SRC = + +HW_DEP_ASM_OBJ = $(HW_DEP_ASM_SRC:.S=.o) + +HW_DEP_C_SRC = + +HW_DEP_C_OBJ = $(HW_DEP_C_SRC:.c=.o) + +BOOT_OBJ = boot/boot.o boot/boot.bin + +ALL_OBJS = $(SHELL_OBJ) $(KERNEL_OBJ) $(LIB_OBJ) \ + $(HW_DEP_ASM_OBJ) $(HW_DEP_C_OBJ) $(BOOT_OBJ) + +CFLAGS += -fno-stack-protector +LDFLAGS += + +all: $(TARGET) + +$(TARGET): boot/boot.bin + dd if=/dev/zero of=$(TARGET) bs=512 count=2880 + dd if=boot/boot.bin of=$(TARGET) bs=512 seek=0 conv=notrunc + +boot/boot.bin: boot/boot.o + $(LD) $(LDFLAGS) --oformat binary -o boot/boot.bin -T boot/boot.ld $^ + +%.o:%.c + $(CC) -c $(CFLAGS) $< -o $@ + +%.o:%.S + $(CC) -c $(CFLAGS) $< -o $@ + +clean: + rm -f $(ALL_OBJS) + +run: $(TARGET) + qemu-system-x86_64 -m 32 -fda $< -boot a diff --git a/arch/x86/boot/boot.S b/arch/x86/boot/boot.S new file mode 100644 index 0000000..a4d30ac --- /dev/null +++ b/arch/x86/boot/boot.S @@ -0,0 +1,19 @@ +.code16 + +.text + mov %cs, %ax + mov %ax, %ds + mov %ax, %es + + mov $message, %ax + mov %ax, %bp + mov $19, %cx + mov $0x1301, %ax + mov $0x0009, %bx + mov $0, %dl + int $0x10 + jmp . + +message: .ascii "bootloader testing!" +.org 510 +.word 0xaa55 diff --git a/arch/x86/boot/boot.ld b/arch/x86/boot/boot.ld new file mode 100644 index 0000000..4b678bc --- /dev/null +++ b/arch/x86/boot/boot.ld @@ -0,0 +1,8 @@ +SECTIONS +{ + .text 0x7c00 : + { + code = .; _code = .; __code = .; + *(.text) + } +}