1 / 36

BOS & Network Driver Practice

T OSSUG. JULUOSDev 星系主題. BOS & Network Driver Practice. Ben Wei (A system creator). Agenda. BOS 簡介 lspci e100_attach T ransmit & Receive Demo Issues Q emu OSE. Agenda. BOS 簡介 lspci e100_attach T ransmit & Receive Demo Issues Q emu OSE. Bos 簡介. Bos ( a.k.a Ben’s OS) 目前實作

dugan
Télécharger la présentation

BOS & Network Driver Practice

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. TOSSUG JULUOSDev 星系主題 BOS & Network Driver Practice Ben Wei (A system creator)

  2. Agenda • BOS 簡介 • lspci • e100_attach • Transmit & Receive • Demo • Issues • Qemu OSE 2

  3. Agenda • BOS 簡介 • lspci • e100_attach • Transmit & Receive • Demo • Issues • Qemu OSE 3

  4. Bos簡介 Bos (a.k.a Ben’s OS) 目前實作 • 簡易的記憶體管理 • Timer中斷處理 • 鍵盤I/O, 佇列 • 多個執行緒的多工切換 • 精簡 blibc函式庫 • bshell簡單的命令模式 (ps, uname, free, clear…) 4

  5. Architecture lspci net Kthread (Bshell) PCI Func Network Driver CU RU Kernel Timer Mem Kernel E100 i82559ER 5

  6. Agenda • BOS 簡介 • lspci • e100_attach • Transmit & Receive • Demo • Issues • Qemu OSE 6

  7. lspci • OSDev.org“here I can find Programming Info on PCI?” • sysInLong: 讀取pci表內容 • sysOutLong: 寫入pci設備命令及資料 7

  8. MIT OSE x86.h • uint32_t inl(int port) __asm __volatile("inl %w1,%0" : "=a" (data) : "d" (port)); • voidoutl(intport, uint32_t data) __asm __volatile("outl %0,%w1" : : "a" (data), "d" (port)); 8

  9. inl/outl NASM ;uint32_t _intl(int port) _inl: movedx, [esp+4] moveax, 0         in eax, dx         ret ;void _outl(int port, uint32_t data) _outl: movedx, [esp+4]  ; port moveax, [esp+8]  ; data         out  dx, eax         ret 9

  10. PCI Config Read pciConfigRead(uint32_t bus, uint32_t slot, uint32_t func, uin32_t offset) address = (uint32_t)((bus << 16) | (slot << 11) | (func << 8) | (offset & 0xfc) | ((uint32_t)1<<31)); outl(0xCF8, address); data = (uint32_t)(intl(0xCFC); 10

  11. Ethernet Controller Info 00:18.0 Vendor:8086, devid:1029, class:0200h(Ethernet Controller),r9,t0,irq11 11

  12. Agenda • BOS 簡介 • lspci • e100_attach • Transmit & Receive • Demo • Issues • Qemu OSE 12

  13. E100_attach 啟用流程 • 啟用後,這時便用使用到 io region 1: 0xc040,長度為64位元組,參考Intel 82559 • 需要將e100 做軟體重置 • e100_reset() • Disable CSR 中斷 • DMA Rings • 傳送的緩衝區Control Block List (CBL): cbl_init() • 接收用的緩衝區Receive Frame Area (RFA): rfa_init() 13

  14. PCI enable e100 func • pci_func_enable(pci_pdata_t f) pci_conf_write(f, PCI_COMMAND_STATUS_REG,                        PCI_COMMAND_IO_ENABLE |                        PCI_COMMAND_MEM_ENABLE |                        PCI_COMMAND_MASTER_ENABLE); 執行結果 PCI function 00:18.0 (8086:1209) enabled 14

  15. E100 Reset voide100_reset() { outl(e100.addr_base[E100_IO] + CSR_PORT, PORT_SW_RESET); delay(10); } 15

  16. Tricky delay() __inline void delay(inti) { while(--i >=0) { inb(0x84); } } 16

  17. Disable e100 interrupt r = e100_exec_cmd(CSR_INT, 1); printf("e100 CSR_INT ret=%d\n", r); • e100_exec_cmd (intcsr_comp, uint8_t cmd) outb(nic.io_base + csr_comp, cmd); do { scb_command = inb(nic.io_base + CSR_COMMAND); } while (scb_command != 0 && --retry > 0); return retry > 0; 17

  18. DMA Rings • Control Block • Control Block List (CBL) • Receive Frame Area (RFA) 18

  19. Control Block (CB) Transmit Control Block (TCB) 19

  20. DMA Rings for TCBs 20

  21. Agenda • BOS 簡介 • lspci • e100_attach • Transmit & Receive • Demo • Issues • Qemu OSE 21

  22. transmit & receive • SendPacket data (transmit & receive) int e100_transmit (constchar *data, uint16_t len) • Receivepacket data int e100_receive (char *data) 22

  23. Agenda • BOS 簡介 • lspci • e100_attach • Transmit & Receive • Demo • Issues • Qemu OSE 23

  24. Demo 24

  25. Demo - recap bos$ net PCI function 00:18.0 (8086:1209) enabled mem region 0: 4096 bytes at 0xf2020000 io region 1: 64 bytes at 0xc040 cblavail = 9, wait = 1, slot = 0x420000, irq=11 rfaavail = 10, wait = 0, slot = 0x420050 25

  26. Agenda • BOS 簡介 • lspci • e100_attach • Transmit & Receive • Demo • Issues • Qemu OSE 26

  27. Issues • 原使用e100設備序號,並不生效;後來研究OSE資料後,發現必須在qemu參數中設定,之後再使用設備序號1209來啟用e100(i82559er),如此才能正確執行在qemu環境。 • 系統在開發的過程中,偶遇到無法正常開機,這時GIT便可派上用場,來縮小問題發生的範圍。 27

  28. Agenda • BOS 簡介 • lspci • e100_attach • Transmit & Receive • Demo • Issues • Qemu OSE 28

  29. 編繹Qemu OSE版本 $ configure--disable-sdl–prefix=/usr/local/qemuose $ --target-list=i386-softmmu $ make $ sudo make install 另外在Bos v0.21中執行Qemu時,將檢查/usr/local/qemuose,若存在則直接使用。 29

  30. Qemu參數 • 參數 qemu-fda "../bos.img" -net user -net nic,model=i82559er • MIT OSE參數 (只在qemu 0.12.5-6.828中支援) -debug-e100 -pcap <file> 30

  31. 結論 • PCI 資訊的存取 • 啟用e100網路卡 • 設定並使用DMA Rings • 更好的偵錯方式來進行網卡開發 • 相關遇到問題的經驗分享 31

  32. Q & A 32

  33. JuluOSDev議程 • 有興趣一起開發Juluos的朋友們,請加入到juluosdev group at google,參與開發議程討論,位置詳見Julu.staros.mobi公告。 33

  34. Backup Slides 34

  35. Glossary of Abbreviations • CB Control Block • CBL Command Block List • CSR Control/Status Registers • CU Command Unit • RFA Receive Frame Area • RFD Receive Frame Descriptor • RU Receive Unit • SCB System Control Block • TCB Transmit Command Block 35

  36. 參考資料及延伸閱讀 • MIT OSE • MIT OSE Lab6 • MIT OSE Tools • Intel 82559 • NASM x86 Quick Reference • OSDev.org • Where can I find programming info on PCI? • Differences Between AT&T and Intel assembler formats 36

More Related