view src/os/storageKeys.c @ 150:e72f984619c7

Consolidated a lot of the defines which relate to the memory layout There is a new file (include/os/memLayout.h) which now includes just about all the #defines
author Jonathan Pevarnek <pevarnj@gmail.com>
date Wed, 02 Nov 2011 09:55:09 -0400
parents eb69d1caa83b
children b18d52f11ade
line wrap: on
line source

#include <os/storageKeys.h>
#include <os/memLayout.h>
#include <string.h>

static struct {
	u32 _zero0;
	u16 _zero1;
	u8 _zero2;
	u8 key:4,
		 f:1, //true if storage key applies for reading also
		 r:1,
		 c:1,
		 _zero3:1;
} StorageKey;

void setStorageKey(intptr_t blockPtr, u8 key, u8 fBit)
{
	StorageKey.key = key;
	StorageKey.f = fBit;
	asm volatile(
			"sske %0,%1\n"
			: /* no output */
			: "d" (StorageKey),
			  "a" (blockPtr)
	);
}

void init_storage_keys(u64 memsize)
{
	memset(&StorageKey, 0, sizeof(StorageKey));
	intptr_t ptr = 0x0;
	u8 key;
	for(ptr = 0x0; ptr < memsize; ptr += BLOCKSIZE) {
		if(ptr >= PROGRAM_STACK_START - STACK_SIZE && ptr < PROGRAM_TEXT_START + 0x10000) {
			//is in the range the program should be accessing
			key = PROGSK;
		} else {
			key = 0;
		}
		setStorageKey(ptr, key, 1);
	}
}