Leanpub Header

Skip to main content

Bare Metal Computing X64 Edition

Low Level Coding of Native Instructions

Most programmers never touch the machine.

They live inside frameworks. They trust kernels. They inherit latency, abstraction, and hidden behavior they do not control.

And they call that “systems programming.”

Bare Metal Computing With X64 — Low Level Coding of Native Instructions is for the engineer who wants authority, not convenience

Minimum price

$19.00

$29.00

You pay

$29.00

Author earns

$23.20
$

...Or Buy With Credits!

You can get credits with a paid monthly or annual Reader Membership, or you can buy them here.
PDF
About

About

About the Book

Most programmers never touch the machine.

They live inside frameworks.
They trust kernels.
They inherit latency, abstraction, and hidden behavior they do not control.

And they call that “systems programming.”

Bare Metal Computing With X64 — Low Level Coding of Native Instructions is for the engineer who wants authority, not convenience.

This book takes you beneath operating systems, beneath drivers, beneath libraries — to the execution model itself.

You will learn:

  • How machine instructions are encoded at the binary level
  • How control registers actually govern execution
  • How paging, TLBs, and memory attributes shape real behavior
  • How interrupts, exceptions, and privilege rings truly work
  • How to bring a processor from reset state into 64-bit long mode
  • How to build deterministic systems without an operating system
  • How to design ultra-low-latency, real-time, and hardware-controlled execution environments

This is not theory.

You will configure descriptor tables.
You will program PCI devices directly.
You will manage DMA safely.
You will measure interrupt latency.
You will debug faults without a safety net.
You will enforce hardware isolation at the silicon boundary.

And you will see how AI can participate in machine-code synthesis while preserving strict architectural invariants — without surrendering control.

If you design robotics platforms, trading engines, edge AI appliances, distributed bare-metal systems, or experimental hardware research platforms, this book gives you something rare:

Clarity at the metal.
Determinism at the instruction level.
Control over the entire execution stack.

Most engineers operate above the machine.

After this book, you won’t.

Share this book

Author

About the Author

gareth thomas

Gareth Morgan Thomas is a qualified expert with extensive expertise across multiple STEM fields. Holding six university diplomas in electronics, software development, web development, and project management, along with qualifications in computer networking, CAD, diesel engineering, well drilling, and welding, he has built a robust foundation of technical knowledge.

Educated in Auckland, New Zealand, Gareth Morgan Thomas also spent three years serving in the New Zealand Army, where he honed his discipline and problem-solving skills. With years of technical training, Gareth Morgan Thomas is now dedicated to sharing his deep understanding of science, technology, engineering, and mathematics through a series of specialized books aimed at both beginners and advanced learners.

Contents

Table of Contents

Chapter 1. The Modern CPU Execution Model

Section 1. Instruction Set Architecture and Machine Code

  • Opcode formats and binary encoding structure
  • Register files and architectural state
  • Addressing modes and operand resolution
  • Flags and condition codes
  • Instruction decoding and execution flow
  • Control registers and system state

Section 2. Execution Modes and Privilege Architecture

  • Real mode fundamentals
  • Protected mode structure
  • Long mode (64-bit) operation
  • Ring levels and privilege enforcement
  • Transitioning between modes
  • Model-specific registers and extended state

Section 3. Microarchitectural Realities

  • Pipelines and superscalar execution
  • Out-of-order execution mechanics
  • Branch prediction and speculation
  • Cache hierarchies and coherency protocols
  • Translation lookaside buffers (TLBs)
  • Performance monitoring counters

Chapter 2. Boot and Control Transfer on Modern Hardware

Section 1. Firmware Foundations

  • BIOS legacy boot process
  • UEFI boot architecture
  • Secure Boot and its implications
  • Firmware memory maps
  • Power-on reset state
  • POST and hardware initialization

Section 2. Bootloader Architecture

  • Boot sector structure and constraints
  • Stage 1 and Stage 2 loaders
  • Loading binaries from storage
  • Stack setup and early execution environment
  • Enabling A20 and memory access above 1MB
  • Transition to protected and long mode

Section 3. Establishing Full Control

  • Exiting firmware services
  • Identity mapping and early paging
  • Setting up GDT and IDT
  • Enabling long mode execution
  • Control register configuration
  • Verifying CPU features and capabilities

Chapter 3. Memory Architecture and Deterministic Control

Section 1. Physical and Virtual Memory Models

  • Physical address space layout
  • Virtual address translation mechanisms
  • Page table hierarchies (PML4 and beyond)
  • Page attributes and access control
  • Large pages and huge pages
  • Memory type range registers (MTRRs)

Section 2. Paging and Execution Management

  • Identity mapping strategies
  • Higher-half kernel layouts
  • Disabling or simplifying paging
  • Managing CR3 and TLB behavior
  • Cache control and memory ordering
  • Executable vs non-executable regions

Section 3. Deterministic Memory Operation

  • Eliminating unpredictable interrupts
  • Cache behavior and false sharing
  • Interrupt masking and NMI considerations
  • Precise timing with TSC
  • DMA and IOMMU configuration
  • Memory barriers and ordering guarantees

Chapter 4. Interrupts, Exceptions, and Hardware Control

Section 1. Interrupt Architecture and Descriptor Tables

  • Interrupt Descriptor Table (IDT) structure
  • Gate types and privilege transitions
  • Interrupt vector layout
  • Interrupt stack tables (IST)
  • Task State Segment (TSS) configuration
  • Loading and activating the IDT

Section 2. Exception Handling and Fault Management

  • Processor-defined exception types
  • Faults, traps, and aborts
  • Error codes and stack frames
  • Double faults and triple faults
  • Recoverable vs non-recoverable conditions
  • Designing stable exception handlers

Section 3. Advanced Interrupt Control

  • Legacy PIC vs Local APIC
  • I/O APIC routing and configuration
  • Inter-Processor Interrupts (IPI)
  • Non-Maskable Interrupts (NMI)
  • Interrupt prioritization and nesting
  • Deterministic interrupt masking strategies

Chapter 5. Direct Hardware Access and Bus-Level Control

Section 1. Memory-Mapped and Port-Mapped I/O

  • Memory-mapped I/O fundamentals
  • Port I/O instructions and usage
  • Access width and alignment constraints
  • Volatile semantics and ordering
  • Device register interaction models
  • Side effects of hardware access

Section 2. PCI and Device Enumeration

  • PCI configuration space structure
  • Bus, device, and function addressing
  • Base Address Registers (BARs)
  • Capability lists and extended capabilities
  • Enumerating and initializing devices
  • Mapping device memory regions

Section 3. Direct Memory Access and IOMMU

  • DMA fundamentals and descriptor rings
  • Bus mastering configuration
  • Cache coherency with DMA
  • IOMMU mapping and isolation
  • Scatter-gather transfers
  • Ensuring deterministic device interaction

Chapter 6. Timing, Scheduling, and Execution Control

Section 1. Hardware Timers and Timekeeping

  • Programmable Interval Timer (PIT)
  • Local APIC timer
  • High Precision Event Timer (HPET)
  • Time Stamp Counter (TSC)
  • Invariant TSC and frequency scaling
  • Clock calibration techniques

Section 2. Scheduling Without an Operating System

  • Cooperative scheduling models
  • Preemptive scheduling design
  • Context switching mechanics
  • Saving and restoring CPU state
  • Stack management for multiple tasks
  • Minimal task control structures

Section 3. Deterministic Execution Guarantees

  • Interrupt latency measurement
  • Jitter analysis and reduction
  • Cache warming strategies
  • Lock-free synchronization
  • Spinlocks and atomic primitives
  • Real-time deadline enforcement

Chapter 7. AI as Machine Code Author

Section 1. Human–AI Architectural Workflow

  • Defining hardware-level specifications
  • Declaring architectural constraints
  • Iterative refinement of execution models
  • Prompt structures for deterministic code generation
  • Validating AI understanding of CPU state
  • Maintaining architectural invariants

Section 2. Machine Code Synthesis

  • Translating requirements into opcode sequences
  • Register allocation strategies
  • Stack discipline enforcement
  • Control flow construction at binary level
  • Direct encoding of instruction bytes
  • Mode-aware instruction generation

Section 3. Validation and Semantic Assurance

  • Binary inspection and disassembly verification
  • Control flow graph reconstruction
  • Detecting undefined behavior
  • Ensuring privilege correctness
  • Verifying memory safety constraints
  • Performance profiling at instruction granularity

Chapter 8. Debugging and Verification Without an OS

Section 1. Hardware-Level Debugging Tools

  • Serial console diagnostics
  • JTAG and hardware debugging interfaces
  • Using QEMU and hardware emulators
  • GDB remote debugging
  • Breakpoints and watchpoints at machine level
  • Single-stepping instruction execution

Section 2. Fault Analysis and Recovery

  • Stack frame reconstruction
  • Register state inspection
  • Handling page faults and general protection faults
  • Diagnosing triple faults
  • Memory corruption detection
  • Structured crash reporting

Section 3. Deterministic Testing and Replay

  • Building reproducible test harnesses
  • Hardware simulation environments
  • Deterministic input injection
  • Fault injection testing
  • Measuring execution timing precisely
  • Regression testing for binary code

The Leanpub 60 Day 100% Happiness Guarantee

Within 60 days of purchase you can get a 100% refund on any Leanpub purchase, in two clicks.

Now, this is technically risky for us, since you'll have the book or course files either way. But we're so confident in our products and services, and in our authors and readers, that we're happy to offer a full money back guarantee for everything we sell.

You can only find out how good something is by trying it, and because of our 100% money back guarantee there's literally no risk to do so!

So, there's no reason not to click the Add to Cart button, is there?

See full terms...

Earn $8 on a $10 Purchase, and $16 on a $20 Purchase

We pay 80% royalties on purchases of $7.99 or more, and 80% royalties minus a 50 cent flat fee on purchases between $0.99 and $7.98. You earn $8 on a $10 sale, and $16 on a $20 sale. So, if we sell 5000 non-refunded copies of your book for $20, you'll earn $80,000.

(Yes, some authors have already earned much more than that on Leanpub.)

In fact, authors have earned over $14 million writing, publishing and selling on Leanpub.

Learn more about writing on Leanpub

Free Updates. DRM Free.

If you buy a Leanpub book, you get free updates for as long as the author updates the book! Many authors use Leanpub to publish their books in-progress, while they are writing them. All readers get free updates, regardless of when they bought the book or how much they paid (including free).

Most Leanpub books are available in PDF (for computers) and EPUB (for phones, tablets and Kindle). The formats that a book includes are shown at the top right corner of this page.

Finally, Leanpub books don't have any DRM copy-protection nonsense, so you can easily read them on any supported device.

Learn more about Leanpub's ebook formats and where to read them

Write and Publish on Leanpub

You can use Leanpub to easily write, publish and sell in-progress and completed ebooks and online courses!

Leanpub is a powerful platform for serious authors, combining a simple, elegant writing and publishing workflow with a store focused on selling in-progress ebooks.

Leanpub is a magical typewriter for authors: just write in plain text, and to publish your ebook, just click a button. (Or, if you are producing your ebook your own way, you can even upload your own PDF and/or EPUB files and then publish with one click!) It really is that easy.

Learn more about writing on Leanpub