Kernel loading

Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
Post Reply
FlashBurn

Kernel loading

Post by FlashBurn »

OK, I?ve created my own filesystem, because so it was easier for me to laod my kernel from a floppy disk. But now I get into troublw ith this, because although I load my kernel 0x1000 and then moving it to 0x100000, there is some code of the bootsector in the kernel. I think so, because there are 4bytes, which are equal to the first 4bytes of the bootsector. But the problem is that my code is hard to read and that you need time and you have to be good at assembly. So first I want to ask, if here is anyone who would help me with my problem. If not, I needn?t to upload my source code.
distantvoices
Member
Member
Posts: 1600
Joined: Wed Oct 18, 2006 11:59 am
Location: Vienna/Austria
Contact:

Re:Kernel loading

Post by distantvoices »

1. Hmmm ... can't you load the kernel directly to 1 mb by passing the proper information to bios int 13h? I did it and it worked as I expected it to.

2. Beeing good at assembler ot not beeng good at assembler that is the question here ... well I can write and read assembler code, but: I won't read UNCOMMENTED assembler code. This is a mess for you and a mess for me as well as for anyone else who wants to help you.

stay safe
... the osdever formerly known as beyond infinity ...
BlueillusionOS iso image
FlashBurn

Re:Kernel loading

Post by FlashBurn »

My bootsector is commented. Maybe you could post the values I need to load my kernel to the 1mb mark?!
distantvoices
Member
Member
Posts: 1600
Joined: Wed Oct 18, 2006 11:59 am
Location: Vienna/Austria
Contact:

Re:Kernel loading

Post by distantvoices »

I am looking ...

Code: Select all


  mov ax,0xffff 
  mov es,ax
  mov bx.0x10

this I use to tell int 13h to load kernel to 0x100000.

found how to do this btw in the fritzos boot loader and in perica senjaks real mode adressing doc.
... the osdever formerly known as beyond infinity ...
BlueillusionOS iso image
FlashBurn

Re:Kernel loading

Post by FlashBurn »

Thank you, but I will use my variant. I also will comment my kernel code and then I upload it. Maybe there is someone who have a look at my code. Is there a way, how I can debug my kernel code with Bochs? I mean I want to look at every instruction so that I may see from where I?m writing into my kernel.
distantvoices
Member
Member
Posts: 1600
Joined: Wed Oct 18, 2006 11:59 am
Location: Vienna/Austria
Contact:

Re:Kernel loading

Post by distantvoices »

debug with box:

start the debugger; indicate a bochserr.txt for trace-log;
make ctrl-c as soon as you enter your boot loader; enter 'trace-on' at box-cli; enter 'c' -> the show goes on.

with 'step n' you can have box execute the next 10 instructions.

In windows, you'll find the debugger option by right click on your *.bxrc-file to call the context menu.
... the osdever formerly known as beyond infinity ...
BlueillusionOS iso image
FlashBurn

Re:Kernel loading

Post by FlashBurn »

Thanks, I used this, but I didn?t found a failure. But I also haven?t got time to take a deeper look. I attached the source of my bootloader and my kernel. If you have questions please ask. I didn?t comment all, because I don?t think that you will look at the whole code. I only commented the important code!

[attachment deleted by admin]
Perica
Member
Member
Posts: 454
Joined: Sat Nov 25, 2006 12:50 am

Re:Kernel loading

Post by Perica »

..
Last edited by Perica on Sun Dec 03, 2006 9:01 pm, edited 1 time in total.
FlashBurn

Re:Kernel loading

Post by FlashBurn »

OK, I?ve forgotten to describe my problem more detailed. I have the problem that when the code grows that the values of the last vars get overwritten! You can test this when you make the following changes:

Old code:

Code: Select all

call mem_info
lidt [IDTR]
sti

.hang
jmp $
New code:

Code: Select all

call mem_info
lidt [IDTR]
sti

mov eax,[taskmngr_thread_desc]
call hex2ascii32bit_str

.hang
jmp $
The value of the var should be 0, but it isn?t 0.

Now try this code:

Code: Select all

;call mem_info
;lidt [IDTR]
;sti

mov eax,[taskmngr_thread_desc]
call hex2ascii32bit_str

.hang
jmp $
Now the value is 0. But why? Because of that I deleted some code? Please help me!

Edit::

I believe now that there is a problem with my bootsector. I assemble my bootsector and my kernel and then I copy both into 1 file so that I have a diskimage! Then I write this diskimage with rawwritewin on a disk. I use logical sectors to load my kernel file of the disk. Maybe this is the problem, but I don?t think so! But it would be good if someone have a look at my bootcode!
FlashBurn

Re:Kernel loading

Post by FlashBurn »

Had anyone a look at my code?
User avatar
Pype.Clicker
Member
Member
Posts: 5964
Joined: Wed Oct 18, 2006 2:31 am
Location: In a galaxy, far, far away
Contact:

Re:Kernel loading

Post by Pype.Clicker »

sounds like nobody did ...
what do you mean by "logical sectors" ? you're booting from a floppy, right ? what is "logical sector" on a floppy ... afaik, only CHS is available on such a disk.
FlashBurn

Re:Kernel loading

Post by FlashBurn »

By logical sectory I mean that I start with sector 0 and go on till sector 2879 (a floppy has 2880 sectors). This is my function to get the head/track/sector from a logical sector:

Code: Select all

SectorsPertrack dw 18
Heads                dw 2

;----------------------------
; Input:
; AX - logical sector
; Output:
; CL - sector
; CH - track
; DH - head
trans_lsn:
???xor dx,dx
???div word[SectorsPerTrack]
???inc dx
???mov cl,dl
???xor dx,dx
???div word[Heads]
???shr dx,8
???mov ch,al
.end
???ret
;----------------------------
FlashBurn

Re:Kernel loading

Post by FlashBurn »

Finally I found the failure ;D My "trans_lsn" function wasn?t right.

This is the right code:

Code: Select all

;----------------------------
;   Input:
;   AX - logical sector
;   Output:
;   CL - sector
;   CH - track
;   DH - head
trans_lsn:
   xor dx,dx
   div word[SectorsPerTrack]
   inc dl
   mov cl,dl
   xor dx,dx
   div word[Heads]
   shl dx,8
   mov ch,al
.end
   ret
;----------------------------
User avatar
Pype.Clicker
Member
Member
Posts: 5964
Joined: Wed Oct 18, 2006 2:31 am
Location: In a galaxy, far, far away
Contact:

Re:Kernel loading

Post by Pype.Clicker »

shr vs shl ... lol :D
Post Reply