F9 Microkernel code reading - part 1

5,318 views
5,208 views

Published on

F9 Microkernel Code reading based on https://github.com/f9micro/f9-kernel

Published in: Technology
0 Comments
3 Likes
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total views
5,318
On SlideShare
0
From Embeds
0
Number of Embeds
1,697
Actions
Shares
0
Downloads
64
Comments
0
Likes
3
Embeds 0
No embeds

No notes for slide

F9 Microkernel code reading - part 1

  1. 1. Part  1  :  Code  Reading   of   F9  Microkernel   ben6   2013-­‐10-­‐16  
  2. 2. F9   Agenda   •  Overview  of  F9-­‐Microkernel     •  Code  reading  (cscope,  ctags)   •  Code  trace  
  3. 3. F9   Agenda   •  Overview  of  F9-­‐Microkernel     •  Code  reading  (cscope,  ctags)   •  Code  trace  
  4. 4. 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)  
  5. 5. 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  
  6. 6. 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  
  7. 7. F9   Agenda   •  Overview  of  F9-­‐Microkernel     •  Code  reading  (cscope,  ctags)   •  Code  trace  
  8. 8. Kernel  Line  of  code   Kernel  C  code  line:  2661   Git  head:  7ae6e15bdf4d67740ef9fa2a0c6a2a194df9553b  
  9. 9. cscope   •  CTRL-­‐D  to  quit   •  Use  arrow  key   <up>,  <down>  to   select   •  Type  symbol  name   your  want  to   search  
  10. 10. Use  case  of  cscope   1.  2.  3.  4.  5.  Get  f9-­‐kernel  source  code     git  clone  h=ps://github.com/f9micro/f9-­‐kernel   Generate  cscope.files  to  be  scanned   –  cd  f9-­‐kernel;  find  .  -­‐name  "*.c"  -­‐o    -­‐name  "*.h"  >  cscope.files   Generate  Cscope  database   cscope  -­‐b  -­‐q  -­‐k   Using  the  database   –  default  Cscope  browser   cscope  -­‐d   (be  able  to  use  vim  or  other  editor  support  cscope  database)   RegeneraHng  database  when  source  code  changes   –  Use  same  command  step  4.   Reference:  hhp://cscope.sourceforge.net/large_projects.html  
  11. 11. vim  +  ctags   •  sudo  apt-­‐get  install  ctags   •  Generate  tags     ctags  –R  *   •  key  definiMon  at  vim     CTRL   +  ]  è  goto  the  funcMon  definiMon   CTRL   +  t    è  back  to  previous  funcMon  call  
  12. 12. PART  1   F9  KERNEL  ENTRY  
  13. 13. F9-­‐kernel  Entry   •  plamorm/f9.ld          è  F9  ldscript   __l4_start  
  14. 14. F9-­‐kernel  Entry   •  plamorm/f9.ld   Header  of  f9.bin  is   isr_vector  table  for   Cortex-­‐M  MCU  
  15. 15. f9-­‐kernel:  __l4_start   kernel/init.c   •  Be  reset   handler   •  F9  startup   entry  
  16. 16. __l4_start   •  IniMal  hooks   •  Copy  data   segment  for  1st   iniMalizaMon   •  Clear  segments   •  IniMalize  system   clock   •  Call  main()  entry  
  17. 17. 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  
  18. 18. 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  
  19. 19. kMmer_event_create   •  kMmer.c   •  Create  new  event   entry     •  add  to  linked  list  of   event  table   •  Add  entry  for  event   scheduling  
  20. 20. Switch  to  kernel   •  Create  kernel  thread  and  enable  running   by  context  switch  
  21. 21. F9   Agenda   •  Overview  of  F9-­‐Microkernel     •  Code  reading  (cscope,  ctags)   •  Code  trace  
  22. 22. Console  setup  before  code  trace   Pl2303  console  with  STM32F4   •  USB2TTL  RX  (white)  -­‐-­‐-­‐>  PA0   •  USB2TTL  TX  (green)  -­‐-­‐-­‐>  PA1   USB-­‐Serial  Controller   Prolific  2303  
  23. 23. Toolchain  for  Cortex-­‐M4   •  Sourcery  CodeBench   –  ARM  Processors:  EABI  Release   –  Verified  versions:  arm-­‐2012.03,  arm-­‐2013.05     •  GNU  Tools  for  ARM  Embedded  Processors  
  24. 24. stlink   Project  for  tools  we  used:  st-­‐ flash,  st-­‐uMl   hhps://github.com/texane/stlink  
  25. 25. Code  trace:  st-­‐uMl   Remote  debug  port  for  gdb  
  26. 26. Code  trace:  gdb  remote   target  remote  :4242  
  27. 27. Code  trace  issue   •  Debug  Panic   Git  HEAD:  7ae6e15bdf4d67740ef9fa2a0c6a2a194df9553b  
  28. 28. Discussions   F9   ?  
  29. 29. 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  

×