nasm -f bin / Elf format
Hello all,
Currently I've been working on creating "bin" executables with nasm using the template given in the article "A Whirlwind Tutorial on Creating Really Teensy ELF Executables for Linux".
Working gradualy, I tried to modify some data in a .data section, and got a segmentation fault. Is that because there isn't a section header table with an entry indicating that the .data section is writable? If yes, is it possible to create the section header table by hand with the same ease as creating the elf header? I'm having difficulties to do it and I'm still learning my ways with the elf format, so, appreciate any help.
Thanks
Signature · 1 line
+Thiago Silva
Quoted 2 lines
Working gradualy, I tried to modify some data in a .data section, and got a segmentation fault.
You probably didn't set your the writable flag for the program section that includes .data. If you created your program section header table manually, make sure that p_flags (the second-to-last field) includes the writable flag (4 = readable, 2 = writable, 1 = executable).
Quoted 2 lines
Is that because there isn't a section header table with an entry indicating that the .data section is writable?
No, the section header table is not used when loading/executing ELF binaries.
b
grub thing
In reply to Thiago Silvahello all!
i'm _that_ boy (again) from last christmas.. hehehe didn't think i'd reach this far though and i just wanna clarify something.
i'm looking at a disassembly of grub's stage 1. and i wanna know why it need's to CLI before setting up the environment?? i tried to interpret it line by line and this is what i have so far
00007C4A FA cli ; disable interrupt 00007C4B 80CA80 or dl,0x80 ; correct boot drive byte 00007C4E EA537C0000 jmp 0x0:0x7c53 ; jmp to next inst 00007C53 31C0 xor ax,ax ; zero ax 00007C55 8ED8 mov ds,ax ; zero data segment 00007C57 8ED0 mov ss,ax ; zero stack segment 00007C59 BC0020 mov sp,0x2000 ; 8 kilobytes 00007C5C FB sti ; enable interrupt
also, since the origin is at 0000:7c00h i figured that must imply that "mov sp, 0x2000" means that the stack starts at 0x7c00+0x2000 = 9c000 right?
today is ash wednesday. tidings.
Re: grub thing
Quoting Aleph One <[email protected]>
Sent on Wed, 1 Mar 2006 07:10:33 +0000
Quoted 3 lines
i'm looking at a disassembly of grub's stage 1. and i wanna know why it need's to CLI before setting up the environment?? i tried to interpret it line by line and this is what i have so far
I'm not an expert, but interruptions must be disabled. I believe grub doesn't install interrupt handlers, and thus a single interrupt would lock the machine (as the appropriate handler would likely point to garbage).
would the BIOS (or similar in other architectures) give the processor to the bootloader with interrupts disabled already?
Quoted 3 lines
also, since the origin is at 0000:7c00h i figured that must imply that "mov sp,
0x2000" means that the stack starts at 0x7c00+0x2000 = 9c000 right?
I guess not. to get what you described, I would do:
mov sp, 0x2000 add sp, 0x7c00
from your disassembly, I'd expect SP to be 0x2000, counting from 0x0000.
Signature · 5 lines
Ricardo Nabinger Sanchez GNU/Linux #140696 [http://counter.li.org] Slackware Linux + FreeBSD Left to themselves, things tend to go from bad to worse.
Re: grub thing
In reply to Aleph OneQuoted 2 lines
i'm looking at a disassembly of grub's stage 1. and i wanna know why it need's to CLI before setting up the environment??
It's because it sets the stack address -- otherwise, interrupt could occur between mov to ss and mov to sp, which would use invalid stack address and be lethal.
Also, it has NOTHING to do with lack of interrupt handlers -- BIOS has handlers for all interrupts needed for bootstrap, and the others are disabled. No bad thing can happen. In fact, it re-enables interrupts right after setting the stack (sti)
Quoted 12 lines
i tried to interpret it
line by line and this is what i have so far00007C4A FA cli ; disable interrupt 00007C4B 80CA80 or dl,0x80 ; correct boot drive byte 00007C4E EA537C0000 jmp 0x0:0x7c53 ; jmp to next inst 00007C53 31C0 xor ax,ax ; zero ax 00007C55 8ED8 mov ds,ax ; zero data segment 00007C57 8ED0 mov ss,ax ; zero stack segment 00007C59 BC0020 mov sp,0x2000 ; 8 kilobytes 00007C5C FB sti ; enable interrupt
Quoted 2 lines
also, since the origin is at 0000:7c00h i figured that must imply that "mov sp,
0x2000" means that the stack starts at 0x7c00+0x2000 = 9c000 right?
No.
Quoted 2 lines
00007C57 8ED0 mov ss,ax ; zero stack segment
00007C59 BC0020 mov sp,0x2000 ; 8 kilobytes
Here, ss==0 and sp==0x2000. Stack starts at ss*0x10+sp == 0x0*0x10+0x2000 == 0x2000. Also, remember it grows down.
----------------------------------------------------------------------
Kliknij po wiecej! >>> http://link.interia.pl/f18ed
Re: grub thing
Quoting Marcin Kościelnicki <[email protected]>
Sent on Wed, 1 Mar 2006 15:42:50 +0100
Quoted 4 lines
Also, it has NOTHING to do with lack of interrupt handlers -- BIOS has handlers for all interrupts needed for bootstrap, and the others are disabled. No bad thing can happen. In fact, it re-enables interrupts right after setting the stack (sti)
thanks for correcting me! :)
Signature · 9 lines
Ricardo Nabinger Sanchez GNU/Linux #140696 [http://counter.li.org] Slackware Linux + FreeBSD Left to themselves, things tend to go from bad to worse. - To unsubscribe from this list: send the line "unsubscribe linux-assembly" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
Re: grub thing
In reply to Marcin KościelnickiOn Wed, 1 Mar 2006 15:42:50 +0100
Marcin Kościelnicki <[email protected]> wrote:
~> i'm looking at a disassembly of grub's stage 1. and i wanna know why it ~> need's to CLI before setting up the environment??
~
~It's because it sets the stack address -- otherwise, interrupt could occur ~between mov to ss and mov to sp, which would use invalid stack address and be ~lethal.
ahh! i see i see. it's for protection.
~
~Also, it has NOTHING to do with lack of interrupt handlers -- BIOS has ~handlers for all interrupts needed for bootstrap, and the others are ~disabled. No bad thing can happen. In fact, it re-enables interrupts right ~after setting the stack (sti)
~
~> i tried to interpret it
~> line by line and this is what i have so far
~>
~> 00007C4A FA cli ; disable interrupt ~> 00007C4B 80CA80 or dl,0x80 ; correct boot drive byte ~> 00007C4E EA537C0000 jmp 0x0:0x7c53 ; jmp to next inst ~> 00007C53 31C0 xor ax,ax ; zero ax ~> 00007C55 8ED8 mov ds,ax ; zero data segment ~> 00007C57 8ED0 mov ss,ax ; zero stack segment ~> 00007C59 BC0020 mov sp,0x2000 ; 8 kilobytes ~> 00007C5C FB sti ; enable interrupt
~>
~> also, since the origin is at 0000:7c00h i figured that must imply that "mov ~> sp, 0x2000" means that the stack starts at 0x7c00+0x2000 = 9c000 right? ~
~No.
~
~> 00007C57 8ED0 mov ss,ax ; zero stack segment ~> 00007C59 BC0020 mov sp,0x2000 ; 8 kilobytes
~
~Here, ss==0 and sp==0x2000. Stack starts at ss*0x10+sp == 0x0*0x10+0x2000 == ~0x2000. Also, remember it grows down.
one note. why must (ss*0x10)?
~
~----------------------------------------------------------------------
~Kliknij po wiecej! >>> http://link.interia.pl/f18ed
~
~-
~To unsubscribe from this list: send the line "unsubscribe linux-assembly" in ~the body of a message to [email protected]
~More majordomo info at http://vger.kernel.org/majordomo-info.html
-
To unsubscribe from this list: send the line "unsubscribe linux-assembly" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
Re: grub thing
In reply to Ricardo Nabinger SanchezOn Wed, 1 Mar 2006 10:34:11 -0300
Ricardo Nabinger Sanchez <[email protected]> wrote:
~Quoting Aleph One <[email protected]>
~Sent on Wed, 1 Mar 2006 07:10:33 +0000
~
~> i'm looking at a disassembly of grub's stage 1. and i wanna know why it ~> need's to CLI before setting up the environment?? i tried to interpret it ~> line by line and this is what i have so far
~
~I'm not an expert, but interruptions must be disabled. I believe grub ~doesn't install interrupt handlers, and thus a single interrupt would lock ~the machine (as the appropriate handler would likely point to garbage). ~
~would the BIOS (or similar in other architectures) give the processor to ~the bootloader with interrupts disabled already?
~
~> also, since the origin is at 0000:7c00h i figured that must imply that ~> "mov sp, 0x2000" means that the stack starts at 0x7c00+0x2000 = 9c000 ~> right?
~
~I guess not. to get what you described, I would do:
~
~ mov sp, 0x2000
~ add sp, 0x7c00
~
~from your disassembly, I'd expect SP to be 0x2000, counting from 0x0000.
groovy! thanks for clarifying this to me. i kinda got messed up thinking about relating the stack with the 7c000 start address :(
~--
~Ricardo Nabinger Sanchez
~GNU/Linux #140696 [http://counter.li.org]
~Slackware Linux + FreeBSD
~
~ Left to themselves, things tend to go from bad to worse.
~-
~To unsubscribe from this list: send the line "unsubscribe linux-assembly" in ~the body of a message to [email protected]
~More majordomo info at http://vger.kernel.org/majordomo-info.html