flat assembler
Message board for the users of flat assembler.
Index
> OS Construction > Changed: 64-bit VESA minimalistic example [SOLVED] |
Author |
|
Madis731 16 Jun 2010, 12:05
EDIT: Please read the newest post!
CHANGELOG: VESA mode listing added mode selection still static long mode does not support 4KB pages on LFB! (is it always true?) I found myself going through all the tutorials and finding nothing new so I figured I'd post here. I just want to understand RealMode My problem is that I need a very simple bootloader, but after I load my kernel, I do not want to use messy org+offsets and segment overrides. I do want to initialize PIC and APIC and VESA. If you haven't noticed the http://www.brokenthorn.com/Resources/OSDev6.html demo silently replaces org 0x7C00 with org 0 and doesn't explain anywhere why and how. Code: ;---------------------------------------------------- ; code located at 0000:7C00, adjust segment registers ;---------------------------------------------------- cli ; disable interrupts mov ax,0x07C0 ; setup registers to point to our segment mov ds,ax mov es,ax mov fs,ax mov gs,ax If code is located @0:7C00, why wouldn't org 0x7C00 mov ds (es,fs,gs), ax=0 work? =PAUSE= Another problem I have is Stage 2. Code: org 0x10000 ; @ 10000 start: xor ax,ax mov ds,ax mov es,ax mov ax,0x9000 mov ss,ax xor sp,sp 16-bit mode doesn't support over 64KB very well (A20 is enabled). Code: lgdt [gdtr] ;This works fine because the address is given in DWORD What if I tried it the "correct" way Code: org 0 ; or should it be org 0x10000 now? start: mov ax,0x1000 mov ds,ax mov es,ax mov ax,0x9000 mov ss,ax xor sp,sp hmm... Code: lgdt [gdtr] ;This doesn't work because it doesn't offset by 0x10000 ;To make it work I need to do: lgdt [ds:gdtr] ; really messed up - shouln't ds be the default mov di,vesa_info ; If I tried to get the LFB address with an interrupt int 0x10 ; it doesn't return anything useful (=0) ; for that I somehow need to tell int 0x10 what segment to ; use, but I figured that one out myself ; Its ES ; ...or I could go the edi way mov edi,vesa_info+0x10000 ; This works, but is ugly Is there any nice tutorial left on the net or am I chasing ghosts? Last edited by Madis731 on 13 Jul 2010, 12:22; edited 3 times in total |
|||
16 Jun 2010, 12:05 |
|
Madis731 16 Jun 2010, 13:06
Ok, sounds good - I know I can ignore A20, xPIC and focus on the real parts.
If I get home, I will find the source that doesn't work I think the right choice would be: 1) init VESA 2) init GTD/IDT/paging 3) goto PM maybe I'm too lazy to write it a 3-stage loader, but I think it can be done in 2 |
|||
16 Jun 2010, 13:06 |
|
sinsi 16 Jun 2010, 13:38
If A20 is left disabled, you won't be able to access each odd MB (1-2,3-4 etc.)
|
|||
16 Jun 2010, 13:38 |
|
cod3b453 16 Jun 2010, 17:28
There's no single "correct" org/xs combination, due to the way in which multiple seg:off will map to the same linear address. Personally, I use org 0x7C00, ds/es/ss = 0 since this will save you having to add the correct offsets to labels and can treat address under 0x10000 as if they are linear.
lgdt takes an absolute address by default (ds could cause problems when switching modes). You can simply do A20+VESA, (E820 mem-map), GDT and PM and then do everything else afterwards. |
|||
16 Jun 2010, 17:28 |
|
Tyler 16 Jun 2010, 18:08
Why do you want to make your own boot loader at all? Grub will do all that for you, and you can just use a boot kernel to do all the initing.
Edit: Oh, it's for research reasons, sorry. The two ways of addressing 7c00 are the same, but I'm like cod3b453, I use org 7c00. 7c0:0 = 7c0*10=7c00 0:7c00 = 7c00 |
|||
16 Jun 2010, 18:08 |
|
bitshifter 16 Jun 2010, 21:12
I prefer to boot at 0x0000:0x7c00
That way i can muck with the IVT directly. Also i prefer to load in 16 bit mode and let the kernel go 32 enable a20 etc... This way the same loader can be used for either 16 or 32 bit os. Code: org 0x7c00 use16 jmp 0:start start: mov ax,cs mov ds,ax ... Also gdtr base should be linear address (segment * 16 + offset) Dont forget that demo uses a temp gdt in asm then a new gdt in C. |
|||
16 Jun 2010, 21:12 |
|
Madis731 17 Jun 2010, 07:12
Here's some help on the problem. I've attached the somewhat working version (the 32-bit one) and a new VESA64 folder for which the conversion is still in progress.
The tree is D:\Programs\QEMU\VESA\ or \VESA64\ Bochs needs to be reconfigured if you need to test that. I've done some changes according to your suggestions. Stage1 remained the same, but Stage2 has org 0x10000 in it + segment hints on every possible mem.ref. EDIT2: Ok - the problem was me, of course, as usual the PIC reprogramming had an iretd in it and some writing @B0000 space (BIOS fonts). After these corrections and adding 2MB of pages to 0xE0000000 - everything works Sorry to bother you, guys... <attach deleted, read new posts> Last edited by Madis731 on 13 Jul 2010, 12:23; edited 1 time in total |
|||
17 Jun 2010, 07:12 |
|
Madis731 08 Jul 2010, 14:01
I wonder what might cause a page fault at the offset of 0x140000 on real hardware. It works on QEMU and Bochs.
It should switch to a mode and clear the whole screen Height*Width*BPP with 16-byte MOVDQA-s, but it will pagefault at 0xFB140000 on a Dell D830. It will reboot with some other modes. Really strange. The 640x480 mode works because 640x480x4=1228800 which is less than 0x140000=>1310720 bytes. Any thoughts? <attach deleted, read new posts> Last edited by Madis731 on 13 Jul 2010, 12:23; edited 1 time in total |
|||
08 Jul 2010, 14:01 |
|
egos 09 Jul 2010, 07:42
Madis731 wrote: Another problem I have is Stage 2. EBDA will be destroyed by your code during execution. Madis731 wrote: What if I tried it the "correct" way Code: org 0 ... org 0x10000+$ |
|||
09 Jul 2010, 07:42 |
|
Madis731 13 Jul 2010, 12:39
org back @ 0
64-bit code @0x10000 only 800x600 works "undisturbed" (640x480 okay in Bochs but not QEMU) paging 4KB => 2MB Update2: Fixed to work on real machines (still doesn't work in VMWare) Automatic 800x600x32BPP detection and boot (easily fixed to selectable) Fonts and test.bmp out of the source - also fixed the FAT12 builder (some of the following text is out-of-date) It seems that LFB doesn't like 4KB pages and would rather eat them with bigger bites Now works on real hardware. This demo will first list all 24bpp+ modes that are supported. 24/32 usually cannot be chosen and you get what you get. Just accept that sometimes its 24 and sometimes its not Standard modes are selected with [1], [2], [3] (on your keyboard). There are some exotic ones aswell. Then it will switch to the mode chosen and: 1) render screen white 2) render screen full of 80x80 24-bit grey blobs 3) draw some rectangles 4) move the first one diagonally across the screen until bottom >= screen.y 5) Then you can move your mouse (yellow rectangle) the numbers are RDTSC taken to redraw the mouse. Everything in ring-0 / 64-bit / identity-mappeg 2MB pages - no tasks.
|
|||||||||||||||||||||
13 Jul 2010, 12:39 |
|
Madis731 31 Aug 2010, 09:48
Update3:
This time there have been quite a few changes: - it will always start in 800x600 24bpp mode or fail otherwise * change in Stage2\VESAKR64.asm lines 86 and 91 * it works on QEMU, Bochs and VirtualBox (I use the latter for VT-x) + added some mouse icons to differentiate sides and corners + move windows with your mouse + background BMP is converted to native bitness on startup * performance advantage on slow CPU/emulator and code size reduction Update4: With this update I will only tell that I started logging all my progress in a Features.txt file and you will find everything in there. If there are problems getting it to run, just drop me a line.
|
|||||||||||||||||||||
31 Aug 2010, 09:48 |
|
< Last Thread | Next Thread > |
Forum Rules:
|
Copyright © 1999-2024, Tomasz Grysztar. Also on GitHub, YouTube.
Website powered by rwasa.