emb426 windows ce memory architecture steve maillet ceo/chief software architect embeddedfusion

32
EMB426 EMB426 Windows CE Memory Windows CE Memory Architecture Architecture Steve Maillet Steve Maillet CEO/Chief Software Architect CEO/Chief Software Architect EmbeddedFusion EmbeddedFusion

Upload: maude-dawson

Post on 11-Jan-2016

219 views

Category:

Documents


1 download

TRANSCRIPT

Page 1: EMB426 Windows CE Memory Architecture Steve Maillet CEO/Chief Software Architect EmbeddedFusion

EMB426EMB426

Windows CE Memory Windows CE Memory ArchitectureArchitecture

Steve MailletSteve MailletCEO/Chief Software ArchitectCEO/Chief Software ArchitectEmbeddedFusionEmbeddedFusion

Page 2: EMB426 Windows CE Memory Architecture Steve Maillet CEO/Chief Software Architect EmbeddedFusion
Page 3: EMB426 Windows CE Memory Architecture Steve Maillet CEO/Chief Software Architect EmbeddedFusion

Part IPart IArchitecture and conceptsArchitecture and concepts

Virtual MemoryVirtual Memory

Kernel Mode versus User ModeKernel Mode versus User Mode

Statically mapped memoryStatically mapped memory

Process memoryProcess memory

System API CallsSystem API Calls

Access PermissionsAccess Permissions

Page 4: EMB426 Windows CE Memory Architecture Steve Maillet CEO/Chief Software Architect EmbeddedFusion

Virtual Memory ModelVirtual Memory Model

Single 32-bit (4 Gigabyte) flat virtual Single 32-bit (4 Gigabyte) flat virtual memory address spacememory address space

Permits efficient use of physical Permits efficient use of physical memory with protectionmemory with protection

Virtual addresses translated to Virtual addresses translated to physical addresses by MMUphysical addresses by MMU

A valid virtual address maps to a A valid virtual address maps to a physical addressphysical address

Static or Dynamically mapped virtual Static or Dynamically mapped virtual addressingaddressing

Page 5: EMB426 Windows CE Memory Architecture Steve Maillet CEO/Chief Software Architect EmbeddedFusion

Virtual MemoryVirtual Memory

2 GB2 GB

UserUserSpaceSpace

Slot 97: NK.EXESlot 97: NK.EXE

ReservedReserved

Statically Mapped Statically Mapped Virtual Addresses: Virtual Addresses:

Un-CachedUn-Cached

Statically Mapped Statically Mapped Virtual Addresses: Virtual Addresses:

CachedCached Slot 0 – Current ProcessSlot 0 – Current Process

Slot 1 – XIP DLL codeSlot 1 – XIP DLL code

Slots 2-32 - ProcessesSlots 2-32 - Processes

Slots 33-63Slots 33-63

Object Store and Object Store and Memory-Mapped FilesMemory-Mapped Files

FFFF FFFFFFFF FFFF

E000 0000E000 0000

C400 0000C400 0000

C200 0000C200 0000

C000 0000C000 0000

A000 0000A000 0000

8000 00008000 0000

7FFF FFFF7FFF FFFF

4200 00004200 0000

0400 00000400 0000

0200 00000200 0000

0000 00000000 0000

Total 4 GB Virtual SpaceTotal 4 GB Virtual Space

2 GB2 GB

Kernel Kernel SpaceSpace

Kernel SpaceKernel Space User SpaceUser Space

ReservedReserved

Kernel Addresses: Kernel Addresses: KPAGE, Trap Area, KPAGE, Trap Area,

OthersOthers

Page 6: EMB426 Windows CE Memory Architecture Steve Maillet CEO/Chief Software Architect EmbeddedFusion

Kernel Mode Versus Kernel Mode Versus User ModeUser Mode

ONLY Difference is access to different regionsONLY Difference is access to different regionsKernel mode code has full access to all memoryKernel mode code has full access to all memory

Process protection still applies!Process protection still applies!

User Mode code only has access to User SpaceUser Mode code only has access to User Space

Kernel Space (0x80000000 – 0xFFFFFFFF)Kernel Space (0x80000000 – 0xFFFFFFFF)Used only by Kernel-mode code with privileged access Used only by Kernel-mode code with privileged access (“Kmode”)(“Kmode”)

SetKMode() protected API or ROMFLAGS Setting for ALL threads SetKMode() protected API or ROMFLAGS Setting for ALL threads in the systemin the system

User Space (0x00000000 – 0x7FFFFFFF)User Space (0x00000000 – 0x7FFFFFFF)Organized as 64 slots of 32 MB (225 bytes) eachOrganized as 64 slots of 32 MB (225 bytes) each

Applications, DLLs and Data located hereApplications, DLLs and Data located here

Page 7: EMB426 Windows CE Memory Architecture Steve Maillet CEO/Chief Software Architect EmbeddedFusion

Statically Mapped MemoryStatically Mapped Memory

2 GB

2 GB

UserUser

512 MB

Uncached

512 MB

Cached

32 MB Flash

Physical MemoryPhysical Memory Virtual MemoryVirtual Memory

0400000004000000

8200000082000000

8000 00008000 0000

A000 0000A000 0000

C000 0000C000 0000

0000000000000000

64 MB RAM

0000 00000000 0000

64 MB RAM

32 MB Flash

64 MB RAM

FFFF FFFFFFFF FFFF

AddressTranslation

32 MB Flash

Kernel Kernel SpaceSpace

UserSpace

Page 8: EMB426 Windows CE Memory Architecture Steve Maillet CEO/Chief Software Architect EmbeddedFusion

Statically Mapped MemoryStatically Mapped Memory

x86, ARMx86, ARMOEM provides OEMAddressTable in OAL OEM provides OEMAddressTable in OAL to define initial mappingsto define initial mappings

MIPS, SHxMIPS, SHxMapping is fixed in the MMU architectureMapping is fixed in the MMU architecture

Page 9: EMB426 Windows CE Memory Architecture Steve Maillet CEO/Chief Software Architect EmbeddedFusion

Process MemoryProcess Memory01FF FFFF01FF FFFF

0001 00000001 0000

0000 00000000 0000

32 MB Process Space32 MB Process Space

Free Virtual SpaceFree Virtual Space

Slot 30Slot 30

Slot 31Slot 31

Slot 32Slot 32

. . .. . .

Slot 63Slot 63

. . .. . .

Current ProcessCurrent Process

XIP ROM DLLsXIP ROM DLLs

nk.exenk.exe

filesys.exefilesys.exe

shell.exeshell.exe

device.exedevice.exe

gwes.exegwes.exe

Resource DLLsResource DLLs

Slot 2Slot 2

Slot 3Slot 3

Slot 4Slot 4

Slot 5Slot 5

Slot 1Slot 1

Slot 0Slot 0

. . .. . .

Slot 97Slot 97C400 0000C400 0000

C200 0000C200 0000

0A00 00000A00 0000

3E00 00003E00 0000

3C00 00003C00 0000

4000 00004000 0000

4200 00004200 0000

0000 00000000 0000

0400 00000400 0000

0200 00000200 0000

0600 00000600 0000

0800 00000800 0000

0C00 00000C00 0000

8000 00008000 0000

7E00 00007E00 0000

Page 10: EMB426 Windows CE Memory Architecture Steve Maillet CEO/Chief Software Architect EmbeddedFusion

System API CallsSystem API CallsApplicationApplication

Win32 Win32 API API

ThunksThunks

Local Process ServicesLocal Process Services

PSL Process PSL Process SwitchingSwitching

filesys.exefilesys.exe gwes.exegwes.exe device.exedevice.exeVirtual MemoryVirtual MemoryProcess/ThreadProcess/ThreadException HandlingException HandlingSchedulingSchedulingLoaderLoaderSynchronizationSynchronizationInitializationInitializationProcess SwitchingProcess SwitchingMemory-Mapped FileMemory-Mapped File

Hardware AbstractionHardware Abstraction

Memory MapMemory MapInterruptsInterruptsBus MapBus Map

Function CallFunction Call

TrapsTraps

Process InterfaceProcess Interface

DLL InterfaceDLL Interface

Interrupt Interrupt HandlingHandling

OALOAL

HeapHeap

Coredll.dllCoredll.dll

N.EXEN.EXE

Nk.libNk.lib

services.exeservices.exeshell.exeshell.exe

Page 11: EMB426 Windows CE Memory Architecture Steve Maillet CEO/Chief Software Architect EmbeddedFusion

System API CallsSystem API Calls

Coredll.dllCoredll.dllLocated at the top of every process slotLocated at the top of every process slotFields system API calls from user mode threadsFields system API calls from user mode threadsImplements some system API calls directlyImplements some system API calls directlyCauses an exception (trap) to pass on system Causes an exception (trap) to pass on system API requestAPI request

KernelKernelCatches system API request exception trapsCatches system API request exception trapsDispatches to a system EXE to fulfill requestDispatches to a system EXE to fulfill requestUser mode thread migrated to system EXE User mode thread migrated to system EXE process spaceprocess spaceAccess rights of user mode thread inherits current Access rights of user mode thread inherits current process rightsprocess rights

Page 12: EMB426 Windows CE Memory Architecture Steve Maillet CEO/Chief Software Architect EmbeddedFusion

System API Calling System API Calling MechanismMechanism

User mode User mode threadthread

Win32 API Win32 API ThunksThunks

Function CallFunction Call

Coredll.dllCoredll.dll

App.exeApp.exe

KernelKernelTrapTrap

Win32 API Win32 API DispatchDispatch

Nk.exeNk.exe

JumpJumpFunction Function

CodeCode

system EXEsystem EXE

ReturnReturnCallCall

Page 13: EMB426 Windows CE Memory Architecture Steve Maillet CEO/Chief Software Architect EmbeddedFusion

Access PermissionsAccess Permissions

Process Access PermissionsProcess Access PermissionsAccess permissions set on per-thread Access permissions set on per-thread basisbasis

GetProcPermissions() / SetProcPermissions()GetProcPermissions() / SetProcPermissions()

Threads accessing other process slots Threads accessing other process slots require permissionrequire permission

Violations cause exceptions reported to Violations cause exceptions reported to the Kernelthe Kernel

Structured exception handling allows Structured exception handling allows process to trap its faultsprocess to trap its faults

Page 14: EMB426 Windows CE Memory Architecture Steve Maillet CEO/Chief Software Architect EmbeddedFusion

Access PermissionsAccess Permissions

Resource DLLs and Memory-Mapped Resource DLLs and Memory-Mapped filesfiles

Accessible by threads in all processesAccessible by threads in all processes

Shared HeapsShared HeapsWritable by threads in creating processWritable by threads in creating process

Read Only by threads in other processesRead Only by threads in other processes

Object Store (Optional)Object Store (Optional)Accessible only by kernel file system Accessible only by kernel file system (filesys.exe)(filesys.exe)

Page 15: EMB426 Windows CE Memory Architecture Steve Maillet CEO/Chief Software Architect EmbeddedFusion

Access PermissionsAccess PermissionsSystem call process contextsSystem call process contexts

GetCurrentProcess()GetCurrentProcess()Process context in which the current thread is runningProcess context in which the current thread is running

GetOwnerProcess()GetOwnerProcess()Original process that created the current threadOriginal process that created the current thread

GetCallerProcessGetCallerProcessProcess that thread most recently migrated fromProcess that thread most recently migrated from

MapCallerPtr()MapCallerPtr()Adjusts a pointer to a specific process slot while validating Adjusts a pointer to a specific process slot while validating caller has access to the datacaller has access to the data

Typically maps a Slot 0 relative address to the owing Typically maps a Slot 0 relative address to the owing processes slot so a driver can use itprocesses slot so a driver can use it

Page 16: EMB426 Windows CE Memory Architecture Steve Maillet CEO/Chief Software Architect EmbeddedFusion

Access PermissionsAccess Permissions

App.exe

Owner Process = App.exeCaller Process = noneCurrent Process = App.exe

Device.exe

Owner Process = App.exeCaller Process = FileSys.exeCurrent Process = Device.exe

FileSys Cache

App.exe

Owner Process = App.exeCaller Process = noneCurrent Process = App.exe

FileSys.exe

Owner Process = App.exeCaller Process = App.exeCurrent Process = FileSys.exe

Device.exe

Owner Process = App.exeCaller Process = FileSys.exeCurrent Process = Device.exe

Application Buffer

FileSys Cache

Security Security ViolationViolation

Page 17: EMB426 Windows CE Memory Architecture Steve Maillet CEO/Chief Software Architect EmbeddedFusion

Part IIPart IIBuild ConfigurationBuild Configuration

BIB FilesBIB Files

BIB Memory TypesBIB Memory Types

ROMOFFSETROMOFFSET

Example SystemExample System

Page 18: EMB426 Windows CE Memory Architecture Steve Maillet CEO/Chief Software Architect EmbeddedFusion

BIB FilesBIB Files

MEMORY section MEMORY section Defines the platform memory informationDefines the platform memory information

Partitions the physical memory into Data Partitions the physical memory into Data memory and Program memorymemory and Program memory

;Name Start address Size (bytes) Type;-----------------------------------------------NK 80300000 01E00000 RAMIMAGE ; (30M) "ROM"RAM 82100000 01E00000 RAM ; (30M)

;Name Start address Size (bytes) Type;-----------------------------------------------NK 80300000 01E00000 RAMIMAGE ; (30M) "ROM"RAM 82100000 01E00000 RAM ; (30M)

Page 19: EMB426 Windows CE Memory Architecture Steve Maillet CEO/Chief Software Architect EmbeddedFusion

BIB Memory Section TypesBIB Memory Section Types

TypeType DescriptionDescriptionRAMIMAGERAMIMAGE OS Image (Read + Execute ONLY)OS Image (Read + Execute ONLY)

MUST start on a 64K boundary!MUST start on a 64K boundary!RAMRAM RAM for OS to partitionRAM for OS to partitionRESERVEDRESERVED Reserved region OS won’t useReserved region OS won’t useNANDIMAGENANDIMAGE Used with BINFS to mark memory Used with BINFS to mark memory

region for paging Files From NAND region for paging Files From NAND storage devicesstorage devices

FIXUPVARFIXUPVAR Used to set the value of a variable Used to set the value of a variable during image build timeduring image build time

Page 20: EMB426 Windows CE Memory Architecture Steve Maillet CEO/Chief Software Architect EmbeddedFusion

BIB FilesBIB Files

Indicate the modules and components that Indicate the modules and components that should be included in the imageshould be included in the image

Text files with four types of sectionsText files with four types of sectionsThe FILES section: Memory reservation for static The FILES section: Memory reservation for static data filesdata files

;Name Path Memory Type-------------------------------------------------------Tahoma.ttf $(_FLATRELEASEDIR)\Tahoma.ttf NK SHU

;Name Path Memory Type-------------------------------------------------------Tahoma.ttf $(_FLATRELEASEDIR)\Tahoma.ttf NK SHU

Taskman.exe $(_FLATRELEASEDIR)\Taskman.exe NK Taskman.exe $(_FLATRELEASEDIR)\Taskman.exe NK

The MODULES section: Specifies object module to The MODULES section: Specifies object module to be loaded in memorybe loaded in memory

Page 21: EMB426 Windows CE Memory Architecture Steve Maillet CEO/Chief Software Architect EmbeddedFusion

BIN File FormatBIN File Format

Header BlockHeader BlockB0000FB0000F Start AddressStart Address Image LengthImage Length

StartStart LengthLength ChecksumChecksum Data…Data…

00 Starting IPStarting IP 00

BIN Record(s)BIN Record(s)

Terminating RecordTerminating Record

Page 22: EMB426 Windows CE Memory Architecture Steve Maillet CEO/Chief Software Architect EmbeddedFusion

ROMOFFSETROMOFFSET

ROMOFFSET is used to adjust the ROMOFFSET is used to adjust the address of records in the Microsoft BIN address of records in the Microsoft BIN file formatfile format

Boot loader uses physical memoryBoot loader uses physical memory

Boot loader copies image from flash Boot loader copies image from flash to RAMto RAM

Boot loader copies image from diskBoot loader copies image from disk

Page 23: EMB426 Windows CE Memory Architecture Steve Maillet CEO/Chief Software Architect EmbeddedFusion

ROMOFFSETROMOFFSETROMIMAGE pseudo codeROMIMAGE pseudo code

WriteBinRecord(UINT32 StartAddress, UINT32 RomOffset,

UINT32 Length, UINT8* pData)

{

Write(StartAddress + RomOffset);Write(StartAddress + RomOffset);

Write(Length);

UINT32 ChkSum = WriteBinData(pData, Length);

Write(ChkSum);

}

Page 24: EMB426 Windows CE Memory Architecture Steve Maillet CEO/Chief Software Architect EmbeddedFusion

Example SystemExample System

ARM core CPUARM core CPUOEMAddressTable requiredOEMAddressTable required

32M Ram at physical address 32M Ram at physical address 0x082000000x08200000

32M Flash at physical address 32M Flash at physical address 0x000000000x00000000

1M Block of “On-Chip” devices at 1M Block of “On-Chip” devices at physical address 0x01200000physical address 0x01200000

Page 25: EMB426 Windows CE Memory Architecture Steve Maillet CEO/Chief Software Architect EmbeddedFusion

Static Mapped MemoryStatic Mapped MemoryCachedCached

RAMIMAGE

RAM

...

00x8x8 02000000200000

00x8x8 00000000000000

SDRAMSDRAM

00x9FFFFFFFx9FFFFFFF

00x9FFx9FF0000000000On-Chip Devices

Page 26: EMB426 Windows CE Memory Architecture Steve Maillet CEO/Chief Software Architect EmbeddedFusion

Static Mapped MemoryStatic Mapped MemoryUncachedUncached

RAMIMAGE

RAM

...

00xAxA02000000200000

00xAxA00000000000000

SDRAMSDRAM

00xBFFFFFFFxBFFFFFFF

00xBFFxBFF0000000000

On-Chip Devices

Page 27: EMB426 Windows CE Memory Architecture Steve Maillet CEO/Chief Software Architect EmbeddedFusion

OEMAddressTableOEMAddressTable

Cached Cached AddressAddress

Physical Physical AddressAddress

Size Size (MB)(MB)

DescriptionDescription

0x800000000x80000000 0x082000000x08200000 3232 RAMRAM

0x9CD000000x9CD00000 0x000000000x00000000 3232 FLASHFLASH

0x9FF000000x9FF00000 0x012000000x01200000 11 On Chip On Chip DevicesDevices

00 00 00 NULL NULL TerminatorTerminator

Page 28: EMB426 Windows CE Memory Architecture Steve Maillet CEO/Chief Software Architect EmbeddedFusion

SummarySummary

Virtual memory central to Windows CEVirtual memory central to Windows CE

Configuration controlled by OEMsConfiguration controlled by OEMsCONFIG.BIBCONFIG.BIB

Device developers need to understand Device developers need to understand and keep total system in mind when and keep total system in mind when configuring their device imagesconfiguring their device images

Page 29: EMB426 Windows CE Memory Architecture Steve Maillet CEO/Chief Software Architect EmbeddedFusion

While At MEDC 2005…While At MEDC 2005…Fill outFill out an evaluation for this session an evaluation for this session

Randomly selected instant Randomly selected instant WINWIN prizes! prizes!

Use Use real technology in a labreal technology in a lab Instructor led Instructor led Reef E/FReef E/F & & Breakers LBreakers L

Self-paced Self-paced Reef B/CReef B/C

VisitVisit the Microsoft Product Pavilion the Microsoft Product Pavilion

in the Exhibit Hall in the Exhibit Hall Shorelines BShorelines B

Page 30: EMB426 Windows CE Memory Architecture Steve Maillet CEO/Chief Software Architect EmbeddedFusion

After The Conference…After The Conference…

DevelopDevelop

BuildBuild

InstallInstall

BuildBuild

JoinJoin

InstallInstall

EnterEnter

JoinJoin

Full-featured trial versions of Windows CE Full-featured trial versions of Windows CE and/or Windows XP Embeddedand/or Windows XP Embedded

Cool stuff & tell us about it: Cool stuff & tell us about it: msdn.microsoft.com/embedded/community

Windows Embedded Partner Program:Windows Embedded Partner Program:www.mswep.com

Windows Mobile 5.0 Eval Kit including Windows Mobile 5.0 Eval Kit including Visual Studio 2005 Beta 2Visual Studio 2005 Beta 2

Mobile2Market Contest and win up to $25000: Mobile2Market Contest and win up to $25000: mobile2marketcontest.com

Microsoft Solutions Partner Program:Microsoft Solutions Partner Program:partner.microsoft.com

Page 31: EMB426 Windows CE Memory Architecture Steve Maillet CEO/Chief Software Architect EmbeddedFusion

Tools & ResourcesTools & Resources

msdn.microsoft.com/msdn.microsoft.com/ embeddedembedded

microsoft.public.microsoft.public. windowsxp.embeddedwindowsxp.embedded windowsce.platbuilderwindowsce.platbuilder windowsce.embedded.vcwindowsce.embedded.vc

blogs.msdn.com/blogs.msdn.com/ mikehallmikehall

Windows CE 5.0 Eval KitWindows CE 5.0 Eval KitWindows XP Embedded Eval KitWindows XP Embedded Eval Kit

msdn.microsoft.com/msdn.microsoft.com/ mobilitymobility

microsoft.public.microsoft.public. pocketpc.developer pocketpc.developer smartphone.developer smartphone.developer dotnet.framework.compactframeworkdotnet.framework.compactframework

blogs.msdn.com/blogs.msdn.com/ windowsmobilewindowsmobile vsdteamvsdteam netcfteamnetcfteam

Windows Mobile 5.0 Eval KitWindows Mobile 5.0 Eval Kit

WebsitesWebsites

NewsgroupsNewsgroups

BlogsBlogs

ToolsTools

BuildBuild DevelopDevelop

Page 32: EMB426 Windows CE Memory Architecture Steve Maillet CEO/Chief Software Architect EmbeddedFusion

© 2005 Microsoft Corporation. All rights reserved.This presentation is for informational purposes only. Microsoft makes no warranties, express or implied, in this summary.