C os programming
Re:C os programming
You left out the BIOS Extended Data Area, it extends down from 0x9FFFF, it's length varies from BIOS to BIOS (which is why you're meant to use the "Get Conventional Memory Size" function).
Re:C os programming
I'll try it. Actually, the bootloader loads the kernel into 0x0100.
The kernel has its own loader(the asm file) which switch into protected mode and then start the c function.
So it doesn't work because, when it switches, the protected mode addresses ovelap and delete from ram the kernel at 0x0100?
If so, i only need to make the bootloader load the kernel at 0x1000000?
The kernel has its own loader(the asm file) which switch into protected mode and then start the c function.
So it doesn't work because, when it switches, the protected mode addresses ovelap and delete from ram the kernel at 0x0100?
If so, i only need to make the bootloader load the kernel at 0x1000000?
Re:C os programming
@ SpiglerG:
Did you visit the FAQ? Did you toy with the BabySteps tutorial? Did you actually try any of the other tutorials before setting out to write your own code?
may i suggest you read through Rolling your Own Bootloader ? We've listed a list of common questions/options and caveats for people not wanting to use GRUB
Did you visit the FAQ? Did you toy with the BabySteps tutorial? Did you actually try any of the other tutorials before setting out to write your own code?
may i suggest you read through Rolling your Own Bootloader ? We've listed a list of common questions/options and caveats for people not wanting to use GRUB
Every good solution is obvious once you've found it.
Re:C os programming
I only need to modify the bootloader and kernel a little. Only set the loading address to 0x100000, isn't it?
After that, will the kernel work?
After that, will the kernel work?
Re:C os programming
Yes. Like I said, you can load it lower but as AR just said, you would need to use the "Get Conventional Memory Size" function to figure out what areas are free and which are not.So it doesn't work because, when it switches, the protected mode addresses ovelap and delete from ram the kernel at 0x0100? If so, i only need to make the bootloader load the kernel at 0x1000000?
A good place for now would be to load it at 1MB. Later on you may want to load it lower depending on what features you would like to support. Just remember to set the A20 gate, or you will not be able to access memory above 1Mb.
Hope this helps.
Re:C os programming
ok. i'll try to load it at 1mb(0x100000) and then enable protected mode and A20.
i'll post later.
PS: i need to make the bootsector switch to pm and enable a20?
or can i do it later.
i'll post later.
PS: i need to make the bootsector switch to pm and enable a20?
or can i do it later.
Re:C os programming
Otherwise, i can switch to protected mode from start.asm, but load it separately from the kernel after the bootsector in the memory and then load another starter for the c function at 0x100000.
So, what should i do?
So, what should i do?
Re:C os programming
Since your bootloader is fat12, there will be no room left for pmode or a20. Use a second file to load into pmode, set a20, and call your c kernel. The a20 gate can be set before or after you enter protected mode.i need to make the bootsector switch to pm and enable a20? or can i do it later.
See above.Otherwise, i can switch to protected mode from start.asm, but load it separately from the kernel after the bootsector in the memory and then load another starter for the c function at 0x100000.
So, what should i do?
Hope this helps.
Re:C os programming
To read a sector i use bios functions.
using bios functions i need to be in real mode, but in real mode i can't use the address 0x100000(in the loader to load the kernel at that address).
using bios functions i need to be in real mode, but in real mode i can't use the address 0x100000(in the loader to load the kernel at that address).
Re:C os programming
This needs to go into your second-stage loader: then set a20, enable protected mode, load kernel.To read a sector i use bios functions.
using bios functions i need to be in real mode, but in real mode i can't use the address 0x100000(in the loader to load the kernel at that address).
Code: Select all
;-----------------------------------------------------
reset_Disk: ; Reset Floppy Disk
xor ax, ax ; Zero AX register
int 13h ; Actually Reset
or ah, ah ; Check for error code
jc reset_Disk ; IF ERROR => reset again
;-----------------------------------------------------------
; Load sectors from the Floppy disk into memory
; Using CHS (Cylinder, Head, Sector) Addressing
;-----------------------------------------------------------
readin_kernel:
mov ax, 0xFFFF ; ES:BX = 0xFFFF:0x0010 (1MB)
mov es, ax
mov bx, 0x0010
mov ah, 0x02 ; Load disk data to ES:BX
mov al, 0x17 ; Load 17 sectors
mov ch, 0x00 ; Track = 0x00
mov cl, 0x02 ; Sector = 0x02
mov dh, 0x00 ; Head = 0x00
mov dl, [DriveNumber] ; Drive number (0x00 = Floppy, 0x80 = Hard Drive)
int 13h ; Read Disk!
or ah, ah ; Check for error code
jc readin_kernel ; If Error => read again
Hope this helps.
Re:C os programming
I didn't remember this. Yes.
But i need to insert the code you gave me and then enable a20, or enable a20 and then insert you code.
But i need to insert the code you gave me and then enable a20, or enable a20 and then insert you code.
Re:C os programming
The reset_disk and read_sectors function needs to be before you enable a20. Then you can either enable a20 before or after you enable protected mode as long as it is set.But i need to insert the code you gave me and then enable a20, or enable a20 and then insert you code.
Yes/no.PS: FFFF:0010 is 1mb? isn't it 1000F
When the IBM-AT was introduced, it was able to access up to sixteen megabytes of memory (instead of the 1 MByte of the IBM-XT). But to remain compatible with the IBM-XT, a quirk in the XT architecture (memory wraparound) had to be duplicated in the AT. To achieve this, the 20th line on the address bus (A20) was turned off.
So if the a20 gate isnt enabled (turned off), it will cause 0xFFFF:0x0010 (1MB) to wraparound and you will get 0.
Segment * 16 + offset
0xFFFF * 0x0010 + 0x0010 = 0x100000 (1MB)
Re:C os programming
Ok.
Now i can't, but tomorrow i'll try it. if it won't work i'll post here.
The code you posted doesn't search for a file(for example kernel.bin), my bootloader doeas it.
Can i use my bootloader code for the bootloader AND a copy for the loader? (the loader copy will switch to pm, load gdt, enable a20, but first of all, will load a kernel.bin at FFFF:0010).
Now i can't, but tomorrow i'll try it. if it won't work i'll post here.
The code you posted doesn't search for a file(for example kernel.bin), my bootloader doeas it.
Can i use my bootloader code for the bootloader AND a copy for the loader? (the loader copy will switch to pm, load gdt, enable a20, but first of all, will load a kernel.bin at FFFF:0010).