PLEASE HELP ME, how to jump to C code in kernel?
Posted: Mon Nov 26, 2007 6:37 am
this program is running in Linux
Using NASM assembler and GCC compiler
I loaded 3rd sector to memory address of 0x2000:0x0000
(1st sector is bootloader "boot.bin", 2nd sector is kernel.bin and 3rd sector is "kRoutine.bin" -> but i wonder if the 3rd sector is correct or not)
in "boot.asm"
and i jump to 0x00020000
in "kernel.asm"
"kRoutine.c" and "kRoutineAsm.asm" will be binded
in "kRoutine.c"
in "kRoutineAsm.asm"
assemble and compile all the source files
and linking like above
and remove unnecessary information to make binary file
and combine all of binary file.
I want to ask is that
this following 2 commands are correct?
and file "kRoutine.bin" is exactly saved in 3rd sector of image?
and can execute main() in "kRoutine.c" by jump to 0x00020000 ?
Thanks for reading!!
Have a nice day
Using NASM assembler and GCC compiler
I loaded 3rd sector to memory address of 0x2000:0x0000
(1st sector is bootloader "boot.bin", 2nd sector is kernel.bin and 3rd sector is "kRoutine.bin" -> but i wonder if the 3rd sector is correct or not)
in "boot.asm"
Code: Select all
.read_kRoutine
mov ax, 0x2000
mov es, ax
mov bx, 0x00
mov ah, 0x02
mov al, 0x01
mov ch, 0x00
mov cl, 0x03
mov dh, 0x00
mov dl, 0x00
int 0x13
;jc .read_kRoutine
...
jmp 0x1000:0x0000 ;jmp to kernel.bin
in "kernel.asm"
Code: Select all
jmp 0x2000:0x0000 ;jmp to kRoutine.bin
"kRoutine.c" and "kRoutineAsm.asm" will be binded
in "kRoutine.c"
Code: Select all
#include <stdio.h>
int main(void){
printk();
halt();
}
in "kRoutineAsm.asm"
Code: Select all
printk:
push ebp
mov ebp, esp
push eax
push edi
push es
pushad
mov ax, SysVideoSelector
mov es, ax
mov edi, 0
mov byte [es:edi], 'H'
inc edi
mov byte [es:edi], 0x06
inc edi
mov byte [es:edi], 'i'
inc edi
mov byte [es:edi], 0x06
inc edi
popad
pop es
pop edi
pop eax
mov esp, ebp
pop ebp
ret
halt:
HLT
jmp halt
assemble and compile all the source files
Code: Select all
nasm -f bin boot.asm -o boot.bin
nasm -f bin kernel.asm -o kernel.bin
gcc -c kRoutine.c
nasm -f elf32 kRoutineAsm.asm
Code: Select all
ld -Ttext 0x00020000 -e main -o kRoutine kRoutine.o RoutineAsm.o
Code: Select all
objcopy -R .note -R .comment -S -O binary kRoutine kRoutine.bin
Code: Select all
cat boot.bin kernel.bin kRoutine.bin > disk.img
this following 2 commands are correct?
Code: Select all
ld -Ttext 0x00020000 -e main -o kRoutine kRoutine.o kRoutineAsm.o
objcopy -R .note -R .comment -S -O binary kRoutine kRoutine.bin
and can execute main() in "kRoutine.c" by jump to 0x00020000 ?
Code: Select all
jmp 0x2000:0000
Thanks for reading!!
Have a nice day