Skip to content
Permalink
Browse files

. 修正(issues #195),(issues #196)

  • Loading branch information...
yaya
yaya committed Jun 9, 2019
1 parent e8224a2 commit c561cc961b32e015bade8ad769e4ebdc418a792e
Showing with 127 additions and 58 deletions.
  1. +0 −3 ChangeLog_chenall.txt
  2. +46 −23 stage2/asm.S
  3. +40 −12 stage2/builtins.c
  4. +41 −20 stage2/graphics.c
@@ -1,7 +1,4 @@
更新说明:
2019-05-12(yaya)
增加 echo -k 参数,显示键盘代码。

2019-05-07(yaya)
改进 setkey 命令及帮助,完全支持匈牙利键盘(由 steve 提供)。
改进 displaymem 及 bootlace 命令。
@@ -35,6 +35,7 @@
*/

#define ASM_FILE
#define repair_memory_holes 1

#include "filesys.h"
#include "shared.h"
@@ -5593,12 +5594,12 @@ minimum_mem_lo_in_map:
.long 0 /* min ram drive base below 16M */
ENTRY(minimum_mem_hi_in_map)
.long 0 /* min ram drive base above 16M */
#if (repair_memory_holes)
ENTRY(prime_end)
.long 0,0
ENTRY(new_end)
.long 0,0

#endif
#if 0
int15_e820_saved_ebx:
.long 0
@@ -5676,6 +5677,15 @@ int15_e820_handler:
cmpl $20, %ecx
jb 2f /* treat this as error: invalid call. */

#if (repair_memory_holes)
orl %ebx, %ebx
jne 3f
movl %ebx, %cs:(prime_end - int13_handler)
movl %ebx, %cs:(prime_end + 4 - int13_handler)
movl %ebx, %cs:(new_end - int13_handler)
movl %ebx, %cs:(new_end + 4 - int13_handler)
#endif
3:
#if 0
cmpl $1, %ebx
jb 8f /* EBX = 0 : start at beginning */
@@ -5727,7 +5737,7 @@ int15_e820_handler:
movl %es:16(%di), %eax /* Type: 1 = usable memory. */
decl %eax /* is it usable? */
jz 5f /* yes, modify usable mem range */
#if 0
#if (!repair_memory_holes)
/* it is reserved memory. only modify low mem range at this moment. */
cmpl %edx, %cs:(EXT_C(int15nolow) - int13_handler) /* EDX=0 */
jnz 4f /* int15 will not handle low mem */
@@ -5748,26 +5758,26 @@ int15_e820_handler:
movl $0xA0000, %es:8(%di)
subl %eax, %es:8(%di)
jmp 4f /* done modifying reserved low mem range */
#endif

andb $0xfe, (prime_end - int13_handler)
#else
andb $0xfe, %cs:(prime_end - int13_handler)
movl %es:4(%di), %edx
cmpl %edx, (prime_end + 4 - int13_handler) //0
cmpl %edx, %cs:(prime_end + 4 - int13_handler) //0
jne 4f
movl %es:(%di), %eax
cmpl %eax, (prime_end - int13_handler)
cmpl %eax, %cs:(prime_end - int13_handler)
jne 4f

subl (new_end - int13_handler), %eax
sbbl (new_end + 4 - int13_handler), %edx
subl %cs:(new_end - int13_handler), %eax
sbbl %cs:(new_end + 4 - int13_handler), %edx
addl %eax, %es:8(%di)
adcl %edx, %es:12(%di)

movl (new_end - int13_handler), %eax
movl (new_end + 4 - int13_handler), %edx
movl %cs:(new_end - int13_handler), %eax
movl %cs:(new_end + 4 - int13_handler), %edx
movl %eax, %es:(%di)
movl %edx, %es:4(%di)
jmp 4f
#endif
5:
/* it is usable memory. */

@@ -5778,13 +5788,20 @@ int15_e820_handler:
#else
movw $(EXT_C(hooked_drive_map)-int13_handler-DRIVE_MAP_SLOT_SIZE), %si
#endif
movw $(DRIVE_MAP_SIZE + 1), %bp

#if (!repair_memory_holes)
movw $(DRIVE_MAP_SIZE + 1), %cx
#else
movw $(DRIVE_MAP_SIZE + 1), %bp
#endif
popl %eax /* available low mem size in bytes */
pushl %eax /* available low mem size in bytes */

// cmpl %edx, %cs:(EXT_C(int15nolow) - int13_handler) /* EDX=0 */
#if (!repair_memory_holes)
cmpl %edx, %cs:(EXT_C(int15nolow) - int13_handler) /* EDX=0 */
#else
cmpl $0, %cs:(EXT_C(int15nolow) - int13_handler)
#endif
jz 7f /* int15 will handle low mem */
jmp 5f /* this "jmp" instruction can be omitted. */
6:
@@ -5820,8 +5837,10 @@ int15_e820_handler:
subl %es:8(%di), %eax
sbbl %es:12(%di), %edx /* EDX:EAX=difference */
jnb 5f /* new length is too big */
// addl %eax, %es:8(%di)
// adcl %edx, %es:12(%di) /* apply new length */
#if (!repair_memory_holes)
addl %eax, %es:8(%di)
adcl %edx, %es:12(%di) /* apply new length */
#else
movl %es:8(%di), %ebx
movl %es:12(%di), %ecx
addl %ebx, %eax
@@ -5830,22 +5849,26 @@ int15_e820_handler:
movl %edx, %es:12(%di)
addl %es:(%di), %eax
adcl %es:4(%di), %edx
movl %eax, (new_end - int13_handler)
movl %edx, (new_end + 4 - int13_handler)
movl %eax, %cs:(new_end - int13_handler)
movl %edx, %cs:(new_end + 4 - int13_handler)

testb $1, (prime_end - int13_handler)
testb $1, %cs:(prime_end - int13_handler)
jne 5f
addl %es:(%di), %ebx
adcl %es:4(%di), %ecx
movl %ebx, (prime_end - int13_handler)
movl %ecx, (prime_end + 4 - int13_handler)
orb $1, (prime_end - int13_handler)
movl %ebx, %cs:(prime_end - int13_handler)
movl %ecx, %cs:(prime_end + 4 - int13_handler)
orb $1, %cs:(prime_end - int13_handler)
#endif
5:
/* try next slot */
addw $DRIVE_MAP_SLOT_SIZE, %si
// loop 6b
#if (!repair_memory_holes)
loop 6b
#else
dec %bp
jne 6b
#endif
/* done modifying usable mem range */
4:
popl %eax /* available low mem size in bytes */
@@ -4194,6 +4194,8 @@ splashimage_func(char *arg, int flags)
}
else if (grub_memcmp (arg, "--fill-color=", 13) == 0)
{
if (graphics_mode < 0xFF)
return !(errnum = ERR_NO_VBE_BIOS);
arg += 13;
if (safe_parse_maxint (&arg, &val))
{
@@ -4668,10 +4670,11 @@ displaymem_func (char *arg, int flags)
struct AddrRangeDesc *map = (struct AddrRangeDesc *) addr;
if (!sector)
{
grub_printf (" %s: Base: 0x%8lX, Length: 0x%8lX\n",
grub_printf (" %s: Base: 0x%8lX, Length: 0x%8lX, End: 0x%8lX\n",
(map->Type == MB_ARD_MEMORY)?"Usable RAM":"Reserved ",
map->BaseAddr,
map->Length);
map->Length,
map->BaseAddr + map->Length);
}
else if (map->Type == MB_ARD_MEMORY)
{
@@ -9368,6 +9371,10 @@ map_func (char *arg, int flags)

if (grub_memcmp (arg, "--status", 8) == 0)
{
int byte = 0;
arg += 8;
if (grub_memcmp (arg, "-byte", 5) == 0)
byte = 1;
arg = skip_to(1,arg);
if (*arg>='0' && *arg <='9')
{
@@ -9453,7 +9460,7 @@ map_func (char *arg, int flags)
break;
}
// if (debug > 0)
grub_printf ("%02X %02X %02X %02X %04X %02X %02X %016lX %016lX %c%c%c\n", hooked_drive_map[i].from_drive, hooked_drive_map[i].to_drive, hooked_drive_map[i].max_head, hooked_drive_map[i].max_sector, hooked_drive_map[i].to_cylinder, hooked_drive_map[i].to_head, hooked_drive_map[i].to_sector, (unsigned long long)hooked_drive_map[i].start_sector, (unsigned long long)hooked_drive_map[i].sector_count, ((hooked_drive_map[i].to_cylinder & 0x4000) ? 'C' : hooked_drive_map[i].to_drive < 0x80 ? 'F' : hooked_drive_map[i].to_drive == 0xFF ? 'M' : 'H'), ((j < DRIVE_MAP_SIZE) ? '=' : '>'), ((hooked_drive_map[i].max_sector & 0x80) ? ((hooked_drive_map[i].to_sector & 0x40) ? 'F' : 'R') :((hooked_drive_map[i].to_sector & 0x40) ? 'S' : 'U')));
grub_printf ("%02X %02X %02X %02X %04X %02X %02X %016lX %016lX %c%c%c\n", hooked_drive_map[i].from_drive, hooked_drive_map[i].to_drive, hooked_drive_map[i].max_head, hooked_drive_map[i].max_sector, hooked_drive_map[i].to_cylinder, hooked_drive_map[i].to_head, hooked_drive_map[i].to_sector, byte?(((unsigned long long)hooked_drive_map[i].start_sector)*0x200):((unsigned long long)hooked_drive_map[i].start_sector), byte?(((unsigned long long)hooked_drive_map[i].sector_count)*0x200):((unsigned long long)hooked_drive_map[i].sector_count), ((hooked_drive_map[i].to_cylinder & 0x4000) ? 'C' : hooked_drive_map[i].to_drive < 0x80 ? 'F' : hooked_drive_map[i].to_drive == 0xFF ? 'M' : 'H'), ((j < DRIVE_MAP_SIZE) ? '=' : '>'), ((hooked_drive_map[i].max_sector & 0x80) ? ((hooked_drive_map[i].to_sector & 0x40) ? 'F' : 'R') :((hooked_drive_map[i].to_sector & 0x40) ? 'S' : 'U')));
}
for (i = 0; i < DRIVE_MAP_SIZE; i++)
{
@@ -9470,7 +9477,7 @@ map_func (char *arg, int flags)
continue;
}
// if (debug > 0)
grub_printf ("%02X %02X %02X %02X %04X %02X %02X %016lX %016lX %c<%c\n", bios_drive_map[i].from_drive, bios_drive_map[i].to_drive, bios_drive_map[i].max_head, bios_drive_map[i].max_sector, bios_drive_map[i].to_cylinder, bios_drive_map[i].to_head, bios_drive_map[i].to_sector, (unsigned long long)bios_drive_map[i].start_sector, (unsigned long long)bios_drive_map[i].sector_count, ((bios_drive_map[i].to_cylinder & 0x4000) ? 'C' : bios_drive_map[i].to_drive < 0x80 ? 'F' : bios_drive_map[i].to_drive == 0xFF ? 'M' : 'H'), ((bios_drive_map[i].max_sector & 0x80) ? ((bios_drive_map[i].to_sector & 0x40) ? 'F' : 'R') :((bios_drive_map[i].to_sector & 0x40) ? 'S' : 'U')));
grub_printf ("%02X %02X %02X %02X %04X %02X %02X %016lX %016lX %c<%c\n", bios_drive_map[i].from_drive, bios_drive_map[i].to_drive, bios_drive_map[i].max_head, bios_drive_map[i].max_sector, bios_drive_map[i].to_cylinder, bios_drive_map[i].to_head, bios_drive_map[i].to_sector, byte?(((unsigned long long)bios_drive_map[i].start_sector)*0x200):((unsigned long long)bios_drive_map[i].start_sector), byte?(((unsigned long long)bios_drive_map[i].start_sector)*0x200):((unsigned long long)bios_drive_map[i].sector_count), ((bios_drive_map[i].to_cylinder & 0x4000) ? 'C' : bios_drive_map[i].to_drive < 0x80 ? 'F' : bios_drive_map[i].to_drive == 0xFF ? 'M' : 'H'), ((bios_drive_map[i].max_sector & 0x80) ? ((bios_drive_map[i].to_sector & 0x40) ? 'F' : 'R') :((bios_drive_map[i].to_sector & 0x40) ? 'S' : 'U')));
}
return 1;
}
@@ -11407,7 +11414,7 @@ static struct builtin builtin_map =
"map",
map_func,
BUILTIN_MENU | BUILTIN_CMDLINE | BUILTIN_SCRIPT | BUILTIN_HELP_LIST | BUILTIN_IFTITLE,
"map [--status] [--mem[=RESERV]] [--hook] [--unhook] [--unmap=DRIVES]\n [--rehook] [--floppies=M] [--harddrives=N] [--memdisk-raw=RAW]\n [--a20-keep-on=AKO] [--safe-mbr-hook=SMH] [--int13-scheme=SCH]\n [--ram-drive=RD] [--rd-base=ADDR] [--rd-size=SIZE] [[--read-only]\n [--fake-write] [--unsafe-boot] [--disable-chs-mode] [--disable-lba-mode]\n [--heads=H] [--sectors-per-track=S] [--swap-drivs=DRIVE1=DRIVE2] [--in-situ=FLAGS_AND_ID] TO_DRIVE FROM_DRIVE]",
"map [--status[-byte]] [--mem[=RESERV]] [--hook] [--unhook] [--unmap=DRIVES]\n [--rehook] [--floppies=M] [--harddrives=N] [--memdisk-raw=RAW]\n [--a20-keep-on=AKO] [--safe-mbr-hook=SMH] [--int13-scheme=SCH]\n [--ram-drive=RD] [--rd-base=ADDR] [--rd-size=SIZE] [[--read-only]\n [--fake-write] [--unsafe-boot] [--disable-chs-mode] [--disable-lba-mode]\n [--heads=H] [--sectors-per-track=S] [--swap-drivs=DRIVE1=DRIVE2] [--in-situ=FLAGS_AND_ID] TO_DRIVE FROM_DRIVE]",
"Map the drive FROM_DRIVE to the drive TO_DRIVE. This is necessary"
" when you chain-load some operating systems, such as DOS, if such an"
" OS resides at a non-first drive. TO_DRIVE can be a disk file, this"
@@ -12242,6 +12249,7 @@ static struct builtin builtin_pause =
BUILTIN_MENU | BUILTIN_CMDLINE | BUILTIN_SCRIPT | BUILTIN_NO_ECHO,
"pause [--test-key] [--wait=T] [MESSAGE ...]",
"Print MESSAGE, then wait until a key is pressed or T seconds has passed."
"--test-key display keyboard code."
};


@@ -15759,12 +15767,32 @@ echo_func (char *arg,int flags)
gotoxy(saved_x, saved_y);
return 1;
}
else if (grub_memcmp(arg,"-k",2) == 0)
else if (grub_memcmp(arg,"-mem=",3) == 0) //-mem=offset=length
{
int i;
grub_printf("Please press the keyboard:");
i = getkey();
grub_printf("\rThe keyboard code is %04x. ",i);
unsigned long long offset;
unsigned long long length;
unsigned char s[16];
unsigned long long j = 16;

arg += 5;
safe_parse_maxint (&arg, &offset);
arg++;
safe_parse_maxint (&arg, &length);

if (j > length)
j = length;
while (1)
{
grub_memmove64((unsigned long long)(int)s, offset, j);
hexdump(offset,(char*)&s,j);
if (quit_print)
break;
offset += j;
length -= j;
if (!length)
break;
j = (length >= 16)?16:length;
}
return 1;
}
else break;
@@ -15847,7 +15875,7 @@ static struct builtin builtin_echo =
"echo",
echo_func,
BUILTIN_MENU | BUILTIN_CMDLINE | BUILTIN_SCRIPT | BUILTIN_HELP_LIST,
"echo [-P:XXYY] [-h] [-e] [-n] [-v] [-rrggbb] [[$[ABCD]]MESSAGE ...] ",
"echo [-P:XXYY] [-h] [-e] [-n] [-v] [-rrggbb] [-mem=offset=length] [[$[ABCD]]MESSAGE ...] ",
"-P:XXYY position control line(XX) and column(YY).\n"
"-h show a color panel.\n"
"-n do not output the trailing newline.\n"
@@ -15856,7 +15884,7 @@ static struct builtin builtin_echo =
" \\Xnnnn show unicode characters(big endian).\n"
"-v show version and memory information.\n"
"-rrggbb show 24 bit colors.\n"
"-k show keyboard code.\n"
"-mem=offset=length hexdump.\n"
"$[ABCD] the color for MESSAGE.(console only, 8 bit number)\n"
"A=bright background, B=bright characters, C=background color, D=Character color.\n"
"$[0xCD] 8 or 64 bit number value for MESSAGE. C=background, D=Character.\n"
@@ -940,15 +940,25 @@ graphics_cls (void)
{
// *(unsigned long *)mem = SPLASH_IMAGE[x+y*SPLASH_W];
lfb = (unsigned char *)SPLASH_IMAGE + x*current_bytes_per_pixel + y*current_bytes_per_scanline;
if(current_bits_per_pixel == 24 || current_bits_per_pixel == 32)
if(current_bits_per_pixel == 32)
*(unsigned long *)mem = *(unsigned long *)lfb;
else if(current_bits_per_pixel == 24)
{
*(unsigned short *)mem = *(unsigned short *)lfb;
*(mem+2) = *(lfb+2);
}
else
*(unsigned short *)mem = *(unsigned short *)lfb;
}
else
{
if(current_bits_per_pixel == 24 || current_bits_per_pixel == 32)
if(current_bits_per_pixel == 32)
*(unsigned long *)mem = color;
else if(current_bits_per_pixel == 24)
{
*(unsigned short *)mem = (unsigned short)color;
*(mem+2) = (unsigned char)(color>>16);
}
else
*(unsigned short *)mem = (unsigned short)pixel_shift(color);
}
@@ -1036,22 +1046,23 @@ vbe_fill_color (unsigned long color)
int i;
unsigned char *p;

if(current_bits_per_pixel == 24 || current_bits_per_pixel == 32)
{
for (i=0;i<(current_x_resolution*current_y_resolution);i++)
{
p = (unsigned char *)IMAGE_BUFFER + i*4;
*(unsigned long *)p = color;
}
}
else
{
for (i=0;i<(current_x_resolution*current_y_resolution);i++)
{
p = (unsigned char *)IMAGE_BUFFER + i*2;
*(unsigned short *)p = (unsigned short)pixel_shift(color);
}
}
for (i=0;i<(current_x_resolution*current_y_resolution);i++)
{
p = (unsigned char *)IMAGE_BUFFER + i*current_bytes_per_pixel;
switch (current_bits_per_pixel)
{
case 32:
*(unsigned long *)p = color;
break;
case 24:
*(unsigned short *)p = (unsigned short)(color);
*(p+2) = (unsigned char)(color>>16);
break;
default:
*(unsigned short *)p = (unsigned short)pixel_shift(color);
break;
}
}
}


@@ -1264,9 +1275,14 @@ static int read_image_bmp(int type)
source = bftmp;
}

if(current_bits_per_pixel == 24 || current_bits_per_pixel == 32)
if(current_bits_per_pixel == 32)
// bmp[x] = bftmp; //
*(unsigned long *)bmp = source;
else if(current_bits_per_pixel == 24)
{
*(unsigned short *)bmp = (unsigned short)source;
*(bmp+2) = (unsigned char)(source>>16);
}
else
*(unsigned short *)bmp = (unsigned short)pixel_shift(source);
}
@@ -1470,8 +1486,13 @@ static void StoreBuffer()
source = color;
}

if(current_bits_per_pixel == 24 || current_bits_per_pixel == 32)
if(current_bits_per_pixel == 32)
*(unsigned long *)lfb = source;
else if(current_bits_per_pixel == 24)
{
*(unsigned short *)lfb = (unsigned short)source;
*(lfb+2) = (unsigned char)(source>>16);
}
else
*(unsigned short *)lfb = (unsigned short)pixel_shift(source);
}

0 comments on commit c561cc9

Please sign in to comment.
You can’t perform that action at this time.