From 9ea98f274e18a3407ce109a331553e1c910274d9 Mon Sep 17 00:00:00 2001 From: Patrick Williams Date: Tue, 18 May 2010 13:51:26 -0500 Subject: Improve make infrastructure. --- config.mk | 26 +++++++++++++ img/.gitignore | 0 kernel.C | 6 --- kernel.ld | 47 ------------------------ makefile | 24 ++---------- obj/.gitignore | 0 src/kernel.ld | 47 ++++++++++++++++++++++++ src/kernel/kernel.C | 6 +++ src/kernel/makefile | 10 +++++ src/kernel/start.S | 103 ++++++++++++++++++++++++++++++++++++++++++++++++++++ src/makefile | 13 +++++++ start.S | 103 ---------------------------------------------------- 12 files changed, 209 insertions(+), 176 deletions(-) create mode 100644 config.mk create mode 100644 img/.gitignore delete mode 100644 kernel.C delete mode 100644 kernel.ld create mode 100644 obj/.gitignore create mode 100644 src/kernel.ld create mode 100644 src/kernel/kernel.C create mode 100644 src/kernel/makefile create mode 100644 src/kernel/start.S create mode 100644 src/makefile delete mode 100644 start.S diff --git a/config.mk b/config.mk new file mode 100644 index 000000000..dac4204d8 --- /dev/null +++ b/config.mk @@ -0,0 +1,26 @@ +CC = powerpc64-unknown-linux-gnu-gcc +CXX = powerpc64-unknown-linux-gnu-g++ +LD = powerpc64-unknown-linux-gnu-ld + +COMMONFLAGS = -O3 -nostdlib +CFLAGS = ${COMMONFLAGS} -mcpu=620 -fno-rtti -fno-exceptions +CXXFLAGS = ${CFLAGS} +LDFLAGS = -static ${COMMONFLAGS} + +${OBJDIR}/%.o : %.C + ${CXX} -c ${CXXFLAGS} $< -o $@ + +${OBJDIR}/%.o : %.S + ${CC} -c ${CFLAGS} $< -o $@ + +${IMGDIR}/%.elf: kernel.ld + ${LD} ${LDFLAGS} ${OBJDIR}/*.o -T kernel.ld -o $@ + +${IMGDIR}/%.bin: kernel.ld + ${LD} ${LDFLAGS} ${OBJDIR}/*.o --oformat=binary -T kernel.ld -o $@ + +%.d: + cd ${basename $@} && ${MAKE} + +%.clean: + cd ${basename $@} && ${MAKE} clean diff --git a/img/.gitignore b/img/.gitignore new file mode 100644 index 000000000..e69de29bb diff --git a/kernel.C b/kernel.C deleted file mode 100644 index 2ea0d2fbc..000000000 --- a/kernel.C +++ /dev/null @@ -1,6 +0,0 @@ -int main() -{ - while(1); - - return 0; -} diff --git a/kernel.ld b/kernel.ld deleted file mode 100644 index 0f44adb34..000000000 --- a/kernel.ld +++ /dev/null @@ -1,47 +0,0 @@ -rom_offset = 0xfff00000; -base_load_address = 0x00000000; -text_load_address = 0x00003000; -hreset_load_address = 0x000ffffc; - -SECTIONS -{ - . = base_load_address; - - .text.intvects ALIGN(0x1000): AT(base_load_address + rom_offset) { - *(.text.intvects) - } - - . = text_load_address; - .text ALIGN(0x1000): { - *(.text) - *(.rodata) - *(.rodata.*) - - } - - .data ALIGN(0x1000): { - data_load_address = .; - *(.data) - *(.data.*) - *(.branch_lt) - *(.bss) - - toc_load_address = .; - *(.toc) - opd_load_address = .; - *(.opd) - *(.got) - } - - . = hreset_load_address; - .text.hreset : { - *(.text.hreset) - } - - /DISCARD/ : { - *(.comment) - *(.gnu.attributes) - } -} - - diff --git a/makefile b/makefile index 7020c5aac..ccd8fed68 100644 --- a/makefile +++ b/makefile @@ -1,21 +1,5 @@ -CC = powerpc64-unknown-linux-gnu-gcc -CXX = powerpc64-unknown-linux-gnu-g++ -LD = powerpc64-unknown-linux-gnu-ld +SUBDIRS = src.d +include ./config.mk -COMMONFLAGS = -O3 -nostdlib -CFLAGS = ${COMMONFLAGS} -mcpu=620 -fno-rtti -fno-exceptions -CXXFLAGS = ${CFLAGS} -LDFLAGS = -static ${COMMONFLAGS} - -OBJECTS = start.o kernel.o - -all: kernel.elf kernel.bin - -kernel.elf: ${OBJECTS} kernel.ld - ${LD} ${LDFLAGS} ${OBJECTS} -T kernel.ld -o kernel.elf - -kernel.bin: ${OBJECTS} kernel.ld - ${LD} ${LDFLAGS} ${OBJECTS} --oformat=binary -T kernel.ld -o kernel.bin - -clean: - (rm -f ${OBJECTS} kernel.elf kernel.bin) +all: ${SUBDIRS} +clean: $(patsubst %.d,%.clean, ${SUBDIRS}) diff --git a/obj/.gitignore b/obj/.gitignore new file mode 100644 index 000000000..e69de29bb diff --git a/src/kernel.ld b/src/kernel.ld new file mode 100644 index 000000000..0f44adb34 --- /dev/null +++ b/src/kernel.ld @@ -0,0 +1,47 @@ +rom_offset = 0xfff00000; +base_load_address = 0x00000000; +text_load_address = 0x00003000; +hreset_load_address = 0x000ffffc; + +SECTIONS +{ + . = base_load_address; + + .text.intvects ALIGN(0x1000): AT(base_load_address + rom_offset) { + *(.text.intvects) + } + + . = text_load_address; + .text ALIGN(0x1000): { + *(.text) + *(.rodata) + *(.rodata.*) + + } + + .data ALIGN(0x1000): { + data_load_address = .; + *(.data) + *(.data.*) + *(.branch_lt) + *(.bss) + + toc_load_address = .; + *(.toc) + opd_load_address = .; + *(.opd) + *(.got) + } + + . = hreset_load_address; + .text.hreset : { + *(.text.hreset) + } + + /DISCARD/ : { + *(.comment) + *(.gnu.attributes) + } +} + + diff --git a/src/kernel/kernel.C b/src/kernel/kernel.C new file mode 100644 index 000000000..2ea0d2fbc --- /dev/null +++ b/src/kernel/kernel.C @@ -0,0 +1,6 @@ +int main() +{ + while(1); + + return 0; +} diff --git a/src/kernel/makefile b/src/kernel/makefile new file mode 100644 index 000000000..74a6bffbc --- /dev/null +++ b/src/kernel/makefile @@ -0,0 +1,10 @@ +OBJDIR = ../../obj +include ../../config.mk + +OBJECTS += ${OBJDIR}/start.o +OBJECTS += ${OBJDIR}/kernel.o + +all: ${OBJECTS} + +clean: + (rm -f ${OBJECTS} ) diff --git a/src/kernel/start.S b/src/kernel/start.S new file mode 100644 index 000000000..481736371 --- /dev/null +++ b/src/kernel/start.S @@ -0,0 +1,103 @@ +.section .text.intvects + +.global _start +_start: + ;// Enter 64 bit mode + mfmsr 0 + lis 11, 0x8000 + sldi 11,11, 32 + or 11,11,0 + mtmsr 11 + isync + + ;// Relocate code + bl pre_relocate ;// fill LR with address +pre_relocate: + mflr 2 + lis 1,0x0010 + cmpl 0,2,1 ;// Check LR is less than 1MB + blt finished_relocate ;// No need to relocate if less than 1MB + + ;// Get addresses for relocation. + ;// Write address in r5 + ;// Read address in r1 + li 5,0 + li 1, -1 ;// fill r1 with ffff..ffffff + lis 3, 0x1 + subi 3,3,1 ;// fill r3 with 0000..00ffff + xor 1,1,3 ;// mask off r1 ffff..ff0000 + + and 1,1,2 ;// and with pre_relocate's address from r2 to get start of + ;// rom section. + + ;// Update LR to low address. + and 6,2,3 + mtlr 6 + + ;// Moving 1MB , so load r2 with (1MB / 8 bytes per word) + lis 2, 0x2 + mtctr 2 +relocate_loop: + ;// The dcbst/sync/icbi/isync sequence comes from PowerISA + ld 4, 0(1) + std 4, 0(5) + dcbst 0,5 + sync + icbi 0,5 + isync + addi 1,1,8 + addi 5,5,8 + bdnz+ relocate_loop + + ;// Now that we've relocated, erase exception prefix. + mfmsr 11 + li 10, 0x40 ;// bit 6 is MSR_EP + not 10,10 + and 11,11,10 + mtmsr 11 + + ;// Jump to low address. + blr + +finished_relocate: + ;// Jump to main. + b _main + +.org _start + 0x100 +intvect_system_reset: + b _start + +.section .text +_main: + ;// Set up initial TOC Base + lis 2, main@h + ori 2, 2, main@l + ld 2,8(2) + + ;// Set up initial stack + lis 1, kernel_stack@h + ori 1, 1, kernel_stack@l + addi 1, 1, 16368 + + ;// Set up exception stack + lis 3, exception_stack@h + ori 3, 3, exception_stack@l + addi 3, 3, 16368 + mtsprg0 3 + + ;// Call main. + bl main +_main_loop: + b _main_loop + + +.section .data + .balign 1024 +kernel_stack: + .space 16*1024 +exception_stack: + .space 16*1024 + +.section .text.hreset +hreset: + b _start diff --git a/src/makefile b/src/makefile new file mode 100644 index 000000000..3247e581e --- /dev/null +++ b/src/makefile @@ -0,0 +1,13 @@ +IMGDIR = ../img +OBJDIR = ../obj +include ../config.mk + +SUBDIRS = kernel.d +IMAGES += ${IMGDIR}/kernel.elf +IMAGES += ${IMGDIR}/kernel.bin + +all: ${SUBDIRS} + ${MAKE} ${IMAGES} + +clean: $(patsubst %.d,%.clean, ${SUBDIRS}) + (rm -f ${IMAGES} ) diff --git a/start.S b/start.S deleted file mode 100644 index 481736371..000000000 --- a/start.S +++ /dev/null @@ -1,103 +0,0 @@ -.section .text.intvects - -.global _start -_start: - ;// Enter 64 bit mode - mfmsr 0 - lis 11, 0x8000 - sldi 11,11, 32 - or 11,11,0 - mtmsr 11 - isync - - ;// Relocate code - bl pre_relocate ;// fill LR with address -pre_relocate: - mflr 2 - lis 1,0x0010 - cmpl 0,2,1 ;// Check LR is less than 1MB - blt finished_relocate ;// No need to relocate if less than 1MB - - ;// Get addresses for relocation. - ;// Write address in r5 - ;// Read address in r1 - li 5,0 - li 1, -1 ;// fill r1 with ffff..ffffff - lis 3, 0x1 - subi 3,3,1 ;// fill r3 with 0000..00ffff - xor 1,1,3 ;// mask off r1 ffff..ff0000 - - and 1,1,2 ;// and with pre_relocate's address from r2 to get start of - ;// rom section. - - ;// Update LR to low address. - and 6,2,3 - mtlr 6 - - ;// Moving 1MB , so load r2 with (1MB / 8 bytes per word) - lis 2, 0x2 - mtctr 2 -relocate_loop: - ;// The dcbst/sync/icbi/isync sequence comes from PowerISA - ld 4, 0(1) - std 4, 0(5) - dcbst 0,5 - sync - icbi 0,5 - isync - addi 1,1,8 - addi 5,5,8 - bdnz+ relocate_loop - - ;// Now that we've relocated, erase exception prefix. - mfmsr 11 - li 10, 0x40 ;// bit 6 is MSR_EP - not 10,10 - and 11,11,10 - mtmsr 11 - - ;// Jump to low address. - blr - -finished_relocate: - ;// Jump to main. - b _main - -.org _start + 0x100 -intvect_system_reset: - b _start - -.section .text -_main: - ;// Set up initial TOC Base - lis 2, main@h - ori 2, 2, main@l - ld 2,8(2) - - ;// Set up initial stack - lis 1, kernel_stack@h - ori 1, 1, kernel_stack@l - addi 1, 1, 16368 - - ;// Set up exception stack - lis 3, exception_stack@h - ori 3, 3, exception_stack@l - addi 3, 3, 16368 - mtsprg0 3 - - ;// Call main. - bl main -_main_loop: - b _main_loop - - -.section .data - .balign 1024 -kernel_stack: - .space 16*1024 -exception_stack: - .space 16*1024 - -.section .text.hreset -hreset: - b _start -- cgit v1.2.1