From eb3f57d3c4d74327badc321c21a9c6eb81d396a6 Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Thu, 31 Dec 2009 13:07:51 +0100 Subject: [PATCH 01/21] proof of concept interrupt wrapping --- conf/i386-pc.rmk | 2 +- disk/i386/pc/biosdisk.c | 54 ++++++++++++ include/grub/i386/pc/biosdisk.h | 2 - include/grub/i386/pc/int.h | 50 +++++++++++ kern/i386/pc/startup.S | 146 ++++++++++++++++---------------- 5 files changed, 176 insertions(+), 78 deletions(-) create mode 100644 include/grub/i386/pc/int.h diff --git a/conf/i386-pc.rmk b/conf/i386-pc.rmk index 4ae753776..45020819a 100644 --- a/conf/i386-pc.rmk +++ b/conf/i386-pc.rmk @@ -64,7 +64,7 @@ kernel_img_HEADERS = boot.h cache.h device.h disk.h dl.h elf.h elfload.h \ partition.h msdos_partition.h reader.h symbol.h term.h time.h types.h \ machine/biosdisk.h machine/boot.h machine/console.h machine/init.h \ machine/memory.h machine/loader.h machine/vga.h machine/vbe.h \ - machine/kernel.h machine/pxe.h i386/pit.h list.h handler.h command.h i18n.h + machine/kernel.h machine/pxe.h i386/pit.h list.h handler.h command.h i18n.h machine/int.h kernel_img_CFLAGS = $(COMMON_CFLAGS) $(TARGET_IMG_CFLAGS) kernel_img_ASFLAGS = $(COMMON_ASFLAGS) kernel_img_LDFLAGS = $(COMMON_LDFLAGS) $(TARGET_IMG_LDFLAGS)$(GRUB_KERNEL_MACHINE_LINK_ADDR) $(COMMON_CFLAGS) diff --git a/disk/i386/pc/biosdisk.c b/disk/i386/pc/biosdisk.c index af184b1ba..0f75dba5f 100644 --- a/disk/i386/pc/biosdisk.c +++ b/disk/i386/pc/biosdisk.c @@ -19,6 +19,7 @@ #include #include #include +#include #include #include #include @@ -28,6 +29,59 @@ #include static int cd_drive = 0; +static int grub_biosdisk_rw_int13_extensions (int ah, int drive, void *dap); + +static int grub_biosdisk_get_num_floppies (void) +{ + struct grub_cpu_int_registers regs; + int drive; + + /* reset the disk system first */ + regs.ax = 0; + regs.dx = 0; + regs.flags = GRUB_CPU_INT_FLAGS_DEFAULT; + + grub_cpu_interrupt (0x13, ®s); + + for (drive = 0; drive < 2; drive++) + { + regs.flags = GRUB_CPU_INT_FLAGS_DEFAULT | GRUB_CPU_INT_FLAGS_CARRY; + regs.dx = drive; + + /* call GET DISK TYPE */ + regs.ax = 0x1500; + grub_cpu_interrupt (0x13, ®s); + if (regs.flags & GRUB_CPU_INT_FLAGS_CARRY) + break; + + /* check if this drive exists */ + if (!(regs.ax & 0x300)) + break; + } + + return drive; +} + +/* + * Call IBM/MS INT13 Extensions (int 13 %ah=AH) for DRIVE. DAP + * is passed for disk address packet. If an error occurs, return + * non-zero, otherwise zero. + */ + +static int +grub_biosdisk_rw_int13_extensions (int ah, int drive, void *dap) +{ + struct grub_cpu_int_registers regs; + regs.ax = ah << 8; + /* compute the address of disk_address_packet */ + regs.ds = (((grub_addr_t) dap) & 0xffff0000) >> 4; + regs.si = (((grub_addr_t) dap) & 0xffff); + regs.dx = drive; + regs.flags = GRUB_CPU_INT_FLAGS_DEFAULT; + + grub_cpu_interrupt (0x13, ®s); + return regs.ax >> 8; +} static int grub_biosdisk_get_drive (const char *name) diff --git a/include/grub/i386/pc/biosdisk.h b/include/grub/i386/pc/biosdisk.h index b87e0e433..83d833cad 100644 --- a/include/grub/i386/pc/biosdisk.h +++ b/include/grub/i386/pc/biosdisk.h @@ -106,7 +106,6 @@ struct grub_biosdisk_dap grub_uint64_t block; } __attribute__ ((packed)); -int EXPORT_FUNC(grub_biosdisk_rw_int13_extensions) (int ah, int drive, void *dap); int EXPORT_FUNC(grub_biosdisk_rw_standard) (int ah, int drive, int coff, int hoff, int soff, int nsec, int segment); int EXPORT_FUNC(grub_biosdisk_check_int13_extensions) (int drive); @@ -118,7 +117,6 @@ int EXPORT_FUNC(grub_biosdisk_get_diskinfo_standard) (int drive, unsigned long *cylinders, unsigned long *heads, unsigned long *sectors); -int EXPORT_FUNC(grub_biosdisk_get_num_floppies) (void); void grub_biosdisk_init (void); void grub_biosdisk_fini (void); diff --git a/include/grub/i386/pc/int.h b/include/grub/i386/pc/int.h new file mode 100644 index 000000000..b8cbe3260 --- /dev/null +++ b/include/grub/i386/pc/int.h @@ -0,0 +1,50 @@ +/* + * GRUB -- GRand Unified Bootloader + * Copyright (C) 2009 Free Software Foundation, Inc. + * + * GRUB is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * GRUB is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with GRUB. If not, see . + */ + +#ifndef GRUB_INTERRUPT_MACHINE_HEADER +#define GRUB_INTERRUPT_MACHINE_HEADER 1 + +#include + +struct grub_cpu_int_registers +{ + grub_uint16_t bx; + grub_uint16_t es; + grub_uint16_t cx; + grub_uint16_t ax; + grub_uint16_t dx; + grub_uint16_t ds; + grub_uint16_t di; + grub_uint16_t flags; + grub_uint16_t si; +}; + +#define GRUB_CPU_INT_FLAGS_CARRY 0x1 +#define GRUB_CPU_INT_FLAGS_PARITY 0x4 +#define GRUB_CPU_INT_FLAGS_ADJUST 0x10 +#define GRUB_CPU_INT_FLAGS_ZERO 0x40 +#define GRUB_CPU_INT_FLAGS_SIGN 0x80 +#define GRUB_CPU_INT_FLAGS_TRAP 0x100 +#define GRUB_CPU_INT_FLAGS_INTERRUPT 0x200 +#define GRUB_CPU_INT_FLAGS_DIRECTION 0x400 +#define GRUB_CPU_INT_FLAGS_OVERFLOW 0x800 +#define GRUB_CPU_INT_FLAGS_DEFAULT GRUB_CPU_INT_FLAGS_INTERRUPT + +void EXPORT_FUNC (grub_cpu_interrupt) (grub_uint8_t intno, struct grub_cpu_int_registers *regs); + +#endif diff --git a/kern/i386/pc/startup.S b/kern/i386/pc/startup.S index 06e26dea3..815686502 100644 --- a/kern/i386/pc/startup.S +++ b/kern/i386/pc/startup.S @@ -566,44 +566,6 @@ FUNCTION(grub_chainloader_real_boot) #include "../loader.S" -/* - * int grub_biosdisk_rw_int13_extensions (int ah, int drive, void *dap) - * - * Call IBM/MS INT13 Extensions (int 13 %ah=AH) for DRIVE. DAP - * is passed for disk address packet. If an error occurs, return - * non-zero, otherwise zero. - */ - -FUNCTION(grub_biosdisk_rw_int13_extensions) - pushl %ebp - pushl %esi - - /* compute the address of disk_address_packet */ - movw %cx, %si - xorw %cx, %cx - shrl $4, %ecx /* save the segment to cx */ - - /* ah */ - movb %al, %dh - /* enter real mode */ - call prot_to_real - - .code16 - movb %dh, %ah - movw %cx, %ds - int $0x13 /* do the operation */ - movb %ah, %dl /* save return value */ - /* back to protected mode */ - DATA32 call real_to_prot - .code32 - - movb %dl, %al /* return value in %eax */ - - popl %esi - popl %ebp - - ret - /* * int grub_biosdisk_rw_standard (int ah, int drive, int coff, int hoff, * int soff, int nsec, int segment) @@ -861,43 +823,6 @@ noclean2: ret $4 -/* - * int grub_biosdisk_get_num_floppies (void) - */ -FUNCTION(grub_biosdisk_get_num_floppies) - pushl %ebp - - xorl %edx, %edx - call prot_to_real - - .code16 - /* reset the disk system first */ - int $0x13 -1: - stc - - /* call GET DISK TYPE */ - movb $0x15, %ah - int $0x13 - - jc 2f - - /* check if this drive exists */ - testb $0x3, %ah - jz 2f - - incb %dl - cmpb $2, %dl - jne 1b -2: - DATA32 call real_to_prot - .code32 - - movl %edx, %eax - popl %ebp - ret - - /* * * grub_get_memsize(i) : return the memory size in KB. i == 0 for conventional @@ -2142,3 +2067,74 @@ FUNCTION(grub_pxe_call) popl %esi popl %ebp ret + +FUNCTION(grub_cpu_interrupt) + pushl %ebp + pushl %esi + pushl %edi + pushl %ebx + pushl %edx + movb %al, intno + movl %edx, %esi + + movl 0(%esi), %ebx + movl 4(%esi), %ecx + movl 8(%esi), %edx + movl 12(%esi), %edi + movw 16(%esi), %si + + call prot_to_real + .code16 + movl %edi, %eax + shrl $16, %eax + push %ax + + movl %ebx, %eax + shrl $16, %eax + movw %ax, %es + + movl %edx, %eax + shrl $16, %eax + movw %ax, %ds + + movl %ecx, %eax + shrl $16, %eax + + popf + .byte 0xcd +intno: + .byte 0 + + pushf + andl $0xffff, %ebx + andl $0xffff, %ecx + andl $0xffff, %edx + andl $0xffff, %edi + + shll $16, %eax + orl %eax, %ecx + + movw %ds, %ax + shll $16, %eax + orl %eax, %edx + + pop %ax + shll $16, %eax + orl %eax, %edi + + DATA32 call real_to_prot + .code32 + pushl %esi + movl 4(%esp), %esi + movl %ebx, 0(%esi) + movl %ecx, 4(%esi) + movl %edx, 8(%esi) + movl %edi, 12(%esi) + popl %eax + movw %ax, 16(%esi) + popl %eax + popl %ebx + popl %edi + popl %esi + popl %ebp + ret From 1453b2ec7fe961363320392cfff6d7e15bbb3cfe Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Sun, 17 Jan 2010 21:16:05 +0100 Subject: [PATCH 02/21] add extended regs support in bios_interrupt --- disk/i386/pc/biosdisk.c | 28 ++++----- include/grub/i386/pc/int.h | 18 +++--- kern/i386/pc/startup.S | 123 ++++++++++++++++++++++--------------- 3 files changed, 97 insertions(+), 72 deletions(-) diff --git a/disk/i386/pc/biosdisk.c b/disk/i386/pc/biosdisk.c index 0f75dba5f..92198e591 100644 --- a/disk/i386/pc/biosdisk.c +++ b/disk/i386/pc/biosdisk.c @@ -33,29 +33,29 @@ static int grub_biosdisk_rw_int13_extensions (int ah, int drive, void *dap); static int grub_biosdisk_get_num_floppies (void) { - struct grub_cpu_int_registers regs; + struct grub_bios_int_registers regs; int drive; /* reset the disk system first */ - regs.ax = 0; - regs.dx = 0; + regs.eax = 0; + regs.edx = 0; regs.flags = GRUB_CPU_INT_FLAGS_DEFAULT; - grub_cpu_interrupt (0x13, ®s); + grub_bios_interrupt (0x13, ®s); for (drive = 0; drive < 2; drive++) { regs.flags = GRUB_CPU_INT_FLAGS_DEFAULT | GRUB_CPU_INT_FLAGS_CARRY; - regs.dx = drive; + regs.edx = drive; /* call GET DISK TYPE */ - regs.ax = 0x1500; - grub_cpu_interrupt (0x13, ®s); + regs.eax = 0x1500; + grub_bios_interrupt (0x13, ®s); if (regs.flags & GRUB_CPU_INT_FLAGS_CARRY) break; /* check if this drive exists */ - if (!(regs.ax & 0x300)) + if (!(regs.eax & 0x300)) break; } @@ -71,16 +71,16 @@ static int grub_biosdisk_get_num_floppies (void) static int grub_biosdisk_rw_int13_extensions (int ah, int drive, void *dap) { - struct grub_cpu_int_registers regs; - regs.ax = ah << 8; + struct grub_bios_int_registers regs; + regs.eax = ah << 8; /* compute the address of disk_address_packet */ regs.ds = (((grub_addr_t) dap) & 0xffff0000) >> 4; - regs.si = (((grub_addr_t) dap) & 0xffff); - regs.dx = drive; + regs.esi = (((grub_addr_t) dap) & 0xffff); + regs.edx = drive; regs.flags = GRUB_CPU_INT_FLAGS_DEFAULT; - grub_cpu_interrupt (0x13, ®s); - return regs.ax >> 8; + grub_bios_interrupt (0x13, ®s); + return (regs.eax >> 8) & 0xff; } static int diff --git a/include/grub/i386/pc/int.h b/include/grub/i386/pc/int.h index b8cbe3260..e1c463925 100644 --- a/include/grub/i386/pc/int.h +++ b/include/grub/i386/pc/int.h @@ -21,17 +21,18 @@ #include -struct grub_cpu_int_registers +struct grub_bios_int_registers { - grub_uint16_t bx; + grub_uint32_t eax; grub_uint16_t es; - grub_uint16_t cx; - grub_uint16_t ax; - grub_uint16_t dx; grub_uint16_t ds; - grub_uint16_t di; grub_uint16_t flags; - grub_uint16_t si; + grub_uint16_t dummy; + grub_uint32_t ebx; + grub_uint32_t ecx; + grub_uint32_t edi; + grub_uint32_t esi; + grub_uint32_t edx; }; #define GRUB_CPU_INT_FLAGS_CARRY 0x1 @@ -45,6 +46,7 @@ struct grub_cpu_int_registers #define GRUB_CPU_INT_FLAGS_OVERFLOW 0x800 #define GRUB_CPU_INT_FLAGS_DEFAULT GRUB_CPU_INT_FLAGS_INTERRUPT -void EXPORT_FUNC (grub_cpu_interrupt) (grub_uint8_t intno, struct grub_cpu_int_registers *regs); +void EXPORT_FUNC (grub_bios_interrupt) (grub_uint8_t intno, + struct grub_bios_int_registers *regs); #endif diff --git a/kern/i386/pc/startup.S b/kern/i386/pc/startup.S index 815686502..cb6ef32a6 100644 --- a/kern/i386/pc/startup.S +++ b/kern/i386/pc/startup.S @@ -2068,73 +2068,96 @@ FUNCTION(grub_pxe_call) popl %ebp ret -FUNCTION(grub_cpu_interrupt) +FUNCTION(grub_bios_interrupt) pushl %ebp - pushl %esi - pushl %edi - pushl %ebx + pushl %ecx + pushl %eax pushl %edx + movb %al, intno - movl %edx, %esi + movl (%edx), %eax + movl %eax, LOCAL(bios_register_eax) + movw 4(%edx), %ax + movw %ax, LOCAL(bios_register_es) + movw 6(%edx), %ax + movw %ax, LOCAL(bios_register_ds) + movw 8(%edx), %ax + movw %ax, LOCAL(bios_register_flags) - movl 0(%esi), %ebx - movl 4(%esi), %ecx - movl 8(%esi), %edx - movl 12(%esi), %edi - movw 16(%esi), %si + movl 12(%edx), %ebx + movl 16(%edx), %ecx + movl 20(%edx), %edi + movl 24(%edx), %esi + movl 28(%edx), %edx call prot_to_real .code16 - movl %edi, %eax - shrl $16, %eax - push %ax - movl %ebx, %eax - shrl $16, %eax - movw %ax, %es - - movl %edx, %eax - shrl $16, %eax - movw %ax, %ds + mov %ds, %ax + push %ax - movl %ecx, %eax - shrl $16, %eax + /* movw imm16, %ax*/ + .byte 0xb8 +LOCAL(bios_register_es): + .short 0 + movw %ax, %es + /* movw imm16, %ax*/ + .byte 0xb8 +LOCAL(bios_register_ds): + .short 0 + movw %ax, %ds + /* movw imm16, %ax*/ + .byte 0xb8 +LOCAL(bios_register_flags): + .short 0 + push %ax popf + + /* movl imm32, %eax*/ + .byte 0x66, 0xb8 +LOCAL(bios_register_eax): + .long 0 + + /* int imm8. */ .byte 0xcd intno: .byte 0 + movl %eax, %cs:LOCAL(bios_register_eax) + movw %ds, %ax + movw %ax, %cs:LOCAL(bios_register_ds) + pop %ax + mov %ax, %ds pushf - andl $0xffff, %ebx - andl $0xffff, %ecx - andl $0xffff, %edx - andl $0xffff, %edi - - shll $16, %eax - orl %eax, %ecx - - movw %ds, %ax - shll $16, %eax - orl %eax, %edx - - pop %ax - shll $16, %eax - orl %eax, %edi + pop %ax + movw %ax, LOCAL(bios_register_flags) + mov %es, %ax + movw %ax, LOCAL(bios_register_es) DATA32 call real_to_prot .code32 - pushl %esi - movl 4(%esp), %esi - movl %ebx, 0(%esi) - movl %ecx, 4(%esi) - movl %edx, 8(%esi) - movl %edi, 12(%esi) - popl %eax - movw %ax, 16(%esi) - popl %eax - popl %ebx - popl %edi - popl %esi - popl %ebp + + popl %eax + + movl %ebx, 12(%eax) + movl %ecx, 16(%eax) + movl %edi, 20(%eax) + movl %esi, 24(%eax) + movl %edx, 28(%eax) + + movl %eax, %edx + + movl LOCAL(bios_register_eax), %eax + movl %eax, (%edx) + movw LOCAL(bios_register_es), %ax + movw %ax, 4(%edx) + movw LOCAL(bios_register_ds), %ax + movw %ax, 6(%edx) + movw LOCAL(bios_register_flags), %ax + movw %ax, 8(%edx) + + popl %eax + popl %ecx + popl %ebp ret From ed32b24af62fa80f0ca0c6b97c4f971083700cc7 Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Mon, 8 Feb 2010 01:21:54 +0100 Subject: [PATCH 03/21] Save forgotten registers --- kern/i386/pc/startup.S | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/kern/i386/pc/startup.S b/kern/i386/pc/startup.S index e62fc0526..059905bd4 100644 --- a/kern/i386/pc/startup.S +++ b/kern/i386/pc/startup.S @@ -2072,6 +2072,9 @@ FUNCTION(grub_bios_interrupt) pushl %ebp pushl %ecx pushl %eax + pushl %ebx + pushl %esi + pushl %edi pushl %edx movb %al, intno @@ -2157,6 +2160,9 @@ intno: movw LOCAL(bios_register_flags), %ax movw %ax, 8(%edx) + popl %edi + popl %esi + popl %ebx popl %eax popl %ecx popl %ebp From 65936631e410142f4527a2b6121507669c4f0551 Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Sun, 4 Apr 2010 14:24:50 +0200 Subject: [PATCH 04/21] intwrap vbe and vga calls --- conf/i386-pc.rmk | 4 +- include/grub/i386/pc/vbe.h | 70 ++--- include/grub/i386/pc/vga.h | 3 - kern/i386/pc/startup.S | 507 ------------------------------------- term/i386/pc/vga.c | 20 ++ video/i386/pc/vbe.c | 195 ++++++++++++++ 6 files changed, 244 insertions(+), 555 deletions(-) diff --git a/conf/i386-pc.rmk b/conf/i386-pc.rmk index 84e6f1b1e..bef17a25b 100644 --- a/conf/i386-pc.rmk +++ b/conf/i386-pc.rmk @@ -54,8 +54,8 @@ kernel_img_SOURCES = kern/i386/pc/startup.S \ kern/env.c \ term/i386/pc/console.c term/i386/vga_common.c \ symlist.c -kernel_img_HEADERS += machine/biosdisk.h machine/vga.h machine/vbe.h \ - machine/pxe.h i386/pit.h machine/init.h machine/int.h +kernel_img_HEADERS += machine/biosdisk.h machine/pxe.h i386/pit.h \ + machine/init.h machine/int.h kernel_img_CFLAGS = $(COMMON_CFLAGS) $(TARGET_IMG_CFLAGS) kernel_img_ASFLAGS = $(COMMON_ASFLAGS) kernel_img_LDFLAGS = $(COMMON_LDFLAGS) $(TARGET_IMG_LDFLAGS)$(GRUB_KERNEL_MACHINE_LINK_ADDR) $(COMMON_CFLAGS) diff --git a/include/grub/i386/pc/vbe.h b/include/grub/i386/pc/vbe.h index abf246fa1..9b05c2299 100644 --- a/include/grub/i386/pc/vbe.h +++ b/include/grub/i386/pc/vbe.h @@ -169,56 +169,40 @@ struct grub_vbe_palette_data grub_uint8_t alignment; } __attribute__ ((packed)); -/* Prototypes for kernel real mode thunks. */ - +/* Prototypes for helper functions. */ /* Call VESA BIOS 0x4f00 to get VBE Controller Information, return status. */ -grub_vbe_status_t EXPORT_FUNC(grub_vbe_bios_get_controller_info) (struct grub_vbe_info_block *controller_info); - +grub_vbe_status_t +grub_vbe_bios_get_controller_info (struct grub_vbe_info_block *controller_info); /* Call VESA BIOS 0x4f01 to get VBE Mode Information, return status. */ -grub_vbe_status_t EXPORT_FUNC(grub_vbe_bios_get_mode_info) (grub_uint32_t mode, - struct grub_vbe_mode_info_block *mode_info); +grub_vbe_status_t +grub_vbe_bios_get_mode_info (grub_uint32_t mode, + struct grub_vbe_mode_info_block *mode_info); +/* Call VESA BIOS 0x4f03 to return current VBE Mode, return status. */ +grub_vbe_status_t +grub_vbe_bios_get_mode (grub_uint32_t *mode); +/* Call VESA BIOS 0x4f05 to set memory window, return status. */ +grub_vbe_status_t +grub_vbe_bios_set_memory_window (grub_uint32_t window, grub_uint32_t position); +/* Call VESA BIOS 0x4f05 to return memory window, return status. */ +grub_vbe_status_t +grub_vbe_bios_get_memory_window (grub_uint32_t window, + grub_uint32_t *position); +/* Call VESA BIOS 0x4f06 to set scanline length (in bytes), return status. */ +grub_vbe_status_t +grub_vbe_bios_set_scanline_length (grub_uint32_t length); +/* Call VESA BIOS 0x4f06 to return scanline length (in bytes), return status. */ +grub_vbe_status_t +grub_vbe_bios_get_scanline_length (grub_uint32_t *length); +/* Call VESA BIOS 0x4f07 to get display start, return status. */ +grub_vbe_status_t +grub_vbe_bios_get_display_start (grub_uint32_t *x, + grub_uint32_t *y); -grub_vbe_status_t EXPORT_FUNC(grub_vbe_bios_getset_dac_palette_width) (int set, int *width); +grub_vbe_status_t grub_vbe_bios_getset_dac_palette_width (int set, int *width); #define grub_vbe_bios_get_dac_palette_width(width) grub_vbe_bios_getset_dac_palette_width(0, (width)) #define grub_vbe_bios_set_dac_palette_width(width) grub_vbe_bios_getset_dac_palette_width(1, (width)) -/* Call VESA BIOS 0x4f02 to set video mode, return status. */ -grub_vbe_status_t EXPORT_FUNC(grub_vbe_bios_set_mode) (grub_uint32_t mode, - struct grub_vbe_crtc_info_block *crtc_info); - -/* Call VESA BIOS 0x4f03 to return current VBE Mode, return status. */ -grub_vbe_status_t EXPORT_FUNC(grub_vbe_bios_get_mode) (grub_uint32_t *mode); - -/* Call VESA BIOS 0x4f05 to set memory window, return status. */ -grub_vbe_status_t EXPORT_FUNC(grub_vbe_bios_set_memory_window) (grub_uint32_t window, - grub_uint32_t position); - -/* Call VESA BIOS 0x4f05 to return memory window, return status. */ -grub_vbe_status_t EXPORT_FUNC(grub_vbe_bios_get_memory_window) (grub_uint32_t window, - grub_uint32_t *position); - -/* Call VESA BIOS 0x4f06 to set scanline length (in bytes), return status. */ -grub_vbe_status_t EXPORT_FUNC(grub_vbe_bios_set_scanline_length) (grub_uint32_t length); - -/* Call VESA BIOS 0x4f06 to return scanline length (in bytes), return status. */ -grub_vbe_status_t EXPORT_FUNC(grub_vbe_bios_get_scanline_length) (grub_uint32_t *length); - -/* Call VESA BIOS 0x4f07 to set display start, return status. */ -grub_vbe_status_t EXPORT_FUNC(grub_vbe_bios_set_display_start) (grub_uint32_t x, - grub_uint32_t y); - -/* Call VESA BIOS 0x4f07 to get display start, return status. */ -grub_vbe_status_t EXPORT_FUNC(grub_vbe_bios_get_display_start) (grub_uint32_t *x, - grub_uint32_t *y); - -/* Call VESA BIOS 0x4f09 to set palette data, return status. */ -grub_vbe_status_t EXPORT_FUNC(grub_vbe_bios_set_palette_data) (grub_uint32_t color_count, - grub_uint32_t start_index, - struct grub_vbe_palette_data *palette_data); - -/* Prototypes for helper functions. */ - grub_err_t grub_vbe_probe (struct grub_vbe_info_block *info_block); grub_err_t grub_vbe_set_video_mode (grub_uint32_t mode, struct grub_vbe_mode_info_block *mode_info); diff --git a/include/grub/i386/pc/vga.h b/include/grub/i386/pc/vga.h index 2724f6401..ecc169022 100644 --- a/include/grub/i386/pc/vga.h +++ b/include/grub/i386/pc/vga.h @@ -25,7 +25,4 @@ /* The VGA (at the beginning of upper memory). */ #define GRUB_MEMORY_MACHINE_VGA_ADDR GRUB_MEMORY_MACHINE_UPPER -/* Set the video mode to MODE and return the previous mode. */ -unsigned char EXPORT_FUNC(grub_vga_set_mode) (unsigned char mode); - #endif /* ! GRUB_VGA_MACHINE_HEADER */ diff --git a/kern/i386/pc/startup.S b/kern/i386/pc/startup.S index a9e819a9f..8e4bd13bd 100644 --- a/kern/i386/pc/startup.S +++ b/kern/i386/pc/startup.S @@ -1434,513 +1434,6 @@ FUNCTION(grub_get_rtc) popl %ebp ret - -/* - * unsigned char grub_vga_set_mode (unsigned char mode) - */ -FUNCTION(grub_vga_set_mode) - pushl %ebp - pushl %ebx - movl %eax, %ecx - - call prot_to_real - .code16 - /* get current mode */ - xorw %bx, %bx - movb $0x0f, %ah - int $0x10 - movb %al, %dl - - /* set the new mode */ - movb %cl, %al - xorb %ah, %ah - int $0x10 - - DATA32 call real_to_prot - .code32 - - movb %dl, %al - popl %ebx - popl %ebp - ret - -/* - * grub_vbe_bios_status_t grub_vbe_get_controller_info (struct grub_vbe_info_block *controller_info) - * - * Register allocations for parameters: - * %eax *controller_info - */ -FUNCTION(grub_vbe_bios_get_controller_info) - pushl %ebp - pushl %edi - pushl %edx - - movw %ax, %di /* Store *controller_info to %edx:%di. */ - xorw %ax, %ax - shrl $4, %eax - mov %eax, %edx /* prot_to_real destroys %eax. */ - - call prot_to_real - .code16 - - pushw %es - - movw %dx, %es /* *controller_info is now on %es:%di. */ - movw $0x4f00, %ax - int $0x10 - - movw %ax, %dx /* real_to_prot destroys %eax. */ - - popw %es - - DATA32 call real_to_prot - .code32 - - movl %edx, %eax - andl $0x0FFFF, %eax /* Return value in %eax. */ - - pop %edx - popl %edi - popl %ebp - ret - -/* - * grub_vbe_status_t grub_vbe_bios_get_mode_info (grub_uint32_t mode, - * struct grub_vbe_mode_info_block *mode_info) - * - * Register allocations for parameters: - * %eax mode - * %edx *mode_info - */ -FUNCTION(grub_vbe_bios_get_mode_info) - pushl %ebp - pushl %edi - - movl %eax, %ecx /* Store mode number to %ecx. */ - - movw %dx, %di /* Store *mode_info to %edx:%di. */ - xorw %dx, %dx - shrl $4, %edx - - call prot_to_real - .code16 - - pushw %es - - movw %dx, %es /* *mode_info is now on %es:%di. */ - movw $0x4f01, %ax - int $0x10 - - movw %ax, %dx /* real_to_prot destroys %eax. */ - - popw %es - - DATA32 call real_to_prot - .code32 - - movl %edx, %eax - andl $0x0FFFF, %eax /* Return value in %eax. */ - - popl %edi - popl %ebp - ret - -/* - * grub_vbe_status_t grub_vbe_bios_set_mode (grub_uint32_t mode, - * struct grub_vbe_crtc_info_block *crtc_info) - * - * Register allocations for parameters: - * %eax mode - * %edx *crtc_info - */ -FUNCTION(grub_vbe_bios_set_mode) - pushl %ebp - pushl %ebx - pushl %edi - - movl %eax, %ebx /* Store mode in %ebx. */ - - movw %dx, %di /* Store *crtc_info to %edx:%di. */ - xorw %dx, %dx - shrl $4, %edx - - call prot_to_real - .code16 - - pushw %es - - movw %dx, %es /* *crtc_info is now on %es:%di. */ - - movw $0x4f02, %ax - int $0x10 - - movw %ax, %dx /* real_to_prot destroys %eax. */ - - popw %es - - DATA32 call real_to_prot - .code32 - - movw %dx, %ax - andl $0xFFFF, %eax /* Return value in %eax. */ - - popl %edi - popl %ebx - popl %ebp - ret - -/* - * grub_vbe_status_t grub_vbe_bios_get_mode (grub_uint32_t *mode) - * - * Register allocations for parameters: - * %eax *mode - */ -FUNCTION(grub_vbe_bios_get_mode) - pushl %ebp - pushl %ebx - pushl %edi - pushl %edx - pushl %eax /* Push *mode to stack. */ - - call prot_to_real - .code16 - - movw $0x4f03, %ax - int $0x10 - - movw %ax, %dx /* real_to_prot destroys %eax. */ - - DATA32 call real_to_prot - .code32 - - popl %edi /* Pops *mode from stack to %edi. */ - andl $0xFFFF, %ebx - movl %ebx, (%edi) - - movw %dx, %ax - andl $0xFFFF, %eax /* Return value in %eax. */ - - popl %edx - popl %edi - popl %ebx - popl %ebp - ret - -/* - * grub_vbe_status_t grub_vbe_bios_getset_dac_palette_width (int set, int *dac_mask_size) - * - * Register allocations for parameters: - * %eax set - * %edx *dac_mask_size - */ -FUNCTION(grub_vbe_bios_getset_dac_palette_width) - pushl %ebp - pushl %ebx - - xorl %ebx, %ebx - - /* If we only want to fetch the value, set %bl to 1. */ - testl %eax, %eax - jne 1f - incb %bl -1: - - /* Put desired width in %bh. */ - movl (%edx), %eax - movb %al, %bh - - call prot_to_real - .code16 - - movw $0x4f08, %ax - int $0x10 - - movw %ax, %cx /* real_to_prot destroys %eax. */ - - DATA32 call real_to_prot - .code32 - - /* Move result back to *dac_mask_size. */ - xorl %eax, %eax - movb %bh, %al - movl %eax, (%edx) - - /* Return value in %eax. */ - movw %cx, %ax - - popl %ebx - popl %ebp - ret - -/* - * grub_vbe_status_t grub_vbe_bios_set_memory_window (grub_uint32_t window, - * grub_uint32_t position); - * - * Register allocations for parameters: - * %eax window - * %edx position - */ -FUNCTION(grub_vbe_bios_set_memory_window) - pushl %ebp - pushl %ebx - - movl %eax, %ebx - - call prot_to_real - .code16 - - movw $0x4f05, %ax - andw $0x00ff, %bx /* BL = window, BH = 0, Set memory window. */ - int $0x10 - - movw %ax, %dx /* real_to_prot destroys %eax. */ - - DATA32 call real_to_prot - .code32 - - movw %dx, %ax - andl $0xFFFF, %eax /* Return value in %eax. */ - - popl %ebx - popl %ebp - ret - -/* - * grub_vbe_status_t grub_vbe_bios_get_memory_window (grub_uint32_t window, - * grub_uint32_t *position); - * - * Register allocations for parameters: - * %eax window - * %edx *position - */ -FUNCTION(grub_vbe_bios_get_memory_window) - pushl %ebp - pushl %ebx - pushl %edi - pushl %edx /* Push *position to stack. */ - - movl %eax, %ebx /* Store window in %ebx. */ - - call prot_to_real - .code16 - - movw $0x4f05, %ax - andw $0x00ff, %bx /* BL = window. */ - orw $0x0100, %bx /* BH = 1, Get memory window. */ - int $0x10 - - movw %ax, %bx /* real_to_prot destroys %eax. */ - - DATA32 call real_to_prot - .code32 - - popl %edi /* pops *position from stack to %edi. */ - andl $0xFFFF, %edx - movl %edx, (%edi) /* Return position to caller. */ - - movw %bx, %ax - andl $0xFFFF, %eax /* Return value in %eax. */ - - popl %edi - popl %ebx - popl %ebp - ret - -/* - * grub_vbe_status_t grub_vbe_bios_set_scanline_length (grub_uint32_t length) - * - * Register allocations for parameters: - * %eax length - */ -FUNCTION(grub_vbe_bios_set_scanline_length) - pushl %ebp - pushl %ebx - pushl %edx - - movl %eax, %ecx /* Store length in %ecx. */ - - call prot_to_real - .code16 - - movw $0x4f06, %ax - movw $0x0002, %bx /* BL = 2, Set Scan Line in Bytes. */ - int $0x10 - - movw %ax, %dx /* real_to_prot destroys %eax. */ - - DATA32 call real_to_prot - .code32 - - movw %dx, %ax - andl $0xFFFF, %eax /* Return value in %eax. */ - - popl %edx - popl %ebx - popl %ebp - ret - -/* - * grub_vbe_status_t grub_vbe_bios_get_scanline_length (grub_uint32_t *length) - * - * Register allocations for parameters: - * %eax *length - */ -FUNCTION(grub_vbe_bios_get_scanline_length) - pushl %ebp - pushl %ebx - pushl %edi - pushl %edx /* Push *length to stack. */ - - call prot_to_real - .code16 - - movw $0x4f06, %ax - movw $0x0001, %bx /* BL = 1, Get Scan Line Length (in bytes). */ - int $0x10 - - movw %ax, %dx /* real_to_prot destroys %eax. */ - - DATA32 call real_to_prot - .code32 - - popl %edi /* Pops *length from stack to %edi. */ - andl $0xFFFF, %ebx - movl %ebx, (%edi) /* Return length to caller. */ - - movw %dx, %ax - andl $0xFFFF, %eax /* Return value in %eax. */ - - popl %edi - popl %ebx - popl %ebp - ret - -/* - * grub_vbe_status_t grub_vbe_bios_set_display_start (grub_uint32_t x, - * grub_uint32_t y) - * - * Register allocations for parameters: - * %eax x - * %edx y - */ -FUNCTION(grub_vbe_bios_set_display_start) - pushl %ebp - pushl %ebx - - movl %eax, %ecx /* Store x in %ecx. */ - - call prot_to_real - .code16 - - movw $0x4f07, %ax - movw $0x0080, %bx /* BL = 80h, Set Display Start - during Vertical Retrace. */ - int $0x10 - - movw %ax, %dx /* real_to_prot destroys %eax. */ - - DATA32 call real_to_prot - .code32 - - movw %dx, %ax - andl $0xFFFF, %eax /* Return value in %eax. */ - - popl %ebx - popl %ebp - ret - -/* - * grub_vbe_status_t grub_vbe_bios_get_display_start (grub_uint32_t *x, - * grub_uint32_t *y) - * - * Register allocations for parameters: - * %eax *x - * %edx *y - */ -FUNCTION(grub_vbe_bios_get_display_start) - pushl %ebp - pushl %ebx - pushl %edi - pushl %eax /* Push *x to stack. */ - pushl %edx /* Push *y to stack. */ - - call prot_to_real - .code16 - - movw $0x4f07, %ax - movw $0x0001, %bx /* BL = 1, Get Display Start. */ - int $0x10 - - movw %ax, %bx /* real_to_prot destroys %eax. */ - - DATA32 call real_to_prot - .code32 - - popl %edi /* Pops *y from stack to %edi. */ - andl $0xFFFF, %edx - movl %edx, (%edi) /* Return y-position to caller. */ - - popl %edi /* Pops *x from stack to %edi. */ - andl $0xFFFF, %ecx - movl %ecx, (%edi) /* Return x-position to caller. */ - - movw %bx, %ax - andl $0xFFFF, %eax /* Return value in %eax. */ - - popl %edi - popl %ebx - popl %ebp - ret - -/* - * grub_vbe_status_t grub_vbe_bios_set_palette_data (grub_uint32_t color_count, - * grub_uint32_t start_index, - * struct grub_vbe_palette_data *palette_data) - * - * Register allocations for parameters: - * %eax color_count - * %edx start_index - * %ecx *palette_data - */ -FUNCTION(grub_vbe_bios_set_palette_data) - pushl %ebp - pushl %ebx - pushl %edi - - movl %eax, %ebx /* Store color_count in %ebx. */ - - movw %cx, %di /* Store *palette_data to %ecx:%di. */ - xorw %cx, %cx - shrl $4, %ecx - - call prot_to_real - .code16 - - pushw %es - - movw %cx, %es /* *palette_data is now on %es:%di. */ - movw %bx, %cx /* color_count is now on %cx. */ - - movw $0x4f09, %ax - xorw %bx, %bx /* BL = 0, Set Palette Data. */ - int $0x10 - - movw %ax, %dx /* real_to_prot destroys %eax. */ - - popw %es - - DATA32 call real_to_prot - .code32 - - movw %dx, %ax - andl $0xFFFF, %eax /* Return value in %eax. */ - - popl %edi - popl %ebx - popl %ebp - ret - - pxe_rm_entry: .long 0 diff --git a/term/i386/pc/vga.c b/term/i386/pc/vga.c index 402b30fe6..85c516b6a 100644 --- a/term/i386/pc/vga.c +++ b/term/i386/pc/vga.c @@ -19,6 +19,7 @@ // TODO: Deprecated and broken. Needs to be converted to Video Driver! #include +#include #include #include #include @@ -82,6 +83,25 @@ static grub_font_t font = 0; #define INPUT_STATUS1_REGISTER 0x3DA #define INPUT_STATUS1_VERTR_BIT 0x08 +static unsigned char +grub_vga_set_mode (unsigned char mode) +{ + struct grub_bios_int_registers regs; + unsigned char ret; + /* get current mode */ + regs.eax = 0x0f00; + regs.ebx = 0; + regs.flags = GRUB_CPU_INT_FLAGS_DEFAULT; + grub_bios_interrupt (0x10, ®s); + + ret = regs.eax & 0xff; + regs.eax = mode; + regs.flags = GRUB_CPU_INT_FLAGS_DEFAULT; + grub_bios_interrupt (0x10, ®s); + + return ret; +} + static inline void wait_vretrace (void) { diff --git a/video/i386/pc/vbe.c b/video/i386/pc/vbe.c index 72b8f1831..45ba86227 100644 --- a/video/i386/pc/vbe.c +++ b/video/i386/pc/vbe.c @@ -28,6 +28,7 @@ #include #include #include +#include static int vbe_detected = -1; @@ -71,6 +72,200 @@ real2pm (grub_vbe_farptr_t ptr) + ((unsigned long) ptr & 0x0000FFFF)); } +/* Call VESA BIOS 0x4f09 to set palette data, return status. */ +static grub_vbe_status_t +grub_vbe_bios_set_palette_data (grub_uint32_t color_count, + grub_uint32_t start_index, + struct grub_vbe_palette_data *palette_data) +{ + struct grub_bios_int_registers regs; + regs.eax = 0x4f09; + regs.ebx = 0; + regs.ecx = color_count; + regs.edx = start_index; + regs.es = (((grub_addr_t) palette_data) & 0xffff0000) >> 4; + regs.edi = ((grub_addr_t) palette_data) & 0xffff; + regs.flags = GRUB_CPU_INT_FLAGS_DEFAULT; + grub_bios_interrupt (0x10, ®s); + return regs.eax & 0xffff; +} + +/* Call VESA BIOS 0x4f00 to get VBE Controller Information, return status. */ +grub_vbe_status_t +grub_vbe_bios_get_controller_info (struct grub_vbe_info_block *ci) +{ + struct grub_bios_int_registers regs; + /* Store *controller_info to %es:%di. */ + regs.es = (((grub_addr_t) ci) & 0xffff0000) >> 4; + regs.edi = ((grub_addr_t) ci) & 0xffff; + regs.eax = 0x4f00; + regs.flags = GRUB_CPU_INT_FLAGS_DEFAULT; + grub_bios_interrupt (0x10, ®s); + return regs.eax & 0xffff; +} + +/* Call VESA BIOS 0x4f01 to get VBE Mode Information, return status. */ +grub_vbe_status_t +grub_vbe_bios_get_mode_info (grub_uint32_t mode, + struct grub_vbe_mode_info_block *mode_info) +{ + struct grub_bios_int_registers regs; + regs.eax = 0x4f01; + regs.ecx = mode; + /* Store *mode_info to %es:%di. */ + regs.es = ((grub_addr_t) mode_info & 0xffff0000) >> 4; + regs.edi = (grub_addr_t) mode_info & 0x0000ffff; + regs.flags = GRUB_CPU_INT_FLAGS_DEFAULT; + grub_bios_interrupt (0x10, ®s); + return regs.eax & 0xffff; +} + +/* Call VESA BIOS 0x4f02 to set video mode, return status. */ +static grub_vbe_status_t +grub_vbe_bios_set_mode (grub_uint32_t mode, + struct grub_vbe_crtc_info_block *crtc_info) +{ + struct grub_bios_int_registers regs; + + regs.eax = 0x4f02; + regs.ebx = mode; + /* Store *crtc_info to %es:%di. */ + regs.es = (((grub_addr_t) crtc_info) & 0xffff0000) >> 4; + regs.edi = ((grub_addr_t) crtc_info) & 0xffff; + regs.flags = GRUB_CPU_INT_FLAGS_DEFAULT; + grub_bios_interrupt (0x10, ®s); + + return regs.eax & 0xffff; +} + +/* Call VESA BIOS 0x4f03 to return current VBE Mode, return status. */ +grub_vbe_status_t +grub_vbe_bios_get_mode (grub_uint32_t *mode) +{ + struct grub_bios_int_registers regs; + + regs.eax = 0x4f03; + regs.flags = GRUB_CPU_INT_FLAGS_DEFAULT; + grub_bios_interrupt (0x10, ®s); + *mode = regs.ebx & 0xffff; + + return regs.eax & 0xffff; +} + +grub_vbe_status_t +grub_vbe_bios_getset_dac_palette_width (int set, int *dac_mask_size) +{ + struct grub_bios_int_registers regs; + + regs.eax = 0x4f08; + regs.ebx = (*dac_mask_size & 0xff) >> 8; + regs.ebx = set ? 1 : 0; + regs.flags = GRUB_CPU_INT_FLAGS_DEFAULT; + grub_bios_interrupt (0x10, ®s); + *dac_mask_size = (regs.ebx >> 8) & 0xff; + + return regs.eax & 0xffff; +} + +/* Call VESA BIOS 0x4f05 to set memory window, return status. */ +grub_vbe_status_t +grub_vbe_bios_set_memory_window (grub_uint32_t window, + grub_uint32_t position) +{ + struct grub_bios_int_registers regs; + + /* BL = window, BH = 0, Set memory window. */ + regs.ebx = window & 0x00ff; + regs.edx = position; + regs.eax = 0x4f05; + regs.flags = GRUB_CPU_INT_FLAGS_DEFAULT; + grub_bios_interrupt (0x10, ®s); + return regs.eax & 0xffff; +} + +/* Call VESA BIOS 0x4f05 to return memory window, return status. */ +grub_vbe_status_t +grub_vbe_bios_get_memory_window (grub_uint32_t window, + grub_uint32_t *position) +{ + struct grub_bios_int_registers regs; + + regs.eax = 0x4f05; + /* BH = 1, Get memory window. BL = window. */ + regs.ebx = (window & 0x00ff) | 0x100; + regs.flags = GRUB_CPU_INT_FLAGS_DEFAULT; + grub_bios_interrupt (0x10, ®s); + + *position = regs.edx & 0xffff; + return regs.eax & 0xffff; +} + +/* Call VESA BIOS 0x4f06 to set scanline length (in bytes), return status. */ +grub_vbe_status_t +grub_vbe_bios_set_scanline_length (grub_uint32_t length) +{ + struct grub_bios_int_registers regs; + + regs.ecx = length; + regs.eax = 0x4f06; + /* BL = 2, Set Scan Line in Bytes. */ + regs.ebx = 0x0002; + regs.flags = GRUB_CPU_INT_FLAGS_DEFAULT; + grub_bios_interrupt (0x10, ®s); + return regs.eax & 0xffff; +} + +/* Call VESA BIOS 0x4f06 to return scanline length (in bytes), return status. */ +grub_vbe_status_t +grub_vbe_bios_get_scanline_length (grub_uint32_t *length) +{ + struct grub_bios_int_registers regs; + + regs.eax = 0x4f06; + regs.ebx = 0x0001; + regs.flags = GRUB_CPU_INT_FLAGS_DEFAULT; + /* BL = 1, Get Scan Line Length (in bytes). */ + grub_bios_interrupt (0x10, ®s); + + *length = regs.ebx & 0xffff; + return regs.eax & 0xffff; +} + +/* Call VESA BIOS 0x4f07 to set display start, return status. */ +static grub_vbe_status_t +grub_vbe_bios_set_display_start (grub_uint32_t x, grub_uint32_t y) +{ + struct grub_bios_int_registers regs; + + /* Store x in %ecx. */ + regs.ecx = x; + regs.edx = y; + regs.eax = 0x4f07; + /* BL = 80h, Set Display Start during Vertical Retrace. */ + regs.ebx = 0x0080; + regs.flags = GRUB_CPU_INT_FLAGS_DEFAULT; + grub_bios_interrupt (0x10, ®s); + return regs.eax & 0xffff; +} + +/* Call VESA BIOS 0x4f07 to get display start, return status. */ +grub_vbe_status_t +grub_vbe_bios_get_display_start (grub_uint32_t *x, + grub_uint32_t *y) +{ + struct grub_bios_int_registers regs; + + regs.eax = 0x4f07; + /* BL = 1, Get Display Start. */ + regs.ebx = 0x0001; + regs.flags = GRUB_CPU_INT_FLAGS_DEFAULT; + grub_bios_interrupt (0x10, ®s); + + *x = regs.ecx & 0xffff; + *y = regs.edx & 0xffff; + return regs.eax & 0xffff; +} + grub_err_t grub_vbe_probe (struct grub_vbe_info_block *info_block) { From 1b8cb8573bca47fbf959be2b7c5f5da868c09735 Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Sun, 4 Apr 2010 15:49:06 +0200 Subject: [PATCH 05/21] intwrap grub_pxe_scan --- fs/i386/pc/pxe.c | 56 +++++++++++++++++++++++++++++----- include/grub/i386/pc/pxe.h | 5 ++-- kern/i386/pc/startup.S | 61 ++------------------------------------ 3 files changed, 53 insertions(+), 69 deletions(-) diff --git a/fs/i386/pc/pxe.c b/fs/i386/pc/pxe.c index 82d8ee583..0a279df45 100644 --- a/fs/i386/pc/pxe.c +++ b/fs/i386/pc/pxe.c @@ -27,6 +27,7 @@ #include #include +#include #include #define SEGMENT(x) ((x) >> 4) @@ -55,6 +56,45 @@ struct grub_pxe_data char filename[0]; }; +static grub_uint32_t pxe_rm_entry = 0; + +static struct grub_pxenv * +grub_pxe_scan (void) +{ + struct grub_bios_int_registers regs; + struct grub_pxenv *ret; + void *pxe; + + regs.flags = GRUB_CPU_INT_FLAGS_DEFAULT; + + regs.ebx = 0; + regs.ecx = 0; + regs.eax = 0x5650; + + grub_bios_interrupt (0x1a, ®s); + + if ((regs.eax & 0xffff) != 0x564e) + return NULL; + ret = (struct grub_pxenv *) ((regs.es << 4) + (regs.ebx & 0xffff)); + if (grub_memcmp (ret->signature, GRUB_PXE_SIGNATURE, sizeof (ret->signature)) + != 0) + return NULL; + if (ret->version < 0x201) + return NULL; + + pxe = (void *) ((((ret->pxe_ptr & 0xffff0000) >> 16) << 4) + + (ret->pxe_ptr & 0xffff)); + if (!pxe) + return NULL; + + /* !PXE */ + if (*(grub_uint32_t *) pxe != 0x45585021) + return NULL; + + pxe_rm_entry = ret->rm_entry; + return ret; +} + static int grub_pxe_iterate (int (*hook) (const char *name)) { @@ -202,14 +242,14 @@ grub_pxefs_open (struct grub_file *file, const char *name) if (curr_file != 0) { - grub_pxe_call (GRUB_PXENV_TFTP_CLOSE, &c.c2); + grub_pxe_call (GRUB_PXENV_TFTP_CLOSE, &c.c2, pxe_rm_entry); curr_file = 0; } c.c1.server_ip = disk_data->server_ip; c.c1.gateway_ip = disk_data->gateway_ip; grub_strcpy ((char *)&c.c1.filename[0], name); - grub_pxe_call (GRUB_PXENV_TFTP_GET_FSIZE, &c.c1); + grub_pxe_call (GRUB_PXENV_TFTP_GET_FSIZE, &c.c1, pxe_rm_entry); if (c.c1.status) return grub_error (GRUB_ERR_FILE_NOT_FOUND, "file not found"); @@ -217,7 +257,7 @@ grub_pxefs_open (struct grub_file *file, const char *name) c.c2.tftp_port = grub_cpu_to_be16 (GRUB_PXE_TFTP_PORT); c.c2.packet_size = grub_pxe_blksize; - grub_pxe_call (GRUB_PXENV_TFTP_OPEN, &c.c2); + grub_pxe_call (GRUB_PXENV_TFTP_OPEN, &c.c2, pxe_rm_entry); if (c.c2.status) return grub_error (GRUB_ERR_BAD_FS, "open fails"); @@ -275,14 +315,14 @@ grub_pxefs_read (grub_file_t file, char *buf, grub_size_t len) struct grub_pxenv_tftp_open o; if (curr_file != 0) - grub_pxe_call (GRUB_PXENV_TFTP_CLOSE, &o); + grub_pxe_call (GRUB_PXENV_TFTP_CLOSE, &o, pxe_rm_entry); o.server_ip = disk_data->server_ip; o.gateway_ip = disk_data->gateway_ip; grub_strcpy ((char *)&o.filename[0], data->filename); o.tftp_port = grub_cpu_to_be16 (GRUB_PXE_TFTP_PORT); o.packet_size = grub_pxe_blksize; - grub_pxe_call (GRUB_PXENV_TFTP_OPEN, &o); + grub_pxe_call (GRUB_PXENV_TFTP_OPEN, &o, pxe_rm_entry); if (o.status) { grub_error (GRUB_ERR_BAD_FS, "open fails"); @@ -297,7 +337,7 @@ grub_pxefs_read (grub_file_t file, char *buf, grub_size_t len) while (pn >= data->packet_number) { c.buffer_size = data->block_size; - grub_pxe_call (GRUB_PXENV_TFTP_READ, &c); + grub_pxe_call (GRUB_PXENV_TFTP_READ, &c, pxe_rm_entry); if (c.status) { grub_error (GRUB_ERR_BAD_FS, "read fails"); @@ -318,7 +358,7 @@ grub_pxefs_close (grub_file_t file) if (curr_file == file) { - grub_pxe_call (GRUB_PXENV_TFTP_CLOSE, &c); + grub_pxe_call (GRUB_PXENV_TFTP_CLOSE, &c, pxe_rm_entry); curr_file = 0; } @@ -454,7 +494,7 @@ grub_pxe_detect (void) ci.packet_type = GRUB_PXENV_PACKET_TYPE_DHCP_ACK; ci.buffer = 0; ci.buffer_size = 0; - grub_pxe_call (GRUB_PXENV_GET_CACHED_INFO, &ci); + grub_pxe_call (GRUB_PXENV_GET_CACHED_INFO, &ci, pxe_rm_entry); if (ci.status) return; diff --git a/include/grub/i386/pc/pxe.h b/include/grub/i386/pc/pxe.h index 39f356c83..049dd1950 100644 --- a/include/grub/i386/pc/pxe.h +++ b/include/grub/i386/pc/pxe.h @@ -168,6 +168,8 @@ #ifndef ASM_FILE +#define GRUB_PXE_SIGNATURE "PXENV+" + struct grub_pxenv { grub_uint8_t signature[6]; /* 'PXENV+'. */ @@ -302,8 +304,7 @@ struct grub_pxenv_unload_stack grub_uint8_t reserved[10]; } __attribute__ ((packed)); -struct grub_pxenv * EXPORT_FUNC(grub_pxe_scan) (void); -int EXPORT_FUNC(grub_pxe_call) (int func, void * data); +int EXPORT_FUNC(grub_pxe_call) (int func, void * data, grub_uint32_t pxe_rm_entry); extern struct grub_pxenv *grub_pxe_pxenv; diff --git a/kern/i386/pc/startup.S b/kern/i386/pc/startup.S index 8e4bd13bd..ef58c738c 100644 --- a/kern/i386/pc/startup.S +++ b/kern/i386/pc/startup.S @@ -1434,65 +1434,8 @@ FUNCTION(grub_get_rtc) popl %ebp ret -pxe_rm_entry: - .long 0 - /* - * struct grub_pxenv *grub_pxe_scan (void); - */ -FUNCTION(grub_pxe_scan) - pushl %ebp - pushl %ebx - - xorl %ebx, %ebx - xorl %ecx, %ecx - - call prot_to_real - .code16 - - pushw %es - - movw $0x5650, %ax - int $0x1A - cmpw $0x564E, %ax - jnz 1f - cmpl $0x4E455850, %es:(%bx) /* PXEN(V+) */ - jnz 1f - cmpw $0x201, %es:6(%bx) /* API version */ - jb 1f - lesw %es:0x28(%bx), %bx /* !PXE structure */ - cmpl $0x45585021, %es:(%bx) /* !PXE */ - jnz 1f - movw %es, %cx - jmp 2f -1: - xorw %bx, %bx - xorw %cx, %cx -2: - - popw %es - - DATA32 call real_to_prot - .code32 - - xorl %eax, %eax - leal (%eax, %ecx, 4), %ecx - leal (%ebx, %ecx, 4), %eax /* eax = ecx * 16 + ebx */ - - orl %eax, %eax - jz 1f - - movl 0x10(%eax), %ecx - movl %ecx, pxe_rm_entry - -1: - - popl %ebx - popl %ebp - ret - -/* - * int grub_pxe_call (int func, void* data); + * int grub_pxe_call (int func, void* data, grub_uint32_t pxe_rm_entry); */ FUNCTION(grub_pxe_call) pushl %ebp @@ -1501,13 +1444,13 @@ FUNCTION(grub_pxe_call) pushl %edi pushl %ebx + movl %ecx, %ebx movl %eax, %ecx movl %edx, %eax andl $0xF, %eax shrl $4, %edx shll $16, %edx addl %eax, %edx - movl pxe_rm_entry, %ebx call prot_to_real .code16 From 42c4f0001610dd487f9af1a7e22a05bc3bf33001 Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Sun, 4 Apr 2010 18:42:48 +0200 Subject: [PATCH 06/21] intwrapped halt --- commands/i386/pc/halt.c | 64 +++++++++++++++++++++++++++++++++++++++++ include/grub/misc.h | 2 +- kern/i386/pc/startup.S | 60 -------------------------------------- 3 files changed, 65 insertions(+), 61 deletions(-) diff --git a/commands/i386/pc/halt.c b/commands/i386/pc/halt.c index 4c39612ae..c237fe361 100644 --- a/commands/i386/pc/halt.c +++ b/commands/i386/pc/halt.c @@ -21,6 +21,7 @@ #include #include #include +#include static const struct grub_arg_option options[] = { @@ -28,6 +29,69 @@ static const struct grub_arg_option options[] = {0, 0, 0, 0, 0, 0} }; +static inline void __attribute__ ((noreturn)) +stop (void) +{ + while (1) + { + asm volatile ("hlt"); + } +} +/* + * Halt the system, using APM if possible. If NO_APM is true, don't use + * APM even if it is available. + */ +void +grub_halt (int no_apm) +{ + struct grub_bios_int_registers regs; + + if (no_apm) + stop (); + + /* detect APM */ + regs.eax = 0x5300; + regs.ebx = 0; + regs.flags = GRUB_CPU_INT_FLAGS_DEFAULT; + grub_bios_interrupt (0x15, ®s); + + if (regs.flags & GRUB_CPU_INT_FLAGS_CARRY) + stop (); + + /* disconnect APM first */ + regs.eax = 0x5304; + regs.ebx = 0; + regs.flags = GRUB_CPU_INT_FLAGS_DEFAULT; + grub_bios_interrupt (0x15, ®s); + + /* connect APM */ + regs.eax = 0x5301; + regs.ebx = 0; + regs.flags = GRUB_CPU_INT_FLAGS_DEFAULT; + grub_bios_interrupt (0x15, ®s); + if (regs.flags & GRUB_CPU_INT_FLAGS_CARRY) + stop (); + + /* set APM protocol level - 1.1 or bust. (this covers APM 1.2 also) */ + regs.eax = 0x530E; + regs.ebx = 0; + regs.ecx = 0x0101; + regs.flags = GRUB_CPU_INT_FLAGS_DEFAULT; + grub_bios_interrupt (0x15, ®s); + if (regs.flags & GRUB_CPU_INT_FLAGS_CARRY) + stop (); + + /* set the power state to off */ + regs.eax = 0x5307; + regs.ebx = 1; + regs.ecx = 3; + regs.flags = GRUB_CPU_INT_FLAGS_DEFAULT; + grub_bios_interrupt (0x15, ®s); + + /* shouldn't reach here */ + stop (); +} + static grub_err_t grub_cmd_halt (grub_extcmd_t cmd, int argc __attribute__ ((unused)), diff --git a/include/grub/misc.h b/include/grub/misc.h index 61174c38d..95c7664f1 100644 --- a/include/grub/misc.h +++ b/include/grub/misc.h @@ -298,7 +298,7 @@ void EXPORT_FUNC (grub_reboot) (void); #ifdef GRUB_MACHINE_PCBIOS /* Halt the system, using APM if possible. If NO_APM is true, don't * use APM even if it is available. */ -void EXPORT_FUNC (grub_halt) (int no_apm); +void grub_halt (int no_apm); #else void EXPORT_FUNC (grub_halt) (void); #endif diff --git a/kern/i386/pc/startup.S b/kern/i386/pc/startup.S index ef58c738c..4c7c74ec7 100644 --- a/kern/i386/pc/startup.S +++ b/kern/i386/pc/startup.S @@ -450,16 +450,6 @@ gate_a20_check_state: */ . = _start + GRUB_KERNEL_MACHINE_RAW_SIZE - /* - * This next part is sort of evil. It takes advantage of the - * byte ordering on the x86 to work in either 16-bit or 32-bit - * mode, so think about it before changing it. - */ - -FUNCTION(grub_hard_stop) - hlt - jmp EXT_C(grub_hard_stop) - /* * grub_stop_floppy() @@ -486,56 +476,6 @@ FUNCTION(grub_exit) jmp cold_reboot .code32 -/* - * grub_halt(int no_apm) - * - * Halt the system, using APM if possible. If NO_APM is true, don't use - * APM even if it is available. - */ -FUNCTION(grub_halt) - /* see if zero */ - testl %eax, %eax - jnz EXT_C(grub_stop) - - call prot_to_real - .code16 - - /* detect APM */ - movw $0x5300, %ax - xorw %bx, %bx - int $0x15 - jc EXT_C(grub_hard_stop) - /* don't check %bx for buggy BIOSes... */ - - /* disconnect APM first */ - movw $0x5304, %ax - xorw %bx, %bx - int $0x15 - - /* connect APM */ - movw $0x5301, %ax - xorw %bx, %bx - int $0x15 - jc EXT_C(grub_hard_stop) - - /* set APM protocol level - 1.1 or bust. (this covers APM 1.2 also) */ - movw $0x530E, %ax - xorw %bx, %bx - movw $0x0101, %cx - int $0x15 - jc EXT_C(grub_hard_stop) - - /* set the power state to off */ - movw $0x5307, %ax - movw $1, %bx - movw $3, %cx - int $0x15 - - /* shouldn't reach here */ - jmp EXT_C(grub_hard_stop) - .code32 - - /* * void grub_chainloader_real_boot (int drive, void *part_addr) * From 77356db852a5866ccef6cf1025fefff27a1ac279 Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Sun, 4 Apr 2010 18:43:26 +0200 Subject: [PATCH 07/21] Intwrapped biosdisk --- conf/i386-pc.rmk | 3 +- disk/i386/pc/biosdisk.c | 160 ++++++++++++++++++++ include/grub/i386/pc/biosdisk.h | 12 -- include/grub/i386/pc/init.h | 2 +- kern/i386/pc/startup.S | 257 -------------------------------- 5 files changed, 162 insertions(+), 272 deletions(-) diff --git a/conf/i386-pc.rmk b/conf/i386-pc.rmk index bef17a25b..39554594c 100644 --- a/conf/i386-pc.rmk +++ b/conf/i386-pc.rmk @@ -54,8 +54,7 @@ kernel_img_SOURCES = kern/i386/pc/startup.S \ kern/env.c \ term/i386/pc/console.c term/i386/vga_common.c \ symlist.c -kernel_img_HEADERS += machine/biosdisk.h machine/pxe.h i386/pit.h \ - machine/init.h machine/int.h +kernel_img_HEADERS += machine/pxe.h i386/pit.h machine/int.h kernel_img_CFLAGS = $(COMMON_CFLAGS) $(TARGET_IMG_CFLAGS) kernel_img_ASFLAGS = $(COMMON_ASFLAGS) kernel_img_LDFLAGS = $(COMMON_LDFLAGS) $(TARGET_IMG_LDFLAGS)$(GRUB_KERNEL_MACHINE_LINK_ADDR) $(COMMON_CFLAGS) diff --git a/disk/i386/pc/biosdisk.c b/disk/i386/pc/biosdisk.c index 4fc29023b..71b516422 100644 --- a/disk/i386/pc/biosdisk.c +++ b/disk/i386/pc/biosdisk.c @@ -83,6 +83,166 @@ grub_biosdisk_rw_int13_extensions (int ah, int drive, void *dap) return (regs.eax >> 8) & 0xff; } +/* + * Call standard and old INT13 (int 13 %ah=AH) for DRIVE. Read/write + * NSEC sectors from COFF/HOFF/SOFF into SEGMENT. If an error occurs, + * return non-zero, otherwise zero. + */ +static int +grub_biosdisk_rw_standard (int ah, int drive, int coff, int hoff, + int soff, int nsec, int segment) +{ + int ret, i; + + /* Try 3 times. */ + for (i = 0; i < 3; i++) + { + struct grub_bios_int_registers regs; + + /* set up CHS information */ + /* set %ch to low eight bits of cylinder */ + regs.ecx = (coff << 8) & 0xff00; + /* set bits 6-7 of %cl to high two bits of cylinder */ + regs.ecx |= (coff >> 2) & 0xc0; + /* set bits 0-5 of %cl to sector */ + regs.ecx |= soff & 0x3f; + + /* set %dh to head and %dl to drive */ + regs.edx = (drive & 0xff) | ((hoff << 8) & 0xff00); + /* set %ah to AH */ + regs.eax = (ah << 8) & 0xff00; + /* set %al to NSEC */ + regs.eax |= nsec & 0xff; + + regs.ebx = 0; + regs.es = segment; + + regs.flags = GRUB_CPU_INT_FLAGS_DEFAULT; + + grub_bios_interrupt (0x13, ®s); + /* check if successful */ + if (!(regs.flags & GRUB_CPU_INT_FLAGS_CARRY)) + return 0; + + /* save return value */ + ret = regs.eax >> 8; + + /* if fail, reset the disk system */ + regs.eax = 0; + regs.edx = (drive & 0xff); + regs.flags = GRUB_CPU_INT_FLAGS_DEFAULT; + grub_bios_interrupt (0x13, ®s); + } + return ret; +} + +/* + * Check if LBA is supported for DRIVE. If it is supported, then return + * the major version of extensions, otherwise zero. + */ +static int +grub_biosdisk_check_int13_extensions (int drive) +{ + struct grub_bios_int_registers regs; + + regs.edx = drive & 0xff; + regs.eax = 0x4100; + regs.ebx = 0x55aa; + regs.flags = GRUB_CPU_INT_FLAGS_DEFAULT; + grub_bios_interrupt (0x13, ®s); + + if (regs.flags & GRUB_CPU_INT_FLAGS_CARRY) + return 0; + + if ((regs.ebx & 0xffff) != 0xaa55) + return 0; + + /* check if AH=0x42 is supported */ + if (!(regs.ecx & 1)) + return 0; + + return (regs.eax >> 8) & 0xff; +} + +/* + * Return the geometry of DRIVE in CYLINDERS, HEADS and SECTORS. If an + * error occurs, then return non-zero, otherwise zero. + */ +static int +grub_biosdisk_get_diskinfo_standard (int drive, + unsigned long *cylinders, + unsigned long *heads, + unsigned long *sectors) +{ + struct grub_bios_int_registers regs; + + regs.eax = 0x0800; + regs.edx = drive & 0xff; + + regs.flags = GRUB_CPU_INT_FLAGS_DEFAULT; + grub_bios_interrupt (0x13, ®s); + + /* Check if unsuccessful. Ignore return value if carry isn't set to + workaround some buggy BIOSes. */ + if ((regs.flags & GRUB_CPU_INT_FLAGS_CARRY) && ((regs.eax & 0xff00) != 0)) + return (regs.eax & 0xff00) >> 8; + + /* bogus BIOSes may not return an error number */ + /* 0 sectors means no disk */ + if (!(regs.ecx & 0x3f)) + /* XXX 0x60 is one of the unused error numbers */ + return 0x60; + + /* the number of heads is counted from zero */ + *heads = ((regs.edx >> 8) & 0xff) + 1; + *cylinders = (((regs.ecx >> 8) & 0xff) | ((regs.ecx << 2) & 0x0300)) + 1; + *sectors = regs.ecx & 0x3f; + return 0; +} + +static int +grub_biosdisk_get_diskinfo_real (int drive, void *drp, grub_uint16_t ax) +{ + struct grub_bios_int_registers regs; + + regs.eax = ax; + + /* compute the address of drive parameters */ + regs.esi = ((grub_addr_t) drp) & 0xf; + regs.ds = ((grub_addr_t) drp) >> 4; + regs.edx = drive & 0xff; + + regs.flags = GRUB_CPU_INT_FLAGS_DEFAULT; + grub_bios_interrupt (0x13, ®s); + + /* Check if unsuccessful. Ignore return value if carry isn't set to + workaround some buggy BIOSes. */ + if ((regs.flags & GRUB_CPU_INT_FLAGS_CARRY) && ((regs.eax & 0xff00) != 0)) + return (regs.eax & 0xff00) >> 8; + + return 0; +} + +/* + * Return the cdrom information of DRIVE in CDRP. If an error occurs, + * then return non-zero, otherwise zero. + */ +static int +grub_biosdisk_get_cdinfo_int13_extensions (int drive, void *cdrp) +{ + return grub_biosdisk_get_diskinfo_real (drive, cdrp, 0x4b01); +} + +/* + * Return the geometry of DRIVE in a drive parameters, DRP. If an error + * occurs, then return non-zero, otherwise zero. + */ +static int +grub_biosdisk_get_diskinfo_int13_extensions (int drive, void *drp) +{ + return grub_biosdisk_get_diskinfo_real (drive, drp, 0x4800); +} + static int grub_biosdisk_get_drive (const char *name) { diff --git a/include/grub/i386/pc/biosdisk.h b/include/grub/i386/pc/biosdisk.h index 83d833cad..69a240a2e 100644 --- a/include/grub/i386/pc/biosdisk.h +++ b/include/grub/i386/pc/biosdisk.h @@ -106,18 +106,6 @@ struct grub_biosdisk_dap grub_uint64_t block; } __attribute__ ((packed)); -int EXPORT_FUNC(grub_biosdisk_rw_standard) (int ah, int drive, int coff, int hoff, - int soff, int nsec, int segment); -int EXPORT_FUNC(grub_biosdisk_check_int13_extensions) (int drive); -int EXPORT_FUNC(grub_biosdisk_get_diskinfo_int13_extensions) (int drive, - void *drp); -int EXPORT_FUNC(grub_biosdisk_get_cdinfo_int13_extensions) (int drive, - void *cdrp); -int EXPORT_FUNC(grub_biosdisk_get_diskinfo_standard) (int drive, - unsigned long *cylinders, - unsigned long *heads, - unsigned long *sectors); - void grub_biosdisk_init (void); void grub_biosdisk_fini (void); diff --git a/include/grub/i386/pc/init.h b/include/grub/i386/pc/init.h index 2be80e773..30130d189 100644 --- a/include/grub/i386/pc/init.h +++ b/include/grub/i386/pc/init.h @@ -33,7 +33,7 @@ grub_uint32_t grub_get_eisa_mmap (void); /* Get a memory map entry. Return next continuation value. Zero means the end. */ -grub_uint32_t EXPORT_FUNC(grub_get_mmap_entry) (struct grub_machine_mmap_entry *entry, +grub_uint32_t grub_get_mmap_entry (struct grub_machine_mmap_entry *entry, grub_uint32_t cont); /* Turn on/off Gate A20. */ diff --git a/kern/i386/pc/startup.S b/kern/i386/pc/startup.S index 4c7c74ec7..6733e12bc 100644 --- a/kern/i386/pc/startup.S +++ b/kern/i386/pc/startup.S @@ -505,263 +505,6 @@ FUNCTION(grub_chainloader_real_boot) #include "../loader.S" -/* - * int grub_biosdisk_rw_standard (int ah, int drive, int coff, int hoff, - * int soff, int nsec, int segment) - * - * Call standard and old INT13 (int 13 %ah=AH) for DRIVE. Read/write - * NSEC sectors from COFF/HOFF/SOFF into SEGMENT. If an error occurs, - * return non-zero, otherwise zero. - */ - -FUNCTION(grub_biosdisk_rw_standard) - pushl %ebp - movl %esp, %ebp - - pushl %ebx - pushl %edi - pushl %esi - - /* set up CHS information */ - - /* set %ch to low eight bits of cylinder */ - xchgb %cl, %ch - /* set bits 6-7 of %cl to high two bits of cylinder */ - shlb $6, %cl - /* set bits 0-5 of %cl to sector */ - addb 0xc(%ebp), %cl - /* set %dh to head */ - movb 0x8(%ebp), %dh - /* set %ah to AH */ - movb %al, %ah - /* set %al to NSEC */ - movb 0x10(%ebp), %al - /* save %ax in %di */ - movw %ax, %di - /* save SEGMENT in %bx */ - movw 0x14(%ebp), %bx - - /* enter real mode */ - call prot_to_real - - .code16 - movw %bx, %es - xorw %bx, %bx - movw $3, %si /* attempt at least three times */ - -1: - movw %di, %ax - int $0x13 /* do the operation */ - jnc 2f /* check if successful */ - - movb %ah, %bl /* save return value */ - /* if fail, reset the disk system */ - xorw %ax, %ax - int $0x13 - - decw %si - cmpw $0, %si - je 2f - xorb %bl, %bl - jmp 1b /* retry */ -2: - /* back to protected mode */ - DATA32 call real_to_prot - .code32 - - movb %bl, %al /* return value in %eax */ - - popl %esi - popl %edi - popl %ebx - popl %ebp - - ret $(4 * 4) - - -/* - * int grub_biosdisk_check_int13_extensions (int drive) - * - * Check if LBA is supported for DRIVE. If it is supported, then return - * the major version of extensions, otherwise zero. - */ - -FUNCTION(grub_biosdisk_check_int13_extensions) - pushl %ebp - pushl %ebx - - /* drive */ - movb %al, %dl - /* enter real mode */ - call prot_to_real - - .code16 - movb $0x41, %ah - movw $0x55aa, %bx - int $0x13 /* do the operation */ - - /* check the result */ - jc 1f - cmpw $0xaa55, %bx - jne 1f - - movb %ah, %bl /* save the major version into %bl */ - - /* check if AH=0x42 is supported */ - andw $1, %cx - jnz 2f - -1: - xorb %bl, %bl -2: - /* back to protected mode */ - DATA32 call real_to_prot - .code32 - - movb %bl, %al /* return value in %eax */ - - popl %ebx - popl %ebp - - ret - - -/* - * int grub_biosdisk_get_cdinfo_int13_extensions (int drive, void *cdrp) - * - * Return the cdrom information of DRIVE in CDRP. If an error occurs, - * then return non-zero, otherwise zero. - */ - -FUNCTION(grub_biosdisk_get_cdinfo_int13_extensions) - movw $0x4B01, %cx - jmp 1f - -/* - * int grub_biosdisk_get_diskinfo_int13_extensions (int drive, void *drp) - * - * Return the geometry of DRIVE in a drive parameters, DRP. If an error - * occurs, then return non-zero, otherwise zero. - */ - -FUNCTION(grub_biosdisk_get_diskinfo_int13_extensions) - movb $0x48, %ch -1: - pushl %ebp - pushl %ebx - pushl %esi - - /* compute the address of drive parameters */ - movw %dx, %si - andl $0xf, %esi - shrl $4, %edx - movw %dx, %bx /* save the segment into %bx */ - /* drive */ - movb %al, %dl - /* enter real mode */ - call prot_to_real - - .code16 - movw %cx, %ax - movw %bx, %ds - int $0x13 /* do the operation */ - jc noclean - /* Clean return value if carry isn't set to workaround - some buggy BIOSes. */ - xor %ax, %ax -noclean: - movb %ah, %bl /* save return value in %bl */ - /* back to protected mode */ - DATA32 call real_to_prot - .code32 - - movb %bl, %al /* return value in %eax */ - - popl %esi - popl %ebx - popl %ebp - - ret - - -/* - * int grub_biosdisk_get_diskinfo_standard (int drive, - * unsigned long *cylinders, - * unsigned long *heads, - * unsigned long *sectors) - * - * Return the geometry of DRIVE in CYLINDERS, HEADS and SECTORS. If an - * error occurs, then return non-zero, otherwise zero. - */ - -FUNCTION(grub_biosdisk_get_diskinfo_standard) - pushl %ebp - pushl %ebx - pushl %edi - - /* push CYLINDERS */ - pushl %edx - /* push HEADS */ - pushl %ecx - /* SECTORS is on the stack */ - - /* drive */ - movb %al, %dl - /* enter real mode */ - call prot_to_real - - .code16 - movb $0x8, %ah - int $0x13 /* do the operation */ - jc noclean2 - /* Clean return value if carry isn't set to workaround - some buggy BIOSes. */ - xor %ax, %ax -noclean2: - /* check if successful */ - testb %ah, %ah - jnz 1f - /* bogus BIOSes may not return an error number */ - testb $0x3f, %cl /* 0 sectors means no disk */ - jnz 1f /* if non-zero, then succeed */ - /* XXX 0x60 is one of the unused error numbers */ - movb $0x60, %ah -1: - movb %ah, %bl /* save return value in %bl */ - /* back to protected mode */ - DATA32 call real_to_prot - .code32 - - /* pop HEADS */ - popl %edi - movb %dh, %al - incl %eax /* the number of heads is counted from zero */ - movl %eax, (%edi) - - /* pop CYLINDERS */ - popl %edi - movb %ch, %al - movb %cl, %ah - shrb $6, %ah /* the number of cylinders is counted from zero */ - incl %eax - movl %eax, (%edi) - - /* SECTORS */ - movl 0x10(%esp), %edi - andb $0x3f, %cl - movzbl %cl, %eax - movl %eax, (%edi) - - xorl %eax, %eax - movb %bl, %al /* return value in %eax */ - - popl %edi - popl %ebx - popl %ebp - - ret $4 - - /* * * grub_get_memsize(i) : return the memory size in KB. i == 0 for conventional From c663074e6d2d35394a5254900bdd03c10279bd8a Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Sat, 10 Apr 2010 14:35:26 +0200 Subject: [PATCH 08/21] intwrap get_memsize --- include/grub/i386/pc/init.h | 4 ---- kern/i386/pc/init.c | 19 +++++++++++++++++- kern/i386/pc/mmap.c | 19 +++++++++++++++++- kern/i386/pc/startup.S | 40 ------------------------------------- 4 files changed, 36 insertions(+), 46 deletions(-) diff --git a/include/grub/i386/pc/init.h b/include/grub/i386/pc/init.h index 30130d189..368668922 100644 --- a/include/grub/i386/pc/init.h +++ b/include/grub/i386/pc/init.h @@ -23,10 +23,6 @@ #include #include -/* Get the memory size in KB. If EXTENDED is zero, return conventional - memory, otherwise return extended memory. */ -grub_uint16_t grub_get_memsize (int extended); - /* Get a packed EISA memory map. Lower 16 bits are between 1MB and 16MB in 1KB parts, and upper 16 bits are above 16MB in 64KB parts. */ grub_uint32_t grub_get_eisa_mmap (void); diff --git a/kern/i386/pc/init.c b/kern/i386/pc/init.c index fa646df19..ab625ef44 100644 --- a/kern/i386/pc/init.c +++ b/kern/i386/pc/init.c @@ -23,6 +23,7 @@ #include #include #include +#include #include #include #include @@ -134,6 +135,22 @@ compact_mem_regions (void) } } +/* + * + * grub_get_conv_memsize(i) : return the conventional memory size in KB. + * BIOS call "INT 12H" to get conventional memory size + * The return value in AX. + */ +static inline grub_uint16_t +grub_get_conv_memsize (void) +{ + struct grub_bios_int_registers regs; + + regs.flags = GRUB_CPU_INT_FLAGS_DEFAULT; + grub_bios_interrupt (0x12, ®s); + return regs.eax & 0xffff; +} + void grub_machine_init (void) { @@ -143,7 +160,7 @@ grub_machine_init (void) /* Initialize the console as early as possible. */ grub_console_init (); - grub_lower_mem = grub_get_memsize (0) << 10; + grub_lower_mem = grub_get_conv_memsize () << 10; /* Sanity check. */ if (grub_lower_mem < GRUB_MEMORY_MACHINE_RESERVED_END) diff --git a/kern/i386/pc/mmap.c b/kern/i386/pc/mmap.c index 52d8fd597..b1bf2056f 100644 --- a/kern/i386/pc/mmap.c +++ b/kern/i386/pc/mmap.c @@ -17,10 +17,27 @@ */ #include +#include #include #include #include +/* + * grub_get_ext_memsize() : return the extended memory size in KB. + * BIOS call "INT 15H, AH=88H" to get extended memory size + * The return value in AX. + * + */ +static inline grub_uint16_t +grub_get_ext_memsize (void) +{ + struct grub_bios_int_registers regs; + + regs.eax = 0x8800; + grub_bios_interrupt (0x15, ®s); + return regs.eax & 0xffff; +} + grub_err_t grub_machine_mmap_iterate (int NESTED_FUNC_ATTR (*hook) (grub_uint64_t, grub_uint64_t, grub_uint32_t)) { @@ -56,7 +73,7 @@ grub_machine_mmap_iterate (int NESTED_FUNC_ATTR (*hook) (grub_uint64_t, grub_uin hook (0x1000000, eisa_mmap & ~0xFFFF, GRUB_MACHINE_MEMORY_AVAILABLE); } else - hook (0x100000, grub_get_memsize (1) << 10, GRUB_MACHINE_MEMORY_AVAILABLE); + hook (0x100000, grub_get_ext_memsize () << 10, GRUB_MACHINE_MEMORY_AVAILABLE); } return 0; diff --git a/kern/i386/pc/startup.S b/kern/i386/pc/startup.S index 6733e12bc..233ab8074 100644 --- a/kern/i386/pc/startup.S +++ b/kern/i386/pc/startup.S @@ -505,46 +505,6 @@ FUNCTION(grub_chainloader_real_boot) #include "../loader.S" -/* - * - * grub_get_memsize(i) : return the memory size in KB. i == 0 for conventional - * memory, i == 1 for extended memory - * BIOS call "INT 12H" to get conventional memory size - * BIOS call "INT 15H, AH=88H" to get extended memory size - * Both have the return value in AX. - * - */ - -FUNCTION(grub_get_memsize) - pushl %ebp - - movl %eax, %edx - - call prot_to_real /* enter real mode */ - .code16 - - testl %edx, %edx - jnz xext - - int $0x12 - jmp xdone - -xext: - movb $0x88, %ah - int $0x15 - -xdone: - movw %ax, %dx - - DATA32 call real_to_prot - .code32 - - movw %dx, %ax - - popl %ebp - ret - - /* * * grub_get_eisa_mmap() : return packed EISA memory map, lower 16 bits is From 0d06476b0540bf7abe4b423fa741a8ec6338d4cc Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Sat, 10 Apr 2010 14:45:27 +0200 Subject: [PATCH 09/21] intwrap get_eisa_map. Fix intwrapping of get_ext_memsize. --- include/grub/i386/pc/init.h | 4 ---- kern/i386/pc/mmap.c | 23 +++++++++++++++++++++++ kern/i386/pc/startup.S | 37 ------------------------------------- 3 files changed, 23 insertions(+), 41 deletions(-) diff --git a/include/grub/i386/pc/init.h b/include/grub/i386/pc/init.h index 368668922..7dc8ee1f4 100644 --- a/include/grub/i386/pc/init.h +++ b/include/grub/i386/pc/init.h @@ -23,10 +23,6 @@ #include #include -/* Get a packed EISA memory map. Lower 16 bits are between 1MB and 16MB - in 1KB parts, and upper 16 bits are above 16MB in 64KB parts. */ -grub_uint32_t grub_get_eisa_mmap (void); - /* Get a memory map entry. Return next continuation value. Zero means the end. */ grub_uint32_t grub_get_mmap_entry (struct grub_machine_mmap_entry *entry, diff --git a/kern/i386/pc/mmap.c b/kern/i386/pc/mmap.c index b1bf2056f..2758d17f8 100644 --- a/kern/i386/pc/mmap.c +++ b/kern/i386/pc/mmap.c @@ -34,10 +34,33 @@ grub_get_ext_memsize (void) struct grub_bios_int_registers regs; regs.eax = 0x8800; + regs.flags = GRUB_CPU_INT_FLAGS_DEFAULT; grub_bios_interrupt (0x15, ®s); return regs.eax & 0xffff; } +/* Get a packed EISA memory map. Lower 16 bits are between 1MB and 16MB + in 1KB parts, and upper 16 bits are above 16MB in 64KB parts. If error, return zero. + BIOS call "INT 15H, AH=E801H" to get EISA memory map, + AX = memory between 1M and 16M in 1K parts. + BX = memory above 16M in 64K parts. +*/ + +static inline grub_uint32_t +grub_get_eisa_mmap (void) +{ + struct grub_bios_int_registers regs; + + regs.flags = GRUB_CPU_INT_FLAGS_DEFAULT; + regs.eax = 0xe801; + grub_bios_interrupt (0x15, ®s); + + if ((regs.eax & 0xff00) == 0x8600) + return 0; + + return (regs.eax & 0xffff) | (regs.ebx << 16); +} + grub_err_t grub_machine_mmap_iterate (int NESTED_FUNC_ATTR (*hook) (grub_uint64_t, grub_uint64_t, grub_uint32_t)) { diff --git a/kern/i386/pc/startup.S b/kern/i386/pc/startup.S index 233ab8074..3fa1b11e8 100644 --- a/kern/i386/pc/startup.S +++ b/kern/i386/pc/startup.S @@ -505,43 +505,6 @@ FUNCTION(grub_chainloader_real_boot) #include "../loader.S" -/* - * - * grub_get_eisa_mmap() : return packed EISA memory map, lower 16 bits is - * memory between 1M and 16M in 1K parts, upper 16 bits is - * memory above 16M in 64K parts. If error, return zero. - * BIOS call "INT 15H, AH=E801H" to get EISA memory map, - * AX = memory between 1M and 16M in 1K parts. - * BX = memory above 16M in 64K parts. - * - */ - -FUNCTION(grub_get_eisa_mmap) - pushl %ebp - pushl %ebx - - call prot_to_real /* enter real mode */ - .code16 - - movw $0xe801, %ax - int $0x15 - - shll $16, %ebx - movw %ax, %bx - - DATA32 call real_to_prot - .code32 - - cmpb $0x86, %bh - je xnoteisa - - movl %ebx, %eax - -xnoteisa: - popl %ebx - popl %ebp - ret - /* * * grub_get_mmap_entry(addr, cont) : address and old continuation value (zero to From f632937ab5c0223259991c3073ed8569df27a304 Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Sat, 10 Apr 2010 19:12:04 +0200 Subject: [PATCH 10/21] intwrap grub_get_mmap_entry --- include/grub/i386/pc/init.h | 5 --- kern/i386/pc/mmap.c | 47 ++++++++++++++++++++ kern/i386/pc/startup.S | 88 ------------------------------------- 3 files changed, 47 insertions(+), 93 deletions(-) diff --git a/include/grub/i386/pc/init.h b/include/grub/i386/pc/init.h index 7dc8ee1f4..a6d2abf41 100644 --- a/include/grub/i386/pc/init.h +++ b/include/grub/i386/pc/init.h @@ -23,11 +23,6 @@ #include #include -/* Get a memory map entry. Return next continuation value. Zero means - the end. */ -grub_uint32_t grub_get_mmap_entry (struct grub_machine_mmap_entry *entry, - grub_uint32_t cont); - /* Turn on/off Gate A20. */ void grub_gate_a20 (int on); diff --git a/kern/i386/pc/mmap.c b/kern/i386/pc/mmap.c index 2758d17f8..25f8a739b 100644 --- a/kern/i386/pc/mmap.c +++ b/kern/i386/pc/mmap.c @@ -61,6 +61,53 @@ grub_get_eisa_mmap (void) return (regs.eax & 0xffff) | (regs.ebx << 16); } +/* + * + * grub_get_mmap_entry(addr, cont) : address and old continuation value (zero to + * start), for the Query System Address Map BIOS call. + * + * Sets the first 4-byte int value of "addr" to the size returned by + * the call. If the call fails, sets it to zero. + * + * Returns: new (non-zero) continuation value, 0 if done. + */ +/* Get a memory map entry. Return next continuation value. Zero means + the end. */ +static grub_uint32_t +grub_get_mmap_entry (struct grub_machine_mmap_entry *entry, + grub_uint32_t cont) +{ + struct grub_bios_int_registers regs; + + regs.flags = GRUB_CPU_INT_FLAGS_DEFAULT; + + /* place address (+4) in ES:DI */ + regs.es = ((grub_addr_t) &entry->addr) >> 4; + regs.edi = ((grub_addr_t) &entry->addr) & 0xf; + + /* set continuation value */ + regs.ebx = cont; + + /* set default maximum buffer size */ + regs.ecx = sizeof (*entry) - sizeof (entry->size); + + /* set EDX to 'SMAP' */ + regs.edx = 0x534d4150; + + regs.eax = 0xe820; + grub_bios_interrupt (0x15, ®s); + + /* write length of buffer (zero if error) into ADDR */ + if ((regs.flags & GRUB_CPU_INT_FLAGS_CARRY) || regs.eax != 0x534d4150 + || regs.ecx < 0x14 || regs.ecx > 0x400) + entry->size = 0; + else + entry->size = regs.ecx; + + /* return the continuation value */ + return regs.ebx; +} + grub_err_t grub_machine_mmap_iterate (int NESTED_FUNC_ATTR (*hook) (grub_uint64_t, grub_uint64_t, grub_uint32_t)) { diff --git a/kern/i386/pc/startup.S b/kern/i386/pc/startup.S index 3fa1b11e8..ee677fc15 100644 --- a/kern/i386/pc/startup.S +++ b/kern/i386/pc/startup.S @@ -505,94 +505,6 @@ FUNCTION(grub_chainloader_real_boot) #include "../loader.S" -/* - * - * grub_get_mmap_entry(addr, cont) : address and old continuation value (zero to - * start), for the Query System Address Map BIOS call. - * - * Sets the first 4-byte int value of "addr" to the size returned by - * the call. If the call fails, sets it to zero. - * - * Returns: new (non-zero) continuation value, 0 if done. - */ - -FUNCTION(grub_get_mmap_entry) - pushl %ebp - pushl %ebx - pushl %edi - pushl %esi - - /* push ADDR */ - pushl %eax - - /* place address (+4) in ES:DI */ - addl $4, %eax - movl %eax, %edi - andl $0xf, %edi - shrl $4, %eax - movl %eax, %esi - - /* set continuation value */ - movl %edx, %ebx - - /* set default maximum buffer size */ - movl $0x14, %ecx - - /* set EDX to 'SMAP' */ - movl $0x534d4150, %edx - - call prot_to_real /* enter real mode */ - .code16 - - movw %si, %es - movl $0xe820, %eax - int $0x15 - - DATA32 jc xnosmap - - cmpl $0x534d4150, %eax - jne xnosmap - - cmpl $0x14, %ecx - jl xnosmap - - cmpl $0x400, %ecx - jg xnosmap - - jmp xsmap - -xnosmap: - xorl %ecx, %ecx - -/* Apple's cc jumps few bytes before the correct - label in this context. Hence nops. */ -#ifdef APPLE_CC - nop - nop - nop - nop - nop - nop -#endif - -xsmap: - DATA32 call real_to_prot - .code32 - - /* write length of buffer (zero if error) into ADDR */ - popl %eax - movl %ecx, (%eax) - - /* set return value to continuation */ - movl %ebx, %eax - - popl %esi - popl %edi - popl %ebx - popl %ebp - ret - - /* * void grub_console_real_putchar (int c) * From 8c5ed46e488770805299fa41a1d1614229d037a1 Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Sat, 10 Apr 2010 19:59:22 +0200 Subject: [PATCH 11/21] Inline grub_stop_floppy --- include/grub/i386/coreboot/init.h | 2 +- .../init.c => include/grub/i386/floppy.h | 20 +++++++++++++------ include/grub/i386/pc/init.h | 3 +-- kern/i386/coreboot/init.c | 10 ---------- kern/i386/loader.S | 6 +++++- 5 files changed, 21 insertions(+), 20 deletions(-) rename kern/i386/ieee1275/init.c => include/grub/i386/floppy.h (62%) diff --git a/include/grub/i386/coreboot/init.h b/include/grub/i386/coreboot/init.h index e67007414..e944f9cc8 100644 --- a/include/grub/i386/coreboot/init.h +++ b/include/grub/i386/coreboot/init.h @@ -21,8 +21,8 @@ #include #include +#include void EXPORT_FUNC(grub_stop) (void) __attribute__ ((noreturn)); -void EXPORT_FUNC(grub_stop_floppy) (void); #endif diff --git a/kern/i386/ieee1275/init.c b/include/grub/i386/floppy.h similarity index 62% rename from kern/i386/ieee1275/init.c rename to include/grub/i386/floppy.h index 9fb98739b..0e3690549 100644 --- a/kern/i386/ieee1275/init.c +++ b/include/grub/i386/floppy.h @@ -1,7 +1,6 @@ -/* init.c -- Initialize GRUB on Open Firmware. */ /* * GRUB -- GRand Unified Bootloader - * Copyright (C) 2003,2004,2005,2007,2008 Free Software Foundation, Inc. + * Copyright (C) 2002,2003,2004,2005,2006,2007,2008,2009,2010 Free Software Foundation, Inc. * * GRUB is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -17,12 +16,21 @@ * along with GRUB. If not, see . */ -#include -#include +#ifndef GRUB_FLOPPY_CPU_HEADER +#define GRUB_FLOPPY_CPU_HEADER 1 -void grub_stop_floppy (void); +#define GRUB_FLOPPY_REG_DIGITAL_OUTPUT 0x3f2 -void +#ifndef ASM_FILE +#include + +/* Stop the floppy drive from spinning, so that other software is + jumped to with a known state. */ +static inline void grub_stop_floppy (void) { + grub_outb (0, GRUB_FLOPPY_REG_DIGITAL_OUTPUT); } +#endif + +#endif diff --git a/include/grub/i386/pc/init.h b/include/grub/i386/pc/init.h index a6d2abf41..4005a1772 100644 --- a/include/grub/i386/pc/init.h +++ b/include/grub/i386/pc/init.h @@ -22,10 +22,9 @@ #include #include #include +#include /* Turn on/off Gate A20. */ void grub_gate_a20 (int on); -void EXPORT_FUNC(grub_stop_floppy) (void); - #endif /* ! GRUB_INIT_MACHINE_HEADER */ diff --git a/kern/i386/coreboot/init.c b/kern/i386/coreboot/init.c index 5f80f28c1..9013d8f91 100644 --- a/kern/i386/coreboot/init.c +++ b/kern/i386/coreboot/init.c @@ -36,8 +36,6 @@ #include #include -#define GRUB_FLOPPY_REG_DIGITAL_OUTPUT 0x3f2 - extern char _start[]; extern char _end[]; @@ -50,14 +48,6 @@ grub_get_rtc (void) grub_fatal ("grub_get_rtc() is not implemented.\n"); } -/* Stop the floppy drive from spinning, so that other software is - jumped to with a known state. */ -void -grub_stop_floppy (void) -{ - grub_outb (0, GRUB_FLOPPY_REG_DIGITAL_OUTPUT); -} - void grub_exit (void) { diff --git a/kern/i386/loader.S b/kern/i386/loader.S index ed57c43ca..9eb5af1f7 100644 --- a/kern/i386/loader.S +++ b/kern/i386/loader.S @@ -45,6 +45,8 @@ * This is the area for all of the special variables. */ +#include + .p2align 2 /* force 4-byte alignment */ /* @@ -96,7 +98,9 @@ bzimage: /* XXX new stack pointer in safe area for calling functions */ movl $0x4000, %esp - call EXT_C(grub_stop_floppy) + movw $GRUB_FLOPPY_REG_DIGITAL_OUTPUT, %dx + xorb %al, %al + outb %al, %dx /* final setup for linux boot */ call prot_to_real From 44f77f21d894176eaa6d02ef4c47f0db49b04536 Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Sat, 10 Apr 2010 20:00:14 +0200 Subject: [PATCH 12/21] Remove misc.S from i386-pc sources --- conf/i386-pc.rmk | 1 - 1 file changed, 1 deletion(-) diff --git a/conf/i386-pc.rmk b/conf/i386-pc.rmk index 6666e3a32..2eca82d25 100644 --- a/conf/i386-pc.rmk +++ b/conf/i386-pc.rmk @@ -40,7 +40,6 @@ cdboot_img_FORMAT = binary # For kernel.img. kernel_img_SOURCES = kern/i386/pc/startup.S \ - kern/i386/misc.S \ kern/main.c kern/device.c \ kern/disk.c kern/dl.c kern/file.c kern/fs.c kern/err.c \ kern/misc.c kern/mm.c kern/term.c \ From d0fd0a359f3507b38b38d12f7e74c253ec46c2b7 Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Tue, 4 May 2010 15:57:18 +0200 Subject: [PATCH 13/21] remove references to kern/i386/ieee1275/init.c --- conf/i386-ieee1275.rmk | 1 - 1 file changed, 1 deletion(-) diff --git a/conf/i386-ieee1275.rmk b/conf/i386-ieee1275.rmk index d4a459b3e..07faa747a 100644 --- a/conf/i386-ieee1275.rmk +++ b/conf/i386-ieee1275.rmk @@ -8,7 +8,6 @@ pkglib_PROGRAMS = kernel.img # For kernel.img. kernel_img_SOURCES = kern/i386/ieee1275/startup.S \ kern/i386/misc.S \ - kern/i386/ieee1275/init.c \ kern/ieee1275/init.c \ kern/ieee1275/mmap.c \ kern/ieee1275/cmain.c kern/ieee1275/openfw.c \ From 8496927478e5af0bd75741dc2d8f792831905786 Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Tue, 4 May 2010 17:15:36 +0200 Subject: [PATCH 14/21] move grub_halt out of kernel on most platforms --- conf/i386-coreboot.rmk | 7 +++--- conf/i386-ieee1275.rmk | 6 ++--- conf/i386-multiboot.rmk | 7 +++--- conf/i386-pc.rmk | 2 +- conf/i386-qemu.rmk | 7 +++--- conf/powerpc-ieee1275.rmk | 2 +- conf/sparc64-ieee1275.rmk | 2 +- conf/x86-efi.rmk | 5 ++-- include/grub/misc.h | 2 +- kern/efi/efi.c | 8 ------ kern/i386/coreboot/init.c | 2 +- kern/i386/qemu/mmap.c | 1 - kern/i386/qemu/startup.S | 5 +++- kern/ieee1275/openfw.c | 10 -------- kern/i386/misc.S => lib/efi/halt.c | 25 +++++++++++-------- {kern => lib}/i386/halt.c | 17 +++++++++++-- .../coreboot/init.h => lib/ieee1275/halt.c | 21 +++++++++------- loader/i386/bsd.c | 1 - 18 files changed, 65 insertions(+), 65 deletions(-) rename kern/i386/misc.S => lib/efi/halt.c (62%) rename {kern => lib}/i386/halt.c (83%) rename include/grub/i386/coreboot/init.h => lib/ieee1275/halt.c (62%) diff --git a/conf/i386-coreboot.rmk b/conf/i386-coreboot.rmk index ca969632a..e6786cdb8 100644 --- a/conf/i386-coreboot.rmk +++ b/conf/i386-coreboot.rmk @@ -8,10 +8,8 @@ GRUB_KERNEL_MACHINE_LINK_ADDR = 0x8200 pkglib_PROGRAMS += kernel.img kernel_img_SOURCES = kern/i386/coreboot/startup.S \ - kern/i386/misc.S \ kern/i386/coreboot/init.c \ kern/i386/coreboot/mmap.c \ - kern/i386/halt.c \ kern/main.c kern/device.c \ kern/disk.c kern/dl.c kern/file.c kern/fs.c kern/err.c \ kern/misc.c kern/mm.c kern/term.c \ @@ -35,7 +33,7 @@ bin_SCRIPTS += grub-mkrescue grub_mkrescue_SOURCES = util/grub-mkrescue.in # Modules. -pkglib_MODULES = linux.mod aout.mod halt.mod datetime.mod mmap.mod +pkglib_MODULES = linux.mod aout.mod datetime.mod mmap.mod # For mmap.mod. mmap_mod_SOURCES = mmap/mmap.c mmap/i386/uppermem.c mmap/i386/mmap.c @@ -49,7 +47,8 @@ linux_mod_CFLAGS = $(COMMON_CFLAGS) linux_mod_LDFLAGS = $(COMMON_LDFLAGS) # For halt.mod. -halt_mod_SOURCES = commands/halt.c +pkglib_MODULES += halt.mod +halt_mod_SOURCES = commands/halt.c lib/i386/halt.c halt_mod_CFLAGS = $(COMMON_CFLAGS) halt_mod_LDFLAGS = $(COMMON_LDFLAGS) diff --git a/conf/i386-ieee1275.rmk b/conf/i386-ieee1275.rmk index b12ddfdda..ba7a26629 100644 --- a/conf/i386-ieee1275.rmk +++ b/conf/i386-ieee1275.rmk @@ -7,7 +7,6 @@ pkglib_PROGRAMS = kernel.img # For kernel.img. kernel_img_SOURCES = kern/i386/ieee1275/startup.S \ - kern/i386/misc.S \ kern/ieee1275/init.c \ kern/ieee1275/mmap.c \ kern/ieee1275/cmain.c kern/ieee1275/openfw.c \ @@ -35,7 +34,7 @@ sbin_SCRIPTS = grub-install grub_install_SOURCES = util/ieee1275/grub-install.in # Modules. -pkglib_MODULES = halt.mod suspend.mod \ +pkglib_MODULES = suspend.mod \ aout.mod linux.mod \ nand.mod datetime.mod \ mmap.mod @@ -57,7 +56,8 @@ suspend_mod_CFLAGS = $(COMMON_CFLAGS) suspend_mod_LDFLAGS = $(COMMON_LDFLAGS) # For halt.mod -halt_mod_SOURCES = commands/halt.c +pkglib_MODULES += halt.mod +halt_mod_SOURCES = commands/halt.c lib/ieee1275/halt.c halt_mod_CFLAGS = $(COMMON_CFLAGS) halt_mod_LDFLAGS = $(COMMON_LDFLAGS) diff --git a/conf/i386-multiboot.rmk b/conf/i386-multiboot.rmk index 69b8e9a48..1da30dfd9 100644 --- a/conf/i386-multiboot.rmk +++ b/conf/i386-multiboot.rmk @@ -8,10 +8,8 @@ GRUB_KERNEL_MACHINE_LINK_ADDR = 0x8200 pkglib_PROGRAMS += kernel.img kernel_img_SOURCES = kern/i386/coreboot/startup.S \ - kern/i386/misc.S \ kern/i386/coreboot/init.c \ kern/i386/multiboot_mmap.c \ - kern/i386/halt.c \ kern/main.c kern/device.c \ kern/disk.c kern/dl.c kern/file.c kern/fs.c kern/err.c \ kern/misc.c kern/mm.c kern/term.c \ @@ -35,7 +33,7 @@ bin_SCRIPTS += grub-mkrescue grub_mkrescue_SOURCES = util/grub-mkrescue.in # Modules. -pkglib_MODULES = linux.mod aout.mod halt.mod datetime.mod mmap.mod +pkglib_MODULES = linux.mod aout.mod datetime.mod mmap.mod # For mmap.mod. mmap_mod_SOURCES = mmap/mmap.c mmap/i386/uppermem.c mmap/i386/mmap.c @@ -49,7 +47,8 @@ linux_mod_CFLAGS = $(COMMON_CFLAGS) linux_mod_LDFLAGS = $(COMMON_LDFLAGS) # For halt.mod. -halt_mod_SOURCES = commands/halt.c +pkglib_MODULES += halt.mod +halt_mod_SOURCES = commands/halt.c lib/i386/halt.c halt_mod_CFLAGS = $(COMMON_CFLAGS) halt_mod_LDFLAGS = $(COMMON_LDFLAGS) diff --git a/conf/i386-pc.rmk b/conf/i386-pc.rmk index b50655e9e..1ad32f41d 100644 --- a/conf/i386-pc.rmk +++ b/conf/i386-pc.rmk @@ -98,7 +98,6 @@ bin_SCRIPTS += grub-mkrescue grub_mkrescue_SOURCES = util/grub-mkrescue.in pkglib_MODULES = biosdisk.mod chain.mod \ - halt.mod \ vbe.mod vbetest.mod vbeinfo.mod \ vga.mod \ aout.mod bsd.mod pxe.mod pxecmd.mod datetime.mod \ @@ -163,6 +162,7 @@ xnu_mod_LDFLAGS = $(COMMON_LDFLAGS) xnu_mod_ASFLAGS = $(COMMON_ASFLAGS) # For halt.mod. +pkglib_MODULES += halt.mod halt_mod_SOURCES = commands/i386/pc/halt.c halt_mod_CFLAGS = $(COMMON_CFLAGS) halt_mod_LDFLAGS = $(COMMON_LDFLAGS) diff --git a/conf/i386-qemu.rmk b/conf/i386-qemu.rmk index 664bef12a..6c2e00586 100644 --- a/conf/i386-qemu.rmk +++ b/conf/i386-qemu.rmk @@ -21,10 +21,8 @@ util/grub-mkrawimage.c_DEPENDENCIES = Makefile pkglib_IMAGES += kernel.img kernel_img_SOURCES = kern/i386/qemu/startup.S \ - kern/i386/misc.S \ kern/i386/coreboot/init.c \ kern/i386/qemu/mmap.c \ - kern/i386/halt.c \ kern/main.c kern/device.c \ kern/disk.c kern/dl.c kern/file.c kern/fs.c kern/err.c \ kern/misc.c kern/mm.c kern/term.c \ @@ -49,7 +47,7 @@ bin_SCRIPTS += grub-mkrescue grub_mkrescue_SOURCES = util/grub-mkrescue.in # Modules. -pkglib_MODULES = linux.mod aout.mod halt.mod datetime.mod mmap.mod +pkglib_MODULES = linux.mod aout.mod datetime.mod mmap.mod # For mmap.mod. mmap_mod_SOURCES = mmap/mmap.c mmap/i386/uppermem.c mmap/i386/mmap.c @@ -63,7 +61,8 @@ linux_mod_CFLAGS = $(COMMON_CFLAGS) linux_mod_LDFLAGS = $(COMMON_LDFLAGS) # For halt.mod. -halt_mod_SOURCES = commands/halt.c +pkglib_MODULES += halt.mod +halt_mod_SOURCES = commands/halt.c lib/i386/halt.c halt_mod_CFLAGS = $(COMMON_CFLAGS) halt_mod_LDFLAGS = $(COMMON_LDFLAGS) diff --git a/conf/powerpc-ieee1275.rmk b/conf/powerpc-ieee1275.rmk index d5968ac8e..736fa4394 100644 --- a/conf/powerpc-ieee1275.rmk +++ b/conf/powerpc-ieee1275.rmk @@ -55,7 +55,7 @@ suspend_mod_LDFLAGS = $(COMMON_LDFLAGS) # For halt.mod pkglib_MODULES += halt.mod -halt_mod_SOURCES = commands/halt.c +halt_mod_SOURCES = commands/halt.c lib/ieee1275/halt.c halt_mod_CFLAGS = $(COMMON_CFLAGS) halt_mod_LDFLAGS = $(COMMON_LDFLAGS) diff --git a/conf/sparc64-ieee1275.rmk b/conf/sparc64-ieee1275.rmk index f0c9b0db7..c6a0d03ec 100644 --- a/conf/sparc64-ieee1275.rmk +++ b/conf/sparc64-ieee1275.rmk @@ -93,7 +93,7 @@ linux_mod_LDFLAGS = $(COMMON_LDFLAGS) # For halt.mod. pkglib_MODULES += halt.mod -halt_mod_SOURCES = commands/halt.c +halt_mod_SOURCES = commands/halt.c lib/ieee1275/halt.c halt_mod_CFLAGS = $(COMMON_CFLAGS) halt_mod_LDFLAGS = $(COMMON_LDFLAGS) diff --git a/conf/x86-efi.rmk b/conf/x86-efi.rmk index e29dad645..1d2221cdf 100644 --- a/conf/x86-efi.rmk +++ b/conf/x86-efi.rmk @@ -17,7 +17,7 @@ grub_install_SOURCES = util/i386/efi/grub-install.in # Modules. pkglib_PROGRAMS = kernel.img pkglib_MODULES = chain.mod appleldr.mod \ - linux.mod halt.mod \ + linux.mod \ datetime.mod loadbios.mod \ fixvideo.mod mmap.mod acpi.mod @@ -77,7 +77,8 @@ linux_mod_LDFLAGS = $(COMMON_LDFLAGS) endif # For halt.mod. -halt_mod_SOURCES = commands/halt.c +pkglib_MODULES += halt.mod +halt_mod_SOURCES = commands/halt.c lib/efi/halt.c halt_mod_CFLAGS = $(COMMON_CFLAGS) halt_mod_LDFLAGS = $(COMMON_LDFLAGS) diff --git a/include/grub/misc.h b/include/grub/misc.h index 44bcfe507..e5635e239 100644 --- a/include/grub/misc.h +++ b/include/grub/misc.h @@ -305,7 +305,7 @@ void EXPORT_FUNC (grub_reboot) (void); * use APM even if it is available. */ void grub_halt (int no_apm); #else -void EXPORT_FUNC (grub_halt) (void); +void grub_halt (void); #endif #endif /* ! GRUB_MISC_HEADER */ diff --git a/kern/efi/efi.c b/kern/efi/efi.c index d8b225535..6806bb72a 100644 --- a/kern/efi/efi.c +++ b/kern/efi/efi.c @@ -173,14 +173,6 @@ grub_reboot (void) } #endif -void -grub_halt (void) -{ - grub_efi_fini (); - efi_call_4 (grub_efi_system_table->runtime_services->reset_system, - GRUB_EFI_RESET_SHUTDOWN, GRUB_EFI_SUCCESS, 0, NULL); -} - int grub_efi_exit_boot_services (grub_efi_uintn_t map_key) { diff --git a/kern/i386/coreboot/init.c b/kern/i386/coreboot/init.c index 93d75eced..594986eb8 100644 --- a/kern/i386/coreboot/init.c +++ b/kern/i386/coreboot/init.c @@ -19,7 +19,6 @@ #include #include #include -#include #include #include #include @@ -33,6 +32,7 @@ #include #include #include +#include #include #include diff --git a/kern/i386/qemu/mmap.c b/kern/i386/qemu/mmap.c index c7fc4f45e..fdc7e191b 100644 --- a/kern/i386/qemu/mmap.c +++ b/kern/i386/qemu/mmap.c @@ -16,7 +16,6 @@ * along with GRUB. If not, see . */ -#include #include #include #include diff --git a/kern/i386/qemu/startup.S b/kern/i386/qemu/startup.S index 7484650b2..22996a394 100644 --- a/kern/i386/qemu/startup.S +++ b/kern/i386/qemu/startup.S @@ -94,6 +94,9 @@ codestart: call EXT_C(grub_main) /* This should never happen. */ - jmp EXT_C(grub_stop) + cli +1: + hlt + jmp 1b #include "../realmode.S" diff --git a/kern/ieee1275/openfw.c b/kern/ieee1275/openfw.c index cf9e1a870..2f15274b6 100644 --- a/kern/ieee1275/openfw.c +++ b/kern/ieee1275/openfw.c @@ -423,13 +423,3 @@ grub_reboot (void) grub_ieee1275_interpret ("reset-all", 0); } #endif - -void -grub_halt (void) -{ - /* Not standardized. We try three known commands. */ - - grub_ieee1275_interpret ("shut-down", 0); - grub_ieee1275_interpret ("power-off", 0); - grub_ieee1275_interpret ("poweroff", 0); -} diff --git a/kern/i386/misc.S b/lib/efi/halt.c similarity index 62% rename from kern/i386/misc.S rename to lib/efi/halt.c index 7d57df9b9..e6fd6d07d 100644 --- a/kern/i386/misc.S +++ b/lib/efi/halt.c @@ -1,6 +1,7 @@ +/* efi.c - generic EFI support */ /* * GRUB -- GRand Unified Bootloader - * Copyright (C) 1999,2000,2001,2002,2003,2005,2006,2007,2008 Free Software Foundation, Inc. + * Copyright (C) 2006,2007,2008,2009,2010 Free Software Foundation, Inc. * * GRUB is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -16,14 +17,16 @@ * along with GRUB. If not, see . */ -#include +#include +#include +#include +#include +#include - .text -/* - * This call is special... it never returns... in fact it should simply - * hang at this point! - */ -FUNCTION(grub_stop) - cli -1: hlt - jmp 1b +void +grub_halt (void) +{ + grub_machine_fini (); + efi_call_4 (grub_efi_system_table->runtime_services->reset_system, + GRUB_EFI_RESET_SHUTDOWN, GRUB_EFI_SUCCESS, 0, NULL); +} diff --git a/kern/i386/halt.c b/lib/i386/halt.c similarity index 83% rename from kern/i386/halt.c rename to lib/i386/halt.c index 10805e42b..74e0c7301 100644 --- a/kern/i386/halt.c +++ b/lib/i386/halt.c @@ -17,11 +17,24 @@ */ #include -#include #include const char bochs_shutdown[] = "Shutdown"; +/* + * This call is special... it never returns... in fact it should simply + * hang at this point! + */ +static inline void __attribute__ ((noreturn)) +stop (void) +{ + asm volatile ("cli"); + while (1) + { + asm volatile ("hlt"); + } +} + void grub_halt (void) { @@ -38,5 +51,5 @@ grub_halt (void) /* In order to return we'd have to check what the previous status of IF flag was. But user most likely doesn't want to return anyway ... */ - grub_stop (); + stop (); } diff --git a/include/grub/i386/coreboot/init.h b/lib/ieee1275/halt.c similarity index 62% rename from include/grub/i386/coreboot/init.h rename to lib/ieee1275/halt.c index e944f9cc8..9453714d3 100644 --- a/include/grub/i386/coreboot/init.h +++ b/lib/ieee1275/halt.c @@ -1,6 +1,7 @@ +/* openfw.c -- Open firmware support functions. */ /* * GRUB -- GRand Unified Bootloader - * Copyright (C) 2007 Free Software Foundation, Inc. + * Copyright (C) 2003,2004,2005,2007,2008,2009 Free Software Foundation, Inc. * * GRUB is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -16,13 +17,15 @@ * along with GRUB. If not, see . */ -#ifndef GRUB_INIT_I386_LINUXBIOS_HEADER -#define GRUB_INIT_I386_LINUXBIOS_HEADER 1 +#include +#include -#include -#include -#include +void +grub_halt (void) +{ + /* Not standardized. We try three known commands. */ -void EXPORT_FUNC(grub_stop) (void) __attribute__ ((noreturn)); - -#endif + grub_ieee1275_interpret ("shut-down", 0); + grub_ieee1275_interpret ("power-off", 0); + grub_ieee1275_interpret ("poweroff", 0); +} diff --git a/loader/i386/bsd.c b/loader/i386/bsd.c index 3c7fe2fee..f9926d114 100644 --- a/loader/i386/bsd.c +++ b/loader/i386/bsd.c @@ -20,7 +20,6 @@ #include #include #include -#include #include #include #include From b2d8783a98e61edf1573a876ad26fedb26d17aa0 Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Tue, 4 May 2010 17:20:26 +0200 Subject: [PATCH 15/21] remove grub_stop_floppy leftover --- kern/i386/pc/startup.S | 12 ------------ 1 file changed, 12 deletions(-) diff --git a/kern/i386/pc/startup.S b/kern/i386/pc/startup.S index ec94a972f..4d4f2c860 100644 --- a/kern/i386/pc/startup.S +++ b/kern/i386/pc/startup.S @@ -451,18 +451,6 @@ gate_a20_check_state: . = _start + GRUB_KERNEL_MACHINE_RAW_SIZE -/* - * grub_stop_floppy() - * - * Stop the floppy drive from spinning, so that other software is - * jumped to with a known state. - */ -FUNCTION(grub_stop_floppy) - movw $0x3F2, %dx - xorb %al, %al - outb %al, %dx - ret - /* * grub_exit() * From 37e67a273bbe6c1ed26883c9b4b4033b9fed510d Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Mon, 30 Aug 2010 00:54:15 +0200 Subject: [PATCH 16/21] Add missing emu/halt.c --- grub-core/lib/emu/halt.c | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 grub-core/lib/emu/halt.c diff --git a/grub-core/lib/emu/halt.c b/grub-core/lib/emu/halt.c new file mode 100644 index 000000000..620935b5a --- /dev/null +++ b/grub-core/lib/emu/halt.c @@ -0,0 +1,25 @@ +/* + * GRUB -- GRand Unified Bootloader + * Copyright (C) 2003,2004,2005,2006,2007,2008,2009,2010 Free Software Foundation, Inc. + * + * GRUB is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * GRUB is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with GRUB. If not, see . + */ + +#include + +void +grub_halt (void) +{ + grub_reboot (); +} From eefe8abd521893e077396bca09a38d828cdee4d8 Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Mon, 30 Aug 2010 15:13:38 +0200 Subject: [PATCH 17/21] Dimplify tags and enable USB on more platforms --- ChangeLog | 9 ++ Makefile.util.def | 12 ++- gentpl.py | 50 ++++------ grub-core/Makefile.am | 25 +---- grub-core/Makefile.core.def | 161 +++++++++++-------------------- grub-core/bus/usb/ohci.c | 14 +-- grub-core/bus/usb/uhci.c | 26 ++--- grub-core/bus/usb/usbtrans.c | 7 +- grub-core/loader/i386/pc/linux.c | 2 +- grub-core/loader/i386/xnu.c | 4 - 10 files changed, 121 insertions(+), 189 deletions(-) diff --git a/ChangeLog b/ChangeLog index 1a0085d9a..b15fc7fe7 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,12 @@ +2010-08-30 Vladimir Serbinenko + + Interrupt wrapping and code simplifications. + + * grub-core/Makefile.am (KERNEL_HEADER_FILES): Remove + include/grub/machine/vga.h, include/grub/machine/vbe.h, + (KERNEL_HEADER_FILES) [i386-pc]: Add include/grub/machine/int.h. + Remove include/grub/machine/init.h. + 2010-08-30 Vladimir Serbinenko * docs/grub.texi (Network): Fix reference to pxe_blksize. diff --git a/Makefile.util.def b/Makefile.util.def index 6b4949fd9..9565dde65 100644 --- a/Makefile.util.def +++ b/Makefile.util.def @@ -330,7 +330,7 @@ script = { script = { mansection = 1; name = grub-mkrescue; - x86_noieee1275 = util/grub-mkrescue.in; + x86 = util/grub-mkrescue.in; powerpc_ieee1275 = util/powerpc/ieee1275/grub-mkrescue.in; enable = i386_pc; enable = x86_efi; @@ -346,15 +346,17 @@ script = { name = grub-install; mips = util/grub-install.in; - i386_noefi_noieee1275 = util/grub-install.in; + i386_pc = util/grub-install.in; + i386_qemu = util/grub-install.in; + i386_coreboot = util/grub-install.in; + i386_multiboot = util/grub-install.in; + sparc64_ieee1275 = util/grub-install.in; x86_efi = util/i386/efi/grub-install.in; i386_ieee1275 = util/ieee1275/grub-install.in; powerpc_ieee1275 = util/ieee1275/grub-install.in; - enable = x86; - enable = mips; - enable = powerpc_ieee1275; + enable = noemu; }; script = { diff --git a/gentpl.py b/gentpl.py index 17bda02c6..abfb20444 100644 --- a/gentpl.py +++ b/gentpl.py @@ -10,46 +10,38 @@ GRUB_PLATFORMS = [ "emu", "i386_pc", "i386_efi", "i386_qemu", "i386_coreboot", "powerpc_ieee1275" ] GROUPS = {} + +GROUPS["common"] = GRUB_PLATFORMS[:] + +# Groups based on CPU GROUPS["i386"] = [ "i386_pc", "i386_efi", "i386_qemu", "i386_coreboot", "i386_multiboot", "i386_ieee1275" ] GROUPS["x86_64"] = [ "x86_64_efi" ] GROUPS["x86"] = GROUPS["i386"] + GROUPS["x86_64"] -GROUPS["x86_efi"] = [ "i386_efi", "x86_64_efi" ] - -GROUPS["nopc"] = GRUB_PLATFORMS[:]; GROUPS["nopc"].remove("i386_pc") -GROUPS["x86_efi_pc"] = GROUPS["x86_efi"] + ["i386_pc"] - -GROUPS["x86_noefi"] = GROUPS["x86"][:]; GROUPS["x86_noefi"].remove("i386_efi"); GROUPS["x86_noefi"].remove("x86_64_efi") -GROUPS["i386_noefi"] = GROUPS["i386"][:]; GROUPS["i386_noefi"].remove("i386_efi") - -GROUPS["x86_noieee1275"] = GROUPS["x86"][:]; GROUPS["x86_noieee1275"].remove("i386_ieee1275") -GROUPS["i386_noieee1275"] = GROUPS["i386"][:]; GROUPS["i386_noieee1275"].remove("i386_ieee1275") - -GROUPS["i386_noefi_noieee1275"] = GROUPS["i386_noefi"][:]; GROUPS["i386_noefi_noieee1275"].remove("i386_ieee1275") - -GROUPS["i386_pc_qemu_coreboot"] = ["i386_pc", "i386_qemu", "i386_coreboot"] -GROUPS["i386_coreboot_multiboot"] = ["i386_coreboot", "i386_multiboot"] -GROUPS["i386_coreboot_multiboot_qemu"] = ["i386_coreboot", "i386_multiboot", "i386_qemu"] -GROUPS["i386_pc_coreboot_multiboot_qemu"] = ["i386_pc", "i386_coreboot", "i386_multiboot", "i386_qemu"] - GROUPS["mips"] = [ "mips_yeeloong" ] GROUPS["sparc64"] = [ "sparc64_ieee1275" ] GROUPS["powerpc"] = [ "powerpc_ieee1275" ] -GROUPS["nosparc64"] = GRUB_PLATFORMS[:]; GROUPS["nosparc64"].remove("sparc64_ieee1275") -GROUPS["x86_noefi_mips"] = GROUPS["x86_noefi"] + GROUPS["mips"] - +# Groups based on firmware +GROUPS["x86_efi"] = [ "i386_efi", "x86_64_efi" ] GROUPS["ieee1275"] = [ "i386_ieee1275", "sparc64_ieee1275", "powerpc_ieee1275" ] -GROUPS["noieee1275"] = GRUB_PLATFORMS[:] -for i in GROUPS["ieee1275"]: GROUPS["noieee1275"].remove(i) -GROUPS["ieee1275_mips"] = GROUPS["ieee1275"] + GROUPS["mips"] - -GROUPS["pci"] = GROUPS["x86"] + GROUPS["mips"] +# emu is a special case so many core functionality isn't needed on this platform GROUPS["noemu"] = GRUB_PLATFORMS[:]; GROUPS["noemu"].remove("emu") -GROUPS["noemu_noieee1275"] = GRUB_PLATFORMS[:] -for i in ["emu"] + GROUPS["ieee1275"]: GROUPS["noemu_noieee1275"].remove(i) -GROUPS["common"] = GRUB_PLATFORMS[:] +# Groups based on hardware features +GROUPS["cmos"] = GROUPS["x86"][:] + ["mips_yeeloong"]; GROUPS["cmos"].remove("i386_efi"); GROUPS["cmos"].remove("x86_64_efi") +GROUPS["pci"] = GROUPS["x86"] + GROUPS["mips"] +GROUPS["usb"] = GROUPS["pci"] + +# If gfxterm is main output console integrate it into kernel +GROUPS["videoinkernel"] = ["mips_yeeloong"] +GROUPS["videomodules"] = GRUB_PLATFORMS[:]; +for i in GROUPS["videoinkernel"]: GROUPS["videomodules"].remove(i) + +# Miscelaneous groups schedulded to disappear in future +GROUPS["nosparc64"] = GRUB_PLATFORMS[:]; GROUPS["nosparc64"].remove("sparc64_ieee1275") +GROUPS["i386_coreboot_multiboot_qemu"] = ["i386_coreboot", "i386_multiboot", "i386_qemu"] +GROUPS["nopc"] = GRUB_PLATFORMS[:]; GROUPS["nopc"].remove("i386_pc") # # Create platform => groups reverse map, where groups covering that diff --git a/grub-core/Makefile.am b/grub-core/Makefile.am index 2dd34ee78..5d13d0313 100644 --- a/grub-core/Makefile.am +++ b/grub-core/Makefile.am @@ -58,8 +58,6 @@ KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/command.h KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/device.h KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/disk.h KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/dl.h -KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/elf.h -KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/elfload.h KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/env.h KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/env_private.h KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/err.h @@ -70,23 +68,14 @@ KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/kernel.h KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/list.h KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/misc.h KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/mm.h -KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/net.h KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/parser.h KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/partition.h -KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/reader.h -KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/symbol.h KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/term.h KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/time.h -KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/types.h KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/mm_private.h KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/boot.h -KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/loader.h -KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/msdos_partition.h if COND_i386_pc -KERNEL_HEADER_FILES += $(top_builddir)/include/grub/machine/biosdisk.h -KERNEL_HEADER_FILES += $(top_builddir)/include/grub/machine/boot.h -KERNEL_HEADER_FILES += $(top_builddir)/include/grub/machine/console.h KERNEL_HEADER_FILES += $(top_builddir)/include/grub/machine/memory.h KERNEL_HEADER_FILES += $(top_builddir)/include/grub/machine/loader.h KERNEL_HEADER_FILES += $(top_builddir)/include/grub/machine/kernel.h @@ -103,33 +92,26 @@ KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/i386/pit.h endif if COND_i386_coreboot -KERNEL_HEADER_FILES += $(top_builddir)/include/grub/machine/boot.h -KERNEL_HEADER_FILES += $(top_builddir)/include/grub/machine/console.h KERNEL_HEADER_FILES += $(top_builddir)/include/grub/machine/memory.h KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/i386/pit.h endif if COND_i386_multiboot -KERNEL_HEADER_FILES += $(top_builddir)/include/grub/machine/boot.h -KERNEL_HEADER_FILES += $(top_builddir)/include/grub/machine/console.h KERNEL_HEADER_FILES += $(top_builddir)/include/grub/machine/memory.h KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/i386/pit.h endif if COND_i386_qemu -KERNEL_HEADER_FILES += $(top_builddir)/include/grub/machine/boot.h -KERNEL_HEADER_FILES += $(top_builddir)/include/grub/machine/console.h KERNEL_HEADER_FILES += $(top_builddir)/include/grub/machine/memory.h KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/pci.h KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/i386/pit.h endif if COND_i386_ieee1275 -KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/loader.h -KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/msdos_partition.h KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/ieee1275/ieee1275.h KERNEL_HEADER_FILES += $(top_builddir)/include/grub/machine/memory.h KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/terminfo.h +KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/i386/pit.h endif if COND_x86_64_efi @@ -164,15 +146,10 @@ endif if COND_sparc64_ieee1275 KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/libgcc.h KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/ieee1275/ieee1275.h -KERNEL_HEADER_FILES += $(top_builddir)/include/grub/machine/kernel.h KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/sparc64/ieee1275/ieee1275.h endif if COND_emu -KERNEL_HEADER_FILES += $(top_builddir)/include/grub/cpu/time.h -KERNEL_HEADER_FILES += $(top_builddir)/include/grub/cpu/types.h -KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/gzio.h -KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/menu.h KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/datetime.h KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/emu/misc.h if COND_GRUB_EMU_SDL diff --git a/grub-core/Makefile.core.def b/grub-core/Makefile.core.def index b573ccf84..353b9d123 100644 --- a/grub-core/Makefile.core.def +++ b/grub-core/Makefile.core.def @@ -36,7 +36,8 @@ kernel = { x86_64_efi_startup = kern/x86_64/efi/startup.S; i386_qemu_startup = kern/i386/qemu/startup.S; i386_ieee1275_startup = kern/i386/ieee1275/startup.S; - i386_coreboot_multiboot_startup = kern/i386/coreboot/startup.S; + i386_coreboot_startup = kern/i386/coreboot/startup.S; + i386_multiboot_startup = kern/i386/coreboot/startup.S; mips_yeeloong_startup = kern/mips/startup.S; sparc64_ieee1275_startup = kern/sparc64/ieee1275/crt0.S; powerpc_ieee1275_startup = kern/powerpc/ieee1275/startup.S; @@ -65,7 +66,12 @@ kernel = { noemu_nodist = symlist.c; - noemu_noieee1275 = kern/generic/rtc_get_time_ms.c; + i386_pc = kern/generic/rtc_get_time_ms.c; + x86_efi = kern/generic/rtc_get_time_ms.c; + i386_qemu = kern/generic/rtc_get_time_ms.c; + i386_coreboot = kern/generic/rtc_get_time_ms.c; + i386_multiboot = kern/generic/rtc_get_time_ms.c; + mips_yeeloong = kern/generic/rtc_get_time_ms.c; ieee1275 = disk/ieee1275/ofdisk.c; ieee1275 = kern/ieee1275/cmain.c; @@ -74,17 +80,20 @@ kernel = { ieee1275 = kern/ieee1275/openfw.c; ieee1275 = term/ieee1275/ofconsole.c; - ieee1275_mips = term/terminfo.c; - ieee1275_mips = term/tparm.c; + ieee1275 = term/terminfo.c; + ieee1275 = term/tparm.c; + mips = term/terminfo.c; + mips = term/tparm.c; i386 = kern/i386/dl.c; i386_coreboot_multiboot_qemu = kern/i386/coreboot/init.c; i386_coreboot_multiboot_qemu = term/i386/pc/vga_text.c; - i386_pc_coreboot_multiboot_qemu = term/i386/vga_common.c; + i386_coreboot_multiboot_qemu = term/i386/vga_common.c; + i386_pc = term/i386/vga_common.c; - x86_noieee1275 = kern/i386/pit.c; + x86 = kern/i386/pit.c; x86_efi = disk/efi/efidisk.c; x86_efi = kern/efi/efi.c; @@ -121,26 +130,13 @@ kernel = { mips_yeeloong = bus/bonito.c; mips_yeeloong = bus/cs5536.c; mips_yeeloong = bus/pci.c; - mips_yeeloong = commands/extcmd.c; - mips_yeeloong = font/font.c; - mips_yeeloong = font/font_cmd.c; - mips_yeeloong = io/bufio.c; mips_yeeloong = kern/mips/cache.S; mips_yeeloong = kern/mips/dl.c; mips_yeeloong = kern/mips/init.c; mips_yeeloong = kern/mips/yeeloong/init.c; - mips_yeeloong = lib/arg.c; mips_yeeloong = term/at_keyboard.c; - mips_yeeloong = term/gfxterm.c; mips_yeeloong = term/serial.c; - mips_yeeloong = video/bitmap.c; - mips_yeeloong = video/bitmap_scale.c; - mips_yeeloong = video/fb/fbblit.c; - mips_yeeloong = video/fb/fbfill.c; - mips_yeeloong = video/fb/fbutil.c; - mips_yeeloong = video/fb/video_fb.c; mips_yeeloong = video/sm712.c; - mips_yeeloong = video/video.c; powerpc_ieee1275 = kern/ieee1275/init.c; powerpc_ieee1275 = kern/powerpc/cache.S; @@ -162,6 +158,20 @@ kernel = { emu = kern/emu/mm.c; emu = kern/emu/time.c; + videoinkernel = lib/arg.c; + videoinkernel = term/gfxterm.c; + videoinkernel = commands/extcmd.c; + videoinkernel = font/font.c; + videoinkernel = font/font_cmd.c; + videoinkernel = io/bufio.c; + videoinkernel = video/bitmap.c; + videoinkernel = video/bitmap_scale.c; + videoinkernel = video/fb/fbblit.c; + videoinkernel = video/fb/fbfill.c; + videoinkernel = video/fb/fbutil.c; + videoinkernel = video/fb/video_fb.c; + videoinkernel = video/video.c; + extra_dist = kern/i386/realmode.S; extra_dist = kern/i386/pc/lzma_decode.S; extra_dist = kern/mips/cache_flush.S; @@ -301,8 +311,7 @@ module = { noemu = bus/usb/usbtrans.c; noemu = bus/usb/usbhub.c; enable = emu; - enable = i386; - enable = mips_yeeloong; + enable = usb; emu_condition = COND_GRUB_EMU_USB; }; @@ -310,8 +319,7 @@ module = { name = usbserial_common; common = bus/usb/serial/common.c; enable = emu; - enable = i386_pc; - enable = mips_yeeloong; + enable = usb; emu_condition = COND_GRUB_EMU_USB; }; @@ -319,8 +327,7 @@ module = { name = usbserial_pl2303; common = bus/usb/serial/pl2303.c; enable = emu; - enable = i386_pc; - enable = mips_yeeloong; + enable = usb; emu_condition = COND_GRUB_EMU_USB; }; @@ -328,22 +335,20 @@ module = { name = usbserial_ftdi; common = bus/usb/serial/ftdi.c; enable = emu; - enable = i386_pc; - enable = mips_yeeloong; + enable = usb; emu_condition = COND_GRUB_EMU_USB; }; module = { name = uhci; common = bus/usb/uhci.c; - enable = i386_pc; + enable = x86; }; module = { name = ohci; common = bus/usb/ohci.c; - enable = i386_pc; - enable = mips_yeeloong; + enable = pci; }; module = { @@ -376,9 +381,8 @@ library = { module = { name = cmostest; - i386 = commands/i386/cmostest.c; - enable = i386_pc; - enable = i386_coreboot; + common = commands/i386/cmostest.c; + enable = cmos; }; module = { @@ -398,7 +402,7 @@ module = { module = { name = acpi; - i386 = commands/acpi.c; + x86 = commands/acpi.c; x86_efi = commands/efi/acpi.c; i386_pc = commands/i386/pc/acpi.c; i386_coreboot = commands/i386/pc/acpi.c; @@ -504,7 +508,7 @@ module = { name = hdparm; common = commands/hdparm.c; common = lib/hexdump.c; - enable = i386_pc; + enable = pci; }; module = { @@ -549,8 +553,7 @@ module = { name = lspci; common = commands/lspci.c; - enable = x86; - enable = mips; + enable = pci; }; module = { @@ -662,8 +665,7 @@ module = { module = { name = usbtest; common = commands/usbtest.c; - enable = i386_pc; - enable = mips_yeeloong; + enable = usb; enable = emu; emu_condition = COND_GRUB_EMU_USB; }; @@ -738,15 +740,13 @@ module = { module = { name = ata; common = disk/ata.c; - enable = x86; - enable = mips; + enable = pci; }; module = { name = ata_pthru; common = disk/ata_pthru.c; - enable = x86; - enable = mips_yeeloong; + enable = pci; }; module = { @@ -758,8 +758,7 @@ module = { module = { name = usbms; common = disk/usbms.c; - enable = i386_pc; - enable = mips_yeeloong; + enable = usb; enable = emu; emu_condition = COND_GRUB_EMU_USB; }; @@ -806,10 +805,7 @@ module = { name = font; common = font/font.c; common = font/font_cmd.c; - enable = emu; - enable = x86; - enable = sparc64; - enable = powerpc; + enable = videomodules; }; module = { @@ -977,10 +973,7 @@ module = { module = { name = bufio; common = io/bufio.c; - enable = emu; - enable = x86; - enable = sparc64; - enable = powerpc; + enable = videomodules; }; module = { @@ -1023,14 +1016,11 @@ module = { module = { name = datetime; - x86_noefi_mips = lib/cmos_datetime.c; + cmos = lib/cmos_datetime.c; x86_efi = lib/efi/datetime.c; sparc64_ieee1275 = lib/ieee1275/datetime.c; powerpc_ieee1275 = lib/ieee1275/datetime.c; - enable = x86; - enable = mips; - enable = sparc64_ieee1275; - enable = powerpc_ieee1275; + enable = noemu; }; module = { @@ -1129,34 +1119,15 @@ module = { module = { name = mmap; - i386_pc = mmap/mmap.c; - i386_pc = mmap/i386/uppermem.c; - i386_pc = mmap/i386/mmap.c; + common = mmap/mmap.c; + x86 = mmap/i386/uppermem.c; + x86 = mmap/i386/mmap.c; + i386_pc = mmap/i386/pc/mmap.c; i386_pc = mmap/i386/pc/mmap_helper.S; - x86_efi = mmap/mmap.c; - x86_efi = mmap/i386/uppermem.c; - x86_efi = mmap/i386/mmap.c; x86_efi = mmap/efi/mmap.c; - i386_coreboot = mmap/mmap.c; - i386_coreboot = mmap/i386/uppermem.c; - i386_coreboot = mmap/i386/mmap.c; - - i386_multiboot = mmap/mmap.c; - i386_multiboot = mmap/i386/uppermem.c; - i386_multiboot = mmap/i386/mmap.c; - - i386_qemu = mmap/mmap.c; - i386_qemu = mmap/i386/uppermem.c; - i386_qemu = mmap/i386/mmap.c; - - i386_ieee1275 = mmap/mmap.c; - i386_ieee1275 = mmap/i386/uppermem.c; - i386_ieee1275 = mmap/i386/mmap.c; - - mips_yeeloong = mmap/mmap.c; mips_yeeloong = mmap/mips/yeeloong/uppermem.c; enable = x86; @@ -1256,10 +1227,7 @@ module = { module = { name = gfxterm; common = term/gfxterm.c; - enable = emu; - enable = x86; - enable = sparc64; - enable = powerpc; + enable = videomodules; }; module = { @@ -1288,8 +1256,7 @@ module = { module = { name = usb_keyboard; common = term/usb_keyboard.c; - enable = i386_pc; - enable = mips_yeeloong; + enable = usb; }; module = { @@ -1334,19 +1301,13 @@ module = { module = { name = bitmap; common = video/bitmap.c; - enable = emu; - enable = x86; - enable = sparc64; - enable = powerpc; + enable = videomodules; }; module = { name = bitmap_scale; common = video/bitmap_scale.c; - enable = emu; - enable = x86; - enable = sparc64; - enable = powerpc; + enable = videomodules; }; module = { @@ -1388,19 +1349,13 @@ module = { common = video/fb/fbblit.c; common = video/fb/fbfill.c; common = video/fb/fbutil.c; - enable = emu; - enable = x86; - enable = sparc64; - enable = powerpc; + enable = videomodules; }; module = { name = video; common = video/video.c; - enable = emu; - enable = x86; - enable = sparc64; - enable = powerpc; + enable = videomodules; }; module = { diff --git a/grub-core/bus/usb/ohci.c b/grub-core/bus/usb/ohci.c index 7f757485c..3373e8038 100644 --- a/grub-core/bus/usb/ohci.c +++ b/grub-core/bus/usb/ohci.c @@ -57,10 +57,10 @@ struct grub_ohci_td /* next values are not for OHCI HW */ grub_uint32_t prev_td_phys; /* we need it to find previous TD * physical address in CPU endian */ - grub_uint32_t link_td; /* pointer to next free/chained TD + volatile struct grub_ohci_td *link_td; /* pointer to next free/chained TD * pointer as uint32 */ grub_uint32_t tr_index; /* index of TD in transfer */ - grub_uint8_t pad[4]; /* padding to 32 bytes */ + grub_uint8_t pad[8 - sizeof (volatile struct grub_ohci_td *)]; /* padding to 32 bytes */ } __attribute__((packed)); /* OHCI Endpoint Descriptor. */ @@ -334,7 +334,7 @@ grub_ohci_pci_iter (grub_pci_device_t dev, /* Preset free TDs chain in TDs */ grub_memset ((void*)o->td, 0, sizeof(struct grub_ohci_td) * GRUB_OHCI_TDS); for (j=0; j < (GRUB_OHCI_TDS-1); j++) - o->td[j].link_td = (grub_uint32_t)&o->td[j+1]; + o->td[j].link_td = &o->td[j+1]; grub_dprintf ("ohci", "TDs: chunk=%p, virt=%p, phys=0x%02x\n", o->td_chunk, o->td, o->td_addr); @@ -561,7 +561,7 @@ static void grub_ohci_free_td (struct grub_ohci *o, grub_ohci_td_t td) { grub_memset ( (void*)td, 0, sizeof(struct grub_ohci_td) ); - td->link_td = (grub_uint32_t) o->td_free; /* Cahin new free TD & rest */ + td->link_td = o->td_free; /* Cahin new free TD & rest */ o->td_free = td; /* Change address of first free TD */ } @@ -604,8 +604,8 @@ grub_ohci_transaction (grub_ohci_td_t td, grub_uint32_t buffer; grub_uint32_t buffer_end; - grub_dprintf ("ohci", "OHCI transaction td=%p type=%d, toggle=%d, size=%d\n", - td, type, toggle, size); + grub_dprintf ("ohci", "OHCI transaction td=%p type=%d, toggle=%d, size=%lu\n", + td, type, toggle, (unsigned long) size); switch (type) { @@ -781,7 +781,7 @@ grub_ohci_transfer (grub_usb_controller_t dev, } /* Chain TDs */ - td_current_virt->link_td = (grub_uint32_t) td_next_virt; + td_current_virt->link_td = td_next_virt; td_current_virt->next_td = grub_cpu_to_le32 ( grub_ohci_td_virt2phys (o, td_next_virt) ); diff --git a/grub-core/bus/usb/uhci.c b/grub-core/bus/usb/uhci.c index 0bba24b54..1fe86f5d4 100644 --- a/grub-core/bus/usb/uhci.c +++ b/grub-core/bus/usb/uhci.c @@ -228,7 +228,7 @@ grub_uhci_pci_iter (grub_pci_device_t dev, /* Link all Transfer Descriptors in a list of available Transfer Descriptors. */ for (i = 0; i < 256; i++) - u->td[i].linkptr = (grub_uint32_t) &u->td[i + 1]; + u->td[i].linkptr = (grub_uint32_t) (grub_addr_t) &u->td[i + 1]; u->td[255 - 1].linkptr = 0; u->tdfree = u->td; @@ -238,20 +238,20 @@ grub_uhci_pci_iter (grub_pci_device_t dev, /* Setup the frame list pointers. Since no isochronous transfers are and will be supported, they all point to the (same!) queue head. */ - fp = (grub_uint32_t) u->qh & (~15); + fp = (grub_uint32_t) (grub_addr_t) u->qh & (~15); /* Mark this as a queue head. */ fp |= 2; for (i = 0; i < 1024; i++) u->framelist[i] = fp; /* Program the framelist address into the UHCI controller. */ grub_uhci_writereg32 (u, GRUB_UHCI_REG_FLBASEADD, - (grub_uint32_t) u->framelist); + (grub_uint32_t) (grub_addr_t) u->framelist); /* Make the Queue Heads point to each other. */ for (i = 0; i < 256; i++) { /* Point to the next QH. */ - u->qh[i].linkptr = (grub_uint32_t) (&u->qh[i + 1]) & (~15); + u->qh[i].linkptr = (grub_uint32_t) (grub_addr_t) (&u->qh[i + 1]) & (~15); /* This is a QH. */ u->qh[i].linkptr |= GRUB_UHCI_LINK_QUEUE_HEAD; @@ -319,7 +319,7 @@ grub_alloc_td (struct grub_uhci *u) return NULL; ret = u->tdfree; - u->tdfree = (grub_uhci_td_t) u->tdfree->linkptr; + u->tdfree = (grub_uhci_td_t) (grub_addr_t) u->tdfree->linkptr; return ret; } @@ -327,7 +327,7 @@ grub_alloc_td (struct grub_uhci *u) static void grub_free_td (struct grub_uhci *u, grub_uhci_td_t td) { - td->linkptr = (grub_uint32_t) u->tdfree; + td->linkptr = (grub_uint32_t) (grub_addr_t) u->tdfree; u->tdfree = td; } @@ -352,7 +352,7 @@ grub_free_queue (struct grub_uhci *u, grub_uhci_td_t td, /* Unlink the queue. */ tdprev = td; - td = (grub_uhci_td_t) td->linkptr2; + td = (grub_uhci_td_t) (grub_addr_t) td->linkptr2; /* Free the TD. */ grub_free_td (u, tdprev); @@ -413,8 +413,8 @@ grub_uhci_transaction (struct grub_uhci *u, unsigned int endp, } grub_dprintf ("uhci", - "transaction: endp=%d, type=%d, addr=%d, toggle=%d, size=%d data=0x%x td=%p\n", - endp, type, addr, toggle, size, data, td); + "transaction: endp=%d, type=%d, addr=%d, toggle=%d, size=%lu data=0x%x td=%p\n", + endp, type, addr, toggle, (unsigned long) size, data, td); /* Don't point to any TD, just terminate. */ td->linkptr = 1; @@ -484,8 +484,8 @@ grub_uhci_transfer (grub_usb_controller_t dev, td_first = td; else { - td_prev->linkptr2 = (grub_uint32_t) td; - td_prev->linkptr = (grub_uint32_t) td; + td_prev->linkptr2 = (grub_uint32_t) (grub_addr_t) td; + td_prev->linkptr = (grub_uint32_t) (grub_addr_t) td; td_prev->linkptr |= 4; } td_prev = td; @@ -497,7 +497,7 @@ grub_uhci_transfer (grub_usb_controller_t dev, /* Link it into the queue and terminate. Now the transaction can take place. */ - qh->elinkptr = (grub_uint32_t) td_first; + qh->elinkptr = (grub_uint32_t) (grub_addr_t) td_first; grub_dprintf ("uhci", "initiate transaction\n"); @@ -508,7 +508,7 @@ grub_uhci_transfer (grub_usb_controller_t dev, { grub_uhci_td_t errtd; - errtd = (grub_uhci_td_t) (qh->elinkptr & ~0x0f); + errtd = (grub_uhci_td_t) (grub_addr_t) (qh->elinkptr & ~0x0f); grub_dprintf ("uhci", ">t status=0x%02x data=0x%02x td=%p\n", errtd->ctrl_status, errtd->buffer & (~15), errtd); diff --git a/grub-core/bus/usb/usbtrans.c b/grub-core/bus/usb/usbtrans.c index db2ec097a..13f5c28ed 100644 --- a/grub-core/bus/usb/usbtrans.c +++ b/grub-core/bus/usb/usbtrans.c @@ -54,8 +54,8 @@ grub_usb_control_msg (grub_usb_device_t dev, grub_memcpy ((char *) data, data_in, size); grub_dprintf ("usb", - "control: reqtype=0x%02x req=0x%02x val=0x%02x idx=0x%02x size=%d\n", - reqtype, request, value, index, size); + "control: reqtype=0x%02x req=0x%02x val=0x%02x idx=0x%02x size=%lu\n", + reqtype, request, value, index, (unsigned long)size); /* Create a transfer. */ transfer = grub_malloc (sizeof (*transfer)); @@ -179,7 +179,8 @@ grub_usb_bulk_readwrite (grub_usb_device_t dev, struct grub_pci_dma_chunk *data_chunk; grub_size_t size = size0; - grub_dprintf ("usb", "bulk: size=0x%02x type=%d\n", size, type); + grub_dprintf ("usb", "bulk: size=0x%02lx type=%d\n", (unsigned long) size, + type); /* FIXME: avoid allocation any kind of buffer in a first place. */ data_chunk = grub_memalign_dma32 (128, size); diff --git a/grub-core/loader/i386/pc/linux.c b/grub-core/loader/i386/pc/linux.c index 1e34b6c85..0719cfb26 100644 --- a/grub-core/loader/i386/pc/linux.c +++ b/grub-core/loader/i386/pc/linux.c @@ -34,7 +34,7 @@ #include #include #include -#include +#include #define GRUB_LINUX_CL_OFFSET 0x9000 #define GRUB_LINUX_CL_END_OFFSET 0x90FF diff --git a/grub-core/loader/i386/xnu.c b/grub-core/loader/i386/xnu.c index 643a895e8..556f1dbf1 100644 --- a/grub-core/loader/i386/xnu.c +++ b/grub-core/loader/i386/xnu.c @@ -123,7 +123,6 @@ static grub_uint64_t guessfsb (void) { const grub_uint64_t sane_value = 100000000; -#ifndef GRUB_MACHINE_IEEE1275 grub_uint32_t manufacturer[3], max_cpuid, capabilities, msrlow; grub_uint64_t start_tsc; grub_uint64_t end_tsc; @@ -209,9 +208,6 @@ guessfsb (void) return grub_divmod64 (2000 * tsc_ticks_per_ms, ((msrlow >> 7) & 0x3e) + ((msrlow >> 14) & 1), 0); -#else - return sane_value; -#endif } struct property_descriptor From 949737be16d6e2381497c24c432c45430615aebf Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Mon, 30 Aug 2010 16:25:14 +0200 Subject: [PATCH 18/21] Fix alignment and add explicit assert for td and ed size --- grub-core/bus/usb/ohci.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/grub-core/bus/usb/ohci.c b/grub-core/bus/usb/ohci.c index 3373e8038..587a36420 100644 --- a/grub-core/bus/usb/ohci.c +++ b/grub-core/bus/usb/ohci.c @@ -55,10 +55,10 @@ struct grub_ohci_td grub_uint32_t next_td; /* LittleEndian physical address */ grub_uint32_t buffer_end; /* LittleEndian physical address */ /* next values are not for OHCI HW */ - grub_uint32_t prev_td_phys; /* we need it to find previous TD - * physical address in CPU endian */ volatile struct grub_ohci_td *link_td; /* pointer to next free/chained TD * pointer as uint32 */ + grub_uint32_t prev_td_phys; /* we need it to find previous TD + * physical address in CPU endian */ grub_uint32_t tr_index; /* index of TD in transfer */ grub_uint8_t pad[8 - sizeof (volatile struct grub_ohci_td *)]; /* padding to 32 bytes */ } __attribute__((packed)); @@ -1406,6 +1406,8 @@ static struct grub_usb_controller_dev usb_controller = GRUB_MOD_INIT(ohci) { + COMPILE_TIME_ASSERT (sizeof (struct grub_ohci_td) == 32); + COMPILE_TIME_ASSERT (sizeof (struct grub_ohci_ed) == 16); grub_ohci_inithw (); grub_usb_controller_dev_register (&usb_controller); grub_loader_register_preboot_hook (grub_ohci_fini_hw, grub_ohci_restore_hw, From b0ea3a5a93c3ec4eaef2b4bd5fb3126b5b0cae1c Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Mon, 30 Aug 2010 16:25:39 +0200 Subject: [PATCH 19/21] Add missing noreturn --- include/grub/misc.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/include/grub/misc.h b/include/grub/misc.h index c516b3dc2..774dc5843 100644 --- a/include/grub/misc.h +++ b/include/grub/misc.h @@ -321,9 +321,9 @@ void EXPORT_FUNC (grub_reboot) (void) __attribute__ ((noreturn)); #ifdef GRUB_MACHINE_PCBIOS /* Halt the system, using APM if possible. If NO_APM is true, don't * use APM even if it is available. */ -void grub_halt (int no_apm); +void grub_halt (int no_apm) __attribute__ ((noreturn)); #else -void grub_halt (void); +void grub_halt (void) __attribute__ ((noreturn)); #endif #ifdef GRUB_MACHINE_EMU From 0f40441b91d1c993fddde8b6b51b0d566547cbf0 Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Mon, 30 Aug 2010 16:26:05 +0200 Subject: [PATCH 20/21] Remove useless prototypes --- include/grub/i386/pc/biosdisk.h | 3 --- 1 file changed, 3 deletions(-) diff --git a/include/grub/i386/pc/biosdisk.h b/include/grub/i386/pc/biosdisk.h index 69a240a2e..f8a9b463f 100644 --- a/include/grub/i386/pc/biosdisk.h +++ b/include/grub/i386/pc/biosdisk.h @@ -106,7 +106,4 @@ struct grub_biosdisk_dap grub_uint64_t block; } __attribute__ ((packed)); -void grub_biosdisk_init (void); -void grub_biosdisk_fini (void); - #endif /* ! GRUB_BIOSDISK_MACHINE_HEADER */ From 9494ef9aaf5b98466e347a192296deedb79c0a12 Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Mon, 30 Aug 2010 16:28:01 +0200 Subject: [PATCH 21/21] Add ChangeLog --- ChangeLog | 230 +++++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 228 insertions(+), 2 deletions(-) diff --git a/ChangeLog b/ChangeLog index b15fc7fe7..e52a07849 100644 --- a/ChangeLog +++ b/ChangeLog @@ -2,10 +2,236 @@ Interrupt wrapping and code simplifications. + * Makefile.util.def (grub-mkrescue): Use x86 tg instead of + x86_noieee1275 which are functionaly equivalent in this case. + (grub-install): Make source on each platform explicit. Enable on + all noemu. + * gentpl.py (x86_efi_pc): Removed group. + (x86_noefi): Likewise. + (i386_noefi): Likewise. + (x86_noieee1275): Likewise. + (i386_noieee1275): Likewise. + (i386_noefi_noieee1275): Likewise. + (i386_pc_qemu_coreboot): Likewise. + (i386_coreboot_multiboot): Likewise. + (i386_pc_coreboot_multiboot_qemu): Likewise. + (x86_noefi_mips): Likewise. + (noieee1275): Likewise. + (ieee1275_mips): Likewise. + (noemu_noieee1275): Likewise. + (cmos): New group. + (usb): Likewise. + (videoinkernel): Likewise. + (videomodules): Likewise. * grub-core/Makefile.am (KERNEL_HEADER_FILES): Remove - include/grub/machine/vga.h, include/grub/machine/vbe.h, + include/grub/elf.h, include/grub/elfload.h, include/grub/net.h, + include/grub/reader.h, include/grub/symbol.h, include/grub/types.h, + include/grub/loader.h, include/grub/msdos_partition.h, + include/grub/machine/biosdisk.h, include/grub/machine/boot.h, + include/grub/machine/console.h, include/grub/machine/vga.h, + include/grub/machine/vbe.h, include/grub/machine/init.h, + include/grub/machine/kernel.h, include/grub/cpu/time.h, + include/grub/cpu/types.h, include/grub/gzio.h and include/grub/menu.h (KERNEL_HEADER_FILES) [i386-pc]: Add include/grub/machine/int.h. - Remove include/grub/machine/init.h. + (KERNEL_HEADER_FILES) [i386-ieee1275]: Add include/grub/i386/pit.h + * grub-core/Makefile.core.def (kernel): Explicit the source for + startup. Explicit the platforms using kern/generic/rtc_get_time_ms.c. + Split ieee1275_mips. Remove kern/i386/halt.c. Remove kern/i386/misc.S. + Enable kern/i386/pit.c on all x86. Remove kern/i386/ieee1275/init.c. + Use videoinkernel tag. + (usb): Enable on all usb. + (usbserial_common): Likewise. + (usbserial_pl2303): Likewise. + (usbserial_ftdi): Likewise. + (uhci): Enable on all x86. + (ohci): Enable on all pci. + (cmostest): Enable on all CMOS. + (acpi): Include commands/acpi.c on all platforms. + (halt): Add relevant lib/*/halt.c. + (hdparm): Enable on all pci. + (lspci): Likewise. + (usbtest): Enable on all usb. + (ata): Enable on all pci. + (ata_pthru): Likewise. + (usbms): Enable on all usb. + (usb_keyboard): Likewise. + (font): Use tag videomodules. + (bufio): Likewise. + (datetime): Use tag cmos. Enable on all noemu. + (mmap): Use tags common and x86. + (gfxterm): Use tag videomodules. + (bitmap): Likewise. + (bitmap_scale): Likewise. + (video_fb): Likewise. + (video): Likewise. + * grub-core/bus/usb/ohci.c (grub_ohci_td): Make link_td a pointer and + adjust padding accordingly. All users updated. + (grub_ohci_transaction): Fix bad format specification. + (GRUB_MOD_INIT): Add asserts for struct size. + * grub-core/bus/usb/uhci.c (grub_uhci_pci_iter): Add explicit casts. + (grub_alloc_td): Likewise. + (grub_free_queue): Likewise. + (grub_uhci_transfer): Likewise. + (grub_uhci_transaction): Fix bad format specification. + * grub-core/bus/usb/usbtrans.c (grub_usb_control_msg): Likewise. + (grub_usb_bulk_readwrite): Likewise. + * grub-core/kern/i386/misc.S (grub_stop): Moved from here ... + * grub-core/commands/i386/pc/halt.c (stop): ...here. Transformed into C. + Made static. + * grub-core/lib/i386/halt.c (stop): ... and here. Transformed into C. + Made static. + * grub-core/kern/i386/pc/startup.S (grub_halt): Moved from here ... + * grub-core/commands/i386/pc/halt.c (grub_halt): ...here. + Transformed into C. + * grub-core/kern/i386/pc/startup.S (grub_biosdisk_rw_int13_extensions): + Moved from here ... + * grub-core/disk/i386/pc/biosdisk.c (grub_biosdisk_rw_int13_extensions): + ... here. Transformed into C. Made static. + * grub-core/kern/i386/pc/startup.S (grub_biosdisk_rw_standard): + Moved from here ... + * grub-core/disk/i386/pc/biosdisk.c (grub_biosdisk_rw_standard): + ... here. Transformed into C. Made static. + * grub-core/kern/i386/pc/startup.S + (grub_biosdisk_check_int13_extensions): Moved from here ... + * grub-core/disk/i386/pc/biosdisk.c + (grub_biosdisk_check_int13_extensions): ... here. Transformed into C. + Made static. + * grub-core/kern/i386/pc/startup.S + (grub_biosdisk_get_cdinfo_int13_extensions): Moved from here ... + * grub-core/disk/i386/pc/biosdisk.c + (grub_biosdisk_get_cdinfo_int13_extensions): ... here. + Transformed into C. Made static. + * grub-core/kern/i386/pc/startup.S + (grub_biosdisk_get_diskinfo_int13_extensions): Moved from here ... + * grub-core/disk/i386/pc/biosdisk.c + (grub_biosdisk_get_diskinfo_int13_extensions): ... here. + Transformed into C. Made static. + * grub-core/kern/i386/pc/startup.S + (grub_biosdisk_get_diskinfo_standard): Moved from here ... + * grub-core/disk/i386/pc/biosdisk.c + (grub_biosdisk_get_diskinfo_standard): ... here. + Transformed into C. Made static. + * grub-core/kern/i386/pc/startup.S + (grub_biosdisk_get_num_floppies): Moved from here ... + * grub-core/disk/i386/pc/biosdisk.c + (grub_biosdisk_get_num_floppies): ... here. + Transformed into C. Made static. + * grub-core/disk/i386/pc/biosdisk.c (grub_biosdisk_get_diskinfo_real): + New function. + * grub-core/kern/i386/pc/startup.S (grub_pxe_scan): Moved from here ... + * grub-core/fs/i386/pc/pxe.c (grub_pxe_scan): ... here. + Transformed into C. Made static. + * grub-core/kern/i386/pc/startup.S (grub_rm_entry): Moved from here ... + * grub-core/fs/i386/pc/pxe.c (grub_rm_entry): ... here. + Transformed into C. Made static. + * grub-core/kern/i386/ieee1275/init.c: Removed. + * grub-core/kern/i386/misc.S: Likewise. + * grub-core/kern/i386/pc/startup.S (grub_get_memsize): + Splitted from here ... + * grub-core/kern/i386/pc/init.c (grub_get_conv_memsize): ... here. + Transformed into C. Made static. All users updated. + * grub-core/kern/i386/pc/mmap.c (grub_get_ext_memsize): ... and here. + Transformed into C. Made static. All users updated. + * grub-core/kern/i386/pc/startup.S (grub_get_eisa_mmap): + Moved from here... + * grub-core/kern/i386/pc/mmap.c (grub_get_eisa_mmap): ... here. + Transformed into C. Made static. All users updated. + * grub-core/kern/i386/pc/startup.S (grub_get_mmap_entry): + Moved from here... + * grub-core/kern/i386/pc/mmap.c (grub_get_mmap_entry): ... here. + Transformed into C. Made static. All users updated. + * grub-core/kern/i386/pc/startup.S (grub_stop_floppy): + Removed (replaced by C version). + * grub-core/kern/i386/pc/startup.S (grub_vga_set_mode): + Moved from here... + * grub-core/video/i386/pc/vga.c (grub_vga_set_mode): ...here. + Transformed into C. Made static. + * grub-core/kern/i386/pc/startup.S (grub_vbe_bios_get_controller_info): + Moved from here... + * grub-core/video/i386/pc/vbe.c (grub_vbe_bios_get_controller_info): + ... here. Transformed into C. + * grub-core/kern/i386/pc/startup.S (grub_vbe_bios_get_mode_info): + Moved from here... + * grub-core/video/i386/pc/vbe.c (grub_vbe_bios_get_mode_info): + ... here. Transformed into C. + * grub-core/kern/i386/pc/startup.S (grub_vbe_bios_set_mode): + Moved from here... + * grub-core/video/i386/pc/vbe.c (grub_vbe_bios_set_mode): + ... here. Transformed into C. Made static. + * grub-core/kern/i386/pc/startup.S (grub_vbe_bios_get_mode): + Moved from here... + * grub-core/video/i386/pc/vbe.c (grub_vbe_bios_get_mode): + ... here. Transformed into C. + * grub-core/kern/i386/pc/startup.S (grub_vbe_bios_getset_dac_palette_width): + Moved from here... + * grub-core/video/i386/pc/vbe.c (grub_vbe_bios_getset_dac_palette_width): + ... here. Transformed into C. + * grub-core/kern/i386/pc/startup.S (grub_vbe_bios_set_memory_window): + Moved from here... + * grub-core/video/i386/pc/vbe.c (grub_vbe_bios_set_memory_window): + ... here. Transformed into C. + * grub-core/kern/i386/pc/startup.S (grub_vbe_bios_get_memory_window): + Moved from here... + * grub-core/video/i386/pc/vbe.c (grub_vbe_bios_get_memory_window): + ... here. Transformed into C. + * grub-core/kern/i386/pc/startup.S (grub_vbe_bios_set_scanline_length): + Moved from here... + * grub-core/video/i386/pc/vbe.c (grub_vbe_bios_set_scanline_length): + ... here. Transformed into C. + * grub-core/kern/i386/pc/startup.S (grub_vbe_bios_get_scanline_length): + Moved from here... + * grub-core/video/i386/pc/vbe.c (grub_vbe_bios_get_scanline_length): + ... here. Transformed into C. + * grub-core/kern/i386/pc/startup.S (grub_vbe_bios_set_display_start): + Moved from here... + * grub-core/video/i386/pc/vbe.c (grub_vbe_bios_set_display_start): + ... here. Transformed into C. Made static. + * grub-core/kern/i386/pc/startup.S (grub_vbe_bios_get_display_start): + Moved from here... + * grub-core/video/i386/pc/vbe.c (grub_vbe_bios_get_display_start): + ... here. Transformed into C. Made static. + * grub-core/kern/i386/pc/startup.S (grub_vbe_bios_set_palette_data): + Moved from here... + * grub-core/video/i386/pc/vbe.c (grub_vbe_bios_set_palette_data): + ... here. Transformed into C. Made static. + * grub-core/kern/i386/pc/startup.S (grub_pxe_call): Receive + pxe_rm_entry as third argument. + (grub_bios_interrupt): New function. + * grub-core/kern/i386/qemu/mmap.c: Remove useless include. + * grub-core/kern/i386/qemu/startup.S (codestart): Do cli;hlt instead + of calling grub_stop. + * grub-core/kern/efi/efi.c (grub_halt): Moved from here ... + * grub-core/lib/efi/halt.c (grub_halt): ...here. + * grub-core/kern/emu/main.c (grub_halt): Moved from here ... + * grub-core/lib/emu/halt.c (grub_halt): ... here. + * grub-core/lib/i386/halt.c: Moved from here ... + * grub-core/lib/i386/halt.c: ... here. + * grub-core/kern/ieee1275/openfw.c (grub_halt): Moved from here ... + * grub-core/lib/ieee1275/halt.c (grub_halt): ... here. + * grub-core/loader/i386/pc/linux.c (grub_linux16_boot): Call + grub_stop_floppy. + * grub-core/loader/i386/xnu.c (guessfsb) [IEEE1275]: Enable. + * include/grub/i386/coreboot/init.h: Removed. + * include/grub/i386/multiboot/init.h: Likewise. + * include/grub/i386/pc/biosdisk.h: Removed all function prototypes. + * include/grub/i386/pc/init.h: Likewise except grub_gate_a20. + * include/grub/i386/pc/int.h: New file. + * include/grub/i386/pc/pxe.h (GRUB_PXE_SIGNATURE): New definition. + (grub_pxe_scan): Removed. + (grub_pxe_call): Update prototype. + * include/grub/i386/pc/vbe.h: Removed EXPORT_FUNC and useless + prototypes. + * include/grub/i386/pc/vga.h (grub_vga_set_mode): Removed. + * include/grub/i386/qemu/init.h: Removed. + * include/grub/mips/yeeloong/kernel.h (grub_reboot): Add missing + noreturn. + (grub_halt): Likewise. + * include/grub/misc.h (grub_halt): Removed EXPORT_FUNC. + (grub_reboot): Likewise. + * grub-core/kern/i386/coreboot/init.c (grub_stop_floppy): Moved from here... + * include/grub/i386/floppy.h (grub_stop_floppy): ...here. Inlined. + + * grub-core/kern/i386/pc/startup.S (grub_hard_stop) 2010-08-30 Vladimir Serbinenko