OSDev.org

The Place to Start for Operating System Developers
It is currently Tue Nov 19, 2019 4:57 am

All times are UTC - 6 hours




Post new topic This topic is locked, you cannot edit posts or make further replies.  [ 17 posts ]  Go to page 1, 2  Next
Author Message
 Post subject: Can't get a working bootloader in my old 8086
PostPosted: Sun Apr 04, 2010 8:25 pm 
Offline
Member
Member
User avatar

Joined: Sat Jul 04, 2009 12:43 am
Posts: 40
Location: Argentina
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?


Top
 Profile  
 
 Post subject: Re: Can't get a working bootloader in my old 8086
PostPosted: Sun Apr 04, 2010 9:26 pm 
Offline
Member
Member

Joined: Sat Nov 21, 2009 5:11 pm
Posts: 653
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.


Top
 Profile  
 
 Post subject: Re: Can't get a working bootloader in my old 8086
PostPosted: Mon Apr 05, 2010 12:25 am 
Offline
Member
Member

Joined: Sun Jan 24, 2010 1:12 am
Posts: 30
Location: The Netherlands
you could use emu8086. It is a 8086 emulator. So you can test your code here first.

hope it helps,
assainator

_________________
Every human has to do something idiot to prevent becoming a complete one


Top
 Profile  
 
 Post subject: Re: Can't get a working bootloader in my old 8086
PostPosted: Mon Apr 05, 2010 9:16 am 
Offline
Member
Member
User avatar

Joined: Fri Mar 07, 2008 5:36 pm
Posts: 2097
Location: Bucharest, Romania
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.

_________________
"Computers in the future may weigh no more than 1.5 tons.", Popular Mechanics (1949)
[ Project UDI ]


Top
 Profile  
 
 Post subject: Re: Can't get a working bootloader in my old 8086
PostPosted: Mon Apr 05, 2010 10:09 am 
Offline
Member
Member
User avatar

Joined: Sat Jul 04, 2009 12:43 am
Posts: 40
Location: Argentina
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!


Top
 Profile  
 
 Post subject: Re: Can't get a working bootloader in my old 8086
PostPosted: Mon Apr 05, 2010 11:33 am 
Offline
Member
Member
User avatar

Joined: Fri Mar 07, 2008 5:36 pm
Posts: 2097
Location: Bucharest, Romania
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.

_________________
"Computers in the future may weigh no more than 1.5 tons.", Popular Mechanics (1949)
[ Project UDI ]


Top
 Profile  
 
 Post subject: Re: Can't get a working bootloader in my old 8086
PostPosted: Mon Apr 05, 2010 3:59 pm 
Offline
Member
Member

Joined: Sat Nov 21, 2009 5:11 pm
Posts: 653
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


Top
 Profile  
 
 Post subject: Re: Can't get a working bootloader in my old 8086
PostPosted: Mon Apr 05, 2010 5:45 pm 
Offline
Member
Member
User avatar

Joined: Fri Mar 07, 2008 5:36 pm
Posts: 2097
Location: Bucharest, Romania
Gigasoft wrote:
- Addresses wrap around at 100000h


They wrap around even on newer processors, that's why the PC BIOS disables the A20 gate.

_________________
"Computers in the future may weigh no more than 1.5 tons.", Popular Mechanics (1949)
[ Project UDI ]


Top
 Profile  
 
 Post subject: Re: Can't get a working bootloader in my old 8086
PostPosted: Tue Apr 06, 2010 7:55 am 
Offline
Member
Member
User avatar

Joined: Sat Jul 04, 2009 12:43 am
Posts: 40
Location: Argentina
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! :)


Top
 Profile  
 
 Post subject: Re: Can't get a working bootloader in my old 8086
PostPosted: Tue Apr 06, 2010 1:00 pm 
Offline
Member
Member

Joined: Wed Oct 31, 2007 9:09 am
Posts: 1383
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.

Quote:
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.

Quote:
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).

Quote:
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


Top
 Profile  
 
 Post subject: Re: Can't get a working bootloader in my old 8086
PostPosted: Tue Apr 06, 2010 1:36 pm 
Offline
Member
Member
User avatar

Joined: Mon Jan 26, 2009 2:48 am
Posts: 792
Au contraire, 07c00:0000 is VERY buggy... Though it is physical address 7c000, unlike 0000:7c00.


Top
 Profile  
 
 Post subject: Re: Can't get a working bootloader in my old 8086
PostPosted: Tue Apr 06, 2010 6:27 pm 
Offline
Member
Member

Joined: Thu Jul 07, 2005 11:00 pm
Posts: 1546
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:
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.

_________________
My new NEW blag


Top
 Profile  
 
 Post subject: Re: Can't get a working bootloader in my old 8086
PostPosted: Wed Apr 07, 2010 12:25 am 
Offline
Member
Member

Joined: Wed Oct 31, 2007 9:09 am
Posts: 1383
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


Top
 Profile  
 
 Post subject: Re: Can't get a working bootloader in my old 8086
PostPosted: Wed Apr 07, 2010 1:32 am 
Offline
Member
Member
User avatar

Joined: Fri Mar 07, 2008 5:36 pm
Posts: 2097
Location: Bucharest, Romania
jal wrote:
Quote:
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:

Code:
push bp
mov bp, sp
xchg bp, [bp]


The "pop sp" version should be obvious.

Quote:
Quote:
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. :wink:

Quote:
Quote:
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.

Quote:
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.

_________________
"Computers in the future may weigh no more than 1.5 tons.", Popular Mechanics (1949)
[ Project UDI ]


Last edited by Love4Boobies on Wed Apr 07, 2010 2:06 am, edited 2 times in total.

Top
 Profile  
 
 Post subject: Re: Can't get a working bootloader in my old 8086
PostPosted: Wed Apr 07, 2010 1:57 am 
Offline
Member
Member
User avatar

Joined: Mon Jan 26, 2009 2:48 am
Posts: 792
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


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic This topic is locked, you cannot edit posts or make further replies.  [ 17 posts ]  Go to page 1, 2  Next

All times are UTC - 6 hours


Who is online

Users browsing this forum: Google [Bot] and 19 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group