2011-03-13 22:00:31

by Jesper Juhl

[permalink] [raw]
Subject: [PATCH][rfc] Use int as return type of main in arch/x86/boot/main.c

I believe the return type of main should always be 'int'.

Signed-off-by: Jesper Juhl <[email protected]>
---
main.c | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/arch/x86/boot/main.c b/arch/x86/boot/main.c
index 40358c8..4b80da8 100644
--- a/arch/x86/boot/main.c
+++ b/arch/x86/boot/main.c
@@ -125,7 +125,7 @@ static void init_heap(void)
}
}

-void main(void)
+int main(void)
{
/* First, copy the boot header into the "zeropage" */
copy_boot_params();
@@ -175,4 +175,6 @@ void main(void)

/* Do the last things and invoke protected mode */
go_to_protected_mode();
+
+ return 0;
}


--
Jesper Juhl <[email protected]> http://www.chaosbits.net/
Plain text mails only, please.
Don't top-post http://www.catb.org/~esr/jargon/html/T/top-post.html


2011-03-14 11:33:24

by jiaweiwei

[permalink] [raw]
Subject: Re: [PATCH][rfc] Use int as return type of main in arch/x86/boot/main.c

On Sun, Mar 13, 2011 at 11:00:09PM +0100, Jesper Juhl wrote:
> I believe the return type of main should always be 'int'.
>
> Signed-off-by: Jesper Juhl <[email protected]>
Acked-by: Harry Wei <[email protected]>
> ---
> main.c | 4 +++-
> 1 file changed, 3 insertions(+), 1 deletion(-)
>
> diff --git a/arch/x86/boot/main.c b/arch/x86/boot/main.c
> index 40358c8..4b80da8 100644
> --- a/arch/x86/boot/main.c
> +++ b/arch/x86/boot/main.c
> @@ -125,7 +125,7 @@ static void init_heap(void)
> }
> }
>
> -void main(void)
> +int main(void)
> {
> /* First, copy the boot header into the "zeropage" */
> copy_boot_params();
> @@ -175,4 +175,6 @@ void main(void)
>
> /* Do the last things and invoke protected mode */
> go_to_protected_mode();
> +
> + return 0;
> }
>
>
> --
> Jesper Juhl <[email protected]> http://www.chaosbits.net/
> Plain text mails only, please.
> Don't top-post http://www.catb.org/~esr/jargon/html/T/top-post.html
>
> --
> To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
> the body of a message to [email protected]
> More majordomo info at http://vger.kernel.org/majordomo-info.html
> Please read the FAQ at http://www.tux.org/lkml/

2011-03-14 16:50:04

by H. Peter Anvin

[permalink] [raw]
Subject: Re: [PATCH][rfc] Use int as return type of main in arch/x86/boot/main.c

On 03/14/2011 04:32 AM, Harry Wei wrote:
> On Sun, Mar 13, 2011 at 11:00:09PM +0100, Jesper Juhl wrote:
>> I believe the return type of main should always be 'int'.
>>
>> Signed-off-by: Jesper Juhl <[email protected]>
> Acked-by: Harry Wei <[email protected]>

It would make more sense to rename the function to something other than
main().

-hpa

2011-03-14 19:03:20

by Steven Rostedt

[permalink] [raw]
Subject: Re: [PATCH][rfc] Use int as return type of main in arch/x86/boot/main.c

On Sun, Mar 13, 2011 at 11:00:09PM +0100, Jesper Juhl wrote:
> I believe the return type of main should always be 'int'.

But this is not userspace, it is called from assmebly in header.S:

# Jump to C code (should not return)
calll main

We don't care what main returns. If it does return anything, then it
dies:

# Setup corrupt somehow...
setup_bad:
movl $setup_corrupt, %eax
calll puts
# Fall through...

.globl die
.type die, @function
die:
hlt
jmp die


-- Steve

>
> Signed-off-by: Jesper Juhl <[email protected]>
> ---
> main.c | 4 +++-
> 1 file changed, 3 insertions(+), 1 deletion(-)
>
> diff --git a/arch/x86/boot/main.c b/arch/x86/boot/main.c
> index 40358c8..4b80da8 100644
> --- a/arch/x86/boot/main.c
> +++ b/arch/x86/boot/main.c
> @@ -125,7 +125,7 @@ static void init_heap(void)
> }
> }
>
> -void main(void)
> +int main(void)
> {
> /* First, copy the boot header into the "zeropage" */
> copy_boot_params();
> @@ -175,4 +175,6 @@ void main(void)
>
> /* Do the last things and invoke protected mode */
> go_to_protected_mode();
> +
> + return 0;
> }
>
>
> --
> Jesper Juhl <[email protected]> http://www.chaosbits.net/
> Plain text mails only, please.
> Don't top-post http://www.catb.org/~esr/jargon/html/T/top-post.html
>
> --
> To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
> the body of a message to [email protected]
> More majordomo info at http://vger.kernel.org/majordomo-info.html
> Please read the FAQ at http://www.tux.org/lkml/

2011-03-14 19:04:08

by Steven Rostedt

[permalink] [raw]
Subject: Re: [PATCH][rfc] Use int as return type of main in arch/x86/boot/main.c

On Mon, Mar 14, 2011 at 09:49:18AM -0700, H. Peter Anvin wrote:
> On 03/14/2011 04:32 AM, Harry Wei wrote:
> > On Sun, Mar 13, 2011 at 11:00:09PM +0100, Jesper Juhl wrote:
> >> I believe the return type of main should always be 'int'.
> >>
> >> Signed-off-by: Jesper Juhl <[email protected]>
> > Acked-by: Harry Wei <[email protected]>
>
> It would make more sense to rename the function to something other than
> main().

Right, maybe "boot_start"?

-- Steve

2011-03-14 22:51:21

by H. Peter Anvin

[permalink] [raw]
Subject: Re: [PATCH][rfc] Use int as return type of main in arch/x86/boot/main.c

On 03/14/2011 12:03 PM, Steven Rostedt wrote:
> On Sun, Mar 13, 2011 at 11:00:09PM +0100, Jesper Juhl wrote:
>> I believe the return type of main should always be 'int'.
>
> But this is not userspace, it is called from assmebly in header.S:
>
> # Jump to C code (should not return)
> calll main
>
> We don't care what main returns. If it does return anything, then it
> dies:
>
> # Setup corrupt somehow...
> setup_bad:
> movl $setup_corrupt, %eax
> calll puts
> # Fall through...
>
> .globl die
> .type die, @function
> die:
> hlt
> jmp die
>

Yes, but some versions of gcc complains about a nonstandard signature to
main(). At least that's what I assume Jesper's issue was.

-hpa

2011-03-14 23:35:23

by Jesper Juhl

[permalink] [raw]
Subject: Re: [PATCH][rfc] Use int as return type of main in arch/x86/boot/main.c

On Mon, 14 Mar 2011, H. Peter Anvin wrote:

> On 03/14/2011 04:32 AM, Harry Wei wrote:
> > On Sun, Mar 13, 2011 at 11:00:09PM +0100, Jesper Juhl wrote:
> >> I believe the return type of main should always be 'int'.
> >>
> >> Signed-off-by: Jesper Juhl <[email protected]>
> > Acked-by: Harry Wei <[email protected]>
>
> It would make more sense to rename the function to something other than
> main().
>
Right. That's probably a better aproach. Thanks.

--
Jesper Juhl <[email protected]> http://www.chaosbits.net/
Plain text mails only, please.
Don't top-post http://www.catb.org/~esr/jargon/html/T/top-post.html

2011-03-15 02:32:01

by Steven Rostedt

[permalink] [raw]
Subject: Re: [PATCH][rfc] Use int as return type of main in arch/x86/boot/main.c

On Mon, 2011-03-14 at 15:50 -0700, H. Peter Anvin wrote:
>
> Yes, but some versions of gcc complains about a nonstandard signature to
> main(). At least that's what I assume Jesper's issue was.

OK, but I prefer the solution you suggested. Let's just rename it.

-- Steve

2011-03-15 13:55:39

by Cong Wang

[permalink] [raw]
Subject: Re: [PATCH][rfc] Use int as return type of main in arch/x86/boot/main.c

On Sun, 13 Mar 2011 23:00:09 +0100, Jesper Juhl wrote:

> I believe the return type of main should always be 'int'.
>

In user-space, yes, but this is not true in kernel space especially here.