linux-assembly.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* nasm -f bin / Elf format
@ 2006-02-22 21:26 Thiago Silva
  2006-02-23  0:32 ` Brian Raiter
  2006-03-01  7:10 ` grub thing Aleph One
  0 siblings, 2 replies; 8+ messages in thread
From: Thiago Silva @ 2006-02-22 21:26 UTC (permalink / raw)
  To: linux-assembly

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
-- 
+Thiago Silva

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: nasm -f bin / Elf format
  2006-02-22 21:26 nasm -f bin / Elf format Thiago Silva
@ 2006-02-23  0:32 ` Brian Raiter
  2006-03-01  7:10 ` grub thing Aleph One
  1 sibling, 0 replies; 8+ messages in thread
From: Brian Raiter @ 2006-02-23  0:32 UTC (permalink / raw)
  To: linux-assembly

> 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).

> 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

^ permalink raw reply	[flat|nested] 8+ messages in thread

* grub thing
  2006-02-22 21:26 nasm -f bin / Elf format Thiago Silva
  2006-02-23  0:32 ` Brian Raiter
@ 2006-03-01  7:10 ` Aleph One
  2006-03-01 13:34   ` Ricardo Nabinger Sanchez
  2006-03-01 14:42   ` Marcin Kościelnicki
  1 sibling, 2 replies; 8+ messages in thread
From: Aleph One @ 2006-03-01  7:10 UTC (permalink / raw)
  To: linux-assembly

hello 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.

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: grub thing
  2006-03-01  7:10 ` grub thing Aleph One
@ 2006-03-01 13:34   ` Ricardo Nabinger Sanchez
  2006-03-02  6:49     ` Aleph One
  2006-03-01 14:42   ` Marcin Kościelnicki
  1 sibling, 1 reply; 8+ messages in thread
From: Ricardo Nabinger Sanchez @ 2006-03-01 13:34 UTC (permalink / raw)
  To: linux-assembly

Quoting  Aleph One <amerei@gmail.com>
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.

-- 
Ricardo Nabinger Sanchez
GNU/Linux #140696 [http://counter.li.org]
Slackware Linux + FreeBSD

  Left to themselves, things tend to go from bad to worse.

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: grub thing
  2006-03-01  7:10 ` grub thing Aleph One
  2006-03-01 13:34   ` Ricardo Nabinger Sanchez
@ 2006-03-01 14:42   ` Marcin Kościelnicki
  2006-03-01 18:08     ` Ricardo Nabinger Sanchez
  2006-03-02  6:46     ` Aleph One
  1 sibling, 2 replies; 8+ messages in thread
From: Marcin Kościelnicki @ 2006-03-01 14:42 UTC (permalink / raw)
  To: linux-assembly

> 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)

> 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.

----------------------------------------------------------------------
Kliknij po wiecej! >>> http://link.interia.pl/f18ed


^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: grub thing
  2006-03-01 14:42   ` Marcin Kościelnicki
@ 2006-03-01 18:08     ` Ricardo Nabinger Sanchez
  2006-03-02  6:46     ` Aleph One
  1 sibling, 0 replies; 8+ messages in thread
From: Ricardo Nabinger Sanchez @ 2006-03-01 18:08 UTC (permalink / raw)
  To: linux-assembly

Quoting  Marcin Ko≈õcielnicki <markosc@interia.pl>
Sent on  Wed, 1 Mar 2006 15:42:50 +0100

> 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! :)

-- 
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 majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: grub thing
  2006-03-01 14:42   ` Marcin Kościelnicki
  2006-03-01 18:08     ` Ricardo Nabinger Sanchez
@ 2006-03-02  6:46     ` Aleph One
  1 sibling, 0 replies; 8+ messages in thread
From: Aleph One @ 2006-03-02  6:46 UTC (permalink / raw)
  To: Marcin Kościelnicki; +Cc: linux-assembly

On Wed, 1 Mar 2006 15:42:50 +0100
Marcin Ko≈õcielnicki <markosc@interia.pl> 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 majordomo@vger.kernel.org
~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 majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: grub thing
  2006-03-01 13:34   ` Ricardo Nabinger Sanchez
@ 2006-03-02  6:49     ` Aleph One
  0 siblings, 0 replies; 8+ messages in thread
From: Aleph One @ 2006-03-02  6:49 UTC (permalink / raw)
  To: Ricardo Nabinger Sanchez; +Cc: linux-assembly

On Wed, 1 Mar 2006 10:34:11 -0300
Ricardo Nabinger Sanchez <rnsanchez@terra.com.br> wrote:

~Quoting  Aleph One <amerei@gmail.com>
~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 majordomo@vger.kernel.org
~More majordomo info at  http://vger.kernel.org/majordomo-info.html

^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2006-03-02  6:49 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2006-02-22 21:26 nasm -f bin / Elf format Thiago Silva
2006-02-23  0:32 ` Brian Raiter
2006-03-01  7:10 ` grub thing Aleph One
2006-03-01 13:34   ` Ricardo Nabinger Sanchez
2006-03-02  6:49     ` Aleph One
2006-03-01 14:42   ` Marcin Kościelnicki
2006-03-01 18:08     ` Ricardo Nabinger Sanchez
2006-03-02  6:46     ` Aleph One

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).