From 95a461a83adf65aa5689b65f85330ce970121f56 Mon Sep 17 00:00:00 2001 From: "H. Peter Anvin" Date: Wed, 13 May 2009 22:05:41 -0700 Subject: [PATCH] core: zero bss and uibss; fix some section confusions Set .bss and .uibss as soon as we are fully loaded. This gives us the more familiar behavior of most normal execution environments. The .earlybss section is not zeroed; therefore, all variables that are set before we have the opportunity to zero need to go in this section. This checkin also fixes some incorrect section directives. Signed-off-by: H. Peter Anvin --- core/conio.inc | 2 ++ core/diskstart.inc | 7 +++--- core/extlinux.asm | 17 +++++++-------- core/init.inc | 11 ++++++++++ core/isolinux.asm | 10 +++++---- core/layout.inc | 2 ++ core/ldlinux.asm | 16 +++++++------- core/pxelinux.asm | 63 +++++++++++++++++++++++++++++------------------------- core/syslinux.ld | 3 +++ core/writehex.inc | 1 - core/writestr.inc | 1 - 11 files changed, 78 insertions(+), 55 deletions(-) diff --git a/core/conio.inc b/core/conio.inc index 8f5a292..fdb4b9f 100644 --- a/core/conio.inc +++ b/core/conio.inc @@ -395,3 +395,5 @@ FlowIgnore resb 1 ; Ignore input unless these bits set TextAttribute resb 1 ; Text attribute for message file DisplayMask resb 1 ; Display modes mask + + section .text diff --git a/core/diskstart.inc b/core/diskstart.inc index 6f38c7a..6896124 100644 --- a/core/diskstart.inc +++ b/core/diskstart.inc @@ -18,9 +18,10 @@ ; ; Expanded superblock - section .bss + section .earlybss alignb 8 SuperInfo resq 16 ; The first 16 bytes expanded 8 times +DriveNumber resb 1 section .init ; @@ -523,11 +524,11 @@ print_bios: mov [BIOSName],si call writestr_early - section .bss + section .earlybss %define HAVE_BIOSNAME 1 BIOSName resw 1 - section .text + section .init ; ; Now we read the rest of LDLINUX.SYS. Don't bother loading the first ; sector again, though. diff --git a/core/extlinux.asm b/core/extlinux.asm index 809571e..39b9813 100644 --- a/core/extlinux.asm +++ b/core/extlinux.asm @@ -108,7 +108,6 @@ ClustSize resd 1 ; Bytes/cluster ("block") ClustMask resd 1 ; Sectors/cluster - 1 PtrsPerBlock1 resd 1 ; Pointers/cluster PtrsPerBlock2 resd 1 ; (Pointers/cluster)^2 -DriveNumber resb 1 ; BIOS drive number ClustShift resb 1 ; Shift count for sectors/cluster ClustByteShift resb 1 ; Shift count for bytes/cluster @@ -121,6 +120,12 @@ Files resb MAX_OPEN*open_file_t_size %include "diskstart.inc" ; +; Common initialization code +; +%include "init.inc" +%include "cpuinit.inc" + +; ; Load the real (ext2) superblock; 1024 bytes long at offset 1024 ; mov bx,SuperBlock @@ -156,12 +161,6 @@ Files resb MAX_OPEN*open_file_t_size mov [PtrsPerBlock2],edx ; -; Common initialization code -; -%include "init.inc" -%include "cpuinit.inc" - -; ; Initialize the metadata cache ; call initcache @@ -174,8 +173,8 @@ Files resb MAX_OPEN*open_file_t_size mov di,kaboom.patch mov al,0e9h stosb - mov ax,kaboom2-3 - sub ax,bx + mov ax,kaboom2-2 + sub ax,di stosw ; diff --git a/core/init.inc b/core/init.inc index 0b213ac..827a509 100644 --- a/core/init.inc +++ b/core/init.inc @@ -2,6 +2,7 @@ ; ----------------------------------------------------------------------- ; ; Copyright 2004-2008 H. Peter Anvin - All Rights Reserved +; Copyright 2009 Intel Corporation; author: H. Peter Anvin ; ; 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 @@ -19,6 +20,16 @@ section .text common_init: + ; Zero bss sections (but not .earlybss, since it may + ; contain already-live data.) + xor eax,eax + mov di,__bss_start + mov cx,__bss_dwords + rep stosd + mov di,__uibss_start + mov cx,__uibss_dwords + rep stosd + ; Now set up screen parameters call adjust_screen diff --git a/core/isolinux.asm b/core/isolinux.asm index 921f7fa..9183b35 100644 --- a/core/isolinux.asm +++ b/core/isolinux.asm @@ -101,8 +101,8 @@ trackbuf resb trackbufsize ; Track buffer goes here ; ends at 2800h ; Some of these are touched before the whole image - ; is loaded. DO NOT move this to .uibss. - section .bss + ; is loaded. DO NOT move this to .bss/.uibss. + section .earlybss alignb 4 ISOFileName resb 64 ; ISO filename canonicalization buffer ISOFileNameEnd equ $ @@ -197,6 +197,7 @@ dsp_dummy: resb 1 ; Scratch, safe to overwrite _spec_end equ $ _spec_len equ _spec_end - _spec_start + section .bss alignb open_file_t_size Files resb MAX_OPEN*open_file_t_size @@ -1077,6 +1078,7 @@ rl_checkpt equ $ ; Must be <= 800h ; ---------------------------------------------------------------------------- ; End of code and data that have to be in the first sector ; ---------------------------------------------------------------------------- + section .text all_read: @@ -1095,8 +1097,8 @@ all_read: mov di,writechr mov al,0e9h stosb - mov ax,writechr_full-3 - sub ax,bx + mov ax,writechr_full-2 + sub ax,di stosw ; Tell the user we got this far... diff --git a/core/layout.inc b/core/layout.inc index 556f4a8..9a6fec5 100644 --- a/core/layout.inc +++ b/core/layout.inc @@ -72,6 +72,8 @@ RBFG_brainfuck: resb 2048 ; Bigger than an Ethernet packet... extern __%1_start, __%1_lma, __%1_end extern __%1_len, __%1_dwords %endmacro + SECINFO bss + SECINFO uibss SECINFO config SECINFO replacestub diff --git a/core/ldlinux.asm b/core/ldlinux.asm index 92dc6da..a37437c 100644 --- a/core/ldlinux.asm +++ b/core/ldlinux.asm @@ -127,7 +127,6 @@ TotalSectors resd 1 ; Total number of sectors ClustSize resd 1 ; Bytes/cluster ClustMask resd 1 ; Sectors/cluster - 1 CopySuper resb 1 ; Distinguish .bs versus .bss -DriveNumber resb 1 ; BIOS drive number ClustShift resb 1 ; Shift count for sectors/cluster ClustByteShift resb 1 ; Shift count for bytes/cluster @@ -140,6 +139,12 @@ Files resb MAX_OPEN*open_file_t_size %include "diskstart.inc" ; +; Common initialization code +; +%include "init.inc" +%include "cpuinit.inc" + +; ; Compute some information about this filesystem. ; @@ -212,11 +217,6 @@ getfattype: .setsize: mov byte [nextcluster+1],cl -; -; Common initialization code -; -%include "cpuinit.inc" -%include "init.inc" ; ; Initialize the metadata cache @@ -231,8 +231,8 @@ getfattype: mov di,kaboom.patch mov al,0e9h stosb - mov ax,kaboom2-3 - sub ax,bx + mov ax,kaboom2-2 + sub ax,di stosw ; diff --git a/core/pxelinux.asm b/core/pxelinux.asm index d98ee42..a8ce4e6 100644 --- a/core/pxelinux.asm +++ b/core/pxelinux.asm @@ -2714,34 +2714,35 @@ pxe_bootp_query_pkt: .buffer: resw 2 ; seg:off of buffer .bufferlimit: resw 1 ; Unused - section .data pxe_udp_open_pkt: -.status: dw 0 ; Status -.sip: dd 0 ; Source (our) IP +.status: resw 1 ; Status +.sip: resd 1 ; Source (our) IP pxe_udp_close_pkt: -.status: dw 0 ; Status +.status: resw 1 ; Status pxe_udp_write_pkt: -.status: dw 0 ; Status -.sip: dd 0 ; Server IP -.gip: dd 0 ; Gateway IP -.lport: dw 0 ; Local port -.rport: dw 0 ; Remote port -.buffersize: dw 0 ; Size of packet -.buffer: dw 0, 0 ; seg:off of buffer +.status: resw 1 ; Status +.sip: resd 1 ; Server IP +.gip: resd 1 ; Gateway IP +.lport: resw 1 ; Local port +.rport: resw 1 ; Remote port +.buffersize: resw 1 ; Size of packet +.buffer: resw 2 ; seg:off of buffer pxe_udp_read_pkt: -.status: dw 0 ; Status -.sip: dd 0 ; Source IP -.dip: dd 0 ; Destination (our) IP -.rport: dw 0 ; Remote port -.lport: dw 0 ; Local port -.buffersize: dw 0 ; Max packet size -.buffer: dw 0, 0 ; seg:off of buffer +.status: resw 1 ; Status +.sip: resd 1 ; Source IP +.dip: resd 1 ; Destination (our) IP +.rport: resw 1 ; Remote port +.lport: resw 1 ; Local port +.buffersize: resw 1 ; Max packet size +.buffer: resw 2 ; seg:off of buffer %if GPXE + section .data + gpxe_file_api_check: .status: dw 0 ; Status .size: dw 20 ; Size in bytes @@ -2750,28 +2751,32 @@ gpxe_file_api_check: .apimask: dd 0 .flags: dd 0 + section .bss + gpxe_file_open: -.status: dw 0 ; Status -.filehandle: dw 0 ; FileHandle -.filename: dd 0 ; seg:off of FileName -.reserved: dd 0 +.status: resw 1 ; Status +.filehandle: resw 1 ; FileHandle +.filename: resd 1 ; seg:off of FileName +.reserved: resd 1 gpxe_get_file_size: -.status: dw 0 ; Status -.filehandle: dw 0 ; FileHandle -.filesize: dd 0 ; FileSize +.status: resw 1 ; Status +.filehandle: resw 1 ; FileHandle +.filesize: resd 1 ; FileSize gpxe_file_read: -.status: dw 0 ; Status -.filehandle: dw 0 ; FileHandle -.buffersize: dw 0 ; BufferSize -.buffer: dd 0 ; seg:off of buffer +.status: resw 1 ; Status +.filehandle: resw 1 ; FileHandle +.buffersize: resw 1 ; BufferSize +.buffer: resd 1 ; seg:off of buffer %endif ; GPXE ; ; Misc initialized (data) variables ; + section .data + alignz 4 BaseStack dd StackBuf ; ESP of base stack dw 0 ; SS of base stack diff --git a/core/syslinux.ld b/core/syslinux.ld index 898b49d..eb21088 100644 --- a/core/syslinux.ld +++ b/core/syslinux.ld @@ -35,6 +35,7 @@ SECTIONS __earlybss_len = __earlybss_end - __earlybss_start; __earlybss_dwords = (__earlybss_len + 3) >> 2; + . = ALIGN(4); .bss : { __bss_start = .; *(.bss) @@ -45,6 +46,7 @@ SECTIONS __bss_len = __bss_end - __bss_start; __bss_dwords = (__bss_len + 3) >> 2; + . = ALIGN(4); .config : AT (__config_lma) { __config_start = .; *(.config) @@ -135,6 +137,7 @@ SECTIONS /* Late uninitialized sections */ + . = ALIGN(4); .uibss : { __uibss_start = .; *(.uibss) diff --git a/core/writehex.inc b/core/writehex.inc index 1dbe4ab..e2bf86b 100644 --- a/core/writehex.inc +++ b/core/writehex.inc @@ -16,7 +16,6 @@ ;; Write hexadecimal numbers to the console ;; - section .text ; ; writehex[248]: Write a hex number in (AL, AX, EAX) to the console ; diff --git a/core/writestr.inc b/core/writestr.inc index 4adc6bf..9c11b32 100644 --- a/core/writestr.inc +++ b/core/writestr.inc @@ -16,7 +16,6 @@ ;; Code to write a simple string. ;; - section .text ; ; crlf: Print a newline ; -- 2.7.4