Check A20 code

Programming, for all ages and all languages.
Post Reply
alaroldai
Posts: 19
Joined: Sat May 07, 2011 6:34 am

Check A20 code

Post by alaroldai »

Hey guys, just starting out writing an os from scratch (that is, bootloader and all). I've got a lot of design ideas but in order to test them I need to finish my bootloader. I'm adapting the code for checking whether the A20 line is open from the wiki to AT&T syntax rather than Intel, and most of it's fine. But for some reason there are some registers (DS and ES, I think) that I'm apparently not allowed to push to stack:

Code: Select all

checka20:
    pushf						# Push flags to stack
    push %ds					# Push important registers to stack
    push %es
    push %di
    push %si

Code: Select all

boot.s:96: Error: operand type mismatch for `push'
boot.s:97: Error: operand type mismatch for `push'
As you can see, the other registers push fine. It's just the DS and ES registers that screw up.
User avatar
Combuster
Member
Member
Posts: 9301
Joined: Wed Oct 18, 2006 3:45 am
Libera.chat IRC: [com]buster
Location: On the balcony, where I can actually keep 1½m distance
Contact:

Re: Check A20 code

Post by Combuster »

Are you using something else than a GCC Cross-Compiler? This works for me:

Code: Select all

combuster@daphnis ~/dev $ cat test.s
.section .text
main:
push %es
push %ds
pop %ds
pop %es
combuster@daphnis ~/dev $ i386-elf-as test.s -o test.o
combuster@daphnis ~/dev $ objdump -S test.o

test.o:     file format elf32-i386


Disassembly of section .text:

00000000 <main>:
   0:	06                   	push   %es
   1:	1e                   	push   %ds
   2:	1f                   	pop    %ds
   3:	07                   	pop    %es
combuster@daphnis ~/dev $ 
"Certainly avoid yourself. He is a newbie and might not realize it. You'll hate his code deeply a few years down the road." - Sortie
[ My OS ] [ VDisk/SFS ]
User avatar
qw
Member
Member
Posts: 792
Joined: Mon Jan 26, 2009 2:48 am

Re: Check A20 code

Post by qw »

alaroldai wrote:As you can see, the other registers push fine. It's just the DS and ES registers that screw up.
Probably you should use "pushw" instead of "push".
User avatar
Owen
Member
Member
Posts: 1700
Joined: Fri Jun 13, 2008 3:21 pm
Location: Cambridge, United Kingdom
Contact:

Re: Check A20 code

Post by Owen »

Hobbes wrote:
alaroldai wrote:As you can see, the other registers push fine. It's just the DS and ES registers that screw up.
Probably you should use "pushw" instead of "push".
pushw will cause 16-bit pushes in 32-bit protected mode. This is probably not what you want
User avatar
qw
Member
Member
Posts: 792
Joined: Mon Jan 26, 2009 2:48 am

Re: Check A20 code

Post by qw »

Owen wrote:pushw will cause 16-bit pushes in 32-bit protected mode. This is probably not what you want
I understood that the code is from a boot loader so it is 16-bits anyway.
alaroldai
Posts: 19
Joined: Sat May 07, 2011 6:34 am

Re: Check A20 code

Post by alaroldai »

Yeah, at this point it's still in 16-bit real mode. First it checks for the A20 line, then it tries to set it, then it switches to protected mode. I tried using pushw, it gives exactly the same error. I'm compiling on Ubuntu 11.04 (64 bit), without using a cross-compiler. Should I be using a cross-compiler? I can't see how that would make much difference (except maybe the version of gas I've got doesn't let you mess with the segment registers because that's the operating system's job?), but I'll give it a go... do I have to download and build it all myself, or is there an Ubuntu package for binutils, etc? Can I just run "sudo apt-get binutils-something"?

**update: I found the "GCC Cross-Compiler on Debian Linux" page, very helpful. I'll give it a try in a minute.

**update 2: Mostly, worked fine, but I haven't tested it yet. I got one error on apt-get update:

Code: Select all

W: Failed to fetch http://www.pedigree-project.org/debian/dists/stable/main/binary-amd64/Packages  404  Not Found
Last edited by alaroldai on Mon May 09, 2011 8:29 pm, edited 1 time in total.
alaroldai
Posts: 19
Joined: Sat May 07, 2011 6:34 am

Re: Check A20 code

Post by alaroldai »

Still got the same errors:

Code: Select all

checka20:
	pushf						# Push flags to stack
    push %ds					# Push important registers to stack
    push %es
    push %di
    push %si
 
    cli							# Clear interrupts
 
    xor %ax, %ax				# Set ax = 0
    mov %ax, %es
 
    not %ax						# ax = 0xFFFF
    mov %ax, %ds					
 
    mov $0x0500, %di
    mov $0x0510, %si
 
    movl %es:(%di), %al
    push %ax
 
    movl %ds:(%si), %al
    push %ax
 
    movl $0x00, %es:(%di)
    movl $0xFF, %ds:(%si)
 
    cmpl $0xFF, %es:(%di)
 
    pop %ax
    mov %al, %ds:(%si)
 
    pop %ax
    mov %al, %es:(%di)
 
    mov $0, %ax
    je check_a20__exit
 
    mov $1, %ax
 
check_a20__exit:
    pop %si
    pop %di
    pop %es
    pop %ds
    popf
 
    ret

Code: Select all

alaroldai@alaroldai-MacBook:~/projects/ROSE/boot$ x86_64-elf-gcc boot.s -o boot.o
boot.s: Assembler messages:
boot.s:96: Error: suffix or operands invalid for `push'
boot.s:97: Error: suffix or operands invalid for `push'
boot.s:112: Error: `%es:(%di)' is not a valid base/index expression
boot.s:115: Error: `%ds:(%si)' is not a valid base/index expression
boot.s:118: Error: `%es:(%di)' is not a valid base/index expression
boot.s:119: Error: `%ds:(%si)' is not a valid base/index expression
boot.s:121: Error: `%es:(%di)' is not a valid base/index expression
boot.s:124: Error: `%ds:(%si)' is not a valid base/index expression
boot.s:127: Error: `%es:(%di)' is not a valid base/index expression
boot.s:137: Error: suffix or operands invalid for `pop'
boot.s:138: Error: suffix or operands invalid for `pop'
gerryg400
Member
Member
Posts: 1801
Joined: Thu Mar 25, 2010 11:26 pm
Location: Melbourne, Australia

Re: Check A20 code

Post by gerryg400 »

Code: Select all

push %ds
is not a valid instruction in 64 bit mode.
If a trainstation is where trains stop, what is a workstation ?
alaroldai
Posts: 19
Joined: Sat May 07, 2011 6:34 am

Re: Check A20 code

Post by alaroldai »

yeah, but I'm not in 64 bit mode yet - this is bootloader code. My computer should still boot into 16-bit real mode, right?
gerryg400
Member
Member
Posts: 1801
Joined: Thu Mar 25, 2010 11:26 pm
Location: Melbourne, Australia

Re: Check A20 code

Post by gerryg400 »

alaroldai wrote:yeah, but I'm not in 64 bit mode yet - this is bootloader code. My computer should still boot into 16-bit real mode, right?
Does your compiler/assembler know that you want to generate 16bit code ?
If a trainstation is where trains stop, what is a workstation ?
alaroldai
Posts: 19
Joined: Sat May 07, 2011 6:34 am

Re: Check A20 code

Post by alaroldai »

Gaah!

Rookie error.

Forgot to put .code16 at the top of the text section. =D>
Casm
Member
Member
Posts: 221
Joined: Sun Oct 17, 2010 2:21 pm
Location: United Kingdom

Re: Check A20 code

Post by Casm »

Isn't disabling the A20 line a piece of nonsense the hardware designers should have left behind long ago? It's about twenty years since anybody has had to worry about how addresses above 1mb are interpreted.
User avatar
DavidCooper
Member
Member
Posts: 1150
Joined: Wed Oct 27, 2010 4:53 pm
Location: Scotland

Re: Check A20 code

Post by DavidCooper »

Casm wrote:Isn't disabling the A20 line a piece of nonsense the hardware designers should have left behind long ago? It's about twenty years since anybody has had to worry about how addresses above 1mb are interpreted.
It might matter to someone's old program, so why would they ditch this and not ditch all the other legacy stuff at the same time? It only takes a few bytes of code to enable it anyway, and it looks as if you can just leave it open after that even if you want to use BIOS services - I haven't met a BIOS yet that closes it or that goes wrong on account of it being open. Has anyone had any problems when calling the BIOS with the A20 on?
Help the people of Laos by liking - https://www.facebook.com/TheSBInitiative/?ref=py_c

MSB-OS: http://www.magicschoolbook.com/computing/os-project - direct machine code programming
Casm
Member
Member
Posts: 221
Joined: Sun Oct 17, 2010 2:21 pm
Location: United Kingdom

Re: Check A20 code

Post by Casm »

DavidCooper wrote:It might matter to someone's old program, so why would they ditch this and not ditch all the other legacy stuff at the same time? It only takes a few bytes of code to enable it anyway, and it looks as if you can just leave it open after that even if you want to use BIOS services - I haven't met a BIOS yet that closes it or that goes wrong on account of it being open. Has anyone had any problems when calling the BIOS with the A20 on?
Just how old would the said program have to be before it relied upon addresses wraping round above 0xFFFFF?

Even the majority of MS-DOS programs didn't need it.

It is a question of where you draw the line. At the moment it would be ridiculous if support for legacy PICs disappeared from motherboards, but twenty years from now it will be a different story.
Post Reply