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
;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
with this boot my kernel entry point its start from 0x1000# 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
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