From 771d631f798c2d029335d5b19ec3e3bc960d1f1f Mon Sep 17 00:00:00 2001 From: NicJA Date: Sun, 8 Jan 2017 20:31:04 +0000 Subject: [PATCH] update comment about first memmap. make sure the stack isn't within our regions before registering it as a rom block. Allow sysbase in either of the fastmem blocks after a reset. git-svn-id: https://svn.aros.org/svn/aros/trunk/AROS@53186 fb15a70f-31f2-0310-bbcc-cdcc74a49acc --- arch/all-unix/kernel/kernel_startup.c | 52 +++++++++++++++++++++++++---------- 1 file changed, 38 insertions(+), 14 deletions(-) diff --git a/arch/all-unix/kernel/kernel_startup.c b/arch/all-unix/kernel/kernel_startup.c index d2973f0464..fe0a46ccef 100644 --- a/arch/all-unix/kernel/kernel_startup.c +++ b/arch/all-unix/kernel/kernel_startup.c @@ -50,7 +50,8 @@ struct HostInterface *HostIFace; THIS_PROGRAM_HANDLES_SYMBOLSET(STARTUP) DEFINESET(STARTUP); -#define CHIPMEMSIZE (16 * 1024 * 1024) +#define CHIPMEMSIZE (16 * 1024 * 1024) +#define STACKINRANGE(ptr, start, length) (((IPTR)ptr > start) && ((IPTR)ptr <= (start + length))) /* * Kickstart entry point. Note that our code area is already made read-only by the bootstrap. @@ -70,7 +71,7 @@ int __startup startup(struct TagItem *msg, ULONG magic) struct HostInterface *hif = NULL; struct mb_mmap *mmap = NULL; unsigned long mmap_len = 0; - BOOL mem_tlsf = FALSE; + BOOL mem_tlsf = FALSE, host_stack = TRUE, sysb_safe = FALSE; UWORD *ranges[] = {NULL, NULL, (UWORD *)-1}; @@ -176,24 +177,36 @@ int __startup startup(struct TagItem *msg, ULONG magic) return -1; } - /* We know that memory map has only one memory range */ + /* + * The first memory map entry represents low + * (32bit) memory, so we allocate the "chip" + * memory from it. + */ chipmh = (struct MemHeader *)(IPTR)mmap->addr; memsize = mmap->len > CHIPMEMSIZE ? CHIPMEMSIZE : mmap->len; - /* Prepare the simulated mem headers */ - /* NOTE: two mem headers are created to cover more cases of memory system */ + if (STACKINRANGE(_stack, mmap->addr, mmap->len)) + host_stack = FALSE; + if (((IPTR)SysBase > mmap->addr) && ((IPTR)SysBase + sizeof(struct ExecBase) < mmap->addr + mmap->len)) + sysb_safe = TRUE; + + /* Prepare the chip memory's header... */ krnCreateMemHeader("CHIP RAM", -5, chipmh, memsize, MEMF_CHIP|MEMF_PUBLIC|MEMF_LOCAL|MEMF_KICK|ARCH_31BIT); if (mem_tlsf) chipmh = krnConvertMemHeaderToTLSF(chipmh); bootmh = chipmh; - if (mmap->len > memsize) + /* If there is sufficient space left after the chip mem block, register it as fast ram... */ + if (mmap->len > (memsize + sizeof(struct MemHeader))) { fastmh = (struct MemHeader *)(mmap->addr + memsize); memsize = mmap->len - memsize; + krnCreateMemHeader("Fast RAM", 0, fastmh , memsize, MEMF_FAST|MEMF_PUBLIC|MEMF_LOCAL|MEMF_KICK|ARCH_31BIT); if (mem_tlsf) fastmh = krnConvertMemHeaderToTLSF(fastmh); + + /* if its larger than 1MB, use it for the boot mem */ if (memsize > (1024 * 1024)) bootmh = fastmh; } @@ -203,12 +216,19 @@ int __startup startup(struct TagItem *msg, ULONG magic) if (mmap_len > sizeof(struct mb_mmap)) { struct mb_mmap *mmapnxt = &mmap[1]; - highmh = (void *)mmapnxt->addr; + if (STACKINRANGE(_stack, mmapnxt->addr, mmapnxt->len)) + host_stack = FALSE; + if (((IPTR)SysBase > mmapnxt->addr) && ((IPTR)SysBase + sizeof(struct ExecBase) < mmapnxt->addr + mmapnxt->len)) + sysb_safe = TRUE; + krnCreateMemHeader("Fast RAM", 0, highmh, mmapnxt->len, MEMF_FAST|MEMF_PUBLIC|MEMF_LOCAL|MEMF_KICK); if (mem_tlsf) highmh = krnConvertMemHeaderToTLSF(highmh); + + if ((bootmh == chipmh) && (mmapnxt->len > (1024 * 1024))) + bootmh = highmh; } #endif @@ -216,7 +236,7 @@ int __startup startup(struct TagItem *msg, ULONG magic) * SysBase pre-validation after a warm restart. * This makes sure that it points to a valid accessible memory region. */ - if (((IPTR)SysBase < mmap->addr) || ((IPTR)SysBase + sizeof(struct ExecBase) > mmap->addr + mmap->len)) + if (!sysb_safe) SysBase = NULL; /* Create SysBase. After this we can use basic exec services, like memory allocation, lists, etc */ @@ -248,12 +268,16 @@ int __startup startup(struct TagItem *msg, ULONG magic) */ krnCreateROMHeader("Kickstart ROM", ranges[0], ranges[1]); - /* - * Stack memory header. This special memory header covers a little part of the programs - * stack so that TypeOfMem() will not return 0 for addresses pointing into the stack - * during initialization. - */ - krnCreateROMHeader("Boot stack", _stack - AROS_STACKSIZE, _stack); + if (host_stack) + { + nbug("[KRN] Protecting host process stack (0x%p - 0x%p)\n", _stack - AROS_STACKSIZE, _stack); + /* + * Stack memory header. This special memory header covers a little part of the programs + * stack so that TypeOfMem() will not return 0 for addresses pointing into the stack + * during initialization. + */ + krnCreateROMHeader("Boot stack", _stack - AROS_STACKSIZE, _stack); + } /* The following is a typical AROS bootup sequence */ InitCode(RTF_SINGLETASK, 0); /* Initialize early modules. This includes hostlib.resource. */ -- 2.11.4.GIT