1 registered members (AndrewAMD),
1,248
guests, and 6
spiders. |
Key:
Admin,
Global Mod,
Mod
|
|
|
assembler help
#319372
04/14/10 15:57
04/14/10 15:57
|
Fear411
Unregistered
|
Fear411
Unregistered
|
hey,
is there anyone who knows assembler and can help me with a problem (bootloader)?
Thanks, Fear
|
|
|
Re: assembler help
[Re: Joey]
#319410
04/14/10 19:26
04/14/10 19:26
|
Fear411
Unregistered
|
Fear411
Unregistered
|
i dont know if the problem is in the bootloader or in the bootable floppy image, but i created a bootload which should load a program, but the program doesn't get loaded.
|
|
|
Re: assembler help
[Re: ]
#319412
04/14/10 19:52
04/14/10 19:52
|
Joined: Aug 2005
Posts: 1,230
MichaelGale
Serious User
|
Serious User
Joined: Aug 2005
Posts: 1,230
|
Have you verified that your bootloader is exactly 512 bytes long and located in the first sector on your floppy? Is your computer / virtual machine set to boot from the floppy? What happens if you run your bootloader?
Your friendly mod is at your service.
|
|
|
Re: assembler help
[Re: MichaelGale]
#319415
04/14/10 20:02
04/14/10 20:02
|
Fear411
Unregistered
|
Fear411
Unregistered
|
yes yes
The bootloader does everything he should except loading/jumping to the program.
Do you need some code?
|
|
|
Re: assembler help
[Re: ]
#319416
04/14/10 20:04
04/14/10 20:04
|
Joined: Aug 2005
Posts: 1,230
MichaelGale
Serious User
|
Serious User
Joined: Aug 2005
Posts: 1,230
|
I suppose so; otherwise it's hard to tell what is going wrong.
Your friendly mod is at your service.
|
|
|
Re: assembler help
[Re: MichaelGale]
#319422
04/14/10 20:48
04/14/10 20:48
|
Fear411
Unregistered
|
Fear411
Unregistered
|
Thats the bootloader
org 0x7C00 ;start address of the bootloder that will load the kernel
xor ax, ax
mov ds, ax
mov es, ax
mov ss, ax
mov sp, ax
mov [bootdrive], dl ;bootdrive stored by BIOS in DL.
;we save it to [bootdrive] to play for safety.
mov si, strLoad ;show loading message
call printStr
;-----------------------
loadKernel:
mov si, strDot ;show loading progress
call printStr
xor ax, ax ;mov ax, 0 => function "reset"
mov dl, [bootdrive] ;boot drive
int 0x13 ;reset floppy drivers
jc loadKernel ;CF set? try again
mov si, strDot
call printStr
;set parameters for reading function
mov ah, 0x2 ;read sectors
mov al, 10 ;read 10 sectors
mov ch, 0 ;cylinder = 0
mov cl, 2 ;sector = 2
mov dh, 0 ;head = 0
mov dl, [bootdrive] ;boot drive
mov bx, 0x8000 ;start address of kernel
int 0x13 ;read sectors
jc loadKernel ;CF set? try again
mov si, strDot
call printStr
mov si, strDone
call printStr
jmp 0x8000
;-----------------------
printStr:
mov ah, 0x0E ;teletype output
.loop:
lodsb ;grab a byte from SI
test al, al ;NULL?
jz .done ;if NULL exit
int 0x10 ;print out the character!
jmp .loop
.done:
ret
;-----------------------
bootdrive db 0 ;boot drive, 0 = floppy
strLoad db "Loading kernel", 0
strDot db ".", 0
strDone db "[DONE]", 13, 10, 0
times 510-($-$$) hlt
db 0x55
db 0xAA
and thats the kernel:
[BITS 32]
[global kernelMain]
[extern _main]
kernelMain:
jmp 0xffff:0x0000 ;reset pc
jmp $
the c kernel is just a main function. At this stage i dont call it. The linker script:
ENTRY(kernelMain)
SECTIONS
{
.text 0x8000 : {
*(.text)
}
.data : {
*(.data)
}
.bss : {
*(.bss)
}
}
and the program to create the floppy image:
char boot_buf[512];
char kernel_buf[1024];
char space_buf[1474560-512-1024] = {0};
int floppy_desc, file_desc;
file_desc = open("boot.bin", O_RDONLY);
read(file_desc, boot_buf, 512);
close(file_desc);
floppy_desc = open("floppy.img", O_RDWR);
lseek(floppy_desc, 0, SEEK_SET);
write(floppy_desc, boot_buf, 512);
file_desc = open("kernel.bin", O_RDONLY);
read(file_desc, kernel_buf, 1024);
close(file_desc);
lseek(floppy_desc, 512, SEEK_SET);
write(floppy_desc, kernel_buf, 1024);
lseek(floppy_desc, 1024+512, SEEK_SET);
write(floppy_desc, space, 1474560-512-1024);
close(floppy_desc);
Last edited by Fear411; 04/15/10 14:19.
|
|
|
Re: assembler help
[Re: ]
#319440
04/14/10 21:23
04/14/10 21:23
|
Joined: Aug 2005
Posts: 1,230
MichaelGale
Serious User
|
Serious User
Joined: Aug 2005
Posts: 1,230
|
You are trying to run a 32-bit program in real mode which is something you can't do. You need to switch to protected mode if you want to run your 32-bit kernel.
Your friendly mod is at your service.
|
|
|
Re: assembler help
[Re: MichaelGale]
#319522
04/15/10 14:29
04/15/10 14:29
|
Fear411
Unregistered
|
Fear411
Unregistered
|
mhh it doesnt work, also when i switch the program to 16bit. But i have another problem. I used fat_imgen to generate the image and then inserted the bootloader and the kernel. But i changed it so it creates the image with the file above, but now it doesnt even boots.
|
|
|
|