Add explicit sizes to all instructions. Use movl for segment register moves

to avoid unnecessary size overrides.  Simplify halt sequences.
This commit is contained in:
mycroft 1994-02-03 23:20:25 +00:00
parent e30d1e5df6
commit 1f71230441
4 changed files with 142 additions and 205 deletions

View File

@ -54,10 +54,9 @@ WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
#include "asm.h"
CR0_PE_ON = 0x1
CR0_PE_OFF = 0xfffffffe
CR0_PE = 0x1
.globl _ouraddr
.globl EXT(ouraddr)
.text
/*
@ -76,11 +75,11 @@ ENTRY(real_to_prot)
lgdt EXT(Gdtr)
# set the PE bit of CR0
mov %cr0, %eax
movl %cr0, %eax
data32
or $CR0_PE_ON, %eax
mov %eax, %cr0
orl $CR0_PE, %eax
movl %eax, %cr0
# make intrasegment jump to flush the processor pipeline and
# reload CS register
@ -90,10 +89,10 @@ ENTRY(real_to_prot)
xprot:
# we are in USE32 mode now
# set up the protected mode segment registers : DS, SS, ES
mov $0x20, %eax
movw %ax, %ds
movw %ax, %ss
movw %ax, %es
movl $0x20, %eax
movl %ax, %ds
movl %ax, %ss
movl %ax, %es
# load idtr so we can debug
lidt EXT(Idtr_prot)
@ -113,7 +112,7 @@ ENTRY(prot_to_real)
movl _ouraddr, %eax
sarl $4, %eax
pushw %ax
movw $xreal, %ax # gas botches pushw $xreal - extra bytes 0, 0
movl $xreal, %eax # gas botches pushw $xreal - extra bytes 0, 0
pushw %ax # decode to add %al, (%eax) (%al usually 0)
# Change to use16 mode.
@ -121,10 +120,10 @@ ENTRY(prot_to_real)
x16:
# clear the PE bit of CR0
mov %cr0, %eax
movl %cr0, %eax
data32
and $CR0_PE_OFF, %eax
mov %eax, %cr0
andl $~CR0_PE, %eax
movl %eax, %cr0
# make intersegment jmp to flush the processor pipeline
# using the fake stack frame set up earlier
@ -134,10 +133,10 @@ x16:
xreal:
# we are in real mode now
# set up the real mode segment registers : DS, SS, ES
movw %cs, %ax
movw %ax, %ds
movw %ax, %ss
movw %ax, %es
movl %cs, %ax
movl %ax, %ds
movl %ax, %ss
movl %ax, %es
# load idtr so we can debug
addr32
@ -155,15 +154,15 @@ xreal:
*/
ENTRY(startprog)
push %ebp
mov %esp, %ebp
pushl %ebp
movl %esp, %ebp
# get things we need into registers
movl 0x8(%ebp), %ecx # entry offset
movl 0x0c(%ebp), %eax # &argv
# make a new stack at 0:0xa0000 (big segs)
mov $0x10, %ebx
movl $0x10, %ebx
movw %bx, %ss
movl $0xa0000, %ebx
movl %ebx, %esp
@ -178,14 +177,14 @@ ENTRY(startprog)
pushl $0 # dummy 'return' address
# push on our entry address
mov $0x08, %ebx # segment
movl $0x08, %ebx # segment
pushl %ebx
pushl %ecx
# convert over the other data segs
mov $0x10, %ebx
movw %bx, %ds
movw %bx, %es
movl $0x10, %ebx
movl %bx, %ds
movl %bx, %es
# convert the PC (and code seg)
lret
@ -196,29 +195,29 @@ ENTRY(startprog)
*/
ENTRY(pbzero)
push %ebp
mov %esp, %ebp
push %es
push %edi
push %ecx
pushl %ebp
movl %esp, %ebp
pushl %es
pushl %edi
pushl %ecx
cld
# set %es to point at the flat segment
mov $0x10, %eax
movw %ax, %es
movl $0x10, %eax
movl %ax, %es
mov 0x8(%ebp), %edi # destination
mov 0xc(%ebp), %ecx # count
mov $0x0, %eax # value
movl 0x8(%ebp), %edi # destination
movl 0xc(%ebp), %ecx # count
movl $0x0, %eax # value
rep
stosb
pop %ecx
pop %edi
pop %es
pop %ebp
popl %ecx
popl %edi
popl %es
popl %ebp
ret
/*
@ -229,31 +228,30 @@ ENTRY(pbzero)
*/
ENTRY(pcpy)
push %ebp
mov %esp, %ebp
push %es
push %esi
push %edi
push %ecx
pushl %ebp
movl %esp, %ebp
pushl %es
pushl %esi
pushl %edi
pushl %ecx
cld
# set %es to point at the flat segment
mov $0x10, %eax
movw %ax, %es
movl $0x10, %eax
movl %ax, %es
mov 0x8(%ebp), %esi # source
mov 0xc(%ebp), %edi # destination
mov 0x10(%ebp), %ecx # count
movl 0x8(%ebp), %esi # source
movl 0xc(%ebp), %edi # destination
movl 0x10(%ebp), %ecx # count
rep
movsb
pop %ecx
pop %edi
pop %esi
pop %es
pop %ebp
popl %ecx
popl %edi
popl %esi
popl %es
popl %ebp
ret

View File

@ -70,13 +70,13 @@ WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
ENTRY(biosread)
push %ebp
mov %esp, %ebp
pushl %ebp
movl %esp, %ebp
push %ebx
push %ecx
push %edx
push %es
pushl %ebx
pushl %ecx
pushl %edx
pushl %es
movb 0x10(%ebp), %dh
movw 0x0c(%ebp), %cx
@ -98,19 +98,19 @@ ENTRY(biosread)
int $0x13
cli
mov %eax, %ebx # save return value (actually movw %ax, %bx)
movl %eax, %ebx # save return value (actually movw %ax, %bx)
data32
call EXT(real_to_prot) # back to protected mode
xor %eax, %eax
xorl %eax, %eax
movb %bh, %al # return value in %ax
pop %es
pop %edx
pop %ecx
pop %ebx
pop %ebp
popl %es
popl %edx
popl %ecx
popl %ebx
popl %ebp
ret
@ -126,17 +126,17 @@ ENTRY(biosread)
ENTRY(putc)
push %ebp
mov %esp, %ebp
push %ebx
push %ecx
pushl %ebp
movl %esp, %ebp
pushl %ebx
pushl %ecx
movb 0x8(%ebp), %cl
call EXT(prot_to_real)
data32
mov $0x1, %ebx # %bh=0, %bl=1 (blue)
movl $0x1, %ebx # %bh=0, %bl=1 (blue)
movb $0xe, %ah
movb %cl, %al
sti
@ -146,9 +146,9 @@ ENTRY(putc)
data32
call EXT(real_to_prot)
pop %ecx
pop %ebx
pop %ebp
popl %ecx
popl %ebx
popl %ebp
ret
@ -161,9 +161,9 @@ ENTRY(putc)
*/
ENTRY(getc)
push %ebp
mov %esp, %ebp
push %ebx # save %ebx
pushl %ebp
movl %esp, %ebp
pushl %ebx # save %ebx
call EXT(prot_to_real)
@ -177,11 +177,11 @@ ENTRY(getc)
data32
call EXT(real_to_prot)
xor %eax, %eax
xorl %eax, %eax
movb %bl, %al
pop %ebx
pop %ebp
popl %ebx
popl %ebp
ret
/*
# ischar()
@ -197,13 +197,13 @@ ENTRY(getc)
# Zero flag = set
*/
ENTRY(ischar)
push %ebp
mov %esp, %ebp
push %ebx
pushl %ebp
movl %esp, %ebp
pushl %ebx
call EXT(prot_to_real) # enter real mode
xor %ebx, %ebx
xorl %ebx, %ebx
movb $0x1, %ah
sti
int $0x16
@ -216,11 +216,11 @@ nochar:
data32
call EXT(real_to_prot)
xor %eax, %eax
xorl %eax, %eax
movb %bl, %al
pop %ebx
pop %ebp
popl %ebx
popl %ebp
ret
/*
@ -231,12 +231,12 @@ nochar:
*/
ENTRY(get_diskinfo)
push %ebp
mov %esp, %ebp
push %es
push %ebx
push %ecx
push %edx
pushl %ebp
movl %esp, %ebp
pushl %es
pushl %ebx
pushl %ecx
pushl %edx
movb 0x8(%ebp), %dl # diskinfo(drive #)
call EXT(prot_to_real) # enter real mode
@ -274,11 +274,11 @@ ok:
andb $0x3f, %cl # mask of cylinder gunk
movb %cl, %al # max sector (and # sectors)
pop %edx
pop %ecx
pop %ebx
pop %es
pop %ebp
popl %edx
popl %ecx
popl %ebx
popl %es
popl %ebp
ret
/*
@ -292,11 +292,11 @@ ok:
*/
ENTRY(memsize)
push %ebp
mov %esp, %ebp
push %ebx
pushl %ebp
movl %esp, %ebp
pushl %ebx
mov 8(%ebp), %ebx
movl 8(%ebp), %ebx
call EXT(prot_to_real) # enter real mode
@ -316,12 +316,12 @@ xext: movb $0x88, %ah
cli
xdone:
mov %eax, %ebx
movl %eax, %ebx
data32
call EXT(real_to_prot)
mov %ebx, %eax
pop %ebx
pop %ebp
movl %ebx, %eax
popl %ebx
popl %ebp
ret

View File

@ -32,10 +32,6 @@
#define BOOT_CS_INDEX 3
#define BOOT_CS16_INDEX 5
#define BOOT_DS_INDEX 4
#define DB_CS_INDEX 14
#define DB_CS16_INDEX 15
#define DB_DS_INDEX 16
#define GDT_INDEX 17
/* Vector numbers. */
#define BREAKPOINT_VECTOR 3
@ -50,9 +46,9 @@
ENTRY(boot2)
data32
subl %eax, %eax
mov %cs, %ax
mov %ax, %ds
mov %ax, %es
movl %cs, %ax
movl %ax, %ds
movl %ax, %es
data32
shll $4, %eax
addr32
@ -67,7 +63,7 @@ ENTRY(boot2)
movb %bl, EXT(Gdt)+(8*gdt_index)+4
data32
shld $16, %eax, %ebx
shldl $16, %eax, %ebx
FIXUP(BOOT_CS_INDEX)
FIXUP(BOOT_CS16_INDEX)
FIXUP(BOOT_DS_INDEX)
@ -77,9 +73,6 @@ ENTRY(boot2)
movl %eax, %ecx
data32
addl $ EXT(Gdt), %eax
data32
shld $16, %eax, %ebx
FIXUP(GDT_INDEX)
addr32
data32
movl %eax, EXT(Gdtr)+2
@ -89,60 +82,6 @@ ENTRY(boot2)
data32
movl %ecx, EXT(Idtr_prot)+2
/* %es = vector table segment for a while */
push %es
data32
subl %eax, %eax
mov %ax, %es
#ifdef BDB
/* fix up GDT entries for bdb */
data32
movl $4*DEBUG_VECTOR, %esi
addr32
movl %es: 2(%esi), %eax /* actually movw to %ax */
data32
shll $4, %eax
data32
shld $16, %eax, %ebx
FIXUP(DB_CS_INDEX)
FIXUP(DB_CS16_INDEX)
FIXUP(DB_DS_INDEX)
/* Fetch entry points of bdb's protected mode trap handlers. These
* are stored at 2 before the corresponding entry points for real mode.
*/
data32
subl %ebx, %ebx
addr32
movl %es: (%esi), %ebx /* actually movw to %bx */
data32
subl %ecx, %ecx
addr32
movl %es: 4*(BREAKPOINT_VECTOR-DEBUG_VECTOR)(%esi), %ecx
/* actually movw to %cx */
/* %es = bdb segment for a while */
data32
shrl $4, %eax
mov %ax, %es
/* XXX appears to be broken */
/* fix up IDT entries for bdb */
subl $2, %ebx
movl %es:(%edi), %eax /* actually movw %es:(%bx), %ax */
addr32
movl %eax, EXT(Idt)+8*DEBUG_VECTOR /* actually movw %ax */
movl %ecx, %ebx
subl $2, %ebx
movl %es:(%edi), %eax /* actually movw %es:(%bx), %ax */
addr32
movl %eax, EXT(Idt)+8*BREAKPOINT_VECTOR /* actually movw %ax */
#endif
/* finished with groping in real mode segments */
pop %es
/* change to protected mode */
data32
call EXT(real_to_prot)
@ -159,8 +98,8 @@ ENTRY(boot2)
pushl %edx
call EXT(boot)
oops:
cli
hlt
jmp oops
.data
.align 2

View File

@ -74,22 +74,22 @@ start:
start1:
# set up %ds
mov %cs, %ax
mov %ax, %ds
movl %cs, %ax
movl %ax, %ds
# set up %ss and %esp
data32
mov $BOOTSEG, %eax
mov %ax, %ss
movl $BOOTSEG, %eax
movl %ax, %ss
data32
mov $BOOTSTACK, %esp
movl $BOOTSTACK, %esp
/*** set up %es, (where we will load boot2 to) ***/
mov %ax, %es
movl %ax, %es
#ifdef DEBUG
data32
mov $one, %esi
movl $one, %esi
data32
call message
#endif
@ -103,18 +103,18 @@ fd:
# reset the disk system
#ifdef DEBUG
data32
mov $two, %esi
movl $two, %esi
data32
call message
#endif
movb $0x0, %ah
int $0x13
data32
mov $0x0001, %ecx # cyl 0, sector 1
movl $0x0001, %ecx # cyl 0, sector 1
movb $0, %dh # head
#ifdef DEBUG
data32
mov $three, %esi
movl $three, %esi
data32
call message
#endif
@ -124,18 +124,18 @@ fd:
hd: /**** load sector 0 into the BOOTSEG ****/
#ifdef DEBUG
data32
mov $four, %esi
movl $four, %esi
data32
call message
#endif
data32
mov $0x0201, %eax
xor %ebx, %ebx # %bx = 0
movl $0x0201, %eax
xorl %ebx, %ebx # %bx = 0
data32
mov $0x0001, %ecx
movl $0x0001, %ecx
#ifdef DEBUG
data32
mov $five, %esi
movl $five, %esi
data32
call message
#endif
@ -148,9 +148,9 @@ hd: /**** load sector 0 into the BOOTSEG ****/
/***# find the first 386BSD partition *****/
data32
mov $PARTSTART, %ebx
movl $PARTSTART, %ebx
data32
mov $NUMPART, %ecx
movl $NUMPART, %ecx
again:
addr32
movb %es:4(%ebx), %al
@ -158,11 +158,11 @@ again:
data32
je found
data32
add $PARTSZ, %ebx
addl $PARTSZ, %ebx
data32
loop again
data32
mov $enoboot, %esi
movl $enoboot, %esi
data32
jmp err_stop
@ -189,7 +189,7 @@ found:
load:
movb $0x2, %ah /* function 2 */
movb $LOADSZ, %al /* number of blocks */
xor %ebx, %ebx /* %bx = 0, put it at 0 in the BOOTSEG */
xorl %ebx, %ebx /* %bx = 0, put it at 0 in the BOOTSEG */
int $0x13
data32
jb read_error
@ -200,7 +200,7 @@ load:
#ifdef DEBUG
data32
mov $six, %esi
movl $six, %esi
data32
call message
#endif
@ -213,7 +213,7 @@ load:
read_error:
data32
mov $eread, %esi
movl $eread, %esi
err_stop:
data32
call message
@ -232,11 +232,11 @@ message:
*/
data32
push %eax
pushl %eax
data32
push %ebx
pushl %ebx
data32
mov $0x0001, %ebx
movl $0x0001, %ebx
cld
nextb:
@ -250,15 +250,15 @@ nextb:
jmp nextb
done:
data32
pop %ebx
popl %ebx
data32
pop %eax
popl %eax
data32
ret
stop: hlt
data32
jmp stop # halt doesnt actually halt forever
stop:
cli
hlt
/* error messages */