Octocontrabass wrote:
The original IBM BIOS didn't save and restore the A20 state. You should assume INT 0x15 AH=0x87 will return with A20 disabled.
That's what I meant. That's why I'm not tampering with A20 until I'm done with BIOS. (Although one of the A20 methods IS BIOS, yes).
Octocontrabass wrote:
If you don't mind forcing your compiled code and your stack to live within the first 64kB of memory alongside the IVT and BDA, you can use GCC.
Well, the only thing you really need to use GCC in 16-bit mode is a code model in which exactly one segment is used. It doesn't necessarily have to be segment 0, but all segment registers must be equal. Also, even 16-bit GCC code requires at least a 386, so if you had any plans to at least detect and filter out older CPUs, you will have to do that in the loader. And you will need an assembly loader.
BTW, that code is pretty simple (this one expects CS and DS to be 0, though):
Code:
cputooold:
movw $cpuoldmsg, %si
jmp error /* routine that prints the string at SI and then hangs in an infinite HLT loop */
cpuoldmsg: .asciz "CPU too old"
detect_cpu:
/* 8086 and 80186 handle PUSH SP differently from more modern CPUs */
pushw %sp
popw %ax
cmpw %ax, %sp
jnz cputooold
/* If we get here, we are on a 286 at least. The 186 introduced the "invalid opcode" exception, so I just use that. */
cli
movw $cputoold, 6*4
movw $0, 6*4+2
sti
movl $0x80000000, %eax
cpuid
cmpl $0x80000000, %eax
jbe cputooold
movl $0x80000001, %eax
cpuid
btl $29, %edx
jnc cputooold
I never understood why some people want to muck about with reserved bits in the flags register.
Schol-R-LEA wrote:
I don't really see that as being worth the effort, to be honest.
What effort? Subtracting the BDA and IVT, you have 64000 bytes of RAM to do with what you want, and all you need to do is load a file into memory and do some ancillary stuff. The only question is what to do with the other 62000 bytes. And since you can assume a 386 at least, you can also slightly extend your reach by way of inline assembler using the FS and GS segments.
Octocontrabass wrote:
Maybe. It depends on how much x86 assembly you can write before you get lost in your own code. (Certainly a problem I've run into...)
Yeah, I am getting there myself. I think I may want to rewrite parts of my ext2 loader in C. Because I am now at the stage where I need to do several loops over complicated data structures, and that is really not fun in assembler.