f9 microkernel code reading - part 1
DESCRIPTION
F9 Microkernel Code reading based on https://github.com/f9micro/f9-kernelTRANSCRIPT
Part 1 : Code Reading of
F9 Microkernel ben6
2013-‐10-‐16
Agenda
• Overview of F9-‐Microkernel
• Code reading (cscope, ctags)
• Code trace
F9
Agenda
• Overview of F9-‐Microkernel
• Code reading (cscope, ctags)
• Code trace
F9
F9 Microkernel Overview
• an experimental microkernel used to construct flexible embedded systems inspired by famous L4 microkernel.
• The moMvaMon of F9 microkernel is to deploy modern kernel techniques to support – running real-‐Mme and Mme-‐sharing applicaMons (ex: wireless communicaMons) for ARM Cortex-‐M series microprocessors with efficiency (performance + power consumpMon)
– security (memory protecMon + isolated execuMon)
CharacterisMcs
• F9 follows the fundamental principles of microkernels in that it implements address spaces, thread management, and IPC only in the privileged kernel.
• Designed and customized for ARM Cortex-‐M, supporMng NVIC (Nested Vectored Interrupt Controller), Bit Banding, MPU (Memory ProtecMon Unit)
• Energy efficient scheduling and Mckless Mmer • KProbes • Independent TCB (Thread Control Block) for each thread with its global ID
CharacterisMcs (Cont.)
• Memory management – Memory pool, Flexible page, Address space
• System calls: – Grant, Map, Flush
• UTCB concept – a small thread-‐specific region in the thread's virtual address space, which is always mapped
• Synchronous IPC • Debugging and profiling mechanisms
Agenda
• Overview of F9-‐Microkernel
• Code reading (cscope, ctags)
• Code trace
F9
Kernel Line of code
Kernel C code line: 2661 Git head: 7ae6e15bdf4d67740ef9fa2a0c6a2a194df9553b
cscope
• CTRL-‐D to quit • Use arrow key
<up>, <down> to select
• Type symbol name your want to search
Use case of cscope 1. Get f9-‐kernel source code
git clone h=ps://github.com/f9micro/f9-‐kernel
2. Generate cscope.files to be scanned – cd f9-‐kernel; find . -‐name "*.c" -‐o -‐name "*.h" > cscope.files
3. Generate Cscope database cscope -‐b -‐q -‐k
4. Using the database – default Cscope browser cscope -‐d (be able to use vim or other editor support cscope database)
5. RegeneraHng database when source code changes – Use same command step 4.
Reference: hhp://cscope.sourceforge.net/large_projects.html
vim + ctags
• sudo apt-‐get install ctags • Generate tags
CTRL + ] è goto the funcMon definiMon
+ t è back to previous funcMon call CTRL
ctags –R *
• key definiMon at vim
F9 KERNEL ENTRY PART 1
F9-‐kernel Entry • plamorm/f9.ld è F9 ldscript __l4_start
F9-‐kernel Entry • plamorm/f9.ld
Header of f9.bin is isr_vector table for Cortex-‐M MCU
f9-‐kernel: __l4_start
kernel/init.c • Be reset handler
• F9 startup entry
__l4_start • IniMal hooks • Copy data
segment for 1st iniMalizaMon
• Clear segments • IniMalize system
clock • Call main() entry
start.c : main.c • IniMal for level plamorm
hooks • Irq iniMal and disable
interrupt • Setup FloaMng Point Unit • Show banner • IniMal for Level kernel
hooks • Create and idle and root
thread • Create Mmer 64 Mcks for
delivering ipc • Init LAST stage hooks • Switch to iniMal kernel
thread
Enable/disable irq
inline assembly Syntax: __asm__ __volaMle__("InstrucMon List"); • __volaMle__ Tell gcc don’t change my intrusMon list
• cpsid, cpsie reference: Implemented interrupt enabling delay in the Cortex-‐M3 and Cortex-‐M4 processors
kMmer_event_create
• kMmer.c
• Create new event entry
• add to linked list of event table
• Add entry for event scheduling
Switch to kernel
• Create kernel thread and enable running by context switch
Agenda
• Overview of F9-‐Microkernel
• Code reading (cscope, ctags)
• Code trace
F9
Console setup before code trace Pl2303 console with STM32F4 • USB2TTL RX (white) -‐-‐-‐> PA0 • USB2TTL TX (green) -‐-‐-‐> PA1
USB-‐Serial Controller Prolific 2303
Toolchain for Cortex-‐M4
• Sourcery CodeBench – ARM Processors: EABI Release – Verified versions: arm-‐2012.03, arm-‐2013.05
• GNU Tools for ARM Embedded Processors
stlink Project for tools we used: st-‐flash, st-‐uMl
hhps://github.com/texane/stlink
Code trace: st-‐uMl
Remote debug port for gdb
Code trace: gdb remote target remote :4242
Code trace issue
• Debug Panic Git HEAD: 7ae6e15bdf4d67740ef9fa2a0c6a2a194df9553b
Discussions
?
F9
References • F9 Microkernel source code and introducMon • Using Cscope on large projects (example: the Linux kernel)
• Ctags wiki
• __asm__ __volaMle__ GCC的内嵌汇编语法 AT&T汇编语⾔言语法(⼀一)
• Implemented interrupt enabling delay in the Cortex-‐M3 and Cortex-‐M4 processors
• texane's stlink project at github