# HG changeset patch # User Paul Boddie # Date 1475413084 -7200 # Node ID c2fc5c9301931b7b2739e27a306955b8a6313640 # Parent e889d6aa6619c312e480f28d416b701bd43cf083 Introduced convenience functions handling page pairs. diff -r e889d6aa6619 -r c2fc5c930193 stage2/memory.h --- a/stage2/memory.h Sun May 15 23:35:50 2016 +0200 +++ b/stage2/memory.h Sun Oct 02 14:58:04 2016 +0200 @@ -1,14 +1,21 @@ #ifndef __MEMORY_H__ #define __MEMORY_H__ +/* Kernel mode addresses. */ + #define STAGE2_INIT_STACK 0x80004000 #define STAGE2_EXCEPTION_STACK 0x80008000 #define STAGE2_PAGE_TABLE 0x81400000 #define STAGE2_PAGE_TABLE_TASK 0x00008000 +/* User mode addresses. */ + #define STAGE2_TASK_STACK 0x01c00000 #define STAGE2_TASK_STACK_SIZE 0x00002000 + +/* Common configuration. */ + #define STAGE2_PAGESIZE (4 * 1024) #endif /* __MEMORY_H__ */ diff -r e889d6aa6619 -r c2fc5c930193 stage2/paging.c --- a/stage2/paging.c Sun May 15 23:35:50 2016 +0200 +++ b/stage2/paging.c Sun Oct 02 14:58:04 2016 +0200 @@ -18,8 +18,19 @@ */ #include "paging.h" +#include "memory.h" inline u32 user_address(u32 addr) { return addr & USER_ADDRESS_MASK; } + +inline u32 previous_page(u32 addr, u32 pagesize) +{ + return addr - pagesize * 2; +} + +inline u32 next_page(u32 addr, u32 pagesize) +{ + return addr + pagesize * 2; +} diff -r e889d6aa6619 -r c2fc5c930193 stage2/paging.h --- a/stage2/paging.h Sun May 15 23:35:50 2016 +0200 +++ b/stage2/paging.h Sun Oct 02 14:58:04 2016 +0200 @@ -8,6 +8,8 @@ #include "xburst_types.h" u32 user_address(u32 addr); +u32 previous_page(u32 addr, u32 pagesize); +u32 next_page(u32 addr, u32 pagesize); #endif /* __ASSEMBLER__ */ diff -r e889d6aa6619 -r c2fc5c930193 stage2/tasks.c --- a/stage2/tasks.c Sun May 15 23:35:50 2016 +0200 +++ b/stage2/tasks.c Sun Oct 02 14:58:04 2016 +0200 @@ -68,7 +68,10 @@ virtual = STAGE2_TASK_STACK; physical = STAGE2_TASK_STACK - STAGE2_TASK_STACK_SIZE * task; - init_page_table(STAGE2_PAGE_TABLE, virtual - STAGE2_PAGESIZE * 2, physical - STAGE2_PAGESIZE * 2, STAGE2_PAGESIZE, TLB_WRITE, task); + init_page_table(STAGE2_PAGE_TABLE, + previous_page(virtual, STAGE2_PAGESIZE), + previous_page(physical, STAGE2_PAGESIZE), + STAGE2_PAGESIZE, TLB_WRITE, task); /* Subtract from the stack pointer to prevent the called function from @@ -86,18 +89,33 @@ /* Map the global object table for the task. */ - init_page_table(STAGE2_PAGE_TABLE, user_address((u32) &_got_start), user_address((u32) &_got_copy_start), STAGE2_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. */ + /* Map all shared pages for the task. First, the read-only code region. */ - for (address = (u32) &_payload_start; address < (u32) &_got_start; address += STAGE2_PAGESIZE * 2) + for (address = (u32) &_payload_start; + address < (u32) &_got_start; + address = next_page(address, STAGE2_PAGESIZE)) { - init_page_table(STAGE2_PAGE_TABLE, user_address(address), user_address(address), STAGE2_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 + STAGE2_PAGESIZE * 2; address < (u32) &_memory_end; address += STAGE2_PAGESIZE * 2) + /* Make the pages after the code writable. */ + + for (address = next_page((u32) &_got_copy_end, STAGE2_PAGESIZE); + address < (u32) &_memory_end; + address = next_page(address, STAGE2_PAGESIZE)) { - init_page_table(STAGE2_PAGE_TABLE, user_address(address), user_address(address), STAGE2_PAGESIZE, TLB_WRITE, task); + init_page_table(STAGE2_PAGE_TABLE, + user_address(address), + user_address(address), + STAGE2_PAGESIZE, TLB_WRITE, task); } }