Page 1 of 1

wiki Pascal_Bare_Bones tutorial How to Boot and start

Posted: Tue Jan 01, 2013 5:11 am
by serkank
i was made kernel.c from another tutorial . and its work ..
This is Boot_sect.asm and kernel_entry.asm

boot_sect.asm for kernel.c

Code: Select all

[ org 0x7c00 ]

KERNEL_OFFSET equ 0x1000                ; This is the memory offset to which
                                        ; we will load our kernel

mov bp , 0x9000                 ; Set - up the stack
mov sp , bp

mov bx , MSG_REAL_MODE          ; Announce that we are starting
call print_string               ; booting from 16 - bit real mode

call load_kernel                ; Load our kernel

call switch_to_pm               ; Switch to protected mode , from which
                                ; we will not return

jmp $

%include "kernel/print_string.asm"     ; Re - use our print_string function
%include "kernel/diskload.asm"
%include "kernel/GDT.asm"
%include "kernel/print_string_pm.asm"
%include "kernel/switch_to_pm.asm"



[ bits 16]


; Kernel load
load_kernel:

mov bx , MSG_LOAD_KERNEL        ; Print a message to say we are loading the kernel
call print_string

mov bx , KERNEL_OFFSET          ; Set - up parameters for our disk_load routine , so
mov dh , 15                     ; that we load the first 15 sectors ( excluding
mov dl , [ BOOT_DRIVE ]         ; the boot sector ) from the boot disk ( i.e. our
call disk_load                  ; kernel code ) to address KERNEL_OFFSET

ret



[ bits 32]

; This is where we arrive after switching to and initialising protected mode.
BEGIN_PM :
mov ebx , MSG_PROT_MODE         ; Use our 32 - bit print routine.
;call print_string_pm            ; announce we are in protected mode


call KERNEL_OFFSET              ; Now jump to the address of our loaded
                                ; kernel code , assume the brace position ,
                                ; and cross your fingers. Here we go !


jmp $                           ; Hang.


; Global variables
BOOT_DRIVE      db 0
MSG_REAL_MODE   db " Started in 16 - bit Real Mode ",0
MSG_PROT_MODE   db " Successfully landed in 32 - bit Protected Mode ",0
MSG_LOAD_KERNEL db " Loading kernel into memory ",0

; Bootsector padding
times 510 -( $ - $$ ) db 0
dw 0xaa55
kernel_entry.asm for kernel.c
;Ensures that we jump straight into the kernel ’s entry function.
[ bits 32]
; We ’ re in protected mode by now , so use 32 - bit instructions.
[ extern main ] ; Declate that we will be referencing the external symbol ’ main ’,
; so the linker can substitute the final address



call main ; invoke main () in our C kernel
jmp $ ; Hang forever when we return from the kernel


Now i want use wiki pascal_bare_bones tutorial but i dont know how can i use it
because its havent boot.asm code.
if i try my boot asm code its give error or it cant find entrypoint for kernel
i think i have problem with linker and fpc
This is kernel.c makefile
# Automatically generate lists of sources using wildcards .
C_SOURCES = $(wildcard kernel/*.c drivers/*.c)
HEADERS = $(wildcard kernel/*.h drivers/*.h )

# TODO : Make sources dep on all header files .

# Convert the *. c filenames to *. o to give a list of object files to build
OBJ = ${C_SOURCES:.c=.o}


# Defaul build target
all : os-image


# Run bochs to simulate booting of our code .
run : all
bochs -f bochsconf

# This is the actual disk image that the computer loads ,
# which is the combination of our compiled bootsector and kernel
os-image : boot/boot_sect.bin kernel.bin
cat $^ > os-image

# Disassemble our kernel - might be useful for debugging .
kernel.dis : kernel.bin
ndisasm -b 32 $< > $@


# This builds the binary of our kernel from two object files :
# - the kernel_entry , which jumps to main () in our kernel
# - the compiled C kernel
kernel.bin : kernel/kernel_entry.o ${OBJ}
ld -o $@ -Ttext 0x1000 $^ --oformat binary

# Generic rule for compiling C code to an object file
# For simplicity , we C files depend on all header files .
%.o : %.c ${HEADERS}
gcc -ffreestanding -c $< -o $@


# Assemble the kernel_entry .
%.o : %.asm
nasm $< -f elf -o $@

%.bin : %.asm
nasm $< -f bin -I "../../16bit/" -o $@

clean :
rm -fr *.bin *.dis *.o os-image
rm -fr kernel/*.o boot/*.bin drivers/*.o
with this boot my kernel entry point its start from 0x1000
but i cant do it for stub.asm..
please help me fix this code or show me a new boot loader for pascal bare_bones tutorial

Re: wiki Pascal_Bare_Bones tutorial How to Boot and start

Posted: Tue Jan 01, 2013 10:36 am
by Combuster
The answer is in the original tutorial text.
a multiboot-compliant boot loader needed
On another note, your current version seems to have all the beginner mistakes that lead to latent bugs. You have a lot to read.

Re: wiki Pascal_Bare_Bones tutorial How to Boot and start

Posted: Tue Jan 01, 2013 1:15 pm
by serkank
multibot boot loader where can i find a sample code for it ?


or how i can fix my codes for work together ? i think if i can modify litle this codes it can work
in my bootloader shortly work like this

Code: Select all

KERNEL_OFFSET equ 0x1000 
call DISKLOAD ; LOAD KERNEL ENTRY POINT TO KERNEL_OFFSET 0x1000
call KERNEL_OFFSET 
and my kernel_entrypoint.asm

Code: Select all

;Ensures that we jump straight into the kernel ’s entry function.
[ bits 32]
; We ’ re in protected mode by now , so use 32 - bit instructions.
[ extern main ] ; Declate that we will be referencing the external symbol ’ main ’,
; so the linker can substitute the final address
call main ; invoke main () in our C kernel
jmp $ ; Hang forever when we return from the kernel
DiskLoad.asm code Load Kernel_entrypoint.asm to address 0x1000
and i can call from bootload.asm to call 0x1000 for run my kernel code..
ld -o $@ -Ttext 0x1000 $^ --oformat binary

i think if i can load stub.asm to 0x1000 i can start this code to...
but should i use ld command i dont know..
is there multibootloader sample in this site ?

Re: wiki Pascal_Bare_Bones tutorial How to Boot and start

Posted: Tue Jan 01, 2013 1:21 pm
by bluemoon
You seems not ready for OS development yet. You wouldn't learn much if we just pull out some code or fix the issues for you, even then, the real deal are yet to come later, you need to learn how to catch fish yourself.
I kindly advice that you spend a week or two reading every page at Main_Page, for good.

Re: wiki Pascal_Bare_Bones tutorial How to Boot and start

Posted: Wed Jan 02, 2013 3:21 pm
by serkank
i must learn much things because i just start to learn. i am trying read. but i want learn step by step.. maybe you understand me wrong .
i dont want people Fix my wrong. i want understand where is my wrong. how i can fix/change my entry point (address). or what i must change..

Ok ... i found somethings about multiboot and convert it for pascal barebone tutorial. now its start.