【问题标题】:VESA not working on BOCHSVESA 不适用于 BOCHS
【发布时间】:2014-12-01 21:29:55
【问题描述】:

我编写了一个简单的引导加载程序,用于设置视频模式并放置一些像素。我已经在 Virtual box、QEMU、Dosbox 和真实硬件上测试过它。对它们很有效,但对 Bochs 无效。模式设置正确,但未绘制像素。

 org 0x7c00

[BITS 16]           ;Tell Assembler to generate 16-bit code

jmp short start         ;Goto start, skip BIOS-Parameter-Block
nop             

;------------BIOS Parameter Block---------------;
;         Needed to recognize the disk      ;
;-----------------------------------------------;
OEMName:        db 'TEST OS '   ;Name of Orignal Equipment Manufacturer
bytesPerSector:     dw 512      ;Number of bytes in each sector
sectPerCluster:     db 1        ;Sectors in one cluster, 1 for FAT12
reservedCluster:    dw 1        ;1 sector is reserved for boot
totalFATs:      db 2        ;There are 2 fats in FAT12 these are copies of each other
rootDirEntries:     dw 224      ;Total entries (files or folders) in root directory
totalSectors:       dw 2880     ;Total Sectors in whole disk
mediaType:      db 0xf0     ;Media type 240 for floppies
sectorsPerFAT:      dw 9        ;Sectors used in on FAT
sectorsPerTrack:    dw 18       ;Sectors in one Track
totalHeads:     dw 2        ;Total sides of disk
hiddenSectors:      dd 0        
hugeSectors:        dd 0
driveNumber:        db 0        ;Drive Number 0 for A:\ floppy
            db 0
signature:      db 41       ;41 for floppies
volumeID:       dd 0        ;Any number
volumeLabel:        db 'TEST OS    ';Any 11-char name
fileSystem:     db 'FAT12   '   ;Type of file system on disk
;------------------------------------------------


;_______________________________________________

gdt:    dd 0x00000000,0x00000000 ;null descriptor
    dd 0x0000ffff,0x00cf9a00 ;code
    dd 0x0000ffff,0x00cf9200

gdtreg: dw 0x17          ;gdt size + 1
    dd 0             ;gdt base (latter filled)

start:
mov ax,0x4f01 ;get vesa mode info
mov cx,0115h ;video mode number
mov di,modeblock
int 0x10
mov esi, [modeblock+0x28] ;save linear frame buffer base = es:di+0x28

mov ax,0x4f02 ;set vesa mode
mov bx,0115h ;video mode number
int 0x10

mov ax,0x2401
int 0x15    ;enable a20 gate

xor eax,eax
mov ax,cs   
shl eax,4
mov [gdt+0x08+2],ax
shr eax,16
mov [gdt+0x20+4],al


xor eax,eax
mov ax,cs
shl eax,4
add eax,gdt
mov [gdtreg+2],eax
lgdt[gdtreg]

mov eax,cr0
or eax,1

cli
mov cr0,eax
jmp 0x08:pstart

[bits 32]
pstart:
mov eax,0x10
mov es,ax
mov ds,ax
mov fs,ax
mov ss,ax
mov gs,ax


cls:
mov eax,0xffffffff
mov edi, esi
mov ecx,1024*768*1/2
cld
rep stosd

;************ THIS PART IS NOT WORKING ON BOCHS. ************
main:
;test code
mov edi,esi 

mov byte[edi],0x00
inc edi
mov byte[edi],0x00
inc edi
mov byte[edi],0xff
inc edi
mov byte[edi],0x00
inc edi

mov byte[edi],0x00
inc edi
mov byte[edi],0xff
inc edi
mov byte[edi],0x00
inc edi
mov byte[edi],0x00
inc edi

mov byte[edi],0xff
inc edi
mov byte[edi],0x00
inc edi
mov byte[edi],0x00
inc edi
mov byte[edi],0x00
inc edi  

mov byte[edi],0x00
inc edi
mov byte[edi],0x00
inc edi
mov byte[edi],0xff
inc edi
mov byte[edi],0x00
inc edi

mov byte[edi],0x00
inc edi
mov byte[edi],0xff
inc edi
mov byte[edi],0x00
inc edi
mov byte[edi],0x00
inc edi

jmp $

times 510-($-$$) db 0
dw 0xaa55

modeblock:

有什么建议吗? 谢谢。

【问题讨论】:

  • 你试过检查AX中的返回码吗?

标签: assembly bootloader bochs vesa


【解决方案1】:

为了获得线性帧缓冲区,您需要通过设置BX 寄存器中的位#14 来请求它,以用于4F02 函数。 Bochs 似乎对此很挑剔,如果您没有启用线性帧缓冲区,则会默默地忽略写入:

if (BX_VGA_THIS vbe.lfb_enabled)
{
...
}
else
{
    if (addr < BX_VGA_THIS vbe.base_address) {
      // banked mode write
      offset = (Bit32u)(BX_VGA_THIS vbe.bank*65536 + (addr - 0xA0000));
    }
    else {
      // LFB write while in banked mode -> ignore
      return;
    }

另外请注意,您不应该对模式编号进行硬编码,因为它们在不同的系统上可能会有所不同。不清楚您要设置什么模式,bochs 认为 0x115 是 800x600x24,但您的代码有 1024*768*1/2,这表明这不是您的预期。

【讨论】:

    【解决方案2】:

    为了使用 VESA VBE,您需要在您的 bochsrc 中通过将 vga 选项设置为 vbe 来启用它。 http://bochs.sourceforge.net/doc/docbook/user/vesa-notes.html

    来自 vesa.org 的 vbe3.pdf

    VBE 返回状态

    AL == 4Fh: Function is supported
    AL != 4Fh: Function is not supported
    AH == 00h: Function call successful
    AH == 01h: Function call failed
    AH == 02h: Function is not supported in the current hardware configuration
    AH == 03h: Function call invalid in current video mode
    

    VBE模式号格式如下:

    D0-D8 = Mode number
    If D8 == 0, this is not a VESA defined VBE mode
    If D8 == 1, this is a VESA defined VBE mode
    D9-D12 = Reserved by VESA for future expansion (= 0)
    D11 = Refresh Rate Control Select
    If D11 == 0, Use current BIOS default refresh rate
    If D11 == 1, Use user specified CRTC values for refresh rate
    D12-13 = Reserved for VBE/AF (must be 0)
    D14 = Linear/Flat Frame Buffer Select
    If D14 == 0, Use Banked/Windowed Frame Buffer
    If D14 == 1, Use Linear/Flat Frame Buffer
    D15 = Preserve Display Memory Select
    If D15 == 0, Clear display memory
    If D15 == 1, Preserve display memory
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2022-01-02
      • 2019-07-23
      • 1970-01-01
      • 2010-11-29
      • 2020-06-21
      • 2014-11-16
      • 1970-01-01
      • 2014-12-25
      相关资源
      最近更新 更多