a simple c runtime by example - yajin

13
Operating Systems (Fall/Winter 2019) A Simple C Runtime by Example Yajin Zhou (http://yajin.org ) Zhejiang University

Upload: others

Post on 29-Oct-2021

5 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: A Simple C Runtime by Example - Yajin

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

Review

• ELF

• QEMU

• A simple runtime for RISC-V

Page 3: A Simple C Runtime by Example - Yajin

ELF

• Sections vs Segments

• Linking view vs

Execution view

Page 4: A Simple C Runtime by Example - Yajin

ELF

Page 5: A Simple C Runtime by Example - Yajin

ELF

Page 6: A Simple C Runtime by Example - Yajin

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

Linker script

Page 8: A Simple C Runtime by Example - Yajin

Linker script

Page 9: A Simple C Runtime by Example - Yajin

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

C Runtime

• What we need?

• Code is in memory

• SP is ready

Page 11: A Simple C Runtime by Example - Yajin

C Runtime

Page 12: A Simple C Runtime by Example - Yajin

NS16550a

• UART Device

Page 13: A Simple C Runtime by Example - Yajin

QEMU Virt