How do you write an operating system, if you have no operating system? Pencil and paper. I'm old enough to have written assembly code in pencil and paper, and assembled it myself, and then typed the binary code into a low-level "monitor" program that came in ROM on my computer. That code coincidentally was the BIOS (the IO system, like device drivers) for cp/m; once I had that working, I was able to boot cp/m.
How do you load the first operating system, if you have no operating system, not even a ROM monitor? You toggle it into the front panel switches. Early computers had complex consoles, which allowed reading and writing memory, and executing individual instructions. For example, I used to use a 24-bit minicomputer (sold in Europe as the Philips P7000, and in the US as "Four Phase Systems") which had no ROM monitor. To boot it, you had to toggle in three or four instructions from the panel and execute them; those were something like "initialize the CPU control word", "load a specific sector from the disk controller", and "branch to that sector".
There is a story (probably apocryphal) that Seymour Cray toggles the while first OS for an early computer (the Univac 1103 or the first CDC) into the front panel, from written notes, then stored it on disk, from which it was distributed.