Make 32 Bit Kernel

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
Cjreek
Member
Member
Posts: 70
Joined: Thu May 28, 2009 2:41 pm
Location: Germany

Make 32 Bit Kernel

Post by Cjreek »

Hi,

I've to admit, that I'm a real beginner in OS development. I startet yesterday. My bootloader works like it is supposed to, but I'd like to have a 32-Bit kernel.

Do I have to switch to protected mode before I can do anything else?

Well, Here's my Code. If I use [Bits 32] my cls and print procedure don't work anymore.

Code: Select all

; boot.asm
; this code only works with [BITS 16] !
[BITS 32]    
   	mov eax, 0x07C0
   	mov ds, eax
   	
   	call cls
   	mov esi, msg
   	call print
 
kernel: 
    jmp kernel
	
cls: 
    mov cx, 2000
    mov ax, 0x0420
    mov dx, 0xB800
    mov es, dx
    rep stosw            ; clear video buffer
    
    mov ah, 0x02
    xor dx, dx
    xor bh, bh
    int 10h              ; reset cursor pos
   
    ret
    
print:
    cld
    mov edx, 0xB800
    mov es, dx
     
  .ploop:    
    lodsb
    or al, al
    jz .done
    mov ah, 0x02   
    mov di, [xpos]   
    stosw                    ; write char at xpos using flags specified in ah
    
    add byte [xpos], 2  ; inc xpos
    jmp .ploop       
  .done:
    ret

msg	 db "Welcome to my OS!", 0
xpos   db 0
         times 510-($-$$) db 0
   	 db 0x55
   	 db 0xAA
Cjreek
User avatar
imate900
Member
Member
Posts: 80
Joined: Sat Feb 28, 2009 11:43 am

Re: Make 32 Bit Kernel

Post by imate900 »

You need to switch into protected mode.

Otherwise, fixed cls and print:

Code: Select all

cls:
    mov cx, 2000
    mov ax, 0x0420
    mov dx, 0xB800
    mov es, dx
    rep stosw            ; clear video buffer
   
    ret
   
print:
    cld
    mov edi, 0xB800
    mov es, dx
     
  .ploop:   
    lodsb
    or al, al
    jz .done
    mov ah, 0x02   
    mov edi, [xpos]   
    stosw                    ; write char at xpos using flags specified in ah
   
    add byte [xpos], 2  ; inc xpos
    jmp .ploop       
  .done:
    ret
Current work on a OS: SauOS (project homepage: http://code.google.com/p/sauos/)
Image
Cjreek
Member
Member
Posts: 70
Joined: Thu May 28, 2009 2:41 pm
Location: Germany

Re: Make 32 Bit Kernel

Post by Cjreek »

Hi,

Ok thanks. I changed my code, but it does not work yet.

And this part:

Code: Select all

print:
    cld
    mov edi, 0xB800
    mov es, dx           <--- this should be edi instead of dx?
But neither cls nor print works :/
User avatar
neon
Member
Member
Posts: 1567
Joined: Sun Feb 18, 2007 7:28 pm
Contact:

Re: Make 32 Bit Kernel

Post by neon »

Rather then taking code without understanding it, you should read this.

You do need to go into protected mode, but you have not performed the steps to create the environment (gdt/ints) nor switch the processor into protected mode. Just adding a [Bits 32] doesnt do anything related to protected mode.
OS Development Series | Wiki | os | ncc
char c[2]={"\x90\xC3"};int main(){void(*f)()=(void(__cdecl*)(void))(void*)&c;f();}
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: Make 32 Bit Kernel

Post by Combuster »

@imate: I find it very disturbing that over half the time, you post incorrect things and worse, assert those as being truth.

@Cjreek: Please read the Babystep tutorial.
"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 ]
Cjreek
Member
Member
Posts: 70
Joined: Thu May 28, 2009 2:41 pm
Location: Germany

Re: Make 32 Bit Kernel

Post by Cjreek »

neon wrote:Rather then taking code without understanding it, you should read this.

You do need to go into protected mode, but you have not performed the steps to create the environment (gdt/ints) nor switch the processor into protected mode. Just adding a [Bits 32] doesnt do anything related to protected mode.
Hi,

Sorry, I'm not that kind of guy who takes code without understanding it ;) I admit, that I used some code from the wiki as a base. But I spend half an hour understanding every single line of code. I could tell you something about every line :wink:

And it seems that there's a misunderstanding. I know that I've done nothing to enter protected mode. That's not my goal (not yet).

My question just was how to make my 16 Bit print and cls code running with [BITS 32] or whether it's necessary to switch to protected mode in order to run 32 Bit code.

And as far as I understood imate900 I can choose between running THIS code in protected mode OR change my code.
And changing my code the way imate900 suggested did not lead to success.

@Combuster: I've read the babystep tutorial til Babystep 4
User avatar
Troy Martin
Member
Member
Posts: 1686
Joined: Fri Apr 18, 2008 4:40 pm
Location: Langley, Vancouver, BC, Canada
Contact:

Re: Make 32 Bit Kernel

Post by Troy Martin »

And changing my code the way imate900 suggested did not lead to success.
And what have we learned from this? :P Just kidding.

@imate: Understand what you're talking about before you say it. If I were you, I'd be doing so or expecting a ban soon enough.
Image
Image
Solar wrote:It keeps stunning me how friendly we - as a community - are towards people who start programming "their first OS" who don't even have a solid understanding of pointers, their compiler, or how a OS is structured.
I wish I could add more tex
User avatar
JamesM
Member
Member
Posts: 2935
Joined: Tue Jul 10, 2007 5:27 am
Location: York, United Kingdom
Contact:

Re: Make 32 Bit Kernel

Post by JamesM »

Hi,
Cjreek wrote:
neon wrote:Rather then taking code without understanding it, you should read this.

You do need to go into protected mode, but you have not performed the steps to create the environment (gdt/ints) nor switch the processor into protected mode. Just adding a [Bits 32] doesnt do anything related to protected mode.
Hi,

Sorry, I'm not that kind of guy who takes code without understanding it ;) I admit, that I used some code from the wiki as a base. But I spend half an hour understanding every single line of code. I could tell you something about every line :wink:

And it seems that there's a misunderstanding. I know that I've done nothing to enter protected mode. That's not my goal (not yet).

My question just was how to make my 16 Bit print and cls code running with [BITS 32] or whether it's necessary to switch to protected mode in order to run 32 Bit code.

And as far as I understood imate900 I can choose between running THIS code in protected mode OR change my code.
And changing my code the way imate900 suggested did not lead to success.

@Combuster: I've read the babystep tutorial til Babystep 4
Apologies if Combuster sounded a little aggressive - we get people who copy-paste without reading in around the ratio 50-1 with people who actually attempt to understand.

There is a mode where you can run 32-bit code without protected mode. It's called "unreal mode" - there should be a wiki article on it. Other than that, if you want to run 32-bit code you'll have to switch to protected mode, which means setting up a GDT and setting the CR0.PE bit. Again, there's plenty about that on the wiki.

Cheers,

James
User avatar
Troy Martin
Member
Member
Posts: 1686
Joined: Fri Apr 18, 2008 4:40 pm
Location: Langley, Vancouver, BC, Canada
Contact:

Re: Make 32 Bit Kernel

Post by Troy Martin »

JamesM wrote:There is a mode where you can run 32-bit code without protected mode. It's called "unreal mode" - there should be a wiki article on it.
Umm, last time I checked, unreal mode was just a register trick to use the GDT's selectors in real mode.
Image
Image
Solar wrote:It keeps stunning me how friendly we - as a community - are towards people who start programming "their first OS" who don't even have a solid understanding of pointers, their compiler, or how a OS is structured.
I wish I could add more tex
User avatar
JamesM
Member
Member
Posts: 2935
Joined: Tue Jul 10, 2007 5:27 am
Location: York, United Kingdom
Contact:

Re: Make 32 Bit Kernel

Post by JamesM »

Troy Martin wrote:
JamesM wrote:There is a mode where you can run 32-bit code without protected mode. It's called "unreal mode" - there should be a wiki article on it.
Umm, last time I checked, unreal mode was just a register trick to use the GDT's selectors in real mode.
Quite right. Lesson learned - don't post at 00:59 am.
User avatar
kop99
Member
Member
Posts: 120
Joined: Fri May 15, 2009 2:58 am

Re: Make 32 Bit Kernel

Post by kop99 »

Cjreek,
Unless you are going to make the real mode kernel, First thing you have to do is Protected Mode entrance...
Cjreek
Member
Member
Posts: 70
Joined: Thu May 28, 2009 2:41 pm
Location: Germany

Re: Make 32 Bit Kernel

Post by Cjreek »

Hi,
JamesM wrote: Apologies if Combuster sounded a little aggressive - we get people who copy-paste without reading in around the ratio 50-1 with people who actually attempt to understand.
I think this sounds familiar with me :mrgreen: I'm registered in another forum and there it's the same. Many people (mostly new members) "code" their programs using copy&paste :roll:
kop99 wrote:Cjreek,
Unless you are going to make the real mode kernel, First thing you have to do is Protected Mode entrance...
This is what I wanted to hear :)

But prepare... For Sure there will be another noob question soon :twisted: :P
(Of course after reading every possible tutorial :mrgreen: )
Post Reply