flat assembler
Message board for the users of flat assembler.

flat assembler > OS Construction > cpm-86 in 32 bit protected mode to 64 bit real mode

Author
Thread Post new topic Reply to topic
connor



Joined: 07 Jun 2016
Posts: 35
Location: sj ca
USING THE FOLLOWING CODE BELOW, How would i add 64 bit real mode?

Code:
; ; P-MODE Version 0.0 ; Demonstration Of 32-Bit Protected Mode Under 'CP/M-86 For The IBM' ; Freeware from Kirk Lawrence ; ; To assemble: ASM86 P-MODE $ SZ PZ ; GENCMD P-MODE ; cseg ;start of code segment org 100h ;leave room for base page jmp start ;go start the program ; cpu_err db 13,10,'P-MODE Version 0.0' db 13,10,'Freeware from Kirk Lawrence' db 13,10,10,'-> Sorry, a 386 or higher processor is required.' db 13,10,07,'$' vid_adr dw 0B800h cls db 27,'n',27,'E$' bottom db 27,'Y',54,32,27,'m$' msg1 db ' Greetings from Protected Mode! ' msg2 db ' Press any key to return to Real Mode ' ; ; Make sure we have a 386 or higher processor. ; start: pushf ;save flags xor ah,ah ;clear high byte push ax ;push AX onto the stack popf ;pop this value into the flag register pushf ;push flags onto the stack pop ax ;...and get flags into AX and ah,0F0h ;try to set the high nibble cmp ah,0F0h ;the high nibble is never 0F0h on a je no_386 ;80386! mov ah,70h ;now try to set NTIOPL push ax popf pushf pop ax and ah,70h ;if they couldn't be modified, there jz no_386 ;is no 80386 installed popf ;restore the flags ; ; Check for TTL monochrome video. If found, set the appropriate address. ; int 11h ;call BIOS equipment check and ax,30h ;test the return in AX cmp ax,30h ;do we have TTL monochrome video? jne clr_sc ;no, so assume color mov vid_adr,0B000h ;set monochrome video address ; ; Clear the screen. ; clr_sc: mov dx,offset cls ;point DX to 'clear screen' sequence call prt_str ;print it ; ; Set the Extra Segment to the video address. ; mov ax,vid_adr mov es,ax ; ; Enter protected mode. ; cli ;interrupts off db 00Fh, 020h, 0C0h ;mov eax,cr0 db 00Ch, 001h ;or al,1 db 00Fh, 022h, 0C0h ;mov cr0,eax ; ; We're now in protected mode. Print a message to the screen. ; mov bx,1646 ;set screen location in BX mov si,offset msg1 ;point SI to the screen message mov cx,38 ;set counter CX to length of scrn msg mov ah,95 ;screen attribute in AH call put_2_scrn ;go write to video memory ; mov bx,1966 ;set screen location in BX mov si,offset msg2 ;point SI to the screen message mov cx,38 ;set counter CX to length of scrn msg mov ah,14 ;screen attribute in AH call put_2_scrn ;go write to video memory ; ; Wait for user keypress. ; get_key: mov dx,60h in al,dx shl al,1 jc get_key ; ; Return to real mode. ; db 024h, 0FEh ;or al,not 1 db 00Fh, 022h, 0C0h ;mov eax,cr0 sti ;interrupts on ; ; Place the cursor at the bottom of the screen and exit. ; mov dx,offset bottom ;point DX to the positioning sequence call prt_str ;print it exit: xor cx,cx ;function 0 - reset system int 224 ;call BDOS services ; ; Processor error-handling routine. ; no_386: mov dx,offset cpu_err ;point to CPU error message call prt_str ;print it jmp exit ;go exit ; ; Routine to write a text string directly to video memory. ; ; Input: AH = screen attribute ; BX = physical location on the screen ; CX = loop counter value ; SI = start of text string ; put_2_scrn: lodsb ;load a byte of the message into AL mov es: byte ptr [bx],al ;move it to the screen inc bx ;increment BX mov es: byte ptr [bx],ah ;move attribute to the screen inc bx ;increment BX loop put_2_scrn ;repeat if CX > 0 ret ;return ; ; Print string routine. ; prt_str: mov cl,9 ;function 9 - print string int 224 ;call BDOS services ret ;return end
Edit by revolution: Added code tags

_________________
9518741
Post 25 Jun 2018, 03:49
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 15871
Location: 162173 Ryugu
I'm not sure that 64 bit real mode is a thing. In long mode you have to enable paging and set up a page table. The CPU enforces this.
Post 25 Jun 2018, 12:07
View user's profile Send private message Visit poster's website Reply with quote
CandyMan



Joined: 04 Sep 2009
Posts: 269
Location: film "CandyMan" directed through Bernard Rose OR Candy Shop
where you define GDT and IDT?
Post 25 Jun 2018, 17:00
View user's profile Send private message Reply with quote
connor



Joined: 07 Jun 2016
Posts: 35
Location: sj ca
i don't know what a page table, GDT or IDT is

all I want is some ideas and brainstorming.

_________________
9518741
Post 26 Jun 2018, 04:05
View user's profile Send private message Reply with quote
CandyMan



Joined: 04 Sep 2009
Posts: 269
Location: film "CandyMan" directed through Bernard Rose OR Candy Shop
protected mode is not the same like real mode. you must define segment descriptors in Global Descriptor Table (GDT) and interupts and exceptions in Interrupt Descriptor Table (IDT). without it your program will be suspended or a computer will reset. additionally one should check (smsw instruction) whether we are in the real mode or can already in virtual. in long mode a paging is necessary.
that's all it isn't so difficult, a little reading documentation requires.
see also:
https://patater.com/gbaguy/x86asm.htm
http://www.cs.virginia.edu/~evans/cs216/guides/x86.html
https://wiki.osdev.org/GDT_Tutorial
http://prodebug.sourceforge.net/pmtut.html
https://www.codeproject.com/Articles/45788/The-Real-Protected-Long-mode-assembly-tutorial-for
Post 26 Jun 2018, 08:28
View user's profile Send private message Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  


< 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 © 2004-2018, Tomasz Grysztar.

Powered by rwasa.