#define __BYTE_ORDER __LITTLE_ENDIAN
-#define le32_to_cpup(x) (*(uint32_t *)(x))
-#define cpu_to_le16p(x) (*(uint16_t*)(x))
-
#endif /* ETHERBOOT_BITS_ENDIAN_H */
}
/**
+ * Find character in user buffer
+ *
+ * @v buffer User buffer
+ * @v offset Starting offset within buffer
+ * @v c Character to search for
+ * @v len Length of user buffer
+ * @ret offset Offset of character, or <0 if not found
+ */
+static inline __attribute__ (( always_inline )) off_t
+memchr_user ( userptr_t buffer, off_t offset, int c, size_t len ) {
+ void *found;
+
+ found = memchr ( ( ( void * ) buffer + offset ), c, len );
+ return ( found ? ( found - ( void * ) buffer ) : -1 );
+}
+
+/**
* Convert virtual address to user buffer
*
* @v virtual Virtual address
call print_message
xorw %ax, %ax
movw %ax, %es
+ pushl %es:( 0x19 * 4 )
+ popl orig_int19
pushw %cs
pushw $int19_entry
popl %es:( 0x19 * 4 )
/* INT19 entry point
*
- * Called via the hooked INT 19 if we detected a non-PnP BIOS.
+ * Called via the hooked INT 19 if we detected a non-PnP BIOS. We
+ * attempt to return via the original INT 19 vector (if we were able to
+ * store it).
*/
int19_entry:
pushw %cs
call exec
- /* No real way to return from INT19 */
+ movl %cs:orig_int19, %eax
+ testl %eax, %eax
+ je 1f
+ /* Chain to original INT 19 vector */
+ ljmp *%cs:orig_int19
+1: /* No chained vector: issue INT 18 as a last resort */
int $0x18
.size int19_entry, . - int19_entry
+orig_int19:
+ .long 0
+ .size orig_int19, . - orig_int19
/* Execute as a boot device
*
PCI_ROM(0x14e4, 0x1677, "tg3-5751", "Broadcom Tigon 3 5751"),
PCI_ROM(0x14e4, 0x1696, "tg3-5782", "Broadcom Tigon 3 5782"),
PCI_ROM(0x14e4, 0x169c, "tg3-5788", "Broadcom Tigon 3 5788"),
+PCI_ROM(0x14e4, 0x169d, "tg3-5789", "Broadcom Tigon 3 5789"),
PCI_ROM(0x14e4, 0x16a6, "tg3-5702X", "Broadcom Tigon 3 5702X"),
PCI_ROM(0x14e4, 0x16a7, "tg3-5703X", "Broadcom Tigon 3 5703X"),
PCI_ROM(0x14e4, 0x16a8, "tg3-5704S", "Broadcom Tigon 3 5704S"),
/* Determine total length of command line */
len = 1; /* NUL */
for ( i = 0 ; i < nargs ; i++ )
- len += ( 1 /* space */ + strlen ( args[i] ) );
+ len += ( 1 /* possible space */ + strlen ( args[i] ) );
{
char buf[len];
char *ptr = buf;
/* Assemble command line */
- for ( i = 0 ; i < nargs ; i++ )
- ptr += sprintf ( ptr, " %s", args[i] );
- assert ( ptr == ( buf + len - 1 ) );
+ buf[0] = '\0';
+ for ( i = 0 ; i < nargs ; i++ ) {
+ ptr += sprintf ( ptr, "%s%s", ( i ? " " : "" ),
+ args[i] );
+ }
+ assert ( ptr < ( buf + len ) );
- return image_set_cmdline ( image, &buf[1] );
+ return image_set_cmdline ( image, buf );
}
}
* data structure.
*/
-#include <stdio.h>
#include <gpxe/image.h>
#include <gpxe/malloc.h>
#include <gpxe/uaccess.h>
if ( reclaimed )
return NULL; /* Already reclaimed */
- printf("Embedded image: %d bytes at %p\n",
- eisize, _embedded_image_start);
+ DBG ( "Embedded image: %zd bytes at %p\n",
+ eisize, _embedded_image_start );
image = alloc_image();
if (!image)
* @ret rc Return status code
*/
static int script_exec ( struct image *image ) {
- char cmdbuf[256];
size_t offset = 0;
- size_t remaining;
+ off_t eol;
size_t len;
- char *eol;
int rc;
/* Temporarily de-register image, so that a "boot" command
while ( offset < image->len ) {
- /* Read up to cmdbuf bytes from script into buffer */
- remaining = ( image->len - offset );
- len = sizeof ( cmdbuf );
- if ( len > remaining )
- len = remaining;
- memset ( cmdbuf, 0, sizeof ( cmdbuf ) );
- copy_from_user ( cmdbuf, image->data, offset, len );
+ /* Find length of next line, excluding any terminating '\n' */
+ eol = memchr_user ( image->data, offset, '\n',
+ ( image->len - offset ) );
+ if ( eol < 0 )
+ eol = image->len;
+ len = ( eol - offset );
- /* Find end of line */
- eol = memchr ( cmdbuf, '\n', sizeof ( cmdbuf ) );
- if ( ! eol )
- eol = memchr ( cmdbuf, '\0', sizeof ( cmdbuf ) );
- if ( ! eol ) {
- DBG ( "Script line too long (max %zd bytes)\n",
- sizeof ( cmdbuf ) );
- rc = -ENOEXEC;
- goto done;
- }
+ /* Copy line, terminate with NUL, and execute command */
+ {
+ char cmdbuf[ len + 1 ];
- /* Mark end of line and execute command */
- *eol = '\0';
- DBG ( "$ %s\n", cmdbuf );
- if ( ( rc = system ( cmdbuf ) ) != 0 ) {
- DBG ( "Command \"%s\" failed: %s\n",
- cmdbuf, strerror ( rc ) );
- goto done;
+ copy_from_user ( cmdbuf, image->data, offset, len );
+ cmdbuf[len] = '\0';
+ DBG ( "$ %s\n", cmdbuf );
+ if ( ( rc = system ( cmdbuf ) ) != 0 ) {
+ DBG ( "Command \"%s\" failed: %s\n",
+ cmdbuf, strerror ( rc ) );
+ goto done;
+ }
}
/* Move to next line */
- offset += ( ( eol - cmdbuf ) + 1 );
+ offset += ( len + 1 );
}
rc = 0;
* @endcode
*
*/
-#define __shared __asm__ ( "_shared_bss" )
+#define __shared __asm__ ( "_shared_bss" ) __aligned
/**
* Optimisation barrier
init_spi ( device );
}
+/** ST M25P32 serial flash */
+static inline __attribute__ (( always_inline )) void
+init_m25p32 ( struct spi_device *device ) {
+ device->address_len = 24;
+ device->nvs.size = ( 4 * 1024 * 1024 );
+ device->nvs.block_size = 256;
+ init_spi ( device );
+}
+
/** Microchip 25XX640 serial EEPROM */
static inline __attribute__ (( always_inline )) void
init_mc25xx640 ( struct spi_device *device ) {
if ( blksize < TFTP_DEFAULT_BLKSIZE )
blksize = TFTP_DEFAULT_BLKSIZE;
snprintf ( uri_string, sizeof ( uri_string ),
- "tftp://%s:%d%s%s?blksize=%d",
+ "tftp://%s:%d%s%s?blksize=%zd",
inet_ntoa ( address ), ntohs ( port ),
( ( filename[0] == '/' ) ? "" : "/" ), filename, blksize );
DBG ( " %s", uri_string );