flat assembler
Message board for the users of flat assembler.
Index
> OS Construction > protected mode |
Author |
|
revolution 24 Dec 2007, 02:03
I think your 'jmp' should be directly after 'mov cr0,eax' without the intervening 'call gate_a20'.
|
|||
24 Dec 2007, 02:03 |
|
dosin 24 Dec 2007, 02:23
Is that the order you have it in your code?
Quote:
try: Code: call gate_a20 ; Activamos Gate A20 xor ax, ax mov ds, ax ; Data segment a cero (es usado por lgdt) lgdt [gdt_desc] ; Cargamos la gdt mov eax, cr0 ; Acvtivamos el modo protegido or al,0x1 ; setiando el primer bit del mov cr0,eax ; registro cr0 a 1. jmp 08:..... |
|||
24 Dec 2007, 02:23 |
|
Dex4u 24 Dec 2007, 05:42
phreak wrote: PD: Someone can explain me why 0x08 ? The 8h is your code segment descriptor (look up GDT ) once you made the jump you need to put valid protected-mode selectors in the DS and SS registers eg: Code: use32modo_protegido: mov ax,0x10 mov ds,ax mov es,ax mov ss,ax mov esp,0x7C00 Note 0x10 = data segment descriptor Here a simple example Code: ;************************************; Basic go to Pmode demo, by Dex; Assemble with fasm; c:\fasm test.asm test.bin;************************************org 0x7C00use16;****************************; Realmode startup code.;****************************start: xor ax,ax mov ds,ax mov es,ax mov ss,ax mov sp,0x7C00;*****************************; Setting up, to enter pmode.;***************************** cli lgdt [gdtr] mov eax, cr0 or al,0x1 mov cr0,eax jmp 0x8: protected;*****************************; Pmode. ;*****************************use32protected: mov ax,0x10 mov ds,ax mov es,ax mov ss,ax mov esp,0x7C00;*****************************; Turn floppy off .;***************************** mov dx,3F2h mov al,0 out dx,al mov byte [es:0xB8000], "P" jmp $;*************************************; GDT.;*************************************gdt: dw 0x0000, 0x0000, 0x0000, 0x0000 ; (0h)sys_code: dw 0xFFFF, 0x0000, 0x9800, 0x00CF ;code segment descriptor (8h)sys_data: dw 0xFFFF, 0x0000, 0x9200, 0x00CF ;data segment descriptor (10h)gdt_end:gdtr: dw gdt_end - gdt - 1 dd gdt;*************************************; Make program 510 byte's + 0xaa55;*************************************times 510- ($-start) db 0dw 0xaa55 If it prints a P in the top left hand corner, your in Pmode. |
|||
24 Dec 2007, 05:42 |
|
phreak 24 Dec 2007, 13:09
Thanks, but it still working only if I do it in the boot loader
|
|||
24 Dec 2007, 13:09 |
|
Mac2004 24 Dec 2007, 15:04
phreak: Maybe my boot loader example helps you a bit?. It loads a secondary binary file and executes it.
It should be easy to convert to act as PM loader. http://board.flatassembler.net/topic.php?t=6529 regards, Mac2004 |
|||
24 Dec 2007, 15:04 |
|
edfed 24 Dec 2007, 15:25
exactlly what you need...
like bios loads the bootloader at segment:7C00h, you need to make a fixed segment system... don't forget to assume ds=cs while boot like loading the second stage boot... ones you have a fixed and exact location for code and datas, you can easy manage them, and set the good GDT... the big problem in your code is that ds is set to zero, but in fct ds must be equal to cs, while cs is the segment for code and data in BOOT loader, the one who is at 7C00h... after the cli, ds=cs or ds=data, depend on your bootloader... then, Code: org 7C00h load 2ndstage at 1000h load data at 2000h mov ds,0 jmp 0:codesegment .... align 512 org 1000h codesegment: ; here is the cs segment cli lgdt [gdt]; gdt is a symbol in ds... 'or cr0,1' jmp 8:entry entry: mov ax,10h mov ds,ax mov es,ax mov fs,ax mov gs,ax mov ss,ax ;now all segments are defined from the gdt align 512 org 2000h datasegment: ;here is ds segment dw 0 gdt: dw @f-.null-1 dd .null .null dq 0 .flatcode dw ?,?,?,? .flatdata dw ?,?,?,? @@: |
|||
24 Dec 2007, 15:25 |
|
< Last Thread | Next Thread > |
Forum Rules:
|
Copyright © 1999-2024, Tomasz Grysztar. Also on GitHub, YouTube.
Website powered by rwasa.