Author Topic: RE: 64-bit MBR  (Read 15927 times)

Offline wolverine79936

  • Jr. Member
  • *
  • Posts: 4
RE: 64-bit MBR
« on: April 04, 2019, 09:10:51 PM »
Good afternoon, everyone.  ;D I have decided to start doing tons of research and work in regards to a operating system. I know, major undertaking, but I am familiar with C/C++ and wanted to learn ASM finally.

My question is quite simple: How in the world do I print to the screen without the BIOS or syscall?!?!?! I've been to like a million different websites searching specifically for 64-bit ASM and 64-bit MBR source code and everything I have found and tried simply doesn't work.

Now, I know y'all are going to need to see my code, but I'm not entirely comfortable putting a whole lot of it up right now. So, I'm going to do my best to explain how I got to the snippet in question and what is meant to happen after the snippet...

So, I set ORG 0x7c00 and tell NASM I need this part of my MBR to run in 16-bit mode. Then I ensure that I am loading at 0x7c00 instead of 0x7c00:0x0000. Then I clear out all the registers in 16-bit mode.

Here is the snippet that I am having trouble with:
Code: [Select]
BITS 64                 ; We are now switching the processor over to long mode. YAY! Progress. Personal joke.
    mov rax, 1
    mov rdi, 1
    mov rsi, msg
    mov rdx, msglen
   
msg: db 'Blah blah blah.',10
msglen: equ $ - msg

Now, after that is just the standard first 512b of padding and the boot signature at the end of the sector.

I have tried writing the 64-bit snippet with BIOS calls and got nowhere. I tried writing it with syscall and obviously that got me nowhere. I tried dropping BIOS interrupts and syscalls from this snippet and snill no dice. I assemble my source code for my mbr and then I write it to the first 512b of a floppy disk image and boot it into Oracle VirtualBox. I have tried a 16-bit mbr and was able to print through BIOS calls. So please, if anyone knows how to fix my issue and is willing to help me, it would be greatly appreciated. :)

Offline fredericopissarra

  • Full Member
  • **
  • Posts: 368
  • Country: br
Re: RE: 64-bit MBR
« Reply #1 on: April 05, 2019, 09:34:24 PM »
First, MBR is executed in REAL mode, always. Not even protected mode...

There are no "syscalls" but bios calls, via INT instruction.

There is two ways to write a string to the screen on MBR: Directly or using INT 0x10/AH=0x0e (See Ralph Brownn's Interrupt List).

Direct way: If you initialize the mode 3, via:
Code: [Select]
mov ax,3
int 0x10
You can write directly to segment 0xb800, offset 0. Each word is char/attribute. See IBM VGA manual, "Video Memory Organization" chapter.

Using BIOS:
Code: [Select]
; void puts( char * );
; Entry: DS:SI = asciiz string ptr.
; Destroys: AX, BX, SI and BP.
puts:
  mov ah,0x0e
  mov bx,7 ; page 0, white color.
.loop:
  lodsb
  test al,al
  jz   .exit
  int  0x10
  jmp .loop
.exit:
  ret
« Last Edit: April 05, 2019, 09:37:09 PM by fredericopissarra »

Offline wolverine79936

  • Jr. Member
  • *
  • Posts: 4
Re: RE: 64-bit MBR
« Reply #2 on: April 06, 2019, 01:25:12 AM »
Thank you very much for the information, fredericopissarra. My understanding of what you just wrote is that the MBR is a 16-bit environment. And now that I know that, that is very useful. I'll just finish touching up my MBR and then go ahead and start working on my kernel from whence I should be able to start making output and input finally. :)

I also meant to ask if anyone knows of someone who has successfully written an all ASM OS or if they all just switched over to a higher language as soon as they were done with their MBR...?
« Last Edit: April 06, 2019, 01:27:20 AM by wolverine79936 »

Offline fredericopissarra

  • Full Member
  • **
  • Posts: 368
  • Country: br
Re: RE: 64-bit MBR
« Reply #3 on: April 06, 2019, 04:24:00 PM »
Thank you very much for the information, fredericopissarra. My understanding of what you just wrote is that the MBR is a 16-bit environment.

You're welcome! But why use MBR? You could develop your bootloader using UEFI and avoid the restriction of space (MBR is 1 sector long, 512 bytes, always) and let UEFI setup the protected mode for you (including long mode)... This kind of bootloader can be as big as you want, using graphics, network, etc...

I also meant to ask if anyone knows of someone who has successfully written an all ASM OS or if they all just switched over to a higher language as soon as they were done with their MBR...?

Well... you can do it, but, in my experience, using C is better, since the compiler otimizes the code better than you and I could do manually... Let ASM for high performance functions only (or small inline functions)...

Offline wolverine79936

  • Jr. Member
  • *
  • Posts: 4
Re: RE: 64-bit MBR
« Reply #4 on: April 06, 2019, 06:36:38 PM »
Thank you for the input, @fredericopissarra. :) I think for me, MBR aside, the idea of writing an OS in ASM is a challenge and I really enjoy challenges when I can make progress on them. As far as the MBR, I know of UEFI, I have a UEFI BIOS, but I haven't spent much time on the UEFI topic so wasn't aware that it could do all of that FOR me. That's really cool. I'll definitely check it out. Thanks again, @fredericopissarra.

Offline fredericopissarra

  • Full Member
  • **
  • Posts: 368
  • Country: br
Re: RE: 64-bit MBR
« Reply #5 on: April 08, 2019, 01:48:37 AM »

Offline wolverine79936

  • Jr. Member
  • *
  • Posts: 4
Re: RE: 64-bit MBR
« Reply #6 on: April 12, 2019, 03:16:48 PM »
Thank you, @fredericopissarra. I will check that out first chance I get. :)

Offline Structure

  • Jr. Member
  • *
  • Posts: 21
Re: RE: 64-bit MBR
« Reply #7 on: January 08, 2020, 08:27:14 PM »
Quote
anyone knows of someone who has successfully written an all ASM OS

challenge accepted...