summaryrefslogtreecommitdiff
path: root/sys/arch/i386/stand/libsa/gidt.S
diff options
context:
space:
mode:
authorDale Rahn <drahn@cvs.openbsd.org>2003-04-17 03:43:20 +0000
committerDale Rahn <drahn@cvs.openbsd.org>2003-04-17 03:43:20 +0000
commit6bb480fd6df5d8e084142751e0b25183459561d6 (patch)
treebaf77d01ee85f750e1cf66d7c3c5fd85b7b5bc07 /sys/arch/i386/stand/libsa/gidt.S
parentd36015cb7ad92f7024a5754fc18618f0b0e13139 (diff)
i386 ELF bootloader. developed with weingart@
Diffstat (limited to 'sys/arch/i386/stand/libsa/gidt.S')
-rw-r--r--sys/arch/i386/stand/libsa/gidt.S219
1 files changed, 90 insertions, 129 deletions
diff --git a/sys/arch/i386/stand/libsa/gidt.S b/sys/arch/i386/stand/libsa/gidt.S
index 6faa27cfb73..85a32bb55bd 100644
--- a/sys/arch/i386/stand/libsa/gidt.S
+++ b/sys/arch/i386/stand/libsa/gidt.S
@@ -1,4 +1,4 @@
-/* $OpenBSD: gidt.S,v 1.24 2001/09/17 13:10:09 deraadt Exp $ */
+/* $OpenBSD: gidt.S,v 1.25 2003/04/17 03:43:18 drahn Exp $ */
/*
* Copyright (c) 1997 Michael Shalayeff
@@ -41,9 +41,6 @@
#undef _LOCORE
#include <assym.h>
-#define addr32 .byte 0x67
-#define data32 .byte 0x66
-
#define SNULL 0x00
#define S32TEXT 0x08
#define S32DATA 0x10
@@ -52,26 +49,17 @@
#ifdef GIDT_DEBUG
#define gidt_debug0 ; \
- movl $0xb8000, %eax ; \
- movl $0x47314730, (%eax)
+ mov $0xb8000, %eax ; \
+ mov $0x47314730, (%eax)
#define gidt_debug1 ; \
- data32 ; \
- movl $(0xb8000 - LINKADDR), %eax ; \
- data32 ; \
- addr32 ; \
- movl $0x4f314f30, (%eax)
+ mov $(0xb8000 - LINKADDR), %eax ; \
+ mov $0x4f314f30, (%eax)
#define gidt_debug2 ; \
- data32 ; \
- movl $0xb8004, %eax ; \
- data32 ; \
- addr32 ; \
- movl $0x47334732, (%eax)
+ mov $0xb8004, %eax ; \
+ mov $0x47334732, (%eax)
#define gidt_debug3 ; \
- data32 ; \
- movl $0xb8004, %eax ; \
- data32 ; \
- addr32 ; \
- movl $0x4f334f32, (%eax)
+ mov $0xb8004, %eax ; \
+ mov $0x4f334f32, (%eax)
#define gidt_debug4 ; \
movl $0xb8008, %eax ; \
movl $0x47344733, (%eax)
@@ -86,58 +74,47 @@
#define prot2real \
gidt_debug0; \
\
- movl $S16DATA, %ax; \
- /* ljmp $S16TEXT, $1f */; \
- .byte 0xea; /* Change to 16bit mode */ \
- .long 1f - LINKADDR; \
- .word S16TEXT; \
+ ljmp $S16TEXT, $1f - LINKADDR; \
1: \
- movl %ax, %ds; \
- movl %ax, %es; \
+ .code16; \
+ movw $S16DATA, %ax; \
+ mov %ax, %ds; \
+ mov %ax, %es; \
gidt_debug1; \
\
movl %cr0, %eax; /* disable pmmm */ \
- data32; \
andl $~CR0_PE, %eax; \
movl %eax, %cr0; \
\
- /* ljmp (LINKADDR >> 4), $1f */; \
- .byte 0xea; /* load real mode cs:ip */ \
- .word 1f; \
- .word (LINKADDR >> 4); \
+ /* reload real cs:ip */ \
+ data32 ljmp $(LINKADDR >> 4), $1f - LINKADDR; \
1: \
- data32; \
- xorl %eax, %eax; /* setup: %ds, %es, %ss */ \
- movl %ax, %ds; \
- movl %ax, %es; \
- movl %ax, %ss; \
+ xor %ax, %ax; /* setup: %ds, %es, %ss */ \
+ mov %ax, %ds; \
+ mov %ax, %es; \
+ mov %ax, %ss; \
\
gidt_debug2; \
\
- addr32; \
- data32; \
- lidt Idtr_real; /* load idtr for real mode */
+ data32 addr32 lidt Idtr_real; /* load idtr for real mode */
#define real2prot \
gidt_debug3; \
\
- addr32; \
- data32; \
- lgdt Gdtr; /* load the gdtr */ \
+ data32 addr32 lgdt Gdtr; /* load the gdtr */ \
\
movl %cr0, %eax; /* enable pmmm */ \
- data32; \
orl $CR0_PE, %eax; \
movl %eax, %cr0; \
\
- data32; \
- ljmp $S32TEXT, $1f; /* reload %cs,flush pipeline */\
+ data32 ljmp $S32TEXT, $1f; /* reload %cs,flush pipeline */\
1: \
+ .code32; \
/* reload 32bit %ds, %ss, %es */ \
- movl $S32DATA, %eax; \
- movl %ax, %ds; \
- movl %ax, %ss; \
- movl %ax, %es; \
+ mov $S32DATA, %eax; \
+ mov %ax, %ds; \
+ mov %ax, %ss; \
+ mov %ax, %es; \
\
gidt_debug4; \
\
@@ -148,6 +125,7 @@
.globl _C_LABEL(BIOS_regs)
.text
+ .code32
.globl _ASM_LABEL(pmm_init)
.globl _C_LABEL(_rtt)
@@ -187,30 +165,21 @@ ENTRY(_rtt)
movl $0, %esp /* segment violation */
ret
- .align 3, 0x90
+ .align 8, 0x90
pmm_init:
- /* reload new gdt */
- lgdt Gdtr
- ljmp $S32TEXT, $1f
-1:
- movl $S32DATA, %eax
- movl %eax, %ds
- movl %eax, %ss
- movl %eax, %es
- movl %eax, %fs
- movl %eax, %gs
-
/* load idtr for interrupts */
lidt Idtr
ret
+
#define IPROC(n) X/**/n
#define IEMU(n) IPROC(emu/**/n)
- .align 3
+ .align 8, 0x90
idt:
#define idte(e) \
- .word IPROC(e), S32TEXT, (0x80|SDT_SYS386TGT) << 8, (LINKADDR >> 16)
- /* internal (0-31) */
+ .short IPROC(e); .short (S32TEXT); \
+ .short ((0x80|SDT_SYS386TGT) << 8); .short (LINKADDR >> 16)
+/* internal (0-31) */
idte(de); idte(db); idte(nmi); idte(bp); idte(of); idte(br)
idte(ud); idte(nm); idte(df); idte(fo); idte(ts); idte(np)
idte(ss); idte(gp); idte(pf); idte(xx); idte(mf); idte(ac)
@@ -235,15 +204,15 @@ Idtr: .word . - idt - 1
.long idt
.word 0
- .align 3
+ .align 8
Idtr_real: .word 1023
.long 0
.word 0
- .align 3
+ .align 8
Idtr_reset: .long 0, 0
- .align 3
+ .align 8
gdt:
/* 0x00 : null */
.space 8
@@ -276,6 +245,7 @@ gdt:
.byte 0xf | 0 | 0 | 0 # hilimit, xx, 16bit, byte granularity
.byte (LINKADDR >> 20) & 0xff # hibase
+.globl Gdtr
Gdtr: .word . - gdt - 1
.long gdt
.word 0
@@ -344,109 +314,100 @@ IEMUENT(44); IEMUENT(45); IEMUENT(46); IEMUENT(47)
*
*/
.globl EMUh
- .align 3, 0x90
+ .align 8, 0x90
EMUh:
/* save %eax */
- movl %eax, 3f
- popl %eax
+ mov %eax, 3f
+ pop %eax
- pushal
- pushl %ds
- pushl %es
- pushl %fs
- pushl %gs
+ pusha
+ push %ds
+ push %es
+ push %fs
+ push %gs
/* save BIOS int vector */
- movb %al, intno
+ mov %al, intno
prot2real
- pushl %ds
+ push %ds
- addr32
- movl _C_LABEL(BIOS_regs)+(BIOSR_ES), %eax
- movl %ax, %es
- addr32
- movl _C_LABEL(BIOS_regs)+(BIOSR_DS), %eax
- movl %ax, %ds
+ addr32 mov _C_LABEL(BIOS_regs)+(BIOSR_ES), %eax
+ mov %ax, %es
+ addr32 mov _C_LABEL(BIOS_regs)+(BIOSR_DS), %eax
+ mov %ax, %ds
- data32
- # movl $Leax, %eax
- .byte 0xb8
-3: .long 0x90909090 /* restore %eax */
+ # data32 movl $Leax, %eax
+ .byte 0x66, 0xb8
+3: .long 0x90909090
;sti
int $0
intno = . - 1
;cli
- popl %ds
+ pop %ds
- addr32
- data32
- movl %ebx, _C_LABEL(BIOS_regs)+(BIOSR_BX)
- movl %es, %bx
- addr32
- movl %bx, _C_LABEL(BIOS_regs)+(BIOSR_ES)
- movb %ah, %bh /* save flags to return to caller */
+ addr32 mov %ebx, _C_LABEL(BIOS_regs)+(BIOSR_BX)
+ mov %es, %bx
+ addr32 mov %ebx, _C_LABEL(BIOS_regs)+(BIOSR_ES)
+ movb %ah, %bh
lahf
xchgb %ah, %bh
- addr32
- data32
- movl %eax, 2f /* save %eax */
+ addr32 mov %eax, 2f
real2prot
- # movl $Leax, %eax
- .byte 0xb8
-2: .long 0x90909090 /* eax */
+ # movl $Leax, %eax
+ .byte 0xb8
+2: .long 0x90909090
/* pass BIOS return values back to caller */
- movl %eax, 0xb*4(%esp)
- movl %ecx, 0xa*4(%esp)
- movl %edx, 0x9*4(%esp)
+ mov %eax, 0xb*4(%esp)
+ mov %ecx, 0xa*4(%esp)
+ mov %edx, 0x9*4(%esp)
movb %bh , 0xe*4(%esp)
/* clear NT flag in eflags */
/* Martin Fredriksson <martin@gbg.netman.se> */
pushf
- popl %eax
- andl $0xffffbfff, %eax
- pushl %eax
+ pop %eax
+ and $0xffffbfff, %eax
+ push %eax
popf
/* save registers into save area */
- movl %eax, _C_LABEL(BIOS_regs)+BIOSR_AX
- movl %ecx, _C_LABEL(BIOS_regs)+BIOSR_CX
- movl %edx, _C_LABEL(BIOS_regs)+BIOSR_DX
- movl %ebp, _C_LABEL(BIOS_regs)+BIOSR_BP
- movl %esi, _C_LABEL(BIOS_regs)+BIOSR_SI
- movl %edi, _C_LABEL(BIOS_regs)+BIOSR_DI
-
- popl %gs
- popl %fs
- popl %es
- popl %ds
- popal
+ mov %eax, _C_LABEL(BIOS_regs)+BIOSR_AX
+ mov %ecx, _C_LABEL(BIOS_regs)+BIOSR_CX
+ mov %edx, _C_LABEL(BIOS_regs)+BIOSR_DX
+ mov %ebp, _C_LABEL(BIOS_regs)+BIOSR_BP
+ mov %esi, _C_LABEL(BIOS_regs)+BIOSR_SI
+ mov %edi, _C_LABEL(BIOS_regs)+BIOSR_DI
+
+ pop %gs
+ pop %fs
+ pop %es
+ pop %ds
+ popa
iret
/* Call buffer at 07c0:0000 in real mode to simulate a BIOS boot */
ENTRY(bootbuf)
- popl %eax /* Don't need return address */
- popl %esi /* Buffer */
- popl %edx /* Device */
+ pop %eax /* Don't need return address */
+ pop %esi /* Buffer */
+ pop %edx /* Device */
prot2real /* Switch */
/* Set up stack */
cli
- xorl %ax, %ax
- movl %ax, %ss
- data32
- movl $0xfffc, %esp
+ xor %ax, %ax
+ mov %ax, %ss
+ mov $0xfffc, %esp
sti
/* Jump to buffer */
- addr32
ljmp $0x0, $0x7c00
+ .end