a simple c runtime by example - yajin
TRANSCRIPT
![Page 1: A Simple C Runtime by Example - Yajin](https://reader030.vdocuments.us/reader030/viewer/2022012502/617bed77e4abca139f00f6dd/html5/thumbnails/1.jpg)
Operating Systems (Fall/Winter 2019)
A Simple C Runtime by Example
Yajin Zhou (http://yajin.org)
Zhejiang University
![Page 2: A Simple C Runtime by Example - Yajin](https://reader030.vdocuments.us/reader030/viewer/2022012502/617bed77e4abca139f00f6dd/html5/thumbnails/2.jpg)
Review
• ELF
• QEMU
• A simple runtime for RISC-V
![Page 3: A Simple C Runtime by Example - Yajin](https://reader030.vdocuments.us/reader030/viewer/2022012502/617bed77e4abca139f00f6dd/html5/thumbnails/3.jpg)
ELF
• Sections vs Segments
• Linking view vs
Execution view
![Page 4: A Simple C Runtime by Example - Yajin](https://reader030.vdocuments.us/reader030/viewer/2022012502/617bed77e4abca139f00f6dd/html5/thumbnails/4.jpg)
ELF
![Page 5: A Simple C Runtime by Example - Yajin](https://reader030.vdocuments.us/reader030/viewer/2022012502/617bed77e4abca139f00f6dd/html5/thumbnails/5.jpg)
ELF
![Page 6: A Simple C Runtime by Example - Yajin](https://reader030.vdocuments.us/reader030/viewer/2022012502/617bed77e4abca139f00f6dd/html5/thumbnails/6.jpg)
Linker script
• The main purpose of the linker script is to describe how the sections
in the input files should be mapped into the output file, and to control
the memory layout of the output file.
• Text section begins from 0x10000, .data section begins from
0x8000000
![Page 7: A Simple C Runtime by Example - Yajin](https://reader030.vdocuments.us/reader030/viewer/2022012502/617bed77e4abca139f00f6dd/html5/thumbnails/7.jpg)
Linker script
![Page 8: A Simple C Runtime by Example - Yajin](https://reader030.vdocuments.us/reader030/viewer/2022012502/617bed77e4abca139f00f6dd/html5/thumbnails/8.jpg)
Linker script
![Page 9: A Simple C Runtime by Example - Yajin](https://reader030.vdocuments.us/reader030/viewer/2022012502/617bed77e4abca139f00f6dd/html5/thumbnails/9.jpg)
Final memory layout – execution view
0x8000 0000
0x8000 018a0x8000 0190
0x8000 01b0
0x8000 01d0
0x8000 11f8
0x8000 01e0
text
rodata
data
stack
0x8000 11e0
heap
Without enabling page table!
![Page 10: A Simple C Runtime by Example - Yajin](https://reader030.vdocuments.us/reader030/viewer/2022012502/617bed77e4abca139f00f6dd/html5/thumbnails/10.jpg)
C Runtime
• What we need?
• Code is in memory
• SP is ready
![Page 11: A Simple C Runtime by Example - Yajin](https://reader030.vdocuments.us/reader030/viewer/2022012502/617bed77e4abca139f00f6dd/html5/thumbnails/11.jpg)
C Runtime
![Page 12: A Simple C Runtime by Example - Yajin](https://reader030.vdocuments.us/reader030/viewer/2022012502/617bed77e4abca139f00f6dd/html5/thumbnails/12.jpg)
NS16550a
• UART Device
![Page 13: A Simple C Runtime by Example - Yajin](https://reader030.vdocuments.us/reader030/viewer/2022012502/617bed77e4abca139f00f6dd/html5/thumbnails/13.jpg)
QEMU Virt