0

I'm trying to print vendorID and DeviceID of my hardware which stores in ebx using this code and I'll boot it:

_start:
    xor eax,eax
    mov eax,0x80000000
    xor ecx,ecx
.main
    mov dx,0x0cf8
    out dx,eax
    mov dx,0x0cfc
    mov ebp,eax
    in  eax,dx
    cmp eax,0xFFFFFFFF ;eax will fill with 0xFFFFFFFF if no device founded on bus
    je  .count
    xor ebx,ebx
    mov [ebx],eax    ;copy the vendor and Device ID
    add ebx,0x0004
    mov [ebx],ebx    ;their locations
    mov eax,ebx
    add eax,0x00000800 ; next device
    inc ecx
    cmp ecx,0x20
    je break
    loop main

.count
    inc ecx
    jmp main

.break
    mov rax,1
    int 0x80


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

the values as you see stores in ebx but I have problem with overwriting and move the cursor (INT 10 & 0x0e)

Q1: How to Print Those values?

Q2: How to find the actual memory address of the hardwares?(for example my network card address is 0x7F800000. (found in Windows 10 System information ))

code resource : https://www.youtube.com/watch?v=NgzT1JfBUr0&t=142s

  • 1
    [Displaying numbers with DOS](https://stackoverflow.com/q/45904075) can be adapted to use BIOS character-output functions instead of DOS stdout. However `mov rax,1` / `int 0x80` is wrong for at least 3 different reasons: 1. this is a BIOS MBR boot sector, so Linux system calls aren't available. 2. This is 16-bit code so `rax` (a 64-bit register) isn't usable. 3. Don't use the `int 0x80` Linux 32-bit ABI in 64-bit code, which this would have to be to use RAX. – Peter Cordes Nov 10 '20 at 13:12
  • 2
    Normally you want BIOS `int 10h`, not `int 10` (aka `int 0xa`). Also, `loop main` looks for a `main` label, but you only defined `.main`, so this won't even assemble. Wait, *is* this even a bootloader? The `times 510-($-$$) db 0` / `dw 0xaa55` boot signature says yes, but the `_start` label and 64-bit code indicate a Linux executable (which you built as 64-bit even though you have 32-bit code in it). So you're trying to port a broken Linux program (that will crash on `in` without an `ioperm` syscal) to an MBR bootloader? – Peter Cordes Nov 10 '20 at 13:16
  • @PeterCordes Thanks, mate. Helped Me a lot. I'll correct them. –  Nov 10 '20 at 13:21
  • For question 2, you need to parse the ACPI tables but that's another thing. Look at https://wiki.osdev.org/DSDT and the other links in the page. – user123 Nov 10 '20 at 16:45

0 Answers0