瀏覽代碼

[undi] Allocate base memory before calling UNDI loader entry point

Allocate base memory (by decreasing the free base memory counter)
before calling the UNDI loader entry point, to minimise surprises for
the UNDI loader code.

Signed-off-by: Michael Brown <mcb30@ipxe.org>
tags/v1.20.1
Michael Brown 8 年之前
父節點
當前提交
8138ea190d
共有 1 個檔案被更改,包括 16 行新增14 行删除
  1. 16
    14
      src/arch/x86/drivers/net/undiload.c

+ 16
- 14
src/arch/x86/drivers/net/undiload.c 查看文件

72
 	/* Only one UNDI instance may be loaded at any given time */
72
 	/* Only one UNDI instance may be loaded at any given time */
73
 	if ( undi_loader_entry.segment ) {
73
 	if ( undi_loader_entry.segment ) {
74
 		DBG ( "UNDI %p cannot load multiple instances\n", undi );
74
 		DBG ( "UNDI %p cannot load multiple instances\n", undi );
75
-		return -EBUSY;
75
+		rc = -EBUSY;
76
+		goto err_multiple;
76
 	}
77
 	}
77
 
78
 
78
 	/* Set up START_UNDI parameters */
79
 	/* Set up START_UNDI parameters */
90
 	undi_loader.UNDI_CS = fbms_seg;
91
 	undi_loader.UNDI_CS = fbms_seg;
91
 	fbms_seg -= ( ( undirom->data_size + 0x0f ) >> 4 );
92
 	fbms_seg -= ( ( undirom->data_size + 0x0f ) >> 4 );
92
 	undi_loader.UNDI_DS = fbms_seg;
93
 	undi_loader.UNDI_DS = fbms_seg;
94
+	undi->fbms = ( fbms_seg >> 6 );
95
+	set_fbms ( undi->fbms );
96
+	DBGC ( undi, "UNDI %p allocated [%d,%d) kB of base memory\n",
97
+	       undi, undi->fbms, undi->restore_fbms );
93
 
98
 
94
 	/* Debug info */
99
 	/* Debug info */
95
-	DBGC ( undi, "UNDI %p loading UNDI ROM %p to CS %04x DS %04x for ",
96
-	       undi, undirom, undi_loader.UNDI_CS, undi_loader.UNDI_DS );
100
+	DBGC ( undi, "UNDI %p loading ROM %p to CS %04x:%04zx DS %04x:%04zx "
101
+	       "for ", undi, undirom, undi_loader.UNDI_CS, undirom->code_size,
102
+	       undi_loader.UNDI_DS, undirom->data_size );
97
 	if ( undi->pci_busdevfn != UNDI_NO_PCI_BUSDEVFN ) {
103
 	if ( undi->pci_busdevfn != UNDI_NO_PCI_BUSDEVFN ) {
98
 		unsigned int bus = ( undi->pci_busdevfn >> 8 );
104
 		unsigned int bus = ( undi->pci_busdevfn >> 8 );
99
 		unsigned int devfn = ( undi->pci_busdevfn & 0xff );
105
 		unsigned int devfn = ( undi->pci_busdevfn & 0xff );
116
 			       : "=a" ( exit )
122
 			       : "=a" ( exit )
117
 			       : "a" ( __from_data16 ( &undi_loader ) )
123
 			       : "a" ( __from_data16 ( &undi_loader ) )
118
 			       : "ebx", "ecx", "edx", "esi", "edi" );
124
 			       : "ebx", "ecx", "edx", "esi", "edi" );
119
-
120
 	if ( exit != PXENV_EXIT_SUCCESS ) {
125
 	if ( exit != PXENV_EXIT_SUCCESS ) {
121
-		/* Clear entry point */
122
-		memset ( &undi_loader_entry, 0, sizeof ( undi_loader_entry ) );
123
-
124
 		rc = -EUNDILOAD ( undi_loader.Status );
126
 		rc = -EUNDILOAD ( undi_loader.Status );
125
 		DBGC ( undi, "UNDI %p loader failed: %s\n",
127
 		DBGC ( undi, "UNDI %p loader failed: %s\n",
126
 		       undi, strerror ( rc ) );
128
 		       undi, strerror ( rc ) );
127
-		return rc;
129
+		goto err_loader;
128
 	}
130
 	}
129
 
131
 
130
 	/* Populate PXE device structure */
132
 	/* Populate PXE device structure */
138
 	       undi->pxenv.offset, undi->ppxe.segment, undi->ppxe.offset,
140
 	       undi->pxenv.offset, undi->ppxe.segment, undi->ppxe.offset,
139
 	       undi->entry.segment, undi->entry.offset );
141
 	       undi->entry.segment, undi->entry.offset );
140
 
142
 
141
-	/* Update free base memory counter */
142
-	undi->fbms = ( fbms_seg >> 6 );
143
-	set_fbms ( undi->fbms );
144
-	DBGC ( undi, "UNDI %p using [%d,%d) kB of base memory\n",
145
-	       undi, undi->fbms, undi->restore_fbms );
146
-
147
 	return 0;
143
 	return 0;
144
+
145
+ err_loader:
146
+	set_fbms ( undi->restore_fbms );
147
+	memset ( &undi_loader_entry, 0, sizeof ( undi_loader_entry ) );
148
+ err_multiple:
149
+	return rc;
148
 }
150
 }
149
 
151
 
150
 /**
152
 /**

Loading…
取消
儲存