Бутлоадер для Z80 с ОЗУ без ПЗУ

Postby lvd » 17 Jan 2019, 19:36

((https://web.archive.org/web/20070206094 ... 80boot.htm попизжено отсюда, схоронено тут во избежание))

Bootloading Z80 using NMI, RESET and CLOCK.

Z80 system without ROM. Using NMI, RESET and CLOCK to bootload.

An NMI will push a value on the stack. The value depends on the instruction address at the time where NMI is given. At beginning is the memory contens unknown, and it is only possible to know the address immidiately after NMI is given (0066H). Because instructions is unknown, will it not be possible to know the address later.

The memory will need to be filled with a known value to control it.

To fill out memory with known values, is a lot of NMI's given, until all memory is filled by pushing 0067H to stack.

The value may not actualy be 0067H because some instruction is more than one byte. Jump and restarts cause another address too. After all memory is filled first time, by using a lot of NMI's, is the adress at 0066H filled with a new value. This value will in near all cases, not be an instrucition that change address (jump or restart), and at next run arround do NMI's store 0067H in all memory. If the orginal instruction at 0066H, is a two or three byte instruction, then 67H to 69H is stored at 0066H for next run arround. They are four cycle, normal load instructions, and they work too and does that 0067H is stored in all memory.

The number of cycles to fill memory is one run arround with any instruction at 0066H, and another with any four cycle instruction after changing the address at 0066H.
Any instruction at 0066H:
The 4-cycle instruction after modifying 0066H:
Total cycles of fill:
5+3+3+23 cycles.
5+3+3+4 cycles.
ramsize * 49 cycles.

If no oscillator is used, is the clock controlled by the PC, else is fill done by releasing clock, and running at 4MHz speed.

After filling, is all memory stored with 4 cycle load instructions, or 4 cycle NOP's, and the number of clock pulses to any instruction after NMI is known. An NMI push's the instruction address on stack, and sets the instruction pointer to 0066H. The clock is now controlled to the address that should be pushed next. It is possible to load the code by pushing values on the stack by an NMI at the address with the value that should be pushed into memory. Everytime NMI is given is instruction pointer set to 0066H by the processor. First is stackpointer unknown, and the instructions may be pushed anyplace in memory. To set stack as e.g. 400H, is 00 04 stored in memory. It does not change timing. It is importent that first push not change the timing, and only four cycle instructions is used. Next, is 00 31 stored. It change timing but it is not a problem. To store a low number as 04H, is starting with zero done by using reset before NMI is given. Memory does now contain 00 31 00 04 somewhere, and setting stack by executing all memory is done. (Running at 4MHz if external oscillator used). Since memory only contain load, nop, and the LD SP operation, is nothing else than stack loaded. Stack is now known, but the memory contain LD SP, n somewhere, and timing is not known. This is in this case handled by filling memory from address 400H and down to 001CH where bootloader is stored. The fill is done by using NMI as before, and with counting clocks. The possibility that the LD SP,n instruction was stored at 0066H is very small, even with a small memory system. It is possible to handle in code. (Unactivated code).

It is only possible to use instructions, with instruction code less than the address where the code is stored. If the stack is at top of memory, then most instructions are accessable. If memory is very small is less instructions accessable. To handle this, will it need to be loaded a bootloader. This bootloader use instructions from 0067H to 0100H+$ only, where $ is address of code to store, and the bootloader allow to be runned on a small system with 256 bytes only. (8085 + 8155 only, a two chip solution with I/O's).

The bootloader is saved into memory. It only uses instructions from 0067H to 0113H. The bootloader is stored at 0000H to 001BH and a 256 byte system use address 00H..1BH for instructions in range 0100H to 0100H+$. These instruction need to be stored before the address is used. Address is stored from top, and the instructions that use 0100H to 0113H is not in 0000H to 0013H address room.

The bootloader uses reset, and clock to store (or read) data. Operation depends on instruction at reset.

The bootloader is not critical to which value to store, and it is possible to change, modify, read etc. A15 is used to return with bit's from bootloader.

As far as I see may the methode be used for a wide range of CPU's. I have only testet it on Z80A, but more processors (8085) may be able to bootload using the methode.

The code, and the schematic, is attached to this document. Only the circuit schematic is needed. Oscillator circuit is not needed, but circuit is clocked by the PC if no oscillator circuit is used. Remember decoubling Z80 and 6116, by using capacitors under the chips if using sockets. Ack is used to indikate if oscillator circuit is used, or if all clocks is controlled by the PC.

Circuit - 2 chips only
z80cpu.gif

Oscillator (not needed)
z80osc.gif
z80osc.gif (5.17 KB) Viewed 6444 times

Source to control - use lpt port
z80v20.zip
(2.42 KB) Downloaded 680 times

Photo (decoubling is under the chips).
z80cpu.jpg
z80cpu.jpg (20.06 KB) Viewed 6444 times

Download files
z80boot3.zip
(27.66 KB) Downloaded 692 times


The software is updated to handle 256 byte systems. It should fail max 1 out of 10.000 powerups, teoretical. Normal, much less, since SRAM do not have the specific address to make it go down, because of its construction. Only cases, where instruction at 0066H is a jump, and only if the address of that jump, have some specific values, as beeing a jump instruction itself - will it be possible that it could fail. As example, C3 C3 C3 - but that is also, one out of a million. And that should be located at 0066H. Almost impossible, compared with typical values of SRAMs at power up. It also fail, if less than 256 bytes RAM, but this version (new) should work with only 256 bytes RAM. Previos version did not work with only 256 bytes memory, even that the text said it should. Both versions, only works, if RAM is at all locations, and no ROM is applied - then should the code be in ROM. The circuit, is only made for no ROM systems, in Z80 address space. I/O's should be in I/O space only, or could be used as RAM too.
F̞͖̭̿̔ͯu̐̅cͬ̑ͩk̨̤̳͇̮̭̪̠̽̿̓̆ͭͩ ̷̩̰͎̩͓̘̾̀ͬ̊ͭ͛ͅda̝̺͙̬͎̝̾͟ ̰̜̝̯͉̯̖̓̎́ͨ̽ͫ͟f̟͇̭̀ͬͨͭ̐̚u̹̼̹̗̞͑̔͂͐̚cͭ̅̊̆̒̆ǩ̝̩̯́ͥ̔̍̑ḭ͓͍̳̬ͦ̽͂n͍͎͈̈̅ͩͬ ̊ͫ̂̾̑̈́f̲͚͉͓͗̋́ͧͦ̅ȗ͇̲̻͈̲̅̎͗͒ͭ͡c̬̟̠̹̯̈́ͩ͘ͅk̫̠̻̋͜a̲͒̾̇!͙͕̺͉̗̩̲̂̏̄̀
User avatar
lvd
 
Posts: 7262
Joined: 07 Apr 2007, 21:28
Group: Registered users

Postby KOE » 21 Jan 2019, 22:30

Я жесткой логикой на фпга тест пзу для спектрума как-то делал. Байтов 15 или около того было.
Мы рождены, чтоб сказку сделать былью
"Кто не обломался, тем еще предстоит"
User avatar
KOE
 
Posts: 4682
Joined: 15 Apr 2007, 13:06
Group: Registered users

Postby KOE » 21 Jan 2019, 22:30

До сих пор иногда использую)))
Мы рождены, чтоб сказку сделать былью
"Кто не обломался, тем еще предстоит"
User avatar
KOE
 
Posts: 4682
Joined: 15 Apr 2007, 13:06
Group: Registered users


Return to Hardware

Who is online

Users browsing this forum: No registered users and 3 guests

cron