From 8bf63395ca00458da14b0b3e37a63761ea6767ab Mon Sep 17 00:00:00 2001 From: "H. Peter Anvin" Date: Sun, 17 May 2009 13:39:42 -0700 Subject: [PATCH] core: move 32-bit code out of the .text16 segment Move all 32-bit code out of the .text16 segment. The code that is used during the relocation of the .text segment (i.e. anywhere on the bcopy path) is moved to .textnr (other than the code already in .bcopyxx) for "no relocate", the rest of the code to .text. Signed-off-by: H. Peter Anvin --- core/com32.inc | 13 +++++++++---- core/pm.inc | 20 ++++++++++++++------ core/syslinux.ld | 14 ++++++++++++++ 3 files changed, 37 insertions(+), 10 deletions(-) diff --git a/core/com32.inc b/core/com32.inc index 632f973..0165c0f 100644 --- a/core/com32.inc +++ b/core/com32.inc @@ -62,7 +62,7 @@ com32_start: mov eax,[HighMemRsvd] xor ax,ax ; Align to a 64K boundary mov [PMESP],eax - mov bx,.pm ; Where to go in PM + mov ebx,.pm ; Where to go in PM jmp enter_pm ; @@ -70,6 +70,7 @@ com32_start: ; progam, in 32-bit mode... ; bits 32 + section .text .pm: ; Set up the calling stack frame @@ -90,6 +91,7 @@ com32_exit: jmp enter_rm bits 16 + section .text16 .rm: mov dword [PMESP],__stack_end ; Stop use of COM32 stack sti @@ -99,6 +101,7 @@ com32_exit: ; 16-bit intcall/farcall handling code ; bits 16 + section .text16 com32_sys_rm: pop gs @@ -119,7 +122,7 @@ com32_sys_rm: push es push fs push gs - mov bx,com32_syscall.resume + mov ebx,com32_syscall.resume jmp enter_pm ; @@ -130,13 +133,14 @@ com32_cfar_rm: .return: mov sp,[cs:Com32SysSP] mov esi,eax - mov bx,core_cfarcall.resume + mov ebx,core_cfarcall.resume jmp enter_pm ; ; 32-bit support code ; bits 32 + section .text ; ; Intcall/farcall invocation. We manifest a structure on the real-mode stack, @@ -272,9 +276,10 @@ core_cfarcall: ret bits 16 - section .bss16 alignb 4 Com32SysSP resd 1 ; SP saved during COM32 syscall + bits 16 section .text16 + diff --git a/core/pm.inc b/core/pm.inc index 3b7dab4..0f2fbb4 100644 --- a/core/pm.inc +++ b/core/pm.inc @@ -20,6 +20,7 @@ ;; PM refers to 32-bit flat protected mode; RM to 16-bit real mode. ;; + bits 16 section .text16 ; ; _pm_call: call PM routine in low memory from RM @@ -34,7 +35,6 @@ ; ; This routine is invoked by the pm_call macro. ; - bits 16 _pm_call: pushfd pushad @@ -44,11 +44,12 @@ _pm_call: push gs mov bp,sp mov ax,cs - mov bx,.pm + mov ebx,.pm mov ds,ax jmp enter_pm bits 32 + section .textnr .pm: ; EAX points to the top of the RM stack, which is EFLAGS test RM_FLAGSH,02h ; RM EFLAGS.IF @@ -60,6 +61,7 @@ _pm_call: jmp enter_rm bits 16 + section .text16 .rm: pop gs pop fs @@ -71,7 +73,7 @@ _pm_call: ; ; enter_pm: Go to PM with interrupt service configured -; BX = PM entry point (in low memory) +; EBX = PM entry point ; EAX = EBP = on exit, points to the RM stack as a 32-bit value ; ECX, EDX, ESI, EDI preserved across this routine ; @@ -81,6 +83,7 @@ _pm_call: ; can enable interrupts by executing STI. ; bits 16 + section .text16 enter_pm: cli xor eax,eax @@ -105,6 +108,7 @@ enter_pm: jmp PM_CS32:.in_pm bits 32 + section .textnr .in_pm: xor eax,eax ; Available for future use... mov fs,eax @@ -121,7 +125,7 @@ enter_pm: mov esp,[PMESP] ; Load protmode %esp mov eax,ebp ; EAX -> top of real-mode stack - jmp bx ; Go to where we need to go + jmp ebx ; Go to where we need to go ; ; enter_rm: Return to RM from PM @@ -135,6 +139,7 @@ enter_pm: ; can enable interrupts by executing STI. ; bits 32 + section .textnr enter_rm: cli cld @@ -142,6 +147,7 @@ enter_rm: jmp PM_CS16:.in_pm16 ; Return to 16-bit mode first bits 16 + section .text16 .in_pm16: mov ax,PM_DS16 ; Real-mode-like segment mov es,ax @@ -184,14 +190,15 @@ PM_IDT_ptr: dw 8*256-1 ; Length ; AL contains the register number. ; bits 32 - section .text16 + section .textnr pm_irq: pushad movzx esi,byte [esp+8*4] ; Interrupt number - mov bx,.rm + mov ebx,.rm jmp enter_rm ; Go to real mode bits 16 + section .text16 .rm: pushf ; Flags on stack call far [cs:esi*4] ; Call IVT entry @@ -199,6 +206,7 @@ pm_irq: jmp enter_pm ; Go back to PM bits 32 + section .textnr .pm: popad add esp,4 ; Drop interrupt number diff --git a/core/syslinux.ld b/core/syslinux.ld index 6e965c0..9149b9b 100644 --- a/core/syslinux.ld +++ b/core/syslinux.ld @@ -96,6 +96,20 @@ SECTIONS __text16_len = __text16_end - __text16_start; __text16_dwords = (__text16_len + 3) >> 2; + /* + * .textnr is used for 32-bit code that is used on the code + * path to initialize the .text segment + */ + . = ALIGN(16); + .textnr : { + FILL(0x90909090) + __textnr_start = .; + *(.textnr) + __textnr_end = .; + } + __textnr_len = __textnr_end - __textnr_start; + __textnr_dwords = (__textnr_len + 3) >> 2; + . = ALIGN(16); .bcopyxx : { FILL(0x90909090) -- 2.7.4