trouble loading function calls

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
assembler01
Member
Member
Posts: 25
Joined: Mon Feb 27, 2012 9:46 am

trouble loading function calls

Post by assembler01 »

I use for my kernel the mikeos bootloader (http://mikeos.berlios.de/). I checked in the mikeos kernel and saw how the segments were setup:

Code: Select all

cli
mov ax, 0
mov ss, ax
mov sp, 0FFFFh
sti
cld
mov ax, 2000h
mov ds, ax
mov es, ax
mov fs, ax
mov gs, ax
And before you question it, yes I know about segments well enough to have made my own hello world bootloader (with a function call), but I found it difficult to make a bootloader to load my kernel. Anyway, I put the above code into my (16 bit) kernel, included the functions for my kernel, and proceeded to load the kernel (I have it in a partition in my hdd) with QEMU, it booted up, told me it found the kernel but the kernel didn't do anything, so I went back to the editor and made a small thing it would do at startup (after the segments were loaded):

Code: Select all

mov ah, 0Eh
mov al, 'o'
int 10h
When I booted it up it had printed the "o" char to the screen which meant that the system calls where the only things that didn't work. How do I get the system calls to work?
Talk is cheap, show me the code. - Linus Torvalds
User avatar
bubach
Member
Member
Posts: 1223
Joined: Sat Oct 23, 2004 11:00 pm
Location: Sweden
Contact:

Re: trouble loading function calls

Post by bubach »

What system calls? You said the kernel didn't do anything, and you then added the BIOS call to print a character. Which worked. So I don't see any problem. If you have additional kernel code that doesn't work, it might be a good idea to show it.
"Simplicity is the ultimate sophistication."
http://bos.asmhackers.net/ - GitHub
assembler01
Member
Member
Posts: 25
Joined: Mon Feb 27, 2012 9:46 am

Re: trouble loading function calls

Post by assembler01 »

Sorry, forgot about that. :lol:

Code: Select all

main:
  call clean_all ; will clear the screen and clean out the GP regs
  .string: db 'Successfully booted!', 0
  mov si, .string
  call print
  hlt

; include the functions:
%include "screen.asm"
%include "clean.asm"
Talk is cheap, show me the code. - Linus Torvalds
Unkn0wn1
Member
Member
Posts: 37
Joined: Fri Jan 13, 2012 11:18 am

Re: trouble loading function calls

Post by Unkn0wn1 »

Have you set the origin of the kernel. And also, what fs are you using in the disk image. Seeing the other files may help, as I am working on something realmode so know my way around...

Also, before you put the HLT instruction at the end of the kernel, put a CLI too. Otherwise, any interrupts will lead to a triple-fault and pulsing of the CPU's RESET pin
Not sane
Just remember, FIND Is Not DOS :)
assembler01
Member
Member
Posts: 25
Joined: Mon Feb 27, 2012 9:46 am

Re: trouble loading function calls

Post by assembler01 »

What do you mean by "origin of kernel". I use fat12 fs. Here is the print function:

Code: Select all

print:
  pusha
.loop:
  lodsb
  cmp al, 0
  je .done
  mov ah, 0eh
  mov bh, 00h
  int10h
  jmp .loop
.done:
  popa
  ret
And here is the cleaning function:

Code: Select all

clean_all:
  ; clear screen
  mov ax, 0600h
  mov bh, 07h
  mov cx, 0000h
  mov dx, 7924h
  int 10h
  ; clean the regs
  mov ax, 0
  mov bx, 0
  mov cx, 0
  mov dx, 0
  mov si, 0
  mov di, 0
  ret
Talk is cheap, show me the code. - Linus Torvalds
User avatar
Combuster
Member
Member
Posts: 9301
Joined: Wed Oct 18, 2006 3:45 am
Libera.chat IRC: [com]buster
Location: On the balcony, where I can actually keep 1½m distance
Contact:

Re: trouble loading function calls

Post by Combuster »

The problem is much more simple. You wrote:

Code: Select all

  .string: db 'Successfully booted!', 0
The processor sees the following instructions:

Code: Select all

   0:   e8 1c 00                call   0x1f    ; first instruction
   3:   53                      push   %bx     ; we come back here after the call and er.... what?
   4:   75 63                   jne    0x69    ; oops
   6:   63 65 73                arpl   %sp,0x73(%di) 
   9:   73 66                   jae    0x71    
   b:   75 6c                   jne    0x79    
   d:   6c                      insb   (%dx),%es:(%di)
   e:   79 20                   jns    0x30    
  10:   62 6f 6f                bound  %bp,0x6f(%bx)
  13:   74 65                   je     0x7a
  15:   64 21 00                and    %ax,%fs:(%bx,%si)
In other words: keep data away from code.



@Unkn0wn1: Please do not suggest random stuff unless you can also post proof that it's the problem at hand. This is not the first time you were posting irrelevant stuff and you just managed to confuse the OP
"Certainly avoid yourself. He is a newbie and might not realize it. You'll hate his code deeply a few years down the road." - Sortie
[ My OS ] [ VDisk/SFS ]
assembler01
Member
Member
Posts: 25
Joined: Mon Feb 27, 2012 9:46 am

Re: trouble loading function calls

Post by assembler01 »

I put the .string in the data section but the function calls do not work.
Talk is cheap, show me the code. - Linus Torvalds
Post Reply