* [question] x86/x86_64 boot process
@ 2012-06-12 20:49 Brandon Falk
2012-06-12 21:05 ` H. Peter Anvin
0 siblings, 1 reply; 8+ messages in thread
From: Brandon Falk @ 2012-06-12 20:49 UTC (permalink / raw)
To: linux-kernel
Greetings. Please CC me on any responses as I do not subscribe to the list.
I'm currently working on a very very small boot loader. Currently it
uses BIOS int 0x13 to load up the 'setup' segments to 0x9000:0x0000. I
jump to this location, set up the kernel options, and then jump to
0x9020:0x0000. Everything goes great. However, I get the message 'No
setup signature found...'. I'm assuming this is due to not loading up
the protected-mode code. I'm slightly confused as to how the protected
mode code is to be loaded. As my 'bzImage' is 2.6MB, I would need to
raise the A20 line to possibly load this up. Does the kernel assist in
this process at all? Should I set up a code32_start routine for my
code to load up the kernel? Once I'm in protected mode, how will I
even access the medium that the kernel is loaded from without creating
a driver?
Currently the medium is a floppy image loaded in VMWare. It's a 64-bit
system. I'm just looking to be pointed in the right direction for the
next step (and if my current steps are valid for Protocol 2.10).
Here's the current code (the code is manually overwritten onto the
bzImage, however only the code... the headers are left intact on the
bzImage):
[org 0x7C00]
[bits 16]
%define koff(x) es:(x-0x7C00)
section .text
start:
xor bx, bx
xor cx, cx
mov ah, 0x02
mov al, 0x1D
mov cl, 0x01
xor dh, dh
push 0x9000
pop es
mov bx, 0x0000 ; read to 9000:0000
int 0x13
jc short halt
jmp 0x9000:(setup-0x7C00)
setup:
mov word [koff(root_flags)], 0
mov word [koff(vid_mode)], 0xFFFF
mov word [koff(root_dev)], 0
mov dword [koff(realmode_switch)], 0
mov byte [koff(type_of_loader)], 0xFF
mov byte [koff(loadflags)], 0b10000001
mov dword [koff(ramdisk_image)], 0
mov dword [koff(ramdisk_size)], 0
mov word [koff(heap_end_ptr)], (0x5000 - 0x200)
mov dword [koff(cmd_line_ptr)], cmdline
mov dword [koff(hw_subarch)], 0
mov dword [koff(setup_data)], 0
cli
mov bx, 0x9000
mov ss, bx
mov ds, bx
mov es, bx
mov fs, bx
mov gs, bx
mov sp, 0x5000
jmp 0x9020:0
halt:
hlt
jmp short halt
cmdline: db 'auto', 0
times 0x1f1-($-$$) db 0
setup_sects: db 0x1D ; ~ read
root_flags: dw 0 ; x ~ modify
syssize: dd 0 ; ~ read
ram_size: dw 0 ; x ~ internal
vid_mode: dw 0 ; * modify
root_dev: dw 0 ; x ~ modify
boot_flag: dw 0 ; * ~ read
; sector 2
jump: dw 0 ; ~ read
header: dd 0 ; ~ read
version: dw 0 ; ~ read
realmode_switch: dd 0 ; o ~ modify
start_sys_reg: dw 0 ; x ~ read
kernel_version: dw 0 ; ~ read
type_of_loader: db 0 ; * ~ write
loadflags: db 0 ; * modify
setup_move_size: dw 0 ; x ~ modify
code32_start: dd 0 ; o ~ modify
ramdisk_image: dd 0 ; * write
ramdisk_size: dd 0 ; * write
bootsect_kludge: dd 0 ; x ~ internal
heap_end_ptr: dw 0 ; * write
ext_loader_ver: db 0 ; o ~ write
ext_loader_type: db 0 ; o ~ write
cmd_line_ptr: dd 0 ; * write
ramdisk_max: dd 0 ; ~ read
kernel_alignment: dd 0 ; ~ read
relocabl_kernel: db 0 ; ~ read
min_alignment: db 0 ; ~ read
db 0
db 0
cmdline_size: dd 0 ; ~ read
hw_subarch: dd 0 ; o ~ write
hw_subarch_data: dq 0 ; o ~ write
payload_offset: dd 0 ; ~ read
payload_length: dd 0 ; ~ read
setup_data: dq 0 ; s ~ write
pref_address: dq 0 ; ~ read
init_size: dd 0 ; ~ read
-Brandon
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [question] x86/x86_64 boot process
2012-06-12 20:49 [question] x86/x86_64 boot process Brandon Falk
@ 2012-06-12 21:05 ` H. Peter Anvin
2012-06-12 21:14 ` Brandon Falk
0 siblings, 1 reply; 8+ messages in thread
From: H. Peter Anvin @ 2012-06-12 21:05 UTC (permalink / raw)
To: Brandon Falk; +Cc: linux-kernel
On 06/12/2012 01:49 PM, Brandon Falk wrote:
> Greetings. Please CC me on any responses as I do not subscribe to the list.
>
> I'm currently working on a very very small boot loader. Currently it
> uses BIOS int 0x13 to load up the 'setup' segments to 0x9000:0x0000. I
> jump to this location, set up the kernel options, and then jump to
> 0x9020:0x0000. Everything goes great. However, I get the message 'No
> setup signature found...'. I'm assuming this is due to not loading up
> the protected-mode code. I'm slightly confused as to how the protected
> mode code is to be loaded. As my 'bzImage' is 2.6MB, I would need to
> raise the A20 line to possibly load this up. Does the kernel assist in
> this process at all? Should I set up a code32_start routine for my
> code to load up the kernel? Once I'm in protected mode, how will I
> even access the medium that the kernel is loaded from without creating
> a driver?
>
> Currently the medium is a floppy image loaded in VMWare. It's a 64-bit
> system. I'm just looking to be pointed in the right direction for the
> next step (and if my current steps are valid for Protocol 2.10).
>
> Here's the current code (the code is manually overwritten onto the
> bzImage, however only the code... the headers are left intact on the
> bzImage):
>
Please read Documentation/x86/boot.txt.
-hpa
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [question] x86/x86_64 boot process
2012-06-12 21:05 ` H. Peter Anvin
@ 2012-06-12 21:14 ` Brandon Falk
2012-06-12 21:15 ` H. Peter Anvin
2012-06-12 21:16 ` H. Peter Anvin
0 siblings, 2 replies; 8+ messages in thread
From: Brandon Falk @ 2012-06-12 21:14 UTC (permalink / raw)
To: H. Peter Anvin; +Cc: linux-kernel
All I really see related to the post-setup stage is:
'The 32-bit (non-real-mode) kernel starts at offset (setup_sects+1)*512
in the kernel file (again, if setup_sects == 0 the real value is 4.)
It should be loaded at address 0x10000 for Image/zImage kernels and
0x100000 for bzImage kernels.'
I've read this document a few times, and it doesn't seem to mention if
the kernel assists in loading. Do I have to load up the whole
protected-mode kernel? Just the first few sectors? I guess that's what
I'm trying to figure out, and I feel the boot.txt has not answered
that for me.
On Tue, Jun 12, 2012 at 5:05 PM, H. Peter Anvin <hpa@zytor.com> wrote:
> On 06/12/2012 01:49 PM, Brandon Falk wrote:
>> Greetings. Please CC me on any responses as I do not subscribe to the list.
>>
>> I'm currently working on a very very small boot loader. Currently it
>> uses BIOS int 0x13 to load up the 'setup' segments to 0x9000:0x0000. I
>> jump to this location, set up the kernel options, and then jump to
>> 0x9020:0x0000. Everything goes great. However, I get the message 'No
>> setup signature found...'. I'm assuming this is due to not loading up
>> the protected-mode code. I'm slightly confused as to how the protected
>> mode code is to be loaded. As my 'bzImage' is 2.6MB, I would need to
>> raise the A20 line to possibly load this up. Does the kernel assist in
>> this process at all? Should I set up a code32_start routine for my
>> code to load up the kernel? Once I'm in protected mode, how will I
>> even access the medium that the kernel is loaded from without creating
>> a driver?
>>
>> Currently the medium is a floppy image loaded in VMWare. It's a 64-bit
>> system. I'm just looking to be pointed in the right direction for the
>> next step (and if my current steps are valid for Protocol 2.10).
>>
>> Here's the current code (the code is manually overwritten onto the
>> bzImage, however only the code... the headers are left intact on the
>> bzImage):
>>
>
> Please read Documentation/x86/boot.txt.
>
> -hpa
>
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [question] x86/x86_64 boot process
2012-06-12 21:14 ` Brandon Falk
@ 2012-06-12 21:15 ` H. Peter Anvin
2012-06-12 21:16 ` H. Peter Anvin
1 sibling, 0 replies; 8+ messages in thread
From: H. Peter Anvin @ 2012-06-12 21:15 UTC (permalink / raw)
To: Brandon Falk; +Cc: linux-kernel
On 06/12/2012 02:14 PM, Brandon Falk wrote:
> All I really see related to the post-setup stage is:
>
> 'The 32-bit (non-real-mode) kernel starts at offset (setup_sects+1)*512
> in the kernel file (again, if setup_sects == 0 the real value is 4.)
> It should be loaded at address 0x10000 for Image/zImage kernels and
> 0x100000 for bzImage kernels.'
>
> I've read this document a few times, and it doesn't seem to mention if
> the kernel assists in loading. Do I have to load up the whole
> protected-mode kernel? Just the first few sectors? I guess that's what
> I'm trying to figure out, and I feel the boot.txt has not answered
> that for me.
>
The kernel doesn't load anything, that is the boot loader's job.
-hpa
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [question] x86/x86_64 boot process
2012-06-12 21:14 ` Brandon Falk
2012-06-12 21:15 ` H. Peter Anvin
@ 2012-06-12 21:16 ` H. Peter Anvin
2012-06-12 21:20 ` Brandon Falk
1 sibling, 1 reply; 8+ messages in thread
From: H. Peter Anvin @ 2012-06-12 21:16 UTC (permalink / raw)
To: Brandon Falk; +Cc: linux-kernel
On 06/12/2012 02:14 PM, Brandon Falk wrote:
> All I really see related to the post-setup stage is:
>
> 'The 32-bit (non-real-mode) kernel starts at offset (setup_sects+1)*512
> in the kernel file (again, if setup_sects == 0 the real value is 4.)
> It should be loaded at address 0x10000 for Image/zImage kernels and
> 0x100000 for bzImage kernels.'
>
> I've read this document a few times, and it doesn't seem to mention if
> the kernel assists in loading. Do I have to load up the whole
> protected-mode kernel? Just the first few sectors? I guess that's what
> I'm trying to figure out, and I feel the boot.txt has not answered
> that for me.
>
I would also strongly discourage you from writing a new bootloader if
you can avoid it. You *certainly* want to avoid the use of the fixed
0x90000 address, that is a decade obsolete.
-hpa
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [question] x86/x86_64 boot process
2012-06-12 21:16 ` H. Peter Anvin
@ 2012-06-12 21:20 ` Brandon Falk
2012-06-12 21:33 ` Brandon Falk
0 siblings, 1 reply; 8+ messages in thread
From: Brandon Falk @ 2012-06-12 21:20 UTC (permalink / raw)
To: H. Peter Anvin; +Cc: linux-kernel
It's currently only for learning purposes, and I will change loading
from 0x90000. Thanks for the help, now that I know that I'm
responsible for loading the protected-mode code, I know what to do
next.
On Tue, Jun 12, 2012 at 5:16 PM, H. Peter Anvin <hpa@zytor.com> wrote:
> On 06/12/2012 02:14 PM, Brandon Falk wrote:
>> All I really see related to the post-setup stage is:
>>
>> 'The 32-bit (non-real-mode) kernel starts at offset (setup_sects+1)*512
>> in the kernel file (again, if setup_sects == 0 the real value is 4.)
>> It should be loaded at address 0x10000 for Image/zImage kernels and
>> 0x100000 for bzImage kernels.'
>>
>> I've read this document a few times, and it doesn't seem to mention if
>> the kernel assists in loading. Do I have to load up the whole
>> protected-mode kernel? Just the first few sectors? I guess that's what
>> I'm trying to figure out, and I feel the boot.txt has not answered
>> that for me.
>>
>
> I would also strongly discourage you from writing a new bootloader if
> you can avoid it. You *certainly* want to avoid the use of the fixed
> 0x90000 address, that is a decade obsolete.
>
> -hpa
>
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [question] x86/x86_64 boot process
2012-06-12 21:20 ` Brandon Falk
@ 2012-06-12 21:33 ` Brandon Falk
2012-06-12 21:37 ` H. Peter Anvin
0 siblings, 1 reply; 8+ messages in thread
From: Brandon Falk @ 2012-06-12 21:33 UTC (permalink / raw)
To: H. Peter Anvin; +Cc: linux-kernel
Would it be reasonable to put the setup code at 0x7c00 (given that I
can fit my boot loader in the space before the kernel header)?
On Tue, Jun 12, 2012 at 5:20 PM, Brandon Falk <bfalk@gamozolabs.com> wrote:
> It's currently only for learning purposes, and I will change loading
> from 0x90000. Thanks for the help, now that I know that I'm
> responsible for loading the protected-mode code, I know what to do
> next.
>
> On Tue, Jun 12, 2012 at 5:16 PM, H. Peter Anvin <hpa@zytor.com> wrote:
>> On 06/12/2012 02:14 PM, Brandon Falk wrote:
>>> All I really see related to the post-setup stage is:
>>>
>>> 'The 32-bit (non-real-mode) kernel starts at offset (setup_sects+1)*512
>>> in the kernel file (again, if setup_sects == 0 the real value is 4.)
>>> It should be loaded at address 0x10000 for Image/zImage kernels and
>>> 0x100000 for bzImage kernels.'
>>>
>>> I've read this document a few times, and it doesn't seem to mention if
>>> the kernel assists in loading. Do I have to load up the whole
>>> protected-mode kernel? Just the first few sectors? I guess that's what
>>> I'm trying to figure out, and I feel the boot.txt has not answered
>>> that for me.
>>>
>>
>> I would also strongly discourage you from writing a new bootloader if
>> you can avoid it. You *certainly* want to avoid the use of the fixed
>> 0x90000 address, that is a decade obsolete.
>>
>> -hpa
>>
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [question] x86/x86_64 boot process
2012-06-12 21:33 ` Brandon Falk
@ 2012-06-12 21:37 ` H. Peter Anvin
0 siblings, 0 replies; 8+ messages in thread
From: H. Peter Anvin @ 2012-06-12 21:37 UTC (permalink / raw)
To: Brandon Falk; +Cc: linux-kernel
On 06/12/2012 02:33 PM, Brandon Falk wrote:
> Would it be reasonable to put the setup code at 0x7c00 (given that I
> can fit my boot loader in the space before the kernel header)?
Should work.
-hpa
^ permalink raw reply [flat|nested] 8+ messages in thread
end of thread, other threads:[~2012-06-12 21:37 UTC | newest]
Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2012-06-12 20:49 [question] x86/x86_64 boot process Brandon Falk
2012-06-12 21:05 ` H. Peter Anvin
2012-06-12 21:14 ` Brandon Falk
2012-06-12 21:15 ` H. Peter Anvin
2012-06-12 21:16 ` H. Peter Anvin
2012-06-12 21:20 ` Brandon Falk
2012-06-12 21:33 ` Brandon Falk
2012-06-12 21:37 ` H. Peter Anvin
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox