Page 1 of 2
Can't get a working bootloader in my old 8086
Posted: Sun Apr 04, 2010 8:25 pm
by dc740
Hello again. I tried to run "BOOTPROG" (a really simple bootloader), but it hangs without showing any error message. The floppy drive has the light on (looks like it's reading) but it doesn't do anything else... it just hangs there.
I also tried another 16 bit real mode bootloader... and for my surprise... the same happened. the bootloader started, it showed "Loading"... then it started to read from the diskette... and the same problem again... it hangs with the floppy drive light on (and it doesn't SOUND to be reading... I'm sure you remember the sound of those old 5 1/4 diskettes)
I tried the same diskettes in a Pentium Celeron... and they worked... so the diskettes are OK. and both bootloaders work fine
I tried to boot DOS in the 8086 machine... and it works... so the 8086 is ok, and the floppy drive is working too (I also tried to run a few programs and they worked smoothly)
Any suggestions? I suppose the bootloaders are using some instruction that hangs the 8086... or maybe the floppy drive needs some special commands that the DOS bootloader handles correctly?
Re: Can't get a working bootloader in my old 8086
Posted: Sun Apr 04, 2010 9:26 pm
by Gigasoft
Most bootloaders use instructions that didn't exist on the 8086. Even something like shr [bp+11],4 won't work on an 8086. The result is often a crash. One of the very first instructions of BOOTPROG is shl ax, 6, which obviously won't work. Then there's push word main. That instruction doesn't exist either.
Re: Can't get a working bootloader in my old 8086
Posted: Mon Apr 05, 2010 12:25 am
by assainator
you could use emu8086. It is a 8086 emulator. So you can test your code here first.
hope it helps,
assainator
Re: Can't get a working bootloader in my old 8086
Posted: Mon Apr 05, 2010 9:16 am
by Love4Boobies
Hi. There are several differences between 8086 and 80386+ boxen, specifically:
- 80386+ CPUs support extended registers, which is the most likely cause of your problems. (Don't worry about fancy instructions, I've never seen them in boot sectors.)
- The support for EDD - however, in order to support the API, extended registers are needed anyway.
- The PUSH/POP problem where SP is (dec/inc)remented before or after the store/store.
It is also common for BIOS implementors to use a buggy loading address for the boot sector (07C00:0000 instead of 0000:7C00) - they do translate to the same physical address but that is not always enough.
Re: Can't get a working bootloader in my old 8086
Posted: Mon Apr 05, 2010 10:09 am
by dc740
thanks! I will use emu8086 and I'll try to debug the problem...
I already knew about the extended registers... the bootloader is completely written in 16 bits assembly.
where can I find the documentation on the differences that could be causing this code not to work?
I want to write something specific for the 8086... I know I don't have protected mode (nor the very basic 286 pmode) so that's not the problem. I just need plain 16 bit 8086 compatible code.
Thanks!
Re: Can't get a working bootloader in my old 8086
Posted: Mon Apr 05, 2010 11:33 am
by Love4Boobies
dc740 wrote:where can I find the documentation on the differences that could be causing this code not to work?
I doubt anyone bothered to write a such a document. If you have problems figuring it out, post the code here and we'll take a peek at it.
Re: Can't get a working bootloader in my old 8086
Posted: Mon Apr 05, 2010 3:59 pm
by Gigasoft
The main differences would be:
- No fixed shift/rotate other than by 1
- No imul with 2 or 3 operands
- No push immediate
- No FS and GS registers
- No bound, ins and outs instructions
- No bit manipulation instructions or any other instructions beginning with 0F
- Push SP pushes the new value of SP instead of the old
- Offsets wrap around at 10000h instead of causing GPF
- Addresses wrap around at 100000h
- After a divide error, the saved IP points to the next instruction
- Will trace through ISRs
- IDIV with result equal to 80h (byte) or 8000h (word) causes divide error
- Shift/rotate uses the entire value of CL, not just the low 5 bits
- No invalid opcode, GPF or stack fault exceptions
Re: Can't get a working bootloader in my old 8086
Posted: Mon Apr 05, 2010 5:45 pm
by Love4Boobies
Gigasoft wrote:- Addresses wrap around at 100000h
They wrap around even on newer processors, that's why the PC BIOS disables the A20 gate.
Re: Can't get a working bootloader in my old 8086
Posted: Tue Apr 06, 2010 7:55 am
by dc740
Wow! thanks! you ROCK!!!
that's exactly what I needed! I'll try to modify to bootloader to get it working on the 8086.
thanks for your help!
Re: Can't get a working bootloader in my old 8086
Posted: Tue Apr 06, 2010 1:00 pm
by jal
Love4Boobies wrote:Don't worry about fancy instructions, I've never seen them in boot sectors.
As Gigasoft correctly pointed out, e.g. shl with anything but cl and 1 causes a hang. I wouldn't consider "shl al, 2" very fancy.
The PUSH/POP problem where SP is (dec/inc)remented before or after the store/store.
That is
not a problem, that's an implementation choice.
It is also common for BIOS implementors to use a buggy loading address for the boot sector (07C00:0000 instead of 0000:7C00) - they do translate to the same physical address but that is not always enough.
There is nothing "buggy" about using 07c00:0000 instead of 0000:7c00. And yes, that
is always the same physical addess in real mode (i.e. 7c000).
I doubt anyone bothered to write a such a document.
Err... you really think that back when the 80286 was released nobody "bothered to write" a document explaining the differences?!
I'm not sure what you were smoking when you write all this, l4b, but usually you're a lot more informative and closer to the truth. Please refrain from posting, especially when someone else (in this case Gigasoft) has already posted everything the OP needed to know.
JAL
Re: Can't get a working bootloader in my old 8086
Posted: Tue Apr 06, 2010 1:36 pm
by qw
Au contraire, 07c00:0000 is VERY buggy... Though it is physical address 7c000, unlike 0000:7c00.
Re: Can't get a working bootloader in my old 8086
Posted: Tue Apr 06, 2010 6:27 pm
by earlz
Hi, you may be interested in looking at this:
http://www.ousob.com/ng/iapx86/ng2e5.php it gives a list of instructions and the processor in which they appeared (for instructions like shl, click through and it'll say which exact opcodes are specific to a CPU)
Also, you may want to look at my own opcode list when I made an 8086 emulator.
http://x86lib.svn.sourceforge.net/viewv ... iew=markup
start at line 75. It's fairly easy to read:
Code: Select all
201 void op16_cmpsw(); //tested, pass #1, full
202 void op16_jcxz_rel8();
203 void op16_adc_al_imm8();
204 void op16_adc_ax_imm8();
205 void op16_adc_rm8_r8();
159 void op16_mov_m16_imm16();
op16_ means which set of opcodes is it (I only have 16 bit ones) and then comes the instruction name, and then the arguments. `al` of course means the register AL and such, and `imm8` means an immediate byte. `rel8` means an 8 byte relative address. rm8 means a Mod R/M byte that points to an 8 byte value. `r8` means an 8 bit register. `sr` means a segment register `m16` is an odd one. It is a Mod R/M, except for the R portion can not be used. `off8` is a 16 bit absolute address to an 8 byte value.
Also, I do have a few inconsistencies such as `call_imm16_imm16` for a far call which was really an edge case to my whole argument naming scheme.
Re: Can't get a working bootloader in my old 8086
Posted: Wed Apr 07, 2010 12:25 am
by jal
Hobbes wrote:Au contraire, 07c00:0000 is VERY buggy... Though it is physical address 7c000, unlike 0000:7c00.
Of course, I must've been asleep. I meant 07c0:0000 of course, 7c00 would not boot at all. No BIOS is *that* buggy :).
JAL
Re: Can't get a working bootloader in my old 8086
Posted: Wed Apr 07, 2010 1:32 am
by Love4Boobies
jal wrote:The PUSH/POP problem where SP is (dec/inc)remented before or after the store/store.
That is
not a problem, that's an implementation choice.
It's
not an implementation choice - the wrong SP value is being pushed. The way around this is to replace all occurences of "push sp" with:
The "pop sp" version should be obvious.
It is also common for BIOS implementors to use a buggy loading address for the boot sector (07C00:0000 instead of 0000:7C00) - they do translate to the same physical address but that is not always enough.
There is nothing "buggy" about using 07c00:0000 instead of 0000:7c00. And yes, that
is always the same physical addess in real mode (i.e. 7c000).
It
is a bug as many people on this forum will tell you - the BIOS Boot Specification specifically defines the address 0000:7C00h to make sure that code will
always work - the same physical address will
not be enough as a simple relative jump will screw everything over. A workaround is a workaround is a workaround.
I doubt anyone bothered to write a such a document.
Err... you really think that back when the 80286 was released nobody "bothered to write" a document explaining the differences?!
I meant officially. And to go through unofficial material is more often than not unreliable. I'm also missing the link in your post to such a list so you are obviously in a bad mood and randomly trying to start a flame with someone.
I'm not sure what you were smoking when you write all this, l4b, but usually you're a lot more informative and closer to the truth. Please refrain from posting, especially when someone else (in this case Gigasoft) has already posted everything the OP needed to know.
In case you need glasses, my post came before Gigasoft's post. Before trying to start a flame with me please make sure you know what you're talking about, you troll.
And now, being less OT, there are also other differences - for instance:
- Divide exceptions in the 8086 will leave CS:IP pointing to the following instruction.
- after reset CS:IP = F000:FFF0 vs. the 8086 FFFF:0000, in order to allow sufficient code space to enter pmode without reloading CS.
- Do not rely on IDIV exceptions for quotients of 80H or 8000H. The 8086 will cause exception 0.
Hope I'm being informative enough this time.
Re: Can't get a working bootloader in my old 8086
Posted: Wed Apr 07, 2010 1:57 am
by qw
dc740 wrote:Wow! thanks! you ROCK!!!
that's exactly what I needed! I'll try to modify to bootloader to get it working on the 8086.
thanks for your help!
Most assemblers have a directive that limits the instruction set to a certain processor. On NASM it is "CPU 8086", on MASM ".8086". It will generate an error if you accidentally use an instruction for a later processor.
Roel