protected mode bootstrap?
protected mode bootstrap?
i need to get a protected mode bootstrap so that i can load some c code in kernel.bin. Does any one know of any tutorials / example code? I tried John Fine's code, but I cant get it to work..
any help would be great!
any help would be great!
RE:protected mode bootstrap? ..GRUB?
ok, no one answered (so far) anyway. but i managed to get grub to boot from the floppy with the menu etc. except now how to i output elf files with djgpp? There is a Loader.asm file that assembles with nasm and the kernel.c that compiles with djgpp. I was using the ld tool from djgpp but i cant get it to output elf files! it says that it dosent recognise the file type..? need help.. please! thanks in advance..
RE:protected mode bootstrap? ..GRUB?
DJGPP LD needs to be recompiled to support elf. That's not fun. Personally, i don't have linux ld on my own machine, but i don't use djgpp either. Instead i use compaq testdrive.
www.testdrive.compaq.com
Upload and compile your own nasm exe and use the servers installed copy of ld that supports elf.
www.testdrive.compaq.com
Upload and compile your own nasm exe and use the servers installed copy of ld that supports elf.
RE:protected mode bootstrap? ..GRUB?
Thanks for that, il have a look...
btw, surely there must be other people who have recompiled ld to support elf!? so has no one thought about distributing this?...
thanks anyway.
btw, surely there must be other people who have recompiled ld to support elf!? so has no one thought about distributing this?...
thanks anyway.
RE:protected mode bootstrap? ..GRUB?
>DJGPP LD needs to be recompiled to support elf.
Sigh. This keeps coming up again and again. We need to get the word out:
*** GRUB will load a kernel in any 32-bit format ***
It doesn't have to be ELF. You don't need to recompile DJGPP. Just use the "aout kludge": http://my.execpc.com/~geezer/osd/boot/grub-how.txt
Sigh. This keeps coming up again and again. We need to get the word out:
*** GRUB will load a kernel in any 32-bit format ***
It doesn't have to be ELF. You don't need to recompile DJGPP. Just use the "aout kludge": http://my.execpc.com/~geezer/osd/boot/grub-how.txt
RE:protected mode bootstrap? ..GRUB?
Or, maybe he just doesn't want to use the aout kludge.
Brill.
Brill.
RE:protected mode bootstrap? ..GRUB?
no, i dont really care what format its in at the moment. i had it as a binary which didnt seem to work. but thanx Anonymous il take a look at the site. but i have heard that elf is a "better" format...?
RE:protected mode bootstrap? ..GRUB?
I can't remember why its better.
Linux switched to using elf from aout because it's easier to load modules or something like that. Whereas bsd still uses aout but hacked up a part of it to do what linux was doing.
It's easier when it comes to multiboot. All you need is 3 dword entries in your header. The magic 1BADB002, flags and checksum which is easier to follow and understand. Reason being is that the aout kludge defines the section locations that your multiboot loader needs in order to boot the kernel properly. Elf has these predefined in its own header anyway. So multiboot, or more specifically Grub at least, just grabs that out the elf headers without the need for the aout kludge.
Brill.
Linux switched to using elf from aout because it's easier to load modules or something like that. Whereas bsd still uses aout but hacked up a part of it to do what linux was doing.
It's easier when it comes to multiboot. All you need is 3 dword entries in your header. The magic 1BADB002, flags and checksum which is easier to follow and understand. Reason being is that the aout kludge defines the section locations that your multiboot loader needs in order to boot the kernel properly. Elf has these predefined in its own header anyway. So multiboot, or more specifically Grub at least, just grabs that out the elf headers without the need for the aout kludge.
Brill.
RE:protected mode bootstrap? ..GRUB?
ok, thanx. but il prob stick to using bin for now... if i can!! i looked at the site from Anonymous, but cant get that to work (my fault, i need more simple... ). So i found this site:
http://osdev.neopages.net/tutorials/basickernel.php
Which should work with grub using bin files.. thats wot it says...
i have tried with the downloaded grub files (http://osdev.neopages.net/downloads/tut ... l_grub.zip) yet still get the "Error 13: Invalid or unsupported executable format".
Im sorry to keep asking about this, but i really want to get it working and must have tried everything (except the right thing!!).
Thanks for your help.
http://osdev.neopages.net/tutorials/basickernel.php
Which should work with grub using bin files.. thats wot it says...
i have tried with the downloaded grub files (http://osdev.neopages.net/downloads/tut ... l_grub.zip) yet still get the "Error 13: Invalid or unsupported executable format".
Im sorry to keep asking about this, but i really want to get it working and must have tried everything (except the right thing!!).
Thanks for your help.
RE:protected mode bootstrap? ..GRUB?
you get that error 13 message because you haven't got your multiboot section headers right
The aout kludge should sort you out there, with the headers. But then so will elf. My multiboot header looks like this...
multiboot_header:
align 4, db 0 ; Align to dword boundary
dd MBOOT_MAGIC1 ; Multiboot magic header
dd MBOOT_FLAGS ; Flags information
dd 0 - (MBOOT_MAGIC1 + MBOOT_FLAGS)
MBOOT_MAGIC1, MBOOT_FLAGS are defined inside an include header file
That file looks like this...
%define MBOOT_MAGIC1 0x1BADB002 ; 'Magic' multi-boot header
%define MBOOT_FLAGS 0x00000002 ; Flags for multi-booting
Then to assemble and link all i do is
nasm -f elf start.asm
and then link by
ld --oformat=elf32-i386 --Ttext=0x01000000 -T script.ld --fatal-warnings -o kernel.bin start.o
That makes me my kernel.bin which i put in a a.img file using WinImage and then boot with bochs.
Because i use elf i dont need anything you found on that ~geezer/osd site but using plain binaries wont fix the problem. As you still need the section header info. You need to either compile/assemble then link with the aout kludge to binary format or compile/assemble then link to elf with or without the aout kludge stuff it wont matter with elf.
If you do use my flags from above by example with the aout kludge, make sure you set the necessary multiboot flags that state that the aout kludge exists.
Otherwise Grub will expect it to be elf and when it doesn't find the elf header will display your error 13 message.
If you want some multiboot specs goto
http://www.mcc.ac.uk/grub/multiboot_3.html
to see the machine state.
Brill.
The aout kludge should sort you out there, with the headers. But then so will elf. My multiboot header looks like this...
multiboot_header:
align 4, db 0 ; Align to dword boundary
dd MBOOT_MAGIC1 ; Multiboot magic header
dd MBOOT_FLAGS ; Flags information
dd 0 - (MBOOT_MAGIC1 + MBOOT_FLAGS)
MBOOT_MAGIC1, MBOOT_FLAGS are defined inside an include header file
That file looks like this...
%define MBOOT_MAGIC1 0x1BADB002 ; 'Magic' multi-boot header
%define MBOOT_FLAGS 0x00000002 ; Flags for multi-booting
Then to assemble and link all i do is
nasm -f elf start.asm
and then link by
ld --oformat=elf32-i386 --Ttext=0x01000000 -T script.ld --fatal-warnings -o kernel.bin start.o
That makes me my kernel.bin which i put in a a.img file using WinImage and then boot with bochs.
Because i use elf i dont need anything you found on that ~geezer/osd site but using plain binaries wont fix the problem. As you still need the section header info. You need to either compile/assemble then link with the aout kludge to binary format or compile/assemble then link to elf with or without the aout kludge stuff it wont matter with elf.
If you do use my flags from above by example with the aout kludge, make sure you set the necessary multiboot flags that state that the aout kludge exists.
Otherwise Grub will expect it to be elf and when it doesn't find the elf header will display your error 13 message.
If you want some multiboot specs goto
http://www.mcc.ac.uk/grub/multiboot_3.html
to see the machine state.
Brill.
RE:protected mode bootstrap? ..GRUB?
ok i took a look at that page.
The content they have on the main page isnt actually grub, or multiboot friendly. Instead they have a link at the bottom of the page for that. I presume you didn't see that?
After downloading that it contains the aout kludge stuff and makes the basic kernel listed on the html page.
Brill.
The content they have on the main page isnt actually grub, or multiboot friendly. Instead they have a link at the bottom of the page for that. I presume you didn't see that?
After downloading that it contains the aout kludge stuff and makes the basic kernel listed on the html page.
Brill.
RE:protected mode bootstrap? ..GRUB?
So this dosent work..?
;---kstart.asm-----------
%include "grub.inc" ; needed for the multiboot header
[BITS 32]
[global start]
[extern _k_main] ; this is in the c file
start:
call _k_main
cli ; stop interrupts
hlt ; halt the CPU
; these are in the linker script file
EXTERN code, bss, end
ALIGN 4
mboot:
dd MULTIBOOT_HEADER_MAGIC
dd MULTIBOOT_HEADER_FLAGS
dd MULTIBOOT_CHECKSUM
dd mboot
dd code
dd bss
dd end
dd start
;------------------------
;---kstart.asm-----------
MULTIBOOT_PAGE_ALIGN equ 1<<0
MULTIBOOT_MEMORY_INFO equ 1<<1
MULTIBOOT_AOUT_KLUDGE equ 1<<16
MULTIBOOT_HEADER_MAGIC equ 0x1BADB002
MULTIBOOT_HEADER_FLAGS equ MULTIBOOT_PAGE_ALIGN | MULTIBOOT_MEMORY_INFO | MULTIBOOT_AOUT_KLUDGE
MULTIBOOT_CHECKSUM equ -(MULTIBOOT_HEADER_MAGIC + MULTIBOOT_HEADER_FLAGS)--;----------------------
then compile/assemble...
nasm -f aout kstart.asm -o ks.o
gcc -c kernel.c -o kernel.o
ld -T link.ld -o kernel.bin ks.o kernel.o
Im sorry, i gotta get this to work!!
;---kstart.asm-----------
%include "grub.inc" ; needed for the multiboot header
[BITS 32]
[global start]
[extern _k_main] ; this is in the c file
start:
call _k_main
cli ; stop interrupts
hlt ; halt the CPU
; these are in the linker script file
EXTERN code, bss, end
ALIGN 4
mboot:
dd MULTIBOOT_HEADER_MAGIC
dd MULTIBOOT_HEADER_FLAGS
dd MULTIBOOT_CHECKSUM
dd mboot
dd code
dd bss
dd end
dd start
;------------------------
;---kstart.asm-----------
MULTIBOOT_PAGE_ALIGN equ 1<<0
MULTIBOOT_MEMORY_INFO equ 1<<1
MULTIBOOT_AOUT_KLUDGE equ 1<<16
MULTIBOOT_HEADER_MAGIC equ 0x1BADB002
MULTIBOOT_HEADER_FLAGS equ MULTIBOOT_PAGE_ALIGN | MULTIBOOT_MEMORY_INFO | MULTIBOOT_AOUT_KLUDGE
MULTIBOOT_CHECKSUM equ -(MULTIBOOT_HEADER_MAGIC + MULTIBOOT_HEADER_FLAGS)--;----------------------
then compile/assemble...
nasm -f aout kstart.asm -o ks.o
gcc -c kernel.c -o kernel.o
ld -T link.ld -o kernel.bin ks.o kernel.o
Im sorry, i gotta get this to work!!
RE:protected mode bootstrap? ..GRUB?
i have no idea if that doesnt work. I was referring to the code on the html page.
It looks ok. But if Grub says error 13 then something is obviously wrong and i would put my money on either the aout section kludge details or the way it's compiled and linked.
Why not try simplifying it by removing all the C references and just assemble the asm code. Then build from the start asm function.
Something like...
grub.inc...
MULTIBOOT_PAGE_ALIGN equ 1<<0
MULTIBOOT_MEMORY_INFO equ 1<<1
MULTIBOOT_AOUT_KLUDGE equ 1<<16
MULTIBOOT_HEADER_MAGIC equ 0x1BADB002
MULTIBOOT_HEADER_FLAGS equ MULTIBOOT_PAGE_ALIGN | MULTIBOOT_MEMORY_INFO | MULTIBOOT_AOUT_KLUDGE
MULTIBOOT_CHECKSUM equ -(MULTIBOOT_HEADER_MAGIC + MULTIBOOT_HEADER_FLAGS)
kstart.asm...
[BITS 32]
[SECTION .text]
%include "grub.inc"
[global start]
start:
cli
hlt
EXTERN code, bss, end
ALIGN 4
mboot:
dd MULTIBOOT_HEADER_MAGIC
dd MULTIBOOT_HEADER_FLAGS
dd MULTIBOOT_CHECKSUM
dd mboot
dd code
dd bss
dd end
dd start
Then assemble with something like...
nasm -f aout kstart.asm
ld --T link.ld -o kernel.bin *.o
Otherwise i would recommend try using elf without the kludge. Get that to boot so you know it works, then convert it to work with aout + kludge.
Brill.
It looks ok. But if Grub says error 13 then something is obviously wrong and i would put my money on either the aout section kludge details or the way it's compiled and linked.
Why not try simplifying it by removing all the C references and just assemble the asm code. Then build from the start asm function.
Something like...
grub.inc...
MULTIBOOT_PAGE_ALIGN equ 1<<0
MULTIBOOT_MEMORY_INFO equ 1<<1
MULTIBOOT_AOUT_KLUDGE equ 1<<16
MULTIBOOT_HEADER_MAGIC equ 0x1BADB002
MULTIBOOT_HEADER_FLAGS equ MULTIBOOT_PAGE_ALIGN | MULTIBOOT_MEMORY_INFO | MULTIBOOT_AOUT_KLUDGE
MULTIBOOT_CHECKSUM equ -(MULTIBOOT_HEADER_MAGIC + MULTIBOOT_HEADER_FLAGS)
kstart.asm...
[BITS 32]
[SECTION .text]
%include "grub.inc"
[global start]
start:
cli
hlt
EXTERN code, bss, end
ALIGN 4
mboot:
dd MULTIBOOT_HEADER_MAGIC
dd MULTIBOOT_HEADER_FLAGS
dd MULTIBOOT_CHECKSUM
dd mboot
dd code
dd bss
dd end
dd start
Then assemble with something like...
nasm -f aout kstart.asm
ld --T link.ld -o kernel.bin *.o
Otherwise i would recommend try using elf without the kludge. Get that to boot so you know it works, then convert it to work with aout + kludge.
Brill.
RE:protected mode bootstrap? ..GRUB?
no luck! :'( i just used the assembler code and got the same error!
but i just thought..
this is my link script...
is it supposed to be a binary output..!?
---link.ld-------------
OUTPUT_FORMAT("binary")
ENTRY(start)
SECTIONS
{
.text 0x100000 : {
code = .; _code = .; __code = .;
*(.text)
. = ALIGN(4096);
}
.data : {
data = .; _data = .; __data = .;
*(.data)
. = ALIGN(4096);
}
.bss :
{
bss = .; _bss = .; __bss = .;
*(.bss)
. = ALIGN(4096);
}
end = .; _end = .; __end = .;
}
-------------------
but i just thought..
this is my link script...
is it supposed to be a binary output..!?
---link.ld-------------
OUTPUT_FORMAT("binary")
ENTRY(start)
SECTIONS
{
.text 0x100000 : {
code = .; _code = .; __code = .;
*(.text)
. = ALIGN(4096);
}
.data : {
data = .; _data = .; __data = .;
*(.data)
. = ALIGN(4096);
}
.bss :
{
bss = .; _bss = .; __bss = .;
*(.bss)
. = ALIGN(4096);
}
end = .; _end = .; __end = .;
}
-------------------