|
|
1.1 root 1: /******************************************************************************
2: * Copyright (c) 2004, 2008 IBM Corporation
3: * All rights reserved.
4: * This program and the accompanying materials
5: * are made available under the terms of the BSD License
6: * which accompanies this distribution, and is available at
7: * http://www.opensource.org/licenses/bsd-license.php
8: *
9: * Contributors:
10: * IBM Corporation - initial implementation
11: *****************************************************************************/
12:
1.1.1.2 ! root 13: #include <stdint.h>
! 14: #include <string.h>
! 15: #include <stdlib.h> /* malloc */
1.1 root 16: #include <of.h>
17: #include <pci.h>
18: #include <kernel.h>
19: #include <cpu.h>
20: #include <fileio.h>
21: #include <ioctl.h> /* ioctl */
1.1.1.2 ! root 22: #include "modules.h"
1.1 root 23:
24: /* Application entry point .*/
25: extern int _start(unsigned char *arg_string, long len);
26: extern int main(int, char**);
1.1.1.2 ! root 27: int _start_kernel(unsigned long p0, unsigned long p1);
1.1 root 28: void * malloc_aligned(size_t size, int align);
29:
30: unsigned long exception_stack_frame;
31:
32: snk_fileio_t fd_array[FILEIO_MAX];
33:
34: extern uint64_t tb_freq;
35:
36: int glue_init(snk_kernel_t *, unsigned int *, size_t, size_t);
37: void glue_release(void);
38:
39: static char save_vector[0x4000];
40: extern char _lowmem_start;
41: extern char _lowmem_end;
42: extern char __client_start;
43: extern char __client_end;
44:
45: snk_kernel_t snk_kernel_interface = {
46: .version = 1,
47: .print = printk,
48: .us_delay = udelay,
49: .ms_delay = mdelay,
50: .k_malloc = malloc,
51: .k_malloc_aligned = malloc_aligned,
52: .k_free = free,
53: .strcmp = strcmp,
54: .snk_call = main,
55: .k_open = open,
56: .k_close = close,
57: .k_read = read,
58: .k_write = write,
59: .k_ioctl = ioctl,
60: .modules_remove = rmmod_by_type,
61: .modules_load = insmod_by_type,
62: };
63:
64: void *
65: malloc_aligned(size_t size, int align)
66: {
67: unsigned long p = (unsigned long) malloc(size + align - 1);
68: p = p + align - 1;
69: p = p & ~(align - 1);
70:
71: return (void *) p;
72: }
73:
74: static void
1.1.1.2 ! root 75: copy_exception_vectors(void)
1.1 root 76: {
77: char *dest;
78: char *src;
79: int len;
80:
81: dest = save_vector;
82: src = (char *) 0x200;
83: len = &_lowmem_end - &_lowmem_start;
84: memcpy(dest, src, len);
85:
86: dest = (char *) 0x200;
87: src = &_lowmem_start;
88: memcpy(dest, src, len);
89: flush_cache(dest, len);
90: }
91:
92: static void
1.1.1.2 ! root 93: restore_exception_vectors(void)
1.1 root 94: {
95: char *dest;
96: char *src;
97: int len;
98:
99: dest = (char *) 0x200;
100: src = save_vector;
101: len = &_lowmem_end - &_lowmem_start;
102: memcpy(dest, src, len);
103: flush_cache(dest, len);
104: }
105:
106: int
107: _start_kernel(unsigned long p0, unsigned long p1)
108: {
109: int rc;
110: unsigned int timebase;
111:
112: /* initialize all file descriptor by marking them as empty */
113: for(rc=0; rc<FILEIO_MAX; ++rc) {
114: fd_array[rc].type = FILEIO_TYPE_EMPTY;
115: fd_array[rc].idx = rc;
116: }
117:
118: /* this is step is e.g. resposible to initialize file descriptor 0 and 1 for STDIO */
119: rc = glue_init(&snk_kernel_interface, &timebase, (size_t)(unsigned long)&__client_start,
120: (size_t)(unsigned long)&__client_end - (size_t)(unsigned long)&__client_start);
121: if(rc < 0)
122: return -1;
123:
124: tb_freq = (uint64_t) timebase;
125: copy_exception_vectors();
126: modules_init();
127: rc = _start((unsigned char *) p0, p1);
128: modules_term();
129: restore_exception_vectors();
130:
131: glue_release();
132: return rc;
133: }
134:
135:
136: void
137: exception_forward(void)
138: {
139: restore_exception_vectors();
140: undo_exception();
141: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.