flat assembler
Message board for the users of flat assembler.

Index > OS Construction > Int 13h?

Goto page 1, 2, 3  Next
Author
Thread Post new topic Reply to topic
rhyno_dagreat



Joined: 31 Jul 2006
Posts: 487
Location: Maryland, Unol Daleithiau
rhyno_dagreat 25 Oct 2007, 23:49
Hey,

I was coding an OS for a class project, and I figured out about protected mode (thanks to Dex4u and ManOfSteel), and I got everything working inside of a single bootsector! Very HappyVery HappyVery Happy

However, I tried going outside of the bootsector and the computer would reset and reset and reset... And it drove me nuts until I realized: I need to load those other sectors into memory! So I plan to do that using Int 13h function 02h.

First I will start up in real mode like normal, except in the bootsector I will load the next few sectors into memory. And then in my second sector I will set up the GDT. But I must wonder... is there anything in particular I must do differently if I'm to set up the GDT and switch to 32-bit mode in the second sector rather than the bootsector?
Post 25 Oct 2007, 23:49
View user's profile Send private message Reply with quote
edfed



Joined: 20 Feb 2006
Posts: 4353
Location: Now
edfed 26 Oct 2007, 00:32
nothing different (in theory)

kernel is the code_segment_selector ( 08 )
entry is the linear offset corresponding on the second's sectors loaded for kernel


Code:
mov bx,k.offset
mov es,k.segment
;k.entry = es*16+bx+offset
mov eax,nextsector
dword_to_disk
mov ah,2
mov al,128 ;equivalent to a full real mode segment 64Kbytes
int 13h
lgdt [es:tmpgdt]
mov eax,cr0
or eax,pmbit
mov cr0,eax
jmp kernel_selector:kernel.entry
...
dw 0aa55h

org 0
idt:
...
gdt:
null_selector:
dq 0
kernel_selector:
db 0FFh, 0FFh, 00h, 00h, 00h, 10011010b, 11001111b, 00h ; CODE 
data_selector:
db 0FFh, 0FFh, 00h, 00h, 00h, 10010010b, 11001111b, 00h ; DATA  
.end:
ldt:
...

tmpgdt dw gdt.end-gdt-1
dd gdt

kernel:
.entry:
;kernel code is here
...
    


something like that!
Post 26 Oct 2007, 00:32
View user's profile Send private message Visit poster's website Reply with quote
rhyno_dagreat



Joined: 31 Jul 2006
Posts: 487
Location: Maryland, Unol Daleithiau
rhyno_dagreat 26 Oct 2007, 00:39
Thanks!
Post 26 Oct 2007, 00:39
View user's profile Send private message Reply with quote
edfed



Joined: 20 Feb 2006
Posts: 4353
Location: Now
edfed 26 Oct 2007, 00:43
tell me if it works
i'am too lazy to try
i have some motivation problems

i seek the young madness of the scientist
but it's hard to do
too much time to read the manuals
and now the result is : i am fed up
Post 26 Oct 2007, 00:43
View user's profile Send private message Visit poster's website Reply with quote
rhyno_dagreat



Joined: 31 Jul 2006
Posts: 487
Location: Maryland, Unol Daleithiau
rhyno_dagreat 26 Oct 2007, 00:46
Fed up with what, if you don't mind my asking?
Post 26 Oct 2007, 00:46
View user's profile Send private message Reply with quote
rhyno_dagreat



Joined: 31 Jul 2006
Posts: 487
Location: Maryland, Unol Daleithiau
rhyno_dagreat 26 Oct 2007, 00:49
And... is the Kernel Segment in your code the same as the Kernel selector?

Scrap that. Didn't look further down, sorry.
Post 26 Oct 2007, 00:49
View user's profile Send private message Reply with quote
edfed



Joined: 20 Feb 2006
Posts: 4353
Location: Now
edfed 26 Oct 2007, 00:51
fed up with boot writing, restart kernel, minding about the best use of mmu

all these technical things have broke my head
to make a simple kernel, this method is ok
but for a very complex and modular, evolutive boot it is very different

and my head is like a teapot now

take a look on my several posts you'll see how is my teapot now Wink
Post 26 Oct 2007, 00:51
View user's profile Send private message Visit poster's website Reply with quote
rhyno_dagreat



Joined: 31 Jul 2006
Posts: 487
Location: Maryland, Unol Daleithiau
rhyno_dagreat 26 Oct 2007, 00:55
LOL
Post 26 Oct 2007, 00:55
View user's profile Send private message Reply with quote
rhyno_dagreat



Joined: 31 Jul 2006
Posts: 487
Location: Maryland, Unol Daleithiau
rhyno_dagreat 26 Oct 2007, 01:00
Arrrggghhh... This is driving me nuts!

It keeps rebooting and is going above the size I had set at the bottom. Any help would be greatly appreciated... not just code fixing but explaination, as I would like to understand what's going on.

Code:
org 7C00h
jmp Start

; Data Goes Here
  TxtClr db 2
  WelcomeStr db "Welcome to TR2-DOS!",0

  gdt:
  db 00h, 00h, 00h, 00h, 00h, 00h, 00h, 00h ; NULL SEGMENT
  db 0FFh, 0FFh, 00h, 00h, 00h, 10011010b, 11001111b, 00h ; CODE SEGMENT
  db 0FFh, 0FFh, 00h, 00h, 00h, 10010010b, 11001111b, 00h ; DATA SEGMENT
  gdt_end:

  ;Global Descriptor Table Descriptor is set up as follows:
  ; -------------------------
  ;| DESCRIPTION  |  SIZE    |
  ;|------------------------ |
  ;| SIZE         |  WORD    |
  ;| TABLE        |  DWORD   |
  ; -------------------------
  gdt_desc: dw gdt_end - gdt - 1
            dd gdt
; Data Ends Here

Start:
xor ax, ax
mov ds, ax
mov ss, ax
mov sp, 9C00h

; Set up VESA text mode 10Ch (132x60)
mov ax, 4F02h
mov bx, 10Ch
int 10h

; Clear interrupts for move to 32-bit mode
cli

mov ax, 0060h
mov es, ax

;Load Global Descriptor Table (GDT) Register
lgdt [es:gdt_desc]

;Set up control register to get into Protected Mode
mov eax, cr0
or al, 1
mov cr0, eax

;Do far jump to first (filled in) selector - the code selector.
jmp 8h:Start32

; ORIGNALLY 32 BIT CODE WENT HERE

times 510-($-$$) db 0
dw 0AA55h

org 0000h

; Welcome to the world of 32-Bit mode! =-D
Start32:
use32
; Start off by setting the data segment to the data selector.
xor bx, bx
mov bx, 10h
mov ds, bx
mov ss, bx

; Move video memory into EBX
;mov eax, 0B8000h

; Load a smiley into video memory!
;mov bx, 0201h
;mov word [ds:eax], bx

; Print Welcome Message
mov si, WelcomeStr
call PrintF

Hang:
jmp Hang

PrintF:
push ebx
push eax
mov ebx, 0B8000h
PutCh:
lodsb
cmp al, 0
je Done
mov ah, [TxtClr]
mov word [ds:ebx], ax
add bx, 2
jmp PutCh

Done:
pop eax
pop ebx
ret

times 1474560-($-$$) db 0
    
Post 26 Oct 2007, 01:00
View user's profile Send private message Reply with quote
edfed



Joined: 20 Feb 2006
Posts: 4353
Location: Now
edfed 26 Oct 2007, 01:01
don't forget the org 0 just after the boot sector end (0aa55h)
idt: is a code that must hold the new idt table
the interrupt codes must be loaded and well pointed
ldt: is optional
gdt: needs to grow in case of new segment alocation
for exemple 0A0000h screen 13h
can be a protected segment

and many other things that are really boilling my brain

but i love it

Code:
                oo
               o  o
                oo            oo
  ooo      oooooooooooo      oo
  o  o  ooo            ooo  ooo
  o   oo                  oooo
  o  oo                   ooo
   oooo                  oo
      oo                oo
       ooooooooooooooooooo      

    
Post 26 Oct 2007, 01:01
View user's profile Send private message Visit poster's website Reply with quote
edfed



Joined: 20 Feb 2006
Posts: 4353
Location: Now
edfed 26 Oct 2007, 01:09
here (your code) es is a real mode segment
mov es,60h will acces to memory @ 600h linear

boot sector is @ segment:7c00h
so it is normal that your lgdt don't work

don't forget that
everything in the memory have a unique linear address
address translation result depend on the segments, segment selectors and pages used

to translate a real mode address in a linear offset
linear = segment*16+offset


Last edited by edfed on 26 Oct 2007, 14:06; edited 3 times in total
Post 26 Oct 2007, 01:09
View user's profile Send private message Visit poster's website Reply with quote
rhyno_dagreat



Joined: 31 Jul 2006
Posts: 487
Location: Maryland, Unol Daleithiau
rhyno_dagreat 26 Oct 2007, 01:22
Okay... I am still somewhat lost. I have the org 0000h after the boot signature, which I changed to org 0600h because that's where I'm supposed to jump to, right?
Post 26 Oct 2007, 01:22
View user's profile Send private message Reply with quote
rhyno_dagreat



Joined: 31 Jul 2006
Posts: 487
Location: Maryland, Unol Daleithiau
rhyno_dagreat 26 Oct 2007, 01:24
Every time I try it in BOCHs, it said it can't read the bootdisk.
Post 26 Oct 2007, 01:24
View user's profile Send private message Reply with quote
edfed



Joined: 20 Feb 2006
Posts: 4353
Location: Now
edfed 26 Oct 2007, 01:26
try it in real boot!
or with virtual pc
virtual pc is a little easier to use;-)
Post 26 Oct 2007, 01:26
View user's profile Send private message Visit poster's website Reply with quote
rhyno_dagreat



Joined: 31 Jul 2006
Posts: 487
Location: Maryland, Unol Daleithiau
rhyno_dagreat 26 Oct 2007, 02:05
Tried it and it still doesn't work. Here's the newly modified code:

Code:
org 7C00h

BootStart:
xor ax, ax
mov ds, ax
mov ss, ax
mov sp, 9C00h

; Set up VESA text mode 10Ch (132x60)
mov ax, 4F02h
mov bx, 10Ch
int 10h

mov ax, 0060h
mov es, ax
xor bx, bx
mov ah, 02h
mov al, 04h
mov cl, 01h
mov ch, 00h
mov dh, 00h
int 13h
jmp 0060:0000h

times 510-($-$$) db 0
dw 0AA55h

org 0600h
jmp Start

; Data Goes Here
  TxtClr db 2
  WelcomeStr db "Welcome to TR2-DOS!",0

  gdt:
  db 00h, 00h, 00h, 00h, 00h, 00h, 00h, 00h ; NULL SEGMENT
  db 0FFh, 0FFh, 00h, 00h, 00h, 10011010b, 11001111b, 00h ; CODE SEGMENT
  db 0FFh, 0FFh, 00h, 00h, 00h, 10010010b, 11001111b, 00h ; DATA SEGMENT
  gdt_end:

  ;Global Descriptor Table Descriptor is set up as follows:
  ; -------------------------
  ;| DESCRIPTION  |  SIZE    |
  ;|------------------------ |
  ;| SIZE         |  WORD    |
  ;| TABLE        |  DWORD   |
  ; -------------------------
  gdt_desc: dw gdt_end - gdt - 1
            dd gdt
; Data Ends Here

Start:
xor ax, ax
mov ds, ax
mov ss, ax

; Clear interrupts for move to 32-bit mode
cli

;Load Global Descriptor Table (GDT) Register
lgdt [es:gdt_desc]

;Set up control register to get into Protected Mode
mov eax, cr0
or al, 1
mov cr0, eax

;Do far jump to first (filled in) selector - the code selector.
jmp 8h:Start32

; Welcome to the world of 32-Bit mode! =-D
Start32:
use32
; Start off by setting the data segment to the data selector.
xor bx, bx
mov bx, 10h
mov ds, bx
mov ss, bx

; Move video memory into EBX
;mov eax, 0B8000h

; Load a smiley into video memory!
;mov bx, 0201h
;mov word [ds:eax], bx

; Print Welcome Message
mov si, WelcomeStr
call PrintF

Hang:
jmp Hang

PrintF:
push ebx
push eax
mov ebx, 0B8000h
PutCh:
lodsb
cmp al, 0
je Done
mov ah, [TxtClr]
mov word [ds:ebx], ax
add bx, 2
jmp PutCh

Done:
pop eax
pop ebx
ret

times 1474560-512-($-$$) db 0
    
Post 26 Oct 2007, 02:05
View user's profile Send private message Reply with quote
edfed



Joined: 20 Feb 2006
Posts: 4353
Location: Now
edfed 26 Oct 2007, 02:19
jmp 60h:0h

if not 60h then it is a decimal number
60=3Ch
Post 26 Oct 2007, 02:19
View user's profile Send private message Visit poster's website Reply with quote
vid
Verbosity in development


Joined: 05 Sep 2003
Posts: 7105
Location: Slovakia
vid 26 Oct 2007, 02:29
rhyno: You are jumping to 60h:0. That means it WILL jump to your code, but CS will be 60h and IP will be 0.

But "org 600h" maked offsets starting from 600h. So fol Example "mov al, [TextClr]" would assemble to "mov al, [600h]", etc... Since CS is already 60, then CS:[0] is linear addreas 600h, not CS:[600h].

Either use "org 0" or "jmp 0:600h"
Post 26 Oct 2007, 02:29
View user's profile Send private message Visit poster's website AIM Address MSN Messenger ICQ Number Reply with quote
rhyno_dagreat



Joined: 31 Jul 2006
Posts: 487
Location: Maryland, Unol Daleithiau
rhyno_dagreat 26 Oct 2007, 02:39
I've got it partially working: It's jumping (I have it set so a smiley face comes up after jump), but it keeps restarting itself still.

Here's the code:

Code:
org 7C00h

BootStart:
xor ax, ax
mov ds, ax
mov ss, ax
mov sp, 9C00h

; Set up VESA text mode 10Ch (132x60)
mov ax, 4F02h
mov bx, 10Ch
int 10h

mov ax, 0060h
mov es, ax
xor bx, bx
mov ah, 02h
mov al, 04h
mov cl, 02h
mov ch, 00h
mov dh, 00h
int 13h
jmp 0060h:0000h

times 510-($-$$) db 0
dw 0AA55h

org 0000h
mov ax, 0060h
mov ds, ax
mov ss, ax
mov ax, 0B800h
mov es, ax
mov bx, 0000h
mov word [es:bx], 0201h
jmp Start

; Data Goes Here
  TxtClr db 2
  WelcomeStr db "Welcome to TR2-DOS!",0

  gdt:
  db 00h, 00h, 00h, 00h, 00h, 00h, 00h, 00h ; NULL SEGMENT
  db 0FFh, 0FFh, 00h, 00h, 00h, 10011010b, 11001111b, 00h ; CODE SEGMENT
  db 0FFh, 0FFh, 00h, 00h, 00h, 10010010b, 11001111b, 00h ; DATA SEGMENT
  gdt_end:

  ;Global Descriptor Table Descriptor is set up as follows:
  ; -------------------------
  ;| DESCRIPTION  |  SIZE    |
  ;|------------------------ |
  ;| SIZE         |  WORD    |
  ;| TABLE        |  DWORD   |
  ; -------------------------
  gdt_desc: dw gdt_end - gdt - 1
            dd gdt
; Data Ends Here

Start:

; Clear interrupts for move to 32-bit mode
cli

;Load Global Descriptor Table (GDT) Register
lgdt [es:gdt_desc]

;Set up control register to get into Protected Mode
mov eax, cr0
or al, 1
mov cr0, eax

;Do far jump to first (filled in) selector - the code selector.
jmp 8h:Start32

; Welcome to the world of 32-Bit mode! =-D
Start32:
use32
; Start off by setting the data segment to the data selector.
xor bx, bx
mov bx, 10h
mov ds, bx
mov ss, bx

; Move video memory into EBX
;mov eax, 0B8000h

; Load a smiley into video memory!
;mov bx, 0201h
;mov word [ds:eax], bx

; Print Welcome Message
mov si, WelcomeStr
call PrintF

Hang:
jmp Hang

PrintF:
push ebx
push eax
mov ebx, 0B8000h
PutCh:
lodsb
cmp al, 0
je Done
mov ah, [TxtClr]
mov word [ds:ebx], ax
add bx, 2
jmp PutCh

Done:
pop eax
pop ebx
ret

times 512-($-$$) db 0
times 1474560-512-($-$$) db 0
    
Post 26 Oct 2007, 02:39
View user's profile Send private message Reply with quote
vid
Verbosity in development


Joined: 05 Sep 2003
Posts: 7105
Location: Slovakia
vid 26 Oct 2007, 02:58
move smily face behind "start" to see if "jmp start" works okay.
Post 26 Oct 2007, 02:58
View user's profile Send private message Visit poster's website AIM Address MSN Messenger ICQ Number Reply with quote
rhyno_dagreat



Joined: 31 Jul 2006
Posts: 487
Location: Maryland, Unol Daleithiau
rhyno_dagreat 26 Oct 2007, 03:02
I did, and it's still not working. I think it's when I make the jump to 32 bit mode that it's rebooting. Here's the current code:

Code:
org 7C00h

BootStart:
xor ax, ax
mov ds, ax
mov ss, ax
mov sp, 9C00h

; Set up VESA text mode 10Ch (132x60)
mov ax, 4F02h
mov bx, 10Ch
int 10h

mov ax, 0060h
mov es, ax
xor bx, bx
mov ah, 02h
mov al, 04h
mov cl, 02h
mov ch, 00h
mov dh, 00h
int 13h
jmp 0060h:0000h

times 510-($-$$) db 0
dw 0AA55h

org 0000h
mov ax, 0060h
mov ds, ax
mov ss, ax
jmp Start

; Data Goes Here
  TxtClr db 2
  WelcomeStr db "Welcome to TR2-DOS!",0

  gdt:
  db 00h, 00h, 00h, 00h, 00h, 00h, 00h, 00h ; NULL SEGMENT
  db 0FFh, 0FFh, 00h, 00h, 00h, 10011010b, 11001111b, 00h ; CODE SEGMENT
  db 0FFh, 0FFh, 00h, 00h, 00h, 10010010b, 11001111b, 00h ; DATA SEGMENT
  gdt_end:

  ;Global Descriptor Table Descriptor is set up as follows:
  ; -------------------------
  ;| DESCRIPTION  |  SIZE    |
  ;|------------------------ |
  ;| SIZE         |  WORD    |
  ;| TABLE        |  DWORD   |
  ; -------------------------
  gdt_desc: dw gdt_end - gdt - 1
            dd gdt
; Data Ends Here

Start:

; Clear interrupts for move to 32-bit mode
cli

;Load Global Descriptor Table (GDT) Register
lgdt [ds:gdt_desc]

;Set up control register to get into Protected Mode
mov eax, cr0
or al, 1
mov cr0, eax

;Do far jump to first (filled in) selector - the code selector.
jmp 8h:Start32

; Welcome to the world of 32-Bit mode! =-D
Start32:
use32
; Start off by setting the data segment to the data selector.
xor bx, bx
mov bx, 10h
mov ds, bx
mov ss, bx
mov esp, 90000h

; Move video memory into EBX
;mov eax, 0B8000h

; Load a smiley into video memory!
;mov bx, 0201h
;mov word [ds:eax], bx

; Print Welcome Message
mov si, WelcomeStr
call PrintF

Hang:
jmp Hang

PrintF:
push ebx
push eax
mov ebx, 0B8000h
PutCh:
lodsb
cmp al, 0
je Done
mov ah, [TxtClr]
mov word [ds:ebx], ax
add bx, 2
jmp PutCh

Done:
pop eax
pop ebx
ret

times 512-($-$$) db 0
times 1474560-512-($-$$) db 0
    
Post 26 Oct 2007, 03:02
View user's profile Send private message Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  
Goto page 1, 2, 3  Next

< Last Thread | Next Thread >
Forum Rules:
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Copyright © 1999-2024, Tomasz Grysztar. Also on GitHub, YouTube.

Website powered by rwasa.