flat assembler
Message board for the users of flat assembler.
Index
> OS Construction > Entering long mode - simple examples Goto page Previous 1, 2 |
Author |
|
Adam Kachwalla 09 Jul 2007, 11:26
In the code below, why are the offsets multiplied by 16 and not 8? Aren't the address locations for the IRQ handlers supposed to be 64-bit (8 byte) values?
Code: MK_IGATES: ;MAKE INTERRUPT GATES (Gates for other interrupts) MOV ESI,IGATE MOVSQ MOVSQ LOOP MK_IGATES MOV WORD [0x80*16],CLOCK ;Set IRQ 0 Handler MOV WORD [0x81*16],KEYBOARD ;Set IRQ 1 Handler LIDT [IDTR] ;Load IDT Register STI ;Now we may enable the interrupts |
|||
09 Jul 2007, 11:26 |
|
Dr. Mario 17 Nov 2007, 17:24
I have tried running it in MS-DOS 7.1 - guess what?
It just freezes. I also have tried it on Windows ME disk - froze like a popsicile. Anything? _________________ Mama-mia, tha' the Athlon 64, Peach! |
|||
17 Nov 2007, 17:24 |
|
vid 17 Nov 2007, 18:59
didn't you happen to try it inside NTVDM emulator (under windows) ?
|
|||
17 Nov 2007, 18:59 |
|
LocoDelAssembly 24 Jan 2009, 18:49
Code: GDTR: ; Global Descriptors Table Register dw 4*8-1 ; limit of GDT (size minus one) dq GDT ; linear address of GDT Is it possible that the "dq" is unneeded? Since the LGDT instruction is executed in real-mode with operand size override, shouldn't the processor just load up to 6 bytes instead of 10? |
|||
24 Jan 2009, 18:49 |
|
jim3001 14 Aug 2013, 10:47
I want to know if accessing memory over 4GB(Ex. access the physical memory address 0x100001000 ) is ok in long mode ?
Ex. mov eax, 5A5A5A5Ah mov [100001000h],eax Is it ok ? |
|||
14 Aug 2013, 10:47 |
|
baldr 14 Aug 2013, 16:37
jim3001,
Why not? 0xA3 opcode in 64-bit mode uses 64-bit moffs32 (immediate absolute address, though 32 suffix may be misleading). When in doubt, RTFM (both manuals explicitly state that fact). If you want to force 64-bit immediate address, use mov [qword addr], eax (otherwise fasm may choose shorter rip-relative encoding for that instruction). Gravedigging? |
|||
14 Aug 2013, 16:37 |
|
Feryno 15 Aug 2013, 05:10
Hi jim3001
before writing somewhere under long mode ensure that the memory is present in translation tables (whether it is mapped, else you raise pagefault exception). You can't write into RAM directly under long mode, you must create entries in translation tables and then write into virtual memory. |
|||
15 Aug 2013, 05:10 |
|
spandexyfronts 07 Oct 2013, 03:44
Many thanks for such a clear example.
I appended your code to some mbr code, compiled, burnt to usb drive and the whole lot worked first time! |
|||
07 Oct 2013, 03:44 |
|
sid123 23 Oct 2013, 14:59
Adam Kachwalla wrote: Hang on a sec... Where's the instruction that actually prints the text? I cannot get it to work under QEMU. It hangs where it is (nothing is printed). Are you using QEMU x86-64? _________________ "Those who can make you believe in absurdities can make you commit atrocities" -- Voltaire https://github.com/Benderx2/R3X XD |
|||
23 Oct 2013, 14:59 |
|
c.j.gowett 16 Jan 2014, 21:03
If you are in 32-bit mode or 64-bit mode, the memory range for video memory is at 0xC0000000 and goes to 0xCFFFFFFF, at least for my video card on my laptop and main computer. If you want to know ALL video ranges for your computer, go to device manager in Windows, go to your video card and right-click on it for properties, then go to the resources tab. It will list all the memory ranges for your video card. All you have to do is write to the video memory (fill the screen) with:
Code: ; 32-bit mode ; when in interrupt mode (16-bit): ; mov ax,4F02h ; mov bx,105h ; int 10h ; this video mode is 1024x768x256 ; graphics mode mov ebx,0xC0000000 fill: mov byte [ebx],42 ;color orange inc ebx cmp ebx,0xC00C0000 jge eFill jmp fill eFill: ; done Code: ; 64-bit mode ; when in interrupt mode (16-bit): ; mov ax,4F02h ; mov bx,105h ; int 10h ; this video mode is 1024x768x256 ; graphics mode mov rbx,0x00000000C0000000 fill: mov byte [rbx],42 ;color orange inc rbx cmp rbx,0x00000000C00C0000 jge eFill jmp fill eFill: ; done EDIT: This is aside from the 0xA0000 and 0xB8000 video memory ranges. i also fixed little mistakes I had in the sample code above. Last edited by c.j.gowett on 16 Jan 2014, 22:43; edited 4 times in total |
|||
16 Jan 2014, 21:03 |
|
cod3b453 16 Jan 2014, 21:20
The VBE get info function 0x4F00 provides the VRAM size in 64k blocks (up to 4GB) in the info block structure and the get mode info function 0x4F01 will give you the base pointer in the mode info block structure. This is useful because I've seen it at 0xC0..0, 0xD0..0 and 0xE0..0 and knowing the size for long mode page mapping can be handy.
|
|||
16 Jan 2014, 21:20 |
|
BAiC 17 Jan 2014, 08:15
CJ: The memory ranges of devices such as video cards are variable. they can be changed by the OS (and typically change when you change hardware) so don't trust Windows Device Manager data in your OS.
|
|||
17 Jan 2014, 08:15 |
|
c.j.gowett 22 Jan 2014, 16:28
I had a feeling that was the case, because I was wondering what the addresses would be if I had less than 4 GB of memory.
|
|||
22 Jan 2014, 16:28 |
|
Fulgurance 19 Mar 2018, 09:51
Sorry for necropost, but when i test this code to enter on 64 bits mode on floppy.img on virtualbox, i have crash. I have just added 0xAA55 signature for boot on device:
Code: ORG 1600h USE16 cli ; disable the interrupts, just in ; case they are not disabled yet lgdt [cs:GDTR] ; load GDT register mov eax,cr0 ; switch to protected mode or al,1 mov cr0,eax jmp CODE_SELECTOR:pm_start NULL_SELECTOR = 0 DATA_SELECTOR = 1 shl 3 ; flat data selector (ring 0) CODE_SELECTOR = 2 shl 3 ; 32-bit code selector (ring 0) LONG_SELECTOR = 3 shl 3 ; 64-bit code selector (ring 0) GDTR: ; Global Descriptors Table Register dw 4*8-1 ; limit of GDT (size minus one) dq GDT ; linear address of GDT GDT rw 4 ; null desciptor dw 0FFFFh,0,9200h,08Fh ; flat data desciptor dw 0FFFFh,0,9A00h,0CFh ; 32-bit code desciptor dw 0FFFFh,0,9A00h,0AFh ; 64-bit code desciptor USE32 pm_start: mov eax,DATA_SELECTOR ; load 4 GB data descriptor mov ds,ax ; to all data segment registers mov es,ax mov fs,ax mov gs,ax mov ss,ax mov eax,cr4 or eax,1 shl 5 mov cr4,eax ; enable physical-address extensions mov edi,70000h mov ecx,4000h shr 2 xor eax,eax rep stosd ; clear the page tables mov dword [70000h],71000h + 111b ; first PDP table mov dword [71000h],72000h + 111b ; first page directory mov dword [72000h],73000h + 111b ; first page table mov edi,73000h ; address of first page table mov eax,0 + 111b mov ecx,256 ; number of pages to map (1 MB) make_page_entries: stosd add edi,4 add eax,1000h loop make_page_entries mov eax,70000h mov cr3,eax ; load page-map level-4 base mov ecx,0C0000080h ; EFER MSR rdmsr or eax,1 shl 8 ; enable long mode wrmsr mov eax,cr0 or eax,1 shl 31 mov cr0,eax ; enable paging jmp LONG_SELECTOR:long_start USE64 long_start: mov rax,'L O N G ' mov [0B8000h],rax jmp long_start db 510-($-$$) dup 0x90 dw 0xAA55 Why ? |
|||
19 Mar 2018, 09:51 |
|
revolution 19 Mar 2018, 10:00
That code wasn't intended to be a boot sector.
You might need to use org 0x7c00 or similar. |
|||
19 Mar 2018, 10:00 |
|
Fulgurance 19 Mar 2018, 10:26
Okay, thanks, it's work
I have little question, why is it necessary to do Code: mov eax,cr0 Code: or al,1 mov cr0,eax Just do that is not sufficient, whatever the value of cr0 ? Code: or al,1 mov cr0,eax Last edited by Fulgurance on 19 Mar 2018, 10:30; edited 1 time in total |
|||
19 Mar 2018, 10:26 |
|
revolution 19 Mar 2018, 10:29
If you only have or al,1 the other bits in eax are not properly defined. They will have whatever was there before.
|
|||
19 Mar 2018, 10:29 |
|
DimonSoft 19 Mar 2018, 10:29
Fulgurance wrote: Okay, thanks, it's work Think about register sizes and initialization. |
|||
19 Mar 2018, 10:29 |
|
Goto page Previous 1, 2 < Last Thread | Next Thread > |
Forum Rules:
|
Copyright © 1999-2024, Tomasz Grysztar. Also on GitHub, YouTube.
Website powered by rwasa.