Subject: .code16 changes for .S files
To: None <port-i386@netbsd.org>
From: David Laight <david@l8s.co.uk>
List: port-i386
Date: 12/12/2002 16:09:28
gas now supports .code16 and .code32 directives making it
possibly to 'demistify' much of the x86 low level boot code.
The attached patches apply the (relatively) mechanical change
to most of the relevant files.
Only one explicit addr32 byte is left (in pxeboot).
start_bootsect.S is absent because I have made non-trivial
changes to it - but that is where I did most of the testing.
I've given Frank the mbr.S code already.
I've tested dosboot. It gets into the boot code and will
give directory listing of a ufs filesystem, but wouldn't load
my big kernel.
I don't have anything to test rom_boot, and don't know what
pxe stands for :-) However all the 'difficult' instructions
seem to be coded properly.
David
Index: lib/bios_pci.S
===================================================================
RCS file: /cvsroot/syssrc/sys/arch/i386/stand/lib/bios_pci.S,v
retrieving revision 1.3
diff -u -r1.3 bios_pci.S
--- lib/bios_pci.S 1997/08/18 22:44:01 1.3
+++ lib/bios_pci.S 2002/12/12 15:41:36
@@ -57,23 +57,22 @@
pushl %edx
call _C_LABEL(prot_to_real) # enter real mode
+ .code16
movb $PCI_FUNCTION_ID, %ah
movb $PCI_BIOS_PRESENT, %al
int $0x1a
jnc ok1
- data32
movl $-1, %ebx
jmp err1
ok1:
- data32
- movl $0,%ebx
- mov %eax, %ebx # !!! at run time, it is mov %ax,%bx
+ xorl %ebx, %ebx
+ mov %ax, %bx
err1:
- data32
- call _C_LABEL(real_to_prot) # back to protected mode
+ calll _C_LABEL(real_to_prot) # back to protected mode
+ .code32
movl 8(%ebp), %eax
movl %edx, (%eax)
@@ -103,23 +102,22 @@
movl 16(%ebp), %esi
call _C_LABEL(prot_to_real) # enter real mode
+ .code16
movb $PCI_FUNCTION_ID, %ah
movb $FIND_PCI_DEVICE, %al
int $0x1a
jnc ok2
- data32
movl $-1, %edx
jmp err2
ok2:
- data32
movl $0,%edx
movb %ah, %dl
err2:
- data32
- call _C_LABEL(real_to_prot) # back to protected mode
+ calll _C_LABEL(real_to_prot) # back to protected mode
+ .code32
movl 20(%ebp), %eax
mov %bx, (%eax)
@@ -149,23 +147,22 @@
movl 12(%ebp), %edi
call _C_LABEL(prot_to_real) # enter real mode
+ .code16
movb $PCI_FUNCTION_ID, %ah
movb $READ_CONFIG_DWORD, %al
int $0x1a
jnc ok3
- data32
movl $-1, %edx
jmp err3
ok3:
- data32
movl $0,%edx
movb %ah, %dl
err3:
- data32
- call _C_LABEL(real_to_prot) # back to protected mode
+ calll _C_LABEL(real_to_prot) # back to protected mode
+ .code32
movl 16(%ebp), %eax
movl %ecx, (%eax)
@@ -196,23 +193,22 @@
movl 16(%ebp), %ecx
call _C_LABEL(prot_to_real) # enter real mode
+ .code16
movb $PCI_FUNCTION_ID, %ah
movb $WRITE_CONFIG_DWORD, %al
int $0x1a
jnc ok4
- data32
movl $-1, %edx
jmp err4
ok4:
- data32
movl $0,%edx
movb %ah, %dl
err4:
- data32
- call _C_LABEL(real_to_prot) # back to protected mode
+ calll _C_LABEL(real_to_prot) # back to protected mode
+ .code32
movl %edx, %eax # return value in %eax
Index: lib/biosdelay.S
===================================================================
RCS file: /cvsroot/syssrc/sys/arch/i386/stand/lib/biosdelay.S,v
retrieving revision 1.1.1.1
diff -u -r1.1.1.1 biosdelay.S
--- lib/biosdelay.S 1997/03/14 02:40:32 1.1.1.1
+++ lib/biosdelay.S 2002/12/12 15:41:37
@@ -59,6 +59,7 @@
movw 22(%esp), %cx
call _C_LABEL(prot_to_real)
+ .code16
movb $0x86, %ah
int $0x15
@@ -66,8 +67,8 @@
movb %ah, %bl # real_to_prot uses %eax
- data32
- call _C_LABEL(real_to_prot)
+ calll _C_LABEL(real_to_prot)
+ .code32
xorl %eax, %eax
movb %bl, %al
Index: lib/biosgetrtc.S
===================================================================
RCS file: /cvsroot/syssrc/sys/arch/i386/stand/lib/biosgetrtc.S,v
retrieving revision 1.2
diff -u -r1.2 biosgetrtc.S
--- lib/biosgetrtc.S 1997/06/13 13:42:27 1.2
+++ lib/biosgetrtc.S 2002/12/12 15:41:41
@@ -49,16 +49,16 @@
xorl %ebx, %ebx
call _C_LABEL(prot_to_real) # enter real mode
+ .code16
movb $2, %ah
int $0x1a
jnc ok
- data32
movl $-1, %ebx
ok:
- data32
- call _C_LABEL(real_to_prot) # back to protected mode
+ calll _C_LABEL(real_to_prot) # back to protected mode
+ .code32
movl 8(%ebp), %eax
movl $0, (%eax)
Index: lib/biosmca.S
===================================================================
RCS file: /cvsroot/syssrc/sys/arch/i386/stand/lib/biosmca.S,v
retrieving revision 1.2
diff -u -r1.2 biosmca.S
--- lib/biosmca.S 2001/05/14 22:14:47 1.2
+++ lib/biosmca.S 2002/12/12 15:41:41
@@ -55,9 +55,6 @@
#include <machine/asm.h>
-#define addr32 .byte 0x67
-#define data32 .byte 0x66
-
.data
.globl _C_LABEL(biosmca_ps2model)
_C_LABEL(biosmca_ps2model): .long 0
@@ -72,6 +69,7 @@
# instead of ISA).
*/
ENTRY(biosmca)
+ .code32
pushl %ebp
movl %esp, %ebp
pushl %ebx
@@ -82,33 +80,29 @@
push %eax
call _C_LABEL(prot_to_real) # enter real mode
+ .code16
# zero %cx
- data32
- xorl %cx, %cx
+ xor %cx, %cx
- data32
- xorl %ax, %ax
- movb $0xc0, %ah # subfunction
+ xor %ax, %ax
+ movb $0xc0, %ah # subfunction
int $0x15
jc back
# check feature byte 1 if MCA bus present and replaces ISA
- addr32
- movb %es:5(%ebx), %ax
- andw $0x02, %ax # bit 1 set means MCA instead of ISA
- cmpw $0x02, %ax # see also arch/i386/mca/mca_machdep.c
+ movw %es:5(%bx), %ax
+ andw $0x02, %ax # bit 1 set means MCA instead of ISA
+ cmpw $0x02, %ax # see also arch/i386/mca/mca_machdep.c
jne back
# save model and submodel bytes to %cx
- addr32
- movb %es:2(%ebx), %ch # model (1 byte)
- addr32
- movb %es:3(%ebx), %cl # submodel (1 byte)
+ movb %es:2(%bx), %ch # model (1 byte)
+ movb %es:3(%bx), %cl # submodel (1 byte)
back:
- data32
- call _C_LABEL(real_to_prot) # back to protected mode
+ calll _C_LABEL(real_to_prot) # back to protected mode
+ .code16
# save model
movl %ecx, _C_LABEL(biosmca_ps2model)
Index: lib/biosmem.S
===================================================================
RCS file: /cvsroot/syssrc/sys/arch/i386/stand/lib/biosmem.S,v
retrieving revision 1.5
diff -u -r1.5 biosmem.S
--- lib/biosmem.S 1997/08/18 22:44:01 1.5
+++ lib/biosmem.S 2002/12/12 15:41:42
@@ -49,15 +49,15 @@
push %edi
call _C_LABEL(prot_to_real)
+ .code16
int $0x12
# zero-extend 16-bit result to 32 bits.
- data32
movl $0, %ebx
- mov %eax,%ebx # !!! at run time, it is mov %ax,%bx
+ mov %ax,%bx
- data32
- call _C_LABEL(real_to_prot)
+ calll _C_LABEL(real_to_prot)
+ .code32
movl %ebx, %eax
@@ -77,17 +77,17 @@
push %edi
call _C_LABEL(prot_to_real)
+ .code16
movb $0x88,%ah
int $0x15
# zero-extend 16-bit result to 32 bits.
- data32
movl $0, %ebx
- mov %eax,%ebx # !!! at run time, it is mov %ax,%bx
+ mov %ax,%bx
- data32
- call _C_LABEL(real_to_prot)
+ calll _C_LABEL(real_to_prot)
+ .code32
movl %ebx, %eax
Index: lib/biosmemx.S
===================================================================
RCS file: /cvsroot/syssrc/sys/arch/i386/stand/lib/biosmemx.S,v
retrieving revision 1.2
diff -u -r1.2 biosmemx.S
--- lib/biosmemx.S 1999/03/08 21:38:28 1.2
+++ lib/biosmemx.S 2002/12/12 15:41:42
@@ -53,24 +53,21 @@
push %edi
call _C_LABEL(prot_to_real)
+ .code16
- data32
- movl $0xe801, %eax
+ movw $0xe801, %ax
int $0x15
jc err2
- data32
movl $0, %ecx
jmp ok2
err2:
- data32
movl $-1, %ecx
ok2:
- data32
movl %eax, %edx
- data32
- call _C_LABEL(real_to_prot)
+ calll _C_LABEL(real_to_prot)
+ .code32
movl 8(%ebp), %eax
movl %edx, (%eax)
@@ -108,15 +105,15 @@
movl 12(%ebp), %edi
call _C_LABEL(prot_to_real)
+ .code16
- data32
- movl $0xe820, %eax
+ movw $0xe820, %ax
int $0x15
setc %cl
- data32
- call _C_LABEL(real_to_prot)
+ calll _C_LABEL(real_to_prot)
+ .code32
movl 8(%ebp), %eax
movl %ebx, 0(%eax)
Index: lib/biosreboot.S
===================================================================
RCS file: /cvsroot/syssrc/sys/arch/i386/stand/lib/biosreboot.S,v
retrieving revision 1.1
diff -u -r1.1 biosreboot.S
--- lib/biosreboot.S 1997/04/13 18:45:37 1.1
+++ lib/biosreboot.S 2002/12/12 15:41:43
@@ -49,13 +49,14 @@
push %edi
call _C_LABEL(prot_to_real)
+ .code16
int $0x19
/* NOTE: We should never even get past this point. */
- data32
- call _C_LABEL(real_to_prot)
+ calll _C_LABEL(real_to_prot)
+ .code32
movl %ebx, %eax
Index: lib/biosvideomode.S
===================================================================
RCS file: /cvsroot/syssrc/sys/arch/i386/stand/lib/biosvideomode.S,v
retrieving revision 1.1
diff -u -r1.1 biosvideomode.S
--- lib/biosvideomode.S 2000/04/23 19:57:14 1.1
+++ lib/biosvideomode.S 2002/12/12 15:41:43
@@ -46,17 +46,17 @@
push %edi
call _C_LABEL(prot_to_real)
+ .code16
movb $0, %ah
movb $2, %al
int $0x10
# zero-extend 16-bit result to 32 bits.
- data32
movl $0, %ebx
- mov %eax,%ebx # !!! at run time, it is mov %ax,%bx
+ movw %ax,%bx # !!! at run time, it is mov %ax,%bx
- data32
- call _C_LABEL(real_to_prot)
+ calll _C_LABEL(real_to_prot)
+ .code32
movl %ebx, %eax
Index: lib/comio.S
===================================================================
RCS file: /cvsroot/syssrc/sys/arch/i386/stand/lib/comio.S,v
retrieving revision 1.2
diff -u -r1.2 comio.S
--- lib/comio.S 1997/10/27 19:51:18 1.2
+++ lib/comio.S 2002/12/12 15:41:43
@@ -25,6 +25,7 @@
movl 8(%ebp), %edx
call _C_LABEL(prot_to_real) # enter real mode
+ .code16
# Initialize the serial port (dl) to 9600 baud, 8N1.
movb $0xe3, %al
@@ -32,8 +33,8 @@
int $0x14
mov %ax,%bx
- data32
- call _C_LABEL(real_to_prot) # back to protected mode
+ calll _C_LABEL(real_to_prot) # back to protected mode
+ .code32
xor %eax,%eax
mov %bx,%ax
@@ -61,6 +62,7 @@
movl 12(%ebp),%edx
call _C_LABEL(prot_to_real) # enter real mode
+ .code16
movb %cl,%al
movb $0x01, %ah
@@ -68,8 +70,8 @@
movb %ah,%bl
- data32
- call _C_LABEL(real_to_prot) # back to protected mode
+ calll _C_LABEL(real_to_prot) # back to protected mode
+ .code32
xor %eax,%eax
movb %bl,%al
@@ -96,13 +98,14 @@
movl 8(%ebp),%edx
call _C_LABEL(prot_to_real) # enter real mode
+ .code16
movb $0x02, %ah
int $0x14
- movl %eax,%ebx # at run time, it is mov %ax,%bx
+ mov %ax, %bx
- data32
- call _C_LABEL(real_to_prot) # back to protected mode
+ calll _C_LABEL(real_to_prot) # back to protected mode
+ .code32
xor %eax,%eax
mov %bx,%ax
@@ -128,13 +131,14 @@
movl 8(%ebp),%edx
call _C_LABEL(prot_to_real) # enter real mode
+ .code16
movb $0x03, %ah
int $0x14
mov %ax,%bx
- data32
- call _C_LABEL(real_to_prot) # back to protected mode
+ calll _C_LABEL(real_to_prot) # back to protected mode
+ .code32
xor %eax,%eax
mov %bx,%ax
Index: lib/conio.S
===================================================================
RCS file: /cvsroot/syssrc/sys/arch/i386/stand/lib/conio.S,v
retrieving revision 1.1.1.1
diff -u -r1.1.1.1 conio.S
--- lib/conio.S 1997/03/14 02:40:32 1.1.1.1
+++ lib/conio.S 2002/12/12 15:41:44
@@ -24,15 +24,15 @@
movb 8(%ebp),%cl
call _C_LABEL(prot_to_real) # enter real mode
+ .code16
movb %cl,%al
- data32
- mov $1,%ebx
+ movw $1,%bx
movb $0x0e,%ah
int $0x10
- data32
- call _C_LABEL(real_to_prot) # back to protected mode
+ calll _C_LABEL(real_to_prot) # back to protected mode
+ .code32
pop %edi
pop %esi
@@ -52,13 +52,14 @@
push %edi
call _C_LABEL(prot_to_real) # enter real mode
+ .code16
movb $0x0,%ah
int $0x16
movb %al,%bl
- data32
- call _C_LABEL(real_to_prot) # back to protected mode
+ calll _C_LABEL(real_to_prot) # back to protected mode
+ .code32
xor %eax,%eax
movb %bl,%al
@@ -80,17 +81,18 @@
push %edi
call _C_LABEL(prot_to_real) # enter real mode
+ .code16
- xor %ebx,%ebx
+ xor %bx,%bx
movb $0x1,%ah
int $0x16
- data32
+ movb $0,%bl
jz 1f
- movb %al,%bl
+ incb %bl
1:
- data32
- call _C_LABEL(real_to_prot) # back to protected mode
+ calll _C_LABEL(real_to_prot) # back to protected mode
+ .code32
xor %eax,%eax
movb %bl,%al
Index: lib/dos_file.S
===================================================================
RCS file: /cvsroot/syssrc/sys/arch/i386/stand/lib/dos_file.S,v
retrieving revision 1.4
diff -u -r1.4 dos_file.S
--- lib/dos_file.S 1999/01/22 22:43:44 1.4
+++ lib/dos_file.S 2002/12/12 15:41:45
@@ -4,9 +4,6 @@
#include <machine/asm.h>
-#define addr32 .byte 0x67
-#define data32 .byte 0x66
-
/*
# MSDOS call "INT 0x21 Function 0x3d" to open a file.
# Call with %ah = 0x3d
@@ -19,37 +16,36 @@
_C_LABEL(doserrno): .long 1
ENTRY(dosopen)
- pushl %ebp
- movl %esp, %ebp
+ .code32
+ pushl %ebp
+ movl %esp, %ebp
pushl %edx
pushl %ebx
pushl %esi
pushl %edi
- movl 0x8(%ebp), %edx # File name.
+ movl 0x8(%ebp), %edx # File name.
call _C_LABEL(prot_to_real) # enter real mode
+ .code16
- movb $0x3d, %ah # Open existing file.
- movb $0x0 , %al # ro
+ movb $0x3d, %ah # Open existing file.
+ movb $0x0 , %al # ro
sti
int $0x21
cli
jnc ok1
- addr32
- movl %eax, _C_LABEL(doserrno)
- data32
+ mov %ax, _C_LABEL(doserrno)
movl $-1, %edx
jmp err1
ok1:
- data32
movl $0,%edx
- mov %eax, %edx # !!! at run time, it is mov %ax,%dx
+ mov %ax, %dx
err1:
- data32
- call _C_LABEL(real_to_prot) # back to protected mode
+ calll _C_LABEL(real_to_prot) # back to protected mode
+ .code32
movl %edx, %eax # return value in %eax
@@ -61,39 +57,38 @@
ret
ENTRY(dosread)
- pushl %ebp
- movl %esp, %ebp
+ .code32
+ pushl %ebp
+ movl %esp, %ebp
pushl %ebx
pushl %ecx
pushl %edx
pushl %esi
pushl %edi
- movl 0x8(%ebp), %ebx # File handle
- movl 0xc(%ebp), %edx # Buffer.
+ movl 0x8(%ebp), %ebx # File handle
+ movl 0xc(%ebp), %edx # Buffer.
movl 0x10(%ebp) , %ecx # Bytes to read
call _C_LABEL(prot_to_real) # enter real mode
+ .code16
- movb $0x3f, %ah # Read from file or device
+ movb $0x3f, %ah # Read from file or device
sti
int $0x21
cli
jnc ok2
- addr32
- movl %eax, _C_LABEL(doserrno)
- data32
+ mov %ax, _C_LABEL(doserrno)
movl $-1, %edx
jmp err2
ok2:
- data32
movl $0,%edx
- mov %eax, %edx # !!! at run time, it is mov %ax,%bx
+ mov %ax, %dx
err2:
- data32
- call _C_LABEL(real_to_prot) # back to protected mode
+ calll _C_LABEL(real_to_prot) # back to protected mode
+ .code32
movl %edx, %eax # return value in %eax
@@ -106,34 +101,33 @@
ret
ENTRY(dosclose)
+ .code32
pushl %ebp
movl %esp, %ebp
pushl %ebx
pushl %esi
pushl %edi
- movl 0x8(%ebp), %ebx # File handle
+ movl 0x8(%ebp), %ebx # File handle
call _C_LABEL(prot_to_real) # enter real mode
+ .code16
- movb $0x3e, %ah # Close file.
+ movb $0x3e, %ah # Close file.
sti
int $0x21
cli
jnc ok3
- addr32
- movl %eax, _C_LABEL(doserrno)
- data32
+ mov %ax, _C_LABEL(doserrno)
movl $-1, %ebx
jmp err3
ok3:
- data32
- movl $0,%ebx
+ movl $0, %ebx
err3:
- data32
- call _C_LABEL(real_to_prot) # back to protected mode
+ calll _C_LABEL(real_to_prot) # back to protected mode
+ .code32
movl %ebx, %eax # return value in %eax
@@ -144,43 +138,41 @@
ret
ENTRY(dosseek)
- pushl %ebp
- movl %esp, %ebp
+ .code32
+ pushl %ebp
+ movl %esp, %ebp
pushl %ebx
pushl %ecx
pushl %edx
pushl %esi
pushl %edi
- movl 0x8(%ebp), %ebx # File handle
- movl 0xc(%ebp), %ecx # Offset
+ movl 0x8(%ebp), %ebx # File handle
+ movl 0xc(%ebp), %ecx # Offset
movl 0x10(%ebp) , %edx # whence
call _C_LABEL(prot_to_real) # enter real mode
+ .code16
- movb $0x42, %ah # Seek
- movb %dl , %al # whence
- mov %cx, %dx #offs lo
- data32
- shr $0x10, %ecx #offs hi
+ movb $0x42, %ah # Seek
+ movb %dl, %al # whence
+ mov %cx, %dx #offs lo
+ shrl $0x10, %ecx #offs hi
sti
int $0x21
cli
jnc ok4
- addr32
- movl %eax, _C_LABEL(doserrno)
- data32
+ mov %ax, _C_LABEL(doserrno)
movl $-1, %edx
jmp err4
ok4:
- data32
- shl $0x10, %edx #new ofs hi
- mov %eax, %edx #new ofs lo - at run time, it is mov %ax,%dx
+ shll $0x10, %edx #new ofs hi
+ mov %ax, %dx #new ofs lo
err4:
- data32
- call _C_LABEL(real_to_prot) # back to protected mode
+ calll _C_LABEL(real_to_prot) # back to protected mode
+ .code32
movl %edx, %eax # return value in %eax
Index: lib/startprog.S
===================================================================
RCS file: /cvsroot/syssrc/sys/arch/i386/stand/lib/startprog.S,v
retrieving revision 1.2
diff -u -r1.2 startprog.S
--- lib/startprog.S 1999/03/01 12:46:16 1.2
+++ lib/startprog.S 2002/12/12 15:41:50
@@ -102,9 +102,9 @@
pushl %ecx #entry
# convert over the other data segs
- movl $flatdataseg, %ebx
- movl %bx, %ds
- movl %bx, %es
+ mov $flatdataseg, %bx
+ mov %bx, %ds
+ mov %bx, %es
# convert the PC (and code seg)
lret
Index: lib/crt/dos/start_dos.S
===================================================================
RCS file: /cvsroot/syssrc/sys/arch/i386/stand/lib/crt/dos/start_dos.S,v
retrieving revision 1.6
diff -u -r1.6 start_dos.S
--- lib/crt/dos/start_dos.S 1999/08/23 08:24:38 1.6
+++ lib/crt/dos/start_dos.S 2002/12/12 15:41:54
@@ -61,8 +61,6 @@
*/
#include <machine/asm.h>
-#define addr32 .byte 0x67
-#define data32 .byte 0x66
.data
.globl _C_LABEL(ourseg)
@@ -130,45 +128,36 @@
.text
ENTRY(start)
- data32
+ .code16
xorl %eax, %eax
- movl %cs, %ax
- movl %ax, %ds
- movl %ax, %es
- addr32
- data32
+ mov %cs, %ax
+ mov %ax, %ds
+ mov %ax, %es
movl %eax, _C_LABEL(ourseg)
- data32
shll $4, %eax
/* fix up GDT entries for bootstrap */
#define FIXUP(gdt_index) \
- addr32; \
- movl %eax, gdt+gdt_index+2; /* actually movw %ax */ \
- addr32; \
+ movw %ax, gdt+gdt_index+2; \
movb %bl, gdt+gdt_index+4
- data32
shldl $16, %eax, %ebx
FIXUP(bootcodeseg)
FIXUP(bootrealseg)
FIXUP(bootdataseg)
/* fix up GDT pointer */
- data32
addl $gdt, %eax
- addr32
- data32
movl %eax, gdtarg+2
/* change to protected mode */
- data32
- call _C_LABEL(real_to_prot)
+ calll _C_LABEL(real_to_prot)
+ .code32
/* clear the bss */
- movl $_C_LABEL(edata), %edi
- movl $_C_LABEL(end), %ecx
- subl %edi, %ecx
+ mov $_C_LABEL(edata), %di
+ mov $_C_LABEL(end), %cx
+ sub %di, %cx
subb %al, %al
rep
stosb
@@ -176,6 +165,7 @@
call _C_LABEL(doscommain)
ENTRY(exit)
call _C_LABEL(prot_to_real)
+ .code16
sti
movb $0x4c,%ah /* return */
int $0x21
@@ -187,33 +177,31 @@
* transfer from real mode to protected mode.
*/
ENTRY(real_to_prot)
+ .code16
# guarantee that interrupt is disabled when in prot mode
cli
# load the gdtr
- addr32
- data32
lgdt gdtarg
# set the PE bit of CR0
movl %cr0, %eax
- data32
orl $CR0_PE, %eax
movl %eax, %cr0
# make intrasegment jump to flush the processor pipeline and
# reload CS register
- data32
ljmp $bootcodeseg, $xprot
xprot:
+ .code32
# we are in USE32 mode now
# set up the protected mode segment registers : DS, SS, ES
movl $bootdataseg, %eax
- movl %ax, %ds
- movl %ax, %ss
- movl %ax, %es
+ movl %eax, %ds
+ movl %eax, %ss
+ movl %eax, %es
ret
@@ -235,27 +223,24 @@
ljmp $bootrealseg, $x16
x16:
+ .code16
# clear the PE bit of CR0
movl %cr0, %eax
- data32
andl $~CR0_PE, %eax
movl %eax, %cr0
# Here we have an 16 bits intersegment jump.
- .byte 0xea
- .word xreal
- .word 0
+ ljmp $0, $xreal /* segment patched above */
xreal:
# we are in real mode now
# set up the real mode segment registers : DS, SS, ES
- movl %cs, %ax
- movl %ax, %ds
- movl %ax, %ss
- movl %ax, %es
+ mov %cs, %ax
+ mov %ax, %ds
+ mov %ax, %ss
+ mov %ax, %es
sti
- data32
- ret
+ retl
/**************************************************************************
___MAIN - Dummy to keep GCC happy
@@ -268,6 +253,7 @@
* where dst is a physical address and cnt is the length
*/
ENTRY(pbzero)
+ .code32
pushl %ebp
movl %esp, %ebp
pushl %es
@@ -277,7 +263,7 @@
# set %es to point at the flat segment
movl $flatdataseg, %eax
- movl %ax, %es
+ movl %eax, %es
movl 8(%ebp), %edi # destination
movl 12(%ebp), %ecx # count
@@ -296,6 +282,7 @@
* where src is a virtual address and dst is a physical address
*/
ENTRY(vpbcopy)
+ .code32
pushl %ebp
movl %esp, %ebp
pushl %es
@@ -306,7 +293,7 @@
# set %es to point at the flat segment
movl $flatdataseg, %eax
- movl %ax, %es
+ movl %eax, %es
movl 8(%ebp), %esi # source
movl 12(%ebp), %edi # destination
@@ -326,6 +313,7 @@
* where src is a physical address and dst is a virtual address
*/
ENTRY(pvbcopy)
+ .code32
pushl %ebp
movl %esp, %ebp
pushl %ds
@@ -336,7 +324,7 @@
# set %ds to point at the flat segment
movl $flatdataseg, %eax
- movl %ax, %ds
+ movl %eax, %ds
movl 8(%ebp), %esi # source
movl 12(%ebp), %edi # destination
@@ -352,9 +340,10 @@
ret
ENTRY(vtophys)
- movl _C_LABEL(ourseg), %eax
+ .code32
+ movl _C_LABEL(ourseg), %eax
shll $4, %eax
- addl 4(%esp), %eax
+ addl 4(%esp), %eax
ret
#ifdef XMS
@@ -367,8 +356,9 @@
.text
ENTRY(checkxms)
- pushl %ebp
- movl %esp, %ebp
+ .code32
+ pushl %ebp
+ movl %esp, %ebp
pushl %ebx
pushl %edx
pushl %es
@@ -376,36 +366,32 @@
pushl %edi
call _C_LABEL(prot_to_real) # enter real mode
+ .code16
- .byte 0xb8 /* movw $0x4300,ax */
- .word 0x4300
- int $0x2f /* check if XMS installed */
+ movw $0x4300, %ax
+ int $0x2f /* check if XMS installed */
cmpb $0x80, %al
jnz noxms
- .byte 0xb8 /* movw $0x4310,ax */
- .word 0x4310
- int $0x2f /* get driver address */
-
- .byte 0x89,0x1e /* save es:bx to _xmsdrv */
- .word _C_LABEL(xmsdrv)
- .byte 0x8c,0x06
- .word _C_LABEL(xmsdrv)+2
+ movw $0x4310, %ax
+ int $0x2f /* get driver address */
- movb $0x08, %ah /* XMS: query free extended memory */
+ movw %bx, _C_LABEL(xmsdrv) /* save es:bx to _xmsdrv */
+ movw %es, _C_LABEL(xmsdrv) + 2
+
+ movb $0x08, %ah /* XMS: query free extended memory */
#if 0
movb $0x00, %bl
#endif
- .byte 0xff, 0x1e
- .word _C_LABEL(xmsdrv) /* result in dx */
+ lcall *_C_LABEL(xmsdrv)
jmp xdone
noxms: /* no XMS manager found */
- movl $0, %edx /* comes out as movw ! */
+ mov $0, %dx
xdone:
- data32
- call _C_LABEL(real_to_prot) # back to protected mode
+ calll _C_LABEL(real_to_prot) # back to protected mode
+ .code32
xorl %eax, %eax
movw %dx, %ax
@@ -428,8 +414,9 @@
Return value: a physical address.
*/
ENTRY(xmsalloc)
- pushl %ebp
- movl %esp, %ebp
+ .code32
+ pushl %ebp
+ movl %esp, %ebp
pushl %ebx
pushl %edx
pushl %esi
@@ -438,16 +425,15 @@
movl 0x8(%ebp), %edx # Kbytes needed
call _C_LABEL(prot_to_real) # enter real mode
+ .code16
- movb $0x09, %ah # XMS allocate block
- .byte 0xff,0x1e
- .word _C_LABEL(xmsdrv) # result: handle in %dx
- movb $0x0c, %ah # XMS lock block
- .byte 0xff,0x1e
- .word _C_LABEL(xmsdrv) # result: 32 bit physical address in DX:BX
+ movb $0x09, %ah # XMS allocate block
+ lcall *_C_LABEL(xmsdrv) # result: handle in %dx
+ movb $0x0c, %ah # XMS lock block
+ lcall *_C_LABEL(xmsdrv) # result: 32 bit physical addr in DX:BX
- data32
- call _C_LABEL(real_to_prot) # back to protected mode
+ calll _C_LABEL(real_to_prot) # back to protected mode
+ .code32
movl %edx, %eax
shl $16, %eax
@@ -465,6 +451,7 @@
* where src and dst are physical addresses
*/
ENTRY(ppbcopy)
+ .code32
pushl %ebp
movl %esp, %ebp
pushl %es
@@ -475,7 +462,7 @@
# set %es to point at the flat segment
movl $flatdataseg, %eax
- movl %ax, %es
+ movl %eax, %es
movl 8(%ebp), %esi # source
movl 12(%ebp), %edi # destination
Index: lib/crt/pxe/start_pxe.S
===================================================================
RCS file: /cvsroot/syssrc/sys/arch/i386/stand/lib/crt/pxe/start_pxe.S,v
retrieving revision 1.2
diff -u -r1.2 start_pxe.S
--- lib/crt/pxe/start_pxe.S 2002/05/10 23:21:17 1.2
+++ lib/crt/pxe/start_pxe.S 2002/12/12 15:41:55
@@ -43,14 +43,12 @@
*/
#include <machine/asm.h>
-#define addr32 .byte 0x67
-#define data32 .byte 0x66
.text
ENTRY(start)
+ .code16
# start is loaded at 0x0:0x7c00 but we want 0x7c0:0x0
# ljmp to the next instruction to adjust %cs
- data32
ljmp $0x7c0, $start1
# Our stack
@@ -58,29 +56,22 @@
start1:
# set up %ds
- data32
xorl %eax, %eax
- movl %cs, %ax
- movl %ax, %ds
+ mov %cs, %ax
+ mov %ax, %ds
# set up %ss and %esp
- movl %ax, %ss
- data32
+ mov %ax, %ss
movl $_C_LABEL(start), %esp
- addr32
- data32
movl %eax, _C_LABEL(ourseg)
shll $4, %eax
/* fix up GDT entries for bootstrap */
#define FIXUP(gdt_index) \
- addr32; \
- movl %eax, gdt+gdt_index+2; /* actually movw %ax */ \
- addr32; \
+ movw %ax, gdt+gdt_index+2; \
movb %bl, gdt+gdt_index+4
- data32
shldl $16, %eax, %ebx
FIXUP(bootcodeseg)
@@ -88,21 +79,18 @@
FIXUP(bootdataseg)
/* fix up GDT pointer */
- data32
addl $gdt, %eax
- addr32
- data32
movl %eax, gdtarg+2
/* change to protected mode */
- data32
- call _C_LABEL(real_to_prot)
+ calll _C_LABEL(real_to_prot)
+ .code16
/* clear bss */
- xorl %eax, %eax
- movl $_C_LABEL(edata), %edi
- movl $_C_LABEL(end), %ecx
- subl %edi, %ecx
+ xorl %eax, %eax
+ movl $_C_LABEL(edata), %edi
+ movl $_C_LABEL(end), %ecx
+ subl %edi, %ecx
cld
rep
stosb
@@ -113,18 +101,15 @@
.globl _C_LABEL(exit)
_C_LABEL(exit):
call _C_LABEL(prot_to_real)
- data32
- movl $efail, %esi
- data32
+ .code16
+ movw $efail, %si
call message
#ifdef notyet
/* sleep for 3s = 0x2dc6c0 us */
movb $0x86, %ah
- data32
- movl $0x002d, %ecx
- data32
- movl $0xc6c0, %edx
+ mov $0x002d, %cx
+ mov $0xc6c0, %dx
int $0x15
/* call ROM BASIC */
@@ -200,33 +185,31 @@
* transfer from real mode to protected mode.
*/
ENTRY(real_to_prot)
+ .code16
# guarantee that interrupt is disabled when in prot mode
cli
# load the gdtr
- addr32
- data32
lgdt gdtarg
# set the PE bit of CR0
movl %cr0, %eax
- data32
orl $CR0_PE, %eax
movl %eax, %cr0
# make intrasegment jump to flush the processor pipeline and
# reload CS register
- data32
ljmp $bootcodeseg, $xprot
xprot:
+ .code32
# we are in USE32 mode now
# set up the protected mode segment registers : DS, SS, ES
- movl $bootdataseg, %eax
- movl %ax, %ds
- movl %ax, %ss
- movl %ax, %es
+ mov $bootdataseg, %ax
+ mov %ax, %ds
+ mov %ax, %ss
+ mov %ax, %es
ret
@@ -235,6 +218,7 @@
* transfer from protected mode to real mode
*/
ENTRY(prot_to_real)
+ .code32
# set up a dummy stack frame for the second seg change.
# Adjust the intersegment jump instruction following
# the clearing of protected mode bit.
@@ -248,33 +232,31 @@
ljmp $bootrealseg, $x16
x16:
+ .code16
# clear the PE bit of CR0
movl %cr0, %eax
- data32
andl $~CR0_PE, %eax
movl %eax, %cr0
- # Here we have an 16 bits intersegment jump.
- .byte 0xea
- .word xreal
- .word 0
+ ljmp $0, $xreal /* segment overwritten above */
xreal:
+ .code16
# we are in real mode now
# set up the real mode segment registers : DS, SS, ES
- movl %cs, %ax
- movl %ax, %ds
- movl %ax, %ss
- movl %ax, %es
+ mov %cs, %ax
+ mov %ax, %ds
+ mov %ax, %ss
+ mov %ax, %es
sti
- data32
- ret
+ retl
/*
* pbzero(dst, cnt)
* where dst is a physical address and cnt is the length
*/
ENTRY(pbzero)
+ .code32
pushl %ebp
movl %esp, %ebp
pushl %es
@@ -284,7 +266,7 @@
# set %es to point at the flat segment
movl $flatdataseg, %eax
- movl %ax, %es
+ movl %eax, %es
movl 8(%ebp), %edi # destination
movl 12(%ebp), %ecx # count
@@ -303,6 +285,7 @@
* where src is a virtual address and dst is a physical address
*/
ENTRY(vpbcopy)
+ .code32
pushl %ebp
movl %esp, %ebp
pushl %es
@@ -313,7 +296,7 @@
# set %es to point at the flat segment
movl $flatdataseg, %eax
- movl %ax, %es
+ movl %eax, %es
movl 8(%ebp), %esi # source
movl 12(%ebp), %edi # destination
@@ -333,6 +316,7 @@
* where src is a physical address and dst is a virtual address
*/
ENTRY(pvbcopy)
+ .code32
pushl %ebp
movl %esp, %ebp
pushl %ds
@@ -343,7 +327,7 @@
# set %ds to point at the flat segment
movl $flatdataseg, %eax
- movl %ax, %ds
+ movl %eax, %ds
movl 8(%ebp), %esi # source
movl 12(%ebp), %edi # destination
@@ -368,6 +352,7 @@
* message: write the error message in %ds:%esi to the console
*/
message:
+ .code16
/*
* BIOS call "INT 10H Function 0Eh" to write character to console
* Call with %ah = 0x0e
@@ -375,34 +360,24 @@
* %bh = page
* %bl = foreground color
*/
- data32
pushl %eax
- data32
pushl %ebx
- data32
pushl %edx
nextb:
cld
lodsb # load a byte into %al
testb %al, %al
- data32
jz done
movb $0x0e, %ah
- data32
- movl $0x0001, %ebx
+ movw $0x0001, %bx
int $0x10
- data32
jmp nextb
done:
- data32
popl %edx
- data32
popl %ebx
- data32
popl %eax
- data32
ret
Index: lib/crt/rom/start_rom.S
===================================================================
RCS file: /cvsroot/syssrc/sys/arch/i386/stand/lib/crt/rom/start_rom.S,v
retrieving revision 1.8
diff -u -r1.8 start_rom.S
--- lib/crt/rom/start_rom.S 1999/11/07 01:06:37 1.8
+++ lib/crt/rom/start_rom.S 2002/12/12 15:41:56
@@ -7,7 +7,6 @@
#include <machine/asm.h>
#define addr32 .byte 0x67
-#define data32 .byte 0x66
reloc = RELOC
@@ -17,6 +16,7 @@
bootstack = BOOTSTACK
.text
+ .code16
textstart:
/* At entry, the processor is in 16 bit real mode and the code is being
@@ -45,61 +45,44 @@
pcidataend:
#endif
1:
- data32
pushl %eax
push %ds
- xorl %eax,%eax
- movl %ax, %ds
+ xor %ax,%ax
+ mov %ax, %ds
/* check signature */
- .byte 0xa1 /* MOV 0x304,%ax */
- .word 0x304
- .byte 0x3d /* CMP $0x4d52, %ax == 'MR' */
- .word 0x4d52
+ mov 0x304, %ax
+ cmp $0x4d52, %ax /* $0x4d52 == 'MR' */
jz 2f /* we have been here - don't clobber saved vector */
/* save old INT19 vector to a secret location (???) */
- .byte 0xa1 /* MOV 0x64, %ax */
- .word 0x64
- .byte 0xa3 /* MOV %ax, 0x300 */
- .word 0x300
- .byte 0xa1 /* MOV 0x66, %ax */
- .word 0x66
- .byte 0xa3 /* MOV %ax, 0x302 */
- .word 0x302
+ movw 0x64, %ax
+ movw %ax, 0x300
+ movw 0x66, %ax
+ movw %ax, 0x302
/* set INT19 vector to our entry */
- data32
movl $(_C_LABEL(start)-reloc), %eax
- .byte 0xa3 /* MOV %ax, 0x64 */
- .word 0x64
- movl %cs, %ax
- .byte 0xa3 /* MOV %ax, 0x66 */
- .word 0x66
-
- /* set a signature (is this a save location?) */
- .byte 0xb8 /* MOV 'MR',%ax */
- .word 0x4d52
- .byte 0xa3 /* MOV %ax, 0x304 */
- .word 0x304
+ movw %ax, 0x64
+ mov %cs, %ax
+ movw %ax, 0x66
+
+ /* set a signature (is this a safe location?) */
+ movw $0x4d52, %ax /* 0x4d52 == 'MR' */
+ movw %ax, 0x304
2: pop %ds
- data32
popl %eax
#ifdef ROMDEBUG
push %ds
pushl %eax
- movl %cs, %ax
- movl %ax, %ds
- popl %eax
- data32
+ mov %cs, %ax
+ mov %ax, %ds
+ pop %ax
pushl %esi
- data32
- movl $(imesg-textstart), %esi
- data32
- call message
- data32
+ movw $(imesg-textstart), %si
+ call message
popl %esi
pop %ds
#endif
@@ -117,39 +100,29 @@
* message: write the message in %ds:%esi to console
*/
message:
- data32
pushl %eax
- data32
pushl %ebx
- data32
pushl %edx
nextb:
cld
lodsb /* load a byte into %al */
testb %al, %al
- data32
jz done
movb $0x0e, %ah
- data32
- movl $0x0001, %ebx
+ movw $0x0001, %bx
int $0x10
- data32
jmp nextb
done:
movb $0x00, %ah /* wait for keypress */
- int $0x16
+ int $0x16
- data32
popl %edx
- data32
popl %ebx
- data32
popl %eax
- data32
ret
#endif /* ROMDEBUG */
@@ -159,90 +132,72 @@
**************************************************************************/
ENTRY(start)
+ .code16
cli
- movl %cs, %ax
- movl %ax, %ds
+ mov %cs, %ax
+ mov %ax, %ds
#ifdef ROMDEBUG
- data32
- movl $(cmesg-textstart), %esi
- data32
- call message
+ movw $(cmesg-textstart), %si
+ call message
#endif
cld
/* copy to reloc and jump to copy */
- xorl %esi, %esi
- xorl %edi, %edi
- data32
- movl $(reloc>>4), %eax
- movl %ax, %es
- data32
+ xor %si, %si
+ xor %di, %di
+ movw $(reloc>>4), %ax
+ mov %ax, %es
movl $(_C_LABEL(edata)-reloc), %ecx
cs
rep
movsb
- data32
- ljmp $(reloc>>4), $1f-reloc /* Jmp to RELOC:1f */
+ ljmpl $(reloc>>4), $1f-reloc /* Jmp to RELOC:1f */
1:
nop
- movl %cs, %ax
- movl %ax, %ds
- movl %ax, %es
- movl %ax, %ss
-#if 0 /* XXX why doesn't this work? */
- data32
- movl $bootstack, %eax
- movl %eax, %esp
-#else
- .byte 0xb8 /* MOV $STACKADDR, %ax */
- .word bootstack
- movl %eax, %esp
-#endif
+ mov %cs, %ax
+ mov %ax, %ds
+ mov %ax, %es
+ mov %ax, %ss
+ movw $bootstack, %ax
+ mov %ax, %sp
/* clear bss */
- xorl %eax, %eax
- data32
- movl $_C_LABEL(edata), %edi
- data32
- movl $_C_LABEL(end), %ecx
- subl %edi, %ecx
+ xor %ax, %ax
+ movl $_C_LABEL(edata), %edi
+ movl $_C_LABEL(end), %ecx
+ subw %di, %cx
cld
rep
stosb
#ifdef ROMDEBUG
- data32
- movl $(rmesg-textstart), %esi
- data32
- call message
+ mov $(rmesg-textstart), %si
+ call message
#endif
- data32
- call _C_LABEL(real_to_prot)
+ calll _C_LABEL(real_to_prot)
+ .code32
call _C_LABEL(main)
.globl _C_LABEL(exit)
_C_LABEL(exit):
call _C_LABEL(prot_to_real)
+ .code16
#ifdef ROMDEBUG
- data32
- movl $(emesg-textstart), %esi
- data32
- call message
+ mov $(emesg-textstart), %si
+ call message
#endif
/* jump to saved vector */
- xor %eax, %eax
- movl %ax, %ds
- .byte 0xa1 /* MOV 0x302, %ax */
- .word 0x302
- push %eax
- .byte 0xa1 /* MOV 0x300, %ax */
- .word 0x300
- push %eax
+ xor %ax, %ax
+ mov %ax, %ds
+ movw 0x302, %ax
+ push %ax
+ movw 0x300, %ax
+ push %ax
lret
/**************************************************************************
@@ -297,26 +252,27 @@
REAL_TO_PROT - Go from REAL mode to Protected Mode
**************************************************************************/
ENTRY(real_to_prot)
+ .code16
cli
- cs
- addr32
- lgdt gdtarg-reloc
+ .code32
+ addr32 /* don't know the syntax for this! */
+ lgdt %cs:gdtarg-reloc
+ .code16
movl %cr0, %eax
- data32
orl $CR0_PE, %eax
mov %eax, %cr0 /* turn on protected mode */
/* jump to relocation, flush prefetch queue, and reload %cs */
- data32
- ljmp $bootcodeseg, $1f
+ ljmpl $bootcodeseg, $1f
1:
+ .code32
/* reload other segment registers */
movl $bootdataseg, %eax
- movl %ax, %ds
- movl %ax, %es
- movl %ax, %ss
+ mov %ax, %ds
+ mov %ax, %es
+ mov %ax, %ss
add $reloc, %esp /* Fix up stack pointer */
pop %eax /* Fix up return Address */
add $reloc, %eax
@@ -328,42 +284,44 @@
PROT_TO_REAL - Go from Protected Mode to REAL Mode
**************************************************************************/
ENTRY(prot_to_real)
+ .code32
pop %eax
sub $reloc, %eax /* Adjust return address */
push %eax
sub $reloc, %esp /* Adjust stack pointer */
ljmp $bootrealseg, $1f /* jump to a 16 bit segment */
1:
+ .code16
/* clear the PE bit of CR0 */
mov %cr0, %eax
- data32
andl $~CR0_PE, %eax
mov %eax, %cr0
/* make intersegment jmp to flush the processor pipeline
* and reload CS register
*/
- data32
- ljmp $(reloc)>>4, $2f-reloc
+ ljmpl $(reloc)>>4, $2f-reloc
2:
/* we are in real mode now
* set up the real mode segment registers : DS, SS, ES
*/
- movl %cs, %ax
- movl %ax, %ds
- movl %ax, %es
- movl %ax, %ss
+ mov %cs, %ax
+ mov %ax, %ds
+ mov %ax, %es
+ mov %ax, %ss
sti
- data32
- ret
+ retl
ENTRY(pbzero)
+ .code32
jmp _C_LABEL(bzero)
ENTRY(vpbcopy)
ENTRY(pvbcopy)
+ .code32
jmp _C_LABEL(bcopy)
ENTRY(vtophys)
- movl 4(%esp), %eax
+ .code32
+ movl 4(%esp), %eax
ret
Index: pxeboot/pxe_call.S
===================================================================
RCS file: /cvsroot/syssrc/sys/arch/i386/stand/pxeboot/pxe_call.S,v
retrieving revision 1.2
diff -u -r1.2 pxe_call.S
--- pxeboot/pxe_call.S 2002/03/27 17:24:22 1.2
+++ pxeboot/pxe_call.S 2002/12/12 15:41:57
@@ -41,10 +41,6 @@
#include <machine/asm.h>
-#define addr32 .byte 0x67
-#define data32 .byte 0x66
-#define farcall .byte 0x9a
-
ENTRY(pxecall_bangpxe)
pushl %ebp
movl %esp, %ebp
@@ -60,18 +56,17 @@
pushw %bx
call _C_LABEL(prot_to_real) # enter real mode
+ .code16
/* The encoding is: 0x9a offlo offhi seglo seghi */
- farcall
+ lcall $0, $0xffff
.globl _C_LABEL(bangpxe_off)
-_C_LABEL(bangpxe_off):
- .word 0
+_C_LABEL(bangpxe_off) = . - 4
.globl _C_LABEL(bangpxe_seg)
-_C_LABEL(bangpxe_seg):
- .word 0
+_C_LABEL(bangpxe_seg) = . - 2
- data32
- call _C_LABEL(real_to_prot) # leave real mode
+ calll _C_LABEL(real_to_prot) # leave real mode
+ .code32
add $6, %esp
@@ -93,22 +88,20 @@
movl 8(%ebp), %ebx
call _C_LABEL(prot_to_real) # enter real mode
+ .code16
/* prot_to_real() has already set %es to BOOTSEG */
- addr32
- leal _C_LABEL(pxe_command_buf), %edi
+ lea _C_LABEL(pxe_command_buf), %di
/* The encoding is: 0x9a offlo offhi seglo seghi */
- farcall
+ lcall $0, $0xffff
.globl _C_LABEL(pxenv_off)
-_C_LABEL(pxenv_off):
- .word 0
+_C_LABEL(pxenv_off) = . - 4
.globl _C_LABEL(pxenv_seg)
-_C_LABEL(pxenv_seg):
- .word 0
+_C_LABEL(pxenv_seg) = . - 2
- data32
- call _C_LABEL(real_to_prot) # leave real mode
+ calll _C_LABEL(real_to_prot) # leave real mode
+ .code32
popl %edi
popl %edx
--
David Laight: david@l8s.co.uk