Coder Social home page Coder Social logo

aaronjanse / bootstrapos Goto Github PK

View Code? Open in Web Editor NEW
11.0 5.0 2.0 31.22 MB

[WIP] Bootstrap your own OS: from machine code to web server

Home Page: https://ajanse.me/bootstrapOS/documentation.html

Shell 2.16% Nix 8.10% Racket 4.15% HTML 54.03% Perl 23.81% C 3.92% Python 3.26% R 0.58%
arm-assembly raspberry-pi-4 tutorial os

bootstrapos's Introduction

bootstrapOS

Many OS tutorials start in assembly or C++. We start in machine code.

In this Raspberry Pi 4 tutorial, we'll write a self-hosted assembler in machine code. We'll then evolve that compiler (by implementing new features then using those features in the compiler source code) into something capable of wrangling a high-level language. Finally, in our high-level language, where most tutorials start, we'll write a simple web server to one day host the tutorial's own documentation.

Progress

Milestone: bootstrap machine code ๐ŸŽ‰

  • print to qemu uart
  • properly setup uart, wait for write, print 'x'
  • wait for read, read, print uart input
  • write all to memory then dump memory in
  • copy mem_in to mem_out then modify above code to print mem_out
  • use bytes to indicate length of output
  • routine to read a certain number of bits to memory, use it to copy machine code
  • remove leading whitespace, ; command for comments
  • print raw binary

Milestone: big-endian machine code ๐ŸŽ‰

  • print binary in little-endian form
  • rewrite codebase in big-endian form (ehh, leave most formatting for later)

Milestone: labeled goto ๐ŸŽ‰

  • J: relative branch with binary
  • L: label for goto (read into memory tape with scheme pos4 name \0)
  • GOTO: goto label
  • rewrite codebase using labeled GOTOs

Milestone: conditional goto ๐ŸŽ‰

  • GOEQ
  • GONE
  • GOGT
  • GOLT
  • GOGE
  • GOLE
  • rewrite codebase using conditional goto

Milestone: labeled functions ๐ŸŽ‰

  • CALL: "goto" but with linked branching
  • rewrite codebase

Milestone: emitting strings

  • MOV reg char
  • EMIT string: macro for series of MOV reg char and CALL emit with escape sequence support
  • rewrite codebase

Milestone: bootstrap assembly

  • RET: return after function call
  • MOV reg hex
  • MOV reg dec
  • MOV reg reg
  • ADD reg reg [reg/value]: set the value of a register
  • SUB reg reg [reg/value]: set the value of a register
  • LDB reg reg_mem offset: load a byte
  • STB reg reg_mem offset: store a byte
  • ORR reg reg (reg >>/<< value)
  • AND reg reg (reg >>/<< value)

Milestone: stack-lang functions

  • .func [name] [num locals]
  • .call [name]

Milestone: push, pop, and dup

  • .push constant [val]

  • .dup

  • .pop local [idx]

  • .push local [idx]

  • .pop param [idx]

  • .push param [idx]

  • .pop global [idx]

  • .push global [idx]

Milestone: stack-lang memory access

  • .load (..., addr) -> (..., val)
  • .store (..., val, addr) -> (...)

Milestone: arithmetic

  • .add
  • .sub

Milestone: heap allocation

  • malloc stack function (..., num bytes) -> (..., addr)

Milestone: parsing and compiling

  • constants
  • unary operations
  • binomial operations
  • global variable declarations
  • basic functions (with goto for fn main)
  • function calling and parameters
  • local variables
  • conditional blocks
  • loops
  • break from loops

  • refactor circle library's ethernet driver
  • rewrite ethernet driver in our high-level language
  • TCP/IP stack
  • http server
  • serve multiple files
  • preemptive multitasking

Lines of code over time

lines of code

for f in ./os/*.txt; do wc -l $f; done | Rscript bar-gen.R ; feh ./loc-stats.png

bootstrapos's People

Contributors

aaronjanse avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.