From patchwork Fri Oct 9 20:30:24 2009 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: serialice for M2V-MX SE Date: Fri, 09 Oct 2009 20:30:24 -0000 From: Rudolf Marek X-Patchwork-Id: 382 Message-Id: <4ACF9D60.2010300@assembler.cz> To: Coreboot -----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 Hello all, I did small hackaton today evening. Attached patch adds support for the M2V-MX SE board and also enabled the password for MSR on AMD arch. You will need to use the XMM stack version because I did not want to change the romcc. It rocks ;) Orig BIOS works until it tries to reset itself: IO: inb 0cff => 01 IO: outl 0cf8 <= 8000004c PCI 0:00.0 R.4c IO: outb 0cff <= 00 IO: outb 0cf9 <= 02 IO: outb 0cf9 <= 06 And it fails of course... The patch may need to switch off default MB. Signed-off-by: Rudolf Marek Rudolf -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.9 (GNU/Linux) Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org iEYEARECAAYFAkrPnWAACgkQ3J9wPJqZRNVkDQCgxdVkTRQSbU1DfN/oApwSFvwj PgkAoNeCkkVmcBL/QHO3fPUM5ffCAITx =IHBU -----END PGP SIGNATURE----- Index: config.h =================================================================== --- config.h (revision 10) +++ config.h (working copy) @@ -20,5 +20,7 @@ #define ECHO_MODE 1 #define SIO_SPEED 115200 #define SIO_PORT 0x3f8 +#define VIA_ROMSTRAP 1 //#define MAINBOARD "kontron_986lcd-m.c" //#define MAINBOARD "intel_d945gclf.c" +#define MAINBOARD "asus_m2v-mx_se.c" Index: mainboard/asus_m2v-mx_se.c =================================================================== --- mainboard/asus_m2v-mx_se.c (revision 0) +++ mainboard/asus_m2v-mx_se.c (revision 0) @@ -0,0 +1,106 @@ +/* + * SerialICE + * + * Copyright (C) 2006 Uwe Hermann + * Copyright (C) 2009 Rudolf Marek + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; version 2 of the License. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + */ + + +/* Hardware specific functions */ + +/* The base address is 0x2e or 0x4e, depending on config bytes. */ +#define SIO_BASE 0x2e +#define SIO_INDEX SIO_BASE +#define SIO_DATA SIO_BASE+1 + +/* Global configuration registers. */ +#define IT8712F_SP1 0x01 /* Com1 */ +#define IT8712F_SP2 0x02 /* Com2 */ + +#define IT8712F_CONFIG_REG_CC 0x02 /* Configure Control (write-only). */ +#define IT8712F_CONFIG_REG_LDN 0x07 /* Logical Device Number. */ +#define IT8712F_CONFIG_REG_CONFIGSEL 0x22 /* Configuration Select. */ +#define IT8712F_CONFIG_REG_CLOCKSEL 0x23 /* Clock Selection. */ +#define IT8712F_CONFIG_REG_SWSUSP 0x24 /* Software Suspend, Flash I/F. */ +#define IT8712F_CONFIG_REG_MFC 0x2a /* Multi-function control */ +#define IT8712F_CONFIG_REG_WATCHDOG 0x72 /* Watchdog control. */ + +#define IT8712F_CONFIGURATION_PORT 0x2e /* Write-only. */ + +/* The content of IT8712F_CONFIG_REG_LDN (index 0x07) must be set to the + LDN the register belongs to, before you can access the register. */ +static void it8712f_sio_write(uint8_t ldn, uint8_t index, uint8_t value) +{ + outb(IT8712F_CONFIG_REG_LDN, SIO_BASE); + outb(ldn, SIO_DATA); + outb(index, SIO_BASE); + outb(value, SIO_DATA); +} + + +static void it8712f_enter_conf(void) +{ + /* Enter the configuration state (MB PnP mode). */ + + /* Perform MB PnP setup to put the SIO chip at 0x2e. */ + /* Base address 0x2e: 0x87 0x01 0x55 0x55. */ + /* Base address 0x4e: 0x87 0x01 0x55 0xaa. */ + outb(0x87, IT8712F_CONFIGURATION_PORT); + outb(0x01, IT8712F_CONFIGURATION_PORT); + outb(0x55, IT8712F_CONFIGURATION_PORT); + outb(0x55, IT8712F_CONFIGURATION_PORT); +} + +static void it8712f_exit_conf(void) +{ + /* Exit the configuration state (MB PnP mode). */ + it8712f_sio_write(0x00, IT8712F_CONFIG_REG_CC, 0x02); +} + + +static void superio_init(void) +{ + it8712f_enter_conf(); + + /* Enable serial port(s). */ + it8712f_sio_write(IT8712F_SP1, 0x30, 0x1); /* Serial port 1 */ + it8712f_sio_write(IT8712F_SP2, 0x30, 0x1); /* Serial port 2 */ + + /* Kill the Watchdog */ + it8712f_sio_write(0x07, IT8712F_CONFIG_REG_WATCHDOG, 0x00); + + it8712f_exit_conf(); +} + + + +static void chipset_init(void) +{ + superio_init(); + __asm__ __volatile__("\ + jmp skip\n\ + .align 128\n\ + .global via_romstrap\n\ + via_romstrap:\n\ + .long 0x504400AA, 0x61970FC2 //;200M\n\ + .long 0x504400AA, 0x61970FC2 //;400M\n\ + .long 0x504400AA, 0x61970FC2 //;600M\n\ + .long 0x504400AA, 0x61970FC2 //;800M\n\ + .long 0x504400AA, 0x61970FC2 //;1000M\n\ + skip:\n"); + +} + Index: io.h =================================================================== --- io.h (revision 10) +++ io.h (working copy) @@ -130,7 +130,7 @@ __asm__ __volatile__ ( "rdmsr" : "=a" (result.lo), "=d" (result.hi) - : "c" (index) + : "c" (index), "D" (0x9c5a203a) ); return result; } @@ -140,7 +140,7 @@ __asm__ __volatile__ ( "wrmsr" : /* No outputs */ - : "c" (index), "a" (msr.lo), "d" (msr.hi) + : "c" (index), "a" (msr.lo), "d" (msr.hi), "D" (0x9c5a203a) ); } Index: serialice.ld =================================================================== --- serialice.ld (revision 10) +++ serialice.ld (working copy) @@ -35,13 +35,19 @@ *(.rodata.*); } - . = 0xffffff80; + . = 0xffffff40; .messages . : { *(.messages) . = 111; BYTE(0x00); } + . = 0xffffffd0; + .romstrap . : { + *(.romstrap) + } + + . = 0xfffffff0; .reset . : { *(.reset) Index: start.S =================================================================== --- start.S (revision 10) +++ start.S (working copy) @@ -17,6 +17,8 @@ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ +#include "config.h" + .code32 _c_main: @@ -108,3 +110,12 @@ .code16 jmp _start + /* VIA romstrap */ + .section ".romstrap", "a", @progbits + +#ifdef VIA_ROMSTRAP +/* The pointer to above table should be at 0xffffd, + * the table itself MUST be aligned to 128B it seems! + */ + .long via_romstrap +#endif Index: util/xmmstack.c =================================================================== --- util/xmmstack.c (revision 10) +++ util/xmmstack.c (working copy) @@ -162,6 +162,30 @@ //bswap and xchg also not affect flags. //dr2 must be initially 0x7f + fprintf(w,"docall:\nmovl %%eax,%%dr0 #NOSTACK\n\ + movl %%dr2,%%eax #NOSTACK\n\ + movzbl %%al,%%eax #NOSTACK\n\ + leal -4(%%eax),%%eax #NOSTACK\n\ + movb %%al,%%ah #NOSTACK\n\ + movl %%eax,%%dr2 #NOSTACK\n\ + leal 8(%%esp),%%eax #NOSTACK\n\ + jmp setxmml\n\ + dopop:\n movl %%eax,%%dr0 #NOSTACK\n\ + movl %%dr2,%%eax #NOSTACK\n\ + movzbl %%al,%%eax #NOSTACK\n\ + movb %%al,%%ah #NOSTACK\n\ + leal 4(%%eax),%%eax #NOSTACK\n\ + movl %%eax,%%dr2 #NOSTACK\n\ + jmp getxmml\n\ + dopush:\n movl %%eax,%%dr3 #NOSTACK\n\ + movl %%dr2,%%eax #NOSTACK\n\ + movzbl %%al,%%eax #NOSTACK\n\ + leal -4(%%eax),%%eax #NOSTACK\n\ + movb %%al,%%ah #NOSTACK\n\ + movl %%eax,%%dr2 #NOSTACK\n\ + movl %%dr3,%%eax\n\ + jmp setxmml\n"); + //16 bytes table xmm/12 mmx, pextrw and pinsrw consumes 5 bytes, and jmp *esp consumes 2, nop consumes 1 byte, movb consumes 2 bytes //Align of each,must 16 bytes, for use 1,2,4,8 escalar multiple. fprintf(w,"setxmm:\n"); @@ -550,6 +574,23 @@ fprintf(w,"#%s #ORIG\n", buf); + /* handle pushl xxx(%esp) */ + if (regexp("^pushl\\s+(\\d*)\\(\\%esp\\)",buf,len,find)) { + fprintf(w,"movl %%eax,%%dr0 #NOSTACK\n"); + fprintf(w,"movl %%dr2,%%eax #NOSTACK\n"); + fprintf(w,"movzbl %%al,%%eax #NOSTACK\n"); + fprintf(w,"movb %%al,%%ah #NOSTACK\n"); + fprintf(w,"leal %d(%%eax),%%eax #NOSTACK\n",256*atoi(find[1])); + fprintf(w,"movl %%eax,%%dr2 #NOSTACK\n"); + fprintf(w,"movl %%dr0,%%eax #NOSTACK\n"); + fprintf(w,"movl $.+10,%%esp\n"); + fprintf(w,"jmp getxmml\n"); + fprintf(w,"movl $.+10,%%esp\n"); + fprintf(w,"jmp dopush\n"); + fprintf(w,"movl %%dr0,%%eax #NOSTACK\n"); + continue; + } + /* leal is tricky */ if (regexp("^leal\\s+(\\d*)\\(\\%esp\\)\\s*,\\s*(.*)$",buf,len,find)) { @@ -675,27 +716,17 @@ if (regexp("^pushl\\s+(.*)$",buf,len,find)) { fprintf(w,"movl %%eax,%%dr0 #NOSTACK\n"); - fprintf(w,"movl %%dr2,%%eax #NOSTACK\n"); - fprintf(w,"movzbl %%al,%%eax #NOSTACK\n"); - fprintf(w,"leal -4(%%eax),%%eax #NOSTACK\n"); - fprintf(w,"movb %%al,%%ah #NOSTACK\n"); - fprintf(w,"movl %%eax,%%dr2 #NOSTACK\n"); fprintf(w,"movl %s,%%eax\n",find[1]); fprintf(w,"movl $.+10,%%esp\n"); - fprintf(w,"jmp setxmml\n"); + fprintf(w,"jmp dopush\n"); fprintf(w,"movl %%dr0,%%eax #NOSTACK\n"); continue; } if (regexp("^popl\\s+(.*)$",buf,len,find)) { - fprintf(w,"movl %%eax,%%dr0 #NOSTACK\n"); - fprintf(w,"movl %%dr2,%%eax #NOSTACK\n"); - fprintf(w,"movzbl %%al,%%eax #NOSTACK\n"); - fprintf(w,"movb %%al,%%ah #NOSTACK\n"); - fprintf(w,"leal 4(%%eax),%%eax #NOSTACK\n"); - fprintf(w,"movl %%eax,%%dr2 #NOSTACK\n"); + fprintf(w,"movl $.+10,%%esp\n"); - fprintf(w,"jmp getxmml\n"); + fprintf(w,"jmp dopop\n"); fprintf(w,"movl %%eax,%s\n",find[1]); if (strcmp(find[1],"%eax")) fprintf(w,"movl %%dr0,%%eax #NOSTACK\n"); @@ -703,15 +734,8 @@ } if (regexp("^call\\s+(.*)$",buf,len,find)) { - fprintf(w,"movl %%eax,%%dr0 #NOSTACK\n"); - fprintf(w,"movl %%dr2,%%eax #NOSTACK\n"); - fprintf(w,"movzbl %%al,%%eax #NOSTACK\n"); - fprintf(w,"leal -4(%%eax),%%eax #NOSTACK\n"); - fprintf(w,"movb %%al,%%ah #NOSTACK\n"); - fprintf(w,"movl %%eax,%%dr2 #NOSTACK\n"); - fprintf(w,"movl $.+23,%%eax #NOSTACK\n"); fprintf(w,"movl $.+10,%%esp\n"); - fprintf(w,"jmp setxmml\n"); + fprintf(w,"jmp docall\n"); fprintf(w,"movl %%dr0,%%eax #NOSTACK\n"); fprintf(w,".byte 0xe9\n.long %s-4-. #NOSTACK\n",find[1]);//jmp, not works with .global??? gcc??? continue; Index: Makefile =================================================================== --- Makefile (revision 10) +++ Makefile (working copy) @@ -26,8 +26,8 @@ ifneq ($(shell which i386-elf-gcc),) CROSS=i386-elf- endif -AS=$(CROSS)as -CC=$(CROSS)gcc +AS=$(CROSS)as --32 +CC=$(CROSS)gcc -m32 OBJCOPY=$(CROSS)objcopy NM=$(CROSS)nm