Browse Source

[pxe] Create pxe_[de]activate() wrapper functions

Merge the pxe_set_netdev()+pxe_[un]hook_int1a() pattern into a single
pxe_[de]activate() call.
tags/v0.9.8
Michael Brown 15 years ago
parent
commit
07b5be3341

+ 6
- 9
src/arch/i386/image/pxe_image.c View File

44
  * @ret rc		Return status code
44
  * @ret rc		Return status code
45
  */
45
  */
46
 static int pxe_exec ( struct image *image ) {
46
 static int pxe_exec ( struct image *image ) {
47
+	struct net_device *netdev;
47
 	int rc;
48
 	int rc;
48
 
49
 
49
-	/* Ensure that PXE stack is ready to use */
50
-	pxe_hook_int1a();
51
-
52
 	/* Arbitrarily pick the most recently opened network device */
50
 	/* Arbitrarily pick the most recently opened network device */
53
-	pxe_set_netdev ( last_opened_netdev() );
54
-
55
-	/* Many things will break if pxe_netdev is NULL */
56
-	if ( ! pxe_netdev ) {
51
+	if ( ( netdev = last_opened_netdev() ) == NULL ) {
57
 		DBGC ( image, "IMAGE %p could not locate PXE net device\n",
52
 		DBGC ( image, "IMAGE %p could not locate PXE net device\n",
58
 		       image );
53
 		       image );
59
 		return -ENODEV;
54
 		return -ENODEV;
60
 	}
55
 	}
61
 
56
 
57
+	/* Activate PXE */
58
+	pxe_activate ( netdev );
59
+
62
 	/* Start PXE NBP */
60
 	/* Start PXE NBP */
63
 	rc = pxe_start_nbp();
61
 	rc = pxe_start_nbp();
64
 
62
 
65
 	/* Deactivate PXE */
63
 	/* Deactivate PXE */
66
-	pxe_set_netdev ( NULL );
67
-	pxe_unhook_int1a();
64
+	pxe_deactivate();
68
 
65
 
69
 	return rc;
66
 	return rc;
70
 }
67
 }

+ 4
- 2
src/arch/i386/include/pxe_call.h View File

11
 #include <pxe_api.h>
11
 #include <pxe_api.h>
12
 #include <realmode.h>
12
 #include <realmode.h>
13
 
13
 
14
+struct net_device;
15
+
14
 /** PXE load address segment */
16
 /** PXE load address segment */
15
 #define PXE_LOAD_SEGMENT 0
17
 #define PXE_LOAD_SEGMENT 0
16
 
18
 
28
 extern struct s_PXENV __text16 ( pxenv );
30
 extern struct s_PXENV __text16 ( pxenv );
29
 #define pxenv __use_text16 ( pxenv )
31
 #define pxenv __use_text16 ( pxenv )
30
 
32
 
31
-extern void pxe_hook_int1a ( void );
32
-extern int pxe_unhook_int1a ( void );
33
+extern void pxe_activate ( struct net_device *netdev );
34
+extern int pxe_deactivate ( void );
33
 extern int pxe_start_nbp ( void );
35
 extern int pxe_start_nbp ( void );
34
 extern __asmcall void pxe_api_call ( struct i386_all_regs *ix86 );
36
 extern __asmcall void pxe_api_call ( struct i386_all_regs *ix86 );
35
 
37
 

+ 47
- 19
src/arch/i386/interface/pxe/pxe_call.c View File

37
 /** INT 1A handler */
37
 /** INT 1A handler */
38
 extern void pxe_int_1a ( void );
38
 extern void pxe_int_1a ( void );
39
 
39
 
40
+/** INT 1A hooked flag */
41
+static int int_1a_hooked = 0;
42
+
40
 /** A function pointer to hold any PXE API call
43
 /** A function pointer to hold any PXE API call
41
  *
44
  *
42
  * Used by pxe_api_call() to avoid large swathes of duplicated code.
45
  * Used by pxe_api_call() to avoid large swathes of duplicated code.
364
 	ix86->regs.ax = ret;
367
 	ix86->regs.ax = ret;
365
 }
368
 }
366
 
369
 
367
-/**
368
- * Hook INT 1A for PXE
369
- *
370
- */
371
-void pxe_hook_int1a ( void ) {
372
-	hook_bios_interrupt ( 0x1a, ( unsigned int ) pxe_int_1a,
373
-			      &pxe_int_1a_vector );
374
-}
375
-
376
-/**
377
- * Unhook INT 1A for PXE
378
- *
379
- * @ret rc		Return status code
380
- */
381
-int pxe_unhook_int1a ( void ) {
382
-	return unhook_bios_interrupt ( 0x1a, ( unsigned int ) pxe_int_1a,
383
-				       &pxe_int_1a_vector );
384
-}
385
-
386
 /**
370
 /**
387
  * Calculate byte checksum as used by PXE
371
  * Calculate byte checksum as used by PXE
388
  *
372
  *
435
 	.initialise = pxe_init_structures,
419
 	.initialise = pxe_init_structures,
436
 };
420
 };
437
 
421
 
422
+/**
423
+ * Activate PXE stack
424
+ *
425
+ * @v netdev		Net device to use as PXE net device
426
+ */
427
+void pxe_activate ( struct net_device *netdev ) {
428
+
429
+	/* Ensure INT 1A is hooked */
430
+	if ( ! int_1a_hooked ) {
431
+		hook_bios_interrupt ( 0x1a, ( unsigned int ) pxe_int_1a,
432
+				      &pxe_int_1a_vector );
433
+		int_1a_hooked = 1;
434
+	}
435
+
436
+	/* Set PXE network device */
437
+	pxe_set_netdev ( netdev );
438
+}
439
+
440
+/**
441
+ * Deactivate PXE stack
442
+ *
443
+ * @ret rc		Return status code
444
+ */
445
+int pxe_deactivate ( void ) {
446
+	int rc;
447
+
448
+	/* Clear PXE network device */
449
+	pxe_set_netdev ( NULL );
450
+
451
+	/* Ensure INT 1A is unhooked, if possible */
452
+	if ( int_1a_hooked ) {
453
+		if ( ( rc = unhook_bios_interrupt ( 0x1a,
454
+						    (unsigned int) pxe_int_1a,
455
+						    &pxe_int_1a_vector ))!= 0){
456
+			DBG ( "Could not unhook INT 1A: %s\n",
457
+			      strerror ( rc ) );
458
+			return rc;
459
+		}
460
+		int_1a_hooked = 0;
461
+	}
462
+
463
+	return 0;
464
+}
465
+
438
 /**
466
 /**
439
  * Start PXE NBP at 0000:7c00
467
  * Start PXE NBP at 0000:7c00
440
  *
468
  *

+ 4
- 10
src/arch/i386/interface/pxe/pxe_preboot.c View File

296
 	}
296
 	}
297
 	DBG ( " using netdev %s", netdev->name );
297
 	DBG ( " using netdev %s", netdev->name );
298
 
298
 
299
-	/* Save as PXE net device */
300
-	pxe_set_netdev ( netdev );
301
-
302
-	/* Hook INT 1A */
303
-	pxe_hook_int1a();
299
+	/* Activate PXE */
300
+	pxe_activate ( netdev );
304
 
301
 
305
 	start_undi->Status = PXENV_STATUS_SUCCESS;
302
 	start_undi->Status = PXENV_STATUS_SUCCESS;
306
 	return PXENV_EXIT_SUCCESS;
303
 	return PXENV_EXIT_SUCCESS;
313
 PXENV_EXIT_t pxenv_stop_undi ( struct s_PXENV_STOP_UNDI *stop_undi ) {
310
 PXENV_EXIT_t pxenv_stop_undi ( struct s_PXENV_STOP_UNDI *stop_undi ) {
314
 	DBG ( "PXENV_STOP_UNDI" );
311
 	DBG ( "PXENV_STOP_UNDI" );
315
 
312
 
316
-	/* Unhook INT 1A */
317
-	pxe_unhook_int1a();
318
-
319
-	/* Clear PXE net device */
320
-	pxe_set_netdev ( NULL );
313
+	/* Deactivate PXE */
314
+	pxe_deactivate();
321
 
315
 
322
 	/* Prepare for unload */
316
 	/* Prepare for unload */
323
 	shutdown ( SHUTDOWN_BOOT );
317
 	shutdown ( SHUTDOWN_BOOT );

Loading…
Cancel
Save