diff --git a/.gitignore b/.gitignore index 714413f..ec3d5c8 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,8 @@ *.swp *.o -app/shell/curt_image.bin -app/shell/curt_image.elf -app/shell/flash-image +*.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 01a9e54..5118bbb 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/app/shell/Makefile b/app/shell/Makefile index 1a98eb2..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 \ @@ -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 \ 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 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) + } +} 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 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;