0

Hello, I am a newbie to assembly. I am working with a custom Bios that does not boot the mbr of the first drive but a custom binary file on the first partition of the first drive. It is written in 32bit nasm and loads a linux kernel directly. What I am trying to do is figure out a way to have it load a bootloader like grub or lilo. The problem is most boot loaders are 16bit so is there way to write the code so it changes to 16bit and then loads the file and runs it?? Here is the code from stage2.asm:

bits 32
%define write_console 0082F158h
%define open_file 00808C94h
%define read_file 0080940Ch
%define outp 00828C64h
%define setup_video 82B890h
%define reset 008016CCh
%define initialise 008309C8h
%define set_vid_mode 008137DCh
%define turnoff 008013A4h
%define wait 0082EF98h
 
org 0x1000000
mov edx, 84Dh
mov eax, 0C0h ; 'À'
out dx, al
 
 
cld
push 1
call setup_video 
add esp, 4
push 3
push vmlinux_bin
call open_file
add esp, 8
push 0FFFFFFFFh
push 100000h
push eax
call read_file
add esp, 0Ch
push eax
push loadkernel
call write_console
add esp, 8
mov ebx, 90000h
xor eax, eax
mov edi, ebx
mov ecx, 0F00h
rep stosb
push 3
push cmdline
call open_file
push 0FFFFFFFFh
push edi
push eax
call read_file
cmp eax, 0
jge continue
xor eax, eax
continue mov byte [edi+eax], 0
push edi
push commandline
call write_console
add esp, 8
; not exactly sure what these lines are for
mov word [ebx+20h], 0A33Fh
mov word [ebx+22h], 0F00h
mov word [ebx+2], 0FFFFh
mov dword [ebx+1E0h], 1F800h
push setupgdt
call write_console
add esp, 4
mov esi, 90000h
cli
lgdt [ds:gdtinfo]
jmp 10h:100000h
ret
 
; ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ
vmlinux_bin db 'vmlinux.bin',0
loadkernel db 'loadKernel:',9,' %d bytes read',0Ah
db 0Dh,0
setupgdt db 'setting up GDT',0Ah
db 0Dh,'jumping to kernel entry',0Ah
db 0Dh,0
cmdline db 'cmdline',0
commandline db 'command line: %s',0Ah
db 0Dh,0
 
 
gdt32 db 0x00,0x00, 0x00,0x00, 0x00, 00000000b, 00000000b, 0
db 0x00,0x00, 0x00,0x00, 0x00, 00000000b, 00000000b, 0
db 0xff,0xff, 0x00,0x00, 0x00, 10011010b, 11001111b, 0
db 0xff,0xff, 0x00,0x00, 0x00, 10010010b, 11001111b, 0
db 0xff,0xff, 0x00,0x00, 0x00, 10010010b, 11001111b, 0
gdtend
gdtinfo dw (gdtend - gdt32 - 1)
dd (gdt32)
2
Contributors
1
Reply
2
Views
11 Years
Discussion Span
Last Post by Ryu
0

Are you sure you want to mess with the BIOS firmware first of all? Be aware that its typical for any kernel to rely on some BIOS interrupt services, and more importantly the firmware have code to configure your system during boot, such as PCI, ISA, PNP confiurations, and other things along with it.. I don't see the point of a costum BIOS if you want to load grub up, grub too is requires some BIOS interrupt services, but really, the standard BIOS will boot up grub anyway so who knows what your trying to achieve here..

You can go back to 16bit mode by simply clearing the PE bit in CR0 register.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.