Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -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
58 changes: 56 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
@@ -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
5 changes: 3 additions & 2 deletions app/shell/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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 \
Expand All @@ -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 \
Expand Down
71 changes: 71 additions & 0 deletions arch/arm/mach-pxa/Makefile
Original file line number Diff line number Diff line change
@@ -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
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ SECTIONS

. = ALIGN(4);
.text :
{ ../../arch/arm/mach-pxa/start.o (.text)
{ start.o (.text)
*(.text)
}
. = ALIGN(4);
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
44 changes: 44 additions & 0 deletions arch/x86/Makefile
Original file line number Diff line number Diff line change
@@ -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
19 changes: 19 additions & 0 deletions arch/x86/boot/boot.S
Original file line number Diff line number Diff line change
@@ -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
8 changes: 8 additions & 0 deletions arch/x86/boot/boot.ld
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
SECTIONS
{
.text 0x7c00 :
{
code = .; _code = .; __code = .;
*(.text)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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) */
Expand All @@ -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 /* */
Expand All @@ -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 */
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
13 changes: 4 additions & 9 deletions lib/stdio.c
Original file line number Diff line number Diff line change
Expand Up @@ -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. */
Expand All @@ -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;
}
Expand Down Expand Up @@ -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. */
Expand Down Expand Up @@ -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') {
Expand All @@ -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;
Expand Down