reformating, we are going to use it for

vsa on geode GX.

There was some bug in setting up stack, what was that?


git-svn-id: svn://svn.coreboot.org/coreboot/trunk@2208 2b7e53f0-3cfb-0310-b3e9-8179ed1497e1
This commit is contained in:
Li-Ta Lo
2006-03-17 19:52:52 +00:00
parent 410075e0f1
commit a5ce2341ec

View File

@@ -77,54 +77,54 @@
Core part of the bios no longer sets up any 16 bit segments */ Core part of the bios no longer sets up any 16 bit segments */
__asm__ ( __asm__ (
/* pointer to original gdt */ /* pointer to original gdt */
"gdtarg: \n\t" "gdtarg: \n"
".word gdt_limit \n\t" " .word gdt_limit \n"
".long gdt \n\t" " .long gdt \n"
/* compute the table limit */ /* compute the table limit */
"__mygdt_limit = __mygdt_end - __mygdt - 1 \n\t" "__mygdt_limit = __mygdt_end - __mygdt - 1 \n"
"__mygdtaddr: \n\t" "__mygdtaddr: \n"
".word __mygdt_limit \n\t" " .word __mygdt_limit \n"
".long __mygdt \n\t" " .long __mygdt \n"
"__mygdt: \n"
"__mygdt: \n\t"
/* selgdt 0, unused */ /* selgdt 0, unused */
".word 0x0000, 0x0000 \n\t" " .word 0x0000, 0x0000 \n"
".byte 0x00, 0x00, 0x00, 0x00 \n\t" " .byte 0x00, 0x00, 0x00, 0x00 \n"
/* selgdt 8, unused */ /* selgdt 8, unused */
".word 0x0000, 0x0000 \n\t" " .word 0x0000, 0x0000 \n"
".byte 0x00, 0x00, 0x00, 0x00 \n\t" " .byte 0x00, 0x00, 0x00, 0x00 \n"
/* selgdt 0x10, flat code segment */ /* selgdt 0x10, flat code segment */
".word 0xffff, 0x0000 \n\t" " .word 0xffff, 0x0000 \n"
".byte 0x00, 0x9b, 0xcf, 0x00 \n\t" " .byte 0x00, 0x9b, 0xcf, 0x00 \n"
/* selgdt 0x18, flat data segment */ /* selgdt 0x18, flat data segment */
".word 0xffff, 0x0000 \n\t" " .word 0xffff, 0x0000 \n"
".byte 0x00, 0x93, 0xcf, 0x00 \n\t" " .byte 0x00, 0x93, 0xcf, 0x00 \n"
/* selgdt 0x20, unused */ /* selgdt 0x20, unused */
".word 0x0000, 0x0000 \n\t" " .word 0x0000, 0x0000 \n"
".byte 0x00, 0x00, 0x00, 0x00 \n\t" " .byte 0x00, 0x00, 0x00, 0x00 \n"
/* selgdt 0x28 16-bit 64k code at 0x00000000 */ /* selgdt 0x28 16-bit 64k code at 0x00000000 */
".word 0xffff, 0x0000 \n\t" " .word 0xffff, 0x0000 \n"
".byte 0, 0x9a, 0, 0 \n\t" " .byte 0, 0x9a, 0, 0 \n"
/* selgdt 0x30 16-bit 64k data at 0x00000000 */ /* selgdt 0x30 16-bit 64k data at 0x00000000 */
".word 0xffff, 0x0000 \n\t" " .word 0xffff, 0x0000 \n"
".byte 0, 0x92, 0, 0 \n\t" " .byte 0, 0x92, 0, 0 \n"
"__mygdt_end: \n\t" "__mygdt_end: \n"
); );
/* Declare a pointer to where our idt is going to be i.e. at mem zero */ /* Declare a pointer to where our idt is going to be i.e. at mem zero */
__asm__ ( __asm__ ("__myidt: \n"
"__myidt: \n" /* 16-bit limit */
" .word 1023 \n" " .word 1023 \n"
/* 24-bit base */
" .long 0 \n" " .long 0 \n"
" .word 0 \n" " .word 0 \n"
); );
@@ -145,7 +145,7 @@ static void real_mode_switch_call_vga(unsigned long devfn)
" movl %esp, %ebp \n" " movl %esp, %ebp \n"
" movl 8(%ebp), %ecx \n" " movl 8(%ebp), %ecx \n"
/* load 'our' gdt */ /* load 'our' gdt */
" lgdt %cs:__mygdtaddr \n\t" " lgdt %cs:__mygdtaddr \n"
/* This configures CS properly for real mode. */ /* This configures CS properly for real mode. */
" ljmp $0x28, $__rms_16bit\n" " ljmp $0x28, $__rms_16bit\n"
@@ -172,9 +172,9 @@ static void real_mode_switch_call_vga(unsigned long devfn)
" ljmp $0, $__rms_real\n" " ljmp $0, $__rms_real\n"
"__rms_real: \n" "__rms_real: \n"
// put the stack at the end of page zero. /* put the stack at the end of page zero.
// that way we can easily share it between real and protected, * that way we can easily share it between real and protected,
// since the 16-bit ESP at segment 0 will work for any case. * since the 16-bit ESP at segment 0 will work for any case.
/* Setup a stack */ /* Setup a stack */
" mov $0x0, %ax \n" " mov $0x0, %ax \n"
" mov %ax, %ss \n" " mov %ax, %ss \n"
@@ -186,7 +186,6 @@ static void real_mode_switch_call_vga(unsigned long devfn)
" mov %ax, %ds \n" " mov %ax, %ds \n"
" lidt __myidt \n" " lidt __myidt \n"
/* Dump zeros in the other segregs */ /* Dump zeros in the other segregs */
" mov %ax, %es \n" " mov %ax, %es \n"
" mov %ax, %fs \n" " mov %ax, %fs \n"
@@ -194,8 +193,9 @@ static void real_mode_switch_call_vga(unsigned long devfn)
" mov $0x40, %ax \n" " mov $0x40, %ax \n"
" mov %ax, %ds \n" " mov %ax, %ds \n"
" mov %cx, %ax \n" " mov %cx, %ax \n"
/* go run the code */
" .byte 0x9a, 0x03, 0, 0, 0xc0 \n" /* run VGA BIOS at 0xc000:0003 */
" lcall $0xc000, $0x0003\n"
/* if we got here, just about done. /* if we got here, just about done.
* Need to get back to protected mode */ * Need to get back to protected mode */
@@ -217,6 +217,7 @@ static void real_mode_switch_call_vga(unsigned long devfn)
/* restore proper gdt and idt */ /* restore proper gdt and idt */
" lgdt %cs:gdtarg \n" " lgdt %cs:gdtarg \n"
" lidt idtarg \n" " lidt idtarg \n"
".globl vga_exit \n" ".globl vga_exit \n"
"vga_exit: \n" "vga_exit: \n"
" mov __stack, %esp \n" " mov __stack, %esp \n"
@@ -229,18 +230,17 @@ extern char real_mode_switch_end[];
/* call vga bios int 10 function 0x4f14 to enable main console /* call vga bios int 10 function 0x4f14 to enable main console
epia-m does not always autosence the main console so forcing it on is good !! */ epia-m does not always autosence the main console so forcing it on is good !! */
void vga_enable_console() void vga_enable_console()
{ {
__asm__ __volatile__ ( __asm__ __volatile__ (
// paranoia -- does ecx get saved? not sure. This is /* paranoia -- does ecx get saved? not sure. This is
// the easiest safe thing to do. * the easiest safe thing to do. */
" pushal \n" " pushal \n"
/* save the stack */ /* save the stack */
" mov %esp, __stack \n" " mov %esp, __stack \n"
/* load 'our' gdt */ /* load 'our' gdt */
" lgdt %cs:__mygdtaddr \n\t" " lgdt %cs:__mygdtaddr \n"
/* This configures CS properly for real mode. */ /* This configures CS properly for real mode. */
" ljmp $0x28, $__vga_ec_16bit\n" " ljmp $0x28, $__vga_ec_16bit\n"
@@ -267,14 +267,15 @@ void vga_enable_console()
" ljmp $0, $__vga_ec_real \n" " ljmp $0, $__vga_ec_real \n"
"__vga_ec_real: \n" "__vga_ec_real: \n"
// put the stack at the end of page zero. /* put the stack at the end of page zero.
// that way we can easily share it between real and protected, * that way we can easily share it between real and protected,
// since the 16-bit ESP at segment 0 will work for any case. * since the 16-bit ESP at segment 0 will work for any case.
/* Setup a stack */ /* Setup a stack */
" mov $0x0, %ax \n" " mov $0x0, %ax \n"
" mov %ax, %ss \n" " mov %ax, %ss \n"
" movl $0x1000, %eax \n" " movl $0x1000, %eax \n"
" movl %eax, %esp \n" " movl %eax, %esp \n"
/* debugging for RGM */ /* debugging for RGM */
" mov $0x11, %al \n" " mov $0x11, %al \n"
" outb %al, $0x80 \n" " outb %al, $0x80 \n"
@@ -291,14 +292,17 @@ void vga_enable_console()
" mov %ax, %gs \n" " mov %ax, %gs \n"
/* ask bios to enable main console */ /* ask bios to enable main console */
/* set up for int 10 call - values found from X server bios call routines */ /* set up for int 10 call - values found from X server
* bios call routines */
" movw $0x4f14,%ax \n" " movw $0x4f14,%ax \n"
" movw $0x8003,%bx \n" " movw $0x8003,%bx \n"
" movw $1, %cx \n" " movw $1, %cx \n"
" movw $0, %dx \n" " movw $0, %dx \n"
" movw $0, %di \n" " movw $0, %di \n"
" .byte 0xcd, 0x10 \n" " int $0x10 \n"
" movb $0x55, %al\noutb %al, $0x80\n"
" movb $0x55, %al \n"
" outb %al, $0x80 \n"
/* if we got here, just about done. /* if we got here, just about done.
* Need to get back to protected mode */ * Need to get back to protected mode */
@@ -317,7 +321,6 @@ void vga_enable_console()
" mov %ax, %gs \n" " mov %ax, %gs \n"
" mov %ax, %ss \n" " mov %ax, %ss \n"
/* restore proper gdt and idt */ /* restore proper gdt and idt */
" lgdt %cs:gdtarg \n" " lgdt %cs:gdtarg \n"
" lidt idtarg \n" " lidt idtarg \n"
@@ -328,9 +331,7 @@ void vga_enable_console()
); );
} }
void do_vgabios(void)
void
do_vgabios(void)
{ {
device_t dev; device_t dev;
unsigned long busdevfn; unsigned long busdevfn;
@@ -352,7 +353,8 @@ do_vgabios(void)
} }
printk_debug("found VGA: vid=%x, did=%x\n", dev->vendor, dev->device); printk_debug("found VGA: vid=%x, did=%x\n", dev->vendor, dev->device);
/* declare rom address here - keep any config data out of the way of core LXB stuff */ /* declare rom address here - keep any config data out of the way
* of core LXB stuff */
rom = 0xfffc0000; rom = 0xfffc0000;
pci_write_config32(dev, PCI_ROM_ADDRESS, rom|1); pci_write_config32(dev, PCI_ROM_ADDRESS, rom|1);
@@ -373,12 +375,10 @@ do_vgabios(void)
real_mode_switch_call_vga(busdevfn); real_mode_switch_call_vga(busdevfn);
} else } else
printk_debug("Failed to copy VGA BIOS to 0xc0000\n"); printk_debug("Failed to copy VGA BIOS to 0xc0000\n");
} else } else
printk_debug("BAD SIGNATURE 0x%x 0x%x\n", buf[0], buf[1]); printk_debug("BAD SIGNATURE 0x%x 0x%x\n", buf[0], buf[1]);
pci_write_config32(dev, PCI_ROM_ADDRESS, 0); pci_write_config32(dev, PCI_ROM_ADDRESS, 0);
} }
@@ -405,7 +405,8 @@ struct realidt {
// more complex code in linuxbios itself. This helps a lot as we don't // more complex code in linuxbios itself. This helps a lot as we don't
// have to do address fixup in this little stub, and calls are absolute // have to do address fixup in this little stub, and calls are absolute
// so the handler is relocatable. // so the handler is relocatable.
void handler(void) { void handler(void)
{
__asm__ __volatile__ ( __asm__ __volatile__ (
" .code16 \n" " .code16 \n"
"idthandle: \n" "idthandle: \n"
@@ -415,10 +416,10 @@ void handler(void) {
"end_idthandle: \n" "end_idthandle: \n"
" .code32 \n" " .code32 \n"
); );
} }
void debughandler(void) { void debughandler(void)
{
__asm__ __volatile__ ( __asm__ __volatile__ (
" .code16 \n" " .code16 \n"
"debughandle: \n" "debughandle: \n"
@@ -431,7 +432,6 @@ void debughandler(void) {
"end_debughandle: \n" "end_debughandle: \n"
".code32 \n" ".code32 \n"
); );
} }
// Calling conventions. The first C function is called with this stuff // Calling conventions. The first C function is called with this stuff
@@ -440,7 +440,8 @@ void debughandler(void) {
// the C function will call the biosint function with these as // the C function will call the biosint function with these as
// REFERENCE parameters. In this way, we can easily get // REFERENCE parameters. In this way, we can easily get
// returns back to the INTx caller (i.e. vgabios) // returns back to the INTx caller (i.e. vgabios)
void callbiosint(void) { void callbiosint(void)
{
__asm__ __volatile__ ( __asm__ __volatile__ (
" .code16 \n" " .code16 \n"
"callbiosint16: \n" "callbiosint16: \n"
@@ -456,8 +457,6 @@ void callbiosint(void) {
// - provides us with a temp for the %cr0 mods. // - provides us with a temp for the %cr0 mods.
" pushl %eax \n" " pushl %eax \n"
" movl %cr0, %eax\n" " movl %cr0, %eax\n"
//"andl $0x7FFAFFD1, %eax\n" /* PG,AM,WP,NE,TS,EM,MP = 0 */
//"orl $0x60000001, %eax\n" /* CD, NW, PE = 1 */
" orl $0x00000001, %eax\n" /* PE = 1 */ " orl $0x00000001, %eax\n" /* PE = 1 */
" movl %eax, %cr0\n" " movl %eax, %cr0\n"
/* Now that we are in protected mode jump to a 32 bit code segment. */ /* Now that we are in protected mode jump to a 32 bit code segment. */
@@ -475,8 +474,8 @@ void callbiosint(void) {
// back to real mode ... // back to real mode ...
" ljmp $0x28, $__rms_16bit2\n" " ljmp $0x28, $__rms_16bit2\n"
"__rms_16bit2: \n" "__rms_16bit2: \n"
".code16 \n" /* 16 bit code from here on... */ " .code16 \n"
/* 16 bit code from here on... */
/* Load the segment registers w/ properly configured segment /* Load the segment registers w/ properly configured segment
* descriptors. They will retain these configurations (limits, * descriptors. They will retain these configurations (limits,
* writability, etc.) once protected mode is turned off. */ * writability, etc.) once protected mode is turned off. */
@@ -496,21 +495,28 @@ void callbiosint(void) {
" ljmp $0, $__rms_real2 \n" " ljmp $0, $__rms_real2 \n"
"__rms_real2: \n" "__rms_real2: \n"
/* Setup a stack */ /* Setup a stack
* FixME: where is esp? */
" mov $0x0, %ax \n" " mov $0x0, %ax \n"
" mov %ax, %ss \n" " mov %ax, %ss \n"
/* ebugging for RGM */ /* ebugging for RGM */
" mov $0x11, %al \n" " mov $0x11, %al \n"
" outb %al, $0x80 \n" " outb %al, $0x80 \n"
/* Load our 16 it idt */
" xor %ax, %ax \n" " xor %ax, %ax \n"
" mov %ax, %ds \n" " mov %ax, %ds \n"
" lidt __myidt \n" " lidt __myidt \n"
/* Dump zeros in the other segregs */
" mov %ax, %es \n" " mov %ax, %es \n"
" mov %ax, %fs \n" " mov %ax, %fs \n"
" mov %ax, %gs \n" " mov %ax, %gs \n"
" mov $0x40, %ax \n" " mov $0x40, %ax \n"
" mov %ax, %ds \n" " mov %ax, %ds \n"
// pop the INT # that you pushed earlier
/* pop the INT # that you pushed earlier */
" popl %eax \n" " popl %eax \n"
" pop %gs \n" " pop %gs \n"
" pop %fs \n" " pop %fs \n"
@@ -522,54 +528,30 @@ void callbiosint(void) {
); );
} }
enum { enum {
PCIBIOS = 0x1a, PCIBIOS = 0x1a,
MEMSIZE = 0x12 MEMSIZE = 0x12
}; };
int
pcibios( int pcibios(unsigned long *pedi, unsigned long *pesi, unsigned long *pebp,
unsigned long *pedi, unsigned long *pesp, unsigned long *pebx, unsigned long *pedx,
unsigned long *pesi, unsigned long *pecx, unsigned long *peax, unsigned long *pflags);
unsigned long *pebp,
unsigned long *pesp, int handleint21(unsigned long *pedi, unsigned long *pesi, unsigned long *pebp,
unsigned long *pebx, unsigned long *pesp, unsigned long *pebx, unsigned long *pedx,
unsigned long *pedx, unsigned long *pecx, unsigned long *peax, unsigned long *pflags
unsigned long *pecx,
unsigned long *peax,
unsigned long *pflags
);
int
handleint21(
unsigned long *pedi,
unsigned long *pesi,
unsigned long *pebp,
unsigned long *pesp,
unsigned long *pebx,
unsigned long *pedx,
unsigned long *pecx,
unsigned long *peax,
unsigned long *pflags
); );
extern void vga_exit(void); extern void vga_exit(void);
int int biosint(unsigned long intnumber,
biosint( unsigned long gsfs, unsigned long dses,
unsigned long intnumber, unsigned long edi, unsigned long esi,
unsigned long gsfs, unsigned long ebp, unsigned long esp,
unsigned long dses, unsigned long ebx, unsigned long edx,
unsigned long edi, unsigned long ecx, unsigned long eax,
unsigned long esi, unsigned long cs_ip, unsigned short stackflags)
unsigned long ebp, {
unsigned long esp,
unsigned long ebx,
unsigned long edx,
unsigned long ecx,
unsigned long eax,
unsigned long cs_ip,
unsigned short stackflags
) {
unsigned long ip; unsigned long ip;
unsigned long cs; unsigned long cs;
unsigned long flags; unsigned long flags;
@@ -579,10 +561,14 @@ biosint(
cs = cs_ip >> 16; cs = cs_ip >> 16;
flags = stackflags; flags = stackflags;
printk_debug("biosint: # 0x%lx, eax 0x%lx ebx 0x%lx ecx 0x%lx edx 0x%lx\n", printk_debug("biosint: INT# 0x%lx\n", intnumber);
intnumber, eax, ebx, ecx, edx); printk_debug("biosint: eax 0x%lx ebx 0x%lx ecx 0x%lx edx 0x%lx\n",
printk_debug("biosint: ebp 0x%lx esp 0x%lx edi 0x%lx esi 0x%lx\n", ebp, esp, edi, esi); eax, ebx, ecx, edx);
printk_debug("biosint: ip 0x%x cs 0x%x flags 0x%x\n", ip, cs, flags); printk_debug("biosint: ebp 0x%lx esp 0x%lx edi 0x%lx esi 0x%lx\n",
ebp, esp, edi, esi);
printk_debug("biosint: ip 0x%x cs 0x%x flags 0x%x\n",
ip, cs, flags);
// cases in a good compiler are just as good as your own tables. // cases in a good compiler are just as good as your own tables.
switch (intnumber) { switch (intnumber) {
case 0 ... 15: case 0 ... 15:
@@ -667,8 +653,8 @@ void setup_realmode_idt(void)
intbyte = codeptr + 3; intbyte = codeptr + 3;
*intbyte = 0x42; /* int42 is the relocated int10 */ *intbyte = 0x42; /* int42 is the relocated int10 */
/* debug handler - useful to set a programmable delay between instructions if the TF bit is set upon /* debug handler - useful to set a programmable delay between instructions if the
call to real mode */ TF bit is set upon call to real mode */
idts[1].cs = 0; idts[1].cs = 0;
idts[1].offset = 16384; idts[1].offset = 16384;
memcpy(16384, &debughandle, &end_debughandle - &debughandle); memcpy(16384, &debughandle, &end_debughandle - &debughandle);
@@ -697,17 +683,10 @@ enum {
}; };
int int
pcibios( pcibios(unsigned long *pedi, unsigned long *pesi, unsigned long *pebp,
unsigned long *pedi, unsigned long *pesp, unsigned long *pebx, unsigned long *pedx,
unsigned long *pesi, unsigned long *pecx, unsigned long *peax, unsigned long *pflags)
unsigned long *pebp, {
unsigned long *pesp,
unsigned long *pebx,
unsigned long *pedx,
unsigned long *pecx,
unsigned long *peax,
unsigned long *pflags
) {
unsigned long edi = *pedi; unsigned long edi = *pedi;
unsigned long esi = *pesi; unsigned long esi = *pesi;
unsigned long ebp = *pebp; unsigned long ebp = *pebp;
@@ -808,7 +787,8 @@ pcibios(
if (retval) if (retval)
retval = PCIBIOS_BADREG; retval = PCIBIOS_BADREG;
printk_debug("0x%x: bus %d devfn 0x%x reg 0x%x val 0x%lx\n", func, bus, devfn, reg, *pecx); printk_debug("0x%x: bus %d devfn 0x%x reg 0x%x val 0x%lx\n",
func, bus, devfn, reg, *pecx);
*peax = 0; *peax = 0;
retval = 0; retval = 0;
} }
@@ -821,8 +801,6 @@ pcibios(
return retval; return retval;
} }
int handleint21(unsigned long *edi, unsigned long *esi, unsigned long *ebp, int handleint21(unsigned long *edi, unsigned long *esi, unsigned long *ebp,
unsigned long *esp, unsigned long *ebx, unsigned long *edx, unsigned long *esp, unsigned long *ebx, unsigned long *edx,
unsigned long *ecx, unsigned long *eax, unsigned long *flags) unsigned long *ecx, unsigned long *eax, unsigned long *flags)