Showing preview only (3,318K chars total). Download the full file or copy to clipboard to get everything.
Repository: rockytriton/LLD
Branch: main
Commit: 57de54e48eb8
Files: 648
Total size: 3.1 MB
Directory structure:
gitextract_cwq282cg/
├── README.md
├── linux_os/
│ ├── part1/
│ │ └── src/
│ │ ├── init.c
│ │ └── start.S
│ ├── part10/
│ │ └── src/
│ │ ├── base.mk
│ │ ├── crt0_s.o
│ │ ├── drmlist/
│ │ │ ├── Makefile
│ │ │ └── drmlist.c
│ │ ├── fbset/
│ │ │ ├── Makefile
│ │ │ └── fbset.c
│ │ ├── include/
│ │ │ ├── libfb.h
│ │ │ ├── mydrm.h
│ │ │ ├── mylib.h
│ │ │ └── printf.h
│ │ ├── init/
│ │ │ ├── Makefile
│ │ │ ├── crt0.S
│ │ │ └── init.c
│ │ ├── lash/
│ │ │ ├── Makefile
│ │ │ └── lash.c
│ │ ├── libfb/
│ │ │ ├── Makefile
│ │ │ └── fb.c
│ │ ├── mydrm/
│ │ │ ├── Makefile
│ │ │ └── mydrm.c
│ │ ├── mylib/
│ │ │ ├── Makefile
│ │ │ ├── mem.c
│ │ │ ├── printf.c
│ │ │ ├── start.S
│ │ │ ├── sys.c
│ │ │ └── util.c
│ │ └── printargs/
│ │ ├── Makefile
│ │ └── printargs.c
│ ├── part2/
│ │ └── src/
│ │ ├── base.mk
│ │ ├── crt0_s.o
│ │ ├── include/
│ │ │ └── mylib.h
│ │ ├── init/
│ │ │ ├── Makefile
│ │ │ ├── crt0.S
│ │ │ └── init.c
│ │ └── mylib/
│ │ ├── Makefile
│ │ ├── start.S
│ │ ├── sys.c
│ │ └── util.c
│ ├── part3/
│ │ └── src/
│ │ ├── base.mk
│ │ ├── crt0_s.o
│ │ ├── include/
│ │ │ └── mylib.h
│ │ ├── init/
│ │ │ ├── Makefile
│ │ │ ├── crt0.S
│ │ │ └── init.c
│ │ ├── lash/
│ │ │ ├── Makefile
│ │ │ └── lash.c
│ │ └── mylib/
│ │ ├── Makefile
│ │ ├── start.S
│ │ ├── sys.c
│ │ └── util.c
│ ├── part4/
│ │ └── src/
│ │ ├── base.mk
│ │ ├── crt0_s.o
│ │ ├── include/
│ │ │ ├── mylib.h
│ │ │ └── printf.h
│ │ ├── init/
│ │ │ ├── Makefile
│ │ │ ├── crt0.S
│ │ │ └── init.c
│ │ ├── lash/
│ │ │ ├── Makefile
│ │ │ └── lash.c
│ │ └── mylib/
│ │ ├── Makefile
│ │ ├── printf.c
│ │ ├── start.S
│ │ ├── sys.c
│ │ └── util.c
│ ├── part5/
│ │ └── src/
│ │ ├── base.mk
│ │ ├── crt0_s.o
│ │ ├── include/
│ │ │ ├── mylib.h
│ │ │ └── printf.h
│ │ ├── init/
│ │ │ ├── Makefile
│ │ │ ├── crt0.S
│ │ │ └── init.c
│ │ ├── lash/
│ │ │ ├── Makefile
│ │ │ └── lash.c
│ │ └── mylib/
│ │ ├── Makefile
│ │ ├── printf.c
│ │ ├── start.S
│ │ ├── sys.c
│ │ └── util.c
│ ├── part6/
│ │ └── src/
│ │ ├── base.mk
│ │ ├── crt0_s.o
│ │ ├── include/
│ │ │ ├── mylib.h
│ │ │ └── printf.h
│ │ ├── init/
│ │ │ ├── Makefile
│ │ │ ├── crt0.S
│ │ │ └── init.c
│ │ ├── lash/
│ │ │ ├── Makefile
│ │ │ └── lash.c
│ │ └── mylib/
│ │ ├── Makefile
│ │ ├── mem.c
│ │ ├── printf.c
│ │ ├── start.S
│ │ ├── sys.c
│ │ └── util.c
│ ├── part7/
│ │ └── src/
│ │ ├── base.mk
│ │ ├── crt0_s.o
│ │ ├── include/
│ │ │ ├── mylib.h
│ │ │ └── printf.h
│ │ ├── init/
│ │ │ ├── Makefile
│ │ │ ├── crt0.S
│ │ │ └── init.c
│ │ ├── lash/
│ │ │ ├── Makefile
│ │ │ └── lash.c
│ │ ├── mylib/
│ │ │ ├── Makefile
│ │ │ ├── mem.c
│ │ │ ├── printf.c
│ │ │ ├── start.S
│ │ │ ├── sys.c
│ │ │ └── util.c
│ │ └── printargs/
│ │ ├── Makefile
│ │ └── printargs.c
│ ├── part8/
│ │ ├── myos.img
│ │ └── src/
│ │ ├── base.mk
│ │ ├── crt0_s.o
│ │ ├── fbset/
│ │ │ ├── Makefile
│ │ │ └── fbset.c
│ │ ├── include/
│ │ │ ├── libfb.h
│ │ │ ├── mylib.h
│ │ │ └── printf.h
│ │ ├── init/
│ │ │ ├── Makefile
│ │ │ ├── crt0.S
│ │ │ └── init.c
│ │ ├── lash/
│ │ │ ├── Makefile
│ │ │ └── lash.c
│ │ ├── libfb/
│ │ │ ├── Makefile
│ │ │ └── fb.c
│ │ ├── mylib/
│ │ │ ├── Makefile
│ │ │ ├── mem.c
│ │ │ ├── printf.c
│ │ │ ├── start.S
│ │ │ ├── sys.c
│ │ │ └── util.c
│ │ └── printargs/
│ │ ├── Makefile
│ │ └── printargs.c
│ ├── part9/
│ │ └── src/
│ │ ├── base.mk
│ │ ├── crt0_s.o
│ │ ├── drmlist/
│ │ │ ├── Makefile
│ │ │ └── drmlist.c
│ │ ├── fbset/
│ │ │ ├── Makefile
│ │ │ └── fbset.c
│ │ ├── include/
│ │ │ ├── libfb.h
│ │ │ ├── mydrm.h
│ │ │ ├── mylib.h
│ │ │ └── printf.h
│ │ ├── init/
│ │ │ ├── Makefile
│ │ │ ├── crt0.S
│ │ │ └── init.c
│ │ ├── lash/
│ │ │ ├── Makefile
│ │ │ └── lash.c
│ │ ├── libfb/
│ │ │ ├── Makefile
│ │ │ └── fb.c
│ │ ├── mydrm/
│ │ │ ├── Makefile
│ │ │ └── mydrm.c
│ │ ├── mylib/
│ │ │ ├── Makefile
│ │ │ ├── mem.c
│ │ │ ├── printf.c
│ │ │ ├── start.S
│ │ │ ├── sys.c
│ │ │ └── util.c
│ │ └── printargs/
│ │ ├── Makefile
│ │ └── printargs.c
│ └── qemu/
│ └── qemu-run.sh
├── ooc/
│ ├── Makefile
│ ├── flog.h
│ ├── log.h
│ ├── log_console.c
│ ├── log_file.c
│ └── main.c
├── pico/
│ └── 6502_part1/
│ ├── CMakeLists.txt
│ ├── pico_sdk_import.cmake
│ └── test.c
└── rpi_bm/
├── part1-5/
│ ├── Makefile
│ ├── README.md
│ ├── config.txt
│ ├── include/
│ │ ├── common.h
│ │ ├── gpio.h
│ │ ├── mini_uart.h
│ │ ├── mm.h
│ │ ├── peripherals/
│ │ │ ├── aux.h
│ │ │ ├── base.h
│ │ │ └── gpio.h
│ │ └── utils.h
│ └── src/
│ ├── boot.S
│ ├── gpio.c
│ ├── kernel.c
│ ├── linker.ld
│ ├── mini_uart.c
│ ├── mm.S
│ └── utils.S
├── part10/
│ ├── Makefile
│ ├── armstub/
│ │ └── src/
│ │ └── armstub.S
│ ├── config.txt
│ ├── i2c-slave/
│ │ └── i2c-slave.ino
│ ├── include/
│ │ ├── common.h
│ │ ├── entry.h
│ │ ├── gpio.h
│ │ ├── i2c.h
│ │ ├── irq.h
│ │ ├── mini_uart.h
│ │ ├── mm.h
│ │ ├── peripherals/
│ │ │ ├── aux.h
│ │ │ ├── base.h
│ │ │ ├── gpio.h
│ │ │ ├── i2c.h
│ │ │ ├── irq.h
│ │ │ └── timer.h
│ │ ├── printf.h
│ │ ├── sysregs.h
│ │ ├── timer.h
│ │ └── utils.h
│ └── src/
│ ├── boot.S
│ ├── entry.S
│ ├── gpio.c
│ ├── i2c.c
│ ├── irq.S
│ ├── irq.c
│ ├── kernel.c
│ ├── linker.ld
│ ├── mini_uart.c
│ ├── mm.S
│ ├── printf.c
│ ├── timer.c
│ └── utils.S
├── part11/
│ ├── Makefile
│ ├── armstub/
│ │ └── src/
│ │ └── armstub.S
│ ├── config.txt
│ ├── i2c-slave/
│ │ └── i2c-slave.ino
│ ├── include/
│ │ ├── common.h
│ │ ├── entry.h
│ │ ├── gpio.h
│ │ ├── i2c.h
│ │ ├── irq.h
│ │ ├── lcd.h
│ │ ├── mini_uart.h
│ │ ├── mm.h
│ │ ├── peripherals/
│ │ │ ├── aux.h
│ │ │ ├── base.h
│ │ │ ├── gpio.h
│ │ │ ├── i2c.h
│ │ │ ├── irq.h
│ │ │ └── timer.h
│ │ ├── printf.h
│ │ ├── sysregs.h
│ │ ├── timer.h
│ │ └── utils.h
│ ├── spi-slave/
│ │ └── spi-slave.ino
│ ├── src/
│ │ ├── boot.S
│ │ ├── entry.S
│ │ ├── gpio.c
│ │ ├── i2c.c
│ │ ├── irq.S
│ │ ├── irq.c
│ │ ├── kernel.c
│ │ ├── lcd.c
│ │ ├── linker.ld
│ │ ├── mini_uart.c
│ │ ├── mm.S
│ │ ├── printf.c
│ │ ├── timer.c
│ │ └── utils.S
│ └── user_submissions/
│ └── README.md
├── part12/
│ ├── .vscode/
│ │ └── settings.json
│ ├── Makefile
│ ├── armstub/
│ │ └── src/
│ │ └── armstub.S
│ ├── config.txt
│ ├── i2c-slave/
│ │ └── i2c-slave.ino
│ ├── include/
│ │ ├── common.h
│ │ ├── entry.h
│ │ ├── gpio.h
│ │ ├── i2c.h
│ │ ├── irq.h
│ │ ├── lcd.h
│ │ ├── led_display.h
│ │ ├── mini_uart.h
│ │ ├── mm.h
│ │ ├── peripherals/
│ │ │ ├── aux.h
│ │ │ ├── base.h
│ │ │ ├── gpio.h
│ │ │ ├── i2c.h
│ │ │ ├── irq.h
│ │ │ ├── spi.h
│ │ │ └── timer.h
│ │ ├── printf.h
│ │ ├── spi.h
│ │ ├── sysregs.h
│ │ ├── timer.h
│ │ └── utils.h
│ └── src/
│ ├── boot.S
│ ├── entry.S
│ ├── gpio.c
│ ├── i2c.c
│ ├── irq.S
│ ├── irq.c
│ ├── kernel.c
│ ├── lcd.c
│ ├── led_display.c
│ ├── linker.ld
│ ├── mini_uart.c
│ ├── mm.S
│ ├── printf.c
│ ├── spi.c
│ ├── timer.c
│ └── utils.S
├── part13/
│ ├── .vscode/
│ │ └── settings.json
│ ├── Makefile
│ ├── armstub/
│ │ └── src/
│ │ └── armstub.S
│ ├── config.txt
│ ├── i2c-slave/
│ │ └── i2c-slave.ino
│ ├── include/
│ │ ├── common.h
│ │ ├── entry.h
│ │ ├── gpio.h
│ │ ├── i2c.h
│ │ ├── irq.h
│ │ ├── lcd.h
│ │ ├── led_display.h
│ │ ├── mailbox.h
│ │ ├── mem.h
│ │ ├── mini_uart.h
│ │ ├── mm.h
│ │ ├── peripherals/
│ │ │ ├── aux.h
│ │ │ ├── base.h
│ │ │ ├── gpio.h
│ │ │ ├── i2c.h
│ │ │ ├── irq.h
│ │ │ ├── spi.h
│ │ │ └── timer.h
│ │ ├── printf.h
│ │ ├── spi.h
│ │ ├── sysregs.h
│ │ ├── timer.h
│ │ ├── utils.h
│ │ └── video.h
│ └── src/
│ ├── boot.S
│ ├── entry.S
│ ├── gpio.c
│ ├── i2c.c
│ ├── irq.S
│ ├── irq.c
│ ├── kernel.c
│ ├── lcd.c
│ ├── led_display.c
│ ├── linker.ld
│ ├── mailbox.c
│ ├── mem.c
│ ├── mini_uart.c
│ ├── mm.S
│ ├── printf.c
│ ├── spi.c
│ ├── timer.c
│ └── utils.S
├── part14/
│ ├── .vscode/
│ │ └── settings.json
│ ├── Makefile
│ ├── armstub/
│ │ └── src/
│ │ └── armstub.S
│ ├── config.txt
│ ├── i2c-slave/
│ │ └── i2c-slave.ino
│ ├── include/
│ │ ├── common.h
│ │ ├── entry.h
│ │ ├── gpio.h
│ │ ├── i2c.h
│ │ ├── irq.h
│ │ ├── lcd.h
│ │ ├── led_display.h
│ │ ├── mailbox.h
│ │ ├── mem.h
│ │ ├── mini_uart.h
│ │ ├── mm.h
│ │ ├── peripherals/
│ │ │ ├── aux.h
│ │ │ ├── base.h
│ │ │ ├── gpio.h
│ │ │ ├── i2c.h
│ │ │ ├── irq.h
│ │ │ ├── spi.h
│ │ │ └── timer.h
│ │ ├── printf.h
│ │ ├── spi.h
│ │ ├── sysregs.h
│ │ ├── timer.h
│ │ ├── utils.h
│ │ └── video.h
│ ├── square_margin
│ └── src/
│ ├── boot.S
│ ├── entry.S
│ ├── fontData.c
│ ├── gpio.c
│ ├── i2c.c
│ ├── irq.S
│ ├── irq.c
│ ├── kernel.c
│ ├── lcd.c
│ ├── led_display.c
│ ├── linker.ld
│ ├── mailbox.c
│ ├── mem.c
│ ├── mini_uart.c
│ ├── mm.S
│ ├── printf.c
│ ├── spi.c
│ ├── timer.c
│ ├── utils.S
│ └── video.c
├── part15/
│ ├── .vscode/
│ │ └── settings.json
│ ├── Makefile
│ ├── armstub/
│ │ └── src/
│ │ └── armstub.S
│ ├── config.txt
│ ├── i2c-slave/
│ │ └── i2c-slave.ino
│ ├── include/
│ │ ├── common.h
│ │ ├── dma.h
│ │ ├── entry.h
│ │ ├── gpio.h
│ │ ├── i2c.h
│ │ ├── irq.h
│ │ ├── lcd.h
│ │ ├── led_display.h
│ │ ├── mailbox.h
│ │ ├── mem.h
│ │ ├── mini_uart.h
│ │ ├── mm.h
│ │ ├── peripherals/
│ │ │ ├── aux.h
│ │ │ ├── base.h
│ │ │ ├── dma.h
│ │ │ ├── gpio.h
│ │ │ ├── i2c.h
│ │ │ ├── irq.h
│ │ │ ├── spi.h
│ │ │ └── timer.h
│ │ ├── printf.h
│ │ ├── spi.h
│ │ ├── sysregs.h
│ │ ├── timer.h
│ │ ├── utils.h
│ │ └── video.h
│ ├── square_margin
│ └── src/
│ ├── boot.S
│ ├── dma.c
│ ├── entry.S
│ ├── fontData.c
│ ├── gpio.c
│ ├── i2c.c
│ ├── irq.S
│ ├── irq.c
│ ├── kernel.c
│ ├── lcd.c
│ ├── led_display.c
│ ├── linker.ld
│ ├── mailbox.c
│ ├── mem.c
│ ├── mini_uart.c
│ ├── mm.S
│ ├── printf.c
│ ├── spi.c
│ ├── timer.c
│ ├── utils.S
│ └── video.c
├── part16/
│ ├── Makefile
│ ├── armstub/
│ │ └── src/
│ │ └── armstub.S
│ ├── config.txt
│ ├── i2c-slave/
│ │ └── i2c-slave.ino
│ ├── include/
│ │ ├── common.h
│ │ ├── dma.h
│ │ ├── entry.h
│ │ ├── gpio.h
│ │ ├── i2c.h
│ │ ├── irq.h
│ │ ├── lcd.h
│ │ ├── led_display.h
│ │ ├── mailbox.h
│ │ ├── mem.h
│ │ ├── mini_uart.h
│ │ ├── mm.h
│ │ ├── mmu.h
│ │ ├── peripherals/
│ │ │ ├── aux.h
│ │ │ ├── base.h
│ │ │ ├── dma.h
│ │ │ ├── gpio.h
│ │ │ ├── i2c.h
│ │ │ ├── irq.h
│ │ │ ├── spi.h
│ │ │ └── timer.h
│ │ ├── printf.h
│ │ ├── spi.h
│ │ ├── sysregs.h
│ │ ├── timer.h
│ │ ├── utils.h
│ │ └── video.h
│ ├── square_margin
│ └── src/
│ ├── boot.S
│ ├── dma.c
│ ├── entry.S
│ ├── fontData.c
│ ├── gpio.c
│ ├── i2c.c
│ ├── irq.S
│ ├── irq.c
│ ├── kernel.c
│ ├── lcd.c
│ ├── led_display.c
│ ├── linker.ld
│ ├── mailbox.c
│ ├── mem.c
│ ├── mini_uart.c
│ ├── mm.S
│ ├── printf.c
│ ├── spi.c
│ ├── timer.c
│ ├── utils.S
│ └── video.c
├── part17/
│ ├── .vscode/
│ │ └── settings.json
│ ├── Makefile
│ ├── armstub/
│ │ ├── build/
│ │ │ ├── armstub.elf
│ │ │ ├── armstub_s.d
│ │ │ └── armstub_s.o
│ │ └── src/
│ │ └── armstub.S
│ ├── config.txt
│ ├── i2c-slave/
│ │ └── i2c-slave.ino
│ ├── include/
│ │ ├── common.h
│ │ ├── dma.h
│ │ ├── entry.h
│ │ ├── gpio.h
│ │ ├── i2c.h
│ │ ├── io.h
│ │ ├── irq.h
│ │ ├── lcd.h
│ │ ├── led_display.h
│ │ ├── mailbox.h
│ │ ├── mem.h
│ │ ├── mini_uart.h
│ │ ├── mm.h
│ │ ├── mmu.h
│ │ ├── peripherals/
│ │ │ ├── aux.h
│ │ │ ├── base.h
│ │ │ ├── dma.h
│ │ │ ├── emmc.h
│ │ │ ├── gpio.h
│ │ │ ├── i2c.h
│ │ │ ├── irq.h
│ │ │ ├── spi.h
│ │ │ └── timer.h
│ │ ├── printf.h
│ │ ├── spi.h
│ │ ├── sysregs.h
│ │ ├── timer.h
│ │ ├── utils.h
│ │ └── video.h
│ ├── square_margin
│ └── src/
│ ├── boot/
│ │ ├── boot.S
│ │ └── entry.S
│ ├── dma/
│ │ └── dma.c
│ ├── drivers/
│ │ ├── emmc/
│ │ │ ├── emmc.c
│ │ │ └── emmc_clock.c
│ │ ├── gpio/
│ │ │ └── gpio.c
│ │ ├── i2c/
│ │ │ ├── i2c.c
│ │ │ └── lcd.c
│ │ ├── mailbox/
│ │ │ └── mailbox.c
│ │ ├── muart/
│ │ │ └── mini_uart.c
│ │ ├── shared/
│ │ │ └── io.c
│ │ ├── spi/
│ │ │ ├── led_display.c
│ │ │ └── spi.c
│ │ └── video/
│ │ ├── fontData.c
│ │ └── video.c
│ ├── kernel/
│ │ ├── irq.S
│ │ ├── irq.c
│ │ ├── kernel.c
│ │ └── timer.c
│ ├── linker.ld
│ ├── mem/
│ │ ├── mem.c
│ │ └── mm.S
│ └── misc/
│ ├── printf.c
│ ├── utils.S
│ └── utils.c
├── part6-7/
│ ├── Makefile
│ ├── armstub/
│ │ └── src/
│ │ └── armstub.S
│ ├── config.txt
│ ├── include/
│ │ ├── common.h
│ │ ├── gpio.h
│ │ ├── mini_uart.h
│ │ ├── mm.h
│ │ ├── peripherals/
│ │ │ ├── aux.h
│ │ │ ├── base.h
│ │ │ └── gpio.h
│ │ ├── printf.h
│ │ ├── sysregs.h
│ │ └── utils.h
│ └── src/
│ ├── boot.S
│ ├── gpio.c
│ ├── kernel.c
│ ├── linker.ld
│ ├── mini_uart.c
│ ├── mm.S
│ ├── printf.c
│ └── utils.S
├── part8/
│ ├── Makefile
│ ├── armstub/
│ │ └── src/
│ │ └── armstub.S
│ ├── config.txt
│ ├── include/
│ │ ├── common.h
│ │ ├── entry.h
│ │ ├── gpio.h
│ │ ├── irq.h
│ │ ├── mini_uart.h
│ │ ├── mm.h
│ │ ├── peripherals/
│ │ │ ├── aux.h
│ │ │ ├── base.h
│ │ │ ├── gpio.h
│ │ │ └── irq.h
│ │ ├── printf.h
│ │ ├── sysregs.h
│ │ └── utils.h
│ └── src/
│ ├── boot.S
│ ├── entry.S
│ ├── gpio.c
│ ├── irq.S
│ ├── irq.c
│ ├── kernel.c
│ ├── linker.ld
│ ├── mini_uart.c
│ ├── mm.S
│ ├── printf.c
│ └── utils.S
└── part9/
├── Makefile
├── armstub/
│ └── src/
│ └── armstub.S
├── config.txt
├── include/
│ ├── common.h
│ ├── entry.h
│ ├── gpio.h
│ ├── irq.h
│ ├── mini_uart.h
│ ├── mm.h
│ ├── peripherals/
│ │ ├── aux.h
│ │ ├── base.h
│ │ ├── gpio.h
│ │ ├── irq.h
│ │ └── timer.h
│ ├── printf.h
│ ├── sysregs.h
│ ├── timer.h
│ └── utils.h
└── src/
├── boot.S
├── entry.S
├── gpio.c
├── irq.S
├── irq.c
├── kernel.c
├── linker.ld
├── mini_uart.c
├── mm.S
├── printf.c
├── timer.c
└── utils.S
================================================
FILE CONTENTS
================================================
================================================
FILE: README.md
================================================
Low Level Devel
Code for https://www.youtube.com/playlist?list=PLVxiWMqQvhg9FCteL7I0aohj1_YiUx1x8
================================================
FILE: linux_os/part1/src/init.c
================================================
#include <syscall.h>
#include <fcntl.h>
unsigned long _syscall(int num, void *a0, void *a1, void *a2, void *a3, void *a4, void *a5);
unsigned long _strlen(char *sz) {
int count = 0;
while(*sz++) {
count++;
}
return count;
}
void delay(int ticks) {
for (int i=0; i<ticks; i++) {
//nothing...
}
}
void print_string(char *str) {
_syscall(SYS_write, (void *)1 /*stdout*/, str, (void *)_strlen(str), 0, 0, 0);
}
unsigned long open_file(char *fn, int flags) {
return _syscall(SYS_open, fn, flags, 0, 0, 0, 0);
}
unsigned long read_file(unsigned long fd, char *buff, unsigned long size) {
return _syscall(SYS_read, fd, buff, size, 0, 0, 0);
}
int main() {
char *msg = "MyOS 0.0.0.1 Initializing...\n";
delay(1000000000);
print_string(msg);
delay(1000000000);
char buff[255];
char *filename = "/src/init.c";
print_string("Opening file: ");
print_string(filename);
print_string("\n");
unsigned long fd = open_file(filename, O_RDONLY);
read_file(fd, buff, sizeof(buff));
print_string(buff);
while(1) {
//event loop, for now just tick...
delay(1000000000);
print_string("TICK!\n");
}
return 0;
}
================================================
FILE: linux_os/part1/src/start.S
================================================
.globl _start
.text
_start:
call main
.globl _syscall
_syscall:
movq %rdi, %rax
movq %rsi, %rdi
movq %rdx, %rsi
movq %rcx, %rdx
movq %r8, %r10
movq %r9, %r8
movq 8(%rsp), %r9
syscall
ret
================================================
FILE: linux_os/part10/src/base.mk
================================================
SHELL ?= /bin/sh
CC ?= gcc
FLAGS ?= -nostdlib -I../include
MYOS_PATH ?= /mnt/myos
DESTDIR ?= /mnt/myos
PREFIX ?= $(DESTDIR)
BINDIR ?= $(PREFIX)/sbin
OBJECTS += ../crt0_s.o
%_c.o: %.c
$(CC) $(FLAGS) -c $< -o $@
%_s.o: %.S
$(CC) $(FLAGS) -c $< -o $@
install:
cp $(TARGET) $(BINDIR)/
clean:
rm *.o $(TARGET)
================================================
FILE: linux_os/part10/src/drmlist/Makefile
================================================
TARGET=drmlist
CSOURCES = $(shell echo *.c)
OBJECTS = $(CSOURCES:.c=_c.o)
LDFLAGS = -lmy -lmydrm -L$(MYOS_PATH)/lib
BINDIR = $(PREFIX)/bin
all: $(TARGET)
$(TARGET): $(OBJECTS)
$(CC) $(LDFLAGS) $(FLAGS) -o $(TARGET) $(OBJECTS)
include ../base.mk
================================================
FILE: linux_os/part10/src/drmlist/drmlist.c
================================================
#include <mydrm.h>
#include <mylib.h>
#include <printf.h>
#include <fcntl.h>
struct mydrm_buf {
uint32_t width;
uint32_t height;
uint32_t stride;
uint32_t size;
uint32_t handle;
uint8_t *map;
uint32_t fb;
};
struct mydrm_data {
int fd;
struct mydrm_buf framebuffer[2];
uint32_t crt_id;
bool pflip_pending;
bool cleanup;
int front_buf;
uint32_t width;
uint32_t height;
};
struct mouse_pos_info {
int x;
int y;
int max_x;
int max_y;
};
struct mouse_pos_info mouse_pos;
struct drm_mode_crtc saved_crtc;
int set_mode(struct mydrm_data *data, struct drm_mode_get_connector conn, struct drm_mode_modeinfo mode);
int main(int argc, char **argv) {
printf("DRM modes:\n");
int fd = mydrm_open("/dev/dri/card0");
struct drm_mode_card_res res;
if (mydrm_get_resources(fd, &res)) {
printf("Failed to open card0 resources\n");
return -1;
}
int hres = 0;
int vres = 0;
if (argc == 3) {
hres = str_to_int(argv[1]);
vres = str_to_int(argv[2]);
printf("Attempting to set res: %dx%d\n", hres, vres);
}
struct mydrm_data data;
data.cleanup = false;
data.pflip_pending = false;
data.front_buf = 0;
data.width = hres;
data.height = vres;
data.fd = fd;
sys_ioctl(fd, DRM_IOCTL_SET_MASTER, 0);
printf("DRM Connectors: %d\n", res.count_connectors);
sleep_sec(1);
for (int i=0; i<res.count_connectors; i++) {
uint32_t *connectors = (uint32_t *)res.connector_id_ptr;
struct drm_mode_get_connector conn;
int ret = mydrm_get_connector(fd, connectors[i], &conn);
if (ret) {
printf("\tFailed to get connector: %d\n", ret);
continue;
}
//printf("Found Connector: %d - %d. Modes %d\n", i, connectors[i], conn.count_modes);
if (conn.connection != DRM_MODE_CONNECTED) {
//printf("\tIgnoring unconnected connector. (%d)\n", conn.connection);
continue;
}
struct drm_mode_modeinfo *modes = (struct drm_mode_modeinfo *)conn.modes_ptr;
for (int m=0; m<conn.count_modes; m++) {
printf("\tMode: %dx%d\n", modes[m].hdisplay, modes[m].vdisplay);
//sleep_sec(1);
if (hres == modes[m].hdisplay && vres == modes[m].vdisplay) {
return set_mode(&data, conn, modes[m]);
}
}
}
sys_ioctl(fd, DRM_IOCTL_DROP_MASTER, 0);
return 0;
}
bool create_framebuffer(int fd, struct mydrm_buf *buf) {
struct drm_mode_create_dumb creq;
struct drm_mode_create_dumb dreq;
struct drm_mode_map_dumb mreq;
mem_set(&creq, 0, sizeof(creq));
creq.width = buf->width;
creq.height = buf->height;
creq.bpp = 32;
int ret = mydrm_ioctl(fd, DRM_IOCTL_MODE_CREATE_DUMB, &creq);
if (ret < 0) {
printf("Failed to create buffer: %d\n", ret);
return false;
}
buf->stride = creq.pitch;
buf->size = creq.size;
buf->handle = creq.handle;
struct drm_mode_fb_cmd fbcmd;
mem_set(&fbcmd, 0, sizeof(fbcmd));
fbcmd.width = buf->width;
fbcmd.height = buf->height;
fbcmd.depth = 24;
fbcmd.bpp = 32;
fbcmd.pitch = buf->stride;
fbcmd.handle = buf->handle;
ret = mydrm_ioctl(fd, DRM_IOCTL_MODE_ADDFB, &fbcmd);
if (ret < 0) {
printf("Failed to add FB: %d\n", ret);
return false;
}
buf->fb = fbcmd.fb_id;
mem_set(&mreq, 0, sizeof(mreq));
mreq.handle = buf->handle;
ret = mydrm_ioctl(fd, DRM_IOCTL_MODE_MAP_DUMB, &mreq);
if (ret) {
printf("Failed to map FB: %d\n", ret);
return false;
}
buf->map = sys_mmap(0, buf->size, PROT_READ | PROT_WRITE, MAP_SHARED, fd, mreq.offset);
if (((int64_t)buf->map) == -1) {
printf("Failed to map FB!\n");
return false;
}
mem_set(buf->map, 0, buf->size);
return true;
}
int cursor_size = 20;
uint32_t bg_color = 0xFF999999;
//AARRGGBB
uint32_t cursor_color = 0xFF0000FF;
bool left_down = false;
bool right_down = false;
static void draw_data(int fd, struct mydrm_data *data) {
struct mydrm_buf *buf = &data->framebuffer[data->front_buf ^ 1];
int start_x = mouse_pos.x;
int start_y = mouse_pos.y;
uint32_t *p = (uint32_t *)buf->map;
//clear background.
mem_set(p, bg_color, buf->size);
for (int x=0; x<cursor_size; x++) {
for (int y=0; y<cursor_size; y++) {
int pos = (start_x + x) + ((start_y + y) * data->width);
if (pos * 4 >= buf->size) {
//don't try to draw past end of buffer..
break;
}
uint32_t color = cursor_color;
if (left_down) {
color |= 0x00FF0000;
}
if (right_down) {
color |= 0x0000FF00;
}
p[pos] = color;
}
}
struct drm_mode_crtc_page_flip flip;
flip.fb_id = buf->fb;
flip.crtc_id = data->crt_id;
flip.user_data = (uint64_t)data;
flip.flags = DRM_MODE_PAGE_FLIP_EVENT;
flip.reserved = 0;
int ret = mydrm_ioctl(fd, DRM_IOCTL_MODE_PAGE_FLIP, &flip);
if (!ret) {
data->pflip_pending = true;
data->front_buf ^= 1;
} else {
printf("Failed to flip: %d\n", ret);
}
}
static void page_flip_event(int fd, uint32_t frame, uint32_t sec, uint32_t usec, void *data) {
struct mydrm_data *dev = data;
dev->pflip_pending = false;
if (!dev->cleanup) {
draw_data(fd, dev);
}
}
int set_mode(struct mydrm_data *data, struct drm_mode_get_connector conn, struct drm_mode_modeinfo mode) {
if (!conn.encoder_id) {
printf("No encoder found!\n");
return -1;
}
struct drm_mode_get_encoder enc;
int ret = 0;
if (ret = mydrm_get_encoder(data->fd, conn.encoder_id, &enc)) {
printf("Encoder load failed: %d, %d - %d - %X\n", ret, data->fd, conn.encoder_id, &enc);
return -1;
}
if (!enc.crtc_id) {
printf("No CRT Controller!\n");
return -1;
}
data->framebuffer[0].width = mode.hdisplay;
data->framebuffer[0].height = mode.vdisplay;
data->framebuffer[1].width = mode.hdisplay;
data->framebuffer[1].height = mode.vdisplay;
mouse_pos.x = 0;
mouse_pos.y = 0;
mouse_pos.max_x = mode.hdisplay;
mouse_pos.max_y = mode.vdisplay;
if (!create_framebuffer(data->fd, &data->framebuffer[0])) {
printf("Failed to create framebuffer 1!\n");
return -1;
}
if (!create_framebuffer(data->fd, &data->framebuffer[1])) {
printf("Failed to create framebuffer 2!\n");
return -1;
}
printf("Buffer created with size: %d\n", data->framebuffer[0].size);
struct drm_mode_crtc crtc;
mem_set(&crtc, 0, sizeof(crtc));
crtc.crtc_id = enc.crtc_id;
data->crt_id = enc.crtc_id;
//get the current CRTC, should be FB controller.
ret = mydrm_ioctl(data->fd, DRM_IOCTL_MODE_GETCRTC, &crtc);
saved_crtc = crtc;
printf("Get CRTC: %d = %d (%d, %d, %x, %s)\n", crtc.crtc_id, ret, crtc.fb_id, crtc.count_connectors, crtc.set_connectors_ptr, crtc.mode.name);
mem_set(&crtc, 0, sizeof(crtc));
crtc.crtc_id = enc.crtc_id;
mem_copy(&crtc.mode, &mode, sizeof(mode));
crtc.x = 0;
crtc.y = 0;
crtc.fb_id = data->framebuffer[0].fb;
crtc.count_connectors = 1;
crtc.set_connectors_ptr = (uint64_t)&conn.connector_id;
crtc.mode_valid = 1;
int mouse_fd = sys_open("/dev/input/mice", O_RDONLY);
printf("MOUSE_FD: %d\n", mouse_fd);
printf("CRTC RES: %d/%d...\n", crtc.mode.hdisplay, crtc.mode.vdisplay);
sleep_sec(4);
//about to set mode...
ret = mydrm_ioctl(data->fd, DRM_IOCTL_MODE_SETCRTC, &crtc);
if (ret) {
printf("FAILED TO SET CRTC! %d\n", ret);
return ret;
}
sleep_sec(1);
draw_data(data->fd, data);
fd_set fds;
FD_ZERO(&fds);
struct mydrm_event_context ev;
mem_set(&ev, 0, sizeof(ev));
ev.version = 2;
ev.page_flip_handler = page_flip_event;
while(true) {
FD_SET(0, &fds);
FD_SET(data->fd, &fds);
FD_SET(mouse_fd, &fds);
ret = sys_select(mouse_fd + 1, &fds, NULL, NULL, NULL);
if (ret < 0) {
printf("SELECT FAILED! %d\n", ret);
break;
}
if (FD_ISSET(0, &fds)) {
//user pressed key...
break;
}
if (FD_ISSET(data->fd, &fds)) {
//drawing happened on the buffer...
mydrm_handle_event(data->fd, &ev);
}
if (FD_ISSET(mouse_fd, &fds)) {
//mouse event..
char buffer[3];
int r = sys_read(mouse_fd, buffer, 3);
mouse_pos.x += buffer[1];
mouse_pos.y -= buffer[2];
left_down = buffer[0] & 1;
right_down = buffer[0] & 2;
if (mouse_pos.x > mouse_pos.max_x - cursor_size) {
mouse_pos.x = mouse_pos.max_x - cursor_size;
}
if (mouse_pos.y > mouse_pos.max_y - cursor_size) {
mouse_pos.y = mouse_pos.max_y - cursor_size;
}
printf("MOUSE: %d, %d, %d\n", buffer[0], buffer[1], buffer[2]);
}
}
//after loop, restore original CRTC...
saved_crtc.count_connectors = 1;
saved_crtc.mode_valid = 1;
saved_crtc.set_connectors_ptr = (uint64_t)&conn.connector_id;
ret = mydrm_ioctl(data->fd, DRM_IOCTL_MODE_SETCRTC, &saved_crtc);
sys_ioctl(data->fd, DRM_IOCTL_DROP_MASTER, 0);
sys_close(data->fd);
printf("DONE!\n");
return 0;
}
================================================
FILE: linux_os/part10/src/fbset/Makefile
================================================
TARGET=fbset
CSOURCES = $(shell echo *.c)
OBJECTS = $(CSOURCES:.c=_c.o)
LDFLAGS = -lmy -lfb -L$(MYOS_PATH)/lib
BINDIR = $(PREFIX)/bin
all: $(TARGET)
$(TARGET): $(OBJECTS)
$(CC) $(LDFLAGS) $(FLAGS) -o $(TARGET) $(OBJECTS)
include ../base.mk
================================================
FILE: linux_os/part10/src/fbset/fbset.c
================================================
#include <mylib.h>
#include <libfb.h>
#include <errno.h>
#include <fcntl.h>
#include "printf.h"
int fill_fb(void *pbuffer, struct fb_var_screeninfo *vi, struct fb_fix_screeninfo *fi, uint32_t color) {
for (int x=0; x<vi->xres; x++) {
for (int y=0; y<vi->yres; y++) {
int location = (x + vi->xoffset) * (vi->bits_per_pixel / 8) + (y + vi->yoffset) * fi->line_length;
uint32_t *pb = (uint32_t*)(pbuffer + location);
*pb = color;
}
}
}
int main(int argc, char **argv) {
printf("Frame Buffer Setting...\n");
if (argc < 3) {
printf("Usage: fbset <xres> <yres>\n");
return -1;
}
int fdcon = sys_open("/dev/console", O_RDWR);
struct fb_var_screeninfo vi;
struct fb_fix_screeninfo fi;
fb_get_info(&vi, &fi);
int xres = str_to_int(argv[1]);
int yres = str_to_int(argv[2]);
printf("Current resolution: %dx%d\n", vi.xres, vi.yres);
printf("Setting resolution: %dx%d\n", xres, yres);
vi.xres = vi.xres_virtual = xres;
vi.yres = vi.yres_virtual = yres;
if (fb_put_info(&vi) != FB_SUCCESS) {
printf("FAILED TO SET BUFFER: %d", errno);
return -1;
}
void *pbuffer = fb_get_buffer();
if (fb_get_info(&vi, &fi) != FB_SUCCESS) {
printf("FAILED TO GET VIDEO INFO: %d\n", errno);
return -1;
}
sleep_sec(2);
fill_fb(pbuffer, &vi, &fi, 0xFFFFFFFF);
sleep_sec(2);
sys_ioctl(fdcon, KDSETMODE, (void*)KD_GRAPHICS);
sleep_sec(2);
fill_fb(pbuffer, &vi, &fi, 0xFFFF0000);
sleep_sec(2);
fill_fb(pbuffer, &vi, &fi, 0xFF00FF00);
sleep_sec(2);
fill_fb(pbuffer, &vi, &fi, 0xFF0000FF);
sleep_sec(2);
sys_ioctl(fdcon, KDSETMODE, (void*)KD_TEXT);
return 0;
}
================================================
FILE: linux_os/part10/src/include/libfb.h
================================================
#include <linux/fb.h>
#include <linux/kd.h>
#define FB_ERR_NOFB0 -1
#define FB_ERR_GETINFO -2
#define FB_ERR_PUTINFO -3
#define FB_ERR_MMAP -4
#define FB_SUCCESS 0
int fb_get_info(struct fb_var_screeninfo *vi, struct fb_fix_screeninfo *fi);
int fb_put_info(struct fb_var_screeninfo *vi);
void *fb_get_buffer();
================================================
FILE: linux_os/part10/src/include/mydrm.h
================================================
#pragma once
#include <stdint.h>
#include <stdbool.h>
#include <drm/drm.h>
#include <drm/drm_mode.h>
struct mydrm_get_cap {
uint64_t capability;
uint64_t value;
};
enum mydrm_modes {
DRM_MODE_CONNECTED = 1,
DRM_MODE_DISCONNECTED = 2,
DRM_MODE_UNKNOWN = 3
};
struct mydrm_event_context {
int version;
void (*vblank_handler)(int fd, uint32_t sequence, uint32_t tv_sec, uint32_t tv_usec, void *user_data);
void (*page_flip_handler)(int fd, uint32_t sequence, uint32_t tv_sec, uint32_t tv_usec, void *user_data);
};
extern int mydrm_ioctl(int fd, unsigned long request, void *arg);
extern int mydrm_open(const char *device_node);
extern int mydrm_get_resources(int fd, struct drm_mode_card_res *res);
extern int mydrm_get_connector(int fd, int id, struct drm_mode_get_connector *conn);
extern int mydrm_get_encoder(int fd, int id, struct drm_mode_get_encoder *enc);
extern int mydrm_handle_event(int fd, struct mydrm_event_context *context);
================================================
FILE: linux_os/part10/src/include/mylib.h
================================================
#pragma once
#include <sys/wait.h>
#include <time.h>
#include <stdbool.h>
#include <stdint.h>
#include <sys/select.h>
#include <sys/mman.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <unistd.h>
#include <sys/wait.h>
extern unsigned long _syscall(int num, void *a0, void *a1, void *a2, void *a3, void *a4, void *a5);
extern unsigned long sys_open(char *fn, int flags);
extern unsigned long sys_read(unsigned long fd, char *buff, unsigned long size);
extern unsigned long sys_reboot();
unsigned long sys_nanosleep(struct timespec *req, struct timespec *rem);
extern unsigned long str_len(char *sz);
extern void str_print(char *str);
extern void delay(int ticks);
extern void sleep_sec(int sec);
extern int str_eq(char *a, char *b);
extern unsigned long sys_write(unsigned long fd, char *buf, unsigned long len);
extern long sys_fork();
extern long sys_execve(char *filename, char **argv, char **envp);
extern int execute_process(char *filename);
extern int str_pos(char *s, char c);
extern unsigned long hex_str_to_ulong(char *s);
extern int str_to_int(char *s);
extern void *sys_brk(void *p);
extern int sys_select(int nfds, fd_set *readfds, fd_set *writefds,
fd_set *exceptfds, struct timeval *timeout);
extern void *mem_alloc(int size);
extern void mem_set(void *p, char n, size_t size);
extern void mem_copy(void *dest, void *source, size_t size);
extern void str_copy(char *dest, char *source);
extern void *sys_mmap(void *addr, size_t length, int prot, int flags, int fd, off_t offset);
extern int sys_munmap(void *addr, size_t length);
extern void *malloc(size_t size);
extern void free(void *addr);
extern int sys_stat(const char *pathname, struct stat *statbuf);
extern int sys_close(unsigned long fd);
extern int sys_ioctl(unsigned long fd, unsigned long cmd, void *arg);
extern int sys_waitid(idtype_t idtype, id_t id, siginfo_t *infop, int options);
================================================
FILE: linux_os/part10/src/include/printf.h
================================================
/*
File: printf.h
Copyright (C) 2004 Kustaa Nyholm
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
See the GNU Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
This library is really just two files: 'printf.h' and 'printf.c'.
They provide a simple and small (+200 loc) printf functionality to
be used in embedded systems.
I've found them so usefull in debugging that I do not bother with a
debugger at all.
They are distributed in source form, so to use them, just compile them
into your project.
Two printf variants are provided: printf and sprintf.
The formats supported by this implementation are: 'd' 'u' 'c' 's' 'x' 'X'.
Zero padding and field width are also supported.
If the library is compiled with 'PRINTF_SUPPORT_LONG' defined then the
long specifier is also
supported. Note that this will pull in some long math routines (pun intended!)
and thus make your executable noticably longer.
The memory foot print of course depends on the target cpu, compiler and
compiler options, but a rough guestimate (based on a H8S target) is about
1.4 kB for code and some twenty 'int's and 'char's, say 60 bytes of stack space.
Not too bad. Your milage may vary. By hacking the source code you can
get rid of some hunred bytes, I'm sure, but personally I feel the balance of
functionality and flexibility versus code size is close to optimal for
many embedded systems.
To use the printf you need to supply your own character output function,
something like :
void putc ( void* p, char c)
{
while (!SERIAL_PORT_EMPTY) ;
SERIAL_PORT_TX_REGISTER = c;
}
Before you can call printf you need to initialize it to use your
character output function with something like:
init_printf(NULL,putc);
Notice the 'NULL' in 'init_printf' and the parameter 'void* p' in 'putc',
the NULL (or any pointer) you pass into the 'init_printf' will eventually be
passed to your 'putc' routine. This allows you to pass some storage space (or
anything really) to the character output function, if necessary.
This is not often needed but it was implemented like that because it made
implementing the sprintf function so neat (look at the source code).
The code is re-entrant, except for the 'init_printf' function, so it
is safe to call it from interupts too, although this may result in mixed output.
If you rely on re-entrancy, take care that your 'putc' function is re-entrant!
The printf and sprintf functions are actually macros that translate to
'tfp_printf' and 'tfp_sprintf'. This makes it possible
to use them along with 'stdio.h' printf's in a single source file.
You just need to undef the names before you include the 'stdio.h'.
Note that these are not function like macros, so if you have variables
or struct members with these names, things will explode in your face.
Without variadic macros this is the best we can do to wrap these
fucnction. If it is a problem just give up the macros and use the
functions directly or rename them.
For further details see source code.
regs Kusti, 23.10.2004
*/
#ifndef __TFP_PRINTF__
#define __TFP_PRINTF__
#include <stdarg.h>
void init_printf(void* putp,void (*putf) (void*,char));
void tfp_printf(char *fmt, ...);
void tfp_sprintf(char* s,char *fmt, ...);
void tfp_format(void* putp,void (*putf) (void*,char),char *fmt, va_list va);
#define printf tfp_printf
#define sprintf tfp_sprintf
#endif
================================================
FILE: linux_os/part10/src/init/Makefile
================================================
TARGET=init
CSOURCES = $(shell echo *.c)
OBJECTS = $(CSOURCES:.c=_c.o)
LDFLAGS = -lmy -lfb -L$(MYOS_PATH)/lib
all: $(TARGET)
$(TARGET): $(OBJECTS)
$(CC) $(LDFLAGS) $(FLAGS) -o $(TARGET) $(OBJECTS)
include ../base.mk
================================================
FILE: linux_os/part10/src/init/crt0.S
================================================
.globl _start
_start: # _start is the entry point known to the linker
xor %ebp, %ebp # effectively RBP := 0, mark the end of stack frames
mov (%rsp), %edi # get argc from the stack (implicitly zero-extended to 64-bit)
lea 8(%rsp), %rsi # take the address of argv from the stack
lea 16(%rsp,%rdi,8), %rdx # take the address of envp from the stack
xor %eax, %eax # per ABI and compatibility with icc
call main # %edi, %rsi, %rdx are the three args (of which first two are C standard) to main
mov %eax, %edi # transfer the return of main to the first argument of _exit
xor %eax, %eax # per ABI and compatibility with icc
call _exit # terminate the program
================================================
FILE: linux_os/part10/src/init/init.c
================================================
#include <syscall.h>
#include <fcntl.h>
#include <mylib.h>
#include <libfb.h>
#include <linux/vt.h>
uint32_t fix_color(uint32_t num) {
return (num & 0xFF00FF00) | ((num & 0xFF) << 16) | ((num >> 16) & 0xFF);
}
int main() {
int fdcon = sys_open("/dev/console", O_RDWR);
sys_ioctl(fdcon, KDSETMODE, (void *)KD_GRAPHICS);
struct fb_var_screeninfo vi;
struct fb_fix_screeninfo fi;
fb_get_info(&vi, &fi);
vi.xres = vi.xres_virtual = 1024;
vi.yres = vi.yres_virtual = 768;
//add error handling here normally...
fb_put_info(&vi);
void *pbuffer = fb_get_buffer();
int fd = sys_open("/etc/myos.img", O_RDONLY);
int buff_size = sizeof(int) * 1024 * 768;
int *buff = malloc(buff_size);
sys_read(fd, buff, buff_size);
sys_close(fd);
int i = 0;
for (int y=0; y<vi.yres; y++) {
for (int x=0; x<vi.xres; x++) {
int location = (x + vi.xoffset) * (vi.bits_per_pixel / 8) + (y + vi.yoffset) * fi.line_length;
uint32_t *pb = (uint32_t *)(pbuffer + location);
*pb = fix_color(buff[i]);
i++;
}
}
sleep_sec(5);
sys_ioctl(fdcon, KDSETMODE, (void *)KD_TEXT);
execute_process("/bin/lash");
while(1) {
//event loop, for now just tick...
sleep_sec(1);
}
return 0;
}
================================================
FILE: linux_os/part10/src/lash/Makefile
================================================
TARGET=lash
CSOURCES = $(shell echo *.c)
OBJECTS = $(CSOURCES:.c=_c.o)
LDFLAGS = -lmy -L$(MYOS_PATH)/lib
BINDIR = $(PREFIX)/bin
all: $(TARGET)
$(TARGET): $(OBJECTS)
$(CC) $(LDFLAGS) $(FLAGS) -o $(TARGET) $(OBJECTS)
include ../base.mk
================================================
FILE: linux_os/part10/src/lash/lash.c
================================================
#include <mylib.h>
#include <fcntl.h>
#include "printf.h"
#include <linux/input-event-codes.h>
unsigned long console_fd = 0;
struct event_file {
struct event_file *next;
int fd;
char name[64];
};
struct input_event {
struct timeval time;
unsigned short type;
unsigned short code;
unsigned int value;
};
struct mouse_pos_info {
int x;
int y;
int max_x;
int max_y;
};
struct mouse_pos_info mouse_pos;
struct event_file *event_list_head;
void load_event_devices() {
printf("Loading Input Devices...\n");
event_list_head = NULL;
mouse_pos.x = 0;
mouse_pos.y = 0;
mouse_pos.max_x = 1024;
mouse_pos.max_y = 768;
for (int i=0; i<10; i++) {
char name[64];
sprintf(name, "/dev/input/event%d", i);
int fd = sys_open(name, O_RDONLY);
if (fd < 0) {
//not found
break;
}
struct event_file *e = malloc(sizeof(struct event_file));
str_copy(e->name, name);
e->fd = fd;
e->next = event_list_head;
event_list_head = e;
}
}
bool handle_event(struct event_file *e, struct input_event *event) {
if (event->type == EV_REL) {
//mouse relative event.
if (event->code == REL_X) {
//mouse X event
int new_x = mouse_pos.x + event->value;
if (new_x >= 0 && new_x <= mouse_pos.max_x) {
mouse_pos.x = new_x;
}
}
if (event->code == REL_Y) {
//mouse y event
int new_y = mouse_pos.y + event->value;
if (new_y >= 0 && new_y <= mouse_pos.max_y) {
mouse_pos.y = new_y;
}
}
printf("\rMOUSE_POS: %d - %d ", mouse_pos.x, mouse_pos.y);
}
if (event->type == EV_KEY) {
printf("KEY_INPUT: %s - %d - %d - %d\n", e->name, event->code, event->type, event->value);
if (event->code == KEY_END) {
printf("Exiting.\n");
return true;
}
}
return false;
}
void handle_events() {
printf("Listening for events...\n");
while(true) {
fd_set fds;
FD_ZERO(&fds);
struct event_file *e = event_list_head;
while(e) {
FD_SET(e->fd, &fds);
e = e->next;
}
int ret = sys_select(event_list_head->fd + 1, &fds, NULL, NULL, NULL);
if (ret < 0) {
printf("SELECT FAILED!\n");
return;
}
e = event_list_head;
while(e) {
if (FD_ISSET(e->fd, &fds)) {
char buffer[1024];
int r = sys_read(e->fd, buffer, sizeof(buffer));
int pos = 0;
while(pos < r) {
struct input_event *event = (struct input_event *)(buffer + pos);
pos += sizeof(struct input_event);
if (handle_event(e, event)) {
return;
}
}
}
e = e->next;
}
}
}
void console_open() {
console_fd = sys_open("/dev/console", O_RDWR | O_NDELAY);
}
char console_read() {
char c = 0;
while(!sys_read(console_fd, &c, 1)) {
struct timespec ts;
ts.tv_sec = 0;
ts.tv_nsec = 10000;
sys_nanosleep(&ts, NULL);
}
return c;
}
void console_write(char c) {
sys_write(console_fd, &c, 1);
}
int read_line(char *buff, int max) {
int i=0;
for (; i<max; i++) {
char c = console_read();
if (c == 0) {
i--;
continue;
}
console_write(c);
buff[i] = c;
if (c == '\b') {
i--;
buff[i] = 0;
}
if (c == '\n') {
buff[i] = 0;
return i;
}
}
return i;
}
char **cmd_to_args(char *cmd) {
int num_spaces = 0;
int len = str_len(cmd);
for (int i=0; i<len; i++) {
if (cmd[i] == ' ') {
cmd[i] = 0;
num_spaces++;
}
}
char **argv = malloc(sizeof(char *) * (num_spaces + 1));
int cur_item = 0;
argv[0] = cmd;
for (int i=0; i<len; i++) {
if (cmd[i] == 0) {
argv[++cur_item] = cmd + i + 1;
}
}
argv[++cur_item] = 0;
return argv;
}
bool find_command(char *fullPath) {
struct stat statbuf;
char binPath[64];
if (sys_stat(fullPath, &statbuf) == 0) {
return true;
}
sprintf(binPath, "/bin/%s", fullPath);
str_copy(fullPath, binPath);
if (sys_stat(fullPath, &statbuf) == 0) {
return true;
}
return false;
}
bool process_command(char *cmd) {
char **argv = cmd_to_args(cmd);
if (str_eq(cmd, "reboot")) {
str_print("\n\n*** SYSTEM REBOOTING ***\n");
sys_reboot();
} else if (str_eq(cmd, "alloc")) {
int size = 0;
if (argv[1]) {
//brk 4096
size = str_to_int(argv[1]);
}
void *p = malloc(size);
printf("Returned pointer: %lX\n", p);
print_heap();
} else if (str_eq(cmd, "free")) {
//free ADDRESS
unsigned long addr = hex_str_to_ulong(argv[1]);
free(addr);
print_heap();
} else if (str_eq(cmd, "store")) {
//store ADDRESS VALUE
//store 1CF0000 12345
//second arg..
char *val = argv[2];
unsigned long addr = hex_str_to_ulong(argv[1]);
int n = str_to_int(val);
printf("Storing %d at %X\n", n, addr);
int *p = (int *)addr;
*p = n;
} else if (str_eq(cmd, "fetch")) {
//fetch ADDRESS
unsigned long addr = hex_str_to_ulong(argv[1]);
int *p = (int *)addr;
printf("Fetched %d from %X\n", *p, addr);
} else if (str_eq(cmd, "events")) {
handle_events();
} else {
struct stat statbuf;
char fullPath[64];
str_copy(fullPath, cmd);
if (find_command(fullPath)) {
long pid = sys_fork();
if (pid == 0) {
char *envp[1];
envp[0] = 0;
int ret = sys_execve(fullPath, argv, envp);
printf("Ret: %d\n", ret);
free(argv);
_exit(ret);
return false;
} else {
siginfo_t info;
int status = 0;
int ret = sys_waitid(P_PID, pid, &info, WEXITED);
printf("Process Returned: %d\n", ret);
}
}
}
free(argv);
return true;
}
int main() {
str_print("\033[H\033[J");
str_print("LASH v0.0.0.3\n");
print_heap();
console_open();
load_event_devices();
print_heap();
str_print(" :> ");
while(1) {
char buff[1024];
read_line(buff, sizeof(buff));
if (str_eq("", buff)) {
str_print(" :> ");
continue;
}
if (!process_command(buff)) {
return 0;
}
str_print(" :> ");
}
}
================================================
FILE: linux_os/part10/src/libfb/Makefile
================================================
LDFLAGS = -shared
TARGET = libfb.so
CSOURCES = $(shell echo *.c)
SSOURCES = $(shell echo *.S)
FLAGS = -nostdlib -I../include -fPIC
OBJECTS = $(CSOURCES:.c=_c.o)
BINDIR = $(PREFIX)/lib
all: $(TARGET)
$(TARGET): $(OBJECTS)
ld $(FLAGS) $(LDFLAGS) -o $(TARGET) $(OBJECTS)
include ../base.mk
================================================
FILE: linux_os/part10/src/libfb/fb.c
================================================
#include <mylib.h>
#include <libfb.h>
#include <fcntl.h>
#include <errno.h>
int fb_get_info(struct fb_var_screeninfo *vi, struct fb_fix_screeninfo *fi) {
int fd = sys_open("/dev/fb0", O_RDONLY);
if (fd < 0) {
errno = fd;
return FB_ERR_NOFB0;
}
int ret;
if ((ret = sys_ioctl(fd, FBIOGET_VSCREENINFO, vi)) < 0) {
errno = ret;
sys_close(fd);
return FB_ERR_GETINFO;
}
if ((ret = sys_ioctl(fd, FBIOGET_FSCREENINFO, fi)) < 0) {
errno = ret;
sys_close(fd);
return FB_ERR_GETINFO;
}
sys_close(fd);
return FB_SUCCESS;
}
int fb_put_info(struct fb_var_screeninfo *vi) {
int fd = sys_open("/dev/fb0", O_RDWR);
if (fd < 0) {
errno = fd;
return FB_ERR_NOFB0;
}
int ret;
if ((ret = sys_ioctl(fd, FBIOPUT_VSCREENINFO, vi)) < 0) {
errno = ret;
sys_close(fd);
return FB_ERR_PUTINFO;
}
sys_close(fd);
return FB_SUCCESS;
}
void *fb_get_buffer() {
struct fb_fix_screeninfo fi;
int fd = sys_open("/dev/fb0", O_RDWR);
if (fd < 0) {
errno = fd;
return (void *)FB_ERR_NOFB0;
}
int ret;
if ((ret = sys_ioctl(fd, FBIOGET_FSCREENINFO, &fi)) < 0) {
errno = ret;
sys_close(fd);
return (void *)FB_ERR_GETINFO;
}
void *fb = sys_mmap(0, fi.smem_len, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0);
sys_close(fd);
return fb;
}
================================================
FILE: linux_os/part10/src/mydrm/Makefile
================================================
LDFLAGS = -shared
TARGET = libmydrm.so
CSOURCES = $(shell echo *.c)
FLAGS = -nostdlib -I../include -fPIC
OBJECTS = $(CSOURCES:.c=_c.o)
BINDIR = $(PREFIX)/lib
all: $(TARGET)
$(TARGET): $(OBJECTS)
ld $(FLAGS) $(LDFLAGS) -o $(TARGET) $(OBJECTS)
include ../base.mk
================================================
FILE: linux_os/part10/src/mydrm/mydrm.c
================================================
#include <mydrm.h>
#include <mylib.h>
#include <fcntl.h>
#include <errno.h>
#ifndef O_CLOEXEC
#define O_CLOEXEC 02000000
#endif
int mydrm_ioctl(int fd, unsigned long request, void *arg) {
int ret;
do {
ret = sys_ioctl(fd, request, arg);
} while(ret == -EINTR || ret == -EAGAIN);
return ret;
}
//opening a device such as /dev/dri/card0
int mydrm_open(const char *device_node) {
int fd = sys_open((char *)device_node, O_RDWR | O_CLOEXEC);
if (fd < 0) {
return fd;
}
struct mydrm_get_cap get_cap = {
.capability = DRM_CAP_DUMB_BUFFER,
.value = 0
};
if (mydrm_ioctl(fd, DRM_IOCTL_GET_CAP, &get_cap) < 0 || !get_cap.value) {
return -EOPNOTSUPP;
}
return fd;
}
int mydrm_get_resources(int fd, struct drm_mode_card_res *res) {
mem_set(res, 0, sizeof(struct drm_mode_card_res));
int ior = 0;
if (mydrm_ioctl(fd, DRM_IOCTL_MODE_GETRESOURCES, res)) {
return -1;
}
if (res->count_fbs) {
res->fb_id_ptr = (uint64_t)malloc(res->count_fbs * sizeof(uint32_t));
mem_set((void *)res->fb_id_ptr, 0, res->count_fbs * sizeof(uint32_t));
}
if (res->count_crtcs) {
res->crtc_id_ptr = (uint64_t)malloc(res->count_crtcs * sizeof(uint32_t));
mem_set((void *)res->crtc_id_ptr, 0, res->count_crtcs * sizeof(uint32_t));
}
if (res->count_connectors) {
res->connector_id_ptr = (uint64_t)malloc(res->count_connectors * sizeof(uint32_t));
mem_set((void *)res->connector_id_ptr, 0, res->count_connectors * sizeof(uint32_t));
}
if (res->count_encoders) {
res->encoder_id_ptr = (uint64_t)malloc(res->count_encoders * sizeof(uint32_t));
mem_set((void *)res->encoder_id_ptr, 0, res->count_encoders * sizeof(uint32_t));
}
ior = mydrm_ioctl(fd, DRM_IOCTL_MODE_GETRESOURCES, res);
if (ior) {
return -1;
}
return 0;
}
int mydrm_get_connector(int fd, int id, struct drm_mode_get_connector *conn) {
mem_set(conn, 0, sizeof(struct drm_mode_get_connector));
conn->connector_id = id;
if (mydrm_ioctl(fd, DRM_IOCTL_MODE_GETCONNECTOR, conn)) {
return -1;
}
if (conn->count_props) {
conn->props_ptr = (uint64_t)malloc(conn->count_props * sizeof(uint32_t));
conn->prop_values_ptr = (uint64_t)malloc(conn->count_props * sizeof(uint64_t));
}
if (conn->count_modes) {
conn->modes_ptr = (uint64_t)malloc(conn->count_modes * sizeof(struct drm_mode_modeinfo));
}
if (conn->count_encoders) {
conn->encoders_ptr = (uint64_t)malloc(conn->count_encoders * sizeof(uint32_t));
}
if (mydrm_ioctl(fd, DRM_IOCTL_MODE_GETCONNECTOR, conn)) {
return -1;
}
return 0;
}
int mydrm_get_encoder(int fd, int id, struct drm_mode_get_encoder *enc) {
mem_set(enc, 0, sizeof(struct drm_mode_get_encoder));
enc->encoder_id = id;
if (mydrm_ioctl(fd, DRM_IOCTL_MODE_GETENCODER, enc)) {
return -1;
}
return 0;
}
int mydrm_handle_event(int fd, struct mydrm_event_context *context) {
char buffer[1024];
struct drm_event *e;
int len = sys_read(fd, buffer, sizeof(buffer));
if (!len) {
return 0;
}
if (len < sizeof(struct drm_event)) {
return -1;
}
int i=0;
while(i < len) {
e = (struct drm_event *)&buffer[i];
i += e->length;
switch(e->type) {
case DRM_EVENT_FLIP_COMPLETE: {
struct drm_event_vblank *vb = (struct drm_event_vblank *)e;
context->page_flip_handler(fd, vb->sequence, vb->tv_sec, vb->tv_usec, (void *)vb->user_data);
} break;
}
}
return 0;
}
================================================
FILE: linux_os/part10/src/mylib/Makefile
================================================
LDFLAGS = -shared
TARGET = libmy.so
CSOURCES = $(shell echo *.c)
SSOURCES = $(shell echo *.S)
FLAGS = -nostdlib -I../include -fPIC
OBJECTS = $(CSOURCES:.c=_c.o)
OBJECTS += $(SSOURCES:.S=_s.o)
BINDIR = $(PREFIX)/lib
all: $(TARGET)
$(TARGET): $(OBJECTS)
ld $(FLAGS) $(LDFLAGS) -o $(TARGET) $(OBJECTS)
include ../base.mk
================================================
FILE: linux_os/part10/src/mylib/mem.c
================================================
#include <mylib.h>
#include "printf.h"
#define DEBUG_MEM 1
#define FLAG_MEM_ALLOCATED 1
#define FLAG_MEM_MAPPED 2
static const int PAGE_SIZE = 4096;
static const int RESIZE_THRESHOLD = 16;
static const int MMAP_THRESHOLD = 128 * 1024;
static const int HEADER_SIZE = 4;
static const int HEADER_FULL_SIZE = HEADER_SIZE * 2;
static uint32_t HEADER_SIZE_MASK = 0xFFFFFFF8;
static uint32_t HEADER_FLAGS_MASK = 7; //0111
/*
CHUNK_HEADER {
size: 29-bits - 8 bit aligned
flags: 3-bits
}
HEAP CHUNK = {
header: 4 bytes
data: $size bytes
header: 4 bytes
}
MMAP CHUNK = {
header: 4 bytes
data: $size bytes
}
Header Flags:
Bit 0 - 0 = free, 1 = allocated
Bit 1 - 0 = heap, 1 = mmap
Bit 2 - reserved.
Heap Layout:
|-H1-SIZE-FLAGS-| < heap start, first chunk header.
|---------------|
|---------------|
|---------------|
|---------------|
|-H1-SIZE-FLAGS-| < first chunk header
|-H2-SIZE-FLAGS-| < second chunk header
|---------------|
|---------------|
|---------------|
|---------------|
|-H2-SIZE-FLAGS-| < second chunk header
|---------------| < heap end (current brk value)
*/
static uint8_t *p_heap_start = NULL;
static uint8_t *p_first_free = NULL;
static uint8_t *p_heap_end = NULL;
#define P_AS_U32(p) ((uint32_t*)p)
static inline uint32_t chunk_size(uint8_t *p) {
return *P_AS_U32(p) & HEADER_SIZE_MASK;
}
static inline bool is_chunk_alloc(uint8_t *p) {
return *P_AS_U32(p) & FLAG_MEM_ALLOCATED;
}
static inline bool is_chunk_free(uint8_t *p) {
return !is_chunk_alloc(p);
}
static inline bool is_chunk_mapped(uint8_t *p) {
return *P_AS_U32(p) & FLAG_MEM_MAPPED;
}
static inline uint8_t *next_chunk(uint8_t *p) {
return (p + chunk_size(p) + HEADER_FULL_SIZE);
}
static inline uint8_t *chunk_set_size(uint8_t *p, size_t size) {
*P_AS_U32(p) = size;
*P_AS_U32((p + size + HEADER_SIZE)) = size;
return p;
}
static inline uint8_t *chunk_set_flags(uint8_t *p, uint32_t flags) {
*P_AS_U32(p) |= flags;
*P_AS_U32((p + chunk_size(p) + HEADER_SIZE)) |= flags;
return p;
}
static inline uint8_t *chunk_unset_flags(uint8_t *p, uint32_t flags) {
*P_AS_U32(p) &= ~flags;
*P_AS_U32((p + chunk_size(p) + HEADER_SIZE)) &= ~flags;
return p;
}
static inline size_t align_8(size_t size) {
uint32_t flags = size & HEADER_FLAGS_MASK;
return flags ? size + 8 - flags : size;
}
static void init_heap() {
p_heap_start = sys_brk(NULL);
p_heap_end = p_heap_start + PAGE_SIZE;
sys_brk(p_heap_end);
//the first free entry is at the start of the heap...
p_first_free = p_heap_start;
//nothing allocated yet, so set size full...
chunk_set_size(p_first_free, PAGE_SIZE - HEADER_FULL_SIZE);
if (DEBUG_MEM) {
printf("MEM: Init Heap:\n");
printf("MEM: \tStart: %lX\n", p_heap_start);
printf("MEM: \tEnd : %lX\n", p_heap_end);
printf("MEM: \tFirst Size: %ld\n", chunk_size(p_first_free));
printf("MEM: \tHeap Size: %ld\n", p_heap_end - p_heap_start);
}
}
void print_heap() {
if (!DEBUG_MEM) {
return;
}
if (!p_heap_start) {
init_heap();
}
printf("MEM: Heap Info %lX to %lX (%ld):\n", p_heap_start, p_heap_end, p_heap_end - p_heap_start);
uint8_t *p = p_heap_start;
while(p < p_heap_end) {
printf("\tMEM: %lX Size: %d - %s\n", p, chunk_size(p), is_chunk_free(p) ? "FREE" : "ALLOC");
p = next_chunk(p);
}
}
static uint8_t *find_first_fit(size_t size) {
for (uint8_t *p = p_first_free; p < p_heap_end; p = next_chunk(p)) {
if (is_chunk_free(p) && chunk_size(p) >= size) {
return p;
}
}
return NULL; //need more memory.
}
static uint8_t *alloc_new_memory(size_t in_size) {
int num_pages = (in_size / PAGE_SIZE) + 1;
if (in_size % PAGE_SIZE < HEADER_FULL_SIZE) {
//there is enough space for buffer, but not buffer + headers.
num_pages++;
}
size_t size = num_pages * PAGE_SIZE;
char *prev_end = p_heap_end;
p_heap_end = sys_brk(p_heap_end + size);
return chunk_set_size(prev_end, size - HEADER_FULL_SIZE);
}
void *malloc(size_t in_size) {
if (!p_heap_start) {
init_heap();
}
if (in_size >= MMAP_THRESHOLD) {
//not going to use heap, actually use mmap instead...
uint8_t *p = sys_mmap(NULL, in_size + HEADER_SIZE_MASK, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);
chunk_set_size(p, in_size);
chunk_set_flags(p, FLAG_MEM_MAPPED | FLAG_MEM_ALLOCATED);
//user's pointer starts just past the header.
return p + HEADER_SIZE;
}
//not mmap, use heap instead.
//8 bit align the size...
size_t size = align_8(in_size);
uint8_t *p = find_first_fit(size);
if (p == NULL) {
p = alloc_new_memory(size);
}
size_t csize = chunk_size(p);
size_t diff = csize - size;
if (diff > RESIZE_THRESHOLD) {
size_t next_size = diff - HEADER_FULL_SIZE;
chunk_set_size(p, size);
chunk_set_size(next_chunk(p), next_size);
}
chunk_set_flags(p, FLAG_MEM_ALLOCATED);
return p + HEADER_SIZE;
}
void free(void *up) {
uint8_t *p = ((uint8_t *)up) - HEADER_SIZE;
if (is_chunk_mapped(p)) {
//it was not on the heap, unmap it.
int ret = sys_munmap(p, chunk_size(p) + HEADER_SIZE);
if (DEBUG_MEM) {
printf("MEM: free mapped, returned %d\n", ret);
}
return;
}
chunk_unset_flags(p, FLAG_MEM_ALLOCATED);
if (is_chunk_free(next_chunk(p))) {
//if next chunk is free, let's merge them.
size_t new_size = chunk_size(p) + chunk_size(next_chunk(p)) + HEADER_FULL_SIZE;
chunk_set_size(p, new_size);
}
if (next_chunk(p) >= p_heap_end) {
//we are on the last chunk on the heap, let's do some actual
//freeing of memory and move the brk back some.
p_heap_end = sys_brk(p);
}
if (p < p_first_free) {
p_first_free = p;
}
}
================================================
FILE: linux_os/part10/src/mylib/printf.c
================================================
/*
File: printf.c
Copyright (C) 2004 Kustaa Nyholm
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#include "printf.h"
#include <mylib.h>
#include <fcntl.h>
typedef void (*putcf) (void*,char);
static putcf stdout_putf = NULL;
static void* stdout_putp = NULL;
#define PRINTF_LONG_SUPPORT 1
#ifdef PRINTF_LONG_SUPPORT
static void uli2a(unsigned long int num, unsigned int base, int uc,char * bf)
{
int n=0;
unsigned long int d=1;
while (num/d >= base)
d*=base;
while (d!=0) {
int dgt = num / d;
num%=d;
d/=base;
if (n || dgt>0|| d==0) {
*bf++ = dgt+(dgt<10 ? '0' : (uc ? 'A' : 'a')-10);
++n;
}
}
*bf=0;
}
static void li2a (long num, char * bf)
{
if (num<0) {
num=-num;
*bf++ = '-';
}
uli2a(num,10,0,bf);
}
#endif
static void ui2a(unsigned int num, unsigned int base, int uc,char * bf)
{
int n=0;
unsigned int d=1;
while (num/d >= base)
d*=base;
while (d!=0) {
int dgt = num / d;
num%= d;
d/=base;
if (n || dgt>0 || d==0) {
*bf++ = dgt+(dgt<10 ? '0' : (uc ? 'A' : 'a')-10);
++n;
}
}
*bf=0;
}
static void i2a (int num, char * bf)
{
if (num<0) {
num=-num;
*bf++ = '-';
}
ui2a(num,10,0,bf);
}
static int a2d(char ch)
{
if (ch>='0' && ch<='9')
return ch-'0';
else if (ch>='a' && ch<='f')
return ch-'a'+10;
else if (ch>='A' && ch<='F')
return ch-'A'+10;
else return -1;
}
static char a2i(char ch, char** src,int base,int* nump)
{
char* p= *src;
int num=0;
int digit;
while ((digit=a2d(ch))>=0) {
if (digit>base) break;
num=num*base+digit;
ch=*p++;
}
*src=p;
*nump=num;
return ch;
}
static void putchw(void* putp,putcf putf,int n, char z, char* bf)
{
char fc=z? '0' : ' ';
char ch;
char* p=bf;
while (*p++ && n > 0)
n--;
while (n-- > 0)
putf(putp,fc);
while ((ch= *bf++))
putf(putp,ch);
}
void tfp_format(void* putp,putcf putf,char *fmt, va_list va)
{
char bf[12];
char ch;
while ((ch=*(fmt++))) {
if (ch!='%')
putf(putp,ch);
else {
char lz=0;
#ifdef PRINTF_LONG_SUPPORT
char lng=0;
#endif
int w=0;
ch=*(fmt++);
if (ch=='0') {
ch=*(fmt++);
lz=1;
}
if (ch>='0' && ch<='9') {
ch=a2i(ch,&fmt,10,&w);
}
#ifdef PRINTF_LONG_SUPPORT
if (ch=='l') {
ch=*(fmt++);
lng=1;
}
#endif
switch (ch) {
case 0:
goto abort;
case 'u' : {
#ifdef PRINTF_LONG_SUPPORT
if (lng)
uli2a(va_arg(va, unsigned long int),10,0,bf);
else
#endif
ui2a(va_arg(va, unsigned int),10,0,bf);
putchw(putp,putf,w,lz,bf);
break;
}
case 'd' : {
#ifdef PRINTF_LONG_SUPPORT
if (lng)
li2a(va_arg(va, unsigned long int),bf);
else
#endif
i2a(va_arg(va, int),bf);
putchw(putp,putf,w,lz,bf);
break;
}
case 'x': case 'X' :
#ifdef PRINTF_LONG_SUPPORT
if (lng)
uli2a(va_arg(va, unsigned long int),16,(ch=='X'),bf);
else
#endif
ui2a(va_arg(va, unsigned int),16,(ch=='X'),bf);
putchw(putp,putf,w,lz,bf);
break;
case 'c' :
putf(putp,(char)(va_arg(va, int)));
break;
case 's' :
putchw(putp,putf,w,0,va_arg(va, char*));
break;
case '%' :
putf(putp,ch);
default:
break;
}
}
}
abort:;
}
void init_printf(void* putp,void (*putf) (void*,char))
{
stdout_putf=putf;
stdout_putp=putp;
}
extern unsigned long printf_fd = 0;
void putc_console(void *p, char c) {
sys_write(printf_fd, &c, 1);
}
void tfp_printf(char *fmt, ...)
{
va_list va;
va_start(va,fmt);
if (stdout_putf == NULL) {
printf_fd = sys_open("/dev/console", O_WRONLY | O_NDELAY);
stdout_putf = putc_console;
}
tfp_format(stdout_putp,stdout_putf,fmt,va);
va_end(va);
}
static void putcp(void* p,char c)
{
*(*((char**)p))++ = c;
}
void tfp_sprintf(char* s,char *fmt, ...)
{
va_list va;
va_start(va,fmt);
tfp_format(&s,putcp,fmt,va);
putcp(&s,0);
va_end(va);
}
================================================
FILE: linux_os/part10/src/mylib/start.S
================================================
.globl _syscall
_syscall:
movq %rdi, %rax
movq %rsi, %rdi
movq %rdx, %rsi
movq %rcx, %rdx
movq %r8, %r10
movq %r9, %r8
movq 8(%rsp), %r9
syscall
ret
================================================
FILE: linux_os/part10/src/mylib/sys.c
================================================
#include <syscall.h>
#include <mylib.h>
unsigned long sys_open(char *fn, int flags) {
return _syscall(SYS_open, fn, (void *)(long)flags, 0, 0, 0, 0);
}
unsigned long sys_read(unsigned long fd, char *buff, unsigned long size) {
return _syscall(SYS_read, (void *)fd, buff, (void *)size, 0, 0, 0);
}
unsigned long sys_reboot() {
return _syscall(SYS_reboot, (void *)0xfee1dead, (void *)672274793, (void*)0x1234567, 0, 0, 0);
}
unsigned long sys_nanosleep(struct timespec *req, struct timespec *rem) {
return _syscall(SYS_nanosleep, req, rem, 0, 0, 0, 0);
}
void sleep_sec(int sec) {
struct timespec tm;
tm.tv_nsec = 0;
tm.tv_sec = sec;
sys_nanosleep(&tm, NULL);
}
unsigned long sys_write(unsigned long fd, char *buf, unsigned long len) {
return _syscall(SYS_write, fd, buf, len, 0, 0, 0);
}
long sys_fork() {
return _syscall(SYS_fork, 0, 0, 0, 0, 0, 0);
}
long sys_execve(char *filename, char **argv, char **envp) {
return _syscall(SYS_execve, filename, argv, envp, 0, 0, 0);
}
int execute_process(char *filename) {
long pid = sys_fork();
if (!pid) {
char *argv[2];
argv[0] = filename;
argv[1] = 0;
char *envp[1];
envp[0] = 0;
return sys_execve(filename, argv, envp);
}
}
/*
.text .data .bss heap invalid stack
[--------|-------|-------|---------|XXXXXXXXXXXXXXXXXXXXXXXXXXXXX|-----]
^ brk (0x1FC1000)
brk(0) = 0x1FC0000
brk(0x1FC0000 + 0x1000) = 0x1FC1000
*/
void *sys_brk(void *p) {
return _syscall(SYS_brk, p, 0, 0, 0, 0, 0);
}
int sys_select(int nfds, fd_set *readfds, fd_set *writefds,
fd_set *exceptfds, struct timeval *timeout) {
return _syscall(SYS_select, nfds, readfds, writefds, exceptfds, timeout, 0);
}
void *sys_mmap(void *addr, size_t length, int prot, int flags, int fd, off_t offset) {
return _syscall(SYS_mmap, addr, length, prot, flags, fd, offset);
}
int sys_munmap(void *addr, size_t length) {
return _syscall(SYS_munmap, addr, length, 0, 0, 0, 0);
}
int sys_stat(const char *pathname, struct stat *statbuf) {
return _syscall(SYS_stat, pathname, statbuf, 0, 0, 0, 0);
}
int sys_close(unsigned long fd) {
return _syscall(SYS_close, fd, 0, 0, 0, 0, 0);
}
int sys_ioctl(unsigned long fd, unsigned long cmd, void *arg) {
return _syscall(SYS_ioctl, fd, cmd, arg, 0, 0, 0);
}
int sys_waitid(idtype_t idtype, id_t id, siginfo_t *infop, int options) {
return _syscall(SYS_waitid, (unsigned long)idtype, id, infop, options, 0, 0);
}
================================================
FILE: linux_os/part10/src/mylib/util.c
================================================
#include <mylib.h>
#include <syscall.h>
#include "printf.h"
unsigned long str_len(char *sz) {
int count = 0;
while(*sz++) {
count++;
}
return count;
}
void delay(int ticks) {
for (int i=0; i<ticks; i++) {
//nothing...
}
}
void str_print(char *str) {
_syscall(SYS_write, (void *)1 /*stdout*/, str, (void *)str_len(str), 0, 0, 0);
}
int str_eq(char *a, char *b) {
char ca = *a;
char cb = *b;
for (; ca != 0 && cb != 0; ca = *(++a), cb = *(++b)) {
if (ca != cb) {
return 0;
}
}
return ca == cb;
}
int str_pos(char *s, char c) {
for (int i=0; s[i]; i++) {
if (s[i] == c) {
return i;
}
}
return -1;
}
unsigned long hex_str_to_ulong(char *s) {
static char *hexchars = "0123456789ABCDEF";
unsigned long result = 0;
for (; *s; s++) {
result *= 0x10;
result += str_pos(hexchars, *s);
}
return result;
}
int str_to_int(char *s) {
bool neg = *s == '-';
int result = 0;
if (neg) {
s++;
}
for (; *s; s++) {
result *= 10;
result += *s - '0';
}
return neg ? -result : result;
}
void mem_set(void *p, char n, size_t size) {
char *b = (char *)p;
for (int i=0; i<size; i++) {
*b++ = n;
}
}
void mem_copy(void *dest, void *source, size_t size) {
char *d = (char *)dest;
char *s = (char *)source;
for (int i=0; i<size; i++) {
d[i] = s[i];
}
}
void str_copy(char *dest, char *source) {
mem_copy(dest, source, str_len(source) + 1);
}
void _exit(int code) {
return _syscall(SYS_exit, code, 0, 0, 0, 0, 0);
}
int errno_value = 0;
int *__errno_location() {
return &errno_value;
}
================================================
FILE: linux_os/part10/src/printargs/Makefile
================================================
TARGET=printargs
CSOURCES = $(shell echo *.c)
OBJECTS = $(CSOURCES:.c=_c.o)
LDFLAGS = -lmy -L$(MYOS_PATH)/lib
BINDIR = $(PREFIX)/bin
all: $(TARGET)
$(TARGET): $(OBJECTS)
$(CC) $(LDFLAGS) $(FLAGS) -o $(TARGET) $(OBJECTS)
include ../base.mk
================================================
FILE: linux_os/part10/src/printargs/printargs.c
================================================
#include <mylib.h>
#include "printf.h"
int main(int argc, char **argv) {
printf("PrintArgs: %d\n", argc);
for (int i=1; i<argc; i++) {
printf("\t%d = %s\n", i, argv[i]);
}
sleep_sec(2);
printf("done\n");
return 0;
}
================================================
FILE: linux_os/part2/src/base.mk
================================================
SHELL ?= /bin/sh
CC ?= gcc
FLAGS ?= -nostdlib -I../include
MYOS_PATH ?= /mnt/myos
DESTDIR ?= /mnt/myos
PREFIX ?= $(DESTDIR)
BINDIR ?= $(PREFIX)/sbin
OBJECTS += ../crt0_s.o
%_c.o: %.c
$(CC) $(FLAGS) -c $< -o $@
%_s.o: %.S
$(CC) $(FLAGS) -c $< -o $@
install:
cp $(TARGET) $(BINDIR)/
clean:
rm *.o $(TARGET)
================================================
FILE: linux_os/part2/src/include/mylib.h
================================================
#pragma once
extern unsigned long _syscall(int num, void *a0, void *a1, void *a2, void *a3, void *a4, void *a5);
extern unsigned long sys_open(char *fn, int flags);
extern unsigned long sys_read(unsigned long fd, char *buff, unsigned long size);
extern unsigned long sys_reboot();
extern unsigned long str_len(char *sz);
extern void str_print(char *str);
extern void delay(int ticks);
extern void sleep_sec(int sec);
================================================
FILE: linux_os/part2/src/init/Makefile
================================================
TARGET=init
CSOURCES = $(shell echo *.c)
OBJECTS = $(CSOURCES:.c=_c.o)
LDFLAGS = -lmy -L$(MYOS_PATH)/lib
all: $(TARGET)
$(TARGET): $(OBJECTS)
$(CC) $(LDFLAGS) $(FLAGS) -o $(TARGET) $(OBJECTS)
include ../base.mk
================================================
FILE: linux_os/part2/src/init/crt0.S
================================================
.globl _start
_start:
call main
================================================
FILE: linux_os/part2/src/init/init.c
================================================
#include <syscall.h>
#include <fcntl.h>
#include <mylib.h>
int main() {
char *msg = "MyOS 0.0.0.1 Initializing...\n";
sleep_sec(1);
str_print(msg);
sleep_sec(1);
char buff[255];
char *filename = "/src/init.c";
str_print("Opening file: ");
str_print(filename);
str_print("\n");
unsigned long fd = sys_open(filename, O_RDONLY);
sys_read(fd, buff, sizeof(buff));
str_print(buff);
for (int t=0; t<3; t++) {
//event loop, for now just tick...
sleep_sec(1);
str_print("TICK!\n");
}
sys_reboot();
return 0;
}
================================================
FILE: linux_os/part2/src/mylib/Makefile
================================================
LDFLAGS = -shared
TARGET = libmy.so
CSOURCES = $(shell echo *.c)
SSOURCES = $(shell echo *.S)
OBJECTS = $(CSOURCES:.c=_c.o)
OBJECTS += $(SSOURCES:.S=_s.o)
BINDIR = $(PREFIX)/lib
all: $(TARGET)
$(TARGET): $(OBJECTS)
ld $(FLAGS) $(LDFLAGS) -o $(TARGET) $(OBJECTS)
include ../base.mk
================================================
FILE: linux_os/part2/src/mylib/start.S
================================================
.globl _syscall
_syscall:
movq %rdi, %rax
movq %rsi, %rdi
movq %rdx, %rsi
movq %rcx, %rdx
movq %r8, %r10
movq %r9, %r8
movq 8(%rsp), %r9
syscall
ret
================================================
FILE: linux_os/part2/src/mylib/sys.c
================================================
#include <syscall.h>
#include <mylib.h>
#include <time.h>
unsigned long sys_open(char *fn, int flags) {
return _syscall(SYS_open, fn, (void *)(long)flags, 0, 0, 0, 0);
}
unsigned long sys_read(unsigned long fd, char *buff, unsigned long size) {
return _syscall(SYS_read, (void *)fd, buff, (void *)size, 0, 0, 0);
}
unsigned long sys_reboot() {
return _syscall(SYS_reboot, (void *)0xfee1dead, (void *)672274793, (void*)0x1234567, 0, 0, 0);
}
unsigned long sys_nanosleep(struct timespec *req, struct timespec *rem) {
return _syscall(SYS_nanosleep, req, rem, 0, 0, 0, 0);
}
void sleep_sec(int sec) {
struct timespec tm;
tm.tv_nsec = 0;
tm.tv_sec = sec;
sys_nanosleep(&tm, NULL);
}
================================================
FILE: linux_os/part2/src/mylib/util.c
================================================
#include <mylib.h>
#include <syscall.h>
unsigned long str_len(char *sz) {
int count = 0;
while(*sz++) {
count++;
}
return count;
}
void delay(int ticks) {
for (int i=0; i<ticks; i++) {
//nothing...
}
}
void str_print(char *str) {
_syscall(SYS_write, (void *)1 /*stdout*/, str, (void *)str_len(str), 0, 0, 0);
}
================================================
FILE: linux_os/part3/src/base.mk
================================================
SHELL ?= /bin/sh
CC ?= gcc
FLAGS ?= -nostdlib -I../include
MYOS_PATH ?= /mnt/myos
DESTDIR ?= /mnt/myos
PREFIX ?= $(DESTDIR)
BINDIR ?= $(PREFIX)/sbin
OBJECTS += ../crt0_s.o
%_c.o: %.c
$(CC) $(FLAGS) -c $< -o $@
%_s.o: %.S
$(CC) $(FLAGS) -c $< -o $@
install:
cp $(TARGET) $(BINDIR)/
clean:
rm *.o $(TARGET)
================================================
FILE: linux_os/part3/src/include/mylib.h
================================================
#pragma once
#include <time.h>
extern unsigned long _syscall(int num, void *a0, void *a1, void *a2, void *a3, void *a4, void *a5);
extern unsigned long sys_open(char *fn, int flags);
extern unsigned long sys_read(unsigned long fd, char *buff, unsigned long size);
extern unsigned long sys_reboot();
unsigned long sys_nanosleep(struct timespec *req, struct timespec *rem);
extern unsigned long str_len(char *sz);
extern void str_print(char *str);
extern void delay(int ticks);
extern void sleep_sec(int sec);
extern int str_eq(char *a, char *b);
extern unsigned long sys_write(unsigned long fd, char *buf, unsigned long len);
extern long sys_fork();
extern long sys_execve(char *filename, char **argv, char **envp);
extern int execute_process(char *filename);
================================================
FILE: linux_os/part3/src/init/Makefile
================================================
TARGET=init
CSOURCES = $(shell echo *.c)
OBJECTS = $(CSOURCES:.c=_c.o)
LDFLAGS = -lmy -L$(MYOS_PATH)/lib
all: $(TARGET)
$(TARGET): $(OBJECTS)
$(CC) $(LDFLAGS) $(FLAGS) -o $(TARGET) $(OBJECTS)
include ../base.mk
================================================
FILE: linux_os/part3/src/init/crt0.S
================================================
.globl _start
_start:
call main
================================================
FILE: linux_os/part3/src/init/init.c
================================================
#include <syscall.h>
#include <fcntl.h>
#include <mylib.h>
int main() {
char *msg = "MyOS 0.0.0.2 Initializing...\n";
sleep_sec(1);
str_print(msg);
sleep_sec(1);
execute_process("/bin/lash");
while(1) {
//event loop, for now just tick...
sleep_sec(1);
}
return 0;
}
================================================
FILE: linux_os/part3/src/lash/Makefile
================================================
TARGET=lash
CSOURCES = $(shell echo *.c)
OBJECTS = $(CSOURCES:.c=_c.o)
LDFLAGS = -lmy -L$(MYOS_PATH)/lib
BINDIR = $(PREFIX)/bin
all: $(TARGET)
$(TARGET): $(OBJECTS)
$(CC) $(LDFLAGS) $(FLAGS) -o $(TARGET) $(OBJECTS)
include ../base.mk
================================================
FILE: linux_os/part3/src/lash/lash.c
================================================
#include <mylib.h>
#include <fcntl.h>
unsigned long console_fd = 0;
void console_open() {
console_fd = sys_open("/dev/console", O_RDWR | O_NDELAY);
}
char console_read() {
char c = 0;
while(!sys_read(console_fd, &c, 1)) {
struct timespec ts;
ts.tv_sec = 0;
ts.tv_nsec = 10000;
sys_nanosleep(&ts, NULL);
}
return c;
}
void console_write(char c) {
sys_write(console_fd, &c, 1);
}
int read_line(char *buff, int max) {
int i=0;
for (; i<max; i++) {
char c = console_read();
if (c == 0) {
i--;
continue;
}
console_write(c);
buff[i] = c;
if (c == '\b') {
i--;
buff[i] = 0;
}
if (c == '\n') {
buff[i] = 0;
return i;
}
}
return i;
}
int main() {
str_print("\033[H\033[J");
str_print("LASH v0.0.0.1\n");
str_print(" :> ");
console_open();
while(1) {
char buff[1024];
read_line(buff, sizeof(buff));
str_print("INPUT: ");
str_print(buff);
str_print("\n");
if (str_eq(buff, "reboot")) {
str_print("\n\n*** SYSTEM REBOOTING ***\n");
sys_reboot();
}
str_print(" :> ");
}
}
================================================
FILE: linux_os/part3/src/mylib/Makefile
================================================
LDFLAGS = -shared
TARGET = libmy.so
CSOURCES = $(shell echo *.c)
SSOURCES = $(shell echo *.S)
OBJECTS = $(CSOURCES:.c=_c.o)
OBJECTS += $(SSOURCES:.S=_s.o)
BINDIR = $(PREFIX)/lib
all: $(TARGET)
$(TARGET): $(OBJECTS)
ld $(FLAGS) $(LDFLAGS) -o $(TARGET) $(OBJECTS)
include ../base.mk
================================================
FILE: linux_os/part3/src/mylib/start.S
================================================
.globl _syscall
_syscall:
movq %rdi, %rax
movq %rsi, %rdi
movq %rdx, %rsi
movq %rcx, %rdx
movq %r8, %r10
movq %r9, %r8
movq 8(%rsp), %r9
syscall
ret
================================================
FILE: linux_os/part3/src/mylib/sys.c
================================================
#include <syscall.h>
#include <mylib.h>
unsigned long sys_open(char *fn, int flags) {
return _syscall(SYS_open, fn, (void *)(long)flags, 0, 0, 0, 0);
}
unsigned long sys_read(unsigned long fd, char *buff, unsigned long size) {
return _syscall(SYS_read, (void *)fd, buff, (void *)size, 0, 0, 0);
}
unsigned long sys_reboot() {
return _syscall(SYS_reboot, (void *)0xfee1dead, (void *)672274793, (void*)0x1234567, 0, 0, 0);
}
unsigned long sys_nanosleep(struct timespec *req, struct timespec *rem) {
return _syscall(SYS_nanosleep, req, rem, 0, 0, 0, 0);
}
void sleep_sec(int sec) {
struct timespec tm;
tm.tv_nsec = 0;
tm.tv_sec = sec;
sys_nanosleep(&tm, NULL);
}
unsigned long sys_write(unsigned long fd, char *buf, unsigned long len) {
return _syscall(SYS_write, fd, buf, len, 0, 0, 0);
}
long sys_fork() {
return _syscall(SYS_fork, 0, 0, 0, 0, 0, 0);
}
long sys_execve(char *filename, char **argv, char **envp) {
return _syscall(SYS_execve, filename, argv, envp, 0, 0, 0);
}
int execute_process(char *filename) {
long pid = sys_fork();
if (!pid) {
char *argv[2];
argv[0] = filename;
argv[1] = 0;
char *envp[1];
envp[0] = 0;
return sys_execve(filename, argv, envp);
}
}
================================================
FILE: linux_os/part3/src/mylib/util.c
================================================
#include <mylib.h>
#include <syscall.h>
unsigned long str_len(char *sz) {
int count = 0;
while(*sz++) {
count++;
}
return count;
}
void delay(int ticks) {
for (int i=0; i<ticks; i++) {
//nothing...
}
}
void str_print(char *str) {
_syscall(SYS_write, (void *)1 /*stdout*/, str, (void *)str_len(str), 0, 0, 0);
}
int str_eq(char *a, char *b) {
char ca = *a;
char cb = *b;
for (; ca != 0 && cb != 0; ca = *(++a), cb = *(++b)) {
if (ca != cb) {
return 0;
}
}
return ca == cb;
}
================================================
FILE: linux_os/part4/src/base.mk
================================================
SHELL ?= /bin/sh
CC ?= gcc
FLAGS ?= -nostdlib -I../include
MYOS_PATH ?= /mnt/myos
DESTDIR ?= /mnt/myos
PREFIX ?= $(DESTDIR)
BINDIR ?= $(PREFIX)/sbin
OBJECTS += ../crt0_s.o
%_c.o: %.c
$(CC) $(FLAGS) -c $< -o $@
%_s.o: %.S
$(CC) $(FLAGS) -c $< -o $@
install:
cp $(TARGET) $(BINDIR)/
clean:
rm *.o $(TARGET)
================================================
FILE: linux_os/part4/src/include/mylib.h
================================================
#pragma once
#include <time.h>
#include <stdbool.h>
extern unsigned long _syscall(int num, void *a0, void *a1, void *a2, void *a3, void *a4, void *a5);
extern unsigned long sys_open(char *fn, int flags);
extern unsigned long sys_read(unsigned long fd, char *buff, unsigned long size);
extern unsigned long sys_reboot();
unsigned long sys_nanosleep(struct timespec *req, struct timespec *rem);
extern unsigned long str_len(char *sz);
extern void str_print(char *str);
extern void delay(int ticks);
extern void sleep_sec(int sec);
extern int str_eq(char *a, char *b);
extern unsigned long sys_write(unsigned long fd, char *buf, unsigned long len);
extern long sys_fork();
extern long sys_execve(char *filename, char **argv, char **envp);
extern int execute_process(char *filename);
extern int str_pos(char *s, char c);
extern unsigned long hex_str_to_ulong(char *s);
extern int str_to_int(char *s);
extern void *sys_brk(void *p);
================================================
FILE: linux_os/part4/src/include/printf.h
================================================
/*
File: printf.h
Copyright (C) 2004 Kustaa Nyholm
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
See the GNU Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
This library is really just two files: 'printf.h' and 'printf.c'.
They provide a simple and small (+200 loc) printf functionality to
be used in embedded systems.
I've found them so usefull in debugging that I do not bother with a
debugger at all.
They are distributed in source form, so to use them, just compile them
into your project.
Two printf variants are provided: printf and sprintf.
The formats supported by this implementation are: 'd' 'u' 'c' 's' 'x' 'X'.
Zero padding and field width are also supported.
If the library is compiled with 'PRINTF_SUPPORT_LONG' defined then the
long specifier is also
supported. Note that this will pull in some long math routines (pun intended!)
and thus make your executable noticably longer.
The memory foot print of course depends on the target cpu, compiler and
compiler options, but a rough guestimate (based on a H8S target) is about
1.4 kB for code and some twenty 'int's and 'char's, say 60 bytes of stack space.
Not too bad. Your milage may vary. By hacking the source code you can
get rid of some hunred bytes, I'm sure, but personally I feel the balance of
functionality and flexibility versus code size is close to optimal for
many embedded systems.
To use the printf you need to supply your own character output function,
something like :
void putc ( void* p, char c)
{
while (!SERIAL_PORT_EMPTY) ;
SERIAL_PORT_TX_REGISTER = c;
}
Before you can call printf you need to initialize it to use your
character output function with something like:
init_printf(NULL,putc);
Notice the 'NULL' in 'init_printf' and the parameter 'void* p' in 'putc',
the NULL (or any pointer) you pass into the 'init_printf' will eventually be
passed to your 'putc' routine. This allows you to pass some storage space (or
anything really) to the character output function, if necessary.
This is not often needed but it was implemented like that because it made
implementing the sprintf function so neat (look at the source code).
The code is re-entrant, except for the 'init_printf' function, so it
is safe to call it from interupts too, although this may result in mixed output.
If you rely on re-entrancy, take care that your 'putc' function is re-entrant!
The printf and sprintf functions are actually macros that translate to
'tfp_printf' and 'tfp_sprintf'. This makes it possible
to use them along with 'stdio.h' printf's in a single source file.
You just need to undef the names before you include the 'stdio.h'.
Note that these are not function like macros, so if you have variables
or struct members with these names, things will explode in your face.
Without variadic macros this is the best we can do to wrap these
fucnction. If it is a problem just give up the macros and use the
functions directly or rename them.
For further details see source code.
regs Kusti, 23.10.2004
*/
#ifndef __TFP_PRINTF__
#define __TFP_PRINTF__
#include <stdarg.h>
void init_printf(void* putp,void (*putf) (void*,char));
void tfp_printf(char *fmt, ...);
void tfp_sprintf(char* s,char *fmt, ...);
void tfp_format(void* putp,void (*putf) (void*,char),char *fmt, va_list va);
#define printf tfp_printf
#define sprintf tfp_sprintf
#endif
================================================
FILE: linux_os/part4/src/init/Makefile
================================================
TARGET=init
CSOURCES = $(shell echo *.c)
OBJECTS = $(CSOURCES:.c=_c.o)
LDFLAGS = -lmy -L$(MYOS_PATH)/lib
all: $(TARGET)
$(TARGET): $(OBJECTS)
$(CC) $(LDFLAGS) $(FLAGS) -o $(TARGET) $(OBJECTS)
include ../base.mk
================================================
FILE: linux_os/part4/src/init/crt0.S
================================================
.globl _start
_start:
call main
================================================
FILE: linux_os/part4/src/init/init.c
================================================
#include <syscall.h>
#include <fcntl.h>
#include <mylib.h>
int main() {
char *msg = "MyOS 0.0.0.2 Initializing...\n";
sleep_sec(1);
str_print(msg);
sleep_sec(1);
execute_process("/bin/lash");
while(1) {
//event loop, for now just tick...
sleep_sec(1);
}
return 0;
}
================================================
FILE: linux_os/part4/src/lash/Makefile
================================================
TARGET=lash
CSOURCES = $(shell echo *.c)
OBJECTS = $(CSOURCES:.c=_c.o)
LDFLAGS = -lmy -L$(MYOS_PATH)/lib
BINDIR = $(PREFIX)/bin
all: $(TARGET)
$(TARGET): $(OBJECTS)
$(CC) $(LDFLAGS) $(FLAGS) -o $(TARGET) $(OBJECTS)
include ../base.mk
================================================
FILE: linux_os/part4/src/lash/lash.c
================================================
#include <mylib.h>
#include <fcntl.h>
#include "printf.h"
unsigned long console_fd = 0;
void console_open() {
console_fd = sys_open("/dev/console", O_RDWR | O_NDELAY);
}
char console_read() {
char c = 0;
while(!sys_read(console_fd, &c, 1)) {
struct timespec ts;
ts.tv_sec = 0;
ts.tv_nsec = 10000;
sys_nanosleep(&ts, NULL);
}
return c;
}
void console_write(char c) {
sys_write(console_fd, &c, 1);
}
int read_line(char *buff, int max) {
int i=0;
for (; i<max; i++) {
char c = console_read();
if (c == 0) {
i--;
continue;
}
console_write(c);
buff[i] = c;
if (c == '\b') {
i--;
buff[i] = 0;
}
if (c == '\n') {
buff[i] = 0;
return i;
}
}
return i;
}
unsigned long cur_brk = 0;
void process_command(char *cmd) {
int end = str_pos(cmd, ' ');
char *arg = 0;
if (end != -1) {
cmd[end] = 0;
arg = cmd + end + 1;
}
if (str_eq(cmd, "reboot")) {
str_print("\n\n*** SYSTEM REBOOTING ***\n");
sys_reboot();
}
if (str_eq(cmd, "brk")) {
int size = 0;
if (arg) {
//brk 4096
size = str_to_int(arg);
}
void *new_val = (void *)(cur_brk + size);
void *addr = sys_brk(new_val);
printf("BRK(%X) = %X\n", new_val, addr);
cur_brk = (unsigned long)sys_brk(0);
}
if (str_eq(cmd, "store")) {
//store ADDRESS VALUE
//store 1CF0000 12345
end = str_pos(arg, ' ');
arg[end] = 0;
//second arg..
char *val = arg + end + 1;
unsigned long addr = hex_str_to_ulong(arg);
int n = str_to_int(val);
printf("Storing %d at %X\n", n, addr);
int *p = (int *)addr;
*p = n;
}
if (str_eq(cmd, "fetch")) {
//fetch ADDRESS
unsigned long addr = hex_str_to_ulong(arg);
int *p = (int *)addr;
printf("Fetched %d from %X\n", *p, addr);
}
}
int main() {
str_print("\033[H\033[J");
str_print("LASH v0.0.0.2\n");
cur_brk = (unsigned long)sys_brk(0);
printf("BRK: %X\n", cur_brk);
str_print(" :> ");
console_open();
while(1) {
char buff[1024];
read_line(buff, sizeof(buff));
process_command(buff);
str_print(" :> ");
}
}
================================================
FILE: linux_os/part4/src/mylib/Makefile
================================================
LDFLAGS = -shared
TARGET = libmy.so
CSOURCES = $(shell echo *.c)
SSOURCES = $(shell echo *.S)
FLAGS = -nostdlib -I../include -fPIC
OBJECTS = $(CSOURCES:.c=_c.o)
OBJECTS += $(SSOURCES:.S=_s.o)
BINDIR = $(PREFIX)/lib
all: $(TARGET)
$(TARGET): $(OBJECTS)
ld $(FLAGS) $(LDFLAGS) -o $(TARGET) $(OBJECTS)
include ../base.mk
================================================
FILE: linux_os/part4/src/mylib/printf.c
================================================
/*
File: printf.c
Copyright (C) 2004 Kustaa Nyholm
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#include "printf.h"
#include <mylib.h>
#include <fcntl.h>
typedef void (*putcf) (void*,char);
static putcf stdout_putf = NULL;
static void* stdout_putp = NULL;
#define PRINTF_LONG_SUPPORT 1
#ifdef PRINTF_LONG_SUPPORT
static void uli2a(unsigned long int num, unsigned int base, int uc,char * bf)
{
int n=0;
unsigned int d=1;
while (num/d >= base)
d*=base;
while (d!=0) {
int dgt = num / d;
num%=d;
d/=base;
if (n || dgt>0|| d==0) {
*bf++ = dgt+(dgt<10 ? '0' : (uc ? 'A' : 'a')-10);
++n;
}
}
*bf=0;
}
static void li2a (long num, char * bf)
{
if (num<0) {
num=-num;
*bf++ = '-';
}
uli2a(num,10,0,bf);
}
#endif
static void ui2a(unsigned int num, unsigned int base, int uc,char * bf)
{
int n=0;
unsigned int d=1;
while (num/d >= base)
d*=base;
while (d!=0) {
int dgt = num / d;
num%= d;
d/=base;
if (n || dgt>0 || d==0) {
*bf++ = dgt+(dgt<10 ? '0' : (uc ? 'A' : 'a')-10);
++n;
}
}
*bf=0;
}
static void i2a (int num, char * bf)
{
if (num<0) {
num=-num;
*bf++ = '-';
}
ui2a(num,10,0,bf);
}
static int a2d(char ch)
{
if (ch>='0' && ch<='9')
return ch-'0';
else if (ch>='a' && ch<='f')
return ch-'a'+10;
else if (ch>='A' && ch<='F')
return ch-'A'+10;
else return -1;
}
static char a2i(char ch, char** src,int base,int* nump)
{
char* p= *src;
int num=0;
int digit;
while ((digit=a2d(ch))>=0) {
if (digit>base) break;
num=num*base+digit;
ch=*p++;
}
*src=p;
*nump=num;
return ch;
}
static void putchw(void* putp,putcf putf,int n, char z, char* bf)
{
char fc=z? '0' : ' ';
char ch;
char* p=bf;
while (*p++ && n > 0)
n--;
while (n-- > 0)
putf(putp,fc);
while ((ch= *bf++))
putf(putp,ch);
}
void tfp_format(void* putp,putcf putf,char *fmt, va_list va)
{
char bf[12];
char ch;
while ((ch=*(fmt++))) {
if (ch!='%')
putf(putp,ch);
else {
char lz=0;
#ifdef PRINTF_LONG_SUPPORT
char lng=0;
#endif
int w=0;
ch=*(fmt++);
if (ch=='0') {
ch=*(fmt++);
lz=1;
}
if (ch>='0' && ch<='9') {
ch=a2i(ch,&fmt,10,&w);
}
#ifdef PRINTF_LONG_SUPPORT
if (ch=='l') {
ch=*(fmt++);
lng=1;
}
#endif
switch (ch) {
case 0:
goto abort;
case 'u' : {
#ifdef PRINTF_LONG_SUPPORT
if (lng)
uli2a(va_arg(va, unsigned long int),10,0,bf);
else
#endif
ui2a(va_arg(va, unsigned int),10,0,bf);
putchw(putp,putf,w,lz,bf);
break;
}
case 'd' : {
#ifdef PRINTF_LONG_SUPPORT
if (lng)
li2a(va_arg(va, unsigned long int),bf);
else
#endif
i2a(va_arg(va, int),bf);
putchw(putp,putf,w,lz,bf);
break;
}
case 'x': case 'X' :
#ifdef PRINTF_LONG_SUPPORT
if (lng)
uli2a(va_arg(va, unsigned long int),16,(ch=='X'),bf);
else
#endif
ui2a(va_arg(va, unsigned int),16,(ch=='X'),bf);
putchw(putp,putf,w,lz,bf);
break;
case 'c' :
putf(putp,(char)(va_arg(va, int)));
break;
case 's' :
putchw(putp,putf,w,0,va_arg(va, char*));
break;
case '%' :
putf(putp,ch);
default:
break;
}
}
}
abort:;
}
void init_printf(void* putp,void (*putf) (void*,char))
{
stdout_putf=putf;
stdout_putp=putp;
}
extern unsigned long printf_fd = 0;
void putc_console(void *p, char c) {
sys_write(printf_fd, &c, 1);
}
void tfp_printf(char *fmt, ...)
{
va_list va;
va_start(va,fmt);
if (stdout_putf == NULL) {
printf_fd = sys_open("/dev/console", O_WRONLY | O_NDELAY);
stdout_putf = putc_console;
}
tfp_format(stdout_putp,stdout_putf,fmt,va);
va_end(va);
}
static void putcp(void* p,char c)
{
*(*((char**)p))++ = c;
}
void tfp_sprintf(char* s,char *fmt, ...)
{
va_list va;
va_start(va,fmt);
tfp_format(&s,putcp,fmt,va);
putcp(&s,0);
va_end(va);
}
================================================
FILE: linux_os/part4/src/mylib/start.S
================================================
.globl _syscall
_syscall:
movq %rdi, %rax
movq %rsi, %rdi
movq %rdx, %rsi
movq %rcx, %rdx
movq %r8, %r10
movq %r9, %r8
movq 8(%rsp), %r9
syscall
ret
================================================
FILE: linux_os/part4/src/mylib/sys.c
================================================
#include <syscall.h>
#include <mylib.h>
unsigned long sys_open(char *fn, int flags) {
return _syscall(SYS_open, fn, (void *)(long)flags, 0, 0, 0, 0);
}
unsigned long sys_read(unsigned long fd, char *buff, unsigned long size) {
return _syscall(SYS_read, (void *)fd, buff, (void *)size, 0, 0, 0);
}
unsigned long sys_reboot() {
return _syscall(SYS_reboot, (void *)0xfee1dead, (void *)672274793, (void*)0x1234567, 0, 0, 0);
}
unsigned long sys_nanosleep(struct timespec *req, struct timespec *rem) {
return _syscall(SYS_nanosleep, req, rem, 0, 0, 0, 0);
}
void sleep_sec(int sec) {
struct timespec tm;
tm.tv_nsec = 0;
tm.tv_sec = sec;
sys_nanosleep(&tm, NULL);
}
unsigned long sys_write(unsigned long fd, char *buf, unsigned long len) {
return _syscall(SYS_write, fd, buf, len, 0, 0, 0);
}
long sys_fork() {
return _syscall(SYS_fork, 0, 0, 0, 0, 0, 0);
}
long sys_execve(char *filename, char **argv, char **envp) {
return _syscall(SYS_execve, filename, argv, envp, 0, 0, 0);
}
int execute_process(char *filename) {
long pid = sys_fork();
if (!pid) {
char *argv[2];
argv[0] = filename;
argv[1] = 0;
char *envp[1];
envp[0] = 0;
return sys_execve(filename, argv, envp);
}
}
/*
.text .data .bss heap invalid stack
[--------|-------|-------|---------|XXXXXXXXXXXXXXXXXXXXXXXXXXXXX|-----]
^ brk (0x1FC1000)
brk(0) = 0x1FC0000
brk(0x1FC0000 + 0x1000) = 0x1FC1000
*/
void *sys_brk(void *p) {
return _syscall(SYS_brk, p, 0, 0, 0, 0, 0);
}
================================================
FILE: linux_os/part4/src/mylib/util.c
================================================
#include <mylib.h>
#include <syscall.h>
#include "printf.h"
unsigned long str_len(char *sz) {
int count = 0;
while(*sz++) {
count++;
}
return count;
}
void delay(int ticks) {
for (int i=0; i<ticks; i++) {
//nothing...
}
}
void str_print(char *str) {
_syscall(SYS_write, (void *)1 /*stdout*/, str, (void *)str_len(str), 0, 0, 0);
}
int str_eq(char *a, char *b) {
char ca = *a;
char cb = *b;
for (; ca != 0 && cb != 0; ca = *(++a), cb = *(++b)) {
if (ca != cb) {
return 0;
}
}
return ca == cb;
}
int str_pos(char *s, char c) {
for (int i=0; s[i]; i++) {
if (s[i] == c) {
return i;
}
}
return -1;
}
unsigned long hex_str_to_ulong(char *s) {
static char *hexchars = "0123456789ABCDEF";
unsigned long result = 0;
for (; *s; s++) {
result *= 0x10;
result += str_pos(hexchars, *s);
}
return result;
}
int str_to_int(char *s) {
bool neg = *s == '-';
int result = 0;
if (neg) {
s++;
}
for (; *s; s++) {
result *= 10;
result += *s - '0';
}
return neg ? -result : result;
}
================================================
FILE: linux_os/part5/src/base.mk
================================================
SHELL ?= /bin/sh
CC ?= gcc
FLAGS ?= -nostdlib -I../include
MYOS_PATH ?= /mnt/myos
DESTDIR ?= /mnt/myos
PREFIX ?= $(DESTDIR)
BINDIR ?= $(PREFIX)/sbin
OBJECTS += ../crt0_s.o
%_c.o: %.c
$(CC) $(FLAGS) -c $< -o $@
%_s.o: %.S
$(CC) $(FLAGS) -c $< -o $@
install:
cp $(TARGET) $(BINDIR)/
clean:
rm *.o $(TARGET)
================================================
FILE: linux_os/part5/src/include/mylib.h
================================================
#pragma once
#include <time.h>
#include <stdbool.h>
#include <sys/select.h>
extern unsigned long _syscall(int num, void *a0, void *a1, void *a2, void *a3, void *a4, void *a5);
extern unsigned long sys_open(char *fn, int flags);
extern unsigned long sys_read(unsigned long fd, char *buff, unsigned long size);
extern unsigned long sys_reboot();
unsigned long sys_nanosleep(struct timespec *req, struct timespec *rem);
extern unsigned long str_len(char *sz);
extern void str_print(char *str);
extern void delay(int ticks);
extern void sleep_sec(int sec);
extern int str_eq(char *a, char *b);
extern unsigned long sys_write(unsigned long fd, char *buf, unsigned long len);
extern long sys_fork();
extern long sys_execve(char *filename, char **argv, char **envp);
extern int execute_process(char *filename);
extern int str_pos(char *s, char c);
extern unsigned long hex_str_to_ulong(char *s);
extern int str_to_int(char *s);
extern void *sys_brk(void *p);
extern int sys_select(int nfds, fd_set *readfds, fd_set *writefds,
fd_set *exceptfds, struct timeval *timeout);
extern void *mem_alloc(int size);
extern void mem_set(void *p, char n, size_t size);
extern void mem_copy(void *dest, void *source, size_t size);
extern void str_copy(char *dest, char *source);
================================================
FILE: linux_os/part5/src/include/printf.h
================================================
/*
File: printf.h
Copyright (C) 2004 Kustaa Nyholm
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
See the GNU Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
This library is really just two files: 'printf.h' and 'printf.c'.
They provide a simple and small (+200 loc) printf functionality to
be used in embedded systems.
I've found them so usefull in debugging that I do not bother with a
debugger at all.
They are distributed in source form, so to use them, just compile them
into your project.
Two printf variants are provided: printf and sprintf.
The formats supported by this implementation are: 'd' 'u' 'c' 's' 'x' 'X'.
Zero padding and field width are also supported.
If the library is compiled with 'PRINTF_SUPPORT_LONG' defined then the
long specifier is also
supported. Note that this will pull in some long math routines (pun intended!)
and thus make your executable noticably longer.
The memory foot print of course depends on the target cpu, compiler and
compiler options, but a rough guestimate (based on a H8S target) is about
1.4 kB for code and some twenty 'int's and 'char's, say 60 bytes of stack space.
Not too bad. Your milage may vary. By hacking the source code you can
get rid of some hunred bytes, I'm sure, but personally I feel the balance of
functionality and flexibility versus code size is close to optimal for
many embedded systems.
To use the printf you need to supply your own character output function,
something like :
void putc ( void* p, char c)
{
while (!SERIAL_PORT_EMPTY) ;
SERIAL_PORT_TX_REGISTER = c;
}
Before you can call printf you need to initialize it to use your
character output function with something like:
init_printf(NULL,putc);
Notice the 'NULL' in 'init_printf' and the parameter 'void* p' in 'putc',
the NULL (or any pointer) you pass into the 'init_printf' will eventually be
passed to your 'putc' routine. This allows you to pass some storage space (or
anything really) to the character output function, if necessary.
This is not often needed but it was implemented like that because it made
implementing the sprintf function so neat (look at the source code).
The code is re-entrant, except for the 'init_printf' function, so it
is safe to call it from interupts too, although this may result in mixed output.
If you rely on re-entrancy, take care that your 'putc' function is re-entrant!
The printf and sprintf functions are actually macros that translate to
'tfp_printf' and 'tfp_sprintf'. This makes it possible
to use them along with 'stdio.h' printf's in a single source file.
You just need to undef the names before you include the 'stdio.h'.
Note that these are not function like macros, so if you have variables
or struct members with these names, things will explode in your face.
Without variadic macros this is the best we can do to wrap these
fucnction. If it is a problem just give up the macros and use the
functions directly or rename them.
For further details see source code.
regs Kusti, 23.10.2004
*/
#ifndef __TFP_PRINTF__
#define __TFP_PRINTF__
#include <stdarg.h>
void init_printf(void* putp,void (*putf) (void*,char));
void tfp_printf(char *fmt, ...);
void tfp_sprintf(char* s,char *fmt, ...);
void tfp_format(void* putp,void (*putf) (void*,char),char *fmt, va_list va);
#define printf tfp_printf
#define sprintf tfp_sprintf
#endif
================================================
FILE: linux_os/part5/src/init/Makefile
================================================
TARGET=init
CSOURCES = $(shell echo *.c)
OBJECTS = $(CSOURCES:.c=_c.o)
LDFLAGS = -lmy -L$(MYOS_PATH)/lib
all: $(TARGET)
$(TARGET): $(OBJECTS)
$(CC) $(LDFLAGS) $(FLAGS) -o $(TARGET) $(OBJECTS)
include ../base.mk
================================================
FILE: linux_os/part5/src/init/crt0.S
================================================
.globl _start
_start:
call main
================================================
FILE: linux_os/part5/src/init/init.c
================================================
#include <syscall.h>
#include <fcntl.h>
#include <mylib.h>
int main() {
char *msg = "MyOS 0.0.0.2 Initializing...\n";
sleep_sec(1);
str_print(msg);
sleep_sec(1);
execute_process("/bin/lash");
while(1) {
//event loop, for now just tick...
sleep_sec(1);
}
return 0;
}
================================================
FILE: linux_os/part5/src/lash/Makefile
================================================
TARGET=lash
CSOURCES = $(shell echo *.c)
OBJECTS = $(CSOURCES:.c=_c.o)
LDFLAGS = -lmy -L$(MYOS_PATH)/lib
BINDIR = $(PREFIX)/bin
all: $(TARGET)
$(TARGET): $(OBJECTS)
$(CC) $(LDFLAGS) $(FLAGS) -o $(TARGET) $(OBJECTS)
include ../base.mk
================================================
FILE: linux_os/part5/src/lash/lash.c
================================================
#include <mylib.h>
#include <fcntl.h>
#include "printf.h"
#include <linux/input-event-codes.h>
unsigned long console_fd = 0;
struct event_file {
struct event_file *next;
int fd;
char name[64];
};
struct input_event {
struct timeval time;
unsigned short type;
unsigned short code;
unsigned int value;
};
struct mouse_pos_info {
int x;
int y;
int max_x;
int max_y;
};
struct mouse_pos_info mouse_pos;
struct event_file *event_list_head;
void load_event_devices() {
printf("Loading Input Devices...\n");
event_list_head = NULL;
mouse_pos.x = 0;
mouse_pos.y = 0;
mouse_pos.max_x = 1024;
mouse_pos.max_y = 768;
for (int i=0; i<10; i++) {
char name[64];
sprintf(name, "/dev/input/event%d", i);
int fd = sys_open(name, O_RDONLY);
if (fd < 0) {
//not found
break;
}
struct event_file *e = mem_alloc(sizeof(struct event_file));
str_copy(e->name, name);
e->fd = fd;
e->next = event_list_head;
event_list_head = e;
}
}
bool handle_event(struct event_file *e, struct input_event *event) {
if (event->type == EV_REL) {
//mouse relative event.
if (event->code == REL_X) {
//mouse X event
int new_x = mouse_pos.x + event->value;
if (new_x >= 0 && new_x <= mouse_pos.max_x) {
mouse_pos.x = new_x;
}
}
if (event->code == REL_Y) {
//mouse y event
int new_y = mouse_pos.y + event->value;
if (new_y >= 0 && new_y <= mouse_pos.max_y) {
mouse_pos.y = new_y;
}
}
printf("\rMOUSE_POS: %d - %d ", mouse_pos.x, mouse_pos.y);
}
if (event->type == EV_KEY) {
printf("KEY_INPUT: %s - %d - %d - %d\n", e->name, event->code, event->type, event->value);
if (event->code == KEY_END) {
printf("Exiting.\n");
return true;
}
}
return false;
}
void handle_events() {
printf("Listening for events...\n");
while(true) {
fd_set fds;
FD_ZERO(&fds);
struct event_file *e = event_list_head;
while(e) {
FD_SET(e->fd, &fds);
e = e->next;
}
int ret = sys_select(event_list_head->fd + 1, &fds, NULL, NULL, NULL);
if (ret < 0) {
printf("SELECT FAILED!\n");
return;
}
e = event_list_head;
while(e) {
if (FD_ISSET(e->fd, &fds)) {
char buffer[1024];
int r = sys_read(e->fd, buffer, sizeof(buffer));
int pos = 0;
while(pos < r) {
struct input_event *event = (struct input_event *)(buffer + pos);
pos += sizeof(struct input_event);
if (handle_event(e, event)) {
return;
}
}
}
e = e->next;
}
}
}
void console_open() {
console_fd = sys_open("/dev/console", O_RDWR | O_NDELAY);
}
char console_read() {
char c = 0;
while(!sys_read(console_fd, &c, 1)) {
struct timespec ts;
ts.tv_sec = 0;
ts.tv_nsec = 10000;
sys_nanosleep(&ts, NULL);
}
return c;
}
void console_write(char c) {
sys_write(console_fd, &c, 1);
}
int read_line(char *buff, int max) {
int i=0;
for (; i<max; i++) {
char c = console_read();
if (c == 0) {
i--;
continue;
}
console_write(c);
buff[i] = c;
if (c == '\b') {
i--;
buff[i] = 0;
}
if (c == '\n') {
buff[i] = 0;
return i;
}
}
return i;
}
unsigned long cur_brk = 0;
void process_command(char *cmd) {
int end = str_pos(cmd, ' ');
char *arg = 0;
if (end != -1) {
cmd[end] = 0;
arg = cmd + end + 1;
}
if (str_eq(cmd, "reboot")) {
str_print("\n\n*** SYSTEM REBOOTING ***\n");
sys_reboot();
}
if (str_eq(cmd, "brk")) {
int size = 0;
if (arg) {
//brk 4096
size = str_to_int(arg);
}
void *new_val = (void *)(cur_brk + size);
void *addr = sys_brk(new_val);
printf("BRK(%X) = %X\n", new_val, addr);
cur_brk = (unsigned long)sys_brk(0);
}
if (str_eq(cmd, "store")) {
//store ADDRESS VALUE
//store 1CF0000 12345
end = str_pos(arg, ' ');
arg[end] = 0;
//second arg..
char *val = arg + end + 1;
unsigned long addr = hex_str_to_ulong(arg);
int n = str_to_int(val);
printf("Storing %d at %X\n", n, addr);
int *p = (int *)addr;
*p = n;
}
if (str_eq(cmd, "fetch")) {
//fetch ADDRESS
unsigned long addr = hex_str_to_ulong(arg);
int *p = (int *)addr;
printf("Fetched %d from %X\n", *p, addr);
}
if (str_eq(cmd, "events")) {
handle_events();
}
}
int main() {
str_print("\033[H\033[J");
str_print("LASH v0.0.0.3\n");
cur_brk = (unsigned long)sys_brk(0);
printf("BRK: %X\n", cur_brk);
console_open();
load_event_devices();
str_print(" :> ");
while(1) {
char buff[1024];
read_line(buff, sizeof(buff));
process_command(buff);
str_print(" :> ");
}
}
================================================
FILE: linux_os/part5/src/mylib/Makefile
================================================
LDFLAGS = -shared
TARGET = libmy.so
CSOURCES = $(shell echo *.c)
SSOURCES = $(shell echo *.S)
FLAGS = -nostdlib -I../include -fPIC
OBJECTS = $(CSOURCES:.c=_c.o)
OBJECTS += $(SSOURCES:.S=_s.o)
BINDIR = $(PREFIX)/lib
all: $(TARGET)
$(TARGET): $(OBJECTS)
ld $(FLAGS) $(LDFLAGS) -o $(TARGET) $(OBJECTS)
include ../base.mk
================================================
FILE: linux_os/part5/src/mylib/printf.c
================================================
/*
File: printf.c
Copyright (C) 2004 Kustaa Nyholm
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#include "printf.h"
#include <mylib.h>
#include <fcntl.h>
typedef void (*putcf) (void*,char);
static putcf stdout_putf = NULL;
static void* stdout_putp = NULL;
#define PRINTF_LONG_SUPPORT 1
#ifdef PRINTF_LONG_SUPPORT
static void uli2a(unsigned long int num, unsigned int base, int uc,char * bf)
{
int n=0;
unsigned int d=1;
while (num/d >= base)
d*=base;
while (d!=0) {
int dgt = num / d;
num%=d;
d/=base;
if (n || dgt>0|| d==0) {
*bf++ = dgt+(dgt<10 ? '0' : (uc ? 'A' : 'a')-10);
++n;
}
}
*bf=0;
}
static void li2a (long num, char * bf)
{
if (num<0) {
num=-num;
*bf++ = '-';
}
uli2a(num,10,0,bf);
}
#endif
static void ui2a(unsigned int num, unsigned int base, int uc,char * bf)
{
int n=0;
unsigned int d=1;
while (num/d >= base)
d*=base;
while (d!=0) {
int dgt = num / d;
num%= d;
d/=base;
if (n || dgt>0 || d==0) {
*bf++ = dgt+(dgt<10 ? '0' : (uc ? 'A' : 'a')-10);
++n;
}
}
*bf=0;
}
static void i2a (int num, char * bf)
{
if (num<0) {
num=-num;
*bf++ = '-';
}
ui2a(num,10,0,bf);
}
static int a2d(char ch)
{
if (ch>='0' && ch<='9')
return ch-'0';
else if (ch>='a' && ch<='f')
return ch-'a'+10;
else if (ch>='A' && ch<='F')
return ch-'A'+10;
else return -1;
}
static char a2i(char ch, char** src,int base,int* nump)
{
char* p= *src;
int num=0;
int digit;
while ((digit=a2d(ch))>=0) {
if (digit>base) break;
num=num*base+digit;
ch=*p++;
}
*src=p;
*nump=num;
return ch;
}
static void putchw(void* putp,putcf putf,int n, char z, char* bf)
{
char fc=z? '0' : ' ';
char ch;
char* p=bf;
while (*p++ && n > 0)
n--;
while (n-- > 0)
putf(putp,fc);
while ((ch= *bf++))
putf(putp,ch);
}
void tfp_format(void* putp,putcf putf,char *fmt, va_list va)
{
char bf[12];
char ch;
while ((ch=*(fmt++))) {
if (ch!='%')
putf(putp,ch);
else {
char lz=0;
#ifdef PRINTF_LONG_SUPPORT
char lng=0;
#endif
int w=0;
ch=*(fmt++);
if (ch=='0') {
ch=*(fmt++);
lz=1;
}
if (ch>='0' && ch<='9') {
ch=a2i(ch,&fmt,10,&w);
}
#ifdef PRINTF_LONG_SUPPORT
if (ch=='l') {
ch=*(fmt++);
lng=1;
}
#endif
switch (ch) {
case 0:
goto abort;
case 'u' : {
#ifdef PRINTF_LONG_SUPPORT
if (lng)
uli2a(va_arg(va, unsigned long int),10,0,bf);
else
#endif
ui2a(va_arg(va, unsigned int),10,0,bf);
putchw(putp,putf,w,lz,bf);
break;
}
case 'd' : {
#ifdef PRINTF_LONG_SUPPORT
if (lng)
li2a(va_arg(va, unsigned long int),bf);
else
#endif
i2a(va_arg(va, int),bf);
putchw(putp,putf,w,lz,bf);
break;
}
case 'x': case 'X' :
#ifdef PRINTF_LONG_SUPPORT
if (lng)
uli2a(va_arg(va, unsigned long int),16,(ch=='X'),bf);
else
#endif
ui2a(va_arg(va, unsigned int),16,(ch=='X'),bf);
putchw(putp,putf,w,lz,bf);
break;
case 'c' :
putf(putp,(char)(va_arg(va, int)));
break;
case 's' :
putchw(putp,putf,w,0,va_arg(va, char*));
break;
case '%' :
putf(putp,ch);
default:
break;
}
}
}
abort:;
}
void init_printf(void* putp,void (*putf) (void*,char))
{
stdout_putf=putf;
stdout_putp=putp;
}
extern unsigned long printf_fd = 0;
void putc_console(void *p, char c) {
sys_write(printf_fd, &c, 1);
}
void tfp_printf(char *fmt, ...)
{
va_list va;
va_start(va,fmt);
if (stdout_putf == NULL) {
printf_fd = sys_open("/dev/console", O_WRONLY | O_NDELAY);
stdout_putf = putc_console;
}
tfp_format(stdout_putp,stdout_putf,fmt,va);
va_end(va);
}
static void putcp(void* p,char c)
{
*(*((char**)p))++ = c;
}
void tfp_sprintf(char* s,char *fmt, ...)
{
va_list va;
va_start(va,fmt);
tfp_format(&s,putcp,fmt,va);
putcp(&s,0);
va_end(va);
}
================================================
FILE: linux_os/part5/src/mylib/start.S
================================================
.globl _syscall
_syscall:
movq %rdi, %rax
movq %rsi, %rdi
movq %rdx, %rsi
movq %rcx, %rdx
movq %r8, %r10
movq %r9, %r8
movq 8(%rsp), %r9
syscall
ret
================================================
FILE: linux_os/part5/src/mylib/sys.c
================================================
#include <syscall.h>
#include <mylib.h>
unsigned long sys_open(char *fn, int flags) {
return _syscall(SYS_open, fn, (void *)(long)flags, 0, 0, 0, 0);
}
unsigned long sys_read(unsigned long fd, char *buff, unsigned long size) {
return _syscall(SYS_read, (void *)fd, buff, (void *)size, 0, 0, 0);
}
unsigned long sys_reboot() {
return _syscall(SYS_reboot, (void *)0xfee1dead, (void *)672274793, (void*)0x1234567, 0, 0, 0);
}
unsigned long sys_nanosleep(struct timespec *req, struct timespec *rem) {
return _syscall(SYS_nanosleep, req, rem, 0, 0, 0, 0);
}
void sleep_sec(int sec) {
struct timespec tm;
tm.tv_nsec = 0;
tm.tv_sec = sec;
sys_nanosleep(&tm, NULL);
}
unsigned long sys_write(unsigned long fd, char *buf, unsigned long len) {
return _syscall(SYS_write, fd, buf, len, 0, 0, 0);
}
long sys_fork() {
return _syscall(SYS_fork, 0, 0, 0, 0, 0, 0);
}
long sys_execve(char *filename, char **argv, char **envp) {
return _syscall(SYS_execve, filename, argv, envp, 0, 0, 0);
}
int execute_process(char *filename) {
long pid = sys_fork();
if (!pid) {
char *argv[2];
argv[0] = filename;
argv[1] = 0;
char *envp[1];
envp[0] = 0;
return sys_execve(filename, argv, envp);
}
}
/*
.text .data .bss heap invalid stack
[--------|-------|-------|---------|XXXXXXXXXXXXXXXXXXXXXXXXXXXXX|-----]
^ brk (0x1FC1000)
brk(0) = 0x1FC0000
brk(0x1FC0000 + 0x1000) = 0x1FC1000
*/
void *sys_brk(void *p) {
return _syscall(SYS_brk, p, 0, 0, 0, 0, 0);
}
int sys_select(int nfds, fd_set *readfds, fd_set *writefds,
fd_set *exceptfds, struct timeval *timeout) {
return _syscall(SYS_select, nfds, readfds, writefds, exceptfds, timeout, 0);
}
================================================
FILE: linux_os/part5/src/mylib/util.c
================================================
#include <mylib.h>
#include <syscall.h>
#include "printf.h"
unsigned long str_len(char *sz) {
int count = 0;
while(*sz++) {
count++;
}
return count;
}
void delay(int ticks) {
for (int i=0; i<ticks; i++) {
//nothing...
}
}
void str_print(char *str) {
_syscall(SYS_write, (void *)1 /*stdout*/, str, (void *)str_len(str), 0, 0, 0);
}
int str_eq(char *a, char *b) {
char ca = *a;
char cb = *b;
for (; ca != 0 && cb != 0; ca = *(++a), cb = *(++b)) {
if (ca != cb) {
return 0;
}
}
return ca == cb;
}
int str_pos(char *s, char c) {
for (int i=0; s[i]; i++) {
if (s[i] == c) {
return i;
}
}
return -1;
}
unsigned long hex_str_to_ulong(char *s) {
static char *hexchars = "0123456789ABCDEF";
unsigned long result = 0;
for (; *s; s++) {
result *= 0x10;
result += str_pos(hexchars, *s);
}
return result;
}
int str_to_int(char *s) {
bool neg = *s == '-';
int result = 0;
if (neg) {
s++;
}
for (; *s; s++) {
result *= 10;
result += *s - '0';
}
return neg ? -result : result;
}
void *mem_alloc(int size) {
unsigned long cur_brk = (unsigned long)sys_brk(0);
int num_pages = size / 4096;
size = (num_pages + 1) * 4096;
sys_brk((void *)(cur_brk + size));
return cur_brk;
}
void mem_set(void *p, char n, size_t size) {
char *b = (char *)p;
for (int i=0; i<size; i++) {
*b++ = n;
}
}
void mem_copy(void *dest, void *source, size_t size) {
char *d = (char *)dest;
char *s = (char *)source;
for (int i=0; i<size; i++) {
d[i] = s[i];
}
}
void str_copy(char *dest, char *source) {
mem_copy(dest, source, str_len(source) + 1);
}
================================================
FILE: linux_os/part6/src/base.mk
================================================
SHELL ?= /bin/sh
CC ?= gcc
FLAGS ?= -nostdlib -I../include
MYOS_PATH ?= /mnt/myos
DESTDIR ?= /mnt/myos
PREFIX ?= $(DESTDIR)
BINDIR ?= $(PREFIX)/sbin
OBJECTS += ../crt0_s.o
%_c.o: %.c
$(CC) $(FLAGS) -c $< -o $@
%_s.o: %.S
$(CC) $(FLAGS) -c $< -o $@
install:
cp $(TARGET) $(BINDIR)/
clean:
rm *.o $(TARGET)
================================================
FILE: linux_os/part6/src/include/mylib.h
================================================
#pragma once
#include <time.h>
#include <stdbool.h>
#include <stdint.h>
#include <sys/select.h>
#include <sys/mman.h>
extern unsigned long _syscall(int num, void *a0, void *a1, void *a2, void *a3, void *a4, void *a5);
extern unsigned long sys_open(char *fn, int flags);
extern unsigned long sys_read(unsigned long fd, char *buff, unsigned long size);
extern unsigned long sys_reboot();
unsigned long sys_nanosleep(struct timespec *req, struct timespec *rem);
extern unsigned long str_len(char *sz);
extern void str_print(char *str);
extern void delay(int ticks);
extern void sleep_sec(int sec);
extern int str_eq(char *a, char *b);
extern unsigned long sys_write(unsigned long fd, char *buf, unsigned long len);
extern long sys_fork();
extern long sys_execve(char *filename, char **argv, char **envp);
extern int execute_process(char *filename);
extern int str_pos(char *s, char c);
extern unsigned long hex_str_to_ulong(char *s);
extern int str_to_int(char *s);
extern void *sys_brk(void *p);
extern int sys_select(int nfds, fd_set *readfds, fd_set *writefds,
fd_set *exceptfds, struct timeval *timeout);
extern void *mem_alloc(int size);
extern void mem_set(void *p, char n, size_t size);
extern void mem_copy(void *dest, void *source, size_t size);
extern void str_copy(char *dest, char *source);
extern void *sys_mmap(void *addr, size_t length, int prot, int flags, int fd, off_t offset);
extern int sys_munmap(void *addr, size_t length);
extern void *malloc(size_t size);
extern void free(void *addr);
================================================
FILE: linux_os/part6/src/include/printf.h
================================================
/*
File: printf.h
Copyright (C) 2004 Kustaa Nyholm
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
See the GNU Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
This library is really just two files: 'printf.h' and 'printf.c'.
They provide a simple and small (+200 loc) printf functionality to
be used in embedded systems.
I've found them so usefull in debugging that I do not bother with a
debugger at all.
They are distributed in source form, so to use them, just compile them
into your project.
Two printf variants are provided: printf and sprintf.
The formats supported by this implementation are: 'd' 'u' 'c' 's' 'x' 'X'.
Zero padding and field width are also supported.
If the library is compiled with 'PRINTF_SUPPORT_LONG' defined then the
long specifier is also
supported. Note that this will pull in some long math routines (pun intended!)
and thus make your executable noticably longer.
The memory foot print of course depends on the target cpu, compiler and
compiler options, but a rough guestimate (based on a H8S target) is about
1.4 kB for code and some twenty 'int's and 'char's, say 60 bytes of stack space.
Not too bad. Your milage may vary. By hacking the source code you can
get rid of some hunred bytes, I'm sure, but personally I feel the balance of
functionality and flexibility versus code size is close to optimal for
many embedded systems.
To use the printf you need to supply your own character output function,
something like :
void putc ( void* p, char c)
{
while (!SERIAL_PORT_EMPTY) ;
SERIAL_PORT_TX_REGISTER = c;
}
Before you can call printf you need to initialize it to use your
character output function with something like:
init_printf(NULL,putc);
Notice the 'NULL' in 'init_printf' and the parameter 'void* p' in 'putc',
the NULL (or any pointer) you pass into the 'init_printf' will eventually be
passed to your 'putc' routine. This allows you to pass some storage space (or
anything really) to the character output function, if necessary.
This is not often needed but it was implemented like that because it made
implementing the sprintf function so neat (look at the source code).
The code is re-entrant, except for the 'init_printf' function, so it
is safe to call it from interupts too, although this may result in mixed output.
If you rely on re-entrancy, take care that your 'putc' function is re-entrant!
The printf and sprintf functions are actually macros that translate to
'tfp_printf' and 'tfp_sprintf'. This makes it possible
to use them along with 'stdio.h' printf's in a single source file.
You just need to undef the names before you include the 'stdio.h'.
Note that these are not function like macros, so if you have variables
or struct members with these names, things will explode in your face.
Without variadic macros this is the best we can do to wrap these
fucnction. If it is a problem just give up the macros and use the
functions directly or rename them.
For further details see source code.
regs Kusti, 23.10.2004
*/
#ifndef __TFP_PRINTF__
#define __TFP_PRINTF__
#include <stdarg.h>
void init_printf(void* putp,void (*putf) (void*,char));
void tfp_printf(char *fmt, ...);
void tfp_sprintf(char* s,char *fmt, ...);
void tfp_format(void* putp,void (*putf) (void*,char),char *fmt, va_list va);
#define printf tfp_printf
#define sprintf tfp_sprintf
#endif
================================================
FILE: linux_os/part6/src/init/Makefile
================================================
TARGET=init
CSOURCES = $(shell echo *.c)
OBJECTS = $(CSOURCES:.c=_c.o)
LDFLAGS = -lmy -L$(MYOS_PATH)/lib
all: $(TARGET)
$(TARGET): $(OBJECTS)
$(CC) $(LDFLAGS) $(FLAGS) -o $(TARGET) $(OBJECTS)
include ../base.mk
================================================
FILE: linux_os/part6/src/init/crt0.S
================================================
.globl _start
_start:
call main
================================================
FILE: linux_os/part6/src/init/init.c
================================================
#include <syscall.h>
#include <fcntl.h>
#include <mylib.h>
int main() {
char *msg = "MyOS 0.0.0.2 Initializing...\n";
sleep_sec(1);
str_print(msg);
sleep_sec(1);
execute_process("/bin/lash");
while(1) {
//event loop, for now just tick...
sleep_sec(1);
}
return 0;
}
================================================
FILE: linux_os/part6/src/lash/Makefile
================================================
TARGET=lash
CSOURCES = $(shell echo *.c)
OBJECTS = $(CSOURCES:.c=_c.o)
LDFLAGS = -lmy -L$(MYOS_PATH)/lib
BINDIR = $(PREFIX)/bin
all: $(TARGET)
$(TARGET): $(OBJECTS)
$(CC) $(LDFLAGS) $(FLAGS) -o $(TARGET) $(OBJECTS)
include ../base.mk
================================================
FILE: linux_os/part6/src/lash/lash.c
================================================
#include <mylib.h>
#include <fcntl.h>
#include "printf.h"
#include <linux/input-event-codes.h>
unsigned long console_fd = 0;
struct event_file {
struct event_file *next;
int fd;
char name[64];
};
struct input_event {
struct timeval time;
unsigned short type;
unsigned short code;
unsigned int value;
};
struct mouse_pos_info {
int x;
int y;
int max_x;
int max_y;
};
struct mouse_pos_info mouse_pos;
struct event_file *event_list_head;
void load_event_devices() {
printf("Loading Input Devices...\n");
event_list_head = NULL;
mouse_pos.x = 0;
mouse_pos.y = 0;
mouse_pos.max_x = 1024;
mouse_pos.max_y = 768;
for (int i=0; i<10; i++) {
char name[64];
sprintf(name, "/dev/input/event%d", i);
int fd = sys_open(name, O_RDONLY);
if (fd < 0) {
//not found
break;
}
struct event_file *e = malloc(sizeof(struct event_file));
str_copy(e->name, name);
e->fd = fd;
e->next = event_list_head;
event_list_head = e;
}
}
bool handle_event(struct event_file *e, struct input_event *event) {
if (event->type == EV_REL) {
//mouse relative event.
if (event->code == REL_X) {
//mouse X event
int new_x = mouse_pos.x + event->value;
if (new_x >= 0 && new_x <= mouse_pos.max_x) {
mouse_pos.x = new_x;
}
}
if (event->code == REL_Y) {
//mouse y event
int new_y = mouse_pos.y + event->value;
if (new_y >= 0 && new_y <= mouse_pos.max_y) {
mouse_pos.y = new_y;
}
}
printf("\rMOUSE_POS: %d - %d ", mouse_pos.x, mouse_pos.y);
}
if (event->type == EV_KEY) {
printf("KEY_INPUT: %s - %d - %d - %d\n", e->name, event->code, event->type, event->value);
if (event->code == KEY_END) {
printf("Exiting.\n");
return true;
}
}
return false;
}
void handle_events() {
printf("Listening for events...\n");
while(true) {
fd_set fds;
FD_ZERO(&fds);
struct event_file *e = event_list_head;
while(e) {
FD_SET(e->fd, &fds);
e = e->next;
}
int ret = sys_select(event_list_head->fd + 1, &fds, NULL, NULL, NULL);
if (ret < 0) {
printf("SELECT FAILED!\n");
return;
}
e = event_list_head;
while(e) {
if (FD_ISSET(e->fd, &fds)) {
char buffer[1024];
int r = sys_read(e->fd, buffer, sizeof(buffer));
int pos = 0;
while(pos < r) {
struct input_event *event = (struct input_event *)(buffer + pos);
pos += sizeof(struct input_event);
if (handle_event(e, event)) {
return;
}
}
}
e = e->next;
}
}
}
void console_open() {
console_fd = sys_open("/dev/console", O_RDWR | O_NDELAY);
}
char console_read() {
char c = 0;
while(!sys_read(console_fd, &c, 1)) {
struct timespec ts;
ts.tv_sec = 0;
ts.tv_nsec = 10000;
sys_nanosleep(&ts, NULL);
}
return c;
}
void console_write(char c) {
sys_write(console_fd, &c, 1);
}
int read_line(char *buff, int max) {
int i=0;
for (; i<max; i++) {
char c = console_read();
if (c == 0) {
i--;
continue;
}
console_write(c);
buff[i] = c;
if (c == '\b') {
i--;
buff[i] = 0;
}
if (c == '\n') {
buff[i] = 0;
return i;
}
}
return i;
}
unsigned long cur_brk = 0;
void process_command(char *cmd) {
int end = str_pos(cmd, ' ');
char *arg = 0;
if (end != -1) {
cmd[end] = 0;
arg = cmd + end + 1;
}
if (str_eq(cmd, "reboot")) {
str_print("\n\n*** SYSTEM REBOOTING ***\n");
sys_reboot();
}
if (str_eq(cmd, "alloc")) {
int size = 0;
if (arg) {
//brk 4096
size = str_to_int(arg);
}
void *p = malloc(size);
printf("Returned pointer: %lX\n", p);
print_heap();
}
if (str_eq(cmd, "free")) {
//free ADDRESS
unsigned long addr = hex_str_to_ulong(arg);
free(addr);
print_heap();
}
if (str_eq(cmd, "store")) {
//store ADDRESS VALUE
//store 1CF0000 12345
end = str_pos(arg, ' ');
arg[end] = 0;
//second arg..
char *val = arg + end + 1;
unsigned long addr = hex_str_to_ulong(arg);
int n = str_to_int(val);
printf("Storing %d at %X\n", n, addr);
int *p = (int *)addr;
*p = n;
}
if (str_eq(cmd, "fetch")) {
//fetch ADDRESS
unsigned long addr = hex_str_to_ulong(arg);
int *p = (int *)addr;
printf("Fetched %d from %X\n", *p, addr);
}
if (str_eq(cmd, "events")) {
handle_events();
}
}
int main() {
str_print("\033[H\033[J");
str_print("LASH v0.0.0.3\n");
print_heap();
console_open();
load_event_devices();
print_heap();
str_print(" :> ");
while(1) {
char buff[1024];
read_line(buff, sizeof(buff));
process_command(buff);
str_print(" :> ");
}
}
================================================
FILE: linux_os/part6/src/mylib/Makefile
================================================
LDFLAGS = -shared
TARGET = libmy.so
CSOURCES = $(shell echo *.c)
SSOURCES = $(shell echo *.S)
FLAGS = -nostdlib -I../include -fPIC
OBJECTS = $(CSOURCES:.c=_c.o)
OBJECTS += $(SSOURCES:.S=_s.o)
BINDIR = $(PREFIX)/lib
all: $(TARGET)
$(TARGET): $(OBJECTS)
ld $(FLAGS) $(LDFLAGS) -o $(TARGET) $(OBJECTS)
include ../base.mk
================================================
FILE: linux_os/part6/src/mylib/mem.c
================================================
#include <mylib.h>
#include "printf.h"
#define DEBUG_MEM 1
#define FLAG_MEM_ALLOCATED 1
#define FLAG_MEM_MAPPED 2
static const int PAGE_SIZE = 4096;
static const int RESIZE_THRESHOLD = 16;
static const int MMAP_THRESHOLD = 128 * 1024;
static const int HEADER_SIZE = 4;
static const int HEADER_FULL_SIZE = HEADER_SIZE * 2;
static uint32_t HEADER_SIZE_MASK = 0xFFFFFFF8;
static uint32_t HEADER_FLAGS_MASK = 7; //0111
/*
CHUNK_HEADER {
size: 29-bits - 8 bit aligned
flags: 3-bits
}
HEAP CHUNK = {
header: 4 bytes
data: $size bytes
header: 4 bytes
}
MMAP CHUNK = {
header: 4 bytes
data: $size bytes
}
Header Flags:
Bit 0 - 0 = free, 1 = allocated
Bit 1 - 0 = heap, 1 = mmap
Bit 2 - reserved.
Heap Layout:
|-H1-SIZE-FLAGS-| < heap start, first chunk header.
|---------------|
|---------------|
|---------------|
|---------------|
|-H1-SIZE-FLAGS-| < first chunk header
|-H2-SIZE-FLAGS-| < second chunk header
|---------------|
|---------------|
|---------------|
|---------------|
|-H2-SIZE-FLAGS-| < second chunk header
|---------------| < heap end (current brk value)
*/
static uint8_t *p_heap_start = NULL;
static uint8_t *p_first_free = NULL;
static uint8_t *p_heap_end = NULL;
#define P_AS_U32(p) ((uint32_t*)p)
static inline uint32_t chunk_size(uint8_t *p) {
return *P_AS_U32(p) & HEADER_SIZE_MASK;
}
static inline bool is_chunk_alloc(uint8_t *p) {
return *P_AS_U32(p) & FLAG_MEM_ALLOCATED;
}
static inline bool is_chunk_free(uint8_t *p) {
return !is_chunk_alloc(p);
}
static inline bool is_chunk_mapped(uint8_t *p) {
return *P_AS_U32(p) & FLAG_MEM_MAPPED;
}
static inline uint8_t *next_chunk(uint8_t *p) {
return (p + chunk_size(p) + HEADER_FULL_SIZE);
}
static inline uint8_t *chunk_set_size(uint8_t *p, size_t size) {
*P_AS_U32(p) = size;
*P_AS_U32((p + size + HEADER_SIZE)) = size;
return p;
}
static inline uint8_t *chunk_set_flags(uint8_t *p, uint32_t flags) {
*P_AS_U32(p) |= flags;
*P_AS_U32((p + chunk_size(p) + HEADER_SIZE)) |= flags;
return p;
}
static inline uint8_t *chunk_unset_flags(uint8_t *p, uint32_t flags) {
*P_AS_U32(p) &= ~flags;
*P_AS_U32((p + chunk_size(p) + HEADER_SIZE)) &= ~flags;
return p;
}
static inline size_t align_8(size_t size) {
uint32_t flags = size & HEADER_FLAGS_MASK;
return flags ? size + 8 - flags : size;
}
static void init_heap() {
p_heap_start = sys_brk(NULL);
p_heap_end = p_heap_start + PAGE_SIZE;
sys_brk(p_heap_end);
//the first free entry is at the start of the heap...
p_first_free = p_heap_start;
//nothing allocated yet, so set size full...
chunk_set_size(p_first_free, PAGE_SIZE - HEADER_FULL_SIZE);
if (DEBUG_MEM) {
printf("MEM: Init Heap:\n");
printf("MEM: \tStart: %lX\n", p_heap_start);
printf("MEM: \tEnd : %lX\n", p_heap_end);
printf("MEM: \tFirst Size: %ld\n", chunk_size(p_first_free));
printf("MEM: \tHeap Size: %ld\n", p_heap_end - p_heap_start);
}
}
void print_heap() {
if (!DEBUG_MEM) {
return;
}
if (!p_heap_start) {
init_heap();
}
printf("MEM: Heap Info %lX to %lX (%ld):\n", p_heap_start, p_heap_end, p_heap_end - p_heap_start);
uint8_t *p = p_heap_start;
while(p < p_heap_end) {
printf("\tMEM: %lX Size: %d - %s\n", p, chunk_size(p), is_chunk_free(p) ? "FREE" : "ALLOC");
p = next_chunk(p);
}
}
static uint8_t *find_first_fit(size_t size) {
for (uint8_t *p = p_first_free; p < p_heap_end; p = next_chunk(p)) {
if (is_chunk_free(p) && chunk_size(p) >= size) {
return p;
}
}
return NULL; //need more memory.
}
static uint8_t *alloc_new_memory(size_t in_size) {
int num_pages = (in_size / PAGE_SIZE) + 1;
if (in_size % PAGE_SIZE < HEADER_FULL_SIZE) {
//there is enough space for buffer, but not buffer + headers.
num_pages++;
}
size_t size = num_pages * PAGE_SIZE;
char *prev_end = p_heap_end;
p_heap_end = sys_brk(p_heap_end + size);
return chunk_set_size(prev_end, size - HEADER_FULL_SIZE);
}
void *malloc(size_t in_size) {
if (!p_heap_start) {
init_heap();
}
if (in_size >= MMAP_THRESHOLD) {
//not going to use heap, actually use mmap instead...
uint8_t *p = sys_mmap(NULL, in_size + HEADER_SIZE_MASK, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);
chunk_set_size(p, in_size);
chunk_set_flags(p, FLAG_MEM_MAPPED | FLAG_MEM_ALLOCATED);
//user's pointer starts just past the header.
return p + HEADER_SIZE;
}
//not mmap, use heap instead.
//8 bit align the size...
size_t size = align_8(in_size);
uint8_t *p = find_first_fit(size);
if (p == NULL) {
p = alloc_new_memory(size);
}
size_t csize = chunk_size(p);
size_t diff = csize - size;
if (diff > RESIZE_THRESHOLD) {
size_t next_size = diff - HEADER_FULL_SIZE;
chunk_set_size(p, size);
chunk_set_size(next_chunk(p), next_size);
}
chunk_set_flags(p, FLAG_MEM_ALLOCATED);
return p + HEADER_SIZE;
}
void free(void *up) {
uint8_t *p = ((uint8_t *)up) - HEADER_SIZE;
if (is_chunk_mapped(p)) {
//it was not on the heap, unmap it.
int ret = sys_munmap(p, chunk_size(p) + HEADER_SIZE);
if (DEBUG_MEM) {
printf("MEM: free mapped, returned %d\n", ret);
}
return;
}
chunk_unset_flags(p, FLAG_MEM_ALLOCATED);
if (is_chunk_free(next_chunk(p))) {
//if next chunk is free, let's merge them.
size_t new_size = chunk_size(p) + chunk_size(next_chunk(p)) + HEADER_FULL_SIZE;
chunk_set_size(p, new_size);
}
if (next_chunk(p) >= p_heap_end) {
//we are on the last chunk on the heap, let's do some actual
//freeing of memory and move the brk back some.
p_heap_end = sys_brk(p);
}
if (p < p_first_free) {
p_first_free = p;
}
}
================================================
FILE: linux_os/part6/src/mylib/printf.c
================================================
/*
File: printf.c
Copyright (C) 2004 Kustaa Nyholm
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#include "printf.h"
#include <mylib.h>
#include <fcntl.h>
typedef void (*putcf) (void*,char);
static putcf stdout_putf = NULL;
static void* stdout_putp = NULL;
#define PRINTF_LONG_SUPPORT 1
#ifdef PRINTF_LONG_SUPPORT
static void uli2a(unsigned long int num, unsigned int base, int uc,char * bf)
{
int n=0;
unsigned long int d=1;
while (num/d >= base)
d*=base;
while (d!=0) {
int dgt = num / d;
num%=d;
d/=base;
if (n || dgt>0|| d==0) {
*bf++ = dgt+(dgt<10 ? '0' : (uc ? 'A' : 'a')-10);
++n;
}
}
*bf=0;
}
static void li2a (long num, char * bf)
{
if (num<0) {
num=-num;
*bf++ = '-';
}
uli2a(num,10,0,bf);
}
#endif
static void ui2a(unsigned int num, unsigned int base, int uc,char * bf)
{
int n=0;
unsigned int d=1;
while (num/d >= base)
d*=base;
while (d!=0) {
int dgt = num / d;
num%= d;
d/=base;
if (n || dgt>0 || d==0) {
*bf++ = dgt+(dgt<10 ? '0' : (uc ? 'A' : 'a')-10);
++n;
}
}
*bf=0;
}
static void i2a (int num, char * bf)
{
if (num<0) {
num=-num;
*bf++ = '-';
}
ui2a(num,10,0,bf);
}
static int a2d(char ch)
{
if (ch>='0' && ch<='9')
return ch-'0';
else if (ch>='a' && ch<='f')
return ch-'a'+10;
else if (ch>='A' && ch<='F')
return ch-'A'+10;
else return -1;
}
static char a2i(char ch, char** src,int base,int* nump)
{
char* p= *src;
int num=0;
int digit;
while ((digit=a2d(ch))>=0) {
if (digit>base) break;
num=num*base+digit;
ch=*p++;
}
*src=p;
*nump=num;
return ch;
}
static void putchw(void* putp,putcf putf,int n, char z, char* bf)
{
char fc=z? '0' : ' ';
char ch;
char* p=bf;
while (*p++ && n > 0)
n--;
while (n-- > 0)
putf(putp,fc);
while ((ch= *bf++))
putf(putp,ch);
}
void tfp_format(void* putp,putcf putf,char *fmt, va_list va)
{
char bf[12];
char ch;
while ((ch=*(fmt++))) {
if (ch!='%')
putf(putp,ch);
else {
char lz=0;
#ifdef PRINTF_LONG_SUPPORT
char lng=0;
#endif
int w=0;
ch=*(fmt++);
if (ch=='0') {
ch=*(fmt++);
lz=1;
}
if (ch>='0' && ch<='9') {
ch=a2i(ch,&fmt,10,&w);
}
#ifdef PRINTF_LONG_SUPPORT
if (ch=='l') {
ch=*(fmt++);
lng=1;
}
#endif
switch (ch) {
case 0:
goto abort;
case 'u' : {
#ifdef PRINTF_LONG_SUPPORT
if (lng)
uli2a(va_arg(va, unsigned long int),10,0,bf);
else
#endif
ui2a(va_arg(va, unsigned int),10,0,bf);
putchw(putp,putf,w,lz,bf);
break;
}
case 'd' : {
#ifdef PRINTF_LONG_SUPPORT
if (lng)
li2a(va_arg(va, unsigned long int),bf);
else
#endif
i2a(va_arg(va, int),bf);
putchw(putp,putf,w,lz,bf);
break;
}
case 'x': case 'X' :
#ifdef PRINTF_LONG_SUPPORT
if (lng)
uli2a(va_arg(va, unsigned long int),16,(ch=='X'),bf);
else
#endif
ui2a(va_arg(va, unsigned int),16,(ch=='X'),bf);
putchw(putp,putf,w,lz,bf);
break;
case 'c' :
putf(putp,(char)(va_arg(va, int)));
break;
case 's' :
putchw(putp,putf,w,0,va_arg(va, char*));
break;
case '%' :
putf(putp,ch);
default:
break;
}
}
}
abort:;
}
void init_printf(void* putp,void (*putf) (void*,char))
{
stdout_putf=putf;
stdout_putp=putp;
}
extern unsigned long printf_fd = 0;
void putc_console(void *p, char c) {
sys_write(printf_fd, &c, 1);
}
void tfp_printf(char *fmt, ...)
{
va_list va;
va_start(va,fmt);
if (stdout_putf == NULL) {
printf_fd = sys_open("/dev/console", O_WRONLY | O_NDELAY);
stdout_putf = putc_console;
}
tfp_format(stdout_putp,stdout_putf,fmt,va);
va_end(va);
}
static void putcp(void* p,char c)
{
*(*((char**)p))++ = c;
}
void tfp_sprintf(char* s,char *fmt, ...)
{
va_list va;
va_start(va,fmt);
tfp_format(&s,putcp,fmt,va);
putcp(&s,0);
va_end(va);
}
================================================
FILE: linux_os/part6/src/mylib/start.S
================================================
.globl _syscall
_syscall:
movq %rdi, %rax
movq %rsi, %rdi
movq %rdx, %rsi
movq %rcx, %rdx
movq %r8, %r10
movq %r9, %r8
movq 8(%rsp), %r9
syscall
ret
================================================
FILE: linux_os/part6/src/mylib/sys.c
================================================
#include <syscall.h>
#include <mylib.h>
unsigned long sys_open(char *fn, int flags) {
return _syscall(SYS_open, fn, (void *)(long)flags, 0, 0, 0, 0);
}
unsigned long sys_read(unsigned long fd, char *buff, unsigned long size) {
return _syscall(SYS_read, (void *)fd, buff, (void *)size, 0, 0, 0);
}
unsigned long sys_reboot() {
return _syscall(SYS_reboot, (void *)0xfee1dead, (void *)672274793, (void*)0x1234567, 0, 0, 0);
}
unsigned long sys_nanosleep(struct timespec *req, struct timespec *rem) {
return _syscall(SYS_nanosleep, req, rem, 0, 0, 0, 0);
}
void sleep_sec(int sec) {
struct timespec tm;
tm.tv_nsec = 0;
tm.tv_sec = sec;
sys_nanosleep(&tm, NULL);
}
unsigned long sys_write(unsigned long fd, char *buf, unsigned long len) {
return _syscall(SYS_write, fd, buf, len, 0, 0, 0);
}
long sys_fork() {
return _syscall(SYS_fork, 0, 0, 0, 0, 0, 0);
}
long sys_execve(char *filename, char **argv, char **envp) {
return _syscall(SYS_execve, filename, argv, envp, 0, 0, 0);
}
int execute_process(char *filename) {
long pid = sys_fork();
if (!pid) {
char *argv[2];
argv[0] = filename;
argv[1] = 0;
char *envp[1];
envp[0] = 0;
return sys_execve(filename, argv, envp);
}
}
/*
.text .data .bss heap invalid stack
[--------|-------|-------|---------|XXXXXXXXXXXXXXXXXXXXXXXXXXXXX|-----]
^ brk (0x1FC1000)
brk(0) = 0x1FC0000
brk(0x1FC0000 + 0x1000) = 0x1FC1000
*/
void *sys_brk(void *p) {
return _syscall(SYS_brk, p, 0, 0, 0, 0, 0);
}
int sys_select(int nfds, fd_set *readfds, fd_set *writefds,
fd_set *exceptfds, struct timeval *timeout) {
return _syscall(SYS_select, nfds, readfds, writefds, exceptfds, timeout, 0);
}
void *sys_mmap(void *addr, size_t length, int prot, int flags, int fd, off_t offset) {
return _syscall(SYS_mmap, addr, length, prot, flags, fd, offset);
}
int sys_munmap(void *addr, size_t length) {
return _syscall(SYS_munmap, addr, length, 0, 0, 0, 0);
}
================================================
FILE: linux_os/part6/src/mylib/util.c
================================================
#include <mylib.h>
#include <syscall.h>
#include "printf.h"
unsigned long str_len(char *sz) {
int count = 0;
while(*sz++) {
count++;
}
return count;
}
void delay(int ticks) {
for (int i=0; i<ticks; i++) {
//nothing...
}
}
void str_print(char *str) {
_syscall(SYS_write, (void *)1 /*stdout*/, str, (void *)str_len(str), 0, 0, 0);
}
int str_eq(char *a, char *b) {
char ca = *a;
char cb = *b;
for (; ca != 0 && cb != 0; ca = *(++a), cb = *(++b)) {
if (ca != cb) {
return 0;
}
}
return ca == cb;
}
int str_pos(char *s, char c) {
for (int i=0; s[i]; i++) {
if (s[i] == c) {
return i;
}
}
return -1;
}
unsigned long hex_str_to_ulong(char *s) {
static char *hexchars = "0123456789ABCDEF";
unsigned long result = 0;
for (; *s; s++) {
result *= 0x10;
result += str_pos(hexchars, *s);
}
return result;
}
int str_to_int(char *s) {
bool neg = *s == '-';
int result = 0;
if (neg) {
s++;
}
for (; *s; s++) {
result *= 10;
result += *s - '0';
}
return neg ? -result : result;
}
void mem_set(void *p, char n, size_t size) {
char *b = (char *)p;
for (int i=0; i<size; i++) {
*b++ = n;
}
}
void mem_copy(void *dest, void *source, size_t size) {
char *d = (char *)dest;
char *s = (char *)source;
for (int i=0; i<size; i++) {
d[i] = s[i];
}
}
void str_copy(char *dest, char *source) {
mem_copy(dest, source, str_len(source) + 1);
}
================================================
FILE: linux_os/part7/src/base.mk
================================================
SHELL ?= /bin/sh
CC ?= gcc
FLAGS ?= -nostdlib -I../include
MYOS_PATH ?= /mnt/myos
DESTDIR ?= /mnt/myos
PREFIX ?= $(DESTDIR)
BINDIR ?= $(PREFIX)/sbin
OBJECTS += ../crt0_s.o
%_c.o: %.c
$(CC) $(FLAGS) -c $< -o $@
%_s.o: %.S
$(CC) $(FLAGS) -c $< -o $@
install:
cp $(TARGET) $(BINDIR)/
clean:
rm *.o $(TARGET)
================================================
FILE: linux_os/part7/src/include/mylib.h
================================================
#pragma once
#include <sys/wait.h>
#include <time.h>
#include <stdbool.h>
#include <stdint.h>
#include <sys/select.h>
#include <sys/mman.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <unistd.h>
extern unsigned long _syscall(int num, void *a0, void *a1, void *a2, void *a3, void *a4, void *a5);
extern unsigned long sys_open(char *fn, int flags);
extern unsigned long sys_read(unsigned long fd, char *buff, unsigned long size);
extern unsigned long sys_reboot();
unsigned long sys_nanosleep(struct timespec *req, struct timespec *rem);
extern unsigned long str_len(char *sz);
extern void str_print(char *str);
extern void delay(int ticks);
extern void sleep_sec(int sec);
extern int str_eq(char *a, char *b);
extern unsigned long sys_write(unsigned long fd, char *buf, unsigned long len);
extern long sys_fork();
extern long sys_execve(char *filename, char **argv, char **envp);
extern int execute_process(char *filename);
extern int str_pos(char *s, char c);
extern unsigned long hex_str_to_ulong(char *s);
extern int str_to_int(char *s);
extern void *sys_brk(void *p);
extern int sys_select(int nfds, fd_set *readfds, fd_set *writefds,
fd_set *exceptfds, struct timeval *timeout);
extern void *mem_alloc(int size);
extern void mem_set(void *p, char n, size_t size);
extern void mem_copy(void *dest, void *source, size_t size);
extern void str_copy(char *dest, char *source);
extern void *sys_mmap(void *addr, size_t length, int prot, int flags, int fd, off_t offset);
extern int sys_munmap(void *addr, size_t length);
extern void *malloc(size_t size);
extern void free(void *addr);
extern int sys_stat(const char *pathname, struct stat *statbuf);
extern int sys_close(unsigned long fd);
================================================
FILE: linux_os/part7/src/include/printf.h
================================================
/*
File: printf.h
Copyright (C) 2004 Kustaa Nyholm
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
See the GNU Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
This library is really just two files: 'printf.h' and 'printf.c'.
They provide a simple and small (+200 loc) printf functionality to
be used in embedded systems.
I've found them so usefull in debugging that I do not bother with a
debugger at all.
They are distributed in source form, so to use them, just compile them
into your project.
Two printf variants are provided: printf and sprintf.
The formats supported by this implementation are: 'd' 'u' 'c' 's' 'x' 'X'.
Zero padding and field width are also supported.
If the library is compiled with 'PRINTF_SUPPORT_LONG' defined then the
long specifier is also
supported. Note that this will pull in some long math routines (pun intended!)
and thus make your executable noticably longer.
The memory foot print of course depends on the target cpu, compiler and
compiler options, but a rough guestimate (based on a H8S target) is about
1.4 kB for code and some twenty 'int's and 'char's, say 60 bytes of stack space.
Not too bad. Your milage may vary. By hacking the source code you can
get rid of some hunred bytes, I'm sure, but personally I feel the balance of
functionality and flexibility versus code size is close to optimal for
many embedded systems.
To use the printf you need to supply your own character output function,
something like :
void putc ( void* p, char c)
{
while (!SERIAL_PORT_EMPTY) ;
SERIAL_PORT_TX_REGISTER = c;
}
Before you can call printf you need to initialize it to use your
character output function with something like:
init_printf(NULL,putc);
Notice the 'NULL' in 'init_printf' and the parameter 'void* p' in 'putc',
the NULL (or any pointer) you pass into the 'init_printf' will eventually be
passed to your 'putc' routine. This allows you to pass some storage space (or
anything really) to the character output function, if necessary.
This is not often needed but it was implemented like that because it made
implementing the sprintf function so neat (look at the source code).
The code is re-entrant, except for the 'init_printf' function, so it
is safe to call it from interupts too, although this may result in mixed output.
If you rely on re-entrancy, take care that your 'putc' function is re-entrant!
The printf and sprintf functions are actually macros that translate to
'tfp_printf' and 'tfp_sprintf'. This makes it possible
to use them along with 'stdio.h' printf's in a single source file.
You just need to undef the names before you include the 'stdio.h'.
Note that these are not function like macros, so if you have variables
or struct members with these names, things will explode in your face.
Without variadic macros this is the best we can do to wrap these
fucnction. If it is a problem just give up the macros and use the
functions directly or rename them.
For further details see source code.
regs Kusti, 23.10.2004
*/
#ifndef __TFP_PRINTF__
#define __TFP_PRINTF__
#include <stdarg.h>
void init_printf(void* putp,void (*putf) (void*,char));
void tfp_printf(char *fmt, ...);
void tfp_sprintf(char* s,char *fmt, ...);
void tfp_format(void* putp,void (*putf) (void*,char),char *fmt, va_list va);
#define printf tfp_printf
#define sprintf tfp_sprintf
#endif
================================================
FILE: linux_os/part7/src/init/Makefile
================================================
TARGET=init
CSOURCES = $(shell echo *.c)
OBJECTS = $(CSOURCES:.c=_c.o)
LDFLAGS = -lmy -L$(MYOS_PATH)/lib
all: $(TARGET)
$(TARGET): $(OBJECTS)
$(CC) $(LDFLAGS) $(FLAGS) -o $(TARGET) $(OBJECTS)
include ../base.mk
================================================
FILE: linux_os/part7/src/init/crt0.S
================================================
.globl _start
_start: # _start is the entry point known to the linker
xor %ebp, %ebp # effectively RBP := 0, mark the end of stack frames
mov (%rsp), %edi # get argc from the stack (implicitly zero-extended to 64-bit)
lea 8(%rsp), %rsi # take the address of argv from the stack
lea 16(%rsp,%rdi,8), %rdx # take the address of envp from the stack
xor %eax, %eax # per ABI and compatibility with icc
call main # %edi, %rsi, %rdx are the three args (of which first two are C standard) to main
mov %eax, %edi # transfer the return of main to the first argument of _exit
xor %eax, %eax # per ABI and compatibility with icc
call _exit # terminate the program
================================================
FILE: linux_os/part7/src/init/init.c
================================================
#include <syscall.h>
#include <fcntl.h>
#include <mylib.h>
int main() {
char *msg = "MyOS 0.0.0.2 Initializing...\n";
sleep_sec(1);
str_print(msg);
sleep_sec(1);
execute_process("/bin/lash");
while(1) {
//event loop, for now just tick...
sleep_sec(1);
}
return 0;
}
================================================
FILE: linux_os/part7/src/lash/Makefile
================================================
TARGET=lash
CSOURCES = $(shell echo *.c)
OBJECTS = $(CSOURCES:.c=_c.o)
LDFLAGS = -lmy -L$(MYOS_PATH)/lib
BINDIR = $(PREFIX)/bin
all: $(TARGET)
$(TARGET): $(OBJECTS)
$(CC) $(LDFLAGS) $(FLAGS) -o $(TARGET) $(OBJECTS)
include ../base.mk
================================================
FILE: linux_os/part7/src/lash/lash.c
================================================
#include <mylib.h>
#include <fcntl.h>
#include "printf.h"
#include <linux/input-event-codes.h>
unsigned long console_fd = 0;
struct event_file {
struct event_file *next;
int fd;
char name[64];
};
struct input_event {
struct timeval time;
unsigned short type;
unsigned short code;
unsigned int value;
};
struct mouse_pos_info {
int x;
int y;
int max_x;
int max_y;
};
struct mouse_pos_info mouse_pos;
struct event_file *event_list_head;
void load_event_devices() {
printf("Loading Input Devices...\n");
event_list_head = NULL;
mouse_pos.x = 0;
mouse_pos.y = 0;
mouse_pos.max_x = 1024;
mouse_pos.max_y = 768;
for (int i=0; i<10; i++) {
char name[64];
sprintf(name, "/dev/input/event%d", i);
int fd = sys_open(name, O_RDONLY);
if (fd < 0) {
//not found
break;
}
struct event_file *e = malloc(sizeof(struct event_file));
str_copy(e->name, name);
e->fd = fd;
e->next = event_list_head;
event_list_head = e;
}
}
bool handle_event(struct event_file *e, struct input_event *event) {
if (event->type == EV_REL) {
//mouse relative event.
if (event->code == REL_X) {
//mouse X event
int new_x = mouse_pos.x + event->value;
if (new_x >= 0 && new_x <= mouse_pos.max_x) {
mouse_pos.x = new_x;
}
}
if (event->code == REL_Y) {
//mouse y event
int new_y = mouse_pos.y + event->value;
if (new_y >= 0 && new_y <= mouse_pos.max_y) {
mouse_pos.y = new_y;
}
}
printf("\rMOUSE_POS: %d - %d ", mouse_pos.x, mouse_pos.y);
}
if (event->type == EV_KEY) {
printf("KEY_INPUT: %s - %d - %d - %d\n", e->name, event->code, event->type, event->value);
if (event->code == KEY_END) {
printf("Exiting.\n");
return true;
}
}
return false;
}
void handle_events() {
printf("Listening for events...\n");
while(true) {
fd_set fds;
FD_ZERO(&fds);
struct event_file *e = event_list_head;
while(e) {
FD_SET(e->fd, &fds);
e = e->next;
}
int ret = sys_select(event_list_head->fd + 1, &fds, NULL, NULL, NULL);
if (ret < 0) {
printf("SELECT FAILED!\n");
return;
}
e = event_list_head;
while(e) {
if (FD_ISSET(e->fd, &fds)) {
char buffer[1024];
int r = sys_read(e->fd, buffer, sizeof(buffer));
int pos = 0;
while(pos < r) {
struct input_event *event = (struct input_event *)(buffer + pos);
pos += sizeof(struct input_event);
if (handle_event(e, event)) {
return;
}
}
}
e = e->next;
}
}
}
void console_open() {
console_fd = sys_open("/dev/console", O_RDWR | O_NDELAY);
}
char console_read() {
char c = 0;
while(!sys_read(console_fd, &c, 1)) {
struct timespec ts;
ts.tv_sec = 0;
ts.tv_nsec = 10000;
sys_nanosleep(&ts, NULL);
}
return c;
}
void console_write(char c) {
sys_write(console_fd, &c, 1);
}
int read_line(char *buff, int max) {
int i=0;
for (; i<max; i++) {
char c = console_read();
if (c == 0) {
i--;
continue;
}
console_write(c);
buff[i] = c;
if (c == '\b') {
i--;
buff[i] = 0;
}
if (c == '\n') {
buff[i] = 0;
return i;
}
}
return i;
}
char **cmd_to_args(char *cmd) {
int num_spaces = 0;
int len = str_len(cmd);
for (int i=0; i<len; i++) {
if (cmd[i] == ' ') {
cmd[i] = 0;
num_spaces++;
}
}
char **argv = malloc(sizeof(char *) * (num_spaces + 1));
int cur_item = 0;
argv[0] = cmd;
for (int i=0; i<len; i++) {
if (cmd[i] == 0) {
argv[++cur_item] = cmd + i + 1;
}
}
argv[++cur_item] = 0;
return argv;
}
bool find_command(char *fullPath) {
struct stat statbuf;
char binPath[64];
if (sys_stat(fullPath, &statbuf) == 0) {
return true;
}
sprintf(binPath, "/bin/%s", fullPath);
str_copy(fullPath, binPath);
if (sys_stat(fullPath, &statbuf) == 0) {
return true;
}
return false;
}
bool process_command(char *cmd) {
char **argv = cmd_to_args(cmd);
if (str_eq(cmd, "reboot")) {
str_print("\n\n*** SYSTEM REBOOTING ***\n");
sys_reboot();
} else if (str_eq(cmd, "alloc")) {
int size = 0;
if (argv[1]) {
//brk 4096
size = str_to_int(argv[1]);
}
void *p = malloc(size);
printf("Returned pointer: %lX\n", p);
print_heap();
} else if (str_eq(cmd, "free")) {
//free ADDRESS
unsigned long addr = hex_str_to_ulong(argv[1]);
free(addr);
print_heap();
} else if (str_eq(cmd, "store")) {
//store ADDRESS VALUE
//store 1CF0000 12345
//second arg..
char *val = argv[2];
unsigned long addr = hex_str_to_ulong(argv[1]);
int n = str_to_int(val);
printf("Storing %d at %X\n", n, addr);
int *p = (int *)addr;
*p = n;
} else if (str_eq(cmd, "fetch")) {
//fetch ADDRESS
unsigned long addr = hex_str_to_ulong(argv[1]);
int *p = (int *)addr;
printf("Fetched %d from %X\n", *p, addr);
} else if (str_eq(cmd, "events")) {
handle_events();
} else {
struct stat statbuf;
char fullPath[64];
str_copy(fullPath, cmd);
if (find_command(fullPath)) {
long pid = sys_fork();
if (pid == 0) {
char *envp[1];
envp[0] = 0;
int ret = sys_execve(fullPath, argv, envp);
printf("Ret: %d\n", ret);
free(argv);
_exit(ret);
return false;
}
}
}
free(argv);
return true;
}
int main() {
str_print("\033[H\033[J");
str_print("LASH v0.0.0.3\n");
print_heap();
console_open();
load_event_devices();
print_heap();
str_print(" :> ");
while(1) {
char buff[1024];
read_line(buff, sizeof(buff));
if (str_eq("", buff)) {
str_print(" :> ");
continue;
}
if (!process_command(buff)) {
return 0;
}
str_print(" :> ");
}
}
================================================
FILE: linux_os/part7/src/mylib/Makefile
================================================
LDFLAGS = -shared
TARGET = libmy.so
CSOURCES = $(shell echo *.c)
SSOURCES = $(shell echo *.S)
FLAGS = -nostdlib -I../include -fPIC
OBJECTS = $(CSOURCES:.c=_c.o)
OBJECTS += $(SSOURCES:.S=_s.o)
BINDIR = $(PREFIX)/lib
all: $(TARGET)
$(TARGET): $(OBJECTS)
ld $(FLAGS) $(LDFLAGS) -o $(TARGET) $(OBJECTS)
include ../base.mk
================================================
FILE: linux_os/part7/src/mylib/mem.c
================================================
#include <mylib.h>
#include "printf.h"
#define DEBUG_MEM 1
#define FLAG_MEM_ALLOCATED 1
#define FLAG_MEM_MAPPED 2
static const int PAGE_SIZE = 4096;
static const int RESIZE_THRESHOLD = 16;
static const int MMAP_THRESHOLD = 128 * 1024;
static const int HEADER_SIZE = 4;
static const int HEADER_FULL_SIZE = HEADER_SIZE * 2;
static uint32_t HEADER_SIZE_MASK = 0xFFFFFFF8;
static uint32_t HEADER_FLAGS_MASK = 7; //0111
/*
CHUNK_HEADER {
size: 29-bits - 8 bit aligned
flags: 3-bits
}
HEAP CHUNK = {
header: 4 bytes
data: $size bytes
header: 4 bytes
}
MMAP CHUNK = {
header: 4 bytes
data: $size bytes
}
Header Flags:
Bit 0 - 0 = free, 1 = allocated
Bit 1 - 0 = heap, 1 = mmap
Bit 2 - reserved.
Heap Layout:
|-H1-SIZE-FLAGS-| < heap start, first chunk header.
|---------------|
|---------------|
|---------------|
|---------------|
|-H1-SIZE-FLAGS-| < first chunk header
|-H2-SIZE-FLAGS-| < second chunk header
|---------------|
|---------------|
|---------------|
|---------------|
|-H2-SIZE-FLAGS-| < second chunk header
|---------------| < heap end (current brk value)
*/
static uint8_t *p_heap_start = NULL;
static uint8_t *p_first_free = NULL;
static uint8_t *p_heap_end = NULL;
#define P_AS_U32(p) ((uint32_t*)p)
static inline uint32_t chunk_size(uint8_t *p) {
return *P_AS_U32(p) & HEADER_SIZE_MASK;
}
static inline bool is_chunk_alloc(uint8_t *p) {
return *P_AS_U32(p) & FLAG_MEM_ALLOCATED;
}
static inline bool is_chunk_free(uint8_t *p) {
return !is_chunk_alloc(p);
}
static inline bool is_chunk_mapped(uint8_t *p) {
return *P_AS_U32(p) & FLAG_MEM_MAPPED;
}
static inline uint8_t *next_chunk(uint8_t *p) {
return (p + chunk_size(p) + HEADER_FULL_SIZE);
}
static inline uint8_t *chunk_set_size(uint8_t *p, size_t size) {
*P_AS_U32(p) = size;
*P_AS_U32((p + size + HEADER_SIZE)) = size;
return p;
}
static inline uint8_t *chunk_set_flags(uint8_t *p, uint32_t flags) {
*P_AS_U32(p) |= flags;
*P_AS_U32((p + chunk_size(p) + HEADER_SIZE)) |= flags;
return p;
}
static inline uint8_t *chunk_unset_flags(uint8_t *p, uint32_t flags) {
*P_AS_U32(p) &= ~flags;
*P_AS_U32((p + chunk_size(p) + HEADER_SIZE)) &= ~flags;
return p;
}
static inline size_t align_8(size_t size) {
uint32_t flags = size & HEADER_FLAGS_MASK;
return flags ? size + 8 - flags : size;
}
static void init_heap() {
p_heap_start = sys_brk(NULL);
p_heap_end = p_heap_start + PAGE_SIZE;
sys_brk(p_heap_end);
//the first free entry is at the start of the heap...
p_first_free = p_heap_start;
//nothing allocated yet, so set size full...
chunk_set_size(p_first_free, PAGE_SIZE - HEADER_FULL_SIZE);
if (DEBUG_MEM) {
printf("MEM: Init Heap:\n");
printf("MEM: \tStart: %lX\n", p_heap_start);
printf("MEM: \tEnd : %lX\n", p_heap_end);
printf("MEM: \tFirst Size: %ld\n", chunk_size(p_first_free));
printf("MEM: \tHeap Size: %ld\n", p_heap_end - p_heap_start);
}
}
void print_heap() {
if (!DEBUG_MEM) {
return;
}
if (!p_heap_start) {
init_heap();
}
printf("MEM: Heap Info %lX to %lX (%ld):\n", p_heap_start, p_heap_end, p_heap_end - p_heap_start);
uint8_t *p = p_heap_start;
while(p < p_heap_end) {
printf("\tMEM: %lX Size: %d - %s\n", p, chunk_size(p), is_chunk_free(p) ? "FREE" : "ALLOC");
p = next_chunk(p);
}
}
static uint8_t *find_first_fit(size_t size) {
for (uint8_t *p = p_first_free; p < p_heap_end; p = next_chunk(p)) {
if (is_chunk_free(p) && chunk_size(p) >= size) {
return p;
}
}
return NULL; //need more memory.
}
static uint8_t *alloc_new_memory(size_t in_size) {
int num_pages = (in_size / PAGE_SIZE) + 1;
if (in_size % PAGE_SIZE < HEADER_FULL_SIZE) {
//there is enough space for buffer, but not buffer + headers.
num_pages++;
}
size_t size = num_pages * PAGE_SIZE;
char *prev_end = p_heap_end;
p_heap_end = sys_brk(p_heap_end + size);
return chunk_set_size(prev_end, size - HEADER_FULL_SIZE);
}
void *malloc(size_t in_size) {
if (!p_heap_start) {
init_heap();
}
if (in_size >= MMAP_THRESHOLD) {
//not going to use heap, actually use mmap instead...
uint8_t *p = sys_mmap(NULL, in_size + HEADER_SIZE_MASK, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);
chunk_set_size(p, in_size);
chunk_set_flags(p, FLAG_MEM_MAPPED | FLAG_MEM_ALLOCATED);
//user's pointer starts just past the header.
return p + HEADER_SIZE;
}
//not mmap, use heap instead.
//8 bit align the size...
size_t size = align_8(in_size);
uint8_t *p = find_first_fit(size);
if (p == NULL) {
p = alloc_new_memory(size);
}
size_t csize = chunk_size(p);
size_t diff = csize - size;
if (diff > RESIZE_THRESHOLD) {
size_t next_size = diff - HEADER_FULL_SIZE;
chunk_set_size(p, size);
chunk_set_size(next_chunk(p), next_size);
}
chunk_set_flags(p, FLAG_MEM_ALLOCATED);
return p + HEADER_SIZE;
}
void free(void *up) {
uint8_t *p = ((uint8_t *)up) - HEADER_SIZE;
if (is_chunk_mapped(p)) {
//it was not on the heap, unmap it.
int ret = sys_munmap(p, chunk_size(p) + HEADER_SIZE);
if (DEBUG_MEM) {
printf("MEM: free mapped, returned %d\n", ret);
}
return;
}
chunk_unset_flags(p, FLAG_MEM_ALLOCATED);
if (is_chunk_free(next_chunk(p))) {
//if next chunk is free, let's merge them.
size_t new_size = chunk_size(p) + chunk_size(next_chunk(p)) + HEADER_FULL_SIZE;
chunk_set_size(p, new_size);
}
if (next_chunk(p) >= p_heap_end) {
//we are on the last chunk on the heap, let's do some actual
//freeing of memory and move the brk back some.
p_heap_end = sys_brk(p);
}
if (p < p_first_free) {
p_first_free = p;
}
}
================================================
FILE: linux_os/part7/src/mylib/printf.c
================================================
/*
File: printf.c
Copyright (C) 2004 Kustaa Nyholm
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#include "printf.h"
#include <mylib.h>
#include <fcntl.h>
typedef void (*putcf) (void*,char);
static putcf stdout_putf = NULL;
static void* stdout_putp = NULL;
#define PRINTF_LONG_SUPPORT 1
#ifdef PRINTF_LONG_SUPPORT
static void uli2a(unsigned long int num, unsigned int base, int uc,char * bf)
{
int n=0;
unsigned long int d=1;
while (num/d >= base)
d*=base;
while (d!=0) {
int dgt = num / d;
num%=d;
d/=base;
if (n || dgt>0|| d==0) {
*bf++ = dgt+(dgt<10 ? '0' : (uc ? 'A' : 'a')-10);
++n;
}
}
*bf=0;
}
static void li2a (long num, char * bf)
{
if (num<0) {
num=-num;
*bf++ = '-';
}
uli2a(num,10,0,bf);
}
#endif
static void ui2a(unsigned int num, unsigned int base, int uc,char * bf)
{
int n=0;
unsigned int d=1;
while (num/d >= base)
d*=base;
while (d!=0) {
int dgt = num / d;
num%= d;
d/=base;
if (n || dgt>0 || d==0) {
*bf++ = dgt+(dgt<10 ? '0' : (uc ? 'A' : 'a')-10);
++n;
}
}
*bf=0;
}
static void i2a (int num, char * bf)
{
if (num<0) {
num=-num;
*bf++ = '-';
}
ui2a(num,10,0,bf);
}
static int a2d(char ch)
{
if (ch>='0' && ch<='9')
return ch-'0';
else if (ch>='a' && ch<='f')
return ch-'a'+10;
else if (ch>='A' && ch<='F')
return ch-'A'+10;
else return -1;
}
static char a2i(char ch, char** src,int base,int* nump)
{
char* p= *src;
int num=0;
int digit;
while ((digit=a2d(ch))>=0) {
if (digit>base) break;
num=num*base+digit;
ch=*p++;
}
*src=p;
*nump=num;
return ch;
}
static void putchw(void* putp,putcf putf,int n, char z, char* bf)
{
char fc=z? '0' : ' ';
char ch;
char* p=bf;
while (*p++ && n > 0)
n--;
while (n-- > 0)
putf(putp,fc);
while ((ch= *bf++))
putf(putp,ch);
}
void tfp_format(void* putp,putcf putf,char *fmt, va_list va)
{
char bf[12];
char ch;
while ((ch=*(fmt++))) {
if (ch!='%')
putf(putp,ch);
else {
char lz=0;
#ifdef PRINTF_LONG_SUPPORT
char lng=0;
#endif
int w=0;
ch=*(fmt++);
if (ch=='0') {
ch=*(fmt++);
lz=1;
}
if (ch>='0' && ch<='9') {
ch=a2i(ch,&fmt,10,&w);
}
#ifdef PRINTF_LONG_SUPPORT
if (ch=='l') {
ch=*(fmt++);
lng=1;
}
#endif
switch (ch) {
case 0:
goto abort;
case 'u' : {
#ifdef PRINTF_LONG_SUPPORT
if (lng)
uli2a(va_arg(va, unsigned long int),10,0,bf);
else
#endif
ui2a(va_arg(va, unsigned int),10,0,bf);
putchw(putp,putf,w,lz,bf);
break;
}
case 'd' : {
#ifdef PRINTF_LONG_SUPPORT
if (lng)
li2a(va_arg(va, unsigned long int),bf);
else
#endif
i2a(va_arg(va, int),bf);
putchw(putp,putf,w,lz,bf);
break;
}
case 'x': case 'X' :
#ifdef PRINTF_LONG_SUPPORT
if (lng)
uli2a(va_arg(va, unsigned long int),16,(ch=='X'),bf);
else
#endif
ui2a(va_arg(va, unsigned int),16,(ch=='X'),bf);
putchw(putp,putf,w,lz,bf);
break;
case 'c' :
putf(putp,(char)(va_arg(va, int)));
break;
case 's' :
putchw(putp,putf,w,0,va_arg(va, char*));
break;
case '%' :
putf(putp,ch);
default:
break;
}
}
}
abort:;
}
void init_printf(void* putp,void (*putf) (void*,char))
{
stdout_putf=putf;
stdout_putp=putp;
}
extern unsigned long printf_fd = 0;
void putc_console(void *p, char c) {
sys_write(printf_fd, &c, 1);
}
void tfp_printf(char *fmt, ...)
{
va_list va;
va_start(va,fmt);
if (stdout_putf == NULL) {
printf_fd = sys_open("/dev/console", O_WRONLY | O_NDELAY);
stdout_putf = putc_console;
}
tfp_format(stdout_putp,stdout_putf,fmt,va);
va_end(va);
}
static void putcp(void* p,char c)
{
*(*((char**)p))++ = c;
}
void tfp_sprintf(char* s,char *fmt, ...)
{
va_list va;
va_start(va,fmt);
tfp_format(&s,putcp,fmt,va);
putcp(&s,0);
va_end(va);
}
================================================
FILE: linux_os/part7/src/mylib/start.S
================================================
.globl _syscall
_syscall:
movq %rdi, %rax
movq %rsi, %rdi
movq %rdx, %rsi
movq %rcx, %rdx
movq %r8, %r10
movq %r9, %r8
movq 8(%rsp), %r9
syscall
ret
================================================
FILE: linux_os/part7/src/mylib/sys.c
================================================
#include <syscall.h>
#include <mylib.h>
unsigned long sys_open(char *fn, int flags) {
return _syscall(SYS_open, fn, (void *)(long)flags, 0, 0, 0, 0);
}
unsigned long sys_read(unsigned long fd, char *buff, unsigned long size) {
return _syscall(SYS_read, (void *)fd, buff, (void *)size, 0, 0, 0);
}
unsigned long sys_reboot() {
return _syscall(SYS_reboot, (void *)0xfee1dead, (void *)672274793, (void*)0x1234567, 0, 0, 0);
}
unsigned long sys_nanosleep(struct timespec *req, struct timespec *rem) {
return _syscall(SYS_nanosleep, req, rem, 0, 0, 0, 0);
}
void sleep_sec(int sec) {
struct timespec tm;
tm.tv_nsec = 0;
tm.tv_sec = sec;
sys_nanosleep(&tm, NULL);
}
unsigned long sys_write(unsigned long fd, char *buf, unsigned long len) {
return _syscall(SYS_write, fd, buf, len, 0, 0, 0);
}
long sys_fork() {
return _syscall(SYS_fork, 0, 0, 0, 0, 0, 0);
}
long sys_execve(char *filename, char **argv, char **envp) {
return _syscall(SYS_execve, filename, argv, envp, 0, 0, 0);
}
int execute_process(char *filename) {
long pid = sys_fork();
if (!pid) {
char *argv[2];
argv[0] = filename;
argv[1] = 0;
char *envp[1];
envp[0] = 0;
return sys_execve(filename, argv, envp);
}
}
/*
.text .data .bss heap invalid stack
[--------|-------|-------|---------|XXXXXXXXXXXXXXXXXXXXXXXXXXXXX|-----]
^ brk (0x1FC1000)
brk(0) = 0x1FC0000
brk(0x1FC0000 + 0x1000) = 0x1FC1000
*/
void *sys_brk(void *p) {
return _syscall(SYS_brk, p, 0, 0, 0, 0, 0);
}
int sys_select(int nfds, fd_set *readfds, fd_set *writefds,
fd_set *exceptfds, struct timeval *timeout) {
return _syscall(SYS_select, nfds, readfds, writefds, exceptfds, timeout, 0);
}
void *sys_mmap(void *addr, size_t length, int prot, int flags, int fd, off_t offset) {
return _syscall(SYS_mmap, addr, length, prot, flags, fd, offset);
}
int sys_munmap(void *addr, size_t length) {
return _syscall(SYS_munmap, addr, length, 0, 0, 0, 0);
}
int sys_stat(const char *pathname, struct stat *statbuf) {
return _syscall(SYS_stat, pathname, statbuf, 0, 0, 0, 0);
}
int sys_close(unsigned long fd) {
return _syscall(SYS_close, fd, 0, 0, 0, 0, 0);
}
================================================
FILE: linux_os/part7/src/mylib/util.c
================================================
#include <mylib.h>
#include <syscall.h>
#include "printf.h"
unsigned long str_len(char *sz) {
int count = 0;
while(*sz++) {
count++;
}
return count;
}
void delay(int ticks) {
for (int i=0; i<ticks; i++) {
//nothing...
}
}
void str_print(char *str) {
_syscall(SYS_write, (void *)1 /*stdout*/, str, (void *)str_len(str), 0, 0, 0);
}
int str_eq(char *a, char *b) {
char ca = *a;
char cb = *b;
for (; ca != 0 && cb != 0; ca = *(++a), cb = *(++b)) {
if (ca != cb) {
return 0;
}
}
return ca == cb;
}
int str_pos(char *s, char c) {
for (int i=0; s[i]; i++) {
if (s[i] == c) {
return i;
}
}
return -1;
}
unsigned long hex_str_to_ulong(char *s) {
static char *hexchars = "0123456789ABCDEF";
unsigned long result = 0;
for (; *s; s++) {
result *= 0x10;
result += str_pos(hexchars, *s);
}
return result;
}
int str_to_int(char *s) {
bool neg = *s == '-';
int result = 0;
if (neg) {
s++;
}
for (; *s; s++) {
result *= 10;
result += *s - '0';
}
return neg ? -result : result;
}
void mem_set(void *p, char n, size_t size) {
char *b = (char *)p;
for (int i=0; i<size; i++) {
*b++ = n;
}
}
void mem_copy(void *dest, void *source, size_t size) {
char *d = (char *)dest;
char *s = (char *)source;
for (int i=0; i<size; i++) {
d[i] = s[i];
}
}
void str_copy(char *dest, char *source) {
mem_copy(dest, source, str_len(source) + 1);
}
void _exit(int code) {
return _syscall(SYS_exit, code, 0, 0, 0, 0, 0);
}
================================================
FILE: linux_os/part7/src/printargs/Makefile
================================================
TARGET=printargs
CSOURCES = $(shell echo *.c)
OBJECTS = $(CSOURCES:.c=_c.o)
LDFLAGS = -lmy -L$(MYOS_PATH)/lib
BINDIR = $(PREFIX)/bin
all: $(TARGET)
$(TARGET): $(OBJECTS)
$(CC) $(LDFLAGS) $(FLAGS) -o $(TARGET) $(OBJECTS)
include ../base.mk
================================================
FILE: linux_os/part7/src/printargs/printargs.c
================================================
#include <mylib.h>
#include "printf.h"
int main(int argc, char **argv) {
printf("PrintArgs: %d\n", argc);
for (int i=1; i<argc; i++) {
printf("\t%d = %s\n", i, argv[i]);
}
sleep_sec(2);
printf("done\n");
return 0;
}
================================================
FILE: linux_os/part8/myos.img
================================================
(:B(:B(:B(:B(:B(:B(:B(:B(:B(:B(:B(:B(:B(:B(:B(:B(:B(:B(:B(:B(:B(:B(:B(:B(:B(:B(:B(:B(:B(:B(:B(:B(:B(:B(:B(:B(:B(:B(:B(:B(:B(:B(:B(:B(:B(:B(:B(:B(:B(:B(:B(:B(:B(:B(:B(:B(:B(:B(:B(:B(:B(:B(:B(:B(:B(:B(:B(:B(:B(:B(:B(:B(:B(:B(:B(:B(:B(:B(:B(:B(:B(:B(:B(:B(:B(:B(:B(:B(:B(:B(:B(:B(:B(:B(:B(:B(:B(:B(:B(:B(:B(:B(:B(:B(:B(:B(:B(:B(:B(:B(:B(:B(:B(:B(:B(:B(:B(:B(:B(:B(:B(:B(:B(:B(:B(:B(:B(:B(:B(:B(:B(:B(:B(:B(:B(:B(:B(:B(:B(:B(:B(:B(:B(:B(:B(:B(:B(:B(:B(:B(:B(:B(:B(:B(:B(:B(:B(:B(:B(:B(:B(:B(:B(:B(:B(:B(:B(:B(:B(:B(:B(:B(:B(:B(:B(:B(:B(:B(:B(:B(:B(:B(:B(:B(:B(:B(:B(:B(:B(:B(:B(:B(:B(:B(:B(:B(:B(:B(:B(:B(:B(:B(:B(:B(:B(:B(:B(:B(:B(:B(:B(:B(:B(:B(:B(:B(:B(:B(:B(:B(:B(:B(:B(:B(:B(:B(:B(:B(:B(:B(:B(:B(:B(:B(:B(:B(:B(:B(:B(:B(:B(:B(:B(:B(:B(:B(:B(:B(:B(:B(:B(:B(:B(:B(:B(:B(:B(:B(:B(:B(:B(:B(:B(:B(:B(:B(:B(:B(:B(:B(:B(:B(:B(:B(:B(:B(:B(:B(:B(:B(:B(:B(:B(:B(:B(:B(:B(:B(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B(:B(:B(:B(:B(:B(:B(:B(:B(:B(:B(:B(:B(:B(:B(:B(:B(:B(:B(:B(:B(:B(:B(:B(:B(:B(:B(:B(:B(:B(:B(:B(:B(:B(:B(:B(:B(:B(:B(:B(:B(:B(:B(:B(:B(:B(:B(:B(:B(:B(:B(:B(:B(:B(:B(:B(:B(:B(:B(:B(:B(:B(:B(:B(:B(:B(:B(:B(:B(:B(:B(:B(:B(:B(:B(:B(:B(:B(:B(:B(:B(:B(:B(:B(:B(:B(:B(:B(:B(:B(:B(:B(:B(:B(:B(:B(:B(:B(:B(:B(:B(:B(:B(:B(:B(:B(:B(:B(:B(:B(:B(:B(:B(:B(:B(:B(:B(:B(:B(:B(:B(:B(:B(:B(:B(:B(:B(:B(:B(:B(:B(:B(:B(:B(:B(:B(:B(:B(:B(:B(:B(:B(:B(:B(:B(:B(:B(:B(:B(:B(:B(:B(:B(:B(:B(:B(:B(:B(:B(:B(:B(:B(:B(:B(:B(:B(:B(:B(:B(:B(:B(:B(:B(:B(:B(:B(:B(:B(:B(:B(:B(:B(:B(:B(:B(:B(:B(:B(:B(:B(:B(:B(:B(:B(:B(:B(:B(:B(:B(:B(:B(:B(:B(:B(:B(:B(:B(:B(:B(:B(:B(:B(:B(:B(:B(:B(:B(:B(:B(:B(:B(:B(:B(:B(:B(:B(:B(:B(:B(:B(:B(:B(:B(:B(:B(:B(:B(:B(:B(:B(:B(:B(:B(:B(:B(:B(:B(:B(:B(:B(:B(:B(:B(:B(:B(:B(:B(:B(:B(:B(:B(:B(:B(:B(:B(:B(:B(:B(:B(:B(:B(:B(:B(:B(:B(:B(:B(:B(:B(:B(:B(:B(:B(:B(:B(:B(:B(:B
gitextract_cwq282cg/
├── README.md
├── linux_os/
│ ├── part1/
│ │ └── src/
│ │ ├── init.c
│ │ └── start.S
│ ├── part10/
│ │ └── src/
│ │ ├── base.mk
│ │ ├── crt0_s.o
│ │ ├── drmlist/
│ │ │ ├── Makefile
│ │ │ └── drmlist.c
│ │ ├── fbset/
│ │ │ ├── Makefile
│ │ │ └── fbset.c
│ │ ├── include/
│ │ │ ├── libfb.h
│ │ │ ├── mydrm.h
│ │ │ ├── mylib.h
│ │ │ └── printf.h
│ │ ├── init/
│ │ │ ├── Makefile
│ │ │ ├── crt0.S
│ │ │ └── init.c
│ │ ├── lash/
│ │ │ ├── Makefile
│ │ │ └── lash.c
│ │ ├── libfb/
│ │ │ ├── Makefile
│ │ │ └── fb.c
│ │ ├── mydrm/
│ │ │ ├── Makefile
│ │ │ └── mydrm.c
│ │ ├── mylib/
│ │ │ ├── Makefile
│ │ │ ├── mem.c
│ │ │ ├── printf.c
│ │ │ ├── start.S
│ │ │ ├── sys.c
│ │ │ └── util.c
│ │ └── printargs/
│ │ ├── Makefile
│ │ └── printargs.c
│ ├── part2/
│ │ └── src/
│ │ ├── base.mk
│ │ ├── crt0_s.o
│ │ ├── include/
│ │ │ └── mylib.h
│ │ ├── init/
│ │ │ ├── Makefile
│ │ │ ├── crt0.S
│ │ │ └── init.c
│ │ └── mylib/
│ │ ├── Makefile
│ │ ├── start.S
│ │ ├── sys.c
│ │ └── util.c
│ ├── part3/
│ │ └── src/
│ │ ├── base.mk
│ │ ├── crt0_s.o
│ │ ├── include/
│ │ │ └── mylib.h
│ │ ├── init/
│ │ │ ├── Makefile
│ │ │ ├── crt0.S
│ │ │ └── init.c
│ │ ├── lash/
│ │ │ ├── Makefile
│ │ │ └── lash.c
│ │ └── mylib/
│ │ ├── Makefile
│ │ ├── start.S
│ │ ├── sys.c
│ │ └── util.c
│ ├── part4/
│ │ └── src/
│ │ ├── base.mk
│ │ ├── crt0_s.o
│ │ ├── include/
│ │ │ ├── mylib.h
│ │ │ └── printf.h
│ │ ├── init/
│ │ │ ├── Makefile
│ │ │ ├── crt0.S
│ │ │ └── init.c
│ │ ├── lash/
│ │ │ ├── Makefile
│ │ │ └── lash.c
│ │ └── mylib/
│ │ ├── Makefile
│ │ ├── printf.c
│ │ ├── start.S
│ │ ├── sys.c
│ │ └── util.c
│ ├── part5/
│ │ └── src/
│ │ ├── base.mk
│ │ ├── crt0_s.o
│ │ ├── include/
│ │ │ ├── mylib.h
│ │ │ └── printf.h
│ │ ├── init/
│ │ │ ├── Makefile
│ │ │ ├── crt0.S
│ │ │ └── init.c
│ │ ├── lash/
│ │ │ ├── Makefile
│ │ │ └── lash.c
│ │ └── mylib/
│ │ ├── Makefile
│ │ ├── printf.c
│ │ ├── start.S
│ │ ├── sys.c
│ │ └── util.c
│ ├── part6/
│ │ └── src/
│ │ ├── base.mk
│ │ ├── crt0_s.o
│ │ ├── include/
│ │ │ ├── mylib.h
│ │ │ └── printf.h
│ │ ├── init/
│ │ │ ├── Makefile
│ │ │ ├── crt0.S
│ │ │ └── init.c
│ │ ├── lash/
│ │ │ ├── Makefile
│ │ │ └── lash.c
│ │ └── mylib/
│ │ ├── Makefile
│ │ ├── mem.c
│ │ ├── printf.c
│ │ ├── start.S
│ │ ├── sys.c
│ │ └── util.c
│ ├── part7/
│ │ └── src/
│ │ ├── base.mk
│ │ ├── crt0_s.o
│ │ ├── include/
│ │ │ ├── mylib.h
│ │ │ └── printf.h
│ │ ├── init/
│ │ │ ├── Makefile
│ │ │ ├── crt0.S
│ │ │ └── init.c
│ │ ├── lash/
│ │ │ ├── Makefile
│ │ │ └── lash.c
│ │ ├── mylib/
│ │ │ ├── Makefile
│ │ │ ├── mem.c
│ │ │ ├── printf.c
│ │ │ ├── start.S
│ │ │ ├── sys.c
│ │ │ └── util.c
│ │ └── printargs/
│ │ ├── Makefile
│ │ └── printargs.c
│ ├── part8/
│ │ ├── myos.img
│ │ └── src/
│ │ ├── base.mk
│ │ ├── crt0_s.o
│ │ ├── fbset/
│ │ │ ├── Makefile
│ │ │ └── fbset.c
│ │ ├── include/
│ │ │ ├── libfb.h
│ │ │ ├── mylib.h
│ │ │ └── printf.h
│ │ ├── init/
│ │ │ ├── Makefile
│ │ │ ├── crt0.S
│ │ │ └── init.c
│ │ ├── lash/
│ │ │ ├── Makefile
│ │ │ └── lash.c
│ │ ├── libfb/
│ │ │ ├── Makefile
│ │ │ └── fb.c
│ │ ├── mylib/
│ │ │ ├── Makefile
│ │ │ ├── mem.c
│ │ │ ├── printf.c
│ │ │ ├── start.S
│ │ │ ├── sys.c
│ │ │ └── util.c
│ │ └── printargs/
│ │ ├── Makefile
│ │ └── printargs.c
│ ├── part9/
│ │ └── src/
│ │ ├── base.mk
│ │ ├── crt0_s.o
│ │ ├── drmlist/
│ │ │ ├── Makefile
│ │ │ └── drmlist.c
│ │ ├── fbset/
│ │ │ ├── Makefile
│ │ │ └── fbset.c
│ │ ├── include/
│ │ │ ├── libfb.h
│ │ │ ├── mydrm.h
│ │ │ ├── mylib.h
│ │ │ └── printf.h
│ │ ├── init/
│ │ │ ├── Makefile
│ │ │ ├── crt0.S
│ │ │ └── init.c
│ │ ├── lash/
│ │ │ ├── Makefile
│ │ │ └── lash.c
│ │ ├── libfb/
│ │ │ ├── Makefile
│ │ │ └── fb.c
│ │ ├── mydrm/
│ │ │ ├── Makefile
│ │ │ └── mydrm.c
│ │ ├── mylib/
│ │ │ ├── Makefile
│ │ │ ├── mem.c
│ │ │ ├── printf.c
│ │ │ ├── start.S
│ │ │ ├── sys.c
│ │ │ └── util.c
│ │ └── printargs/
│ │ ├── Makefile
│ │ └── printargs.c
│ └── qemu/
│ └── qemu-run.sh
├── ooc/
│ ├── Makefile
│ ├── flog.h
│ ├── log.h
│ ├── log_console.c
│ ├── log_file.c
│ └── main.c
├── pico/
│ └── 6502_part1/
│ ├── CMakeLists.txt
│ ├── pico_sdk_import.cmake
│ └── test.c
└── rpi_bm/
├── part1-5/
│ ├── Makefile
│ ├── README.md
│ ├── config.txt
│ ├── include/
│ │ ├── common.h
│ │ ├── gpio.h
│ │ ├── mini_uart.h
│ │ ├── mm.h
│ │ ├── peripherals/
│ │ │ ├── aux.h
│ │ │ ├── base.h
│ │ │ └── gpio.h
│ │ └── utils.h
│ └── src/
│ ├── boot.S
│ ├── gpio.c
│ ├── kernel.c
│ ├── linker.ld
│ ├── mini_uart.c
│ ├── mm.S
│ └── utils.S
├── part10/
│ ├── Makefile
│ ├── armstub/
│ │ └── src/
│ │ └── armstub.S
│ ├── config.txt
│ ├── i2c-slave/
│ │ └── i2c-slave.ino
│ ├── include/
│ │ ├── common.h
│ │ ├── entry.h
│ │ ├── gpio.h
│ │ ├── i2c.h
│ │ ├── irq.h
│ │ ├── mini_uart.h
│ │ ├── mm.h
│ │ ├── peripherals/
│ │ │ ├── aux.h
│ │ │ ├── base.h
│ │ │ ├── gpio.h
│ │ │ ├── i2c.h
│ │ │ ├── irq.h
│ │ │ └── timer.h
│ │ ├── printf.h
│ │ ├── sysregs.h
│ │ ├── timer.h
│ │ └── utils.h
│ └── src/
│ ├── boot.S
│ ├── entry.S
│ ├── gpio.c
│ ├── i2c.c
│ ├── irq.S
│ ├── irq.c
│ ├── kernel.c
│ ├── linker.ld
│ ├── mini_uart.c
│ ├── mm.S
│ ├── printf.c
│ ├── timer.c
│ └── utils.S
├── part11/
│ ├── Makefile
│ ├── armstub/
│ │ └── src/
│ │ └── armstub.S
│ ├── config.txt
│ ├── i2c-slave/
│ │ └── i2c-slave.ino
│ ├── include/
│ │ ├── common.h
│ │ ├── entry.h
│ │ ├── gpio.h
│ │ ├── i2c.h
│ │ ├── irq.h
│ │ ├── lcd.h
│ │ ├── mini_uart.h
│ │ ├── mm.h
│ │ ├── peripherals/
│ │ │ ├── aux.h
│ │ │ ├── base.h
│ │ │ ├── gpio.h
│ │ │ ├── i2c.h
│ │ │ ├── irq.h
│ │ │ └── timer.h
│ │ ├── printf.h
│ │ ├── sysregs.h
│ │ ├── timer.h
│ │ └── utils.h
│ ├── spi-slave/
│ │ └── spi-slave.ino
│ ├── src/
│ │ ├── boot.S
│ │ ├── entry.S
│ │ ├── gpio.c
│ │ ├── i2c.c
│ │ ├── irq.S
│ │ ├── irq.c
│ │ ├── kernel.c
│ │ ├── lcd.c
│ │ ├── linker.ld
│ │ ├── mini_uart.c
│ │ ├── mm.S
│ │ ├── printf.c
│ │ ├── timer.c
│ │ └── utils.S
│ └── user_submissions/
│ └── README.md
├── part12/
│ ├── .vscode/
│ │ └── settings.json
│ ├── Makefile
│ ├── armstub/
│ │ └── src/
│ │ └── armstub.S
│ ├── config.txt
│ ├── i2c-slave/
│ │ └── i2c-slave.ino
│ ├── include/
│ │ ├── common.h
│ │ ├── entry.h
│ │ ├── gpio.h
│ │ ├── i2c.h
│ │ ├── irq.h
│ │ ├── lcd.h
│ │ ├── led_display.h
│ │ ├── mini_uart.h
│ │ ├── mm.h
│ │ ├── peripherals/
│ │ │ ├── aux.h
│ │ │ ├── base.h
│ │ │ ├── gpio.h
│ │ │ ├── i2c.h
│ │ │ ├── irq.h
│ │ │ ├── spi.h
│ │ │ └── timer.h
│ │ ├── printf.h
│ │ ├── spi.h
│ │ ├── sysregs.h
│ │ ├── timer.h
│ │ └── utils.h
│ └── src/
│ ├── boot.S
│ ├── entry.S
│ ├── gpio.c
│ ├── i2c.c
│ ├── irq.S
│ ├── irq.c
│ ├── kernel.c
│ ├── lcd.c
│ ├── led_display.c
│ ├── linker.ld
│ ├── mini_uart.c
│ ├── mm.S
│ ├── printf.c
│ ├── spi.c
│ ├── timer.c
│ └── utils.S
├── part13/
│ ├── .vscode/
│ │ └── settings.json
│ ├── Makefile
│ ├── armstub/
│ │ └── src/
│ │ └── armstub.S
│ ├── config.txt
│ ├── i2c-slave/
│ │ └── i2c-slave.ino
│ ├── include/
│ │ ├── common.h
│ │ ├── entry.h
│ │ ├── gpio.h
│ │ ├── i2c.h
│ │ ├── irq.h
│ │ ├── lcd.h
│ │ ├── led_display.h
│ │ ├── mailbox.h
│ │ ├── mem.h
│ │ ├── mini_uart.h
│ │ ├── mm.h
│ │ ├── peripherals/
│ │ │ ├── aux.h
│ │ │ ├── base.h
│ │ │ ├── gpio.h
│ │ │ ├── i2c.h
│ │ │ ├── irq.h
│ │ │ ├── spi.h
│ │ │ └── timer.h
│ │ ├── printf.h
│ │ ├── spi.h
│ │ ├── sysregs.h
│ │ ├── timer.h
│ │ ├── utils.h
│ │ └── video.h
│ └── src/
│ ├── boot.S
│ ├── entry.S
│ ├── gpio.c
│ ├── i2c.c
│ ├── irq.S
│ ├── irq.c
│ ├── kernel.c
│ ├── lcd.c
│ ├── led_display.c
│ ├── linker.ld
│ ├── mailbox.c
│ ├── mem.c
│ ├── mini_uart.c
│ ├── mm.S
│ ├── printf.c
│ ├── spi.c
│ ├── timer.c
│ └── utils.S
├── part14/
│ ├── .vscode/
│ │ └── settings.json
│ ├── Makefile
│ ├── armstub/
│ │ └── src/
│ │ └── armstub.S
│ ├── config.txt
│ ├── i2c-slave/
│ │ └── i2c-slave.ino
│ ├── include/
│ │ ├── common.h
│ │ ├── entry.h
│ │ ├── gpio.h
│ │ ├── i2c.h
│ │ ├── irq.h
│ │ ├── lcd.h
│ │ ├── led_display.h
│ │ ├── mailbox.h
│ │ ├── mem.h
│ │ ├── mini_uart.h
│ │ ├── mm.h
│ │ ├── peripherals/
│ │ │ ├── aux.h
│ │ │ ├── base.h
│ │ │ ├── gpio.h
│ │ │ ├── i2c.h
│ │ │ ├── irq.h
│ │ │ ├── spi.h
│ │ │ └── timer.h
│ │ ├── printf.h
│ │ ├── spi.h
│ │ ├── sysregs.h
│ │ ├── timer.h
│ │ ├── utils.h
│ │ └── video.h
│ ├── square_margin
│ └── src/
│ ├── boot.S
│ ├── entry.S
│ ├── fontData.c
│ ├── gpio.c
│ ├── i2c.c
│ ├── irq.S
│ ├── irq.c
│ ├── kernel.c
│ ├── lcd.c
│ ├── led_display.c
│ ├── linker.ld
│ ├── mailbox.c
│ ├── mem.c
│ ├── mini_uart.c
│ ├── mm.S
│ ├── printf.c
│ ├── spi.c
│ ├── timer.c
│ ├── utils.S
│ └── video.c
├── part15/
│ ├── .vscode/
│ │ └── settings.json
│ ├── Makefile
│ ├── armstub/
│ │ └── src/
│ │ └── armstub.S
│ ├── config.txt
│ ├── i2c-slave/
│ │ └── i2c-slave.ino
│ ├── include/
│ │ ├── common.h
│ │ ├── dma.h
│ │ ├── entry.h
│ │ ├── gpio.h
│ │ ├── i2c.h
│ │ ├── irq.h
│ │ ├── lcd.h
│ │ ├── led_display.h
│ │ ├── mailbox.h
│ │ ├── mem.h
│ │ ├── mini_uart.h
│ │ ├── mm.h
│ │ ├── peripherals/
│ │ │ ├── aux.h
│ │ │ ├── base.h
│ │ │ ├── dma.h
│ │ │ ├── gpio.h
│ │ │ ├── i2c.h
│ │ │ ├── irq.h
│ │ │ ├── spi.h
│ │ │ └── timer.h
│ │ ├── printf.h
│ │ ├── spi.h
│ │ ├── sysregs.h
│ │ ├── timer.h
│ │ ├── utils.h
│ │ └── video.h
│ ├── square_margin
│ └── src/
│ ├── boot.S
│ ├── dma.c
│ ├── entry.S
│ ├── fontData.c
│ ├── gpio.c
│ ├── i2c.c
│ ├── irq.S
│ ├── irq.c
│ ├── kernel.c
│ ├── lcd.c
│ ├── led_display.c
│ ├── linker.ld
│ ├── mailbox.c
│ ├── mem.c
│ ├── mini_uart.c
│ ├── mm.S
│ ├── printf.c
│ ├── spi.c
│ ├── timer.c
│ ├── utils.S
│ └── video.c
├── part16/
│ ├── Makefile
│ ├── armstub/
│ │ └── src/
│ │ └── armstub.S
│ ├── config.txt
│ ├── i2c-slave/
│ │ └── i2c-slave.ino
│ ├── include/
│ │ ├── common.h
│ │ ├── dma.h
│ │ ├── entry.h
│ │ ├── gpio.h
│ │ ├── i2c.h
│ │ ├── irq.h
│ │ ├── lcd.h
│ │ ├── led_display.h
│ │ ├── mailbox.h
│ │ ├── mem.h
│ │ ├── mini_uart.h
│ │ ├── mm.h
│ │ ├── mmu.h
│ │ ├── peripherals/
│ │ │ ├── aux.h
│ │ │ ├── base.h
│ │ │ ├── dma.h
│ │ │ ├── gpio.h
│ │ │ ├── i2c.h
│ │ │ ├── irq.h
│ │ │ ├── spi.h
│ │ │ └── timer.h
│ │ ├── printf.h
│ │ ├── spi.h
│ │ ├── sysregs.h
│ │ ├── timer.h
│ │ ├── utils.h
│ │ └── video.h
│ ├── square_margin
│ └── src/
│ ├── boot.S
│ ├── dma.c
│ ├── entry.S
│ ├── fontData.c
│ ├── gpio.c
│ ├── i2c.c
│ ├── irq.S
│ ├── irq.c
│ ├── kernel.c
│ ├── lcd.c
│ ├── led_display.c
│ ├── linker.ld
│ ├── mailbox.c
│ ├── mem.c
│ ├── mini_uart.c
│ ├── mm.S
│ ├── printf.c
│ ├── spi.c
│ ├── timer.c
│ ├── utils.S
│ └── video.c
├── part17/
│ ├── .vscode/
│ │ └── settings.json
│ ├── Makefile
│ ├── armstub/
│ │ ├── build/
│ │ │ ├── armstub.elf
│ │ │ ├── armstub_s.d
│ │ │ └── armstub_s.o
│ │ └── src/
│ │ └── armstub.S
│ ├── config.txt
│ ├── i2c-slave/
│ │ └── i2c-slave.ino
│ ├── include/
│ │ ├── common.h
│ │ ├── dma.h
│ │ ├── entry.h
│ │ ├── gpio.h
│ │ ├── i2c.h
│ │ ├── io.h
│ │ ├── irq.h
│ │ ├── lcd.h
│ │ ├── led_display.h
│ │ ├── mailbox.h
│ │ ├── mem.h
│ │ ├── mini_uart.h
│ │ ├── mm.h
│ │ ├── mmu.h
│ │ ├── peripherals/
│ │ │ ├── aux.h
│ │ │ ├── base.h
│ │ │ ├── dma.h
│ │ │ ├── emmc.h
│ │ │ ├── gpio.h
│ │ │ ├── i2c.h
│ │ │ ├── irq.h
│ │ │ ├── spi.h
│ │ │ └── timer.h
│ │ ├── printf.h
│ │ ├── spi.h
│ │ ├── sysregs.h
│ │ ├── timer.h
│ │ ├── utils.h
│ │ └── video.h
│ ├── square_margin
│ └── src/
│ ├── boot/
│ │ ├── boot.S
│ │ └── entry.S
│ ├── dma/
│ │ └── dma.c
│ ├── drivers/
│ │ ├── emmc/
│ │ │ ├── emmc.c
│ │ │ └── emmc_clock.c
│ │ ├── gpio/
│ │ │ └── gpio.c
│ │ ├── i2c/
│ │ │ ├── i2c.c
│ │ │ └── lcd.c
│ │ ├── mailbox/
│ │ │ └── mailbox.c
│ │ ├── muart/
│ │ │ └── mini_uart.c
│ │ ├── shared/
│ │ │ └── io.c
│ │ ├── spi/
│ │ │ ├── led_display.c
│ │ │ └── spi.c
│ │ └── video/
│ │ ├── fontData.c
│ │ └── video.c
│ ├── kernel/
│ │ ├── irq.S
│ │ ├── irq.c
│ │ ├── kernel.c
│ │ └── timer.c
│ ├── linker.ld
│ ├── mem/
│ │ ├── mem.c
│ │ └── mm.S
│ └── misc/
│ ├── printf.c
│ ├── utils.S
│ └── utils.c
├── part6-7/
│ ├── Makefile
│ ├── armstub/
│ │ └── src/
│ │ └── armstub.S
│ ├── config.txt
│ ├── include/
│ │ ├── common.h
│ │ ├── gpio.h
│ │ ├── mini_uart.h
│ │ ├── mm.h
│ │ ├── peripherals/
│ │ │ ├── aux.h
│ │ │ ├── base.h
│ │ │ └── gpio.h
│ │ ├── printf.h
│ │ ├── sysregs.h
│ │ └── utils.h
│ └── src/
│ ├── boot.S
│ ├── gpio.c
│ ├── kernel.c
│ ├── linker.ld
│ ├── mini_uart.c
│ ├── mm.S
│ ├── printf.c
│ └── utils.S
├── part8/
│ ├── Makefile
│ ├── armstub/
│ │ └── src/
│ │ └── armstub.S
│ ├── config.txt
│ ├── include/
│ │ ├── common.h
│ │ ├── entry.h
│ │ ├── gpio.h
│ │ ├── irq.h
│ │ ├── mini_uart.h
│ │ ├── mm.h
│ │ ├── peripherals/
│ │ │ ├── aux.h
│ │ │ ├── base.h
│ │ │ ├── gpio.h
│ │ │ └── irq.h
│ │ ├── printf.h
│ │ ├── sysregs.h
│ │ └── utils.h
│ └── src/
│ ├── boot.S
│ ├── entry.S
│ ├── gpio.c
│ ├── irq.S
│ ├── irq.c
│ ├── kernel.c
│ ├── linker.ld
│ ├── mini_uart.c
│ ├── mm.S
│ ├── printf.c
│ └── utils.S
└── part9/
├── Makefile
├── armstub/
│ └── src/
│ └── armstub.S
├── config.txt
├── include/
│ ├── common.h
│ ├── entry.h
│ ├── gpio.h
│ ├── irq.h
│ ├── mini_uart.h
│ ├── mm.h
│ ├── peripherals/
│ │ ├── aux.h
│ │ ├── base.h
│ │ ├── gpio.h
│ │ ├── irq.h
│ │ └── timer.h
│ ├── printf.h
│ ├── sysregs.h
│ ├── timer.h
│ └── utils.h
└── src/
├── boot.S
├── entry.S
├── gpio.c
├── irq.S
├── irq.c
├── kernel.c
├── linker.ld
├── mini_uart.c
├── mm.S
├── printf.c
├── timer.c
└── utils.S
SYMBOL INDEX (1409 symbols across 303 files)
FILE: linux_os/part1/src/init.c
function _strlen (line 6) | unsigned long _strlen(char *sz) {
function delay (line 16) | void delay(int ticks) {
function print_string (line 22) | void print_string(char *str) {
function open_file (line 26) | unsigned long open_file(char *fn, int flags) {
function read_file (line 30) | unsigned long read_file(unsigned long fd, char *buff, unsigned long size) {
function main (line 34) | int main() {
FILE: linux_os/part10/src/drmlist/drmlist.c
type mydrm_buf (line 6) | struct mydrm_buf {
type mydrm_data (line 16) | struct mydrm_data {
type mouse_pos_info (line 27) | struct mouse_pos_info {
type mouse_pos_info (line 34) | struct mouse_pos_info
type drm_mode_crtc (line 36) | struct drm_mode_crtc
type mydrm_data (line 38) | struct mydrm_data
type drm_mode_get_connector (line 38) | struct drm_mode_get_connector
type drm_mode_modeinfo (line 38) | struct drm_mode_modeinfo
function main (line 40) | int main(int argc, char **argv) {
function create_framebuffer (line 110) | bool create_framebuffer(int fd, struct mydrm_buf *buf) {
function draw_data (line 178) | static void draw_data(int fd, struct mydrm_data *data) {
function page_flip_event (line 229) | static void page_flip_event(int fd, uint32_t frame, uint32_t sec, uint32...
function set_mode (line 239) | int set_mode(struct mydrm_data *data, struct drm_mode_get_connector conn...
FILE: linux_os/part10/src/fbset/fbset.c
function fill_fb (line 7) | int fill_fb(void *pbuffer, struct fb_var_screeninfo *vi, struct fb_fix_s...
function main (line 17) | int main(int argc, char **argv) {
FILE: linux_os/part10/src/include/libfb.h
type fb_var_screeninfo (line 10) | struct fb_var_screeninfo
type fb_fix_screeninfo (line 10) | struct fb_fix_screeninfo
type fb_var_screeninfo (line 11) | struct fb_var_screeninfo
FILE: linux_os/part10/src/include/mydrm.h
type mydrm_get_cap (line 8) | struct mydrm_get_cap {
type mydrm_modes (line 13) | enum mydrm_modes {
type mydrm_event_context (line 19) | struct mydrm_event_context {
type drm_mode_card_res (line 27) | struct drm_mode_card_res
type drm_mode_get_connector (line 28) | struct drm_mode_get_connector
type drm_mode_get_encoder (line 30) | struct drm_mode_get_encoder
type mydrm_event_context (line 31) | struct mydrm_event_context
FILE: linux_os/part10/src/include/mylib.h
type timespec (line 19) | struct timespec
type timespec (line 19) | struct timespec
type timeval (line 39) | struct timeval
type stat (line 50) | struct stat
FILE: linux_os/part10/src/init/init.c
function fix_color (line 7) | uint32_t fix_color(uint32_t num) {
function main (line 11) | int main() {
FILE: linux_os/part10/src/lash/lash.c
type event_file (line 8) | struct event_file {
type input_event (line 15) | struct input_event {
type mouse_pos_info (line 22) | struct mouse_pos_info {
type mouse_pos_info (line 29) | struct mouse_pos_info
type event_file (line 31) | struct event_file
function load_event_devices (line 33) | void load_event_devices() {
function handle_event (line 61) | bool handle_event(struct event_file *e, struct input_event *event) {
function handle_events (line 99) | void handle_events() {
function console_open (line 143) | void console_open() {
function console_read (line 147) | char console_read() {
function console_write (line 160) | void console_write(char c) {
function read_line (line 164) | int read_line(char *buff, int max) {
function find_command (line 219) | bool find_command(char *fullPath) {
function process_command (line 237) | bool process_command(char *cmd) {
function main (line 316) | int main() {
FILE: linux_os/part10/src/libfb/fb.c
function fb_get_info (line 6) | int fb_get_info(struct fb_var_screeninfo *vi, struct fb_fix_screeninfo *...
function fb_put_info (line 31) | int fb_put_info(struct fb_var_screeninfo *vi) {
type fb_fix_screeninfo (line 51) | struct fb_fix_screeninfo
FILE: linux_os/part10/src/mydrm/mydrm.c
function mydrm_ioctl (line 10) | int mydrm_ioctl(int fd, unsigned long request, void *arg) {
function mydrm_open (line 21) | int mydrm_open(const char *device_node) {
function mydrm_get_resources (line 40) | int mydrm_get_resources(int fd, struct drm_mode_card_res *res) {
function mydrm_get_connector (line 78) | int mydrm_get_connector(int fd, int id, struct drm_mode_get_connector *c...
function mydrm_get_encoder (line 106) | int mydrm_get_encoder(int fd, int id, struct drm_mode_get_encoder *enc) {
function mydrm_handle_event (line 118) | int mydrm_handle_event(int fd, struct mydrm_event_context *context) {
FILE: linux_os/part10/src/mylib/mem.c
function chunk_size (line 61) | static inline uint32_t chunk_size(uint8_t *p) {
function is_chunk_alloc (line 65) | static inline bool is_chunk_alloc(uint8_t *p) {
function is_chunk_free (line 69) | static inline bool is_chunk_free(uint8_t *p) {
function is_chunk_mapped (line 73) | static inline bool is_chunk_mapped(uint8_t *p) {
function align_8 (line 99) | static inline size_t align_8(size_t size) {
function init_heap (line 104) | static void init_heap() {
function print_heap (line 125) | void print_heap() {
function free (line 211) | void free(void *up) {
FILE: linux_os/part10/src/mylib/printf.c
function uli2a (line 29) | static void uli2a(unsigned long int num, unsigned int base, int uc,char ...
function li2a (line 47) | static void li2a (long num, char * bf)
function ui2a (line 58) | static void ui2a(unsigned int num, unsigned int base, int uc,char * bf)
function i2a (line 76) | static void i2a (int num, char * bf)
function a2d (line 85) | static int a2d(char ch)
function a2i (line 96) | static char a2i(char ch, char** src,int base,int* nump)
function putchw (line 111) | static void putchw(void* putp,putcf putf,int n, char z, char* bf)
function tfp_format (line 124) | void tfp_format(void* putp,putcf putf,char *fmt, va_list va)
function init_printf (line 203) | void init_printf(void* putp,void (*putf) (void*,char))
function putc_console (line 212) | void putc_console(void *p, char c) {
function tfp_printf (line 216) | void tfp_printf(char *fmt, ...)
function putcp (line 230) | static void putcp(void* p,char c)
function tfp_sprintf (line 237) | void tfp_sprintf(char* s,char *fmt, ...)
FILE: linux_os/part10/src/mylib/sys.c
function sys_open (line 4) | unsigned long sys_open(char *fn, int flags) {
function sys_read (line 8) | unsigned long sys_read(unsigned long fd, char *buff, unsigned long size) {
function sys_reboot (line 12) | unsigned long sys_reboot() {
function sys_nanosleep (line 16) | unsigned long sys_nanosleep(struct timespec *req, struct timespec *rem) {
function sleep_sec (line 20) | void sleep_sec(int sec) {
function sys_write (line 28) | unsigned long sys_write(unsigned long fd, char *buf, unsigned long len) {
function sys_fork (line 32) | long sys_fork() {
function sys_execve (line 36) | long sys_execve(char *filename, char **argv, char **envp) {
function execute_process (line 40) | int execute_process(char *filename) {
function sys_select (line 67) | int sys_select(int nfds, fd_set *readfds, fd_set *writefds,
function sys_munmap (line 76) | int sys_munmap(void *addr, size_t length) {
function sys_stat (line 80) | int sys_stat(const char *pathname, struct stat *statbuf) {
function sys_close (line 84) | int sys_close(unsigned long fd) {
function sys_ioctl (line 88) | int sys_ioctl(unsigned long fd, unsigned long cmd, void *arg) {
function sys_waitid (line 92) | int sys_waitid(idtype_t idtype, id_t id, siginfo_t *infop, int options) {
FILE: linux_os/part10/src/mylib/util.c
function str_len (line 5) | unsigned long str_len(char *sz) {
function delay (line 15) | void delay(int ticks) {
function str_print (line 21) | void str_print(char *str) {
function str_eq (line 25) | int str_eq(char *a, char *b) {
function str_pos (line 38) | int str_pos(char *s, char c) {
function hex_str_to_ulong (line 48) | unsigned long hex_str_to_ulong(char *s) {
function str_to_int (line 60) | int str_to_int(char *s) {
function mem_set (line 76) | void mem_set(void *p, char n, size_t size) {
function mem_copy (line 84) | void mem_copy(void *dest, void *source, size_t size) {
function str_copy (line 93) | void str_copy(char *dest, char *source) {
function _exit (line 97) | void _exit(int code) {
FILE: linux_os/part10/src/printargs/printargs.c
function main (line 4) | int main(int argc, char **argv) {
FILE: linux_os/part2/src/init/init.c
function main (line 5) | int main() {
FILE: linux_os/part2/src/mylib/sys.c
function sys_open (line 5) | unsigned long sys_open(char *fn, int flags) {
function sys_read (line 9) | unsigned long sys_read(unsigned long fd, char *buff, unsigned long size) {
function sys_reboot (line 13) | unsigned long sys_reboot() {
function sys_nanosleep (line 17) | unsigned long sys_nanosleep(struct timespec *req, struct timespec *rem) {
function sleep_sec (line 21) | void sleep_sec(int sec) {
FILE: linux_os/part2/src/mylib/util.c
function str_len (line 4) | unsigned long str_len(char *sz) {
function delay (line 14) | void delay(int ticks) {
function str_print (line 20) | void str_print(char *str) {
FILE: linux_os/part3/src/include/mylib.h
type timespec (line 9) | struct timespec
type timespec (line 9) | struct timespec
FILE: linux_os/part3/src/init/init.c
function main (line 5) | int main() {
FILE: linux_os/part3/src/lash/lash.c
function console_open (line 6) | void console_open() {
function console_read (line 10) | char console_read() {
function console_write (line 23) | void console_write(char c) {
function read_line (line 27) | int read_line(char *buff, int max) {
function main (line 56) | int main() {
FILE: linux_os/part3/src/mylib/sys.c
function sys_open (line 4) | unsigned long sys_open(char *fn, int flags) {
function sys_read (line 8) | unsigned long sys_read(unsigned long fd, char *buff, unsigned long size) {
function sys_reboot (line 12) | unsigned long sys_reboot() {
function sys_nanosleep (line 16) | unsigned long sys_nanosleep(struct timespec *req, struct timespec *rem) {
function sleep_sec (line 20) | void sleep_sec(int sec) {
function sys_write (line 28) | unsigned long sys_write(unsigned long fd, char *buf, unsigned long len) {
function sys_fork (line 32) | long sys_fork() {
function sys_execve (line 36) | long sys_execve(char *filename, char **argv, char **envp) {
function execute_process (line 40) | int execute_process(char *filename) {
FILE: linux_os/part3/src/mylib/util.c
function str_len (line 4) | unsigned long str_len(char *sz) {
function delay (line 14) | void delay(int ticks) {
function str_print (line 20) | void str_print(char *str) {
function str_eq (line 24) | int str_eq(char *a, char *b) {
FILE: linux_os/part4/src/include/mylib.h
type timespec (line 10) | struct timespec
type timespec (line 10) | struct timespec
FILE: linux_os/part4/src/init/init.c
function main (line 5) | int main() {
FILE: linux_os/part4/src/lash/lash.c
function console_open (line 7) | void console_open() {
function console_read (line 11) | char console_read() {
function console_write (line 24) | void console_write(char c) {
function read_line (line 28) | int read_line(char *buff, int max) {
function process_command (line 59) | void process_command(char *cmd) {
function main (line 117) | int main() {
FILE: linux_os/part4/src/mylib/printf.c
function uli2a (line 29) | static void uli2a(unsigned long int num, unsigned int base, int uc,char ...
function li2a (line 47) | static void li2a (long num, char * bf)
function ui2a (line 58) | static void ui2a(unsigned int num, unsigned int base, int uc,char * bf)
function i2a (line 76) | static void i2a (int num, char * bf)
function a2d (line 85) | static int a2d(char ch)
function a2i (line 96) | static char a2i(char ch, char** src,int base,int* nump)
function putchw (line 111) | static void putchw(void* putp,putcf putf,int n, char z, char* bf)
function tfp_format (line 124) | void tfp_format(void* putp,putcf putf,char *fmt, va_list va)
function init_printf (line 203) | void init_printf(void* putp,void (*putf) (void*,char))
function putc_console (line 212) | void putc_console(void *p, char c) {
function tfp_printf (line 216) | void tfp_printf(char *fmt, ...)
function putcp (line 230) | static void putcp(void* p,char c)
function tfp_sprintf (line 237) | void tfp_sprintf(char* s,char *fmt, ...)
FILE: linux_os/part4/src/mylib/sys.c
function sys_open (line 4) | unsigned long sys_open(char *fn, int flags) {
function sys_read (line 8) | unsigned long sys_read(unsigned long fd, char *buff, unsigned long size) {
function sys_reboot (line 12) | unsigned long sys_reboot() {
function sys_nanosleep (line 16) | unsigned long sys_nanosleep(struct timespec *req, struct timespec *rem) {
function sleep_sec (line 20) | void sleep_sec(int sec) {
function sys_write (line 28) | unsigned long sys_write(unsigned long fd, char *buf, unsigned long len) {
function sys_fork (line 32) | long sys_fork() {
function sys_execve (line 36) | long sys_execve(char *filename, char **argv, char **envp) {
function execute_process (line 40) | int execute_process(char *filename) {
FILE: linux_os/part4/src/mylib/util.c
function str_len (line 5) | unsigned long str_len(char *sz) {
function delay (line 15) | void delay(int ticks) {
function str_print (line 21) | void str_print(char *str) {
function str_eq (line 25) | int str_eq(char *a, char *b) {
function str_pos (line 38) | int str_pos(char *s, char c) {
function hex_str_to_ulong (line 48) | unsigned long hex_str_to_ulong(char *s) {
function str_to_int (line 60) | int str_to_int(char *s) {
FILE: linux_os/part5/src/include/mylib.h
type timespec (line 11) | struct timespec
type timespec (line 11) | struct timespec
type timeval (line 31) | struct timeval
FILE: linux_os/part5/src/init/init.c
function main (line 5) | int main() {
FILE: linux_os/part5/src/lash/lash.c
type event_file (line 8) | struct event_file {
type input_event (line 15) | struct input_event {
type mouse_pos_info (line 22) | struct mouse_pos_info {
type mouse_pos_info (line 29) | struct mouse_pos_info
type event_file (line 31) | struct event_file
function load_event_devices (line 33) | void load_event_devices() {
function handle_event (line 61) | bool handle_event(struct event_file *e, struct input_event *event) {
function handle_events (line 99) | void handle_events() {
function console_open (line 143) | void console_open() {
function console_read (line 147) | char console_read() {
function console_write (line 160) | void console_write(char c) {
function read_line (line 164) | int read_line(char *buff, int max) {
function process_command (line 195) | void process_command(char *cmd) {
function main (line 257) | int main() {
FILE: linux_os/part5/src/mylib/printf.c
function uli2a (line 29) | static void uli2a(unsigned long int num, unsigned int base, int uc,char ...
function li2a (line 47) | static void li2a (long num, char * bf)
function ui2a (line 58) | static void ui2a(unsigned int num, unsigned int base, int uc,char * bf)
function i2a (line 76) | static void i2a (int num, char * bf)
function a2d (line 85) | static int a2d(char ch)
function a2i (line 96) | static char a2i(char ch, char** src,int base,int* nump)
function putchw (line 111) | static void putchw(void* putp,putcf putf,int n, char z, char* bf)
function tfp_format (line 124) | void tfp_format(void* putp,putcf putf,char *fmt, va_list va)
function init_printf (line 203) | void init_printf(void* putp,void (*putf) (void*,char))
function putc_console (line 212) | void putc_console(void *p, char c) {
function tfp_printf (line 216) | void tfp_printf(char *fmt, ...)
function putcp (line 230) | static void putcp(void* p,char c)
function tfp_sprintf (line 237) | void tfp_sprintf(char* s,char *fmt, ...)
FILE: linux_os/part5/src/mylib/sys.c
function sys_open (line 4) | unsigned long sys_open(char *fn, int flags) {
function sys_read (line 8) | unsigned long sys_read(unsigned long fd, char *buff, unsigned long size) {
function sys_reboot (line 12) | unsigned long sys_reboot() {
function sys_nanosleep (line 16) | unsigned long sys_nanosleep(struct timespec *req, struct timespec *rem) {
function sleep_sec (line 20) | void sleep_sec(int sec) {
function sys_write (line 28) | unsigned long sys_write(unsigned long fd, char *buf, unsigned long len) {
function sys_fork (line 32) | long sys_fork() {
function sys_execve (line 36) | long sys_execve(char *filename, char **argv, char **envp) {
function execute_process (line 40) | int execute_process(char *filename) {
function sys_select (line 67) | int sys_select(int nfds, fd_set *readfds, fd_set *writefds,
FILE: linux_os/part5/src/mylib/util.c
function str_len (line 5) | unsigned long str_len(char *sz) {
function delay (line 15) | void delay(int ticks) {
function str_print (line 21) | void str_print(char *str) {
function str_eq (line 25) | int str_eq(char *a, char *b) {
function str_pos (line 38) | int str_pos(char *s, char c) {
function hex_str_to_ulong (line 48) | unsigned long hex_str_to_ulong(char *s) {
function str_to_int (line 60) | int str_to_int(char *s) {
function mem_set (line 87) | void mem_set(void *p, char n, size_t size) {
function mem_copy (line 95) | void mem_copy(void *dest, void *source, size_t size) {
function str_copy (line 104) | void str_copy(char *dest, char *source) {
FILE: linux_os/part6/src/include/mylib.h
type timespec (line 13) | struct timespec
type timespec (line 13) | struct timespec
type timeval (line 33) | struct timeval
FILE: linux_os/part6/src/init/init.c
function main (line 5) | int main() {
FILE: linux_os/part6/src/lash/lash.c
type event_file (line 8) | struct event_file {
type input_event (line 15) | struct input_event {
type mouse_pos_info (line 22) | struct mouse_pos_info {
type mouse_pos_info (line 29) | struct mouse_pos_info
type event_file (line 31) | struct event_file
function load_event_devices (line 33) | void load_event_devices() {
function handle_event (line 61) | bool handle_event(struct event_file *e, struct input_event *event) {
function handle_events (line 99) | void handle_events() {
function console_open (line 143) | void console_open() {
function console_read (line 147) | char console_read() {
function console_write (line 160) | void console_write(char c) {
function read_line (line 164) | int read_line(char *buff, int max) {
function process_command (line 195) | void process_command(char *cmd) {
function main (line 264) | int main() {
FILE: linux_os/part6/src/mylib/mem.c
function chunk_size (line 61) | static inline uint32_t chunk_size(uint8_t *p) {
function is_chunk_alloc (line 65) | static inline bool is_chunk_alloc(uint8_t *p) {
function is_chunk_free (line 69) | static inline bool is_chunk_free(uint8_t *p) {
function is_chunk_mapped (line 73) | static inline bool is_chunk_mapped(uint8_t *p) {
function align_8 (line 99) | static inline size_t align_8(size_t size) {
function init_heap (line 104) | static void init_heap() {
function print_heap (line 125) | void print_heap() {
function free (line 211) | void free(void *up) {
FILE: linux_os/part6/src/mylib/printf.c
function uli2a (line 29) | static void uli2a(unsigned long int num, unsigned int base, int uc,char ...
function li2a (line 47) | static void li2a (long num, char * bf)
function ui2a (line 58) | static void ui2a(unsigned int num, unsigned int base, int uc,char * bf)
function i2a (line 76) | static void i2a (int num, char * bf)
function a2d (line 85) | static int a2d(char ch)
function a2i (line 96) | static char a2i(char ch, char** src,int base,int* nump)
function putchw (line 111) | static void putchw(void* putp,putcf putf,int n, char z, char* bf)
function tfp_format (line 124) | void tfp_format(void* putp,putcf putf,char *fmt, va_list va)
function init_printf (line 203) | void init_printf(void* putp,void (*putf) (void*,char))
function putc_console (line 212) | void putc_console(void *p, char c) {
function tfp_printf (line 216) | void tfp_printf(char *fmt, ...)
function putcp (line 230) | static void putcp(void* p,char c)
function tfp_sprintf (line 237) | void tfp_sprintf(char* s,char *fmt, ...)
FILE: linux_os/part6/src/mylib/sys.c
function sys_open (line 4) | unsigned long sys_open(char *fn, int flags) {
function sys_read (line 8) | unsigned long sys_read(unsigned long fd, char *buff, unsigned long size) {
function sys_reboot (line 12) | unsigned long sys_reboot() {
function sys_nanosleep (line 16) | unsigned long sys_nanosleep(struct timespec *req, struct timespec *rem) {
function sleep_sec (line 20) | void sleep_sec(int sec) {
function sys_write (line 28) | unsigned long sys_write(unsigned long fd, char *buf, unsigned long len) {
function sys_fork (line 32) | long sys_fork() {
function sys_execve (line 36) | long sys_execve(char *filename, char **argv, char **envp) {
function execute_process (line 40) | int execute_process(char *filename) {
function sys_select (line 67) | int sys_select(int nfds, fd_set *readfds, fd_set *writefds,
function sys_munmap (line 76) | int sys_munmap(void *addr, size_t length) {
FILE: linux_os/part6/src/mylib/util.c
function str_len (line 5) | unsigned long str_len(char *sz) {
function delay (line 15) | void delay(int ticks) {
function str_print (line 21) | void str_print(char *str) {
function str_eq (line 25) | int str_eq(char *a, char *b) {
function str_pos (line 38) | int str_pos(char *s, char c) {
function hex_str_to_ulong (line 48) | unsigned long hex_str_to_ulong(char *s) {
function str_to_int (line 60) | int str_to_int(char *s) {
function mem_set (line 76) | void mem_set(void *p, char n, size_t size) {
function mem_copy (line 84) | void mem_copy(void *dest, void *source, size_t size) {
function str_copy (line 93) | void str_copy(char *dest, char *source) {
FILE: linux_os/part7/src/include/mylib.h
type timespec (line 18) | struct timespec
type timespec (line 18) | struct timespec
type timeval (line 38) | struct timeval
type stat (line 49) | struct stat
FILE: linux_os/part7/src/init/init.c
function main (line 5) | int main() {
FILE: linux_os/part7/src/lash/lash.c
type event_file (line 8) | struct event_file {
type input_event (line 15) | struct input_event {
type mouse_pos_info (line 22) | struct mouse_pos_info {
type mouse_pos_info (line 29) | struct mouse_pos_info
type event_file (line 31) | struct event_file
function load_event_devices (line 33) | void load_event_devices() {
function handle_event (line 61) | bool handle_event(struct event_file *e, struct input_event *event) {
function handle_events (line 99) | void handle_events() {
function console_open (line 143) | void console_open() {
function console_read (line 147) | char console_read() {
function console_write (line 160) | void console_write(char c) {
function read_line (line 164) | int read_line(char *buff, int max) {
function find_command (line 219) | bool find_command(char *fullPath) {
function process_command (line 237) | bool process_command(char *cmd) {
function main (line 310) | int main() {
FILE: linux_os/part7/src/mylib/mem.c
function chunk_size (line 61) | static inline uint32_t chunk_size(uint8_t *p) {
function is_chunk_alloc (line 65) | static inline bool is_chunk_alloc(uint8_t *p) {
function is_chunk_free (line 69) | static inline bool is_chunk_free(uint8_t *p) {
function is_chunk_mapped (line 73) | static inline bool is_chunk_mapped(uint8_t *p) {
function align_8 (line 99) | static inline size_t align_8(size_t size) {
function init_heap (line 104) | static void init_heap() {
function print_heap (line 125) | void print_heap() {
function free (line 211) | void free(void *up) {
FILE: linux_os/part7/src/mylib/printf.c
function uli2a (line 29) | static void uli2a(unsigned long int num, unsigned int base, int uc,char ...
function li2a (line 47) | static void li2a (long num, char * bf)
function ui2a (line 58) | static void ui2a(unsigned int num, unsigned int base, int uc,char * bf)
function i2a (line 76) | static void i2a (int num, char * bf)
function a2d (line 85) | static int a2d(char ch)
function a2i (line 96) | static char a2i(char ch, char** src,int base,int* nump)
function putchw (line 111) | static void putchw(void* putp,putcf putf,int n, char z, char* bf)
function tfp_format (line 124) | void tfp_format(void* putp,putcf putf,char *fmt, va_list va)
function init_printf (line 203) | void init_printf(void* putp,void (*putf) (void*,char))
function putc_console (line 212) | void putc_console(void *p, char c) {
function tfp_printf (line 216) | void tfp_printf(char *fmt, ...)
function putcp (line 230) | static void putcp(void* p,char c)
function tfp_sprintf (line 237) | void tfp_sprintf(char* s,char *fmt, ...)
FILE: linux_os/part7/src/mylib/sys.c
function sys_open (line 4) | unsigned long sys_open(char *fn, int flags) {
function sys_read (line 8) | unsigned long sys_read(unsigned long fd, char *buff, unsigned long size) {
function sys_reboot (line 12) | unsigned long sys_reboot() {
function sys_nanosleep (line 16) | unsigned long sys_nanosleep(struct timespec *req, struct timespec *rem) {
function sleep_sec (line 20) | void sleep_sec(int sec) {
function sys_write (line 28) | unsigned long sys_write(unsigned long fd, char *buf, unsigned long len) {
function sys_fork (line 32) | long sys_fork() {
function sys_execve (line 36) | long sys_execve(char *filename, char **argv, char **envp) {
function execute_process (line 40) | int execute_process(char *filename) {
function sys_select (line 67) | int sys_select(int nfds, fd_set *readfds, fd_set *writefds,
function sys_munmap (line 76) | int sys_munmap(void *addr, size_t length) {
function sys_stat (line 80) | int sys_stat(const char *pathname, struct stat *statbuf) {
function sys_close (line 84) | int sys_close(unsigned long fd) {
FILE: linux_os/part7/src/mylib/util.c
function str_len (line 5) | unsigned long str_len(char *sz) {
function delay (line 15) | void delay(int ticks) {
function str_print (line 21) | void str_print(char *str) {
function str_eq (line 25) | int str_eq(char *a, char *b) {
function str_pos (line 38) | int str_pos(char *s, char c) {
function hex_str_to_ulong (line 48) | unsigned long hex_str_to_ulong(char *s) {
function str_to_int (line 60) | int str_to_int(char *s) {
function mem_set (line 76) | void mem_set(void *p, char n, size_t size) {
function mem_copy (line 84) | void mem_copy(void *dest, void *source, size_t size) {
function str_copy (line 93) | void str_copy(char *dest, char *source) {
function _exit (line 97) | void _exit(int code) {
FILE: linux_os/part7/src/printargs/printargs.c
function main (line 4) | int main(int argc, char **argv) {
FILE: linux_os/part8/src/fbset/fbset.c
function fill_fb (line 7) | int fill_fb(void *pbuffer, struct fb_var_screeninfo *vi, struct fb_fix_s...
function main (line 17) | int main(int argc, char **argv) {
FILE: linux_os/part8/src/include/libfb.h
type fb_var_screeninfo (line 10) | struct fb_var_screeninfo
type fb_fix_screeninfo (line 10) | struct fb_fix_screeninfo
type fb_var_screeninfo (line 11) | struct fb_var_screeninfo
FILE: linux_os/part8/src/include/mylib.h
type timespec (line 19) | struct timespec
type timespec (line 19) | struct timespec
type timeval (line 39) | struct timeval
type stat (line 50) | struct stat
FILE: linux_os/part8/src/init/init.c
function fix_color (line 7) | uint32_t fix_color(uint32_t num) {
function main (line 11) | int main() {
FILE: linux_os/part8/src/lash/lash.c
type event_file (line 8) | struct event_file {
type input_event (line 15) | struct input_event {
type mouse_pos_info (line 22) | struct mouse_pos_info {
type mouse_pos_info (line 29) | struct mouse_pos_info
type event_file (line 31) | struct event_file
function load_event_devices (line 33) | void load_event_devices() {
function handle_event (line 61) | bool handle_event(struct event_file *e, struct input_event *event) {
function handle_events (line 99) | void handle_events() {
function console_open (line 143) | void console_open() {
function console_read (line 147) | char console_read() {
function console_write (line 160) | void console_write(char c) {
function read_line (line 164) | int read_line(char *buff, int max) {
function find_command (line 219) | bool find_command(char *fullPath) {
function process_command (line 237) | bool process_command(char *cmd) {
function main (line 316) | int main() {
FILE: linux_os/part8/src/libfb/fb.c
function fb_get_info (line 6) | int fb_get_info(struct fb_var_screeninfo *vi, struct fb_fix_screeninfo *...
function fb_put_info (line 31) | int fb_put_info(struct fb_var_screeninfo *vi) {
type fb_fix_screeninfo (line 51) | struct fb_fix_screeninfo
FILE: linux_os/part8/src/mylib/mem.c
function chunk_size (line 61) | static inline uint32_t chunk_size(uint8_t *p) {
function is_chunk_alloc (line 65) | static inline bool is_chunk_alloc(uint8_t *p) {
function is_chunk_free (line 69) | static inline bool is_chunk_free(uint8_t *p) {
function is_chunk_mapped (line 73) | static inline bool is_chunk_mapped(uint8_t *p) {
function align_8 (line 99) | static inline size_t align_8(size_t size) {
function init_heap (line 104) | static void init_heap() {
function print_heap (line 125) | void print_heap() {
function free (line 211) | void free(void *up) {
FILE: linux_os/part8/src/mylib/printf.c
function uli2a (line 29) | static void uli2a(unsigned long int num, unsigned int base, int uc,char ...
function li2a (line 47) | static void li2a (long num, char * bf)
function ui2a (line 58) | static void ui2a(unsigned int num, unsigned int base, int uc,char * bf)
function i2a (line 76) | static void i2a (int num, char * bf)
function a2d (line 85) | static int a2d(char ch)
function a2i (line 96) | static char a2i(char ch, char** src,int base,int* nump)
function putchw (line 111) | static void putchw(void* putp,putcf putf,int n, char z, char* bf)
function tfp_format (line 124) | void tfp_format(void* putp,putcf putf,char *fmt, va_list va)
function init_printf (line 203) | void init_printf(void* putp,void (*putf) (void*,char))
function putc_console (line 212) | void putc_console(void *p, char c) {
function tfp_printf (line 216) | void tfp_printf(char *fmt, ...)
function putcp (line 230) | static void putcp(void* p,char c)
function tfp_sprintf (line 237) | void tfp_sprintf(char* s,char *fmt, ...)
FILE: linux_os/part8/src/mylib/sys.c
function sys_open (line 4) | unsigned long sys_open(char *fn, int flags) {
function sys_read (line 8) | unsigned long sys_read(unsigned long fd, char *buff, unsigned long size) {
function sys_reboot (line 12) | unsigned long sys_reboot() {
function sys_nanosleep (line 16) | unsigned long sys_nanosleep(struct timespec *req, struct timespec *rem) {
function sleep_sec (line 20) | void sleep_sec(int sec) {
function sys_write (line 28) | unsigned long sys_write(unsigned long fd, char *buf, unsigned long len) {
function sys_fork (line 32) | long sys_fork() {
function sys_execve (line 36) | long sys_execve(char *filename, char **argv, char **envp) {
function execute_process (line 40) | int execute_process(char *filename) {
function sys_select (line 67) | int sys_select(int nfds, fd_set *readfds, fd_set *writefds,
function sys_munmap (line 76) | int sys_munmap(void *addr, size_t length) {
function sys_stat (line 80) | int sys_stat(const char *pathname, struct stat *statbuf) {
function sys_close (line 84) | int sys_close(unsigned long fd) {
function sys_ioctl (line 88) | int sys_ioctl(unsigned long fd, unsigned long cmd, void *arg) {
function sys_waitid (line 92) | int sys_waitid(idtype_t idtype, id_t id, siginfo_t *infop, int options) {
FILE: linux_os/part8/src/mylib/util.c
function str_len (line 5) | unsigned long str_len(char *sz) {
function delay (line 15) | void delay(int ticks) {
function str_print (line 21) | void str_print(char *str) {
function str_eq (line 25) | int str_eq(char *a, char *b) {
function str_pos (line 38) | int str_pos(char *s, char c) {
function hex_str_to_ulong (line 48) | unsigned long hex_str_to_ulong(char *s) {
function str_to_int (line 60) | int str_to_int(char *s) {
function mem_set (line 76) | void mem_set(void *p, char n, size_t size) {
function mem_copy (line 84) | void mem_copy(void *dest, void *source, size_t size) {
function str_copy (line 93) | void str_copy(char *dest, char *source) {
function _exit (line 97) | void _exit(int code) {
FILE: linux_os/part8/src/printargs/printargs.c
function main (line 4) | int main(int argc, char **argv) {
FILE: linux_os/part9/src/drmlist/drmlist.c
function main (line 5) | int main(int argc, char **argv) {
FILE: linux_os/part9/src/fbset/fbset.c
function fill_fb (line 7) | int fill_fb(void *pbuffer, struct fb_var_screeninfo *vi, struct fb_fix_s...
function main (line 17) | int main(int argc, char **argv) {
FILE: linux_os/part9/src/include/libfb.h
type fb_var_screeninfo (line 10) | struct fb_var_screeninfo
type fb_fix_screeninfo (line 10) | struct fb_fix_screeninfo
type fb_var_screeninfo (line 11) | struct fb_var_screeninfo
FILE: linux_os/part9/src/include/mydrm.h
type mydrm_get_cap (line 8) | struct mydrm_get_cap {
type mydrm_modes (line 13) | enum mydrm_modes {
type drm_mode_card_res (line 21) | struct drm_mode_card_res
type drm_mode_get_connector (line 22) | struct drm_mode_get_connector
FILE: linux_os/part9/src/include/mylib.h
type timespec (line 19) | struct timespec
type timespec (line 19) | struct timespec
type timeval (line 39) | struct timeval
type stat (line 50) | struct stat
FILE: linux_os/part9/src/init/init.c
function fix_color (line 7) | uint32_t fix_color(uint32_t num) {
function main (line 11) | int main() {
FILE: linux_os/part9/src/lash/lash.c
type event_file (line 8) | struct event_file {
type input_event (line 15) | struct input_event {
type mouse_pos_info (line 22) | struct mouse_pos_info {
type mouse_pos_info (line 29) | struct mouse_pos_info
type event_file (line 31) | struct event_file
function load_event_devices (line 33) | void load_event_devices() {
function handle_event (line 61) | bool handle_event(struct event_file *e, struct input_event *event) {
function handle_events (line 99) | void handle_events() {
function console_open (line 143) | void console_open() {
function console_read (line 147) | char console_read() {
function console_write (line 160) | void console_write(char c) {
function read_line (line 164) | int read_line(char *buff, int max) {
function find_command (line 219) | bool find_command(char *fullPath) {
function process_command (line 237) | bool process_command(char *cmd) {
function main (line 316) | int main() {
FILE: linux_os/part9/src/libfb/fb.c
function fb_get_info (line 6) | int fb_get_info(struct fb_var_screeninfo *vi, struct fb_fix_screeninfo *...
function fb_put_info (line 31) | int fb_put_info(struct fb_var_screeninfo *vi) {
type fb_fix_screeninfo (line 51) | struct fb_fix_screeninfo
FILE: linux_os/part9/src/mydrm/mydrm.c
function mydrm_ioctl (line 10) | int mydrm_ioctl(int fd, unsigned long request, void *arg) {
function mydrm_open (line 21) | int mydrm_open(const char *device_node) {
function mydrm_get_resources (line 40) | int mydrm_get_resources(int fd, struct drm_mode_card_res *res) {
function mydrm_get_connector (line 78) | int mydrm_get_connector(int fd, int id, struct drm_mode_get_connector *c...
FILE: linux_os/part9/src/mylib/mem.c
function chunk_size (line 61) | static inline uint32_t chunk_size(uint8_t *p) {
function is_chunk_alloc (line 65) | static inline bool is_chunk_alloc(uint8_t *p) {
function is_chunk_free (line 69) | static inline bool is_chunk_free(uint8_t *p) {
function is_chunk_mapped (line 73) | static inline bool is_chunk_mapped(uint8_t *p) {
function align_8 (line 99) | static inline size_t align_8(size_t size) {
function init_heap (line 104) | static void init_heap() {
function print_heap (line 125) | void print_heap() {
function free (line 211) | void free(void *up) {
FILE: linux_os/part9/src/mylib/printf.c
function uli2a (line 29) | static void uli2a(unsigned long int num, unsigned int base, int uc,char ...
function li2a (line 47) | static void li2a (long num, char * bf)
function ui2a (line 58) | static void ui2a(unsigned int num, unsigned int base, int uc,char * bf)
function i2a (line 76) | static void i2a (int num, char * bf)
function a2d (line 85) | static int a2d(char ch)
function a2i (line 96) | static char a2i(char ch, char** src,int base,int* nump)
function putchw (line 111) | static void putchw(void* putp,putcf putf,int n, char z, char* bf)
function tfp_format (line 124) | void tfp_format(void* putp,putcf putf,char *fmt, va_list va)
function init_printf (line 203) | void init_printf(void* putp,void (*putf) (void*,char))
function putc_console (line 212) | void putc_console(void *p, char c) {
function tfp_printf (line 216) | void tfp_printf(char *fmt, ...)
function putcp (line 230) | static void putcp(void* p,char c)
function tfp_sprintf (line 237) | void tfp_sprintf(char* s,char *fmt, ...)
FILE: linux_os/part9/src/mylib/sys.c
function sys_open (line 4) | unsigned long sys_open(char *fn, int flags) {
function sys_read (line 8) | unsigned long sys_read(unsigned long fd, char *buff, unsigned long size) {
function sys_reboot (line 12) | unsigned long sys_reboot() {
function sys_nanosleep (line 16) | unsigned long sys_nanosleep(struct timespec *req, struct timespec *rem) {
function sleep_sec (line 20) | void sleep_sec(int sec) {
function sys_write (line 28) | unsigned long sys_write(unsigned long fd, char *buf, unsigned long len) {
function sys_fork (line 32) | long sys_fork() {
function sys_execve (line 36) | long sys_execve(char *filename, char **argv, char **envp) {
function execute_process (line 40) | int execute_process(char *filename) {
function sys_select (line 67) | int sys_select(int nfds, fd_set *readfds, fd_set *writefds,
function sys_munmap (line 76) | int sys_munmap(void *addr, size_t length) {
function sys_stat (line 80) | int sys_stat(const char *pathname, struct stat *statbuf) {
function sys_close (line 84) | int sys_close(unsigned long fd) {
function sys_ioctl (line 88) | int sys_ioctl(unsigned long fd, unsigned long cmd, void *arg) {
function sys_waitid (line 92) | int sys_waitid(idtype_t idtype, id_t id, siginfo_t *infop, int options) {
FILE: linux_os/part9/src/mylib/util.c
function str_len (line 5) | unsigned long str_len(char *sz) {
function delay (line 15) | void delay(int ticks) {
function str_print (line 21) | void str_print(char *str) {
function str_eq (line 25) | int str_eq(char *a, char *b) {
function str_pos (line 38) | int str_pos(char *s, char c) {
function hex_str_to_ulong (line 48) | unsigned long hex_str_to_ulong(char *s) {
function str_to_int (line 60) | int str_to_int(char *s) {
function mem_set (line 76) | void mem_set(void *p, char n, size_t size) {
function mem_copy (line 84) | void mem_copy(void *dest, void *source, size_t size) {
function str_copy (line 93) | void str_copy(char *dest, char *source) {
function _exit (line 97) | void _exit(int code) {
FILE: linux_os/part9/src/printargs/printargs.c
function main (line 4) | int main(int argc, char **argv) {
FILE: ooc/log.h
type logger (line 3) | typedef struct logger_ logger;
type log_interface (line 6) | typedef struct log_interface_ {
type logger_ (line 14) | struct logger_ {
FILE: ooc/log_console.c
function console_init (line 4) | int console_init(logger *self, void *data) {
function console_info (line 9) | void console_info(logger *self, char *str) {
function console_error (line 13) | void console_error(logger *self, char *str) {
function console_close (line 17) | void console_close(logger *self) {
FILE: ooc/log_file.c
type filelog_data (line 19) | typedef struct filelog_data_ {
function file_init (line 24) | int file_init(logger *self, void *data) {
function filelog_create (line 41) | int filelog_create(logger *impl, char *filename) {
function file_info (line 53) | void file_info(logger *self, char *str) {
function file_error (line 58) | void file_error(logger *self, char *str) {
function file_close (line 63) | void file_close(logger *self) {
FILE: ooc/main.c
function do_something (line 10) | void do_something(logger *log) {
function main (line 22) | int main() {
FILE: pico/6502_part1/test.c
function write_data (line 62) | void write_data(uint8_t val) {
function reserved_addr (line 68) | bool reserved_addr(uint8_t addr) {
function scan_bus (line 72) | void scan_bus() {
function nothing (line 101) | int nothing() {
function main (line 105) | int main() {
FILE: rpi_bm/part1-5/include/common.h
type u8 (line 5) | typedef uint8_t u8;
type u16 (line 6) | typedef uint16_t u16;
type u32 (line 7) | typedef uint32_t u32;
type u64 (line 8) | typedef uint64_t u64;
type u32 (line 10) | typedef volatile u32 reg32;
FILE: rpi_bm/part1-5/include/gpio.h
type GpioFunc (line 5) | typedef enum _GpioFunc {
FILE: rpi_bm/part1-5/include/peripherals/aux.h
type AuxRegs (line 7) | struct AuxRegs {
FILE: rpi_bm/part1-5/include/peripherals/gpio.h
type GpioPinData (line 7) | struct GpioPinData {
type GpioRegs (line 12) | struct GpioRegs {
FILE: rpi_bm/part1-5/src/gpio.c
function gpio_pin_set_func (line 4) | void gpio_pin_set_func(u8 pinNumber, GpioFunc func) {
function gpio_pin_enable (line 15) | void gpio_pin_enable(u8 pinNumber) {
FILE: rpi_bm/part1-5/src/kernel.c
function kernel_main (line 4) | void kernel_main() {
FILE: rpi_bm/part1-5/src/mini_uart.c
function uart_init (line 9) | void uart_init() {
function uart_send (line 37) | void uart_send(char c) {
function uart_recv (line 43) | char uart_recv() {
function uart_send_string (line 49) | void uart_send_string(char *str) {
FILE: rpi_bm/part10/include/common.h
type u8 (line 5) | typedef uint8_t u8;
type u16 (line 6) | typedef uint16_t u16;
type u32 (line 7) | typedef uint32_t u32;
type u64 (line 8) | typedef uint64_t u64;
type u32 (line 10) | typedef volatile u32 reg32;
FILE: rpi_bm/part10/include/gpio.h
type GpioFunc (line 5) | typedef enum _GpioFunc {
FILE: rpi_bm/part10/include/i2c.h
type i2c_status (line 5) | typedef enum _i2c_status {
FILE: rpi_bm/part10/include/peripherals/aux.h
type AuxRegs (line 7) | struct AuxRegs {
FILE: rpi_bm/part10/include/peripherals/gpio.h
type GpioPinData (line 7) | struct GpioPinData {
type GpioRegs (line 12) | struct GpioRegs {
FILE: rpi_bm/part10/include/peripherals/i2c.h
type I2CRegs (line 5) | struct I2CRegs {
FILE: rpi_bm/part10/include/peripherals/irq.h
type vc_irqs (line 7) | enum vc_irqs {
type arm_irq_regs_2711 (line 15) | struct arm_irq_regs_2711 {
type arm_irq_regs_2837 (line 29) | struct arm_irq_regs_2837 {
type arm_irq_regs (line 44) | typedef struct arm_irq_regs_2837 arm_irq_regs;
type arm_irq_regs (line 48) | typedef struct arm_irq_regs_2711 arm_irq_regs;
FILE: rpi_bm/part10/include/peripherals/timer.h
type timer_regs (line 9) | struct timer_regs {
FILE: rpi_bm/part10/src/gpio.c
function gpio_pin_set_func (line 4) | void gpio_pin_set_func(u8 pinNumber, GpioFunc func) {
function gpio_pin_enable (line 15) | void gpio_pin_enable(u8 pinNumber) {
FILE: rpi_bm/part10/src/i2c.c
function i2c_init (line 8) | void i2c_init() {
function i2c_status (line 17) | i2c_status i2c_recv(u8 address, u8 *buffer, u32 size) {
function i2c_status (line 53) | i2c_status i2c_send(u8 address, u8 *buffer, u32 size) {
FILE: rpi_bm/part10/src/irq.c
function show_invalid_entry_message (line 31) | void show_invalid_entry_message(u32 type, u64 esr, u64 address) {
function enable_interrupt_controller (line 36) | void enable_interrupt_controller() {
function handle_irq (line 46) | void handle_irq() {
FILE: rpi_bm/part10/src/kernel.c
function putc (line 8) | void putc(void *p, char c) {
function kernel_main (line 18) | void kernel_main() {
FILE: rpi_bm/part10/src/mini_uart.c
function uart_init (line 9) | void uart_init() {
function uart_send (line 37) | void uart_send(char c) {
function uart_recv (line 43) | char uart_recv() {
function uart_send_string (line 49) | void uart_send_string(char *str) {
FILE: rpi_bm/part10/src/printf.c
function uli2a (line 26) | static void uli2a(unsigned long int num, unsigned int base, int uc,char ...
function li2a (line 44) | static void li2a (long num, char * bf)
function ui2a (line 55) | static void ui2a(unsigned int num, unsigned int base, int uc,char * bf)
function i2a (line 73) | static void i2a (int num, char * bf)
function a2d (line 82) | static int a2d(char ch)
function a2i (line 93) | static char a2i(char ch, char** src,int base,int* nump)
function putchw (line 108) | static void putchw(void* putp,putcf putf,int n, char z, char* bf)
function tfp_format (line 121) | void tfp_format(void* putp,putcf putf,char *fmt, va_list va)
function init_printf (line 200) | void init_printf(void* putp,void (*putf) (void*,char))
function tfp_printf (line 206) | void tfp_printf(char *fmt, ...)
function putcp (line 214) | static void putcp(void* p,char c)
function tfp_sprintf (line 221) | void tfp_sprintf(char* s,char *fmt, ...)
FILE: rpi_bm/part10/src/timer.c
function timer_init (line 12) | void timer_init() {
function handle_timer_1 (line 22) | void handle_timer_1() {
function handle_timer_3 (line 30) | void handle_timer_3() {
function u64 (line 38) | u64 timer_get_ticks() {
function timer_sleep (line 52) | void timer_sleep(u32 ms) {
FILE: rpi_bm/part11/include/common.h
type u8 (line 6) | typedef uint8_t u8;
type u16 (line 7) | typedef uint16_t u16;
type u32 (line 8) | typedef uint32_t u32;
type u64 (line 9) | typedef uint64_t u64;
type u32 (line 11) | typedef volatile u32 reg32;
FILE: rpi_bm/part11/include/gpio.h
type GpioFunc (line 5) | typedef enum _GpioFunc {
FILE: rpi_bm/part11/include/i2c.h
type i2c_status (line 5) | typedef enum _i2c_status {
FILE: rpi_bm/part11/include/peripherals/aux.h
type AuxRegs (line 7) | struct AuxRegs {
FILE: rpi_bm/part11/include/peripherals/gpio.h
type GpioPinData (line 7) | struct GpioPinData {
type GpioRegs (line 12) | struct GpioRegs {
FILE: rpi_bm/part11/include/peripherals/i2c.h
type I2CRegs (line 5) | struct I2CRegs {
FILE: rpi_bm/part11/include/peripherals/irq.h
type vc_irqs (line 7) | enum vc_irqs {
type arm_irq_regs_2711 (line 15) | struct arm_irq_regs_2711 {
type arm_irq_regs_2837 (line 29) | struct arm_irq_regs_2837 {
type arm_irq_regs (line 44) | typedef struct arm_irq_regs_2837 arm_irq_regs;
type arm_irq_regs (line 48) | typedef struct arm_irq_regs_2711 arm_irq_regs;
FILE: rpi_bm/part11/include/peripherals/timer.h
type timer_regs (line 9) | struct timer_regs {
FILE: rpi_bm/part11/src/gpio.c
function gpio_pin_set_func (line 4) | void gpio_pin_set_func(u8 pinNumber, GpioFunc func) {
function gpio_pin_enable (line 15) | void gpio_pin_enable(u8 pinNumber) {
FILE: rpi_bm/part11/src/i2c.c
function i2c_init (line 8) | void i2c_init() {
function i2c_status (line 17) | i2c_status i2c_recv(u8 address, u8 *buffer, u32 size) {
function i2c_status (line 53) | i2c_status i2c_send(u8 address, u8 *buffer, u32 size) {
FILE: rpi_bm/part11/src/irq.c
function show_invalid_entry_message (line 31) | void show_invalid_entry_message(u32 type, u64 esr, u64 address) {
function enable_interrupt_controller (line 36) | void enable_interrupt_controller() {
function handle_irq (line 46) | void handle_irq() {
FILE: rpi_bm/part11/src/kernel.c
function putc (line 8) | void putc(void *p, char c) {
function kernel_main (line 18) | void kernel_main() {
FILE: rpi_bm/part11/src/lcd.c
type Flags (line 18) | enum Flags {
function write_i2c (line 68) | static void write_i2c(u8 data) {
function pulse (line 74) | static void pulse(u8 data) {
function write_4bits (line 82) | static void write_4bits(u8 data) {
function lcd_send (line 87) | void lcd_send(u8 data, u8 mode) {
function lcd_command (line 92) | void lcd_command(u8 command) {
function lcd_init (line 96) | void lcd_init(u8 address) {
function lcd_backlight (line 118) | void lcd_backlight(bool on) {
function lcd_print (line 129) | void lcd_print(char *s) {
FILE: rpi_bm/part11/src/mini_uart.c
function uart_init (line 9) | void uart_init() {
function uart_send (line 37) | void uart_send(char c) {
function uart_recv (line 43) | char uart_recv() {
function uart_send_string (line 49) | void uart_send_string(char *str) {
FILE: rpi_bm/part11/src/printf.c
function uli2a (line 26) | static void uli2a(unsigned long int num, unsigned int base, int uc,char ...
function li2a (line 44) | static void li2a (long num, char * bf)
function ui2a (line 55) | static void ui2a(unsigned int num, unsigned int base, int uc,char * bf)
function i2a (line 73) | static void i2a (int num, char * bf)
function a2d (line 82) | static int a2d(char ch)
function a2i (line 93) | static char a2i(char ch, char** src,int base,int* nump)
function putchw (line 108) | static void putchw(void* putp,putcf putf,int n, char z, char* bf)
function tfp_format (line 121) | void tfp_format(void* putp,putcf putf,char *fmt, va_list va)
function init_printf (line 200) | void init_printf(void* putp,void (*putf) (void*,char))
function tfp_printf (line 206) | void tfp_printf(char *fmt, ...)
function putcp (line 214) | static void putcp(void* p,char c)
function tfp_sprintf (line 221) | void tfp_sprintf(char* s,char *fmt, ...)
FILE: rpi_bm/part11/src/timer.c
function timer_init (line 12) | void timer_init() {
function handle_timer_1 (line 22) | void handle_timer_1() {
function handle_timer_3 (line 30) | void handle_timer_3() {
function u64 (line 38) | u64 timer_get_ticks() {
function timer_sleep (line 52) | void timer_sleep(u32 ms) {
FILE: rpi_bm/part12/include/common.h
type u8 (line 6) | typedef uint8_t u8;
type u16 (line 7) | typedef uint16_t u16;
type u32 (line 8) | typedef uint32_t u32;
type u64 (line 9) | typedef uint64_t u64;
type u32 (line 11) | typedef volatile u32 reg32;
FILE: rpi_bm/part12/include/gpio.h
type GpioFunc (line 5) | typedef enum _GpioFunc {
FILE: rpi_bm/part12/include/i2c.h
type i2c_status (line 5) | typedef enum _i2c_status {
FILE: rpi_bm/part12/include/led_display.h
type led_display_opcodes (line 17) | typedef enum {
FILE: rpi_bm/part12/include/peripherals/aux.h
type AuxRegs (line 7) | struct AuxRegs {
FILE: rpi_bm/part12/include/peripherals/gpio.h
type GpioPinData (line 7) | struct GpioPinData {
type GpioRegs (line 12) | struct GpioRegs {
FILE: rpi_bm/part12/include/peripherals/i2c.h
type I2CRegs (line 5) | struct I2CRegs {
FILE: rpi_bm/part12/include/peripherals/irq.h
type vc_irqs (line 7) | enum vc_irqs {
type arm_irq_regs_2711 (line 15) | struct arm_irq_regs_2711 {
type arm_irq_regs_2837 (line 29) | struct arm_irq_regs_2837 {
type arm_irq_regs (line 44) | typedef struct arm_irq_regs_2837 arm_irq_regs;
type arm_irq_regs (line 48) | typedef struct arm_irq_regs_2711 arm_irq_regs;
FILE: rpi_bm/part12/include/peripherals/spi.h
type Spi0Regs (line 5) | struct Spi0Regs {
FILE: rpi_bm/part12/include/peripherals/timer.h
type timer_regs (line 9) | struct timer_regs {
FILE: rpi_bm/part12/src/gpio.c
function gpio_pin_set_func (line 4) | void gpio_pin_set_func(u8 pinNumber, GpioFunc func) {
function gpio_pin_enable (line 15) | void gpio_pin_enable(u8 pinNumber) {
FILE: rpi_bm/part12/src/i2c.c
function i2c_init (line 8) | void i2c_init() {
function i2c_status (line 17) | i2c_status i2c_recv(u8 address, u8 *buffer, u32 size) {
function i2c_status (line 53) | i2c_status i2c_send(u8 address, u8 *buffer, u32 size) {
FILE: rpi_bm/part12/src/irq.c
function show_invalid_entry_message (line 31) | void show_invalid_entry_message(u32 type, u64 esr, u64 address) {
function enable_interrupt_controller (line 36) | void enable_interrupt_controller() {
function handle_irq (line 46) | void handle_irq() {
FILE: rpi_bm/part12/src/kernel.c
function putc (line 10) | void putc(void *p, char c) {
function kernel_main (line 21) | void kernel_main() {
FILE: rpi_bm/part12/src/lcd.c
type Flags (line 18) | enum Flags {
function write_i2c (line 68) | static void write_i2c(u8 data) {
function pulse (line 74) | static void pulse(u8 data) {
function write_4bits (line 82) | static void write_4bits(u8 data) {
function lcd_send (line 87) | void lcd_send(u8 data, u8 mode) {
function lcd_command (line 92) | void lcd_command(u8 command) {
function lcd_init (line 96) | void lcd_init(u8 address) {
function lcd_backlight (line 118) | void lcd_backlight(bool on) {
function lcd_print (line 129) | void lcd_print(char *s) {
FILE: rpi_bm/part12/src/led_display.c
function led_display_init (line 9) | void led_display_init() {
function led_display_send_command (line 18) | void led_display_send_command(u8 opcode, u8 data) {
function led_display_clear (line 26) | void led_display_clear() {
function led_display_intensity (line 32) | void led_display_intensity(u8 value) {
function led_display_set_digit (line 36) | void led_display_set_digit(u8 digit, u8 value, bool dot) {
FILE: rpi_bm/part12/src/mini_uart.c
function uart_init (line 9) | void uart_init() {
function uart_send (line 37) | void uart_send(char c) {
function uart_recv (line 43) | char uart_recv() {
function uart_send_string (line 49) | void uart_send_string(char *str) {
FILE: rpi_bm/part12/src/printf.c
function uli2a (line 26) | static void uli2a(unsigned long int num, unsigned int base, int uc,char ...
function li2a (line 44) | static void li2a (long num, char * bf)
function ui2a (line 55) | static void ui2a(unsigned int num, unsigned int base, int uc,char * bf)
function i2a (line 73) | static void i2a (int num, char * bf)
function a2d (line 82) | static int a2d(char ch)
function a2i (line 93) | static char a2i(char ch, char** src,int base,int* nump)
function putchw (line 108) | static void putchw(void* putp,putcf putf,int n, char z, char* bf)
function tfp_format (line 121) | void tfp_format(void* putp,putcf putf,char *fmt, va_list va)
function init_printf (line 200) | void init_printf(void* putp,void (*putf) (void*,char))
function tfp_printf (line 206) | void tfp_printf(char *fmt, ...)
function putcp (line 214) | static void putcp(void* p,char c)
function tfp_sprintf (line 221) | void tfp_sprintf(char* s,char *fmt, ...)
FILE: rpi_bm/part12/src/spi.c
function spi_init (line 6) | void spi_init() {
function spi_send_recv (line 19) | void spi_send_recv(u8 chip_select, u8 *sbuffer, u8 *rbuffer, u32 size) {
function spi_send (line 59) | void spi_send(u8 chip_select, u8 *data, u32 size) {
function spi_recv (line 63) | void spi_recv(u8 chip_select, u8 *data, u32 size) {
FILE: rpi_bm/part12/src/timer.c
function timer_init (line 12) | void timer_init() {
function handle_timer_1 (line 22) | void handle_timer_1() {
function handle_timer_3 (line 30) | void handle_timer_3() {
function u64 (line 38) | u64 timer_get_ticks() {
function timer_sleep (line 52) | void timer_sleep(u32 ms) {
FILE: rpi_bm/part13/include/common.h
type u8 (line 6) | typedef uint8_t u8;
type u16 (line 7) | typedef uint16_t u16;
type u32 (line 8) | typedef uint32_t u32;
type u64 (line 9) | typedef uint64_t u64;
type u32 (line 11) | typedef volatile u32 reg32;
FILE: rpi_bm/part13/include/gpio.h
type GpioFunc (line 5) | typedef enum _GpioFunc {
FILE: rpi_bm/part13/include/i2c.h
type i2c_status (line 5) | typedef enum _i2c_status {
FILE: rpi_bm/part13/include/led_display.h
type led_display_opcodes (line 17) | typedef enum {
FILE: rpi_bm/part13/include/mailbox.h
type mailbox_tag (line 5) | typedef struct {
type mailbox_command (line 11) | typedef struct {
type mailbox_generic (line 16) | typedef struct {
type mailbox_power (line 22) | typedef struct {
type mailbox_clock (line 28) | typedef struct {
type clock_type (line 34) | typedef enum {
type rpi_firmware_property_status (line 68) | enum rpi_firmware_property_status {
type rpi_firmware_property_tag (line 74) | enum rpi_firmware_property_tag {
FILE: rpi_bm/part13/include/peripherals/aux.h
type AuxRegs (line 7) | struct AuxRegs {
FILE: rpi_bm/part13/include/peripherals/gpio.h
type GpioPinData (line 7) | struct GpioPinData {
type GpioRegs (line 12) | struct GpioRegs {
FILE: rpi_bm/part13/include/peripherals/i2c.h
type I2CRegs (line 5) | struct I2CRegs {
FILE: rpi_bm/part13/include/peripherals/irq.h
type vc_irqs (line 7) | enum vc_irqs {
type arm_irq_regs_2711 (line 15) | struct arm_irq_regs_2711 {
type arm_irq_regs_2837 (line 29) | struct arm_irq_regs_2837 {
type arm_irq_regs (line 44) | typedef struct arm_irq_regs_2837 arm_irq_regs;
type arm_irq_regs (line 48) | typedef struct arm_irq_regs_2711 arm_irq_regs;
FILE: rpi_bm/part13/include/peripherals/spi.h
type Spi0Regs (line 5) | struct Spi0Regs {
FILE: rpi_bm/part13/include/peripherals/timer.h
type timer_regs (line 9) | struct timer_regs {
FILE: rpi_bm/part13/src/gpio.c
function gpio_pin_set_func (line 4) | void gpio_pin_set_func(u8 pinNumber, GpioFunc func) {
function gpio_pin_enable (line 15) | void gpio_pin_enable(u8 pinNumber) {
FILE: rpi_bm/part13/src/i2c.c
function i2c_init (line 8) | void i2c_init() {
function i2c_status (line 17) | i2c_status i2c_recv(u8 address, u8 *buffer, u32 size) {
function i2c_status (line 53) | i2c_status i2c_send(u8 address, u8 *buffer, u32 size) {
FILE: rpi_bm/part13/src/irq.c
function show_invalid_entry_message (line 31) | void show_invalid_entry_message(u32 type, u64 esr, u64 address) {
function enable_interrupt_controller (line 36) | void enable_interrupt_controller() {
function handle_irq (line 46) | void handle_irq() {
FILE: rpi_bm/part13/src/kernel.c
function putc (line 11) | void putc(void *p, char c) {
function kernel_main (line 22) | void kernel_main() {
FILE: rpi_bm/part13/src/lcd.c
type Flags (line 18) | enum Flags {
function write_i2c (line 68) | static void write_i2c(u8 data) {
function pulse (line 74) | static void pulse(u8 data) {
function write_4bits (line 82) | static void write_4bits(u8 data) {
function lcd_send (line 87) | void lcd_send(u8 data, u8 mode) {
function lcd_command (line 92) | void lcd_command(u8 command) {
function lcd_init (line 96) | void lcd_init(u8 address) {
function lcd_backlight (line 118) | void lcd_backlight(bool on) {
function lcd_print (line 129) | void lcd_print(char *s) {
FILE: rpi_bm/part13/src/led_display.c
function led_display_init (line 9) | void led_display_init() {
function led_display_send_command (line 18) | void led_display_send_command(u8 opcode, u8 data) {
function led_display_clear (line 26) | void led_display_clear() {
function led_display_intensity (line 32) | void led_display_intensity(u8 value) {
function led_display_set_digit (line 36) | void led_display_set_digit(u8 digit, u8 value, bool dot) {
FILE: rpi_bm/part13/src/mailbox.c
type mailbox_regs (line 6) | typedef struct {
function mailbox_regs (line 14) | mailbox_regs *MBX() {
type property_buffer (line 18) | typedef struct {
function mailbox_write (line 39) | static void mailbox_write(u8 channel, u32 data) {
function u32 (line 45) | static u32 mailbox_read(u8 channel) {
function mailbox_process (line 59) | bool mailbox_process(mailbox_tag *tag, u32 tag_size) {
function mailbox_generic_command (line 78) | bool mailbox_generic_command(u32 tag_id, u32 id, u32 *value) {
function u32 (line 96) | u32 mailbox_clock_rate(clock_type ct) {
function mailbox_power_check (line 108) | bool mailbox_power_check(u32 type) {
FILE: rpi_bm/part13/src/mini_uart.c
function uart_init (line 9) | void uart_init() {
function uart_send (line 37) | void uart_send(char c) {
function uart_recv (line 43) | char uart_recv() {
function uart_send_string (line 49) | void uart_send_string(char *str) {
FILE: rpi_bm/part13/src/printf.c
function uli2a (line 26) | static void uli2a(unsigned long int num, unsigned int base, int uc,char ...
function li2a (line 44) | static void li2a (long num, char * bf)
function ui2a (line 55) | static void ui2a(unsigned int num, unsigned int base, int uc,char * bf)
function i2a (line 73) | static void i2a (int num, char * bf)
function a2d (line 82) | static int a2d(char ch)
function a2i (line 93) | static char a2i(char ch, char** src,int base,int* nump)
function putchw (line 108) | static void putchw(void* putp,putcf putf,int n, char z, char* bf)
function tfp_format (line 121) | void tfp_format(void* putp,putcf putf,char *fmt, va_list va)
function init_printf (line 200) | void init_printf(void* putp,void (*putf) (void*,char))
function tfp_printf (line 206) | void tfp_printf(char *fmt, ...)
function putcp (line 214) | static void putcp(void* p,char c)
function tfp_sprintf (line 221) | void tfp_sprintf(char* s,char *fmt, ...)
FILE: rpi_bm/part13/src/spi.c
function spi_init (line 6) | void spi_init() {
function spi_send_recv (line 19) | void spi_send_recv(u8 chip_select, u8 *sbuffer, u8 *rbuffer, u32 size) {
function spi_send (line 59) | void spi_send(u8 chip_select, u8 *data, u32 size) {
function spi_recv (line 63) | void spi_recv(u8 chip_select, u8 *data, u32 size) {
FILE: rpi_bm/part13/src/timer.c
function timer_init (line 12) | void timer_init() {
function handle_timer_1 (line 22) | void handle_timer_1() {
function handle_timer_3 (line 30) | void handle_timer_3() {
function u64 (line 38) | u64 timer_get_ticks() {
function timer_sleep (line 52) | void timer_sleep(u32 ms) {
FILE: rpi_bm/part14/include/common.h
type u8 (line 6) | typedef uint8_t u8;
type u16 (line 7) | typedef uint16_t u16;
type u32 (line 8) | typedef uint32_t u32;
type u64 (line 9) | typedef uint64_t u64;
type u32 (line 11) | typedef volatile u32 reg32;
FILE: rpi_bm/part14/include/gpio.h
type GpioFunc (line 5) | typedef enum _GpioFunc {
FILE: rpi_bm/part14/include/i2c.h
type i2c_status (line 5) | typedef enum _i2c_status {
FILE: rpi_bm/part14/include/led_display.h
type led_display_opcodes (line 17) | typedef enum {
FILE: rpi_bm/part14/include/mailbox.h
type mailbox_tag (line 5) | typedef struct {
type mailbox_command (line 11) | typedef struct {
type mailbox_generic (line 16) | typedef struct {
type mailbox_power (line 22) | typedef struct {
type mailbox_clock (line 28) | typedef struct {
type clock_type (line 34) | typedef enum {
type rpi_firmware_property_status (line 68) | enum rpi_firmware_property_status {
type rpi_firmware_property_tag (line 74) | enum rpi_firmware_property_tag {
FILE: rpi_bm/part14/include/peripherals/aux.h
type AuxRegs (line 7) | struct AuxRegs {
FILE: rpi_bm/part14/include/peripherals/gpio.h
type GpioPinData (line 7) | struct GpioPinData {
type GpioRegs (line 12) | struct GpioRegs {
FILE: rpi_bm/part14/include/peripherals/i2c.h
type I2CRegs (line 5) | struct I2CRegs {
FILE: rpi_bm/part14/include/peripherals/irq.h
type vc_irqs (line 7) | enum vc_irqs {
type arm_irq_regs_2711 (line 15) | struct arm_irq_regs_2711 {
type arm_irq_regs_2837 (line 29) | struct arm_irq_regs_2837 {
type arm_irq_regs (line 44) | typedef struct arm_irq_regs_2837 arm_irq_regs;
type arm_irq_regs (line 48) | typedef struct arm_irq_regs_2711 arm_irq_regs;
FILE: rpi_bm/part14/include/peripherals/spi.h
type Spi0Regs (line 5) | struct Spi0Regs {
FILE: rpi_bm/part14/include/peripherals/timer.h
type timer_regs (line 9) | struct timer_regs {
FILE: rpi_bm/part14/src/fontData.c
function u32 (line 247) | u32 font_get_height() {
function u32 (line 251) | u32 font_get_width() {
function font_get_pixel (line 255) | bool font_get_pixel(char ch, u32 x, u32 y) {
FILE: rpi_bm/part14/src/gpio.c
function gpio_pin_set_func (line 4) | void gpio_pin_set_func(u8 pinNumber, GpioFunc func) {
function gpio_pin_enable (line 15) | void gpio_pin_enable(u8 pinNumber) {
FILE: rpi_bm/part14/src/i2c.c
function i2c_init (line 8) | void i2c_init() {
function i2c_status (line 17) | i2c_status i2c_recv(u8 address, u8 *buffer, u32 size) {
function i2c_status (line 53) | i2c_status i2c_send(u8 address, u8 *buffer, u32 size) {
FILE: rpi_bm/part14/src/irq.c
function show_invalid_entry_message (line 31) | void show_invalid_entry_message(u32 type, u64 esr, u64 address) {
function enable_interrupt_controller (line 36) | void enable_interrupt_controller() {
function handle_irq (line 46) | void handle_irq() {
FILE: rpi_bm/part14/src/kernel.c
function putc (line 12) | void putc(void *p, char c) {
function kernel_main (line 23) | void kernel_main() {
FILE: rpi_bm/part14/src/lcd.c
type Flags (line 18) | enum Flags {
function write_i2c (line 68) | static void write_i2c(u8 data) {
function pulse (line 74) | static void pulse(u8 data) {
function write_4bits (line 82) | static void write_4bits(u8 data) {
function lcd_send (line 87) | void lcd_send(u8 data, u8 mode) {
function lcd_command (line 92) | void lcd_command(u8 command) {
function lcd_init (line 96) | void lcd_init(u8 address) {
function lcd_backlight (line 118) | void lcd_backlight(bool on) {
function lcd_print (line 129) | void lcd_print(char *s) {
FILE: rpi_bm/part14/src/led_display.c
function led_display_init (line 9) | void led_display_init() {
function led_display_send_command (line 18) | void led_display_send_command(u8 opcode, u8 data) {
function led_display_clear (line 26) | void led_display_clear() {
function led_display_intensity (line 32) | void led_display_intensity(u8 value) {
function led_display_set_digit (line 36) | void led_display_set_digit(u8 digit, u8 value, bool dot) {
FILE: rpi_bm/part14/src/mailbox.c
type mailbox_regs (line 6) | typedef struct {
function mailbox_regs (line 14) | mailbox_regs *MBX() {
type property_buffer (line 18) | typedef struct {
function mailbox_write (line 39) | static void mailbox_write(u8 channel, u32 data) {
function u32 (line 45) | static u32 mailbox_read(u8 channel) {
function mailbox_process (line 59) | bool mailbox_process(mailbox_tag *tag, u32 tag_size) {
function mailbox_generic_command (line 78) | bool mailbox_generic_command(u32 tag_id, u32 id, u32 *value) {
function u32 (line 96) | u32 mailbox_clock_rate(clock_type ct) {
function mailbox_power_check (line 108) | bool mailbox_power_check(u32 type) {
FILE: rpi_bm/part14/src/mini_uart.c
function uart_init (line 9) | void uart_init() {
function uart_send (line 37) | void uart_send(char c) {
function uart_recv (line 43) | char uart_recv() {
function uart_send_string (line 49) | void uart_send_string(char *str) {
FILE: rpi_bm/part14/src/printf.c
function uli2a (line 26) | static void uli2a(unsigned long int num, unsigned int base, int uc,char ...
function li2a (line 44) | static void li2a (long num, char * bf)
function ui2a (line 55) | static void ui2a(unsigned int num, unsigned int base, int uc,char * bf)
function i2a (line 73) | static void i2a (int num, char * bf)
function a2d (line 82) | static int a2d(char ch)
function a2i (line 93) | static char a2i(char ch, char** src,int base,int* nump)
function putchw (line 108) | static void putchw(void* putp,putcf putf,int n, char z, char* bf)
function tfp_format (line 121) | void tfp_format(void* putp,putcf putf,char *fmt, va_list va)
function init_printf (line 200) | void init_printf(void* putp,void (*putf) (void*,char))
function tfp_printf (line 206) | void tfp_printf(char *fmt, ...)
function putcp (line 214) | static void putcp(void* p,char c)
function tfp_sprintf (line 221) | void tfp_sprintf(char* s,char *fmt, ...)
FILE: rpi_bm/part14/src/spi.c
function spi_init (line 6) | void spi_init() {
function spi_send_recv (line 19) | void spi_send_recv(u8 chip_select, u8 *sbuffer, u8 *rbuffer, u32 size) {
function spi_send (line 59) | void spi_send(u8 chip_select, u8 *data, u32 size) {
function spi_recv (line 63) | void spi_recv(u8 chip_select, u8 *data, u32 size) {
FILE: rpi_bm/part14/src/timer.c
function timer_init (line 12) | void timer_init() {
function handle_timer_1 (line 22) | void handle_timer_1() {
function handle_timer_3 (line 30) | void handle_timer_3() {
function u64 (line 38) | u64 timer_get_ticks() {
function timer_sleep (line 52) | void timer_sleep(u32 ms) {
FILE: rpi_bm/part14/src/video.c
type mailbox_fb_size (line 6) | typedef struct {
type mailbox_fb_depth (line 12) | typedef struct {
type mailbox_fb_pitch (line 17) | typedef struct {
type mailbox_fb_buffer (line 22) | typedef struct {
type mailbox_fb_request (line 28) | typedef struct {
function video_set_resolution (line 38) | void video_set_resolution(u32 xres, u32 yres, u32 bpp) {
function video_draw_pixel (line 114) | void video_draw_pixel(u32 x, u32 y, u32 color) {
function video_draw_char (line 138) | void video_draw_char(char c, u32 pos_x, u32 pos_y) {
function video_draw_string (line 147) | void video_draw_string(char *s, u32 pos_x, u32 pos_y) {
FILE: rpi_bm/part15/include/common.h
type u8 (line 6) | typedef uint8_t u8;
type u16 (line 7) | typedef uint16_t u16;
type u32 (line 8) | typedef uint32_t u32;
type u64 (line 9) | typedef uint64_t u64;
type u32 (line 11) | typedef volatile u32 reg32;
FILE: rpi_bm/part15/include/dma.h
type dma_channel (line 5) | typedef struct {
type dma_channel_type (line 11) | typedef enum {
FILE: rpi_bm/part15/include/gpio.h
type GpioFunc (line 5) | typedef enum _GpioFunc {
FILE: rpi_bm/part15/include/i2c.h
type i2c_status (line 5) | typedef enum _i2c_status {
FILE: rpi_bm/part15/include/led_display.h
type led_display_opcodes (line 17) | typedef enum {
FILE: rpi_bm/part15/include/mailbox.h
type mailbox_tag (line 5) | typedef struct {
type mailbox_command (line 11) | typedef struct {
type mailbox_generic (line 16) | typedef struct {
type mailbox_power (line 22) | typedef struct {
type mailbox_clock (line 28) | typedef struct {
type clock_type (line 34) | typedef enum {
type rpi_firmware_property_status (line 68) | enum rpi_firmware_property_status {
type rpi_firmware_property_tag (line 74) | enum rpi_firmware_property_tag {
FILE: rpi_bm/part15/include/peripherals/aux.h
type AuxRegs (line 7) | struct AuxRegs {
FILE: rpi_bm/part15/include/peripherals/dma.h
type dma_control_block (line 7) | typedef struct {
type dma_channel_regs (line 17) | typedef struct {
FILE: rpi_bm/part15/include/peripherals/gpio.h
type GpioPinData (line 7) | struct GpioPinData {
type GpioRegs (line 12) | struct GpioRegs {
FILE: rpi_bm/part15/include/peripherals/i2c.h
type I2CRegs (line 5) | struct I2CRegs {
FILE: rpi_bm/part15/include/peripherals/irq.h
type vc_irqs (line 7) | enum vc_irqs {
type arm_irq_regs_2711 (line 15) | struct arm_irq_regs_2711 {
type arm_irq_regs_2837 (line 29) | struct arm_irq_regs_2837 {
type arm_irq_regs (line 44) | typedef struct arm_irq_regs_2837 arm_irq_regs;
type arm_irq_regs (line 48) | typedef struct arm_irq_regs_2711 arm_irq_regs;
FILE: rpi_bm/part15/include/peripherals/spi.h
type Spi0Regs (line 5) | struct Spi0Regs {
FILE: rpi_bm/part15/include/peripherals/timer.h
type timer_regs (line 9) | struct timer_regs {
FILE: rpi_bm/part15/src/dma.c
function u16 (line 11) | static u16 allocate_channel(u32 channel) {
function dma_channel (line 33) | dma_channel *dma_open_channel(u32 channel) {
function dma_close_channel (line 58) | void dma_close_channel(dma_channel *channel) {
function dma_setup_mem_copy (line 62) | void dma_setup_mem_copy(dma_channel *channel, void *dest, void *src, u32...
function dma_start (line 76) | void dma_start(dma_channel *channel) {
function dma_wait (line 85) | bool dma_wait(dma_channel *channel) {
FILE: rpi_bm/part15/src/fontData.c
function u32 (line 247) | u32 font_get_height() {
function u32 (line 251) | u32 font_get_width() {
function font_get_pixel (line 255) | bool font_get_pixel(char ch, u32 x, u32 y) {
FILE: rpi_bm/part15/src/gpio.c
function gpio_pin_set_func (line 4) | void gpio_pin_set_func(u8 pinNumber, GpioFunc func) {
function gpio_pin_enable (line 15) | void gpio_pin_enable(u8 pinNumber) {
FILE: rpi_bm/part15/src/i2c.c
function i2c_init (line 8) | void i2c_init() {
function i2c_status (line 17) | i2c_status i2c_recv(u8 address, u8 *buffer, u32 size) {
function i2c_status (line 53) | i2c_status i2c_send(u8 address, u8 *buffer, u32 size) {
FILE: rpi_bm/part15/src/irq.c
function show_invalid_entry_message (line 31) | void show_invalid_entry_message(u32 type, u64 esr, u64 address) {
function enable_interrupt_controller (line 36) | void enable_interrupt_controller() {
function handle_irq (line 46) | void handle_irq() {
FILE: rpi_bm/part15/src/kernel.c
function putc (line 12) | void putc(void *p, char c) {
function kernel_main (line 23) | void kernel_main() {
FILE: rpi_bm/part15/src/lcd.c
type Flags (line 18) | enum Flags {
function write_i2c (line 68) | static void write_i2c(u8 data) {
function pulse (line 74) | static void pulse(u8 data) {
function write_4bits (line 82) | static void write_4bits(u8 data) {
function lcd_send (line 87) | void lcd_send(u8 data, u8 mode) {
function lcd_command (line 92) | void lcd_command(u8 command) {
function lcd_init (line 96) | void lcd_init(u8 address) {
function lcd_backlight (line 118) | void lcd_backlight(bool on) {
function lcd_print (line 129) | void lcd_print(char *s) {
FILE: rpi_bm/part15/src/led_display.c
function led_display_init (line 9) | void led_display_init() {
function led_display_send_command (line 18) | void led_display_send_command(u8 opcode, u8 data) {
function led_display_clear (line 26) | void led_display_clear() {
function led_display_intensity (line 32) | void led_display_intensity(u8 value) {
function led_display_set_digit (line 36) | void led_display_set_digit(u8 digit, u8 value, bool dot) {
FILE: rpi_bm/part15/src/mailbox.c
type mailbox_regs (line 6) | typedef struct {
function mailbox_regs (line 14) | mailbox_regs *MBX() {
type property_buffer (line 18) | typedef struct {
function mailbox_write (line 39) | static void mailbox_write(u8 channel, u32 data) {
function u32 (line 45) | static u32 mailbox_read(u8 channel) {
function mailbox_process (line 59) | bool mailbox_process(mailbox_tag *tag, u32 tag_size) {
function mailbox_generic_command (line 78) | bool mailbox_generic_command(u32 tag_id, u32 id, u32 *value) {
function u32 (line 96) | u32 mailbox_clock_rate(clock_type ct) {
function mailbox_power_check (line 108) | bool mailbox_power_check(u32 type) {
FILE: rpi_bm/part15/src/mini_uart.c
function uart_init (line 9) | void uart_init() {
function uart_send (line 37) | void uart_send(char c) {
function uart_recv (line 43) | char uart_recv() {
function uart_send_string (line 49) | void uart_send_string(char *str) {
FILE: rpi_bm/part15/src/printf.c
function uli2a (line 26) | static void uli2a(unsigned long int num, unsigned int base, int uc,char ...
function li2a (line 44) | static void li2a (long num, char * bf)
function ui2a (line 55) | static void ui2a(unsigned int num, unsigned int base, int uc,char * bf)
function i2a (line 73) | static void i2a (int num, char * bf)
function a2d (line 82) | static int a2d(char ch)
function a2i (line 93) | static char a2i(char ch, char** src,int base,int* nump)
function putchw (line 108) | static void putchw(void* putp,putcf putf,int n, char z, char* bf)
function tfp_format (line 121) | void tfp_format(void* putp,putcf putf,char *fmt, va_list va)
function init_printf (line 200) | void init_printf(void* putp,void (*putf) (void*,char))
function tfp_printf (line 206) | void tfp_printf(char *fmt, ...)
function putcp (line 214) | static void putcp(void* p,char c)
function tfp_sprintf (line 221) | void tfp_sprintf(char* s,char *fmt, ...)
FILE: rpi_bm/part15/src/spi.c
function spi_init (line 6) | void spi_init() {
function spi_send_recv (line 19) | void spi_send_recv(u8 chip_select, u8 *sbuffer, u8 *rbuffer, u32 size) {
function spi_send (line 59) | void spi_send(u8 chip_select, u8 *data, u32 size) {
function spi_recv (line 63) | void spi_recv(u8 chip_select, u8 *data, u32 size) {
FILE: rpi_bm/part15/src/timer.c
function timer_init (line 12) | void timer_init() {
function handle_timer_1 (line 22) | void handle_timer_1() {
function handle_timer_3 (line 30) | void handle_timer_3() {
function u64 (line 38) | u64 timer_get_ticks() {
function timer_sleep (line 52) | void timer_sleep(u32 ms) {
FILE: rpi_bm/part15/src/video.c
type mailbox_fb_size (line 8) | typedef struct {
type mailbox_fb_depth (line 14) | typedef struct {
type mailbox_fb_pitch (line 19) | typedef struct {
type mailbox_fb_buffer (line 24) | typedef struct {
type mailbox_fb_request (line 30) | typedef struct {
function video_init (line 56) | void video_init() {
function video_set_dma (line 83) | void video_set_dma(bool b) {
function do_dma (line 87) | void do_dma(void *dest, void *src, u32 total) {
function video_dma (line 116) | void video_dma() {
type mailbox_set_palette (line 120) | typedef struct {
function video_set_resolution (line 127) | void video_set_resolution(u32 xres, u32 yres, u32 bpp) {
function video_draw_pixel (line 248) | void video_draw_pixel(u32 x, u32 y, u32 color) {
function video_draw_char (line 264) | void video_draw_char(char c, u32 pos_x, u32 pos_y) {
function video_draw_string (line 281) | void video_draw_string(char *s, u32 pos_x, u32 pos_y) {
FILE: rpi_bm/part16/include/common.h
type u8 (line 6) | typedef uint8_t u8;
type u16 (line 7) | typedef uint16_t u16;
type u32 (line 8) | typedef uint32_t u32;
type u64 (line 9) | typedef uint64_t u64;
type u32 (line 11) | typedef volatile u32 reg32;
FILE: rpi_bm/part16/include/dma.h
type dma_channel (line 5) | typedef struct {
type dma_channel_type (line 11) | typedef enum {
FILE: rpi_bm/part16/include/gpio.h
type GpioFunc (line 5) | typedef enum _GpioFunc {
FILE: rpi_bm/part16/include/i2c.h
type i2c_status (line 5) | typedef enum _i2c_status {
FILE: rpi_bm/part16/include/led_display.h
type led_display_opcodes (line 17) | typedef enum {
FILE: rpi_bm/part16/include/mailbox.h
type mailbox_tag (line 5) | typedef struct {
type mailbox_command (line 11) | typedef struct {
type mailbox_generic (line 16) | typedef struct {
type mailbox_power (line 22) | typedef struct {
type mailbox_clock (line 28) | typedef struct {
type clock_type (line 34) | typedef enum {
type rpi_firmware_property_status (line 68) | enum rpi_firmware_property_status {
type rpi_firmware_property_tag (line 74) | enum rpi_firmware_property_tag {
FILE: rpi_bm/part16/include/peripherals/aux.h
type AuxRegs (line 7) | struct AuxRegs {
FILE: rpi_bm/part16/include/peripherals/dma.h
type dma_control_block (line 7) | typedef struct {
type dma_channel_regs (line 17) | typedef struct {
FILE: rpi_bm/part16/include/peripherals/gpio.h
type GpioPinData (line 7) | struct GpioPinData {
type GpioRegs (line 12) | struct GpioRegs {
FILE: rpi_bm/part16/include/peripherals/i2c.h
type I2CRegs (line 5) | struct I2CRegs {
FILE: rpi_bm/part16/include/peripherals/irq.h
type vc_irqs (line 7) | enum vc_irqs {
type arm_irq_regs_2711 (line 15) | struct arm_irq_regs_2711 {
type arm_irq_regs_2837 (line 29) | struct arm_irq_regs_2837 {
type arm_irq_regs (line 44) | typedef struct arm_irq_regs_2837 arm_irq_regs;
type arm_irq_regs (line 48) | typedef struct arm_irq_regs_2711 arm_irq_regs;
FILE: rpi_bm/part16/include/peripherals/spi.h
type Spi0Regs (line 5) | struct Spi0Regs {
FILE: rpi_bm/part16/include/peripherals/timer.h
type timer_regs (line 9) | struct timer_regs {
FILE: rpi_bm/part16/src/dma.c
function u16 (line 11) | static u16 allocate_channel(u32 channel) {
function dma_channel (line 33) | dma_channel *dma_open_channel(u32 channel) {
function dma_close_channel (line 58) | void dma_close_channel(dma_channel *channel) {
function dma_setup_mem_copy (line 62) | void dma_setup_mem_copy(dma_channel *channel, void *dest, void *src, u32...
function dma_start (line 76) | void dma_start(dma_channel *channel) {
function dma_wait (line 85) | bool dma_wait(dma_channel *channel) {
FILE: rpi_bm/part16/src/fontData.c
function u32 (line 247) | u32 font_get_height() {
function u32 (line 251) | u32 font_get_width() {
function font_get_pixel (line 255) | bool font_get_pixel(char ch, u32 x, u32 y) {
FILE: rpi_bm/part16/src/gpio.c
function gpio_pin_set_func (line 4) | void gpio_pin_set_func(u8 pinNumber, GpioFunc func) {
function gpio_pin_enable (line 15) | void gpio_pin_enable(u8 pinNumber) {
FILE: rpi_bm/part16/src/i2c.c
function i2c_init (line 8) | void i2c_init() {
function i2c_status (line 17) | i2c_status i2c_recv(u8 address, u8 *buffer, u32 size) {
function i2c_status (line 53) | i2c_status i2c_send(u8 address, u8 *buffer, u32 size) {
FILE: rpi_bm/part16/src/irq.c
function show_invalid_entry_message (line 31) | void show_invalid_entry_message(u32 type, u64 esr, u64 address) {
function enable_interrupt_controller (line 36) | void enable_interrupt_controller() {
function handle_irq (line 46) | void handle_irq() {
FILE: rpi_bm/part16/src/kernel.c
function putc (line 12) | void putc(void *p, char c) {
type align_check1 (line 22) | struct align_check1 {
type align_check2 (line 30) | struct align_check2 {
function kernel_main (line 39) | void kernel_main() {
FILE: rpi_bm/part16/src/lcd.c
type Flags (line 18) | enum Flags {
function write_i2c (line 68) | static void write_i2c(u8 data) {
function pulse (line 74) | static void pulse(u8 data) {
function write_4bits (line 82) | static void write_4bits(u8 data) {
function lcd_send (line 87) | void lcd_send(u8 data, u8 mode) {
function lcd_command (line 92) | void lcd_command(u8 command) {
function lcd_init (line 96) | void lcd_init(u8 address) {
function lcd_backlight (line 118) | void lcd_backlight(bool on) {
function lcd_print (line 129) | void lcd_print(char *s) {
FILE: rpi_bm/part16/src/led_display.c
function led_display_init (line 9) | void led_display_init() {
function led_display_send_command (line 18) | void led_display_send_command(u8 opcode, u8 data) {
function led_display_clear (line 26) | void led_display_clear() {
function led_display_intensity (line 32) | void led_display_intensity(u8 value) {
function led_display_set_digit (line 36) | void led_display_set_digit(u8 digit, u8 value, bool dot) {
FILE: rpi_bm/part16/src/mailbox.c
type mailbox_regs (line 6) | typedef struct {
function mailbox_regs (line 14) | mailbox_regs *MBX() {
type property_buffer (line 18) | typedef struct {
function mailbox_write (line 39) | static void mailbox_write(u8 channel, u32 data) {
function u32 (line 45) | static u32 mailbox_read(u8 channel) {
function mailbox_process (line 59) | bool mailbox_process(mailbox_tag *tag, u32 tag_size) {
function mailbox_generic_command (line 78) | bool mailbox_generic_command(u32 tag_id, u32 id, u32 *value) {
function u32 (line 96) | u32 mailbox_clock_rate(clock_type ct) {
function mailbox_power_check (line 108) | bool mailbox_power_check(u32 type) {
FILE: rpi_bm/part16/src/mem.c
function free_memory (line 19) | void free_memory(void *base) {
function create_table_entry (line 101) | void create_table_entry(u64 tbl, u64 next_tbl, u64 va, u64 shift, u64 fl...
function create_block_map (line 108) | void create_block_map(u64 pmd, u64 vstart, u64 vend, u64 pa) {
function init_mmu (line 136) | void init_mmu() {
FILE: rpi_bm/part16/src/mini_uart.c
function uart_init (line 9) | void uart_init() {
function uart_send (line 37) | void uart_send(char c) {
function uart_recv (line 43) | char uart_recv() {
function uart_send_string (line 49) | void uart_send_string(char *str) {
FILE: rpi_bm/part16/src/printf.c
function uli2a (line 26) | static void uli2a(unsigned long int num, unsigned int base, int uc,char ...
function li2a (line 44) | static void li2a (long num, char * bf)
function ui2a (line 55) | static void ui2a(unsigned int num, unsigned int base, int uc,char * bf)
function i2a (line 73) | static void i2a (int num, char * bf)
function a2d (line 82) | static int a2d(char ch)
function a2i (line 93) | static char a2i(char ch, char** src,int base,int* nump)
function putchw (line 108) | static void putchw(void* putp,putcf putf,int n, char z, char* bf)
function tfp_format (line 121) | void tfp_format(void* putp,putcf putf,char *fmt, va_list va)
function init_printf (line 200) | void init_printf(void* putp,void (*putf) (void*,char))
function tfp_printf (line 206) | void tfp_printf(char *fmt, ...)
function putcp (line 214) | static void putcp(void* p,char c)
function tfp_sprintf (line 221) | void tfp_sprintf(char* s,char *fmt, ...)
FILE: rpi_bm/part16/src/spi.c
function spi_init (line 6) | void spi_init() {
function spi_send_recv (line 19) | void spi_send_recv(u8 chip_select, u8 *sbuffer, u8 *rbuffer, u32 size) {
function spi_send (line 59) | void spi_send(u8 chip_select, u8 *data, u32 size) {
function spi_recv (line 63) | void spi_recv(u8 chip_select, u8 *data, u32 size) {
FILE: rpi_bm/part16/src/timer.c
function timer_init (line 12) | void timer_init() {
function handle_timer_1 (line 22) | void handle_timer_1() {
function handle_timer_3 (line 30) | void handle_timer_3() {
function u64 (line 38) | u64 timer_get_ticks() {
function timer_sleep (line 52) | void timer_sleep(u32 ms) {
FILE: rpi_bm/part16/src/video.c
type mailbox_fb_size (line 8) | typedef struct {
type mailbox_fb_depth (line 14) | typedef struct {
type mailbox_fb_pitch (line 19) | typedef struct {
type mailbox_fb_buffer (line 24) | typedef struct {
type mailbox_fb_request (line 30) | typedef struct {
function video_init (line 56) | void video_init() {
function video_set_dma (line 83) | void video_set_dma(bool b) {
function do_dma (line 87) | void do_dma(void *dest, void *src, u32 total) {
function video_dma (line 116) | void video_dma() {
type mailbox_set_palette (line 120) | typedef struct {
function video_set_resolution (line 127) | void video_set_resolution(u32 xres, u32 yres, u32 bpp) {
function video_draw_pixel (line 248) | void video_draw_pixel(u32 x, u32 y, u32 color) {
function video_draw_char (line 264) | void video_draw_char(char c, u32 pos_x, u32 pos_y) {
function video_draw_string (line 281) | void video_draw_string(char *s, u32 pos_x, u32 pos_y) {
FILE: rpi_bm/part17/include/common.h
type u8 (line 6) | typedef uint8_t u8;
type u16 (line 7) | typedef uint16_t u16;
type u32 (line 8) | typedef uint32_t u32;
type u64 (line 9) | typedef uint64_t u64;
type u32 (line 11) | typedef volatile u32 reg32;
FILE: rpi_bm/part17/include/dma.h
type dma_channel (line 5) | typedef struct {
type dma_channel_type (line 11) | typedef enum {
FILE: rpi_bm/part17/include/gpio.h
type GpioFunc (line 5) | typedef enum _GpioFunc {
FILE: rpi_bm/part17/include/i2c.h
type i2c_status (line 5) | typedef enum _i2c_status {
FILE: rpi_bm/part17/include/io.h
type io_device (line 5) | typedef struct _io_device {
FILE: rpi_bm/part17/include/led_display.h
type led_display_opcodes (line 17) | typedef enum {
FILE: rpi_bm/part17/include/mailbox.h
type mailbox_tag (line 5) | typedef struct {
type mailbox_command (line 11) | typedef struct {
type mailbox_generic (line 16) | typedef struct {
type mailbox_power (line 22) | typedef struct {
type mailbox_clock (line 28) | typedef struct {
type clock_type (line 34) | typedef enum {
type rpi_firmware_property_status (line 68) | enum rpi_firmware_property_status {
type rpi_firmware_property_tag (line 74) | enum rpi_firmware_property_tag {
FILE: rpi_bm/part17/include/peripherals/aux.h
type AuxRegs (line 7) | struct AuxRegs {
FILE: rpi_bm/part17/include/peripherals/dma.h
type dma_control_block (line 7) | typedef struct {
type dma_channel_regs (line 17) | typedef struct {
FILE: rpi_bm/part17/include/peripherals/emmc.h
type emmc_cmd (line 15) | typedef struct {
type cmd_resp_type (line 34) | typedef enum {
type cmd_type (line 41) | typedef enum {
type scr_register (line 58) | typedef struct {
type sd_error (line 64) | typedef enum {
type emmc_device (line 79) | typedef struct {
type emmc_regs (line 97) | typedef struct {
FILE: rpi_bm/part17/include/peripherals/gpio.h
type GpioPinData (line 7) | struct GpioPinData {
type GpioRegs (line 12) | struct GpioRegs {
FILE: rpi_bm/part17/include/peripherals/i2c.h
type I2CRegs (line 5) | struct I2CRegs {
FILE: rpi_bm/part17/include/peripherals/irq.h
type vc_irqs (line 7) | enum vc_irqs {
type arm_irq_regs_2711 (line 15) | struct arm_irq_regs_2711 {
type arm_irq_regs_2837 (line 29) | struct arm_irq_regs_2837 {
type arm_irq_regs (line 44) | typedef struct arm_irq_regs_2837 arm_irq_regs;
type arm_irq_regs (line 48) | typedef struct arm_irq_regs_2711 arm_irq_regs;
FILE: rpi_bm/part17/include/peripherals/spi.h
type Spi0Regs (line 5) | struct Spi0Regs {
FILE: rpi_bm/part17/include/peripherals/timer.h
type timer_regs (line 9) | struct timer_regs {
FILE: rpi_bm/part17/src/dma/dma.c
function u16 (line 11) | static u16 allocate_channel(u32 channel) {
function dma_channel (line 33) | dma_channel *dma_open_channel(u32 channel) {
function dma_close_channel (line 57) | void dma_close_channel(dma_channel *channel) {
function dma_setup_mem_copy (line 61) | void dma_setup_mem_copy(dma_channel *channel, void *dest, void *src, u32...
function dma_start (line 75) | void dma_start(dma_channel *channel) {
function dma_wait (line 84) | bool dma_wait(dma_channel *channel) {
FILE: rpi_bm/part17/src/drivers/emmc/emmc.c
function wait_reg_mask (line 18) | bool wait_reg_mask(reg32 *reg, u32 mask, bool set, u32 timeout) {
function u32 (line 89) | static u32 sd_error_mask(sd_error err) {
function set_last_error (line 93) | static void set_last_error(u32 intr_val) {
function do_data_transfer (line 98) | static bool do_data_transfer(emmc_cmd cmd) {
function emmc_issue_command (line 138) | static bool emmc_issue_command(emmc_cmd cmd, u32 arg, u32 timeout) {
function emmc_command (line 226) | static bool emmc_command(u32 command, u32 arg, u32 timeout) {
function reset_command (line 243) | static bool reset_command() {
function emmc_app_command (line 259) | bool emmc_app_command(u32 command, u32 arg, u32 timeout) {
function check_v2_card (line 283) | static bool check_v2_card() {
function check_usable_card (line 314) | static bool check_usable_card() {
function check_sdhc_support (line 336) | static bool check_sdhc_support(bool v2_card) {
function check_ocr (line 364) | static bool check_ocr() {
function check_rca (line 394) | static bool check_rca() {
function select_card (line 429) | static bool select_card() {
function set_scr (line 449) | static bool set_scr() {
function emmc_card_reset (line 504) | static bool emmc_card_reset() {
function emmc_io_read (line 581) | int emmc_io_read(io_device *dev, void *b, u32 size) {
function emmc_io_seek (line 585) | void emmc_io_seek(io_device *dev, u64 offset) {
function do_data_command (line 589) | bool do_data_command(bool write, u8 *b, u32 bsize, u32 block_no) {
function do_read (line 639) | int do_read(u8 *b, u32 bsize, u32 block_no) {
function emmc_read (line 651) | int emmc_read(u8 *buffer, u32 size) {
function emmc_seek (line 669) | void emmc_seek(u64 _offset) {
function emmc_init (line 680) | bool emmc_init() {
FILE: rpi_bm/part17/src/drivers/emmc/emmc_clock.c
function u32 (line 7) | u32 get_clock_divider(u32 base_clock, u32 target_rate) {
function switch_clock_rate (line 57) | bool switch_clock_rate(u32 base_clock, u32 target_rate) {
function emmc_setup_clock (line 81) | bool emmc_setup_clock() {
FILE: rpi_bm/part17/src/drivers/gpio/gpio.c
function gpio_pin_set_func (line 4) | void gpio_pin_set_func(u8 pinNumber, GpioFunc func) {
function gpio_pin_enable (line 15) | void gpio_pin_enable(u8 pinNumber) {
FILE: rpi_bm/part17/src/drivers/i2c/i2c.c
function i2c_init (line 8) | void i2c_init() {
function i2c_status (line 17) | i2c_status i2c_recv(u8 address, u8 *buffer, u32 size) {
function i2c_status (line 53) | i2c_status i2c_send(u8 address, u8 *buffer, u32 size) {
FILE: rpi_bm/part17/src/drivers/i2c/lcd.c
type Flags (line 18) | enum Flags {
function write_i2c (line 68) | static void write_i2c(u8 data) {
function pulse (line 74) | static void pulse(u8 data) {
function write_4bits (line 82) | static void write_4bits(u8 data) {
function lcd_send (line 87) | void lcd_send(u8 data, u8 mode) {
function lcd_command (line 92) | void lcd_command(u8 command) {
function lcd_init (line 96) | void lcd_init(u8 address) {
function lcd_backlight (line 118) | void lcd_backlight(bool on) {
function lcd_print (line 129) | void lcd_print(char *s) {
FILE: rpi_bm/part17/src/drivers/mailbox/mailbox.c
type mailbox_regs (line 6) | typedef struct {
function mailbox_regs (line 14) | mailbox_regs *MBX() {
type property_buffer (line 18) | typedef struct {
function mailbox_write (line 39) | static void mailbox_write(u8 channel, u32 data) {
function u32 (line 45) | static u32 mailbox_read(u8 channel) {
function mailbox_process (line 59) | bool mailbox_process(mailbox_tag *tag, u32 tag_size) {
function mailbox_generic_command (line 78) | bool mailbox_generic_command(u32 tag_id, u32 id, u32 *value) {
function u32 (line 96) | u32 mailbox_clock_rate(clock_type ct) {
function mailbox_power_check (line 108) | bool mailbox_power_check(u32 type) {
FILE: rpi_bm/part17/src/drivers/muart/mini_uart.c
function uart_send (line 10) | void uart_send(char c) {
function uart_recv (line 16) | char uart_recv() {
function uart_send_string (line 22) | void uart_send_string(char *str) {
function muart_read (line 33) | int muart_read(struct _io_device *d, void *buff, u32 size) {
function muart_write (line 43) | int muart_write(struct _io_device *d, void *buff, u32 size) {
function uart_init (line 62) | void uart_init() {
FILE: rpi_bm/part17/src/drivers/shared/io.c
function io_device_register (line 7) | bool io_device_register(io_device *dev) {
function io_device (line 18) | io_device *io_device_find(char *name) {
FILE: rpi_bm/part17/src/drivers/spi/led_display.c
function led_display_init (line 9) | void led_display_init() {
function led_display_send_command (line 18) | void led_display_send_command(u8 opcode, u8 data) {
function led_display_clear (line 26) | void led_display_clear() {
function led_display_intensity (line 32) | void led_display_intensity(u8 value) {
function led_display_set_digit (line 36) | void led_display_set_digit(u8 digit, u8 value, bool dot) {
FILE: rpi_bm/part17/src/drivers/spi/spi.c
function spi_init (line 6) | void spi_init() {
function spi_send_recv (line 19) | void spi_send_recv(u8 chip_select, u8 *sbuffer, u8 *rbuffer, u32 size) {
function spi_send (line 59) | void spi_send(u8 chip_select, u8 *data, u32 size) {
function spi_recv (line 63) | void spi_recv(u8 chip_select, u8 *data, u32 size) {
FILE: rpi_bm/part17/src/drivers/video/fontData.c
function u32 (line 247) | u32 font_get_height() {
function u32 (line 251) | u32 font_get_width() {
function font_get_pixel (line 255) | bool font_get_pixel(char ch, u32 x, u32 y) {
FILE: rpi_bm/part17/src/drivers/video/video.c
type mailbox_fb_size (line 9) | typedef struct {
type mailbox_fb_depth (line 15) | typedef struct {
type mailbox_fb_pitch (line 20) | typedef struct {
type mailbox_fb_buffer (line 25) | typedef struct {
type mailbox_fb_request (line 31) | typedef struct {
function video_init (line 52) | void video_init() {
function video_set_dma (line 79) | void video_set_dma(bool b) {
function do_dma (line 83) | void do_dma(void *dest, void *src, u32 total) {
function video_dma (line 112) | void video_dma() {
type mailbox_set_palette (line 116) | typedef struct {
function video_set_resolution (line 123) | void video_set_resolution(u32 xres, u32 yres, u32 bpp) {
function video_draw_pixel (line 244) | void video_draw_pixel(u32 x, u32 y, u32 color) {
function video_draw_char (line 260) | void video_draw_char(char c, u32 pos_x, u32 pos_y) {
function video_draw_string (line 277) | void video_draw_string(char *s, u32 pos_x, u32 pos_y) {
FILE: rpi_bm/part17/src/kernel/irq.c
function show_invalid_entry_message (line 31) | void show_invalid_entry_message(u32 type, u64 esr, u64 address) {
function enable_interrupt_controller (line 36) | void enable_interrupt_controller() {
function handle_irq (line 46) | void handle_irq() {
FILE: rpi_bm/part17/src/kernel/kernel.c
function putc (line 14) | void putc(void *p, char c) {
type chs_address (line 27) | typedef struct PACKED {
type partition_entry (line 34) | typedef struct PACKED {
type master_boot_record (line 43) | typedef struct PACKED {
function kernel_main (line 50) | void kernel_main() {
FILE: rpi_bm/part17/src/kernel/timer.c
function timer_init (line 12) | void timer_init() {
function handle_timer_1 (line 22) | void handle_timer_1() {
function handle_timer_3 (line 28) | void handle_timer_3() {
function u64 (line 34) | u64 timer_get_ticks() {
function timer_sleep (line 48) | void timer_sleep(u32 ms) {
FILE: rpi_bm/part17/src/mem/mem.c
function free_memory (line 19) | void free_memory(void *base) {
function create_table_entry (line 101) | void create_table_entry(u64 tbl, u64 next_tbl, u64 va, u64 shift, u64 fl...
function create_block_map (line 108) | void create_block_map(u64 pmd, u64 vstart, u64 vend, u64 pa) {
function init_mmu (line 136) | void init_mmu() {
FILE: rpi_bm/part17/src/misc/printf.c
function stdout_putf (line 26) | static void stdout_putf(void *p, char c) {
function uli2a (line 32) | static void uli2a(unsigned long int num, unsigned int base, int uc,char ...
function li2a (line 50) | static void li2a (long num, char * bf)
function ui2a (line 61) | static void ui2a(unsigned int num, unsigned int base, int uc,char * bf)
function i2a (line 79) | static void i2a (int num, char * bf)
function a2d (line 88) | static int a2d(char ch)
function a2i (line 99) | static char a2i(char ch, char** src,int base,int* nump)
function putchw (line 114) | static void putchw(void* putp,putcf putf,int n, char z, char* bf)
function tfp_format (line 127) | void tfp_format(void* putp,putcf putf,char *fmt, va_list va)
function init_printf (line 206) | void init_printf(void* putp, io_device *dev) {
function tfp_printf (line 213) | void tfp_printf(char *fmt, ...)
function putcp (line 221) | static void putcp(void* p,char c)
function tfp_sprintf (line 228) | void tfp_sprintf(char* s,char *fmt, ...)
FILE: rpi_bm/part17/src/misc/utils.c
function str_eq (line 4) | bool str_eq(char *a, char *b) {
function strcat (line 14) | int strcat(char *dst, char *src) {
function strcpy (line 19) | int strcpy(char *dst, char *src) {
function strlen (line 32) | int strlen(char *s) {
FILE: rpi_bm/part6-7/include/common.h
type u8 (line 5) | typedef uint8_t u8;
type u16 (line 6) | typedef uint16_t u16;
type u32 (line 7) | typedef uint32_t u32;
type u64 (line 8) | typedef uint64_t u64;
type u32 (line 10) | typedef volatile u32 reg32;
FILE: rpi_bm/part6-7/include/gpio.h
type GpioFunc (line 5) | typedef enum _GpioFunc {
FILE: rpi_bm/part6-7/include/peripherals/aux.h
type AuxRegs (line 7) | struct AuxRegs {
FILE: rpi_bm/part6-7/include/peripherals/gpio.h
type GpioPinData (line 7) | struct GpioPinData {
type GpioRegs (line 12) | struct GpioRegs {
FILE: rpi_bm/part6-7/src/gpio.c
function gpio_pin_set_func (line 4) | void gpio_pin_set_func(u8 pinNumber, GpioFunc func) {
function gpio_pin_enable (line 15) | void gpio_pin_enable(u8 pinNumber) {
FILE: rpi_bm/part6-7/src/kernel.c
function putc (line 5) | void putc(void *p, char c) {
function kernel_main (line 15) | void kernel_main() {
FILE: rpi_bm/part6-7/src/mini_uart.c
function uart_init (line 9) | void uart_init() {
function uart_send (line 37) | void uart_send(char c) {
function uart_recv (line 43) | char uart_recv() {
function uart_send_string (line 49) | void uart_send_string(char *str) {
FILE: rpi_bm/part6-7/src/printf.c
function uli2a (line 26) | static void uli2a(unsigned long int num, unsigned int base, int uc,char ...
function li2a (line 44) | static void li2a (long num, char * bf)
function ui2a (line 55) | static void ui2a(unsigned int num, unsigned int base, int uc,char * bf)
function i2a (line 73) | static void i2a (int num, char * bf)
function a2d (line 82) | static int a2d(char ch)
function a2i (line 93) | static char a2i(char ch, char** src,int base,int* nump)
function putchw (line 108) | static void putchw(void* putp,putcf putf,int n, char z, char* bf)
function tfp_format (line 121) | void tfp_format(void* putp,putcf putf,char *fmt, va_list va)
function init_printf (line 200) | void init_printf(void* putp,void (*putf) (void*,char))
function tfp_printf (line 206) | void tfp_printf(char *fmt, ...)
function putcp (line 214) | static void putcp(void* p,char c)
function tfp_sprintf (line 221) | void tfp_sprintf(char* s,char *fmt, ...)
FILE: rpi_bm/part8/include/common.h
type u8 (line 5) | typedef uint8_t u8;
type u16 (line 6) | typedef uint16_t u16;
type u32 (line 7) | typedef uint32_t u32;
type u64 (line 8) | typedef uint64_t u64;
type u32 (line 10) | typedef volatile u32 reg32;
FILE: rpi_bm/part8/include/gpio.h
type GpioFunc (line 5) | typedef enum _GpioFunc {
FILE: rpi_bm/part8/include/peripherals/aux.h
type AuxRegs (line 7) | struct AuxRegs {
FILE: rpi_bm/part8/include/peripherals/gpio.h
type GpioPinData (line 7) | struct GpioPinData {
type GpioRegs (line 12) | struct GpioRegs {
FILE: rpi_bm/part8/include/peripherals/irq.h
type vc_irqs (line 6) | enum vc_irqs {
type arm_irq_regs_2711 (line 10) | struct arm_irq_regs_2711 {
type arm_irq_regs_2837 (line 24) | struct arm_irq_regs_2837 {
type arm_irq_regs (line 39) | typedef struct arm_irq_regs_2837 arm_irq_regs;
type arm_irq_regs (line 43) | typedef struct arm_irq_regs_2711 arm_irq_regs;
FILE: rpi_bm/part8/src/gpio.c
function gpio_pin_set_func (line 4) | void gpio_pin_set_func(u8 pinNumber, GpioFunc func) {
function gpio_pin_enable (line 15) | void gpio_pin_enable(u8 pinNumber) {
FILE: rpi_bm/part8/src/irq.c
function show_invalid_entry_message (line 30) | void show_invalid_entry_message(u32 type, u64 esr, u64 address) {
function enable_interrupt_controller (line 35) | void enable_interrupt_controller() {
function handle_irq (line 45) | void handle_irq() {
FILE: rpi_bm/part8/src/kernel.c
function putc (line 6) | void putc(void *p, char c) {
function kernel_main (line 16) | void kernel_main() {
FILE: rpi_bm/part8/src/mini_uart.c
function uart_init (line 9) | void uart_init() {
function uart_send (line 37) | void uart_send(char c) {
function uart_recv (line 43) | char uart_recv() {
function uart_send_string (line 49) | void uart_send_string(char *str) {
FILE: rpi_bm/part8/src/printf.c
function uli2a (line 26) | static void uli2a(unsigned long int num, unsigned int base, int uc,char ...
function li2a (line 44) | static void li2a (long num, char * bf)
function ui2a (line 55) | static void ui2a(unsigned int num, unsigned int base, int uc,char * bf)
function i2a (line 73) | static void i2a (int num, char * bf)
function a2d (line 82) | static int a2d(char ch)
function a2i (line 93) | static char a2i(char ch, char** src,int base,int* nump)
function putchw (line 108) | static void putchw(void* putp,putcf putf,int n, char z, char* bf)
function tfp_format (line 121) | void tfp_format(void* putp,putcf putf,char *fmt, va_list va)
function init_printf (line 200) | void init_printf(void* putp,void (*putf) (void*,char))
function tfp_printf (line 206) | void tfp_printf(char *fmt, ...)
function putcp (line 214) | static void putcp(void* p,char c)
function tfp_sprintf (line 221) | void tfp_sprintf(char* s,char *fmt, ...)
FILE: rpi_bm/part9/include/common.h
type u8 (line 5) | typedef uint8_t u8;
type u16 (line 6) | typedef uint16_t u16;
type u32 (line 7) | typedef uint32_t u32;
type u64 (line 8) | typedef uint64_t u64;
type u32 (line 10) | typedef volatile u32 reg32;
FILE: rpi_bm/part9/include/gpio.h
type GpioFunc (line 5) | typedef enum _GpioFunc {
FILE: rpi_bm/part9/include/peripherals/aux.h
type AuxRegs (line 7) | struct AuxRegs {
FILE: rpi_bm/part9/include/peripherals/gpio.h
type GpioPinData (line 7) | struct GpioPinData {
type GpioRegs (line 12) | struct GpioRegs {
FILE: rpi_bm/part9/include/peripherals/irq.h
type vc_irqs (line 7) | enum vc_irqs {
type arm_irq_regs_2711 (line 15) | struct arm_irq_regs_2711 {
type arm_irq_regs_2837 (line 29) | struct arm_irq_regs_2837 {
type arm_irq_regs (line 44) | typedef struct arm_irq_regs_2837 arm_irq_regs;
type arm_irq_regs (line 48) | typedef struct arm_irq_regs_2711 arm_irq_regs;
FILE: rpi_bm/part9/include/peripherals/timer.h
type timer_regs (line 9) | struct timer_regs {
FILE: rpi_bm/part9/src/gpio.c
function gpio_pin_set_func (line 4) | void gpio_pin_set_func(u8 pinNumber, GpioFunc func) {
function gpio_pin_enable (line 15) | void gpio_pin_enable(u8 pinNumber) {
FILE: rpi_bm/part9/src/irq.c
function show_invalid_entry_message (line 31) | void show_invalid_entry_message(u32 type, u64 esr, u64 address) {
function enable_interrupt_controller (line 36) | void enable_interrupt_controller() {
function handle_irq (line 46) | void handle_irq() {
FILE: rpi_bm/part9/src/kernel.c
function putc (line 7) | void putc(void *p, char c) {
function kernel_main (line 17) | void kernel_main() {
FILE: rpi_bm/part9/src/mini_uart.c
function uart_init (line 9) | void uart_init() {
function uart_send (line 37) | void uart_send(char c) {
function uart_recv (line 43) | char uart_recv() {
function uart_send_string (line 49) | void uart_send_string(char *str) {
FILE: rpi_bm/part9/src/printf.c
function uli2a (line 26) | static void uli2a(unsigned long int num, unsigned int base, int uc,char ...
function li2a (line 44) | static void li2a (long num, char * bf)
function ui2a (line 55) | static void ui2a(unsigned int num, unsigned int base, int uc,char * bf)
function i2a (line 73) | static void i2a (int num, char * bf)
function a2d (line 82) | static int a2d(char ch)
function a2i (line 93) | static char a2i(char ch, char** src,int base,int* nump)
function putchw (line 108) | static void putchw(void* putp,putcf putf,int n, char z, char* bf)
function tfp_format (line 121) | void tfp_format(void* putp,putcf putf,char *fmt, va_list va)
function init_printf (line 200) | void init_printf(void* putp,void (*putf) (void*,char))
function tfp_printf (line 206) | void tfp_printf(char *fmt, ...)
function putcp (line 214) | static void putcp(void* p,char c)
function tfp_sprintf (line 221) | void tfp_sprintf(char* s,char *fmt, ...)
FILE: rpi_bm/part9/src/timer.c
function timer_init (line 12) | void timer_init() {
function handle_timer_1 (line 22) | void handle_timer_1() {
function handle_timer_3 (line 30) | void handle_timer_3() {
function u64 (line 38) | u64 timer_get_ticks() {
function timer_sleep (line 52) | void timer_sleep(u32 ms) {
Condensed preview — 648 files, each showing path, character count, and a content snippet. Download the .json file or copy for the full structured content (3,453K chars).
[
{
"path": "README.md",
"chars": 99,
"preview": "Low Level Devel\n\nCode for https://www.youtube.com/playlist?list=PLVxiWMqQvhg9FCteL7I0aohj1_YiUx1x8\n"
},
{
"path": "linux_os/part1/src/init.c",
"chars": 1240,
"preview": "#include <syscall.h>\n#include <fcntl.h>\n\nunsigned long _syscall(int num, void *a0, void *a1, void *a2, void *a3, void *a"
},
{
"path": "linux_os/part1/src/start.S",
"chars": 228,
"preview": ".globl _start\n.text\n_start:\n call main\n\n.globl _syscall\n_syscall:\n movq %rdi, %rax\n movq %rsi, %rdi\n movq %r"
},
{
"path": "linux_os/part10/src/base.mk",
"chars": 315,
"preview": "SHELL ?= /bin/sh\nCC ?= gcc\nFLAGS ?= -nostdlib -I../include\nMYOS_PATH ?= /mnt/myos\nDESTDIR ?= /mnt/myos\n\nPREFIX ?= $(DEST"
},
{
"path": "linux_os/part10/src/drmlist/Makefile",
"chars": 251,
"preview": "\nTARGET=drmlist\nCSOURCES = $(shell echo *.c)\nOBJECTS = $(CSOURCES:.c=_c.o)\n\nLDFLAGS = -lmy -lmydrm -L$(MYOS_PATH)/lib\nBI"
},
{
"path": "linux_os/part10/src/drmlist/drmlist.c",
"chars": 9708,
"preview": "#include <mydrm.h>\n#include <mylib.h>\n#include <printf.h>\n#include <fcntl.h>\n\nstruct mydrm_buf {\n uint32_t width;\n "
},
{
"path": "linux_os/part10/src/fbset/Makefile",
"chars": 246,
"preview": "\nTARGET=fbset\nCSOURCES = $(shell echo *.c)\nOBJECTS = $(CSOURCES:.c=_c.o)\n\nLDFLAGS = -lmy -lfb -L$(MYOS_PATH)/lib\nBINDIR "
},
{
"path": "linux_os/part10/src/fbset/fbset.c",
"chars": 1775,
"preview": "#include <mylib.h>\n#include <libfb.h>\n#include <errno.h>\n#include <fcntl.h>\n#include \"printf.h\"\n\nint fill_fb(void *pbuff"
},
{
"path": "linux_os/part10/src/include/libfb.h",
"chars": 314,
"preview": "#include <linux/fb.h>\n#include <linux/kd.h>\n\n#define FB_ERR_NOFB0 -1\n#define FB_ERR_GETINFO -2\n#define FB_ERR_PUTINFO -3"
},
{
"path": "linux_os/part10/src/include/mydrm.h",
"chars": 978,
"preview": "#pragma once\n\n#include <stdint.h>\n#include <stdbool.h>\n#include <drm/drm.h>\n#include <drm/drm_mode.h>\n\nstruct mydrm_get_"
},
{
"path": "linux_os/part10/src/include/mylib.h",
"chars": 1910,
"preview": "#pragma once\n\n#include <sys/wait.h>\n#include <time.h>\n#include <stdbool.h>\n#include <stdint.h>\n#include <sys/select.h>\n#"
},
{
"path": "linux_os/part10/src/include/printf.h",
"chars": 3918,
"preview": "/*\nFile: printf.h\nCopyright (C) 2004 Kustaa Nyholm\nThis library is free software; you can redistribute it and/or\nmodify"
},
{
"path": "linux_os/part10/src/init/Makefile",
"chars": 222,
"preview": "\nTARGET=init\nCSOURCES = $(shell echo *.c)\nOBJECTS = $(CSOURCES:.c=_c.o)\n\nLDFLAGS = -lmy -lfb -L$(MYOS_PATH)/lib\n\nall: $("
},
{
"path": "linux_os/part10/src/init/crt0.S",
"chars": 759,
"preview": ".globl _start\n\n_start: # _start is the entry point known to the linker\n xor %ebp, %ebp # effectively RBP :"
},
{
"path": "linux_os/part10/src/init/init.c",
"chars": 1333,
"preview": "#include <syscall.h>\n#include <fcntl.h>\n#include <mylib.h>\n#include <libfb.h>\n#include <linux/vt.h>\n\nuint32_t fix_color("
},
{
"path": "linux_os/part10/src/lash/Makefile",
"chars": 240,
"preview": "\nTARGET=lash\nCSOURCES = $(shell echo *.c)\nOBJECTS = $(CSOURCES:.c=_c.o)\n\nLDFLAGS = -lmy -L$(MYOS_PATH)/lib\nBINDIR = $(PR"
},
{
"path": "linux_os/part10/src/lash/lash.c",
"chars": 7123,
"preview": "#include <mylib.h>\n#include <fcntl.h>\n#include \"printf.h\"\n#include <linux/input-event-codes.h>\n\nunsigned long console_fd"
},
{
"path": "linux_os/part10/src/libfb/Makefile",
"chars": 294,
"preview": "\nLDFLAGS = -shared\nTARGET = libfb.so\nCSOURCES = $(shell echo *.c)\nSSOURCES = $(shell echo *.S)\nFLAGS = -nostdlib -I../in"
},
{
"path": "linux_os/part10/src/libfb/fb.c",
"chars": 1460,
"preview": "#include <mylib.h>\n#include <libfb.h>\n#include <fcntl.h>\n#include <errno.h>\n\nint fb_get_info(struct fb_var_screeninfo *v"
},
{
"path": "linux_os/part10/src/mydrm/Makefile",
"chars": 268,
"preview": "\nLDFLAGS = -shared\nTARGET = libmydrm.so\nCSOURCES = $(shell echo *.c)\nFLAGS = -nostdlib -I../include -fPIC\n\nOBJECTS = $(C"
},
{
"path": "linux_os/part10/src/mydrm/mydrm.c",
"chars": 3718,
"preview": "#include <mydrm.h>\n#include <mylib.h>\n#include <fcntl.h>\n#include <errno.h>\n\n#ifndef O_CLOEXEC\n#define O_CLOEXEC\t0200000"
},
{
"path": "linux_os/part10/src/mylib/Makefile",
"chars": 325,
"preview": "\nLDFLAGS = -shared\nTARGET = libmy.so\nCSOURCES = $(shell echo *.c)\nSSOURCES = $(shell echo *.S)\nFLAGS = -nostdlib -I../in"
},
{
"path": "linux_os/part10/src/mylib/mem.c",
"chars": 6157,
"preview": "#include <mylib.h>\n#include \"printf.h\"\n\n#define DEBUG_MEM 1\n#define FLAG_MEM_ALLOCATED 1\n#define FLAG_MEM_MAPPED 2\n\nstat"
},
{
"path": "linux_os/part10/src/mylib/printf.c",
"chars": 5702,
"preview": "/*\nFile: printf.c\nCopyright (C) 2004 Kustaa Nyholm\nThis library is free software; you can redistribute it and/or\nmodify"
},
{
"path": "linux_os/part10/src/mylib/start.S",
"chars": 187,
"preview": ".globl _syscall\n_syscall:\n movq %rdi, %rax\n movq %rsi, %rdi\n movq %rdx, %rsi\n movq %rcx, %rdx\n movq %r8, "
},
{
"path": "linux_os/part10/src/mylib/sys.c",
"chars": 2593,
"preview": "#include <syscall.h>\n#include <mylib.h>\n\nunsigned long sys_open(char *fn, int flags) {\n return _syscall(SYS_open, fn,"
},
{
"path": "linux_os/part10/src/mylib/util.c",
"chars": 1756,
"preview": "#include <mylib.h>\n#include <syscall.h>\n#include \"printf.h\"\n\nunsigned long str_len(char *sz) {\n int count = 0;\n\n w"
},
{
"path": "linux_os/part10/src/printargs/Makefile",
"chars": 245,
"preview": "\nTARGET=printargs\nCSOURCES = $(shell echo *.c)\nOBJECTS = $(CSOURCES:.c=_c.o)\n\nLDFLAGS = -lmy -L$(MYOS_PATH)/lib\nBINDIR ="
},
{
"path": "linux_os/part10/src/printargs/printargs.c",
"chars": 252,
"preview": "#include <mylib.h>\n#include \"printf.h\"\n\nint main(int argc, char **argv) {\n printf(\"PrintArgs: %d\\n\", argc);\n\n for "
},
{
"path": "linux_os/part2/src/base.mk",
"chars": 315,
"preview": "SHELL ?= /bin/sh\nCC ?= gcc\nFLAGS ?= -nostdlib -I../include\nMYOS_PATH ?= /mnt/myos\nDESTDIR ?= /mnt/myos\n\nPREFIX ?= $(DEST"
},
{
"path": "linux_os/part2/src/include/mylib.h",
"chars": 421,
"preview": "#pragma once\n\nextern unsigned long _syscall(int num, void *a0, void *a1, void *a2, void *a3, void *a4, void *a5);\n\nexter"
},
{
"path": "linux_os/part2/src/init/Makefile",
"chars": 217,
"preview": "\nTARGET=init\nCSOURCES = $(shell echo *.c)\nOBJECTS = $(CSOURCES:.c=_c.o)\n\nLDFLAGS = -lmy -L$(MYOS_PATH)/lib\n\nall: $(TARGE"
},
{
"path": "linux_os/part2/src/init/crt0.S",
"chars": 36,
"preview": ".globl _start\n_start:\n call main\n"
},
{
"path": "linux_os/part2/src/init/init.c",
"chars": 602,
"preview": "#include <syscall.h>\n#include <fcntl.h>\n#include <mylib.h>\n\nint main() {\n char *msg = \"MyOS 0.0.0.1 Initializing...\\n"
},
{
"path": "linux_os/part2/src/mylib/Makefile",
"chars": 288,
"preview": "\nLDFLAGS = -shared\nTARGET = libmy.so\nCSOURCES = $(shell echo *.c)\nSSOURCES = $(shell echo *.S)\n\nOBJECTS = $(CSOURCES:.c="
},
{
"path": "linux_os/part2/src/mylib/start.S",
"chars": 187,
"preview": ".globl _syscall\n_syscall:\n movq %rdi, %rax\n movq %rsi, %rdi\n movq %rdx, %rsi\n movq %rcx, %rdx\n movq %r8, "
},
{
"path": "linux_os/part2/src/mylib/sys.c",
"chars": 716,
"preview": "#include <syscall.h>\n#include <mylib.h>\n#include <time.h>\n\nunsigned long sys_open(char *fn, int flags) {\n return _sys"
},
{
"path": "linux_os/part2/src/mylib/util.c",
"chars": 361,
"preview": "#include <mylib.h>\n#include <syscall.h>\n\nunsigned long str_len(char *sz) {\n int count = 0;\n\n while(*sz++) {\n "
},
{
"path": "linux_os/part3/src/base.mk",
"chars": 315,
"preview": "SHELL ?= /bin/sh\nCC ?= gcc\nFLAGS ?= -nostdlib -I../include\nMYOS_PATH ?= /mnt/myos\nDESTDIR ?= /mnt/myos\n\nPREFIX ?= $(DEST"
},
{
"path": "linux_os/part3/src/include/mylib.h",
"chars": 764,
"preview": "#pragma once\n#include <time.h>\n\nextern unsigned long _syscall(int num, void *a0, void *a1, void *a2, void *a3, void *a4,"
},
{
"path": "linux_os/part3/src/init/Makefile",
"chars": 217,
"preview": "\nTARGET=init\nCSOURCES = $(shell echo *.c)\nOBJECTS = $(CSOURCES:.c=_c.o)\n\nLDFLAGS = -lmy -L$(MYOS_PATH)/lib\n\nall: $(TARGE"
},
{
"path": "linux_os/part3/src/init/crt0.S",
"chars": 36,
"preview": ".globl _start\n_start:\n call main\n"
},
{
"path": "linux_os/part3/src/init/init.c",
"chars": 321,
"preview": "#include <syscall.h>\n#include <fcntl.h>\n#include <mylib.h>\n\nint main() {\n char *msg = \"MyOS 0.0.0.2 Initializing...\\n"
},
{
"path": "linux_os/part3/src/lash/Makefile",
"chars": 240,
"preview": "\nTARGET=lash\nCSOURCES = $(shell echo *.c)\nOBJECTS = $(CSOURCES:.c=_c.o)\n\nLDFLAGS = -lmy -L$(MYOS_PATH)/lib\nBINDIR = $(PR"
},
{
"path": "linux_os/part3/src/lash/lash.c",
"chars": 1307,
"preview": "#include <mylib.h>\n#include <fcntl.h>\n\nunsigned long console_fd = 0;\n\nvoid console_open() {\n console_fd = sys_open(\"/"
},
{
"path": "linux_os/part3/src/mylib/Makefile",
"chars": 288,
"preview": "\nLDFLAGS = -shared\nTARGET = libmy.so\nCSOURCES = $(shell echo *.c)\nSSOURCES = $(shell echo *.S)\n\nOBJECTS = $(CSOURCES:.c="
},
{
"path": "linux_os/part3/src/mylib/start.S",
"chars": 187,
"preview": ".globl _syscall\n_syscall:\n movq %rdi, %rax\n movq %rsi, %rdi\n movq %rdx, %rsi\n movq %rcx, %rdx\n movq %r8, "
},
{
"path": "linux_os/part3/src/mylib/sys.c",
"chars": 1287,
"preview": "#include <syscall.h>\n#include <mylib.h>\n\nunsigned long sys_open(char *fn, int flags) {\n return _syscall(SYS_open, fn,"
},
{
"path": "linux_os/part3/src/mylib/util.c",
"chars": 573,
"preview": "#include <mylib.h>\n#include <syscall.h>\n\nunsigned long str_len(char *sz) {\n int count = 0;\n\n while(*sz++) {\n "
},
{
"path": "linux_os/part4/src/base.mk",
"chars": 315,
"preview": "SHELL ?= /bin/sh\nCC ?= gcc\nFLAGS ?= -nostdlib -I../include\nMYOS_PATH ?= /mnt/myos\nDESTDIR ?= /mnt/myos\n\nPREFIX ?= $(DEST"
},
{
"path": "linux_os/part4/src/include/mylib.h",
"chars": 934,
"preview": "#pragma once\n#include <time.h>\n#include <stdbool.h>\n\nextern unsigned long _syscall(int num, void *a0, void *a1, void *a2"
},
{
"path": "linux_os/part4/src/include/printf.h",
"chars": 3918,
"preview": "/*\nFile: printf.h\nCopyright (C) 2004 Kustaa Nyholm\nThis library is free software; you can redistribute it and/or\nmodify"
},
{
"path": "linux_os/part4/src/init/Makefile",
"chars": 217,
"preview": "\nTARGET=init\nCSOURCES = $(shell echo *.c)\nOBJECTS = $(CSOURCES:.c=_c.o)\n\nLDFLAGS = -lmy -L$(MYOS_PATH)/lib\n\nall: $(TARGE"
},
{
"path": "linux_os/part4/src/init/crt0.S",
"chars": 36,
"preview": ".globl _start\n_start:\n call main\n"
},
{
"path": "linux_os/part4/src/init/init.c",
"chars": 321,
"preview": "#include <syscall.h>\n#include <fcntl.h>\n#include <mylib.h>\n\nint main() {\n char *msg = \"MyOS 0.0.0.2 Initializing...\\n"
},
{
"path": "linux_os/part4/src/lash/Makefile",
"chars": 240,
"preview": "\nTARGET=lash\nCSOURCES = $(shell echo *.c)\nOBJECTS = $(CSOURCES:.c=_c.o)\n\nLDFLAGS = -lmy -L$(MYOS_PATH)/lib\nBINDIR = $(PR"
},
{
"path": "linux_os/part4/src/lash/lash.c",
"chars": 2459,
"preview": "#include <mylib.h>\n#include <fcntl.h>\n#include \"printf.h\"\n\nunsigned long console_fd = 0;\n\nvoid console_open() {\n cons"
},
{
"path": "linux_os/part4/src/mylib/Makefile",
"chars": 325,
"preview": "\nLDFLAGS = -shared\nTARGET = libmy.so\nCSOURCES = $(shell echo *.c)\nSSOURCES = $(shell echo *.S)\nFLAGS = -nostdlib -I../in"
},
{
"path": "linux_os/part4/src/mylib/printf.c",
"chars": 5697,
"preview": "/*\nFile: printf.c\nCopyright (C) 2004 Kustaa Nyholm\nThis library is free software; you can redistribute it and/or\nmodify"
},
{
"path": "linux_os/part4/src/mylib/start.S",
"chars": 187,
"preview": ".globl _syscall\n_syscall:\n movq %rdi, %rax\n movq %rsi, %rdi\n movq %rdx, %rsi\n movq %rcx, %rdx\n movq %r8, "
},
{
"path": "linux_os/part4/src/mylib/sys.c",
"chars": 1626,
"preview": "#include <syscall.h>\n#include <mylib.h>\n\nunsigned long sys_open(char *fn, int flags) {\n return _syscall(SYS_open, fn,"
},
{
"path": "linux_os/part4/src/mylib/util.c",
"chars": 1200,
"preview": "#include <mylib.h>\n#include <syscall.h>\n#include \"printf.h\"\n\nunsigned long str_len(char *sz) {\n int count = 0;\n\n w"
},
{
"path": "linux_os/part5/src/base.mk",
"chars": 315,
"preview": "SHELL ?= /bin/sh\nCC ?= gcc\nFLAGS ?= -nostdlib -I../include\nMYOS_PATH ?= /mnt/myos\nDESTDIR ?= /mnt/myos\n\nPREFIX ?= $(DEST"
},
{
"path": "linux_os/part5/src/include/mylib.h",
"chars": 1294,
"preview": "#pragma once\n#include <time.h>\n#include <stdbool.h>\n#include <sys/select.h>\n\nextern unsigned long _syscall(int num, void"
},
{
"path": "linux_os/part5/src/include/printf.h",
"chars": 3918,
"preview": "/*\nFile: printf.h\nCopyright (C) 2004 Kustaa Nyholm\nThis library is free software; you can redistribute it and/or\nmodify"
},
{
"path": "linux_os/part5/src/init/Makefile",
"chars": 217,
"preview": "\nTARGET=init\nCSOURCES = $(shell echo *.c)\nOBJECTS = $(CSOURCES:.c=_c.o)\n\nLDFLAGS = -lmy -L$(MYOS_PATH)/lib\n\nall: $(TARGE"
},
{
"path": "linux_os/part5/src/init/crt0.S",
"chars": 36,
"preview": ".globl _start\n_start:\n call main\n"
},
{
"path": "linux_os/part5/src/init/init.c",
"chars": 321,
"preview": "#include <syscall.h>\n#include <fcntl.h>\n#include <mylib.h>\n\nint main() {\n char *msg = \"MyOS 0.0.0.2 Initializing...\\n"
},
{
"path": "linux_os/part5/src/lash/Makefile",
"chars": 240,
"preview": "\nTARGET=lash\nCSOURCES = $(shell echo *.c)\nOBJECTS = $(CSOURCES:.c=_c.o)\n\nLDFLAGS = -lmy -L$(MYOS_PATH)/lib\nBINDIR = $(PR"
},
{
"path": "linux_os/part5/src/lash/lash.c",
"chars": 5556,
"preview": "#include <mylib.h>\n#include <fcntl.h>\n#include \"printf.h\"\n#include <linux/input-event-codes.h>\n\nunsigned long console_fd"
},
{
"path": "linux_os/part5/src/mylib/Makefile",
"chars": 325,
"preview": "\nLDFLAGS = -shared\nTARGET = libmy.so\nCSOURCES = $(shell echo *.c)\nSSOURCES = $(shell echo *.S)\nFLAGS = -nostdlib -I../in"
},
{
"path": "linux_os/part5/src/mylib/printf.c",
"chars": 5697,
"preview": "/*\nFile: printf.c\nCopyright (C) 2004 Kustaa Nyholm\nThis library is free software; you can redistribute it and/or\nmodify"
},
{
"path": "linux_os/part5/src/mylib/start.S",
"chars": 187,
"preview": ".globl _syscall\n_syscall:\n movq %rdi, %rax\n movq %rsi, %rdi\n movq %rdx, %rsi\n movq %rcx, %rdx\n movq %r8, "
},
{
"path": "linux_os/part5/src/mylib/sys.c",
"chars": 1834,
"preview": "#include <syscall.h>\n#include <mylib.h>\n\nunsigned long sys_open(char *fn, int flags) {\n return _syscall(SYS_open, fn,"
},
{
"path": "linux_os/part5/src/mylib/util.c",
"chars": 1818,
"preview": "#include <mylib.h>\n#include <syscall.h>\n#include \"printf.h\"\n\nunsigned long str_len(char *sz) {\n int count = 0;\n\n w"
},
{
"path": "linux_os/part6/src/base.mk",
"chars": 315,
"preview": "SHELL ?= /bin/sh\nCC ?= gcc\nFLAGS ?= -nostdlib -I../include\nMYOS_PATH ?= /mnt/myos\nDESTDIR ?= /mnt/myos\n\nPREFIX ?= $(DEST"
},
{
"path": "linux_os/part6/src/include/mylib.h",
"chars": 1543,
"preview": "#pragma once\n#include <time.h>\n#include <stdbool.h>\n#include <stdint.h>\n#include <sys/select.h>\n#include <sys/mman.h>\n\ne"
},
{
"path": "linux_os/part6/src/include/printf.h",
"chars": 3918,
"preview": "/*\nFile: printf.h\nCopyright (C) 2004 Kustaa Nyholm\nThis library is free software; you can redistribute it and/or\nmodify"
},
{
"path": "linux_os/part6/src/init/Makefile",
"chars": 217,
"preview": "\nTARGET=init\nCSOURCES = $(shell echo *.c)\nOBJECTS = $(CSOURCES:.c=_c.o)\n\nLDFLAGS = -lmy -L$(MYOS_PATH)/lib\n\nall: $(TARGE"
},
{
"path": "linux_os/part6/src/init/crt0.S",
"chars": 36,
"preview": ".globl _start\n_start:\n call main\n"
},
{
"path": "linux_os/part6/src/init/init.c",
"chars": 321,
"preview": "#include <syscall.h>\n#include <fcntl.h>\n#include <mylib.h>\n\nint main() {\n char *msg = \"MyOS 0.0.0.2 Initializing...\\n"
},
{
"path": "linux_os/part6/src/lash/Makefile",
"chars": 240,
"preview": "\nTARGET=lash\nCSOURCES = $(shell echo *.c)\nOBJECTS = $(CSOURCES:.c=_c.o)\n\nLDFLAGS = -lmy -L$(MYOS_PATH)/lib\nBINDIR = $(PR"
},
{
"path": "linux_os/part6/src/lash/lash.c",
"chars": 5590,
"preview": "#include <mylib.h>\n#include <fcntl.h>\n#include \"printf.h\"\n#include <linux/input-event-codes.h>\n\nunsigned long console_fd"
},
{
"path": "linux_os/part6/src/mylib/Makefile",
"chars": 325,
"preview": "\nLDFLAGS = -shared\nTARGET = libmy.so\nCSOURCES = $(shell echo *.c)\nSSOURCES = $(shell echo *.S)\nFLAGS = -nostdlib -I../in"
},
{
"path": "linux_os/part6/src/mylib/mem.c",
"chars": 6157,
"preview": "#include <mylib.h>\n#include \"printf.h\"\n\n#define DEBUG_MEM 1\n#define FLAG_MEM_ALLOCATED 1\n#define FLAG_MEM_MAPPED 2\n\nstat"
},
{
"path": "linux_os/part6/src/mylib/printf.c",
"chars": 5702,
"preview": "/*\nFile: printf.c\nCopyright (C) 2004 Kustaa Nyholm\nThis library is free software; you can redistribute it and/or\nmodify"
},
{
"path": "linux_os/part6/src/mylib/start.S",
"chars": 187,
"preview": ".globl _syscall\n_syscall:\n movq %rdi, %rax\n movq %rsi, %rdi\n movq %rdx, %rsi\n movq %rcx, %rdx\n movq %r8, "
},
{
"path": "linux_os/part6/src/mylib/sys.c",
"chars": 2100,
"preview": "#include <syscall.h>\n#include <mylib.h>\n\nunsigned long sys_open(char *fn, int flags) {\n return _syscall(SYS_open, fn,"
},
{
"path": "linux_os/part6/src/mylib/util.c",
"chars": 1602,
"preview": "#include <mylib.h>\n#include <syscall.h>\n#include \"printf.h\"\n\nunsigned long str_len(char *sz) {\n int count = 0;\n\n w"
},
{
"path": "linux_os/part7/src/base.mk",
"chars": 315,
"preview": "SHELL ?= /bin/sh\nCC ?= gcc\nFLAGS ?= -nostdlib -I../include\nMYOS_PATH ?= /mnt/myos\nDESTDIR ?= /mnt/myos\n\nPREFIX ?= $(DEST"
},
{
"path": "linux_os/part7/src/include/mylib.h",
"chars": 1737,
"preview": "#pragma once\n\n#include <sys/wait.h>\n#include <time.h>\n#include <stdbool.h>\n#include <stdint.h>\n#include <sys/select.h>\n#"
},
{
"path": "linux_os/part7/src/include/printf.h",
"chars": 3918,
"preview": "/*\nFile: printf.h\nCopyright (C) 2004 Kustaa Nyholm\nThis library is free software; you can redistribute it and/or\nmodify"
},
{
"path": "linux_os/part7/src/init/Makefile",
"chars": 217,
"preview": "\nTARGET=init\nCSOURCES = $(shell echo *.c)\nOBJECTS = $(CSOURCES:.c=_c.o)\n\nLDFLAGS = -lmy -L$(MYOS_PATH)/lib\n\nall: $(TARGE"
},
{
"path": "linux_os/part7/src/init/crt0.S",
"chars": 759,
"preview": ".globl _start\n\n_start: # _start is the entry point known to the linker\n xor %ebp, %ebp # effectively RBP :"
},
{
"path": "linux_os/part7/src/init/init.c",
"chars": 321,
"preview": "#include <syscall.h>\n#include <fcntl.h>\n#include <mylib.h>\n\nint main() {\n char *msg = \"MyOS 0.0.0.2 Initializing...\\n"
},
{
"path": "linux_os/part7/src/lash/Makefile",
"chars": 240,
"preview": "\nTARGET=lash\nCSOURCES = $(shell echo *.c)\nOBJECTS = $(CSOURCES:.c=_c.o)\n\nLDFLAGS = -lmy -L$(MYOS_PATH)/lib\nBINDIR = $(PR"
},
{
"path": "linux_os/part7/src/lash/lash.c",
"chars": 6916,
"preview": "#include <mylib.h>\n#include <fcntl.h>\n#include \"printf.h\"\n#include <linux/input-event-codes.h>\n\nunsigned long console_fd"
},
{
"path": "linux_os/part7/src/mylib/Makefile",
"chars": 325,
"preview": "\nLDFLAGS = -shared\nTARGET = libmy.so\nCSOURCES = $(shell echo *.c)\nSSOURCES = $(shell echo *.S)\nFLAGS = -nostdlib -I../in"
},
{
"path": "linux_os/part7/src/mylib/mem.c",
"chars": 6157,
"preview": "#include <mylib.h>\n#include \"printf.h\"\n\n#define DEBUG_MEM 1\n#define FLAG_MEM_ALLOCATED 1\n#define FLAG_MEM_MAPPED 2\n\nstat"
},
{
"path": "linux_os/part7/src/mylib/printf.c",
"chars": 5702,
"preview": "/*\nFile: printf.c\nCopyright (C) 2004 Kustaa Nyholm\nThis library is free software; you can redistribute it and/or\nmodify"
},
{
"path": "linux_os/part7/src/mylib/start.S",
"chars": 187,
"preview": ".globl _syscall\n_syscall:\n movq %rdi, %rax\n movq %rsi, %rdi\n movq %rdx, %rsi\n movq %rcx, %rdx\n movq %r8, "
},
{
"path": "linux_os/part7/src/mylib/sys.c",
"chars": 2312,
"preview": "#include <syscall.h>\n#include <mylib.h>\n\nunsigned long sys_open(char *fn, int flags) {\n return _syscall(SYS_open, fn,"
},
{
"path": "linux_os/part7/src/mylib/util.c",
"chars": 1680,
"preview": "#include <mylib.h>\n#include <syscall.h>\n#include \"printf.h\"\n\nunsigned long str_len(char *sz) {\n int count = 0;\n\n w"
},
{
"path": "linux_os/part7/src/printargs/Makefile",
"chars": 245,
"preview": "\nTARGET=printargs\nCSOURCES = $(shell echo *.c)\nOBJECTS = $(CSOURCES:.c=_c.o)\n\nLDFLAGS = -lmy -L$(MYOS_PATH)/lib\nBINDIR ="
},
{
"path": "linux_os/part7/src/printargs/printargs.c",
"chars": 252,
"preview": "#include <mylib.h>\n#include \"printf.h\"\n\nint main(int argc, char **argv) {\n printf(\"PrintArgs: %d\\n\", argc);\n\n for "
},
{
"path": "linux_os/part8/myos.img",
"chars": 2336903,
"preview": "(:B(:B(:B(:B(:B(:B(:B(:B(:B(:B(:B(:B(:B(:B(:B(:B(:B(:B(:B(:B(:B(:B(:B(:B(:B(:B(:B(:B(:B(:B(:B(:B(:B(:B(:B(:B(:B(:B(:B(:B"
},
{
"path": "linux_os/part8/src/base.mk",
"chars": 315,
"preview": "SHELL ?= /bin/sh\nCC ?= gcc\nFLAGS ?= -nostdlib -I../include\nMYOS_PATH ?= /mnt/myos\nDESTDIR ?= /mnt/myos\n\nPREFIX ?= $(DEST"
},
{
"path": "linux_os/part8/src/fbset/Makefile",
"chars": 246,
"preview": "\nTARGET=fbset\nCSOURCES = $(shell echo *.c)\nOBJECTS = $(CSOURCES:.c=_c.o)\n\nLDFLAGS = -lmy -lfb -L$(MYOS_PATH)/lib\nBINDIR "
},
{
"path": "linux_os/part8/src/fbset/fbset.c",
"chars": 1775,
"preview": "#include <mylib.h>\n#include <libfb.h>\n#include <errno.h>\n#include <fcntl.h>\n#include \"printf.h\"\n\nint fill_fb(void *pbuff"
},
{
"path": "linux_os/part8/src/include/libfb.h",
"chars": 314,
"preview": "#include <linux/fb.h>\n#include <linux/kd.h>\n\n#define FB_ERR_NOFB0 -1\n#define FB_ERR_GETINFO -2\n#define FB_ERR_PUTINFO -3"
},
{
"path": "linux_os/part8/src/include/mylib.h",
"chars": 1910,
"preview": "#pragma once\n\n#include <sys/wait.h>\n#include <time.h>\n#include <stdbool.h>\n#include <stdint.h>\n#include <sys/select.h>\n#"
},
{
"path": "linux_os/part8/src/include/printf.h",
"chars": 3918,
"preview": "/*\nFile: printf.h\nCopyright (C) 2004 Kustaa Nyholm\nThis library is free software; you can redistribute it and/or\nmodify"
},
{
"path": "linux_os/part8/src/init/Makefile",
"chars": 222,
"preview": "\nTARGET=init\nCSOURCES = $(shell echo *.c)\nOBJECTS = $(CSOURCES:.c=_c.o)\n\nLDFLAGS = -lmy -lfb -L$(MYOS_PATH)/lib\n\nall: $("
},
{
"path": "linux_os/part8/src/init/crt0.S",
"chars": 759,
"preview": ".globl _start\n\n_start: # _start is the entry point known to the linker\n xor %ebp, %ebp # effectively RBP :"
},
{
"path": "linux_os/part8/src/init/init.c",
"chars": 1333,
"preview": "#include <syscall.h>\n#include <fcntl.h>\n#include <mylib.h>\n#include <libfb.h>\n#include <linux/vt.h>\n\nuint32_t fix_color("
},
{
"path": "linux_os/part8/src/lash/Makefile",
"chars": 240,
"preview": "\nTARGET=lash\nCSOURCES = $(shell echo *.c)\nOBJECTS = $(CSOURCES:.c=_c.o)\n\nLDFLAGS = -lmy -L$(MYOS_PATH)/lib\nBINDIR = $(PR"
},
{
"path": "linux_os/part8/src/lash/lash.c",
"chars": 7123,
"preview": "#include <mylib.h>\n#include <fcntl.h>\n#include \"printf.h\"\n#include <linux/input-event-codes.h>\n\nunsigned long console_fd"
},
{
"path": "linux_os/part8/src/libfb/Makefile",
"chars": 294,
"preview": "\nLDFLAGS = -shared\nTARGET = libfb.so\nCSOURCES = $(shell echo *.c)\nSSOURCES = $(shell echo *.S)\nFLAGS = -nostdlib -I../in"
},
{
"path": "linux_os/part8/src/libfb/fb.c",
"chars": 1460,
"preview": "#include <mylib.h>\n#include <libfb.h>\n#include <fcntl.h>\n#include <errno.h>\n\nint fb_get_info(struct fb_var_screeninfo *v"
},
{
"path": "linux_os/part8/src/mylib/Makefile",
"chars": 325,
"preview": "\nLDFLAGS = -shared\nTARGET = libmy.so\nCSOURCES = $(shell echo *.c)\nSSOURCES = $(shell echo *.S)\nFLAGS = -nostdlib -I../in"
},
{
"path": "linux_os/part8/src/mylib/mem.c",
"chars": 6157,
"preview": "#include <mylib.h>\n#include \"printf.h\"\n\n#define DEBUG_MEM 1\n#define FLAG_MEM_ALLOCATED 1\n#define FLAG_MEM_MAPPED 2\n\nstat"
},
{
"path": "linux_os/part8/src/mylib/printf.c",
"chars": 5702,
"preview": "/*\nFile: printf.c\nCopyright (C) 2004 Kustaa Nyholm\nThis library is free software; you can redistribute it and/or\nmodify"
},
{
"path": "linux_os/part8/src/mylib/start.S",
"chars": 187,
"preview": ".globl _syscall\n_syscall:\n movq %rdi, %rax\n movq %rsi, %rdi\n movq %rdx, %rsi\n movq %rcx, %rdx\n movq %r8, "
},
{
"path": "linux_os/part8/src/mylib/sys.c",
"chars": 2593,
"preview": "#include <syscall.h>\n#include <mylib.h>\n\nunsigned long sys_open(char *fn, int flags) {\n return _syscall(SYS_open, fn,"
},
{
"path": "linux_os/part8/src/mylib/util.c",
"chars": 1756,
"preview": "#include <mylib.h>\n#include <syscall.h>\n#include \"printf.h\"\n\nunsigned long str_len(char *sz) {\n int count = 0;\n\n w"
},
{
"path": "linux_os/part8/src/printargs/Makefile",
"chars": 245,
"preview": "\nTARGET=printargs\nCSOURCES = $(shell echo *.c)\nOBJECTS = $(CSOURCES:.c=_c.o)\n\nLDFLAGS = -lmy -L$(MYOS_PATH)/lib\nBINDIR ="
},
{
"path": "linux_os/part8/src/printargs/printargs.c",
"chars": 252,
"preview": "#include <mylib.h>\n#include \"printf.h\"\n\nint main(int argc, char **argv) {\n printf(\"PrintArgs: %d\\n\", argc);\n\n for "
},
{
"path": "linux_os/part9/src/base.mk",
"chars": 315,
"preview": "SHELL ?= /bin/sh\nCC ?= gcc\nFLAGS ?= -nostdlib -I../include\nMYOS_PATH ?= /mnt/myos\nDESTDIR ?= /mnt/myos\n\nPREFIX ?= $(DEST"
},
{
"path": "linux_os/part9/src/drmlist/Makefile",
"chars": 251,
"preview": "\nTARGET=drmlist\nCSOURCES = $(shell echo *.c)\nOBJECTS = $(CSOURCES:.c=_c.o)\n\nLDFLAGS = -lmy -lmydrm -L$(MYOS_PATH)/lib\nBI"
},
{
"path": "linux_os/part9/src/drmlist/drmlist.c",
"chars": 1266,
"preview": "#include <mydrm.h>\n#include <mylib.h>\n#include <printf.h>\n\nint main(int argc, char **argv) {\n printf(\"DRM modes:\\n\");"
},
{
"path": "linux_os/part9/src/fbset/Makefile",
"chars": 246,
"preview": "\nTARGET=fbset\nCSOURCES = $(shell echo *.c)\nOBJECTS = $(CSOURCES:.c=_c.o)\n\nLDFLAGS = -lmy -lfb -L$(MYOS_PATH)/lib\nBINDIR "
},
{
"path": "linux_os/part9/src/fbset/fbset.c",
"chars": 1775,
"preview": "#include <mylib.h>\n#include <libfb.h>\n#include <errno.h>\n#include <fcntl.h>\n#include \"printf.h\"\n\nint fill_fb(void *pbuff"
},
{
"path": "linux_os/part9/src/include/libfb.h",
"chars": 314,
"preview": "#include <linux/fb.h>\n#include <linux/kd.h>\n\n#define FB_ERR_NOFB0 -1\n#define FB_ERR_GETINFO -2\n#define FB_ERR_PUTINFO -3"
},
{
"path": "linux_os/part9/src/include/mydrm.h",
"chars": 553,
"preview": "#pragma once\n\n#include <stdint.h>\n#include <stdbool.h>\n#include <drm/drm.h>\n#include <drm/drm_mode.h>\n\nstruct mydrm_get_"
},
{
"path": "linux_os/part9/src/include/mylib.h",
"chars": 1910,
"preview": "#pragma once\n\n#include <sys/wait.h>\n#include <time.h>\n#include <stdbool.h>\n#include <stdint.h>\n#include <sys/select.h>\n#"
},
{
"path": "linux_os/part9/src/include/printf.h",
"chars": 3918,
"preview": "/*\nFile: printf.h\nCopyright (C) 2004 Kustaa Nyholm\nThis library is free software; you can redistribute it and/or\nmodify"
},
{
"path": "linux_os/part9/src/init/Makefile",
"chars": 222,
"preview": "\nTARGET=init\nCSOURCES = $(shell echo *.c)\nOBJECTS = $(CSOURCES:.c=_c.o)\n\nLDFLAGS = -lmy -lfb -L$(MYOS_PATH)/lib\n\nall: $("
},
{
"path": "linux_os/part9/src/init/crt0.S",
"chars": 759,
"preview": ".globl _start\n\n_start: # _start is the entry point known to the linker\n xor %ebp, %ebp # effectively RBP :"
},
{
"path": "linux_os/part9/src/init/init.c",
"chars": 1333,
"preview": "#include <syscall.h>\n#include <fcntl.h>\n#include <mylib.h>\n#include <libfb.h>\n#include <linux/vt.h>\n\nuint32_t fix_color("
},
{
"path": "linux_os/part9/src/lash/Makefile",
"chars": 240,
"preview": "\nTARGET=lash\nCSOURCES = $(shell echo *.c)\nOBJECTS = $(CSOURCES:.c=_c.o)\n\nLDFLAGS = -lmy -L$(MYOS_PATH)/lib\nBINDIR = $(PR"
},
{
"path": "linux_os/part9/src/lash/lash.c",
"chars": 7123,
"preview": "#include <mylib.h>\n#include <fcntl.h>\n#include \"printf.h\"\n#include <linux/input-event-codes.h>\n\nunsigned long console_fd"
},
{
"path": "linux_os/part9/src/libfb/Makefile",
"chars": 294,
"preview": "\nLDFLAGS = -shared\nTARGET = libfb.so\nCSOURCES = $(shell echo *.c)\nSSOURCES = $(shell echo *.S)\nFLAGS = -nostdlib -I../in"
},
{
"path": "linux_os/part9/src/libfb/fb.c",
"chars": 1460,
"preview": "#include <mylib.h>\n#include <libfb.h>\n#include <fcntl.h>\n#include <errno.h>\n\nint fb_get_info(struct fb_var_screeninfo *v"
},
{
"path": "linux_os/part9/src/mydrm/Makefile",
"chars": 268,
"preview": "\nLDFLAGS = -shared\nTARGET = libmydrm.so\nCSOURCES = $(shell echo *.c)\nFLAGS = -nostdlib -I../include -fPIC\n\nOBJECTS = $(C"
},
{
"path": "linux_os/part9/src/mydrm/mydrm.c",
"chars": 2758,
"preview": "#include <mydrm.h>\n#include <mylib.h>\n#include <fcntl.h>\n#include <errno.h>\n\n#ifndef O_CLOEXEC\n#define O_CLOEXEC\t0200000"
},
{
"path": "linux_os/part9/src/mylib/Makefile",
"chars": 325,
"preview": "\nLDFLAGS = -shared\nTARGET = libmy.so\nCSOURCES = $(shell echo *.c)\nSSOURCES = $(shell echo *.S)\nFLAGS = -nostdlib -I../in"
},
{
"path": "linux_os/part9/src/mylib/mem.c",
"chars": 6157,
"preview": "#include <mylib.h>\n#include \"printf.h\"\n\n#define DEBUG_MEM 1\n#define FLAG_MEM_ALLOCATED 1\n#define FLAG_MEM_MAPPED 2\n\nstat"
},
{
"path": "linux_os/part9/src/mylib/printf.c",
"chars": 5702,
"preview": "/*\nFile: printf.c\nCopyright (C) 2004 Kustaa Nyholm\nThis library is free software; you can redistribute it and/or\nmodify"
},
{
"path": "linux_os/part9/src/mylib/start.S",
"chars": 187,
"preview": ".globl _syscall\n_syscall:\n movq %rdi, %rax\n movq %rsi, %rdi\n movq %rdx, %rsi\n movq %rcx, %rdx\n movq %r8, "
},
{
"path": "linux_os/part9/src/mylib/sys.c",
"chars": 2593,
"preview": "#include <syscall.h>\n#include <mylib.h>\n\nunsigned long sys_open(char *fn, int flags) {\n return _syscall(SYS_open, fn,"
},
{
"path": "linux_os/part9/src/mylib/util.c",
"chars": 1756,
"preview": "#include <mylib.h>\n#include <syscall.h>\n#include \"printf.h\"\n\nunsigned long str_len(char *sz) {\n int count = 0;\n\n w"
},
{
"path": "linux_os/part9/src/printargs/Makefile",
"chars": 245,
"preview": "\nTARGET=printargs\nCSOURCES = $(shell echo *.c)\nOBJECTS = $(CSOURCES:.c=_c.o)\n\nLDFLAGS = -lmy -L$(MYOS_PATH)/lib\nBINDIR ="
},
{
"path": "linux_os/part9/src/printargs/printargs.c",
"chars": 252,
"preview": "#include <mylib.h>\n#include \"printf.h\"\n\nint main(int argc, char **argv) {\n printf(\"PrintArgs: %d\\n\", argc);\n\n for "
},
{
"path": "linux_os/qemu/qemu-run.sh",
"chars": 578,
"preview": "#!/bin/bash\n#will make an image in ~/git/LLD/linux_os/qemu/myos.img and run it with qemu\n\nrm -f ~/git/LLD/linux_os/qemu/"
},
{
"path": "ooc/Makefile",
"chars": 79,
"preview": "all: logtest\n\nlogtest:\n\tgcc *.c -o logtest\n\nclean:\n\trm -f logtest\n\trm -f *.log\n"
},
{
"path": "ooc/flog.h",
"chars": 82,
"preview": "#pragma once\n\n#include \"log.h\"\n\nint filelog_create(logger *impl, char *filename);\n"
},
{
"path": "ooc/log.h",
"chars": 485,
"preview": "#pragma once\n\ntypedef struct logger_ logger;\n\n//separate struct for function interface\ntypedef struct log_interface_ {\n "
},
{
"path": "ooc/log_console.c",
"chars": 535,
"preview": "#include \"log.h\"\n#include <stdio.h>\n\nint console_init(logger *self, void *data) {\n printf(\"Console Logger Init\\n\");\n "
},
{
"path": "ooc/log_file.c",
"chars": 1370,
"preview": "#include \"log.h\"\n#include <stdlib.h>\n#include <stdio.h>\n#include <errno.h>\n\nint file_init(logger *self, void *data);\nvoi"
},
{
"path": "ooc/main.c",
"chars": 1614,
"preview": "#include \"log.h\"\n#include \"flog.h\"\n\n#include <stdio.h>\n\n//macros for less typing...\n#define ILOG(log, msg) (log)->interf"
},
{
"path": "pico/6502_part1/CMakeLists.txt",
"chars": 298,
"preview": "cmake_minimum_required(VERSION 3.13)\ninclude(pico_sdk_import.cmake)\nproject(test_project)\npico_sdk_init()\n\nadd_executabl"
},
{
"path": "pico/6502_part1/pico_sdk_import.cmake",
"chars": 2763,
"preview": "# This is a copy of <PICO_SDK_PATH>/external/pico_sdk_import.cmake\n\n# This can be dropped into an external project to he"
},
{
"path": "pico/6502_part1/test.c",
"chars": 5679,
"preview": "#include \"pico/stdlib.h\"\n#include <stdio.h>\n#include \"hardware/i2c.h\"\n#include \"pico/binary_info.h\"\n\nconst uint BASE_BUS"
},
{
"path": "rpi_bm/part1-5/Makefile",
"chars": 1168,
"preview": "RPI_VERSION ?= 4\n\nBOOTMNT ?= /media/parallels/boot\n\nARMGNU ?= aarch64-linux-gnu\n\nCOPS = -DRPI_VERSION=$(RPI_VERSION) -Wa"
},
{
"path": "rpi_bm/part1-5/README.md",
"chars": 101,
"preview": "Lower Level Devel\n\nCode for https://www.youtube.com/playlist?list=PLVxiWMqQvhg9FCteL7I0aohj1_YiUx1x8\n"
},
{
"path": "rpi_bm/part1-5/config.txt",
"chars": 81,
"preview": "arm_64bit=1\nuart_2ndstage=1\ndtoverlay=miniuart-bt\n\n[pi4]\nkernel=kernel8-rpi4.img\n"
},
{
"path": "rpi_bm/part1-5/include/common.h",
"chars": 150,
"preview": "#pragma once\n\n#include <stdint.h>\n\ntypedef uint8_t u8;\ntypedef uint16_t u16;\ntypedef uint32_t u32;\ntypedef uint64_t u64;"
},
{
"path": "rpi_bm/part1-5/include/gpio.h",
"chars": 303,
"preview": "#pragma once\n\n#include \"peripherals/gpio.h\"\n\ntypedef enum _GpioFunc {\n GFInput = 0,\n GFOutput = 1,\n GFAlt0 = 4,"
},
{
"path": "rpi_bm/part1-5/include/mini_uart.h",
"chars": 108,
"preview": "#pragma once\n\nvoid uart_init();\nchar uart_recv();\nvoid uart_send(char c);\nvoid uart_send_string(char *str);\n"
},
{
"path": "rpi_bm/part1-5/include/mm.h",
"chars": 305,
"preview": "#pragma once\n\n#define PAGE_SHIFT 12\n#define TABLE_SHIFT 9\n#define SECTION_SHIFT (PAGE_SHIFT + TABLE_SHIFT)\n#define PAGE_"
},
{
"path": "rpi_bm/part1-5/include/peripherals/aux.h",
"chars": 424,
"preview": "#pragma once\n\n#include \"common.h\"\n\n#include \"peripherals/base.h\"\n\nstruct AuxRegs {\n reg32 irq_status;\n reg32 enabl"
},
{
"path": "rpi_bm/part1-5/include/peripherals/base.h",
"chars": 171,
"preview": "#pragma once\n\n#if RPI_VERSION == 3\n#define PBASE 0x3F000000\n\n#elif RPI_VERSION == 4\n#define PBASE 0xFE000000\n\n#else\n#def"
},
{
"path": "rpi_bm/part1-5/include/peripherals/gpio.h",
"chars": 701,
"preview": "#pragma once\n\n#include \"common.h\"\n\n#include \"peripherals/base.h\"\n\nstruct GpioPinData {\n reg32 reserved;\n reg32 dat"
},
{
"path": "rpi_bm/part1-5/include/utils.h",
"chars": 118,
"preview": "#pragma once\n\n#include \"common.h\"\n\nvoid delay(u64 ticks);\nvoid put32(u64 address, u32 value);\nu32 get32(u64 address);\n"
},
{
"path": "rpi_bm/part1-5/src/boot.S",
"chars": 323,
"preview": "#include \"mm.h\"\n\n.section \".text.boot\"\n\n.globl _start\n_start:\n mrs x0, mpidr_el1\n and x0, x0, #0xFF\n cbz x0, ma"
},
{
"path": "rpi_bm/part1-5/src/gpio.c",
"chars": 593,
"preview": "#include \"gpio.h\"\n#include \"utils.h\"\n\nvoid gpio_pin_set_func(u8 pinNumber, GpioFunc func) {\n u8 bitStart = (pinNumber"
},
{
"path": "rpi_bm/part1-5/src/kernel.c",
"chars": 404,
"preview": "#include \"common.h\"\n#include \"mini_uart.h\"\n\nvoid kernel_main() {\n uart_init();\n uart_send_string(\"Rasperry PI Bare"
},
{
"path": "rpi_bm/part1-5/src/linker.ld",
"chars": 206,
"preview": "SECTIONS\n{\n .text.boot : { *(.text.boot) }\n .text : { *(.text) }\n .rodata : { *(.rodata) }\n .data : { *(.dat"
},
{
"path": "rpi_bm/part1-5/src/mini_uart.c",
"chars": 1025,
"preview": "#include \"gpio.h\"\n#include \"utils.h\"\n#include \"peripherals/aux.h\"\n#include \"mini_uart.h\"\n\n#define TXD 14\n#define RXD 15\n"
},
{
"path": "rpi_bm/part1-5/src/mm.S",
"chars": 91,
"preview": ".globl memzero\nmemzero:\n str xzr, [x0], #8\n subs x1, x1, #8\n b.gt memzero\n ret\n"
},
{
"path": "rpi_bm/part1-5/src/utils.S",
"chars": 154,
"preview": ".globl delay\ndelay:\n subs x0, x0, #1\n bne delay\n ret\n\n.globl put32\nput32:\n str w1, [x0]\n ret\n\n.globl get3"
},
{
"path": "rpi_bm/part10/Makefile",
"chars": 1512,
"preview": "RPI_VERSION ?= 4\n\nBOOTMNT ?= /media/parallels/boot\n\nARMGNU ?= aarch64-linux-gnu\n\nCOPS = -DRPI_VERSION=$(RPI_VERSION) -Wa"
},
{
"path": "rpi_bm/part10/armstub/src/armstub.S",
"chars": 249,
"preview": ".globl _start\n_start:\n ldr w0, kernel_entry32\n br x0\n\n.ltorg\n\n.org 0xf0\n.globl stub_magic\nstub_magic:\n .word 0x"
},
{
"path": "rpi_bm/part10/config.txt",
"chars": 106,
"preview": "arm_64bit=1\nuart_2ndstage=1\ndtoverlay=miniuart-bt\n\narmstub=armstub-new.bin\n\n[pi4]\nkernel=kernel8-rpi4.img\n"
},
{
"path": "rpi_bm/part10/i2c-slave/i2c-slave.ino",
"chars": 658,
"preview": "#include <Wire.h>\n\n#define ADDRESS 21\n\nconst char *answer = \"HELLO_I2C\";\n\nvoid setup() {\n \n Wire.begin(ADDRESS);\n Wir"
},
{
"path": "rpi_bm/part10/include/common.h",
"chars": 150,
"preview": "#pragma once\n\n#include <stdint.h>\n\ntypedef uint8_t u8;\ntypedef uint16_t u16;\ntypedef uint32_t u32;\ntypedef uint64_t u64;"
},
{
"path": "rpi_bm/part10/include/entry.h",
"chars": 576,
"preview": "#pragma once\n\n//D1.10.2\n#define SYNC_INVALID_EL1t\t\t0 \n#define IRQ_INVALID_EL1t\t\t1 \n#define FIQ_INVALID_EL1t\t\t2 \n#define "
},
{
"path": "rpi_bm/part10/include/gpio.h",
"chars": 303,
"preview": "#pragma once\n\n#include \"peripherals/gpio.h\"\n\ntypedef enum _GpioFunc {\n GFInput = 0,\n GFOutput = 1,\n GFAlt0 = 4,"
},
{
"path": "rpi_bm/part10/include/i2c.h",
"chars": 290,
"preview": "#pragma once\n\n#include \"common.h\"\n\ntypedef enum _i2c_status {\n I2CS_SUCCESS,\n I2CS_ACK_ERROR,\n I2CS_DATA_LOSS,\n"
},
{
"path": "rpi_bm/part10/include/irq.h",
"chars": 115,
"preview": "#pragma once\n\nvoid irq_init_vectors();\nvoid irq_enable();\nvoid irq_disable();\n\nvoid enable_interrupt_controller();\n"
},
{
"path": "rpi_bm/part10/include/mini_uart.h",
"chars": 108,
"preview": "#pragma once\n\nvoid uart_init();\nchar uart_recv();\nvoid uart_send(char c);\nvoid uart_send_string(char *str);\n"
},
{
"path": "rpi_bm/part10/include/mm.h",
"chars": 305,
"preview": "#pragma once\n\n#define PAGE_SHIFT 12\n#define TABLE_SHIFT 9\n#define SECTION_SHIFT (PAGE_SHIFT + TABLE_SHIFT)\n#define PAGE_"
},
{
"path": "rpi_bm/part10/include/peripherals/aux.h",
"chars": 424,
"preview": "#pragma once\n\n#include \"common.h\"\n\n#include \"peripherals/base.h\"\n\nstruct AuxRegs {\n reg32 irq_status;\n reg32 enabl"
},
{
"path": "rpi_bm/part10/include/peripherals/base.h",
"chars": 208,
"preview": "#pragma once\n\n#if RPI_VERSION == 3\n#define PBASE 0x3F000000\n\n#elif RPI_VERSION == 4\n#define PBASE 0xFE000000\n\n#else\n#def"
},
{
"path": "rpi_bm/part10/include/peripherals/gpio.h",
"chars": 701,
"preview": "#pragma once\n\n#include \"common.h\"\n\n#include \"peripherals/base.h\"\n\nstruct GpioPinData {\n reg32 reserved;\n reg32 dat"
},
{
"path": "rpi_bm/part10/include/peripherals/i2c.h",
"chars": 777,
"preview": "#pragma once\n#include \"peripherals/base.h\"\n#include \"common.h\"\n\nstruct I2CRegs {\n reg32 control;\n reg32 status;\n "
},
{
"path": "rpi_bm/part10/include/peripherals/irq.h",
"chars": 1026,
"preview": "#pragma once\n\n#include \"peripherals/base.h\"\n#include \"common.h\"\n\n//6.2.4\nenum vc_irqs {\n SYS_TIMER_IRQ_0 = 1,\n SYS"
},
{
"path": "rpi_bm/part10/include/peripherals/timer.h",
"chars": 276,
"preview": "#pragma once\n\n#include \"peripherals/base.h\"\n#include \"common.h\"\n\n#define CLOCKHZ 1000000\n\n//10.2\nstruct timer_regs {\n "
},
{
"path": "rpi_bm/part10/include/printf.h",
"chars": 3918,
"preview": "/*\nFile: printf.h\nCopyright (C) 2004 Kustaa Nyholm\nThis library is free software; you can redistribute it and/or\nmodify"
},
{
"path": "rpi_bm/part10/include/sysregs.h",
"chars": 1130,
"preview": "#pragma once\n\n//D13.2.113\n\n#define SCTLR_RESERVED (3 << 28) | (3 << 22) | (1 << 20) | (1 << 11)\n#define"
}
]
// ... and 448 more files (download for full content)
About this extraction
This page contains the full source code of the rockytriton/LLD GitHub repository, extracted and formatted as plain text for AI agents and large language models (LLMs). The extraction includes 648 files (3.1 MB), approximately 831.2k tokens, and a symbol index with 1409 extracted functions, classes, methods, constants, and types. Use this with OpenClaw, Claude, ChatGPT, Cursor, Windsurf, or any other AI tool that accepts text input. You can copy the full output to your clipboard or download it as a .txt file.
Extracted by GitExtract — free GitHub repo to text converter for AI. Built by Nikandr Surkov.