# HG changeset patch # User Paul Boddie # Date 1463254615 -7200 # Node ID aac340efb570ed225c59a2e0a9695d7e25a405ea # Parent 593fb3352d9b0dee806eaf09594cb2554b405e2c Introduced memory layout headers and consolidated memory-related definitions. Made the linker scripts more consistent. diff -r 593fb3352d9b -r aac340efb570 stage1/board.c --- a/stage1/board.c Tue May 10 13:58:05 2016 +0200 +++ b/stage1/board.c Sat May 14 21:36:55 2016 +0200 @@ -5,7 +5,7 @@ * Copyright (C) 2005-2006 Ingenic Semiconductor, * Copyright (C) 2006 Stefan Roese, DENX Software Engineering, sr@denx.de. * Copyright (C) Xiangfu Liu - * Copyright (C) 2015 Paul Boddie + * Copyright (C) 2015, 2016 Paul Boddie * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -28,6 +28,7 @@ #include "jz4740.h" #endif +#include "memory.h" #include "sdram.h" #include "usb_boot_defines.h" @@ -47,7 +48,7 @@ { /* Get the fw args from memory. See head1.S for the memory layout. */ - fw_args = (struct fw_args *)0x80002008; + fw_args = (struct fw_args *) STAGE1_ARGS; FW_CPU_ID = fw_args->cpu_id ; /* Where the arguments have not been initialised, use the defaults. */ diff -r 593fb3352d9b -r aac340efb570 stage1/board.h --- a/stage1/board.h Tue May 10 13:58:05 2016 +0200 +++ b/stage1/board.h Sat May 14 21:36:55 2016 +0200 @@ -3,9 +3,9 @@ /* Initialisation functions. */ -void load_args(void); -void gpio_init(void); -void pll_init(void); -void sdram_init(void); +void load_args(); +void gpio_init(); +void pll_init(); +void sdram_init(); #endif /* __BOARD_H__ */ diff -r 593fb3352d9b -r aac340efb570 stage1/head1.S --- a/stage1/head1.S Tue May 10 13:58:05 2016 +0200 +++ b/stage1/head1.S Sat May 14 21:36:55 2016 +0200 @@ -20,13 +20,14 @@ * along with this program. If not, see . */ +#include "memory.h" +#include "mips.h" + .text .extern c_main .globl _start .set noreorder -#include "mips.h" - _start: b real_start nop @@ -56,7 +57,7 @@ /* Setup stack, jump to C code. */ - la $sp, 0x80004000 + la $sp, STAGE1_STACK j c_main nop diff -r 593fb3352d9b -r aac340efb570 stage1/memory.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/stage1/memory.h Sat May 14 21:36:55 2016 +0200 @@ -0,0 +1,7 @@ +#ifndef __MEMORY_H__ +#define __MEMORY_H__ + +#define STAGE1_ARGS 0x80002008 +#define STAGE1_STACK 0x80004000 + +#endif /* __MEMORY_H__ */ diff -r 593fb3352d9b -r aac340efb570 stage1/stage1.ld --- a/stage1/stage1.ld Tue May 10 13:58:05 2016 +0200 +++ b/stage1/stage1.ld Sat May 14 21:36:55 2016 +0200 @@ -1,31 +1,26 @@ OUTPUT_ARCH(mips) ENTRY(_start) -MEMORY -{ - ram : ORIGIN = 0x80002000 , LENGTH = 0x100000 -} SECTIONS { - . = ALIGN(4); - .text : { *(.text*) } > ram + . = 0x80002000; + .text : { *(.text*) } . = ALIGN(4); - .rodata : { *(.rodata*) } > ram + .rodata : { *(.rodata*) } . = ALIGN(4); - .sdata : { *(.sdata*) } > ram + .sdata : { *(.sdata*) } . = ALIGN(4); - .data : { *(.data*) *(.scommon*) *(.reginfo*) } > ram + .data : { *(.data*) *(.scommon*) *(.reginfo*) } _gp = ABSOLUTE(.); /* Base of small data */ - .got : { *(.got*) } > ram + .got : { *(.got*) } . = ALIGN(4); - .sbss : { *(.sbss*) } > ram - .bss : { *(.bss*) } > ram + .sbss : { *(.sbss*) } + .bss : { *(.bss*) } . = ALIGN (4); } - diff -r 593fb3352d9b -r aac340efb570 stage2/cpu.c --- a/stage2/cpu.c Tue May 10 13:58:05 2016 +0200 +++ b/stage2/cpu.c Sat May 14 21:36:55 2016 +0200 @@ -24,8 +24,9 @@ #include "cpu.h" #include "cpu_op.h" +#include "memory.h" +#include "paging.h" #include "sdram.h" -#include "paging.h" void flush_icache_all(void) { @@ -120,7 +121,7 @@ 0x1000 * 8 == 0x8000 bytes */ - u32 base = page_table + page_table_task_size * asid; + u32 base = page_table + STAGE2_PAGE_TABLE_TASK * asid; /* Each page table entry corresponds to a pair of 4KB pages and holds two values. */ diff -r 593fb3352d9b -r aac340efb570 stage2/entry.S --- a/stage2/entry.S Tue May 10 13:58:05 2016 +0200 +++ b/stage2/entry.S Sat May 14 21:36:55 2016 +0200 @@ -17,8 +17,8 @@ * along with this program. If not, see . */ +#include "memory.h" #include "mips.h" -#include "paging.h" .text .extern interrupt_handler @@ -45,9 +45,9 @@ /* Otherwise, load the page table entries. */ andi $k1, $k0, 0xff /* ASID */ - li $k0, page_table_task_size - mul $k0, $k0, $k1 /* [ASID] (ASID * page_table_task_size) */ - li $k1, page_table_start /* page_table */ + li $k0, STAGE2_PAGE_TABLE_TASK + mul $k0, $k0, $k1 /* [ASID] (ASID * STAGE2_PAGE_TABLE_TASK) */ + li $k1, STAGE2_PAGE_TABLE /* page_table */ addu $k1, $k0, $k1 /* page_table[ASID] */ mfc0 $k0, CP0_CONTEXT @@ -138,7 +138,7 @@ /* Switch to the kernel exception stack. */ - li $sp, 0x80008000 + li $sp, STAGE2_EXCEPTION_STACK /* Invoke the rest of the interrupt handling process. */ diff -r 593fb3352d9b -r aac340efb570 stage2/head2.S --- a/stage2/head2.S Tue May 10 13:58:05 2016 +0200 +++ b/stage2/head2.S Sat May 14 21:36:55 2016 +0200 @@ -20,6 +20,7 @@ * along with this program. If not, see . */ +#include "memory.h" #include "mips.h" #include "sdram.h" @@ -53,7 +54,7 @@ real_start: /* Initialise the default kernel stack. */ - la $sp, 0x80004000 + la $sp, STAGE2_INIT_STACK /* Initialise the globals pointer. */ diff -r 593fb3352d9b -r aac340efb570 stage2/memory.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/stage2/memory.h Sat May 14 21:36:55 2016 +0200 @@ -0,0 +1,14 @@ +#ifndef __MEMORY_H__ +#define __MEMORY_H__ + +#define STAGE2_INIT_STACK 0x80004000 +#define STAGE2_EXCEPTION_STACK 0x80008000 + +#define STAGE2_PAGE_TABLE 0x81400000 +#define STAGE2_PAGE_TABLE_TASK 0x00008000 + +#define STAGE2_TASK_STACK 0x01c00000 +#define STAGE2_TASK_STACK_SIZE 0x00002000 +#define STAGE2_PAGESIZE (4 * 1024) + +#endif /* __MEMORY_H__ */ diff -r 593fb3352d9b -r aac340efb570 stage2/paging.h --- a/stage2/paging.h Tue May 10 13:58:05 2016 +0200 +++ b/stage2/paging.h Sat May 14 21:36:55 2016 +0200 @@ -1,9 +1,6 @@ #ifndef __PAGING_H__ #define __PAGING_H__ -#define page_table_start 0x81400000 -#define page_table_task_size 0x00008000 - #define USER_ADDRESS_MASK 0x7fffffff #ifndef __ASSEMBLER__ diff -r 593fb3352d9b -r aac340efb570 stage2/tasks.c --- a/stage2/tasks.c Tue May 10 13:58:05 2016 +0200 +++ b/stage2/tasks.c Sat May 14 21:36:55 2016 +0200 @@ -19,6 +19,7 @@ #include "cpu.h" #include "cpu_op.h" +#include "memory.h" #include "mips.h" #include "paging.h" #include "tasks.h" @@ -32,12 +33,6 @@ u32 *current_stack_pointer; u32 *current_registers; -/* Address locations and paging configuration. */ - -const u32 stack_start = 0x01c00000; -const u32 stack_size = 0x00002000; -const u32 pagesize = 4 * 1024; - /* A reference to locations for the symbol tables. */ extern u32 _got_start, _got_copy_start, _got_copy_end; @@ -70,10 +65,10 @@ is never started. */ - virtual = stack_start; - physical = stack_start - stack_size * task; + virtual = STAGE2_TASK_STACK; + physical = STAGE2_TASK_STACK - STAGE2_TASK_STACK_SIZE * task; - init_page_table(page_table_start, virtual - pagesize * 2, physical - pagesize * 2, pagesize, TLB_WRITE, task); + init_page_table(STAGE2_PAGE_TABLE, virtual - STAGE2_PAGESIZE * 2, physical - STAGE2_PAGESIZE * 2, STAGE2_PAGESIZE, TLB_WRITE, task); /* Subtract from the stack pointer to prevent the called function from @@ -91,18 +86,18 @@ /* Map the global object table for the task. */ - init_page_table(page_table_start, user_address((u32) &_got_start), user_address((u32) &_got_copy_start), pagesize, TLB_READ, task); + init_page_table(STAGE2_PAGE_TABLE, user_address((u32) &_got_start), user_address((u32) &_got_copy_start), STAGE2_PAGESIZE, TLB_READ, task); /* Map all shared pages for the task. */ - for (address = (u32) &_payload_start; address < (u32) &_got_start; address += pagesize * 2) + for (address = (u32) &_payload_start; address < (u32) &_got_start; address += STAGE2_PAGESIZE * 2) { - init_page_table(page_table_start, user_address(address), user_address(address), pagesize, TLB_READ, task); + init_page_table(STAGE2_PAGE_TABLE, user_address(address), user_address(address), STAGE2_PAGESIZE, TLB_READ, task); } - for (address = (u32) &_got_copy_end + pagesize * 2; address < (u32) &_memory_end; address += pagesize * 2) + for (address = (u32) &_got_copy_end + STAGE2_PAGESIZE * 2; address < (u32) &_memory_end; address += STAGE2_PAGESIZE * 2) { - init_page_table(page_table_start, user_address(address), user_address(address), pagesize, TLB_WRITE, task); + init_page_table(STAGE2_PAGE_TABLE, user_address(address), user_address(address), STAGE2_PAGESIZE, TLB_WRITE, task); } }