Changeset ce8725be in mainline


Ignore:
Timestamp:
2006-06-25T21:33:26Z (19 years ago)
Author:
Jakub Jermar <jakub@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
d22645e
Parents:
282f4724
Message:

Cleanup boot infrastructure: ppc32 (and elsewhere).

Files:
1 added
1 deleted
11 edited
3 moved

Legend:

Unmodified
Added
Removed
  • Makefile

    r282f4724 rce8725be  
    7676        $(MAKE) -C $(USPACEDIR) clean ARCH=$(ARCH)
    7777
     78clean_boot_gen:
     79        -rm generic/*.o genarch/*.o
     80
    7881distclean_kernel:
    7982        $(MAKE) -C $(KERNELDIR) distclean ARCH=$(ARCH)
  • arch/mips32/Makefile.inc

    r282f4724 rce8725be  
    3333        cp arch/$(ARCH)/loader/image.boot image.boot
    3434
    35 clean: clean_kernel clean_uspace
     35clean: clean_boot_gen clean_kernel clean_uspace
    3636        make -C arch/$(ARCH)/loader clean
    3737        -rm -f image.boot
  • arch/mips32/loader/Makefile

    r282f4724 rce8725be  
    4747endif
    4848
    49 CFLAGS = -nostdinc -nostdlib -fno-builtin -Werror-implicit-function-declaration -Wmissing-prototypes -Werror -O3 -mno-abicalls -G 0 -fno-zero-initialized-in-bss -mhard-float -mips3
    50 DEFS = -I.
     49CFLAGS = -I. -I../../../generic -nostdinc -nostdlib -fno-builtin -Werror-implicit-function-declaration -Wmissing-prototypes -Werror -O3 -mno-abicalls -G 0 -fno-zero-initialized-in-bss -mhard-float -mips3
    5150
    5251SOURCES = \
  • arch/mips32/loader/main.c

    r282f4724 rce8725be  
    2828
    2929#include "main.h"
    30 #include "../../../generic/printf.h"
     30#include <printf.h>
    3131#include "msim.h"
    3232#include "asm.h"
  • arch/mips32/loader/msim.c

    r282f4724 rce8725be  
    2828 
    2929#include "msim.h"
    30 #include "../../../generic/printf.h"
     30#include <printf.h>
    3131
    3232#define MSIM_VIDEORAM            0xB0000000
  • arch/mips32/loader/types.h

    r282f4724 rce8725be  
    3030#define TYPES_H__
    3131
    32 #include "../../../generic/types.h"
     32#include <gentypes.h>
    3333
    3434typedef signed char __s8;
  • arch/ppc32/Makefile.inc

    r282f4724 rce8725be  
    3333        cp arch/$(ARCH)/loader/image.boot image.boot
    3434
    35 clean: clean_kernel clean_uspace
     35clean: clean_boot_gen clean_kernel clean_uspace
    3636        make -C arch/$(ARCH)/loader clean KERNELDIR=../../../$(KERNELDIR) USPACEDIR=../../../$(USPACEDIR)
    3737        -rm -f image.boot
  • arch/ppc32/loader/Makefile

    r282f4724 rce8725be  
    4747endif
    4848
    49 CFLAGS = -nostdinc -nostdlib -fno-builtin -Werror-implicit-function-declaration -Wmissing-prototypes -Werror -O3 -mcpu=powerpc -msoft-float -m32
     49CFLAGS = -I. -I../../../generic -I../../../genarch -nostdinc -nostdlib -fno-builtin -Werror-implicit-function-declaration -Wmissing-prototypes -Werror -O3 -mcpu=powerpc -msoft-float -m32
    5050
    5151SOURCES = \
    5252        main.c \
    5353        ofw.c \
    54         printf.c \
     54        ../../../genarch/ofw.c \
     55        ../../../generic/printf.c \
    5556        asm.S \
    5657        boot.S
  • arch/ppc32/loader/main.c

    r282f4724 rce8725be  
    2828
    2929#include "main.h"
    30 #include "printf.h"
     30#include <printf.h>
    3131#include "asm.h"
    3232#include "_components.h"
  • arch/ppc32/loader/ofw.c

    r282f4724 rce8725be  
    2727 */
    2828 
    29 #include "ofw.h"
    30 #include "asm.h"
    31 #include "printf.h"
     29#include <ofw.h>
     30#include <printf.h>
    3231
    33 #define MAX_OFW_ARGS    10
    34 #define BUF_SIZE                1024
    35 
    36 typedef unsigned int ofw_arg_t;
    37 typedef unsigned int ihandle;
    38 typedef unsigned int phandle;
    39 
    40 /** OpenFirmware command structure
    41  *
    42  */
    43 typedef struct {
    44         const char *service;          /**< Command name */
    45         unsigned int nargs;           /**< Number of in arguments */
    46         unsigned int nret;            /**< Number of out arguments */
    47         ofw_arg_t args[MAX_OFW_ARGS]; /**< List of arguments */
    48 } ofw_args_t;
    49 
    50 typedef void (*ofw_entry)(ofw_args_t *);
    51 
    52 
    53 typedef struct {
    54         unsigned int info;
    55         unsigned int addr_hi;
    56     unsigned int addr_lo;
    57 } pci_addr_t;
    58 
    59 typedef struct {
    60         pci_addr_t addr;
    61     unsigned int size_hi;
    62     unsigned int size_lo;
    63 } pci_reg_t;
    64 
    65 
    66 ofw_entry ofw;
    67 
    68 phandle ofw_chosen;
    69 ihandle ofw_stdout;
    70 phandle ofw_root;
    71 ihandle ofw_mmu;
    72 phandle ofw_memory;
    73 phandle ofw_aliases;
    74 
    75 
    76 static int ofw_call(const char *service, const int nargs, const int nret, ofw_arg_t *rets, ...)
     32void write(const char *str, const int len)
    7733{
    78         va_list list;
    79         ofw_args_t args;
    80         int i;
    81        
    82         args.service = service;
    83         args.nargs = nargs;
    84         args.nret = nret;
    85        
    86         va_start(list, rets);
    87         for (i = 0; i < nargs; i++)
    88                 args.args[i] = va_arg(list, ofw_arg_t);
    89         va_end(list);
    90        
    91         for (i = 0; i < nret; i++)
    92                 args.args[i + nargs] = 0;
    93        
    94         ofw(&args);
    95        
    96         for (i = 1; i < nret; i++)
    97                 rets[i - 1] = args.args[i + nargs];
    98        
    99         return args.args[nargs];
     34        ofw_write(str, len);
    10035}
    101 
    102 
    103 static phandle ofw_find_device(const char *name)
    104 {
    105         return ofw_call("finddevice", 1, 1, NULL, name);
    106 }
    107 
    108 
    109 static int ofw_get_property(const phandle device, const char *name, const void *buf, const int buflen)
    110 {
    111         return ofw_call("getprop", 4, 1, NULL, device, name, buf, buflen);
    112 }
    113 
    114 
    115 static unsigned int ofw_get_address_cells(const phandle device)
    116 {
    117         unsigned int ret;
    118        
    119         if (ofw_get_property(device, "#address-cells", &ret, sizeof(ret)) <= 0)
    120                 if (ofw_get_property(ofw_root, "#address-cells", &ret, sizeof(ret)) <= 0)
    121                         ret = 1;
    122        
    123         return ret;
    124 }
    125 
    126 
    127 static unsigned int ofw_get_size_cells(const phandle device)
    128 {
    129         unsigned int ret;
    130        
    131         if (ofw_get_property(device, "#size-cells", &ret, sizeof(ret)) <= 0)
    132                 if (ofw_get_property(ofw_root, "#size-cells", &ret, sizeof(ret)) <= 0)
    133                         ret = 1;
    134        
    135         return ret;
    136 }
    137 
    138 
    139 static ihandle ofw_open(const char *name)
    140 {
    141         return ofw_call("open", 1, 1, NULL, name);
    142 }
    143 
    144 
    145 void init(void)
    146 {
    147         ofw_chosen = ofw_find_device("/chosen");
    148         if (ofw_chosen == -1)
    149                 halt();
    150        
    151         if (ofw_get_property(ofw_chosen, "stdout",  &ofw_stdout, sizeof(ofw_stdout)) <= 0)
    152                 ofw_stdout = 0;
    153        
    154         ofw_root = ofw_find_device("/");
    155         if (ofw_root == -1) {
    156                 puts("\r\nError: Unable to find / device, halted.\r\n");
    157                 halt();
    158         }
    159        
    160         if (ofw_get_property(ofw_chosen, "mmu",  &ofw_mmu, sizeof(ofw_mmu)) <= 0) {
    161                 puts("\r\nError: Unable to get mmu property, halted.\r\n");
    162                 halt();
    163         }
    164        
    165         ofw_memory = ofw_find_device("/memory");
    166         if (ofw_memory == -1) {
    167                 puts("\r\nError: Unable to find /memory device, halted.\r\n");
    168                 halt();
    169         }
    170        
    171         ofw_aliases = ofw_find_device("/aliases");
    172         if (ofw_aliases == -1) {
    173                 puts("\r\nError: Unable to find /aliases device, halted.\r\n");
    174                 halt();
    175         }
    176 }
    177 
    178 
    179 void ofw_write(const char *str, const int len)
    180 {
    181         if (ofw_stdout == 0)
    182                 return;
    183        
    184         ofw_call("write", 3, 1, NULL, ofw_stdout, str, len);
    185 }
    186 
    187 
    188 void *ofw_translate(const void *virt)
    189 {
    190         ofw_arg_t result[3];
    191        
    192         if (ofw_call("call-method", 4, 4, result, "translate", ofw_mmu, virt, 1) != 0) {
    193                 puts("Error: MMU method translate() failed, halting.\n");
    194                 halt();
    195         }
    196         return (void *) result[2];
    197 }
    198 
    199 
    200 int ofw_map(const void *phys, const void *virt, const int size, const int mode)
    201 {
    202         return ofw_call("call-method", 6, 1, NULL, "map", ofw_mmu, mode, size, virt, phys);
    203 }
    204 
    205 
    206 int ofw_memmap(memmap_t *map)
    207 {
    208         unsigned int buf[BUF_SIZE];
    209         int ret = ofw_get_property(ofw_memory, "reg", buf, sizeof(unsigned int) * BUF_SIZE);
    210         if (ret <= 0)
    211                 return false;
    212                
    213         unsigned int ac = ofw_get_address_cells(ofw_memory);
    214         unsigned int sc = ofw_get_size_cells(ofw_memory);
    215        
    216         int pos;
    217         map->total = 0;
    218         map->count = 0;
    219         for (pos = 0; (pos < ret / sizeof(unsigned int)) && (map->count < MEMMAP_MAX_RECORDS); pos += ac + sc) {
    220                 void * start = (void *) buf[pos + ac - 1];
    221                 unsigned int size = buf[pos + ac + sc - 1];
    222                
    223                 if (size > 0) {
    224                         map->zones[map->count].start = start;
    225                         map->zones[map->count].size = size;
    226                         map->count++;
    227                         map->total += size;
    228                 }
    229         }
    230 }
    231 
    232 
    233 int ofw_screen(screen_t *screen)
    234 {
    235         char device_name[BUF_SIZE];
    236        
    237         if (ofw_get_property(ofw_aliases, "screen", device_name, sizeof(char) * BUF_SIZE) <= 0)
    238                 return false;
    239        
    240         phandle device = ofw_find_device(device_name);
    241         if (device == -1)
    242                 return false;
    243        
    244         if (ofw_get_property(device, "address", &screen->addr, sizeof(screen->addr)) <= 0)
    245                 return false;
    246        
    247         if (ofw_get_property(device, "width", &screen->width, sizeof(screen->width)) <= 0)
    248                 return false;
    249        
    250         if (ofw_get_property(device, "height", &screen->height, sizeof(screen->height)) <= 0)
    251                 return false;
    252        
    253         if (ofw_get_property(device, "depth", &screen->bpp, sizeof(screen->bpp)) <= 0)
    254                 return false;
    255        
    256         if (ofw_get_property(device, "linebytes", &screen->scanline, sizeof(screen->scanline)) <= 0)
    257                 return false;
    258        
    259         return true;
    260 }
    261 
    262 
    263 int ofw_keyboard(keyboard_t *keyboard)
    264 {
    265         char device_name[BUF_SIZE];
    266        
    267         if (ofw_get_property(ofw_aliases, "macio", device_name, sizeof(char) * BUF_SIZE) <= 0)
    268                 return false;
    269        
    270         phandle device = ofw_find_device(device_name);
    271         if (device == -1)
    272                 return false;
    273        
    274         pci_reg_t macio;
    275         if (ofw_get_property(device, "assigned-addresses", &macio, sizeof(macio)) <= 0)
    276                 return false;
    277        
    278         keyboard->addr = (void *) macio.addr.addr_lo;
    279         keyboard->size = macio.size_lo;
    280        
    281         return true;
    282 }
  • arch/ppc32/loader/types.h

    r282f4724 rce8725be  
    2727 */
    2828
    29 #ifndef GENERIC_TYPES_H__
    30 #define GENERIC_TYPES_H__
     29#ifndef TYPES_H__
     30#define TYPES_H__
    3131
    32 #define NULL 0
    33 #define false 0
    34 #define true 1
     32#include <gentypes.h>
     33
     34typedef signed char __s8;
     35
     36typedef unsigned char __u8;
     37typedef unsigned short __u16;
     38typedef unsigned int __u32;
     39typedef unsigned long long __u64;
     40
     41typedef __u32 __address;
     42typedef __u32 __native;
    3543
    3644#endif
  • arch/ppc64/Makefile.inc

    r282f4724 rce8725be  
    3333        cp arch/$(ARCH)/loader/image.boot image.boot
    3434
    35 clean: clean_kernel clean_uspace
     35clean: clean_boot_gen clean_kernel clean_uspace
    3636        make -C arch/$(ARCH)/loader clean KERNELDIR=../../../$(KERNELDIR) USPACEDIR=../../../$(USPACEDIR)
    3737        -rm -f image.boot
  • generic/gentypes.h

    r282f4724 rce8725be  
    2727 */
    2828
    29 #ifndef __PRINTF_H__
    30 #define __PRINTF_H__
     29#ifndef GENTYPES_H__
     30#define GENTYPES_H__
    3131
    32 #define INT8    1
    33 #define INT16   2
    34 #define INT32   4
    35 #define INT64   8
    36 
    37 typedef signed char __s8;
    38 
    39 typedef unsigned char __u8;
    40 typedef unsigned short __u16;
    41 typedef unsigned int __u32;
    42 typedef unsigned long long __u64;
    43 
    44 typedef __u32 __address;
    45 typedef __u32 __native;
    46 
    47 typedef char *char_ptr;
    48 
    49 void puts(const char *str);
    50 void printf(const char *fmt, ...);
     32#define NULL 0
     33#define false 0
     34#define true 1
    5135
    5236#endif
Note: See TracChangeset for help on using the changeset viewer.