ยท Steve Grice ยท pagekey operating system  ยท 4 min read

OS20: Researching PCI (Peripheral Component Interconnect)

In this video, we make massive improvements to stdlib, add memset and memcpy, and most importantly, allow ourselves to get out of VGA (graphics) mode once we enter it.

Timestamps

  • 0:00 Debugging Walkthrough
  • 2:23 Full System Demo
  • 2:27 Demo on Real Hardware
  • 3:00 Slides: Major Changes
  • 6:06 Notes Walkthrough
  • 7:28 Merge Request Walkthrough

Notes

  • Only waste multiple lifetimes if you want hi res! Low res VGA is not too hard
  • VGA resources osdev
  • Can fix up the cursor:
  • Absolutely need a better way of analyzing memory - VGA and regular mem
  • Installed ghex for exploring dump-guest-memory
    • In qemu:
      • dump-guest-memory mem.bin
      • ghex mem.bin, CTL-F for stuff
  • https://qemu.readthedocs.io/en/latest/system/monitor.html
    • info ramblock
      • Has a vga ramblock etc
    • memsaveย addrย sizeย file
    • pmemsave addr size file
    • info mtree
  • https://qemu.readthedocs.io/en/latest/devel/memory.html
    • QEMU models:
      • Regular RAM
      • Memory-mapped IO (MMIO)
      • Rerouting physical memory
  • Acyclic graph of MemoryRegion objects
  • Types of regions
    • RAM
    • MMIO
    • ROM
    • ROM device
    • IOMMU
    • container (of other memory regions, for grouping)
    • alias
    • reservation
  • https://www.qemu.org/2018/02/09/understanding-qemu-devices/
    • Understanding QEMU Devices
    • โ€Most bare-metal machines are basically giant memory maps, where software poking at a particular address will have a particular side effectโ€
    • x86 has two memory spaces - main and I/O
    • Relevant to future video:
      • โ€œhow to manage an IDE disk - the driver is merely software that is programmed to make specific I/O requests to a specific subset of the memory map (wherever the IDE bus lives, which is specific to the hardware board).โ€œ
  • http://www.osdever.net/FreeVGA/vga/vgamem.htm
    • Accessing VGA memory
    • RAM Enable: Do we listen to the CPU?
    • Memory Map Select: Where do we read from?
    • 00 โ€” A0000h-BFFFFh โ€” 128K
      • pmemsave 0xa0000 128000 00.bin
    • 01 โ€” A0000h-AFFFFh โ€” 64K
      • pmemsave 0xa0000 64000 01.bin
    • 10 โ€” B0000h-B7FFFh โ€” 32K
      • pmemsave 0xa0000 32000 10.bin
    • 11 โ€” B8000h-BFFFFh โ€” 32K
      • pmemsave 0xa0000 32000 11.bin
  • https://www.kraxel.org/blog/2019/09/display-devices-in-qemu/
    • Display Devices in QEMU
  • https://blog.reds.ch/?p=1379
    • Accessing the RAM of a QEMU Emulated System from another Process
    • Can map qemu to /dev/shm file
  • How do we check RAM enable, Memory Map Select fields on VGA?
  • Which parts of memory can we save stuff in without breaking everything?
  • https://wiki.osdev.org/Memory_Map_(x86)
    • Memory Map (x86)
    • โ€œThe region of RAM above 1 MiB is not standardized, well-defined, or contiguous.โ€
    • I guess that means we just go for it??
    • 0x00100000-0x00EFFFFF: RAM - free for use if it exists
  • info mtree seems to have various named regions (a DAG)
(qemu) info mtree
address-space: memory
  0000000000000000-ffffffffffffffff (prio 0, i/o): system
    0000000000000000-0000000007ffffff (prio 0, i/o): alias ram-below-4g @pc.ram 0000000000000000-0000000007ffffff
  • Trying to access fields
  • http://www.osdever.net/FreeVGA/vga/graphreg.htm#06
    • Graphics Address Register, Graphics Data Register
    • Address reg: 0x3CE
    • Data reg: 0x3CF
    • Misc graphics reg: Index 0x06
  • http://www.osdever.net/FreeVGA/vga/vgareg.htm
    • Accessing Graphics Registers: each have two unique read/write ports
      • First: Address Register. Second: Data Register
      • Best to save/restore address register (in case youโ€™re in an ISR)
      • Steps
          1. Input the value of address register, save it (inb)
          1. Output index of desired data reg to addr reg
          1. Read value of data reg, save if needed
        • 4-5 only apply if writing
          1. Restore addr reg value
    • Accessing external registers
      • Simpler - just read/write to their ports
  • So for us that looks like:
    • RAM Enable - External Register / General Register
      • Read port 0x3CC
    • Memory Map Select - Graphics Register
      • Read port 0x3CE, save this value
      • Write 0x06 to 0x3CE
      • Read 0x3CF - this is misc graphics reg value
      • Write 0x3CE with original value
  • Okay - RAM Enable is 1, Memory Select is 11, which is 0xB8000 - MAKES SENSE!
  • http://www.osdever.net/FreeVGA/vga/seqreg.htm
    • Can select various character sets
  • https://wiki.osdev.org/VGA_Hardware#The_Sequencer
    • โ€The Sequencer either operates in text (alphanumeric) mode or graphics modeโ€
  • https://www.ardent-tool.com/video/VGA_Video_Modes.html

There are five tasks you must perform to coordinate the different components of the VGA subsystem:

  • Program the CRTC.
  • Program the sequencer.
  • Select a dot-clock frequency.
  • Specify the displayed character height.
  • Update relevant ROM BIOS variables.
Contents
Back to Blog