L4RE學習筆記——服務介紹
1.服務概述:
Sigma0,theRootPager
Sigma0是L4Re的第一個非常有用的task,用於處理root task(moe)的缺頁異常。它可以認為是核心的一部分,儘管它執行在非特權模式。
Moe,theRootTask
Moe是L4的根任務,負責bootstrap the system,並且為上層應用提供基本的資源管理,包括:
Memory:以動態分配((L4Re::Mem_alloc, L4::Factory)和資料空間((L4Re::Dataspace)方式
Cpu:以排程(L4::Scheduler)方式
Virtual memory management:L4Re::Rm
Moe還進一步實現了
為了啟動系統,Moe啟動了一個ELF程式——init程序。Init程序通常就是“Ned”,它可以訪問moe管理的所有資源和sigma0提供的介面。
Ned,theDefaultInitProcess
為了讓root task免於複雜指令碼引擎,同時避免啟動過程中特定的依賴(這些依賴可能造成死鎖),真正系統的啟動和配置由一個外部的task來管理——init程序(Ned)。
系統配置通過lua指令碼。
Io,thePlatformandDeviceResourceManager
因為
OtherServers
以下的服務包,位於L4Re的頂層環境中:
Rtc,the Real-Time Clock Server
fb-drv,the Low-Level Graphics Driver(可以跑VESA)
Uvmm,the virtual machine monitor
Mag,the GUI Multiplexer
Cons,the Console Multiplexer
2.1 Moe,theRoot-Task
Moe提供L4Re抽象物件的一些預設實現:data space(L4Re::Dataspace)、region map(L4Re::Rm)、memory allocator(L4Re:Mem_alloc,L4Re:Factory)、name space(L4Re::Namespace)。
Moe由以下子系統構成:
Name-Space Provider — 提供名字空間的例項
BootFS — 提供啟動過程中load檔案的訪問
Log Subsystem —Log
Scheduler Subsystem —排程
Memory Allocator, Generic Factory — 記憶體分配
Dataspace可以分配任意大小,分配粒度為機器頁大小(L4_PAGESIZE)。
Name-Space Provider
Moe單獨建立一個名字空間給BootFS,即“rom”目錄。
BootFS提供一個針對啟動過程中載入檔案的名字空間(rom),這些檔案可以連結進boot image或者通過bootloader(GRUB)載入。
rom目錄是L4Re::Namespace物件,而裡面的每個檔案則是L4Re::Dataspace物件
預設所有的檔案都是在namaspace——rom中可見和只讀的。檔案還可以提供一個引數“:rw”來標記modules是可讀寫的。這樣moe會將其放在另一個namespace——rwfs。
在modules.list中的寫法示例:
module somemodule : rw
Command-LineOptions
moe[--debug=<flags>][--init=<binary>][--l4re-dbg=<flags>][--ldr-flags=<flags>][--<initoptions>]
--debug=<debug flags>
info, warn, boot, server, loader, exceptions,and ns (or all)
--init=<init process>
可以重寫預設的init程序(rom/ned)
--l4re-dbg=<debug flags>
Flag同--debug,區別:此處為init的flag,--debug為moe的
--ldr-flags=<loader flags>
pre_alloc,all_segs_cow, pinned_segs
-- <init options>
通過“--”加空格傳入的引數會直接傳遞到init程序
2.2 Ned,the Init Process
Lua Bindings for L4Re
Ned提供對L4Re抽象的各種繫結,它們位於L4包中(require “L4”)
幾個常量
Proto={
Dataspace=0x4000,
Namespace=0x4001,
Goos=0x4003,
Mem_alloc=0x4004,
Rm=0x4005,
Event=0x4006,
Inhibitor=0x4007,
Sigma0=-6,
Log=-13,
Scheduler=-14,
Factory=-15,
Vm=-16,
Dma_space=-17,
Irq_sender=-18,
Irq_muxer=-19,
Semaphore=-20,
Iommu=-22,
Ipc_gate=0,
}
Dbg={
Info=1,
Warn=2,
Boot=4,
Server=0x10,
Exceptions=0x20,
Cmd_line=0x40,
Loader=0x80,
Name_space=0x400,
All=0xffffffff,
}
Ldr_flags={
eager_map=0x1,--L4RE_AUX_LDR_FLAG_EAGER_MAP
all_segs_cow=0x2,--L4RE_AUX_LDR_FLAG_ALL_SEGS_COW
pinned_segs=0x4,--L4RE_AUX_LDR_FLAG_PINNED_SEGS
}
Ned啟動一個新task是通過L4.loader,這個類提供三個選項:
new_channel():返回一個新的IPC gate
start()和startv():啟動一個新的程序,並返回程序物件
Ned同樣可以帶命令列引數
[--interactive|-i][--cmdcap|-cCAP][--noexit][--execute|-eSTATEMENT]<luascript>[options passed to lua script]
2.3 Io,the Io Server
Io的配置包含兩個部分:硬體的描述;虛擬匯流排的描述。
一個基於PCI的例圖:
一個io配置檔案的示例
--vim:ft=lua --Example configuration for io --Configure two platform devices to be known to io Io.Dt.add_children(Io.system_bus(),function() --create a new hardware device called"FOODEVICE" FOODEVICE=Io.Hw.Device(function() --set the compatibility IDs for this device --a client tries to match against these IDs and configures --itself accordingly --the list should be sorted from specific to less specific IDs compatible={"dev-foo,mmio","dev-foo"}; --set the‘hid’property of the device,the hid can also be used --as a compatible ID when matching clients Property.hid="dev-foo,Example"; --note:names for resources are truncated to 4 letters and a client --can determine the name from the ID field of a l4vbus_resource_t --add two resources‘irq0’and‘reg0’to the device Resource.irq0=Io.Res.irq(17); Resource.reg0=Io.Res.mmio(0x6f000000,0x6f007fff); end); --create a new hardware device called "BARDEVICE" BARDEVICE=Io.Hw.Device(function() --set the compatibility IDs for this device --a client tries to match against these IDs and configures --itself accordingly --the list should be sorted from specific to lesss pecific IDs compatible={"dev-bar,mmio","dev-bar"}; --set the‘hid’property of the device,the hid can also be used --as a compatible ID when matching clients Property.hid="dev-bar,Example"; --Specify that this device is able to use direct memory access(DMA). --This is needed to allow clients to gain access to DMA addresses --used by this device to directly access memory. Property.flags=Io.Hw_device_DF_dma_supported; --note:names for resources are truncated to 4 letters and a client --can determine the name from the ID field of a l4vbus_resource_t --add three resources’irq0’,’irq1’,and’reg0’to the device Resource.irq0=Io.Res.irq(19); Resource.irq1=Io.Res.irq(20); Resource.reg0=Io.Res.mmio(0x6f100000,0x6f100fff); end); end); Io.add_vbusses { --Create a virtual bus for a client and give access to FOODEVICE client1=Io.Vi.System_bus(function() dev=wrap(Io.system_bus():match("FOODEVICE")); end); --Create a virtual bus for another client and give it access to BARDEVICE client2=Io.Vi.System_bus(function() dev=wrap(Io.system_bus():match("BARDEVICE")); end); } |
每個裝置支援一個‘compatible’屬性,它是一個字串(跟linux的dts類似)。客戶端根據這個屬性進行匹配。其他的裝置成員根據其型別來分別處理:資源(io.Res),資源名限制在4個字元,儲存在l4vbus_resource_t的ID域;裝置,會作為當前裝置的一個子節點;其他的型別則被認為是裝置的屬性來配置裝置驅動。