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