flat assembler
Message board for the users of flat assembler.
Index
> OS Construction > switching into protected mode |
Author |
|
Fulgurance 25 Feb 2020, 07:30
Hello ! Can you post your assembly code to help you to understand more ?
Have you read OSDev example ? It's very explained good. https://wiki.osdev.org/Protected_Mode And look my past post, i have posted questions and code about switching to protected mode. |
|||
25 Feb 2020, 07:30 |
|
connor 26 Feb 2020, 04:21
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 _________________ cars tech weed bitches country & thug life |
|||
26 Feb 2020, 04:21 |
|
revolution 26 Feb 2020, 04:33
What system is that designed for? Int 224 is not normal for an x86 BIOS.
Also, why all the dbs? fasm can assemble the opcodes for you, no need to manually do it. |
|||
26 Feb 2020, 04:33 |
|
connor 27 Feb 2020, 05:57
int 224 same as int 0e0h
is the interupt for the kernal system, which for some reason is called BDOS Has no support for anything cool. so it wont surprise me if i am the only one actively coding nativley for this fossilized trolobyte. _________________ cars tech weed bitches country & thug life |
|||
27 Feb 2020, 05:57 |
|
edfed 29 Mar 2020, 01:49
here a very light version of pm switch
Code: format binary as "img" ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;boot and protected mode switch ; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; org 7C00h ; where the binary should be loaded in ram boot: ; boot = 7c00h (org) cli ; disable interrupts lgdt fword[cs:gdt.size] ; load the gdt from [cs:gdt] 6 bytes pseudo descriptor mov eax,cr0 ; equivalent to "or cr0,1" or al,1 ; switches the CPU in protected mode- mov cr0,eax ; protected mode enable jmp gdt.code:.pmode ; equivalent to "mov cs,gdt.data" + "mov ip,.pmode" .pmode: ; the first instruction right after pm enable use32 ; code below is 32 bits mov ax,gdt.data ; mov ds,ax ; make ds = .data entry in gdt, flat linear adress space call os ; jmp $ ; infinite loop ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; gdt: dw 0 ; in order to align dword part of pseudo desciptor on dword boundary .size dw @f-gdt-1 ; word part of pseudo desciptor, size of gdt in bytes .linear dd gdt ; dword part of pseudo descriptor, linear base adress .code=$-gdt ; first entry in gdt (8*1) dw -1,0 ; 4Gbytes, start at linear 0 db 0,9ah,0cfh,0 ; granularity = 64Kbytes, code segment, ring 0, read only,etc... .data=$-gdt ; second entry in gdt (8*2) dw -1,0 ; 4Gbytes, start at linear 0 db 0,92h,0cfh,0 ; granularity = 64Kbytes, data segment, ring 0, read/write,etc... @@: ; used for gdt.size calculation ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; os: ; mov dword[0b8000h],0b64bb64fh ret ; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; free = 510-(padding-$$) ; define "free" bytes count padding rb free ; reserve "free" bytes to make line below at offset 510 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; dw 0aa55h ; magic number boot mark, used by bios to test if valid boot sector ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; d1='0'+free shr 8 and 0fh ; d2='0'+free shr 4 and 0fh ; d3='0'+free and 0fh ; if d1>'9' ; d1=d1+7 ; end if ; ; if d2>'9' ; d2=d2+7 ; end if ; ; if d3>'9' ; d3=d3+7 ; end if ; ; display d1,d2,d3,'h ' ; display 'free bytes',13,10 ; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; d1='0'+(510-free)shr 8 and 0fh ; d2='0'+(510-free)shr 4 and 0fh ; d3='0'+(510-free)and 0fh ; if d1>'9' ; d1=d1+7 ; end if ; ; if d2>'9' ; d2=d2+7 ; end if ; ; if d3>'9' ; d3=d3+7 ; end if ; ; display d1,d2,d3,'h ' ; display 'used bytes',13,10 ; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
|||
29 Mar 2020, 01:49 |
|
connor 09 Apr 2020, 03:17
hmm
one small problem the operating system and its development tools work only in 16 bit and im learning how to code in the most unforgiving way possible its beyond my band width
_________________ cars tech weed bitches country & thug life |
|||||||||||
09 Apr 2020, 03:17 |
|
Kek 30 Jun 2020, 11:49
Why are you writing protected mode code for CP/M-86, which only was ever designed to run on an 8088/8086? Your code won't get very far on a 16-bit only operating system.
|
|||
30 Jun 2020, 11:49 |
|
connor 01 Jul 2020, 15:54
Thanks Mr. Obvious,
I do what I want. _________________ cars tech weed bitches country & thug life |
|||
01 Jul 2020, 15:54 |
|
< Last Thread | Next Thread > |
Forum Rules:
|
Copyright © 1999-2024, Tomasz Grysztar. Also on GitHub, YouTube.
Website powered by rwasa.