Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Custom staged BIOS help

Status
Not open for further replies.

linuxjunkie

Technical User
Sep 19, 2006
1
US
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:
Code:
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)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top