# HG changeset patch # User Paul Boddie # Date 1462881485 -7200 # Node ID 593fb3352d9b0dee806eaf09594cb2554b405e2c # Parent 739db6eca61a4a7f7462318fae8b74c10dfb83ac Mapped task stacks from 0x01c0000 downwards, moved kernel stacks to 0x8000 and below, made the code region read-only. Added definitions for TLB flags. diff -r 739db6eca61a -r 593fb3352d9b include/mips.h --- a/include/mips.h Thu May 05 12:19:24 2016 +0200 +++ b/include/mips.h Tue May 10 13:58:05 2016 +0200 @@ -25,4 +25,14 @@ #define CAUSE_IV 0x00800000 +#define TLB_CACHED 0x00000018 +#define TLB_DIRTY 0x00000004 +#define TLB_VALID 0x00000002 +#define TLB_GLOBAL 0x00000001 + +#define TLB_READ (TLB_CACHED | TLB_VALID) +#define TLB_WRITE (TLB_CACHED | TLB_DIRTY | TLB_VALID) +#define TLB_ALL_READ (TLB_CACHED | TLB_VALID | TLB_GLOBAL) +#define TLB_ALL_WRITE (TLB_CACHED | TLB_DIRTY | TLB_VALID | TLB_GLOBAL) + #endif /* __MIPS_H__ */ diff -r 739db6eca61a -r 593fb3352d9b stage2/entry.S --- a/stage2/entry.S Thu May 05 12:19:24 2016 +0200 +++ b/stage2/entry.S Tue May 10 13:58:05 2016 +0200 @@ -136,9 +136,9 @@ lw $k1, 0($k1) /* &stack_pointers[current_task] */ sw $sp, 0($k1) - /* Switch to the kernel stack. */ + /* Switch to the kernel exception stack. */ - li $sp, 0x80070000 + li $sp, 0x80008000 /* Invoke the rest of the interrupt handling process. */ diff -r 739db6eca61a -r 593fb3352d9b stage2/head2.S --- a/stage2/head2.S Thu May 05 12:19:24 2016 +0200 +++ b/stage2/head2.S Tue May 10 13:58:05 2016 +0200 @@ -51,9 +51,9 @@ .word 0 real_start: - /* Initialise the stack. */ + /* Initialise the default kernel stack. */ - la $sp, 0x80080000 + la $sp, 0x80004000 /* Initialise the globals pointer. */ diff -r 739db6eca61a -r 593fb3352d9b stage2/tasks.c --- a/stage2/tasks.c Thu May 05 12:19:24 2016 +0200 +++ b/stage2/tasks.c Tue May 10 13:58:05 2016 +0200 @@ -19,6 +19,7 @@ #include "cpu.h" #include "cpu_op.h" +#include "mips.h" #include "paging.h" #include "tasks.h" @@ -33,7 +34,7 @@ /* Address locations and paging configuration. */ -const u32 stack_start = 0x00080000; +const u32 stack_start = 0x01c00000; const u32 stack_size = 0x00002000; const u32 pagesize = 4 * 1024; @@ -65,13 +66,14 @@ /* Each task employs a stack at a multiple of the given start address in - physical memory, but at the same address in virtual memory. + physical memory, but at the same address in virtual memory. Task zero + is never started. */ virtual = stack_start; physical = stack_start - stack_size * task; - init_page_table(page_table_start, virtual - pagesize * 2, physical - pagesize * 2, pagesize, 0x1e, task); + init_page_table(page_table_start, virtual - pagesize * 2, physical - pagesize * 2, pagesize, TLB_WRITE, task); /* Subtract from the stack pointer to prevent the called function from @@ -89,18 +91,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, 0x1e, task); + init_page_table(page_table_start, user_address((u32) &_got_start), user_address((u32) &_got_copy_start), pagesize, TLB_READ, task); /* Map all shared pages for the task. */ for (address = (u32) &_payload_start; address < (u32) &_got_start; address += pagesize * 2) { - init_page_table(page_table_start, user_address(address), user_address(address), pagesize, 0x1e, task); + init_page_table(page_table_start, user_address(address), user_address(address), pagesize, TLB_READ, task); } for (address = (u32) &_got_copy_end + pagesize * 2; address < (u32) &_memory_end; address += pagesize * 2) { - init_page_table(page_table_start, user_address(address), user_address(address), pagesize, 0x1e, task); + init_page_table(page_table_start, user_address(address), user_address(address), pagesize, TLB_WRITE, task); } }