Zbr's days.
May
Sun Mon Tue Wed Thu Fri Sat
   
29    
2007
Months
May

About TODO Blog RSS Old blog Projects Gallery Notes

Tue, 29 May 2007

My small SuperH bootloader.


SH IPL+g version 0.9, Copyright (C) 2000 Free Software Foundation, Inc.

This software comes with ABSOLUTELY NO WARRANTY; for details type `w'.
This is free software, and you are welcome to redistribute it under
certain conditions; type `l' for details.

2002/09/09 Making.  2004/09/08 I-O DATA NSU Update.
266:133:33 on base clock 22.22MHz and SDRAM 4 burst. CF boot.

PCIC initialization done.
MASTER:48bit LBA mode non support
Disk drive detected: LEXAR ATA FLASH V1.00 11014102039199095066 
LBA: 001EBF10
DiskSize: 1031675904Byte
PIO MODE1
Set Transfer Mode result: 50 
> b
Set Transfer Mode result: 50 
Initialize Device Parameters result: 50 
IDLE result: 50 
Starting from MBR
SECOND LOADER
Bootloader code is pretty simple - it reads predefined number of sectors (currently only one) from predefined sector number into memory and jumps there for execution.
In the example above, first bootloader resides in MBR and is limited to be 512 bytes only, so it reads into memory data from flash using IPL calls via traps from second sector and jumps to that memory. Second application just prints a string into serial console using IPL calls.

here is exerpt of the reading code for example:
read_sector:
	mov	#2, r0			! READ SECTORS
	mov	r13, r6			! destination address
	mov	#1, r5			! looks like source address (source sector number)
	mov	#0, r4			! device number (?)
	mov	#1, r7			! number of sectors
	trapa	#0x3f

	tst	r0, r0
	bt	second_loader

	! Error
	mova	message_err, r0
	mov	r0, r4
	mov	#6, r5
	mov	#0, r0			! Serial Output
	trapa	#0x3f

second_loader:
	mov	#6, r0			! Cache "on"
	mov	#0, r4
	trapa	#0x3f

	mov	r13, r0
	jmp	@r0
	nop
So, code it pretty simple, but it does work.
Next task is to read the whole kernel into mem and jump there. Stay tuned.

/devel/sh :: Link / Comments (0)

Please solve this captcha to be allowed to post (need to reload in a minute): 36 * 42

Comments are closed for this story.