Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
(However, some BIOS' load to 0x7c0:0x0000 (segment 0x07c0, offset 0), which resolves to the same physical address, but can be surprising. A good practice is to enforce CS:IP at the very start of your boot sector.)
Indeed, Linux (used to) use that address for its bootsector (source). I actually put the text section at 0x7C00 with ld.
(However, some BIOS' load to 0x7c0:0x0000 (segment 0x07c0, offset 0), which resolves to the same physical address, but can be surprising. A good practice is to enforce CS:IP at the very start of your boot sector.)
Indeed, Linux (used to) use that address for its bootsector (source). I actually put the text section at 0x7C00 with ld.
No, you've done it right. Your bootloader performs a long jump to 0000:asmain right away, forcing CS and adjusting IP. Additionally, that would screw up all your memory references if it were wrong.
The problem has something to do with the location of the call in your bootloader. For example, if you wrap the first call to PrintRegister in a loop, it will happily print 0xDEAD over and over. If you delete a few instructions up above you can squeeze in another call to PrintRegister as well. But if the call is located too far into memory, it fails. I'm guessing something is overwriting part of your bootloader code in memory. At first I thought it was the stack, but I moved it around and still the same problem.
In QEMU, all four calls to PrintRegister take place. On the problematic laptops, only the first three seem to happen.
I've experienced the same issue.
intx13 wrote: I'm guessing something is overwriting part of your bootloader code in memory. At first I thought it was the stack, but I moved it around and still the same problem.
Or, perhaps, the code is overflowing the 512 bytes? However the adjacent area should be free for use...
Adjust the number of nops to effect the problem. No nops and it works fine. 4 nops and it prints out two exclamation points and hangs.
15 nops and it doesn't print anything. There's another number that will make it print repeatedly for maybe 10 seconds, then start printing a different character and then hang, but I forget how many.
This code doesn't use your print function, doesn't do anything but call int 0x13 repeatedly, so it would seem that BIOS is touching memory it shouldn't.
The whole computer is brand new, only like two weeks old. I am having different times computer freezes, and have the error that came from the log viewer:
AMI BIOS detected: BIOS may corrupt low RAM, working around it.
Well, there you go I guess. What kind of junky BIOS uses 7C00-7E00 for scratch space though?!
eisdt, your options moving forward are:
Relocate your code after boot to somewhere safe
Don't use those offending interrupts until you're executing somewhere else
/*
* Some BIOSes seem to corrupt the low 64k of memory during events
* like suspend/resume and unplugging an HDMI cable. Reserve all
* remaining free memory in that area and fill it with a distinct
* pattern.
*/
For a normal boot loader, you can guarantee the OS isn't doing suspend or resume, and the chance of the user plugging in or removing a HDMI cable while booting is almost zero. I doubt any of the boot loaders for Linux guard against this either.
A kernel might want to guard against this; but a kernel isn't a boot loader; and I suspect that you could create a copy of the area before suspend and check it after resume; and there's no reason to avoid the RAM itself during normal operation.
Cheers,
Brendan
For all things; perfection is, and will always remain, impossible to achieve in practice. However; by striving for perfection we create things that are as perfect as practically possible. Let the pursuit of perfection be our guide.