White space cleanup in vm86.c so that the next patch is more readable.

Signed-off-by: Myles Watson <mylesgw@gmail.com>
Acked-by: Myles Watson <mylesgw@gmail.com>


git-svn-id: svn://coreboot.org/repository/coreboot-v3@962 f3766cd6-281f-0410-b1cd-43a5c92072e9
This commit is contained in:
Myles Watson 2008-10-29 18:12:22 +00:00
parent 3eec9e7790
commit b04f94ae37

View file

@ -30,11 +30,11 @@
#include <io.h> #include <io.h>
/* The address arguments to this function are PHYSICAL ADDRESSES */ /* The address arguments to this function are PHYSICAL ADDRESSES */
static void real_mode_switch_call_vga(unsigned long devfn) static void real_mode_switch_call_vga(unsigned long devfn)
{ {
__asm__ __volatile__ ( __asm__ __volatile__ (
/* paranoia -- does ecx get saved? not sure. /* paranoia -- does ecx get saved? not sure.
* This is the easiest safe thing to do. * This is the easiest safe thing to do.
*/ */
" pushal \n" " pushal \n"
@ -45,7 +45,7 @@ static void real_mode_switch_call_vga(unsigned long devfn)
"1:\n" "1:\n"
/* get devfn into %ecx */ /* get devfn into %ecx */
" movl %esp, %ebp \n" " movl %esp, %ebp \n"
// FIXME: why is this 8? // FIXME: why is this 8?
" movl 8(%ebp), %ecx \n" " movl 8(%ebp), %ecx \n"
/* load 'our' gdt */ /* load 'our' gdt */
" lgdt %cs:__mygdtaddr \n" " lgdt %cs:__mygdtaddr \n"
@ -56,10 +56,10 @@ static void real_mode_switch_call_vga(unsigned long devfn)
" .code16 \n" " .code16 \n"
/* 16 bit code from here on... */ /* 16 bit code from here on... */
/* Load the segment registers w/ properly configured /* Load the segment registers w/ properly configured
* segment descriptors. They will retain these * segment descriptors. They will retain these
* configurations (limits, writability, etc.) once * configurations (limits, writability, etc.) once
* protected mode is turned off. * protected mode is turned off.
*/ */
" mov $0x30, %ax \n" " mov $0x30, %ax \n"
" mov %ax, %ds \n" " mov %ax, %ds \n"
@ -77,9 +77,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"
/* Setup a stack: Put the stack at the end of page zero. /* Setup a stack: Put the stack at the end of page zero.
* That way we can easily share it between real and * That way we can easily share it between real and
* protected, since the 16-bit ESP at segment 0 will * protected, since the 16-bit ESP at segment 0 will
* work for any case. */ * work for any case. */
" mov $0x0, %ax \n" " mov $0x0, %ax \n"
" mov %ax, %ss \n" " mov %ax, %ss \n"
@ -102,15 +102,15 @@ static void real_mode_switch_call_vga(unsigned long devfn)
/* run VGA BIOS at 0xc000:0003 */ /* run VGA BIOS at 0xc000:0003 */
" lcall $0xc000, $0x0003\n" " 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
*/ */
" movl %cr0, %eax \n" " movl %cr0, %eax \n"
" orl $0x0000001, %eax\n" /* PE = 1 */ " orl $0x0000001, %eax\n" /* PE = 1 */
" movl %eax, %cr0 \n" " movl %eax, %cr0 \n"
/* Now that we are in protected mode /* Now that we are in protected mode
* jump to a 32 bit code segment. * jump to a 32 bit code segment.
*/ */
" data32 ljmp $0x10, $vgarestart\n" " data32 ljmp $0x10, $vgarestart\n"
"vgarestart:\n" "vgarestart:\n"
@ -137,12 +137,12 @@ static void real_mode_switch_call_vga(unsigned long devfn)
// __asm__ (".text\n""real_mode_switch_end:\n"); // __asm__ (".text\n""real_mode_switch_end:\n");
// extern char real_mode_switch_end[]; // 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) void vga_enable_console(void)
{ {
__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 */
@ -176,8 +176,8 @@ void vga_enable_console(void)
" 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"
@ -213,7 +213,7 @@ void vga_enable_console(void)
" movb $0x55, %al \n" " movb $0x55, %al \n"
" outb %al, $0x80 \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 */
" movl %cr0, %eax \n" " movl %cr0, %eax \n"
" orl $0x0000001, %eax\n" /* PE = 1 */ " orl $0x0000001, %eax\n" /* PE = 1 */
@ -243,7 +243,7 @@ void vga_enable_console(void)
void run_bios(struct device *dev, unsigned long addr) void run_bios(struct device *dev, unsigned long addr)
{ {
int i; int i;
/* clear vga bios data area */ /* clear vga bios data area */
for (i = 0x400; i < 0x500; i++) { for (i = 0x400; i < 0x500; i++) {
*(unsigned char *) i = 0; *(unsigned char *) i = 0;
@ -253,32 +253,32 @@ void run_bios(struct device *dev, unsigned long addr)
} }
// we had hoped to avoid this. // we had hoped to avoid this.
// this is a stub IDT only. It's main purpose is to ignore calls // this is a stub IDT only. It's main purpose is to ignore calls
// to the BIOS. // to the BIOS.
// no longer. Dammit. We have to respond to these. // no longer. Dammit. We have to respond to these.
struct realidt { struct realidt {
unsigned short offset, cs; unsigned short offset, cs;
}; };
// from a handy writeup that andrey found. // from a handy writeup that andrey found.
// handler. // handler.
// There are some assumptions we can make here. // There are some assumptions we can make here.
// First, the Top Of Stack (TOS) is located on the top of page zero. // First, the Top Of Stack (TOS) is located on the top of page zero.
// we can share this stack between real and protected mode. // we can share this stack between real and protected mode.
// that simplifies a lot of things ... // that simplifies a lot of things ...
// we'll just push all the registers on the stack as longwords, // we'll just push all the registers on the stack as longwords,
// and pop to protected mode. // and pop to protected mode.
// second, since this only ever runs as part of coreboot, // second, since this only ever runs as part of coreboot,
// we know all the segment register values -- so we don't save any. // we know all the segment register values -- so we don't save any.
// keep the handler that calls things small. It can do a call to // keep the handler that calls things small. It can do a call to
// more complex code in coreboot itself. This helps a lot as we don't // more complex code in coreboot 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"
" pushal \n" " pushal \n"
@ -291,7 +291,7 @@ void handler(void)
void debughandler(void) void debughandler(void)
{ {
__asm__ __volatile__ ( __asm__ __volatile__ (
" .code16 \n" " .code16 \n"
"debughandle: \n" "debughandle: \n"
" pushw %cx \n" " pushw %cx \n"
@ -307,9 +307,9 @@ void debughandler(void)
// Calling conventions. The first C function is called with this stuff // Calling conventions. The first C function is called with this stuff
// on the stack. They look like value parameters, but note that if you // on the stack. They look like value parameters, but note that if you
// modify them they will go back to the INTx function modified. // modify them they will go back to the INTx function modified.
// 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)
{ {
@ -321,7 +321,7 @@ void callbiosint(void)
" push %fs \n" " push %fs \n"
" push %gs \n" " push %gs \n"
// clean up the int #. To save space we put it in the lower // clean up the int #. To save space we put it in the lower
// byte. But the top 24 bits are junk. // byte. But the top 24 bits are junk.
" andl $0xff, %eax\n" " andl $0xff, %eax\n"
// this push does two things: // this push does two things:
// - put the INT # on the stack as a parameter // - put the INT # on the stack as a parameter
@ -356,7 +356,7 @@ void callbiosint(void)
" mov %ax, %fs \n" " mov %ax, %fs \n"
" mov %ax, %gs \n" " mov %ax, %gs \n"
" mov %ax, %ss \n" " mov %ax, %ss \n"
/* Turn off protection (bit 0 in CR0) */ /* Turn off protection (bit 0 in CR0) */
" movl %cr0, %eax \n" " movl %cr0, %eax \n"
" andl $0xFFFFFFFE, %eax \n" " andl $0xFFFFFFFE, %eax \n"
@ -400,7 +400,7 @@ void callbiosint(void)
} }
enum { enum {
PCIBIOS = 0x1a, PCIBIOS = 0x1a,
MEMSIZE = 0x12 MEMSIZE = 0x12
}; };
@ -411,36 +411,36 @@ int pcibios(unsigned long *pedi, unsigned long *pesi, unsigned long *pebp,
int handleint21(unsigned long *pedi, unsigned long *pesi, unsigned long *pebp, int handleint21(unsigned long *pedi, unsigned long *pesi, unsigned long *pebp,
unsigned long *pesp, unsigned long *pebx, unsigned long *pedx, unsigned long *pesp, unsigned long *pebx, unsigned long *pedx,
unsigned long *pecx, unsigned long *peax, unsigned long *pflags unsigned long *pecx, unsigned long *peax, unsigned long *pflags
); );
extern void vga_exit(void); extern void vga_exit(void);
int biosint(unsigned long intnumber, int biosint(unsigned long intnumber,
unsigned long gsfs, unsigned long dses, unsigned long gsfs, unsigned long dses,
unsigned long edi, unsigned long esi, unsigned long edi, unsigned long esi,
unsigned long ebp, unsigned long esp, unsigned long ebp, unsigned long esp,
unsigned long ebx, unsigned long edx, unsigned long ebx, unsigned long edx,
unsigned long ecx, unsigned long eax, unsigned long ecx, unsigned long eax,
unsigned long cs_ip, unsigned short stackflags) 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;
int ret = -1; int ret = -1;
ip = cs_ip & 0xffff; ip = cs_ip & 0xffff;
cs = cs_ip >> 16; cs = cs_ip >> 16;
flags = stackflags; flags = stackflags;
printk(BIOS_DEBUG, "biosint: INT# 0x%lx\n", intnumber); printk(BIOS_DEBUG, "biosint: INT# 0x%lx\n", intnumber);
printk(BIOS_DEBUG, "biosint: eax 0x%lx ebx 0x%lx ecx 0x%lx edx 0x%lx\n", printk(BIOS_DEBUG, "biosint: eax 0x%lx ebx 0x%lx ecx 0x%lx edx 0x%lx\n",
eax, ebx, ecx, edx); eax, ebx, ecx, edx);
printk(BIOS_DEBUG, "biosint: ebp 0x%lx esp 0x%lx edi 0x%lx esi 0x%lx\n", printk(BIOS_DEBUG, "biosint: ebp 0x%lx esp 0x%lx edi 0x%lx esi 0x%lx\n",
ebp, esp, edi, esi); ebp, esp, edi, esi);
printk(BIOS_DEBUG, "biosint: ip 0x%lx cs 0x%lx flags 0x%lx\n", printk(BIOS_DEBUG, "biosint: ip 0x%lx cs 0x%lx flags 0x%lx\n",
ip, cs, flags); 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:
// These are not BIOS service, but the CPU-generated exceptions // These are not BIOS service, but the CPU-generated exceptions
@ -457,22 +457,22 @@ int biosint(unsigned long intnumber,
// "longjmp" // "longjmp"
vga_exit(); vga_exit();
break; break;
case PCIBIOS: case PCIBIOS:
ret = pcibios( &edi, &esi, &ebp, &esp, ret = pcibios( &edi, &esi, &ebp, &esp,
&ebx, &edx, &ecx, &eax, &flags); &ebx, &edx, &ecx, &eax, &flags);
break; break;
case MEMSIZE: case MEMSIZE:
// who cares. // who cares.
eax = 64 * 1024; eax = 64 * 1024;
ret = 0; ret = 0;
break; break;
case 0x15: case 0x15:
ret=handleint21( &edi, &esi, &ebp, &esp, ret=handleint21( &edi, &esi, &ebp, &esp,
&ebx, &edx, &ecx, &eax, &flags); &ebx, &edx, &ecx, &eax, &flags);
break; break;
default: default:
printk(BIOS_INFO, "BIOSINT: Unsupport int #0x%lx\n", printk(BIOS_INFO, "BIOSINT: Unsupport int #0x%lx\n",
intnumber); intnumber);
break; break;
} }
@ -482,10 +482,10 @@ int biosint(unsigned long intnumber,
flags &= ~1; flags &= ~1;
stackflags = flags; stackflags = flags;
return ret; return ret;
} }
void setup_realmode_idt(void) void setup_realmode_idt(void)
{ {
extern unsigned char idthandle, end_idthandle; extern unsigned char idthandle, end_idthandle;
#if 0 #if 0
@ -496,14 +496,14 @@ void setup_realmode_idt(void)
struct realidt *idts = (struct realidt *) 0; struct realidt *idts = (struct realidt *) 0;
int codesize = &end_idthandle - &idthandle; int codesize = &end_idthandle - &idthandle;
unsigned char *intbyte, *codeptr; unsigned char *intbyte, *codeptr;
// for each int, we create a customized little handler // for each int, we create a customized little handler
// that just pushes %ax, puts the int # in %al, // that just pushes %ax, puts the int # in %al,
// then calls the common interrupt handler. // then calls the common interrupt handler.
// this necessitated because intel didn't know much about // this necessitated because intel didn't know much about
// architecture when they did the 8086 (it shows) // architecture when they did the 8086 (it shows)
// (hmm do they know anymore even now :-) // (hmm do they know anymore even now :-)
// obviously you can see I don't really care about memory // obviously you can see I don't really care about memory
// efficiency. If I did I would probe back through the stack // efficiency. If I did I would probe back through the stack
// and get it that way. But that's really disgusting. // and get it that way. But that's really disgusting.
for (i = 0; i < 256; i++) { for (i = 0; i < 256; i++) {
@ -514,11 +514,11 @@ void setup_realmode_idt(void)
intbyte = codeptr + 3; intbyte = codeptr + 3;
*intbyte = i; *intbyte = i;
} }
// fixed entry points // fixed entry points
// VGA BIOSes tend to hardcode f000:f065 as the previous handler of // VGA BIOSes tend to hardcode f000:f065 as the previous handler of
// int10. // int10.
// calling convention here is the same as INTs, we can reuse // calling convention here is the same as INTs, we can reuse
// the int entry code. // the int entry code.
codeptr = (unsigned char *) 0xff065; codeptr = (unsigned char *) 0xff065;
@ -526,14 +526,14 @@ 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 */
/* The source of the following code is not yet known. /* The source of the following code is not yet known.
* We feel it may be useful someday, but right now it * We feel it may be useful someday, but right now it
* scribbles over code space. We are leaving it here as a * scribbles over code space. We are leaving it here as a
* "Living comment" since it may at some point be needed * "Living comment" since it may at some point be needed
* again. It is a very intriguing idea -- one could run * again. It is a very intriguing idea -- one could run
* vm86 code with TF set and set programmable times * vm86 code with TF set and set programmable times
* between instructions to slow them down. For those who * between instructions to slow them down. For those who
* recall the "turbo" switch on old PCs, this is the * recall the "turbo" switch on old PCs, this is the
* software equivalent. * software equivalent.
*/ */
#if 0 #if 0
@ -544,7 +544,7 @@ void setup_realmode_idt(void)
memcpy((void *)16384, &debughandle, &end_debughandle - &debughandle); memcpy((void *)16384, &debughandle, &end_debughandle - &debughandle);
#endif #endif
} }
@ -561,25 +561,25 @@ enum {
}; };
// errors go in AH. Just set these up so that word assigns // errors go in AH. Just set these up so that word assigns
// will work. KISS. // will work. KISS.
enum { enum {
PCIBIOS_NODEV = 0x8600, PCIBIOS_NODEV = 0x8600,
PCIBIOS_BADREG = 0x8700 PCIBIOS_BADREG = 0x8700
}; };
int int
pcibios(unsigned long *pedi, unsigned long *pesi, unsigned long *pebp, pcibios(unsigned long *pedi, unsigned long *pesi, unsigned long *pebp,
unsigned long *pesp, unsigned long *pebx, unsigned long *pedx, unsigned long *pesp, unsigned long *pebx, unsigned long *pedx,
unsigned long *pecx, unsigned long *peax, unsigned long *pflags) unsigned long *pecx, unsigned long *peax, unsigned long *pflags)
{ {
unsigned short func = (unsigned short) *peax; unsigned short func = (unsigned short) *peax;
int retval = 0; int retval = 0;
unsigned short devid, vendorid, devfn; unsigned short devid, vendorid, devfn;
/* Use short to get rid of gabage in upper half of 32-bit register */ /* Use short to get rid of gabage in upper half of 32-bit register */
short devindex; short devindex;
unsigned char bus; unsigned char bus;
struct device *dev; struct device *dev;
switch(func) { switch(func) {
case CHECK: case CHECK:
*pedx = 0x4350; *pedx = 0x4350;
@ -601,7 +601,7 @@ pcibios(unsigned long *pedi, unsigned long *pesi, unsigned long *pebp,
unsigned short busdevfn; unsigned short busdevfn;
*peax = 0; *peax = 0;
// busnum is an unsigned char; // busnum is an unsigned char;
// devfn is an int, so we mask it off. // devfn is an int, so we mask it off.
busdevfn = (dev->bus->secondary << 8) busdevfn = (dev->bus->secondary << 8)
| (dev->path.pci.devfn & 0xff); | (dev->path.pci.devfn & 0xff);
printk(BIOS_DEBUG, "0x%x: return 0x%x\n", func, busdevfn); printk(BIOS_DEBUG, "0x%x: return 0x%x\n", func, busdevfn);
@ -624,7 +624,7 @@ pcibios(unsigned long *pedi, unsigned long *pesi, unsigned long *pebp,
unsigned short word; unsigned short word;
unsigned char byte; unsigned char byte;
unsigned char reg; unsigned char reg;
devfn = *pebx & 0xff; devfn = *pebx & 0xff;
bus = *pebx >> 8; bus = *pebx >> 8;
reg = *pedi; reg = *pedi;
@ -661,8 +661,8 @@ pcibios(unsigned long *pedi, unsigned long *pesi, unsigned long *pebp,
pci_write_config32(dev, reg, dword); pci_write_config32(dev, reg, dword);
break; break;
} }
if (retval) if (retval)
retval = PCIBIOS_BADREG; retval = PCIBIOS_BADREG;
printk(BIOS_DEBUG, "0x%x: bus %d devfn 0x%x reg 0x%x val 0x%lx\n", printk(BIOS_DEBUG, "0x%x: bus %d devfn 0x%x reg 0x%x val 0x%lx\n",
func, bus, devfn, reg, *pecx); func, bus, devfn, reg, *pecx);
@ -674,9 +674,9 @@ pcibios(unsigned long *pedi, unsigned long *pesi, unsigned long *pebp,
printk(BIOS_ERR, "UNSUPPORTED PCIBIOS FUNCTION 0x%x\n", func); printk(BIOS_ERR, "UNSUPPORTED PCIBIOS FUNCTION 0x%x\n", func);
break; break;
} }
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,
@ -704,7 +704,7 @@ int handleint21(unsigned long *edi, unsigned long *esi, unsigned long *ebp,
case 0x5f02: case 0x5f02:
*eax=0x5f; *eax=0x5f;
*ebx= (*ebx & 0xffff0000) | 2; *ebx= (*ebx & 0xffff0000) | 2;
*ecx= (*ecx & 0xffff0000) | 0x401; // PAL + crt only *ecx= (*ecx & 0xffff0000) | 0x401; // PAL + crt only
*edx= (*edx & 0xffff0000) | 0; // TV Layout - default *edx= (*edx & 0xffff0000) | 0; // TV Layout - default
res=0; res=0;
break; break;